aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2017-10-23 15:46:33 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2017-10-24 23:31:59 +0800
commit9d0ccdfdcc2ce962d76c406b83b15e520a971eae (patch)
treed556942ad76bc89650eb6275547d09d678914c36
parentcd1f0c74c1439302cd691449c0493ed7a1c14bf3 (diff)
downloaddexon-sol-tools-9d0ccdfdcc2ce962d76c406b83b15e520a971eae.tar
dexon-sol-tools-9d0ccdfdcc2ce962d76c406b83b15e520a971eae.tar.gz
dexon-sol-tools-9d0ccdfdcc2ce962d76c406b83b15e520a971eae.tar.bz2
dexon-sol-tools-9d0ccdfdcc2ce962d76c406b83b15e520a971eae.tar.lz
dexon-sol-tools-9d0ccdfdcc2ce962d76c406b83b15e520a971eae.tar.xz
dexon-sol-tools-9d0ccdfdcc2ce962d76c406b83b15e520a971eae.tar.zst
dexon-sol-tools-9d0ccdfdcc2ce962d76c406b83b15e520a971eae.zip
Add tests testing that rounding or makerFillAmount is correct and that we only validate partial fees
-rw-r--r--test/order_validation_test.ts33
1 files changed, 31 insertions, 2 deletions
diff --git a/test/order_validation_test.ts b/test/order_validation_test.ts
index 784fa9ec4..07a050fea 100644
--- a/test/order_validation_test.ts
+++ b/test/order_validation_test.ts
@@ -210,14 +210,14 @@ describe('OrderValidation', () => {
});
describe('#validateFillOrderBalancesAllowancesThrowIfInvalidAsync', () => {
let exchangeTransferSimulator: ExchangeTransferSimulator;
- let transferFromAsync: any;
+ let transferFromAsync: Sinon.SinonSpy;
const bigNumberMatch = (expected: BigNumber.BigNumber) => {
return Sinon.match((value: BigNumber.BigNumber) => value.eq(expected));
};
beforeEach('create exchangeTransferSimulator', async () => {
exchangeTransferSimulator = new ExchangeTransferSimulator(zeroEx.token);
transferFromAsync = Sinon.spy();
- exchangeTransferSimulator.transferFromAsync = transferFromAsync;
+ exchangeTransferSimulator.transferFromAsync = transferFromAsync as any;
});
it('should call exchangeTransferSimulator.transferFrom in a correct order', async () => {
const makerFee = new BigNumber(2);
@@ -291,5 +291,34 @@ describe('OrderValidation', () => {
),
).to.be.true();
});
+ it('should correctly round the fillMakerTokenAmount', async () => {
+ const makerTokenAmount = new BigNumber(3);
+ const takerTokenAmount = new BigNumber(1);
+ const signedOrder = await fillScenarios.createAsymmetricFillableSignedOrderAsync(
+ makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, makerTokenAmount, takerTokenAmount,
+ );
+ await orderValidationUtils.validateFillOrderBalancesAllowancesThrowIfInvalidAsync(
+ exchangeTransferSimulator, signedOrder, takerTokenAmount, takerAddress, zrxTokenAddress,
+ );
+ expect(transferFromAsync.callCount).to.be.equal(4);
+ expect(transferFromAsync.getCall(0).args[3]).to.be.bignumber.equal(makerTokenAmount);
+ });
+ it('should correctly round the makerFeeAmount', async () => {
+ const makerFee = new BigNumber(2);
+ const takerFee = new BigNumber(4);
+ const signedOrder = await fillScenarios.createFillableSignedOrderWithFeesAsync(
+ makerTokenAddress, takerTokenAddress, makerFee, takerFee, makerAddress, takerAddress,
+ fillableAmount, ZeroEx.NULL_ADDRESS,
+ );
+ const fillTakerTokenAmount = fillableAmount.div(2).round(0);
+ await orderValidationUtils.validateFillOrderBalancesAllowancesThrowIfInvalidAsync(
+ exchangeTransferSimulator, signedOrder, fillTakerTokenAmount, takerAddress, zrxTokenAddress,
+ );
+ const makerPartialFee = makerFee.div(2);
+ const takerPartialFee = takerFee.div(2);
+ expect(transferFromAsync.callCount).to.be.equal(4);
+ expect(transferFromAsync.getCall(2).args[3]).to.be.bignumber.equal(makerPartialFee);
+ expect(transferFromAsync.getCall(4).args[3]).to.be.bignumber.equal(takerPartialFee);
+ });
});
});