From afa24aa122f0217b64f853ec33a8f3813cc80e1f Mon Sep 17 00:00:00 2001 From: Jacob Evans Date: Thu, 22 Nov 2018 15:40:34 +1100 Subject: chore: Work around for Ganache timestamp bug --- .../contracts/test/extensions/dutch_auction.ts | 31 ++++++++++------------ 1 file changed, 14 insertions(+), 17 deletions(-) (limited to 'packages') diff --git a/packages/contracts/test/extensions/dutch_auction.ts b/packages/contracts/test/extensions/dutch_auction.ts index 28e72858c..ae614cbd8 100644 --- a/packages/contracts/test/extensions/dutch_auction.ts +++ b/packages/contracts/test/extensions/dutch_auction.ts @@ -244,11 +244,11 @@ describe.only(ContractName.DutchAuction, () => { expect(auctionDetails.beginAmount).to.be.bignumber.equal(auctionBeginAmount); }); it('should match orders at current amount and send excess to buyer', async () => { - let auctionDetails = await dutchAuctionContract.getAuctionDetails.callAsync(sellOrder); + const auctionDetails = await dutchAuctionContract.getAuctionDetails.callAsync(sellOrder); buyOrder = await buyerOrderFactory.newSignedOrderAsync({ makerAssetAmount: auctionDetails.currentAmount.times(2), }); - const receipt = await web3Wrapper.awaitTransactionSuccessAsync( + await web3Wrapper.awaitTransactionSuccessAsync( await dutchAuctionContract.matchOrders.sendTransactionAsync( buyOrder, sellOrder, @@ -259,16 +259,14 @@ describe.only(ContractName.DutchAuction, () => { }, ), ); - auctionDetails = await dutchAuctionContract.getAuctionDetails.callAsync( - sellOrder, - {}, - parseInt(receipt.blockNumber as any, 16), - ); const newBalances = await erc20Wrapper.getBalancesAsync(); expect(newBalances[dutchAuctionContract.address][wethContract.address]).to.be.bignumber.equal( constants.ZERO_AMOUNT, ); - expect(newBalances[makerAddress][wethContract.address]).to.be.bignumber.equal( + // HACK gte used here due to a bug in ganache where the timestamp can change + // between multiple calls to the same block. Which can move the amount in our case + // ref: https://github.com/trufflesuite/ganache-core/issues/111 + expect(newBalances[makerAddress][wethContract.address]).to.be.bignumber.gte( erc20Balances[makerAddress][wethContract.address].plus(auctionDetails.currentAmount), ); expect(newBalances[takerAddress][wethContract.address]).to.be.bignumber.equal( @@ -317,7 +315,7 @@ describe.only(ContractName.DutchAuction, () => { ); await web3Wrapper.awaitTransactionSuccessAsync(txHash); const newBalances = await erc20Wrapper.getBalancesAsync(); - expect(newBalances[makerAddress][wethContract.address]).to.be.bignumber.equal( + expect(newBalances[makerAddress][wethContract.address]).to.be.bignumber.gte( erc20Balances[makerAddress][wethContract.address].plus(auctionDetails.currentAmount), ); expect(newBalances[feeRecipientAddress][zrxToken.address]).to.be.bignumber.equal( @@ -340,7 +338,7 @@ describe.only(ContractName.DutchAuction, () => { ); await web3Wrapper.awaitTransactionSuccessAsync(txHash); const newBalances = await erc20Wrapper.getBalancesAsync(); - expect(newBalances[makerAddress][wethContract.address]).to.be.bignumber.equal( + expect(newBalances[makerAddress][wethContract.address]).to.be.bignumber.gte( erc20Balances[makerAddress][wethContract.address].plus(auctionDetails.currentAmount), ); expect(newBalances[feeRecipientAddress][zrxToken.address]).to.be.bignumber.equal( @@ -434,7 +432,8 @@ describe.only(ContractName.DutchAuction, () => { takerAssetAmount: new BigNumber(1), takerAssetData: sellOrder.makerAssetData, }); - const receipt = await web3Wrapper.awaitTransactionSuccessAsync( + const auctionDetails = await dutchAuctionContract.getAuctionDetails.callAsync(sellOrder); + await web3Wrapper.awaitTransactionSuccessAsync( await dutchAuctionContract.matchOrders.sendTransactionAsync( buyOrder, sellOrder, @@ -445,13 +444,11 @@ describe.only(ContractName.DutchAuction, () => { }, ), ); - const auctionDetails = await dutchAuctionContract.getAuctionDetails.callAsync( - sellOrder, - {}, - parseInt(receipt.blockNumber as any, 16), - ); const newBalances = await erc20Wrapper.getBalancesAsync(); - expect(newBalances[makerAddress][wethContract.address]).to.be.bignumber.equal( + // HACK gte used here due to a bug in ganache where the timestamp can change + // between multiple calls to the same block. Which can move the amount in our case + // ref: https://github.com/trufflesuite/ganache-core/issues/111 + expect(newBalances[makerAddress][wethContract.address]).to.be.bignumber.gte( erc20Balances[makerAddress][wethContract.address].plus(auctionDetails.currentAmount), ); const newOwner = await erc721Token.ownerOf.callAsync(makerAssetId); -- cgit v1.2.3