aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorLeonid <logvinov.leon@gmail.com>2017-10-04 19:30:36 +0800
committerGitHub <noreply@github.com>2017-10-04 19:30:36 +0800
commit836d9be7fee9986c8ffa380633d873ba557511f4 (patch)
treebdbe710ada39c7619efa5087cdd4eee6256cbf33 /test
parent5d554ab88246563a8efcbde1b92e45ab926214d5 (diff)
parente5bdf60460330a24597e018f3611e7bc939c1362 (diff)
downloaddexon-sol-tools-836d9be7fee9986c8ffa380633d873ba557511f4.tar
dexon-sol-tools-836d9be7fee9986c8ffa380633d873ba557511f4.tar.gz
dexon-sol-tools-836d9be7fee9986c8ffa380633d873ba557511f4.tar.bz2
dexon-sol-tools-836d9be7fee9986c8ffa380633d873ba557511f4.tar.lz
dexon-sol-tools-836d9be7fee9986c8ffa380633d873ba557511f4.tar.xz
dexon-sol-tools-836d9be7fee9986c8ffa380633d873ba557511f4.tar.zst
dexon-sol-tools-836d9be7fee9986c8ffa380633d873ba557511f4.zip
Merge pull request #178 from 0xProject/feature/getLogs
Add zeroEx.getLogsAsync
Diffstat (limited to 'test')
-rw-r--r--test/exchange_wrapper_test.ts74
-rw-r--r--test/token_wrapper_test.ts54
-rw-r--r--test/utils/token_utils.ts4
3 files changed, 130 insertions, 2 deletions
diff --git a/test/exchange_wrapper_test.ts b/test/exchange_wrapper_test.ts
index 45a2d3907..71c5713ad 100644
--- a/test/exchange_wrapper_test.ts
+++ b/test/exchange_wrapper_test.ts
@@ -771,4 +771,78 @@ describe('ExchangeWrapper', () => {
expect(zrxAddress).to.equal(zrxToken.address);
});
});
+ describe('#getLogsAsync', () => {
+ let makerTokenAddress: string;
+ let takerTokenAddress: string;
+ let makerAddress: string;
+ let takerAddress: string;
+ const fillableAmount = new BigNumber(5);
+ const shouldThrowOnInsufficientBalanceOrAllowance = true;
+ const subscriptionOpts: SubscriptionOpts = {
+ fromBlock: 'earliest',
+ toBlock: 'latest',
+ };
+ let txHash: string;
+ before(async () => {
+ [, makerAddress, takerAddress] = userAddresses;
+ const [makerToken, takerToken] = tokenUtils.getNonProtocolTokens();
+ makerTokenAddress = makerToken.address;
+ takerTokenAddress = takerToken.address;
+ });
+ it('should get logs with decoded args emitted by LogFill', 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 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);
+ });
+ it('should only get the logs with the correct event name', 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 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 68dca0769..da020f714 100644
--- a/test/token_wrapper_test.ts
+++ b/test/token_wrapper_test.ts
@@ -14,6 +14,7 @@ import {
ContractEvent,
TransferContractEventArgs,
ApprovalContractEventArgs,
+ LogWithDecodedArgs,
} from '../src';
import {BlockchainLifecycle} from './utils/blockchain_lifecycle';
import {TokenUtils} from './utils/token_utils';
@@ -435,4 +436,57 @@ describe('TokenWrapper', () => {
})().catch(done);
});
});
+ describe('#getLogsAsync', () => {
+ let tokenAddress: string;
+ let tokenTransferProxyAddress: string;
+ const subscriptionOpts: SubscriptionOpts = {
+ fromBlock: 'earliest',
+ toBlock: 'latest',
+ };
+ 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 () => {
+ 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,
+ );
+ expect(logs).to.have.length(1);
+ expect(logs[0].event).to.be.equal(eventName);
+ expect(logs[0].args._owner).to.be.equal(coinbase);
+ expect(logs[0].args._spender).to.be.equal(tokenTransferProxyAddress);
+ 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 () => {
+ 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);
+ });
+ });
});
diff --git a/test/utils/token_utils.ts b/test/utils/token_utils.ts
index 60cf4527b..51cb9411c 100644
--- a/test/utils/token_utils.ts
+++ b/test/utils/token_utils.ts
@@ -1,5 +1,5 @@
import * as _ from 'lodash';
-import {Token, ZeroExError} from '../../src';
+import {Token, InternalZeroExError} from '../../src/types';
const PROTOCOL_TOKEN_SYMBOL = 'ZRX';
@@ -11,7 +11,7 @@ export class TokenUtils {
public getProtocolTokenOrThrow(): Token {
const zrxToken = _.find(this.tokens, {symbol: PROTOCOL_TOKEN_SYMBOL});
if (_.isUndefined(zrxToken)) {
- throw new Error(ZeroExError.ZrxNotInTokenRegistry);
+ throw new Error(InternalZeroExError.ZrxNotInTokenRegistry);
}
return zrxToken;
}