aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contracts/test/ether_token.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/contracts/test/ether_token.ts')
-rw-r--r--packages/contracts/test/ether_token.ts60
1 files changed, 36 insertions, 24 deletions
diff --git a/packages/contracts/test/ether_token.ts b/packages/contracts/test/ether_token.ts
index 418fbc45e..9b04dd187 100644
--- a/packages/contracts/test/ether_token.ts
+++ b/packages/contracts/test/ether_token.ts
@@ -1,4 +1,4 @@
-import { ContractWrappersError, ZeroEx } from '0x.js';
+import { ContractWrappers, ContractWrappersError } from '@0xproject/contract-wrappers';
import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils';
import { BigNumber, promisify } from '@0xproject/utils';
import { Web3Wrapper } from '@0xproject/web3-wrapper';
@@ -17,16 +17,23 @@ const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
describe('EtherToken', () => {
let account: string;
- const gasPrice = ZeroEx.toBaseUnitAmount(new BigNumber(20), 9);
- let zeroEx: ZeroEx;
+ const gasPrice = Web3Wrapper.toBaseUnitAmount(new BigNumber(20), 9);
+ let contractWrappers: ContractWrappers;
let etherTokenAddress: string;
+
+ before(async () => {
+ await blockchainLifecycle.startAsync();
+ });
+ after(async () => {
+ await blockchainLifecycle.revertAsync();
+ });
before(async () => {
const accounts = await web3Wrapper.getAvailableAddressesAsync();
account = accounts[0];
const etherToken = await WETH9Contract.deployFrom0xArtifactAsync(artifacts.EtherToken, provider, txDefaults);
etherTokenAddress = etherToken.address;
- zeroEx = new ZeroEx(provider, {
+ contractWrappers = new ContractWrappers(provider, {
gasPrice,
networkId: constants.TESTRPC_NETWORK_ID,
});
@@ -42,23 +49,23 @@ describe('EtherToken', () => {
const initEthBalance = await web3Wrapper.getBalanceInWeiAsync(account);
const ethToDeposit = initEthBalance.plus(1);
- return expect(zeroEx.etherToken.depositAsync(etherTokenAddress, ethToDeposit, account)).to.be.rejectedWith(
- ContractWrappersError.InsufficientEthBalanceForDeposit,
- );
+ return expect(
+ contractWrappers.etherToken.depositAsync(etherTokenAddress, ethToDeposit, account),
+ ).to.be.rejectedWith(ContractWrappersError.InsufficientEthBalanceForDeposit);
});
it('should convert deposited Ether to wrapped Ether tokens', async () => {
const initEthBalance = await web3Wrapper.getBalanceInWeiAsync(account);
- const initEthTokenBalance = await zeroEx.token.getBalanceAsync(etherTokenAddress, account);
+ const initEthTokenBalance = await contractWrappers.token.getBalanceAsync(etherTokenAddress, account);
const ethToDeposit = new BigNumber(Web3Wrapper.toWei(new BigNumber(1)));
- const txHash = await zeroEx.etherToken.depositAsync(etherTokenAddress, ethToDeposit, account);
- const receipt = await zeroEx.awaitTransactionMinedAsync(txHash);
+ const txHash = await contractWrappers.etherToken.depositAsync(etherTokenAddress, ethToDeposit, account);
+ const receipt = await web3Wrapper.awaitTransactionMinedAsync(txHash, constants.AWAIT_TRANSACTION_MINED_MS);
const ethSpentOnGas = gasPrice.times(receipt.gasUsed);
const finalEthBalance = await web3Wrapper.getBalanceInWeiAsync(account);
- const finalEthTokenBalance = await zeroEx.token.getBalanceAsync(etherTokenAddress, account);
+ const finalEthTokenBalance = await contractWrappers.token.getBalanceAsync(etherTokenAddress, account);
expect(finalEthBalance).to.be.bignumber.equal(initEthBalance.minus(ethToDeposit.plus(ethSpentOnGas)));
expect(finalEthTokenBalance).to.be.bignumber.equal(initEthTokenBalance.plus(ethToDeposit));
@@ -67,29 +74,34 @@ describe('EtherToken', () => {
describe('withdraw', () => {
it('should throw if caller attempts to withdraw greater than caller balance', async () => {
- const initEthTokenBalance = await zeroEx.token.getBalanceAsync(etherTokenAddress, account);
+ const initEthTokenBalance = await contractWrappers.token.getBalanceAsync(etherTokenAddress, account);
const ethTokensToWithdraw = initEthTokenBalance.plus(1);
return expect(
- zeroEx.etherToken.withdrawAsync(etherTokenAddress, ethTokensToWithdraw, account),
+ contractWrappers.etherToken.withdrawAsync(etherTokenAddress, ethTokensToWithdraw, account),
).to.be.rejectedWith(ContractWrappersError.InsufficientWEthBalanceForWithdrawal);
});
it('should convert ether tokens to ether with sufficient balance', async () => {
const ethToDeposit = new BigNumber(Web3Wrapper.toWei(new BigNumber(1)));
- await zeroEx.etherToken.depositAsync(etherTokenAddress, ethToDeposit, account);
- const initEthTokenBalance = await zeroEx.token.getBalanceAsync(etherTokenAddress, account);
+ await contractWrappers.etherToken.depositAsync(etherTokenAddress, ethToDeposit, account);
+ const initEthTokenBalance = await contractWrappers.token.getBalanceAsync(etherTokenAddress, account);
const initEthBalance = await web3Wrapper.getBalanceInWeiAsync(account);
const ethTokensToWithdraw = initEthTokenBalance;
expect(ethTokensToWithdraw).to.not.be.bignumber.equal(0);
- const txHash = await zeroEx.etherToken.withdrawAsync(etherTokenAddress, ethTokensToWithdraw, account, {
- gasLimit: constants.MAX_ETHERTOKEN_WITHDRAW_GAS,
- });
- const receipt = await zeroEx.awaitTransactionMinedAsync(txHash);
+ const txHash = await contractWrappers.etherToken.withdrawAsync(
+ etherTokenAddress,
+ ethTokensToWithdraw,
+ account,
+ {
+ gasLimit: constants.MAX_ETHERTOKEN_WITHDRAW_GAS,
+ },
+ );
+ const receipt = await web3Wrapper.awaitTransactionMinedAsync(txHash, constants.AWAIT_TRANSACTION_MINED_MS);
const ethSpentOnGas = gasPrice.times(receipt.gasUsed);
const finalEthBalance = await web3Wrapper.getBalanceInWeiAsync(account);
- const finalEthTokenBalance = await zeroEx.token.getBalanceAsync(etherTokenAddress, account);
+ const finalEthTokenBalance = await contractWrappers.token.getBalanceAsync(etherTokenAddress, account);
expect(finalEthBalance).to.be.bignumber.equal(
initEthBalance.plus(ethTokensToWithdraw.minus(ethSpentOnGas)),
@@ -101,9 +113,9 @@ describe('EtherToken', () => {
describe('fallback', () => {
it('should convert sent ether to ether tokens', async () => {
const initEthBalance = await web3Wrapper.getBalanceInWeiAsync(account);
- const initEthTokenBalance = await zeroEx.token.getBalanceAsync(etherTokenAddress, account);
+ const initEthTokenBalance = await contractWrappers.token.getBalanceAsync(etherTokenAddress, account);
- const ethToDeposit = ZeroEx.toBaseUnitAmount(new BigNumber(1), 18);
+ const ethToDeposit = Web3Wrapper.toBaseUnitAmount(new BigNumber(1), 18);
const txHash = await web3Wrapper.sendTransactionAsync({
from: account,
@@ -112,11 +124,11 @@ describe('EtherToken', () => {
gasPrice,
});
- const receipt = await zeroEx.awaitTransactionMinedAsync(txHash);
+ const receipt = await web3Wrapper.awaitTransactionMinedAsync(txHash, constants.AWAIT_TRANSACTION_MINED_MS);
const ethSpentOnGas = gasPrice.times(receipt.gasUsed);
const finalEthBalance = await web3Wrapper.getBalanceInWeiAsync(account);
- const finalEthTokenBalance = await zeroEx.token.getBalanceAsync(etherTokenAddress, account);
+ const finalEthTokenBalance = await contractWrappers.token.getBalanceAsync(etherTokenAddress, account);
expect(finalEthBalance).to.be.bignumber.equal(initEthBalance.minus(ethToDeposit.plus(ethSpentOnGas)));
expect(finalEthTokenBalance).to.be.bignumber.equal(initEthTokenBalance.plus(ethToDeposit));