From 45df9de5b5b4ab6cfd4fda1b568f8109ec2c0371 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Fri, 2 Feb 2018 18:38:53 +0100 Subject: Assert that the balances don't change if arbitrage fails --- packages/contracts/test/tutorials/arbitrage.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'packages') diff --git a/packages/contracts/test/tutorials/arbitrage.ts b/packages/contracts/test/tutorials/arbitrage.ts index b2f1c338a..68b8f555e 100644 --- a/packages/contracts/test/tutorials/arbitrage.ts +++ b/packages/contracts/test/tutorials/arbitrage.ts @@ -22,7 +22,7 @@ const web3 = web3Factory.create(); const web3Wrapper = new Web3Wrapper(web3.currentProvider); const blockchainLifecycle = new BlockchainLifecycle(); -describe.only('Arbitrage', () => { +describe('Arbitrage', () => { let coinbase: string; let maker: string; let edMaker: string; @@ -177,13 +177,14 @@ describe.only('Arbitrage', () => { r = [order.params.r as string, edSignature.r]; s = [order.params.s as string, edSignature.s]; }); - it('1', async () => { + it('should successfully execute the arbitrage if not front-runner', async () => { const txHash = await arbitrage.makeAtomicTrade(addresses, values, v, r, s, { from: coinbase }); const res = await zeroEx.awaitTransactionMinedAsync(txHash); const postBalance = await weth.balanceOf(arbitrage.address); expect(postBalance).to.be.bignumber.equal(ZeroEx.toBaseUnitAmount(new BigNumber(2), 18)); }); - it('2', async () => { + it('should fail and revert if front-runned', async () => { + const preBalance = await weth.balanceOf(arbitrage.address); // Front-running transaction await etherDelta.trade( tokenGet, @@ -199,9 +200,11 @@ describe.only('Arbitrage', () => { ZeroEx.toBaseUnitAmount(new BigNumber(1), 18), { from: edFrontRunner }, ); - return expect(arbitrage.makeAtomicTrade(addresses, values, v, r, s, { from: coinbase })).to.be.rejectedWith( + await expect(arbitrage.makeAtomicTrade(addresses, values, v, r, s, { from: coinbase })).to.be.rejectedWith( constants.REVERT, ); + const postBalance = await weth.balanceOf(arbitrage.address); + expect(preBalance).to.be.bignumber.equal(postBalance); }); }); }); -- cgit v1.2.3