aboutsummaryrefslogtreecommitdiffstats
path: root/packages/0x.js/test
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2017-12-20 21:01:35 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2017-12-20 21:02:25 +0800
commitd639a22cffebed137d703ad76b30f5bcb42de9a4 (patch)
tree49ae2b855043520c6b128b612dfcf54dfdd3e277 /packages/0x.js/test
parentb1f36a9024700ab948f7bd75eff24b29032e5907 (diff)
downloaddexon-sol-tools-d639a22cffebed137d703ad76b30f5bcb42de9a4.tar
dexon-sol-tools-d639a22cffebed137d703ad76b30f5bcb42de9a4.tar.gz
dexon-sol-tools-d639a22cffebed137d703ad76b30f5bcb42de9a4.tar.bz2
dexon-sol-tools-d639a22cffebed137d703ad76b30f5bcb42de9a4.tar.lz
dexon-sol-tools-d639a22cffebed137d703ad76b30f5bcb42de9a4.tar.xz
dexon-sol-tools-d639a22cffebed137d703ad76b30f5bcb42de9a4.tar.zst
dexon-sol-tools-d639a22cffebed137d703ad76b30f5bcb42de9a4.zip
Add WETH9 tests
Diffstat (limited to 'packages/0x.js/test')
-rw-r--r--packages/0x.js/test/ether_token_wrapper_test.ts58
-rw-r--r--packages/0x.js/test/utils/token_utils.ts2
2 files changed, 57 insertions, 3 deletions
diff --git a/packages/0x.js/test/ether_token_wrapper_test.ts b/packages/0x.js/test/ether_token_wrapper_test.ts
index f3feb39c6..03f5216ee 100644
--- a/packages/0x.js/test/ether_token_wrapper_test.ts
+++ b/packages/0x.js/test/ether_token_wrapper_test.ts
@@ -9,9 +9,11 @@ import {
BlockParamLiteral,
BlockRange,
DecodedLogEvent,
+ DepositContractEventArgs,
EtherTokenEvents,
Token,
TransferContractEventArgs,
+ WithdrawalContractEventArgs,
ZeroEx,
ZeroExError,
} from '../src';
@@ -48,6 +50,10 @@ describe('EtherTokenWrapper', () => {
gasPrice,
networkId: constants.TESTRPC_NETWORK_ID,
};
+ const transferAmount = new BigNumber(42);
+ const allowanceAmount = new BigNumber(42);
+ const depositAmount = new BigNumber(42);
+ const withdrawalAmount = new BigNumber(42);
before(async () => {
web3 = web3Factory.create();
zeroEx = new ZeroEx(web3.currentProvider, zeroExConfig);
@@ -132,8 +138,6 @@ describe('EtherTokenWrapper', () => {
describe('#subscribe', () => {
const indexFilterValues = {};
let etherTokenAddress: string;
- const transferAmount = new BigNumber(42);
- const allowanceAmount = new BigNumber(42);
before(() => {
const tokenUtils = new TokenUtils(tokens);
const etherToken = tokenUtils.getWethTokenOrThrow();
@@ -187,6 +191,43 @@ describe('EtherTokenWrapper', () => {
);
})().catch(done);
});
+ it('Should receive the Deposit event when ether is being deposited', (done: DoneCallback) => {
+ (async () => {
+ const callback = (err: Error, logEvent: DecodedLogEvent<DepositContractEventArgs>) => {
+ expect(logEvent).to.not.be.undefined();
+ expect(logEvent.isRemoved).to.be.false();
+ const args = logEvent.log.args;
+ expect(args._owner).to.be.equal(addressWithETH);
+ expect(args._value).to.be.bignumber.equal(depositAmount);
+ done();
+ };
+ zeroEx.etherToken.subscribe(
+ etherTokenAddress, EtherTokenEvents.Deposit, indexFilterValues, callback);
+ await zeroEx.etherToken.depositAsync(
+ etherTokenAddress, depositAmount, addressWithETH,
+ );
+ })().catch(done);
+ });
+ it('Should receive the Withdrawal event when ether is being withdrewn', (done: DoneCallback) => {
+ (async () => {
+ const callback = (err: Error, logEvent: DecodedLogEvent<WithdrawalContractEventArgs>) => {
+ expect(logEvent).to.not.be.undefined();
+ expect(logEvent.isRemoved).to.be.false();
+ const args = logEvent.log.args;
+ expect(args._owner).to.be.equal(addressWithETH);
+ expect(args._value).to.be.bignumber.equal(depositAmount);
+ done();
+ };
+ await zeroEx.etherToken.depositAsync(
+ etherTokenAddress, depositAmount, addressWithETH,
+ );
+ zeroEx.etherToken.subscribe(
+ etherTokenAddress, EtherTokenEvents.Withdrawal, indexFilterValues, callback);
+ await zeroEx.etherToken.withdrawAsync(
+ etherTokenAddress, withdrawalAmount, addressWithETH,
+ );
+ })().catch(done);
+ });
it('Outstanding subscriptions are cancelled when zeroEx.setProvider called', (done: DoneCallback) => {
(async () => {
const callbackNeverToBeCalled = (err: Error, logEvent: DecodedLogEvent<ApprovalContractEventArgs>) => {
@@ -255,6 +296,19 @@ describe('EtherTokenWrapper', () => {
expect(args._spender).to.be.equal(tokenTransferProxyAddress);
expect(args._value).to.be.bignumber.equal(zeroEx.token.UNLIMITED_ALLOWANCE_IN_BASE_UNITS);
});
+ it('should get logs with decoded args emitted by Deposit', async () => {
+ await zeroEx.etherToken.depositAsync(etherTokenAddress, depositAmount, addressWithETH);
+ const eventName = EtherTokenEvents.Deposit;
+ const indexFilterValues = {};
+ const logs = await zeroEx.etherToken.getLogsAsync<DepositContractEventArgs>(
+ etherTokenAddress, eventName, blockRange, indexFilterValues,
+ );
+ expect(logs).to.have.length(1);
+ const args = logs[0].args;
+ expect(logs[0].event).to.be.equal(eventName);
+ expect(args._owner).to.be.equal(addressWithETH);
+ expect(args._value).to.be.bignumber.equal(depositAmount);
+ });
it('should only get the logs with the correct event name', async () => {
txHash = await zeroEx.token.setUnlimitedProxyAllowanceAsync(etherTokenAddress, addressWithETH);
await zeroEx.awaitTransactionMinedAsync(txHash);
diff --git a/packages/0x.js/test/utils/token_utils.ts b/packages/0x.js/test/utils/token_utils.ts
index 7da7f466c..8774925bc 100644
--- a/packages/0x.js/test/utils/token_utils.ts
+++ b/packages/0x.js/test/utils/token_utils.ts
@@ -3,7 +3,7 @@ import * as _ from 'lodash';
import {InternalZeroExError, Token} from '../../src/types';
const PROTOCOL_TOKEN_SYMBOL = 'ZRX';
-const WETH_TOKEN_SYMBOL = 'WETH';
+const WETH_TOKEN_SYMBOL = 'WETH9';
export class TokenUtils {
private tokens: Token[];