aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2018-06-27 16:37:57 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2018-06-29 22:52:52 +0800
commit9c8701f5f69ee93f87ae0fb86618b0692ffc7443 (patch)
tree6497eb9401fe48919f7f312627cf3a172a6b91eb
parent7ac84aff0a5988b097c1a2679d3ade68ad70dde5 (diff)
downloaddexon-0x-contracts-9c8701f5f69ee93f87ae0fb86618b0692ffc7443.tar.gz
dexon-0x-contracts-9c8701f5f69ee93f87ae0fb86618b0692ffc7443.tar.zst
dexon-0x-contracts-9c8701f5f69ee93f87ae0fb86618b0692ffc7443.zip
Refactor ether token wrapper test
-rw-r--r--packages/contract-wrappers/test/ether_token_wrapper_test.ts117
1 files changed, 64 insertions, 53 deletions
diff --git a/packages/contract-wrappers/test/ether_token_wrapper_test.ts b/packages/contract-wrappers/test/ether_token_wrapper_test.ts
index b13ac72bb..1e46f05d1 100644
--- a/packages/contract-wrappers/test/ether_token_wrapper_test.ts
+++ b/packages/contract-wrappers/test/ether_token_wrapper_test.ts
@@ -6,22 +6,21 @@ import * as chai from 'chai';
import 'mocha';
import {
- ApprovalContractEventArgs,
BlockParamLiteral,
BlockRange,
ContractWrappers,
ContractWrappersError,
DecodedLogEvent,
- DepositContractEventArgs,
- EtherTokenEvents,
- Token,
- TransferContractEventArgs,
- WithdrawalContractEventArgs,
+ WETH9ApprovalEventArgs,
+ WETH9DepositEventArgs,
+ WETH9Events,
+ WETH9TransferEventArgs,
+ WETH9WithdrawalEventArgs,
} from '../src';
import { chaiSetup } from './utils/chai_setup';
import { constants } from './utils/constants';
-import { TokenUtils } from './utils/token_utils';
+import { tokenUtils } from './utils/token_utils';
import { provider, web3Wrapper } from './utils/web3_wrapper';
chaiSetup.configure();
@@ -36,7 +35,6 @@ const MAX_REASONABLE_GAS_COST_IN_WEI = 62517;
describe('EtherTokenWrapper', () => {
let contractWrappers: ContractWrappers;
- let tokens: Token[];
let userAddresses: string[];
let addressWithETH: string;
let wethContractAddress: string;
@@ -54,7 +52,6 @@ describe('EtherTokenWrapper', () => {
const withdrawalAmount = new BigNumber(42);
before(async () => {
contractWrappers = new ContractWrappers(provider, zeroExConfig);
- tokens = await contractWrappers.tokenRegistry.getTokensAsync();
userAddresses = await web3Wrapper.getAvailableAddressesAsync();
addressWithETH = userAddresses[0];
wethContractAddress = contractWrappers.etherToken.getContractAddressIfExists() as string;
@@ -85,7 +82,10 @@ describe('EtherTokenWrapper', () => {
describe('#depositAsync', () => {
it('should successfully deposit ETH and issue Wrapped ETH tokens', async () => {
const preETHBalance = await web3Wrapper.getBalanceInWeiAsync(addressWithETH);
- const preWETHBalance = await contractWrappers.token.getBalanceAsync(wethContractAddress, addressWithETH);
+ const preWETHBalance = await contractWrappers.erc20Token.getBalanceAsync(
+ wethContractAddress,
+ addressWithETH,
+ );
expect(preETHBalance).to.be.bignumber.gt(0);
expect(preWETHBalance).to.be.bignumber.equal(0);
@@ -97,7 +97,7 @@ describe('EtherTokenWrapper', () => {
await web3Wrapper.awaitTransactionSuccessAsync(txHash);
const postETHBalanceInWei = await web3Wrapper.getBalanceInWeiAsync(addressWithETH);
- const postWETHBalanceInBaseUnits = await contractWrappers.token.getBalanceAsync(
+ const postWETHBalanceInBaseUnits = await contractWrappers.erc20Token.getBalanceAsync(
wethContractAddress,
addressWithETH,
);
@@ -126,7 +126,10 @@ describe('EtherTokenWrapper', () => {
const expectedPreETHBalance = ETHBalanceInWei.minus(depositWeiAmount);
const preETHBalance = await web3Wrapper.getBalanceInWeiAsync(addressWithETH);
- const preWETHBalance = await contractWrappers.token.getBalanceAsync(wethContractAddress, addressWithETH);
+ const preWETHBalance = await contractWrappers.erc20Token.getBalanceAsync(
+ wethContractAddress,
+ addressWithETH,
+ );
let gasCost = expectedPreETHBalance.minus(preETHBalance);
expect(gasCost).to.be.bignumber.lte(MAX_REASONABLE_GAS_COST_IN_WEI);
expect(preWETHBalance).to.be.bignumber.equal(depositWeiAmount);
@@ -139,7 +142,7 @@ describe('EtherTokenWrapper', () => {
await web3Wrapper.awaitTransactionSuccessAsync(txHash);
const postETHBalance = await web3Wrapper.getBalanceInWeiAsync(addressWithETH);
- const postWETHBalanceInBaseUnits = await contractWrappers.token.getBalanceAsync(
+ const postWETHBalanceInBaseUnits = await contractWrappers.erc20Token.getBalanceAsync(
wethContractAddress,
addressWithETH,
);
@@ -150,7 +153,10 @@ describe('EtherTokenWrapper', () => {
expect(gasCost).to.be.bignumber.lte(MAX_REASONABLE_GAS_COST_IN_WEI);
});
it('should throw if user has insufficient WETH balance for withdrawal', async () => {
- const preWETHBalance = await contractWrappers.token.getBalanceAsync(wethContractAddress, addressWithETH);
+ const preWETHBalance = await contractWrappers.erc20Token.getBalanceAsync(
+ wethContractAddress,
+ addressWithETH,
+ );
expect(preWETHBalance).to.be.bignumber.equal(0);
// tslint:disable-next-line:custom-no-magic-numbers
@@ -164,10 +170,8 @@ describe('EtherTokenWrapper', () => {
describe('#subscribe', () => {
const indexFilterValues = {};
let etherTokenAddress: string;
- before(() => {
- const tokenUtils = new TokenUtils(tokens);
- const etherToken = tokenUtils.getWethTokenOrThrow();
- etherTokenAddress = etherToken.address;
+ before(async () => {
+ etherTokenAddress = tokenUtils.getWethTokenAddress();
});
afterEach(() => {
contractWrappers.etherToken.unsubscribeAll();
@@ -180,7 +184,7 @@ describe('EtherTokenWrapper', () => {
it('Should receive the Transfer event when tokens are transfered', (done: DoneCallback) => {
(async () => {
const callback = callbackErrorReporter.reportNodeCallbackErrors(done)(
- (logEvent: DecodedLogEvent<TransferContractEventArgs>) => {
+ (logEvent: DecodedLogEvent<WETH9TransferEventArgs>) => {
expect(logEvent).to.not.be.undefined();
expect(logEvent.isRemoved).to.be.false();
expect(logEvent.log.logIndex).to.be.equal(0);
@@ -195,11 +199,11 @@ describe('EtherTokenWrapper', () => {
await contractWrappers.etherToken.depositAsync(etherTokenAddress, transferAmount, addressWithETH);
contractWrappers.etherToken.subscribe(
etherTokenAddress,
- EtherTokenEvents.Transfer,
+ WETH9Events.Transfer,
indexFilterValues,
callback,
);
- await contractWrappers.token.transferAsync(
+ await contractWrappers.erc20Token.transferAsync(
etherTokenAddress,
addressWithETH,
addressWithoutFunds,
@@ -210,7 +214,7 @@ describe('EtherTokenWrapper', () => {
it('Should receive the Approval event when allowance is being set', (done: DoneCallback) => {
(async () => {
const callback = callbackErrorReporter.reportNodeCallbackErrors(done)(
- (logEvent: DecodedLogEvent<ApprovalContractEventArgs>) => {
+ (logEvent: DecodedLogEvent<WETH9ApprovalEventArgs>) => {
expect(logEvent).to.not.be.undefined();
expect(logEvent.isRemoved).to.be.false();
const args = logEvent.log.args;
@@ -221,11 +225,11 @@ describe('EtherTokenWrapper', () => {
);
contractWrappers.etherToken.subscribe(
etherTokenAddress,
- EtherTokenEvents.Approval,
+ WETH9Events.Approval,
indexFilterValues,
callback,
);
- await contractWrappers.token.setAllowanceAsync(
+ await contractWrappers.erc20Token.setAllowanceAsync(
etherTokenAddress,
addressWithETH,
addressWithoutFunds,
@@ -236,7 +240,7 @@ describe('EtherTokenWrapper', () => {
it('Should receive the Deposit event when ether is being deposited', (done: DoneCallback) => {
(async () => {
const callback = callbackErrorReporter.reportNodeCallbackErrors(done)(
- (logEvent: DecodedLogEvent<DepositContractEventArgs>) => {
+ (logEvent: DecodedLogEvent<WETH9DepositEventArgs>) => {
expect(logEvent).to.not.be.undefined();
expect(logEvent.isRemoved).to.be.false();
const args = logEvent.log.args;
@@ -246,7 +250,7 @@ describe('EtherTokenWrapper', () => {
);
contractWrappers.etherToken.subscribe(
etherTokenAddress,
- EtherTokenEvents.Deposit,
+ WETH9Events.Deposit,
indexFilterValues,
callback,
);
@@ -256,7 +260,7 @@ describe('EtherTokenWrapper', () => {
it('Should receive the Withdrawal event when ether is being withdrawn', (done: DoneCallback) => {
(async () => {
const callback = callbackErrorReporter.reportNodeCallbackErrors(done)(
- (logEvent: DecodedLogEvent<WithdrawalContractEventArgs>) => {
+ (logEvent: DecodedLogEvent<WETH9WithdrawalEventArgs>) => {
expect(logEvent).to.not.be.undefined();
expect(logEvent.isRemoved).to.be.false();
const args = logEvent.log.args;
@@ -267,7 +271,7 @@ describe('EtherTokenWrapper', () => {
await contractWrappers.etherToken.depositAsync(etherTokenAddress, depositAmount, addressWithETH);
contractWrappers.etherToken.subscribe(
etherTokenAddress,
- EtherTokenEvents.Withdrawal,
+ WETH9Events.Withdrawal,
indexFilterValues,
callback,
);
@@ -277,13 +281,13 @@ describe('EtherTokenWrapper', () => {
it('should cancel outstanding subscriptions when ZeroEx.setProvider is called', (done: DoneCallback) => {
(async () => {
const callbackNeverToBeCalled = callbackErrorReporter.reportNodeCallbackErrors(done)(
- (logEvent: DecodedLogEvent<ApprovalContractEventArgs>) => {
+ (logEvent: DecodedLogEvent<WETH9ApprovalEventArgs>) => {
done(new Error('Expected this subscription to have been cancelled'));
},
);
contractWrappers.etherToken.subscribe(
etherTokenAddress,
- EtherTokenEvents.Transfer,
+ WETH9Events.Transfer,
indexFilterValues,
callbackNeverToBeCalled,
);
@@ -292,11 +296,11 @@ describe('EtherTokenWrapper', () => {
await contractWrappers.etherToken.depositAsync(etherTokenAddress, transferAmount, addressWithETH);
contractWrappers.etherToken.subscribe(
etherTokenAddress,
- EtherTokenEvents.Transfer,
+ WETH9Events.Transfer,
indexFilterValues,
callbackToBeCalled,
);
- await contractWrappers.token.transferAsync(
+ await contractWrappers.erc20Token.transferAsync(
etherTokenAddress,
addressWithETH,
addressWithoutFunds,
@@ -307,19 +311,19 @@ describe('EtherTokenWrapper', () => {
it('Should cancel subscription when unsubscribe called', (done: DoneCallback) => {
(async () => {
const callbackNeverToBeCalled = callbackErrorReporter.reportNodeCallbackErrors(done)(
- (logEvent: DecodedLogEvent<ApprovalContractEventArgs>) => {
+ (logEvent: DecodedLogEvent<WETH9ApprovalEventArgs>) => {
done(new Error('Expected this subscription to have been cancelled'));
},
);
await contractWrappers.etherToken.depositAsync(etherTokenAddress, transferAmount, addressWithETH);
const subscriptionToken = contractWrappers.etherToken.subscribe(
etherTokenAddress,
- EtherTokenEvents.Transfer,
+ WETH9Events.Transfer,
indexFilterValues,
callbackNeverToBeCalled,
);
contractWrappers.etherToken.unsubscribe(subscriptionToken);
- await contractWrappers.token.transferAsync(
+ await contractWrappers.erc20Token.transferAsync(
etherTokenAddress,
addressWithETH,
addressWithoutFunds,
@@ -331,7 +335,7 @@ describe('EtherTokenWrapper', () => {
});
describe('#getLogsAsync', () => {
let etherTokenAddress: string;
- let tokenTransferProxyAddress: string;
+ let erc20ProxyAddress: string;
const blockRange: BlockRange = {
fromBlock: 0,
toBlock: BlockParamLiteral.Latest,
@@ -339,17 +343,18 @@ describe('EtherTokenWrapper', () => {
let txHash: string;
before(() => {
addressWithETH = userAddresses[0];
- const tokenUtils = new TokenUtils(tokens);
- const etherToken = tokenUtils.getWethTokenOrThrow();
- etherTokenAddress = etherToken.address;
- tokenTransferProxyAddress = contractWrappers.proxy.getContractAddress();
+ etherTokenAddress = tokenUtils.getWethTokenAddress();
+ erc20ProxyAddress = contractWrappers.erc20Proxy.getContractAddress();
});
it('should get logs with decoded args emitted by Approval', async () => {
- txHash = await contractWrappers.token.setUnlimitedProxyAllowanceAsync(etherTokenAddress, addressWithETH);
+ txHash = await contractWrappers.erc20Token.setUnlimitedProxyAllowanceAsync(
+ etherTokenAddress,
+ addressWithETH,
+ );
await web3Wrapper.awaitTransactionSuccessAsync(txHash);
- const eventName = EtherTokenEvents.Approval;
+ const eventName = WETH9Events.Approval;
const indexFilterValues = {};
- const logs = await contractWrappers.etherToken.getLogsAsync<ApprovalContractEventArgs>(
+ const logs = await contractWrappers.etherToken.getLogsAsync<WETH9ApprovalEventArgs>(
etherTokenAddress,
eventName,
blockRange,
@@ -359,14 +364,14 @@ describe('EtherTokenWrapper', () => {
const args = logs[0].args;
expect(logs[0].event).to.be.equal(eventName);
expect(args._owner).to.be.equal(addressWithETH);
- expect(args._spender).to.be.equal(tokenTransferProxyAddress);
- expect(args._value).to.be.bignumber.equal(contractWrappers.token.UNLIMITED_ALLOWANCE_IN_BASE_UNITS);
+ expect(args._spender).to.be.equal(erc20ProxyAddress);
+ expect(args._value).to.be.bignumber.equal(contractWrappers.erc20Token.UNLIMITED_ALLOWANCE_IN_BASE_UNITS);
});
it('should get logs with decoded args emitted by Deposit', async () => {
await contractWrappers.etherToken.depositAsync(etherTokenAddress, depositAmount, addressWithETH);
- const eventName = EtherTokenEvents.Deposit;
+ const eventName = WETH9Events.Deposit;
const indexFilterValues = {};
- const logs = await contractWrappers.etherToken.getLogsAsync<DepositContractEventArgs>(
+ const logs = await contractWrappers.etherToken.getLogsAsync<WETH9DepositEventArgs>(
etherTokenAddress,
eventName,
blockRange,
@@ -379,9 +384,12 @@ describe('EtherTokenWrapper', () => {
expect(args._value).to.be.bignumber.equal(depositAmount);
});
it('should only get the logs with the correct event name', async () => {
- txHash = await contractWrappers.token.setUnlimitedProxyAllowanceAsync(etherTokenAddress, addressWithETH);
+ txHash = await contractWrappers.erc20Token.setUnlimitedProxyAllowanceAsync(
+ etherTokenAddress,
+ addressWithETH,
+ );
await web3Wrapper.awaitTransactionSuccessAsync(txHash);
- const differentEventName = EtherTokenEvents.Transfer;
+ const differentEventName = WETH9Events.Transfer;
const indexFilterValues = {};
const logs = await contractWrappers.etherToken.getLogsAsync(
etherTokenAddress,
@@ -392,18 +400,21 @@ describe('EtherTokenWrapper', () => {
expect(logs).to.have.length(0);
});
it('should only get the logs with the correct indexed fields', async () => {
- txHash = await contractWrappers.token.setUnlimitedProxyAllowanceAsync(etherTokenAddress, addressWithETH);
+ txHash = await contractWrappers.erc20Token.setUnlimitedProxyAllowanceAsync(
+ etherTokenAddress,
+ addressWithETH,
+ );
await web3Wrapper.awaitTransactionSuccessAsync(txHash);
- txHash = await contractWrappers.token.setUnlimitedProxyAllowanceAsync(
+ txHash = await contractWrappers.erc20Token.setUnlimitedProxyAllowanceAsync(
etherTokenAddress,
addressWithoutFunds,
);
await web3Wrapper.awaitTransactionSuccessAsync(txHash);
- const eventName = EtherTokenEvents.Approval;
+ const eventName = WETH9Events.Approval;
const indexFilterValues = {
_owner: addressWithETH,
};
- const logs = await contractWrappers.etherToken.getLogsAsync<ApprovalContractEventArgs>(
+ const logs = await contractWrappers.etherToken.getLogsAsync<WETH9ApprovalEventArgs>(
etherTokenAddress,
eventName,
blockRange,