diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-10-04 18:30:00 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-10-04 18:30:00 +0800 |
commit | 504beeb2f321c6c35cfcc3edfff1669bdebc939b (patch) | |
tree | 760abc8cf5591bda3d27e98a835d5f3ec15bf43a /test | |
parent | 9af47eb063406753456f16bf3efb916666c76d7f (diff) | |
download | dexon-0x-contracts-504beeb2f321c6c35cfcc3edfff1669bdebc939b.tar.gz dexon-0x-contracts-504beeb2f321c6c35cfcc3edfff1669bdebc939b.tar.zst dexon-0x-contracts-504beeb2f321c6c35cfcc3edfff1669bdebc939b.zip |
Add filtering by topic
Diffstat (limited to 'test')
-rw-r--r-- | test/exchange_wrapper_test.ts | 40 | ||||
-rw-r--r-- | test/token_wrapper_test.ts | 25 |
2 files changed, 57 insertions, 8 deletions
diff --git a/test/exchange_wrapper_test.ts b/test/exchange_wrapper_test.ts index ab709a446..71c5713ad 100644 --- a/test/exchange_wrapper_test.ts +++ b/test/exchange_wrapper_test.ts @@ -779,10 +779,10 @@ describe('ExchangeWrapper', () => { const fillableAmount = new BigNumber(5); const shouldThrowOnInsufficientBalanceOrAllowance = true; const subscriptionOpts: SubscriptionOpts = { - fromBlock: 0, + fromBlock: 'earliest', toBlock: 'latest', }; - const indexFilterValues = {}; + let txHash: string; before(async () => { [, makerAddress, takerAddress] = userAddresses; const [makerToken, takerToken] = tokenUtils.getNonProtocolTokens(); @@ -793,10 +793,12 @@ describe('ExchangeWrapper', () => { const signedOrder = await fillScenarios.createFillableSignedOrderAsync( makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount, ); - await zeroEx.exchange.fillOrderAsync( + txHash = await zeroEx.exchange.fillOrderAsync( signedOrder, fillableAmount, shouldThrowOnInsufficientBalanceOrAllowance, takerAddress, ); + await zeroEx.awaitTransactionMinedAsync(txHash); const eventName = ExchangeEvents.LogFill; + const indexFilterValues = {}; const logs = await zeroEx.exchange.getLogsAsync(eventName, subscriptionOpts, indexFilterValues); expect(logs).to.have.length(1); expect(logs[0].event).to.be.equal(eventName); @@ -805,12 +807,42 @@ describe('ExchangeWrapper', () => { const signedOrder = await fillScenarios.createFillableSignedOrderAsync( makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount, ); - await zeroEx.exchange.fillOrderAsync( + txHash = await zeroEx.exchange.fillOrderAsync( signedOrder, fillableAmount, shouldThrowOnInsufficientBalanceOrAllowance, takerAddress, ); + await zeroEx.awaitTransactionMinedAsync(txHash); const differentEventName = ExchangeEvents.LogCancel; + const indexFilterValues = {}; const logs = await zeroEx.exchange.getLogsAsync(differentEventName, subscriptionOpts, indexFilterValues); expect(logs).to.have.length(0); }); + it('should only get the logs with the correct indexed fields', async () => { + const signedOrder = await fillScenarios.createFillableSignedOrderAsync( + makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount, + ); + txHash = await zeroEx.exchange.fillOrderAsync( + signedOrder, fillableAmount, shouldThrowOnInsufficientBalanceOrAllowance, takerAddress, + ); + await zeroEx.awaitTransactionMinedAsync(txHash); + + const differentMakerAddress = userAddresses[2]; + const anotherSignedOrder = await fillScenarios.createFillableSignedOrderAsync( + makerTokenAddress, takerTokenAddress, differentMakerAddress, takerAddress, fillableAmount, + ); + txHash = await zeroEx.exchange.fillOrderAsync( + anotherSignedOrder, fillableAmount, shouldThrowOnInsufficientBalanceOrAllowance, takerAddress, + ); + await zeroEx.awaitTransactionMinedAsync(txHash); + + const eventName = ExchangeEvents.LogFill; + const indexFilterValues = { + maker: differentMakerAddress, + }; + const logs = await zeroEx.exchange.getLogsAsync( + eventName, subscriptionOpts, indexFilterValues, + ); + expect(logs).to.have.length(1); + expect(logs[0].args.maker).to.be.equal(differentMakerAddress); + }); }); }); diff --git a/test/token_wrapper_test.ts b/test/token_wrapper_test.ts index 7cd33057b..da020f714 100644 --- a/test/token_wrapper_test.ts +++ b/test/token_wrapper_test.ts @@ -440,19 +440,20 @@ describe('TokenWrapper', () => { let tokenAddress: string; let tokenTransferProxyAddress: string; const subscriptionOpts: SubscriptionOpts = { - fromBlock: 0, + fromBlock: 'earliest', toBlock: 'latest', }; - const indexFilterValues = {}; + let txHash: string; before(async () => { const token = tokens[0]; tokenAddress = token.address; tokenTransferProxyAddress = await zeroEx.proxy.getContractAddressAsync(); }); it('should get logs with decoded args emitted by Approval', async () => { - const txHash = await zeroEx.token.setUnlimitedProxyAllowanceAsync(tokenAddress, coinbase); + txHash = await zeroEx.token.setUnlimitedProxyAllowanceAsync(tokenAddress, coinbase); await zeroEx.awaitTransactionMinedAsync(txHash); const eventName = TokenEvents.Approval; + const indexFilterValues = {}; const logs = await zeroEx.token.getLogsAsync( tokenAddress, eventName, subscriptionOpts, indexFilterValues, ); @@ -463,13 +464,29 @@ describe('TokenWrapper', () => { expect(logs[0].args._value).to.be.bignumber.equal(zeroEx.token.UNLIMITED_ALLOWANCE_IN_BASE_UNITS); }); it('should only get the logs with the correct event name', async () => { - const txHash = await zeroEx.token.setUnlimitedProxyAllowanceAsync(tokenAddress, coinbase); + txHash = await zeroEx.token.setUnlimitedProxyAllowanceAsync(tokenAddress, coinbase); await zeroEx.awaitTransactionMinedAsync(txHash); const differentEventName = TokenEvents.Transfer; + const indexFilterValues = {}; const logs = await zeroEx.token.getLogsAsync( tokenAddress, differentEventName, subscriptionOpts, indexFilterValues, ); expect(logs).to.have.length(0); }); + it('should only get the logs with the correct indexed fields', async () => { + txHash = await zeroEx.token.setUnlimitedProxyAllowanceAsync(tokenAddress, coinbase); + await zeroEx.awaitTransactionMinedAsync(txHash); + txHash = await zeroEx.token.setUnlimitedProxyAllowanceAsync(tokenAddress, addressWithoutFunds); + await zeroEx.awaitTransactionMinedAsync(txHash); + const eventName = TokenEvents.Approval; + const indexFilterValues = { + _owner: coinbase, + }; + const logs = await zeroEx.token.getLogsAsync( + tokenAddress, eventName, subscriptionOpts, indexFilterValues, + ); + expect(logs).to.have.length(1); + expect(logs[0].args._owner).to.be.equal(coinbase); + }); }); }); |