aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contracts/test/ts/ether_token_v2.ts
diff options
context:
space:
mode:
authorAmir Bandeali <abandeali1@gmail.com>2017-12-06 04:45:08 +0800
committerAmir Bandeali <abandeali1@gmail.com>2017-12-13 07:02:05 +0800
commitb58bf8259db7378b841e6695d99580027b4e2969 (patch)
treeb24f2ed8ec0e8408548731763691033cde772717 /packages/contracts/test/ts/ether_token_v2.ts
parente6862e973983d478b7683425983f18b4680dd238 (diff)
downloaddexon-0x-contracts-b58bf8259db7378b841e6695d99580027b4e2969.tar.gz
dexon-0x-contracts-b58bf8259db7378b841e6695d99580027b4e2969.tar.zst
dexon-0x-contracts-b58bf8259db7378b841e6695d99580027b4e2969.zip
Add tests for ERC20Token and EtherToken_v2
Diffstat (limited to 'packages/contracts/test/ts/ether_token_v2.ts')
-rw-r--r--packages/contracts/test/ts/ether_token_v2.ts52
1 files changed, 48 insertions, 4 deletions
diff --git a/packages/contracts/test/ts/ether_token_v2.ts b/packages/contracts/test/ts/ether_token_v2.ts
index 857371578..0c352b522 100644
--- a/packages/contracts/test/ts/ether_token_v2.ts
+++ b/packages/contracts/test/ts/ether_token_v2.ts
@@ -8,7 +8,7 @@ import {Artifacts} from '../../util/artifacts';
import {chaiSetup} from './utils/chai_setup';
-const {EtherToken} = new Artifacts(artifacts);
+const {EtherTokenV2} = new Artifacts(artifacts);
chaiSetup.configure();
const expect = chai.expect;
@@ -17,13 +17,14 @@ const expect = chai.expect;
// with type `any` to a variable of type `Web3`.
const web3: Web3 = (global as any).web3;
-contract('EtherToken', (accounts: string[]) => {
+contract('EtherTokenV2', (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;
+ beforeEach(async () => {
+ const etherToken = await EtherTokenV2.new();
+ etherTokenAddress = etherToken.address;
zeroEx = new ZeroEx(web3.currentProvider, {
gasPrice,
etherTokenContractAddress: etherTokenAddress,
@@ -62,9 +63,32 @@ contract('EtherToken', (accounts: string[]) => {
expect(finalEthBalance).to.be.bignumber.equal(initEthBalance.minus(ethToDeposit.plus(ethSpentOnGas)));
expect(finalEthTokenBalance).to.be.bignumber.equal(initEthTokenBalance.plus(ethToDeposit));
});
+
+ it('should log 1 event with correct arguments', async () => {
+ const ethToDeposit = new BigNumber(web3.toWei(1, 'ether'));
+
+ const txHash = await zeroEx.etherToken.depositAsync(ethToDeposit, account);
+ const receipt = await zeroEx.awaitTransactionMinedAsync(txHash);
+
+ const logs = receipt.logs;
+ expect(logs.length).to.equal(1);
+
+ const expectedFrom = ZeroEx.NULL_ADDRESS;
+ const expectedTo = account;
+ const expectedValue = ethToDeposit;
+ const logArgs = logs[0].args;
+ expect(logArgs._from).to.equal(expectedFrom);
+ expect(logArgs._to).to.equal(expectedTo);
+ expect(logArgs._value).to.be.bignumber.equal(ethToDeposit);
+ });
});
describe('withdraw', () => {
+ beforeEach(async () => {
+ const ethToDeposit = new BigNumber(web3.toWei(1, 'ether'));
+ await zeroEx.etherToken.depositAsync(ethToDeposit, account);
+ });
+
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);
@@ -89,6 +113,26 @@ contract('EtherToken', (accounts: string[]) => {
.equal(initEthBalance.plus(ethTokensToWithdraw.minus(ethSpentOnGas)));
expect(finalEthTokenBalance).to.be.bignumber.equal(initEthTokenBalance.minus(ethTokensToWithdraw));
});
+
+ it('should log 1 event with correct arguments', 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(ethTokensToWithdraw, account);
+ const receipt = await zeroEx.awaitTransactionMinedAsync(txHash);
+
+ const logs = receipt.logs;
+ expect(logs.length).to.equal(1);
+
+ const expectedFrom = account;
+ const expectedTo = ZeroEx.NULL_ADDRESS;
+ const expectedValue = ethTokensToWithdraw;
+ const logArgs = logs[0].args;
+ expect(logArgs._from).to.equal(expectedFrom);
+ expect(logArgs._to).to.equal(expectedTo);
+ expect(logArgs._value).to.be.bignumber.equal(ethTokensToWithdraw);
+ });
});
describe('fallback', () => {