aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contracts/test/exchange
diff options
context:
space:
mode:
authorRemco Bloemen <remco@wicked.ventures>2018-08-23 03:23:32 +0800
committerRemco Bloemen <remco@wicked.ventures>2018-08-25 05:09:51 +0800
commit3dad6ee55e9f51daa66cfe3c83dd17abc31f23f5 (patch)
tree0450ae8f09ce0eabdaa419dc54fe9d2b6067b853 /packages/contracts/test/exchange
parent5d70df771b151800b8a04b5569529843701c9fbd (diff)
downloaddexon-sol-tools-3dad6ee55e9f51daa66cfe3c83dd17abc31f23f5.tar
dexon-sol-tools-3dad6ee55e9f51daa66cfe3c83dd17abc31f23f5.tar.gz
dexon-sol-tools-3dad6ee55e9f51daa66cfe3c83dd17abc31f23f5.tar.bz2
dexon-sol-tools-3dad6ee55e9f51daa66cfe3c83dd17abc31f23f5.tar.lz
dexon-sol-tools-3dad6ee55e9f51daa66cfe3c83dd17abc31f23f5.tar.xz
dexon-sol-tools-3dad6ee55e9f51daa66cfe3c83dd17abc31f23f5.tar.zst
dexon-sol-tools-3dad6ee55e9f51daa66cfe3c83dd17abc31f23f5.zip
Add tests for getPartialAmountCeil
Diffstat (limited to 'packages/contracts/test/exchange')
-rw-r--r--packages/contracts/test/exchange/internal.ts40
1 files changed, 40 insertions, 0 deletions
diff --git a/packages/contracts/test/exchange/internal.ts b/packages/contracts/test/exchange/internal.ts
index 0231cc3f1..69625ee1d 100644
--- a/packages/contracts/test/exchange/internal.ts
+++ b/packages/contracts/test/exchange/internal.ts
@@ -1,6 +1,7 @@
import { BlockchainLifecycle } from '@0xproject/dev-utils';
import { Order, RevertReason, SignedOrder } from '@0xproject/types';
import { BigNumber } from '@0xproject/utils';
+import * as chai from 'chai';
import * as _ from 'lodash';
import { TestExchangeInternalsContract } from '../../generated_contract_wrappers/test_exchange_internals';
@@ -16,6 +17,8 @@ import { FillResults } from '../utils/types';
import { provider, txDefaults, web3Wrapper } from '../utils/web3_wrapper';
chaiSetup.configure();
+const expect = chai.expect;
+
const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
const MAX_UINT256 = new BigNumber(2).pow(256).minus(1);
@@ -213,6 +216,43 @@ describe('Exchange core internal functions', () => {
);
});
+ describe.only('getPartialAmountCeil', async () => {
+ async function referenceGetPartialAmountCeilAsync(
+ numerator: BigNumber,
+ denominator: BigNumber,
+ target: BigNumber,
+ ) {
+ if (denominator.eq(0)) {
+ throw new Error('revert DIVISION_BY_ZERO');
+ }
+ const product = numerator.mul(target);
+ const offset = product.add(denominator.sub(1));
+ if (offset.greaterThan(MAX_UINT256)) {
+ throw overflowErrorForCall;
+ }
+ const result = offset.dividedToIntegerBy(denominator);
+ if (product.mod(denominator).eq(0)) {
+ expect(result.mul(denominator)).to.be.bignumber.eq(product);
+ } else {
+ expect(result.mul(denominator)).to.be.bignumber.gt(product);
+ }
+ return result;
+ }
+ async function testGetPartialAmountCeilAsync(
+ numerator: BigNumber,
+ denominator: BigNumber,
+ target: BigNumber,
+ ): Promise<BigNumber> {
+ return testExchange.publicGetPartialAmountCeil.callAsync(numerator, denominator, target);
+ }
+ await testCombinatoriallyWithReferenceFuncAsync(
+ 'getPartialAmountCeil',
+ referenceGetPartialAmountCeilAsync,
+ testGetPartialAmountCeilAsync,
+ [uint256Values, uint256Values, uint256Values],
+ );
+ });
+
describe('isRoundingError', async () => {
async function referenceIsRoundingErrorAsync(
numerator: BigNumber,