aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contracts/test/ts/ether_token.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/contracts/test/ts/ether_token.ts')
-rw-r--r--packages/contracts/test/ts/ether_token.ts206
1 files changed, 103 insertions, 103 deletions
diff --git a/packages/contracts/test/ts/ether_token.ts b/packages/contracts/test/ts/ether_token.ts
index f807cdaa3..c770b4001 100644
--- a/packages/contracts/test/ts/ether_token.ts
+++ b/packages/contracts/test/ts/ether_token.ts
@@ -18,107 +18,107 @@ const expect = chai.expect;
const web3: Web3 = (global as any).web3;
contract('EtherToken', (accounts: string[]) => {
- const account = accounts[0];
- const gasPrice = ZeroEx.toBaseUnitAmount(new BigNumber(20), 9);
- let zeroEx: ZeroEx;
- let etherTokenAddress: string;
-
- before(async () => {
- etherTokenAddress = EtherToken.address;
- zeroEx = new ZeroEx(web3.currentProvider, {
- gasPrice,
- networkId: constants.TESTRPC_NETWORK_ID,
- });
- });
-
- const sendTransactionAsync = promisify<string>(web3.eth.sendTransaction);
- const getEthBalanceAsync = async (owner: string) => {
- const balanceStr = await promisify<string>(web3.eth.getBalance)(owner);
- const balance = new BigNumber(balanceStr);
- return balance;
- };
-
- describe('deposit', () => {
- it('should throw if caller attempts to deposit more Ether than caller balance', async () => {
- const initEthBalance = await getEthBalanceAsync(account);
- const ethToDeposit = initEthBalance.plus(1);
-
- return expect(zeroEx.etherToken.depositAsync(etherTokenAddress, ethToDeposit, account)).to.be.rejectedWith(
- ZeroExError.InsufficientEthBalanceForDeposit,
- );
- });
-
- it('should convert deposited Ether to wrapped Ether tokens', async () => {
- const initEthBalance = await getEthBalanceAsync(account);
- const initEthTokenBalance = await zeroEx.token.getBalanceAsync(etherTokenAddress, account);
-
- const ethToDeposit = new BigNumber(web3.toWei(1, 'ether'));
-
- const txHash = await zeroEx.etherToken.depositAsync(etherTokenAddress, ethToDeposit, account);
- const receipt = await zeroEx.awaitTransactionMinedAsync(txHash);
-
- const ethSpentOnGas = gasPrice.times(receipt.gasUsed);
- const finalEthBalance = await getEthBalanceAsync(account);
- const finalEthTokenBalance = await zeroEx.token.getBalanceAsync(etherTokenAddress, account);
-
- expect(finalEthBalance).to.be.bignumber.equal(initEthBalance.minus(ethToDeposit.plus(ethSpentOnGas)));
- expect(finalEthTokenBalance).to.be.bignumber.equal(initEthTokenBalance.plus(ethToDeposit));
- });
- });
-
- describe('withdraw', () => {
- it('should throw if caller attempts to withdraw greater than caller balance', async () => {
- const initEthTokenBalance = await zeroEx.token.getBalanceAsync(etherTokenAddress, account);
- const ethTokensToWithdraw = initEthTokenBalance.plus(1);
-
- return expect(
- zeroEx.etherToken.withdrawAsync(etherTokenAddress, ethTokensToWithdraw, account),
- ).to.be.rejectedWith(ZeroExError.InsufficientWEthBalanceForWithdrawal);
- });
-
- it('should convert ether tokens to ether with sufficient balance', async () => {
- const initEthTokenBalance = await zeroEx.token.getBalanceAsync(etherTokenAddress, account);
- const initEthBalance = await getEthBalanceAsync(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 ethSpentOnGas = gasPrice.times(receipt.gasUsed);
- const finalEthBalance = await getEthBalanceAsync(account);
- const finalEthTokenBalance = await zeroEx.token.getBalanceAsync(etherTokenAddress, account);
-
- expect(finalEthBalance).to.be.bignumber.equal(
- initEthBalance.plus(ethTokensToWithdraw.minus(ethSpentOnGas)),
- );
- expect(finalEthTokenBalance).to.be.bignumber.equal(initEthTokenBalance.minus(ethTokensToWithdraw));
- });
- });
-
- describe('fallback', () => {
- it('should convert sent ether to ether tokens', async () => {
- const initEthBalance = await getEthBalanceAsync(account);
- const initEthTokenBalance = await zeroEx.token.getBalanceAsync(etherTokenAddress, account);
-
- const ethToDeposit = ZeroEx.toBaseUnitAmount(new BigNumber(1), 18);
-
- const txHash = await sendTransactionAsync({
- from: account,
- to: etherTokenAddress,
- value: ethToDeposit,
- gasPrice,
- });
-
- const receipt = await zeroEx.awaitTransactionMinedAsync(txHash);
-
- const ethSpentOnGas = gasPrice.times(receipt.gasUsed);
- const finalEthBalance = await getEthBalanceAsync(account);
- const finalEthTokenBalance = await zeroEx.token.getBalanceAsync(etherTokenAddress, account);
-
- expect(finalEthBalance).to.be.bignumber.equal(initEthBalance.minus(ethToDeposit.plus(ethSpentOnGas)));
- expect(finalEthTokenBalance).to.be.bignumber.equal(initEthTokenBalance.plus(ethToDeposit));
- });
- });
+ const account = accounts[0];
+ const gasPrice = ZeroEx.toBaseUnitAmount(new BigNumber(20), 9);
+ let zeroEx: ZeroEx;
+ let etherTokenAddress: string;
+
+ before(async () => {
+ etherTokenAddress = EtherToken.address;
+ zeroEx = new ZeroEx(web3.currentProvider, {
+ gasPrice,
+ networkId: constants.TESTRPC_NETWORK_ID,
+ });
+ });
+
+ const sendTransactionAsync = promisify<string>(web3.eth.sendTransaction);
+ const getEthBalanceAsync = async (owner: string) => {
+ const balanceStr = await promisify<string>(web3.eth.getBalance)(owner);
+ const balance = new BigNumber(balanceStr);
+ return balance;
+ };
+
+ describe('deposit', () => {
+ it('should throw if caller attempts to deposit more Ether than caller balance', async () => {
+ const initEthBalance = await getEthBalanceAsync(account);
+ const ethToDeposit = initEthBalance.plus(1);
+
+ return expect(zeroEx.etherToken.depositAsync(etherTokenAddress, ethToDeposit, account)).to.be.rejectedWith(
+ ZeroExError.InsufficientEthBalanceForDeposit,
+ );
+ });
+
+ it('should convert deposited Ether to wrapped Ether tokens', async () => {
+ const initEthBalance = await getEthBalanceAsync(account);
+ const initEthTokenBalance = await zeroEx.token.getBalanceAsync(etherTokenAddress, account);
+
+ const ethToDeposit = new BigNumber(web3.toWei(1, 'ether'));
+
+ const txHash = await zeroEx.etherToken.depositAsync(etherTokenAddress, ethToDeposit, account);
+ const receipt = await zeroEx.awaitTransactionMinedAsync(txHash);
+
+ const ethSpentOnGas = gasPrice.times(receipt.gasUsed);
+ const finalEthBalance = await getEthBalanceAsync(account);
+ const finalEthTokenBalance = await zeroEx.token.getBalanceAsync(etherTokenAddress, account);
+
+ expect(finalEthBalance).to.be.bignumber.equal(initEthBalance.minus(ethToDeposit.plus(ethSpentOnGas)));
+ expect(finalEthTokenBalance).to.be.bignumber.equal(initEthTokenBalance.plus(ethToDeposit));
+ });
+ });
+
+ describe('withdraw', () => {
+ it('should throw if caller attempts to withdraw greater than caller balance', async () => {
+ const initEthTokenBalance = await zeroEx.token.getBalanceAsync(etherTokenAddress, account);
+ const ethTokensToWithdraw = initEthTokenBalance.plus(1);
+
+ return expect(
+ zeroEx.etherToken.withdrawAsync(etherTokenAddress, ethTokensToWithdraw, account),
+ ).to.be.rejectedWith(ZeroExError.InsufficientWEthBalanceForWithdrawal);
+ });
+
+ it('should convert ether tokens to ether with sufficient balance', async () => {
+ const initEthTokenBalance = await zeroEx.token.getBalanceAsync(etherTokenAddress, account);
+ const initEthBalance = await getEthBalanceAsync(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 ethSpentOnGas = gasPrice.times(receipt.gasUsed);
+ const finalEthBalance = await getEthBalanceAsync(account);
+ const finalEthTokenBalance = await zeroEx.token.getBalanceAsync(etherTokenAddress, account);
+
+ expect(finalEthBalance).to.be.bignumber.equal(
+ initEthBalance.plus(ethTokensToWithdraw.minus(ethSpentOnGas)),
+ );
+ expect(finalEthTokenBalance).to.be.bignumber.equal(initEthTokenBalance.minus(ethTokensToWithdraw));
+ });
+ });
+
+ describe('fallback', () => {
+ it('should convert sent ether to ether tokens', async () => {
+ const initEthBalance = await getEthBalanceAsync(account);
+ const initEthTokenBalance = await zeroEx.token.getBalanceAsync(etherTokenAddress, account);
+
+ const ethToDeposit = ZeroEx.toBaseUnitAmount(new BigNumber(1), 18);
+
+ const txHash = await sendTransactionAsync({
+ from: account,
+ to: etherTokenAddress,
+ value: ethToDeposit,
+ gasPrice,
+ });
+
+ const receipt = await zeroEx.awaitTransactionMinedAsync(txHash);
+
+ const ethSpentOnGas = gasPrice.times(receipt.gasUsed);
+ const finalEthBalance = await getEthBalanceAsync(account);
+ const finalEthTokenBalance = await zeroEx.token.getBalanceAsync(etherTokenAddress, account);
+
+ expect(finalEthBalance).to.be.bignumber.equal(initEthBalance.minus(ethToDeposit.plus(ethSpentOnGas)));
+ expect(finalEthTokenBalance).to.be.bignumber.equal(initEthTokenBalance.plus(ethToDeposit));
+ });
+ });
});