aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contracts/test/utils
diff options
context:
space:
mode:
authorGreg Hysen <greg.hysen@gmail.com>2018-08-21 05:02:40 +0800
committerGreg Hysen <greg.hysen@gmail.com>2018-08-25 09:17:26 +0800
commit0ecdf1e2132141b199fa929ec1c6ca9979f06302 (patch)
treed9eda13e85e4c989590995fcfdd9babb6216e719 /packages/contracts/test/utils
parent057891b342cf639b493adcf0a136f7ee421aaaf9 (diff)
downloaddexon-sol-tools-0ecdf1e2132141b199fa929ec1c6ca9979f06302.tar
dexon-sol-tools-0ecdf1e2132141b199fa929ec1c6ca9979f06302.tar.gz
dexon-sol-tools-0ecdf1e2132141b199fa929ec1c6ca9979f06302.tar.bz2
dexon-sol-tools-0ecdf1e2132141b199fa929ec1c6ca9979f06302.tar.lz
dexon-sol-tools-0ecdf1e2132141b199fa929ec1c6ca9979f06302.tar.xz
dexon-sol-tools-0ecdf1e2132141b199fa929ec1c6ca9979f06302.tar.zst
dexon-sol-tools-0ecdf1e2132141b199fa929ec1c6ca9979f06302.zip
All existing tests pass.
Diffstat (limited to 'packages/contracts/test/utils')
-rw-r--r--packages/contracts/test/utils/match_order_tester.ts53
1 files changed, 33 insertions, 20 deletions
diff --git a/packages/contracts/test/utils/match_order_tester.ts b/packages/contracts/test/utils/match_order_tester.ts
index fa2eabc12..ded429322 100644
--- a/packages/contracts/test/utils/match_order_tester.ts
+++ b/packages/contracts/test/utils/match_order_tester.ts
@@ -9,6 +9,7 @@ import { ERC20Wrapper } from './erc20_wrapper';
import { ERC721Wrapper } from './erc721_wrapper';
import { ExchangeWrapper } from './exchange_wrapper';
import { ERC20BalancesByOwner, ERC721TokenIdsByOwner, TransferAmountsByMatchOrders as TransferAmounts } from './types';
+import { TransactionReceiptWithDecodedLogs } from '../../../../node_modules/ethereum-types';
chaiSetup.configure();
const expect = chai.expect;
@@ -108,7 +109,7 @@ export class MatchOrderTester {
: new BigNumber(0);
expect(expectedOrderFilledAmountRight).to.be.bignumber.equal(orderTakerAssetFilledAmountRight);
// Match left & right orders
- await this._exchangeWrapper.matchOrdersAsync(signedOrderLeft, signedOrderRight, takerAddress);
+ const transactionReceipt = await this._exchangeWrapper.matchOrdersAsync(signedOrderLeft, signedOrderRight, takerAddress);
const newERC20BalancesByOwner = await this._erc20Wrapper.getBalancesAsync();
const newERC721TokenIdsByOwner = await this._erc721Wrapper.getBalancesAsync();
// Calculate expected balance changes
@@ -117,6 +118,8 @@ export class MatchOrderTester {
signedOrderRight,
orderTakerAssetFilledAmountLeft,
orderTakerAssetFilledAmountRight,
+ transactionReceipt,
+ takerAddress
);
let expectedERC20BalancesByOwner: ERC20BalancesByOwner;
let expectedERC721TokenIdsByOwner: ERC721TokenIdsByOwner;
@@ -135,6 +138,7 @@ export class MatchOrderTester {
expectedERC721TokenIdsByOwner,
newERC721TokenIdsByOwner,
);
+
expect(didExpectedBalancesMatchRealBalances).to.be.true();
return [newERC20BalancesByOwner, newERC721TokenIdsByOwner];
}
@@ -150,26 +154,35 @@ export class MatchOrderTester {
signedOrderRight: SignedOrder,
orderTakerAssetFilledAmountLeft: BigNumber,
orderTakerAssetFilledAmountRight: BigNumber,
+ transactionReceipt: TransactionReceiptWithDecodedLogs,
+ takerAddress: string
): Promise<TransferAmounts> {
- let amountBoughtByLeftMaker = await this._exchangeWrapper.getTakerAssetFilledAmountAsync(
- orderHashUtils.getOrderHashHex(signedOrderLeft),
- );
- amountBoughtByLeftMaker = amountBoughtByLeftMaker.minus(orderTakerAssetFilledAmountLeft);
- const amountSoldByLeftMaker = amountBoughtByLeftMaker
- .times(signedOrderLeft.makerAssetAmount)
- .dividedToIntegerBy(signedOrderLeft.takerAssetAmount);
- const amountReceivedByRightMaker = amountBoughtByLeftMaker
- .times(signedOrderRight.takerAssetAmount)
- .dividedToIntegerBy(signedOrderRight.makerAssetAmount);
- const amountReceivedByTaker = amountSoldByLeftMaker.minus(amountReceivedByRightMaker);
- let amountBoughtByRightMaker = await this._exchangeWrapper.getTakerAssetFilledAmountAsync(
- orderHashUtils.getOrderHashHex(signedOrderRight),
- );
- amountBoughtByRightMaker = amountBoughtByRightMaker.minus(orderTakerAssetFilledAmountRight);
- const amountSoldByRightMaker = amountBoughtByRightMaker
- .times(signedOrderRight.makerAssetAmount)
- .dividedToIntegerBy(signedOrderRight.takerAssetAmount);
- const amountReceivedByLeftMaker = amountSoldByRightMaker;
+ // Parse logs
+ expect(transactionReceipt.logs.length).to.be.equal(2);
+ // First log is for left fill
+ const leftLog = ((transactionReceipt.logs[0] as any) as {args: { makerAddress: string, takerAddress: string, makerAssetFilledAmount: string, takerAssetFilledAmount: string, makerFeePaid: string, takerFeePaid: string}});
+ expect(leftLog.args.makerAddress).to.be.equal(signedOrderLeft.makerAddress);
+ expect(leftLog.args.takerAddress).to.be.equal(takerAddress);
+ const amountBoughtByLeftMaker = new BigNumber(leftLog.args.takerAssetFilledAmount);
+ const amountSoldByLeftMaker = new BigNumber(leftLog.args.makerAssetFilledAmount);
+ // Second log is for right fill
+ const rightLog = ((transactionReceipt.logs[1] as any) as {args: { makerAddress: string, takerAddress: string, makerAssetFilledAmount: string, takerAssetFilledAmount: string, makerFeePaid: string, takerFeePaid: string}});
+ expect(rightLog.args.makerAddress).to.be.equal(signedOrderRight.makerAddress);
+ expect(rightLog.args.takerAddress).to.be.equal(takerAddress);
+ const amountBoughtByRightMaker = new BigNumber(rightLog.args.takerAssetFilledAmount);
+ const amountSoldByRightMaker = new BigNumber(rightLog.args.makerAssetFilledAmount);
+ // Determine amount received by taker
+ const amountReceivedByTaker = amountSoldByLeftMaker.sub(amountBoughtByRightMaker);
+
+ const amountReceivedByLeftMaker = amountBoughtByLeftMaker;
+ const amountReceivedByRightMaker = amountBoughtByRightMaker;
+
+ console.log("Amount bought by left maker = ", JSON.stringify(amountBoughtByLeftMaker));
+ console.log("Amount sold by left maker = ", JSON.stringify(amountSoldByLeftMaker));
+ console.log("Amount bought by right maker = ", JSON.stringify(amountBoughtByRightMaker));
+ console.log("Amount sold by right maker = ", JSON.stringify(amountSoldByRightMaker));
+ console.log("Amount received by taker = ", JSON.stringify(amountReceivedByTaker));
+ //const amountReceivedByLeftMaker = amountSoldByRightMaker;
const feePaidByLeftMaker = signedOrderLeft.makerFee
.times(amountSoldByLeftMaker)
.dividedToIntegerBy(signedOrderLeft.makerAssetAmount);