aboutsummaryrefslogtreecommitdiffstats
path: root/packages/0x.js
diff options
context:
space:
mode:
Diffstat (limited to 'packages/0x.js')
-rw-r--r--packages/0x.js/src/contract_wrappers/ether_token_wrapper.ts2
-rw-r--r--packages/0x.js/test/ether_token_wrapper_test.ts58
-rw-r--r--packages/0x.js/test/utils/token_utils.ts2
3 files changed, 58 insertions, 4 deletions
diff --git a/packages/0x.js/src/contract_wrappers/ether_token_wrapper.ts b/packages/0x.js/src/contract_wrappers/ether_token_wrapper.ts
index 7b2743811..3e5be3ae4 100644
--- a/packages/0x.js/src/contract_wrappers/ether_token_wrapper.ts
+++ b/packages/0x.js/src/contract_wrappers/ether_token_wrapper.ts
@@ -121,7 +121,7 @@ export class EtherTokenWrapper extends ContractWrapper {
etherTokenAddress: string, eventName: EtherTokenEvents, indexFilterValues: IndexedFilterValues,
callback: EventCallback<ArgsType>): string {
assert.isETHAddressHex('etherTokenAddress', etherTokenAddress);
- assert.doesBelongToStringEnum('eventName', eventName, TokenEvents);
+ assert.doesBelongToStringEnum('eventName', eventName, EtherTokenEvents);
assert.doesConformToSchema('indexFilterValues', indexFilterValues, schemas.indexFilterValuesSchema);
assert.isFunction('callback', callback);
const subscriptionToken = this._subscribe<ArgsType>(
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[];