Merge pull request #2387 from 0xProject/feature/fuzz/staking-rewards

`@0x/contracts-integrations`: Staking rewards fuzz test
This commit is contained in:
mzhu25
2019-12-12 15:43:29 -08:00
committed by GitHub
47 changed files with 1429 additions and 447 deletions

View File

@@ -65,6 +65,7 @@
"chai": "^4.0.1",
"chai-as-promised": "^7.1.0",
"chai-bignumber": "^3.0.0",
"decimal.js": "^10.2.0",
"dirty-chai": "^2.0.1",
"ethereum-types": "^3.0.0",
"ethereumjs-util": "^5.1.1",

View File

@@ -54,12 +54,15 @@ export { replaceKeysDeep, shortZip } from './lang_utils';
export {
assertIntegerRoughlyEquals,
assertRoughlyEquals,
fromFixed,
getRandomFloat,
getRandomInteger,
getRandomPortion,
getNumericalDivergence,
getPercentageOfValue,
toBaseUnitAmount,
toDecimal,
toFixed,
} from './number_utils';
export { orderHashUtils } from './order_hash';
export { transactionHashUtils } from './transaction_hash';

View File

@@ -1,11 +1,24 @@
import { BigNumber } from '@0x/utils';
import { Web3Wrapper } from '@0x/web3-wrapper';
import * as crypto from 'crypto';
import { Decimal } from 'decimal.js';
import { expect } from './chai_setup';
import { constants } from './constants';
import { Numberish } from './types';
Decimal.set({ precision: 80 });
/**
* Convert `x` to a `Decimal` type.
*/
export function toDecimal(x: Numberish): Decimal {
if (BigNumber.isBigNumber(x)) {
return new Decimal(x.toString(10));
}
return new Decimal(x);
}
/**
* Generate a random integer between `min` and `max`, inclusive.
*/
@@ -33,6 +46,22 @@ export function getRandomFloat(min: Numberish, max: Numberish): BigNumber {
.plus(min);
}
export const FIXED_POINT_BASE = new BigNumber(2).pow(127);
/**
* Convert `n` to fixed-point integer represenatation.
*/
export function toFixed(n: Numberish): BigNumber {
return new BigNumber(n).times(FIXED_POINT_BASE).integerValue();
}
/**
* Convert `n` from fixed-point integer represenatation.
*/
export function fromFixed(n: Numberish): BigNumber {
return new BigNumber(n).dividedBy(FIXED_POINT_BASE);
}
/**
* Converts two decimal numbers to integers with `precision` digits, then returns
* the absolute difference.