From 81c48872415998e53ad653aabf183e18257ec327 Mon Sep 17 00:00:00 2001 From: Alex Browne Date: Mon, 1 Oct 2018 16:44:13 -0700 Subject: Move generated contract wrappers and artifacts into contracts package --- packages/contracts/test/tokens/erc721_token.ts | 8 +- packages/contracts/test/tokens/ether_token.ts | 138 --------------------- .../test/tokens/unlimited_allowance_token.ts | 4 +- packages/contracts/test/tokens/weth9.ts | 138 +++++++++++++++++++++ packages/contracts/test/tokens/zrx_token.ts | 6 +- 5 files changed, 147 insertions(+), 147 deletions(-) delete mode 100644 packages/contracts/test/tokens/ether_token.ts create mode 100644 packages/contracts/test/tokens/weth9.ts (limited to 'packages/contracts/test/tokens') diff --git a/packages/contracts/test/tokens/erc721_token.ts b/packages/contracts/test/tokens/erc721_token.ts index e61fd7d51..fe10e060a 100644 --- a/packages/contracts/test/tokens/erc721_token.ts +++ b/packages/contracts/test/tokens/erc721_token.ts @@ -7,13 +7,13 @@ import { LogWithDecodedArgs } from 'ethereum-types'; import { DummyERC721ReceiverContract, DummyERC721ReceiverTokenReceivedEventArgs, -} from '../../generated_contract_wrappers/dummy_erc721_receiver'; +} from '../../generated-wrappers/dummy_erc721_receiver'; import { DummyERC721TokenContract, DummyERC721TokenTransferEventArgs, -} from '../../generated_contract_wrappers/dummy_erc721_token'; -import { InvalidERC721ReceiverContract } from '../../generated_contract_wrappers/invalid_erc721_receiver'; -import { artifacts } from '../utils/artifacts'; +} from '../../generated-wrappers/dummy_erc721_token'; +import { InvalidERC721ReceiverContract } from '../../generated-wrappers/invalid_erc721_receiver'; +import { artifacts } from '../../src/artifacts'; import { expectTransactionFailedAsync, expectTransactionFailedWithoutReasonAsync } from '../utils/assertions'; import { chaiSetup } from '../utils/chai_setup'; import { constants } from '../utils/constants'; diff --git a/packages/contracts/test/tokens/ether_token.ts b/packages/contracts/test/tokens/ether_token.ts deleted file mode 100644 index a104fc915..000000000 --- a/packages/contracts/test/tokens/ether_token.ts +++ /dev/null @@ -1,138 +0,0 @@ -import { BlockchainLifecycle } from '@0xproject/dev-utils'; -import { BigNumber } from '@0xproject/utils'; -import { Web3Wrapper } from '@0xproject/web3-wrapper'; -import * as chai from 'chai'; - -import { WETH9Contract } from '../../generated_contract_wrappers/weth9'; -import { artifacts } from '../utils/artifacts'; -import { expectInsufficientFundsAsync, expectTransactionFailedWithoutReasonAsync } from '../utils/assertions'; -import { chaiSetup } from '../utils/chai_setup'; -import { constants } from '../utils/constants'; -import { provider, txDefaults, web3Wrapper } from '../utils/web3_wrapper'; - -chaiSetup.configure(); -const expect = chai.expect; -const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper); - -describe('EtherToken', () => { - let account: string; - const gasPrice = Web3Wrapper.toBaseUnitAmount(new BigNumber(20), 9); - let etherToken: WETH9Contract; - - before(async () => { - await blockchainLifecycle.startAsync(); - }); - after(async () => { - await blockchainLifecycle.revertAsync(); - }); - before(async () => { - const accounts = await web3Wrapper.getAvailableAddressesAsync(); - account = accounts[0]; - - etherToken = await WETH9Contract.deployFrom0xArtifactAsync(artifacts.EtherToken, provider, { - gasPrice, - ...txDefaults, - }); - }); - beforeEach(async () => { - await blockchainLifecycle.startAsync(); - }); - afterEach(async () => { - await blockchainLifecycle.revertAsync(); - }); - describe('deposit', () => { - it('should throw if caller attempts to deposit more Ether than caller balance', async () => { - const initEthBalance = await web3Wrapper.getBalanceInWeiAsync(account); - const ethToDeposit = initEthBalance.plus(1); - - return expectInsufficientFundsAsync(etherToken.deposit.sendTransactionAsync({ value: ethToDeposit })); - }); - - it('should convert deposited Ether to wrapped Ether tokens', async () => { - const initEthBalance = await web3Wrapper.getBalanceInWeiAsync(account); - const initEthTokenBalance = await etherToken.balanceOf.callAsync(account); - - const ethToDeposit = new BigNumber(Web3Wrapper.toWei(new BigNumber(1))); - - const txHash = await etherToken.deposit.sendTransactionAsync({ value: ethToDeposit }); - const receipt = await web3Wrapper.awaitTransactionSuccessAsync( - txHash, - constants.AWAIT_TRANSACTION_MINED_MS, - ); - - const ethSpentOnGas = gasPrice.times(receipt.gasUsed); - const finalEthBalance = await web3Wrapper.getBalanceInWeiAsync(account); - const finalEthTokenBalance = await etherToken.balanceOf.callAsync(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 etherToken.balanceOf.callAsync(account); - const ethTokensToWithdraw = initEthTokenBalance.plus(1); - - return expectTransactionFailedWithoutReasonAsync( - etherToken.withdraw.sendTransactionAsync(ethTokensToWithdraw), - ); - }); - - it('should convert ether tokens to ether with sufficient balance', async () => { - const ethToDeposit = new BigNumber(Web3Wrapper.toWei(new BigNumber(1))); - await web3Wrapper.awaitTransactionSuccessAsync( - await etherToken.deposit.sendTransactionAsync({ value: ethToDeposit }), - constants.AWAIT_TRANSACTION_MINED_MS, - ); - const initEthTokenBalance = await etherToken.balanceOf.callAsync(account); - const initEthBalance = await web3Wrapper.getBalanceInWeiAsync(account); - const ethTokensToWithdraw = initEthTokenBalance; - expect(ethTokensToWithdraw).to.not.be.bignumber.equal(0); - const txHash = await etherToken.withdraw.sendTransactionAsync(ethTokensToWithdraw, { - gas: constants.MAX_ETHERTOKEN_WITHDRAW_GAS, - }); - const receipt = await web3Wrapper.awaitTransactionSuccessAsync( - txHash, - constants.AWAIT_TRANSACTION_MINED_MS, - ); - - const ethSpentOnGas = gasPrice.times(receipt.gasUsed); - const finalEthBalance = await web3Wrapper.getBalanceInWeiAsync(account); - const finalEthTokenBalance = await etherToken.balanceOf.callAsync(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 web3Wrapper.getBalanceInWeiAsync(account); - const initEthTokenBalance = await etherToken.balanceOf.callAsync(account); - - const ethToDeposit = Web3Wrapper.toBaseUnitAmount(new BigNumber(1), 18); - - const txHash = await web3Wrapper.sendTransactionAsync({ - from: account, - to: etherToken.address, - value: ethToDeposit, - gasPrice, - }); - - const receipt = await web3Wrapper.awaitTransactionSuccessAsync( - txHash, - constants.AWAIT_TRANSACTION_MINED_MS, - ); - - const ethSpentOnGas = gasPrice.times(receipt.gasUsed); - const finalEthBalance = await web3Wrapper.getBalanceInWeiAsync(account); - const finalEthTokenBalance = await etherToken.balanceOf.callAsync(account); - - expect(finalEthBalance).to.be.bignumber.equal(initEthBalance.minus(ethToDeposit.plus(ethSpentOnGas))); - expect(finalEthTokenBalance).to.be.bignumber.equal(initEthTokenBalance.plus(ethToDeposit)); - }); - }); -}); diff --git a/packages/contracts/test/tokens/unlimited_allowance_token.ts b/packages/contracts/test/tokens/unlimited_allowance_token.ts index 63680fe9b..ec00e43ab 100644 --- a/packages/contracts/test/tokens/unlimited_allowance_token.ts +++ b/packages/contracts/test/tokens/unlimited_allowance_token.ts @@ -3,8 +3,8 @@ import { RevertReason } from '@0xproject/types'; import { BigNumber } from '@0xproject/utils'; import * as chai from 'chai'; -import { DummyERC20TokenContract } from '../../generated_contract_wrappers/dummy_erc20_token'; -import { artifacts } from '../utils/artifacts'; +import { DummyERC20TokenContract } from '../../generated-wrappers/dummy_erc20_token'; +import { artifacts } from '../../src/artifacts'; import { expectContractCallFailedAsync } from '../utils/assertions'; import { chaiSetup } from '../utils/chai_setup'; import { constants } from '../utils/constants'; diff --git a/packages/contracts/test/tokens/weth9.ts b/packages/contracts/test/tokens/weth9.ts new file mode 100644 index 000000000..25463ac62 --- /dev/null +++ b/packages/contracts/test/tokens/weth9.ts @@ -0,0 +1,138 @@ +import { BlockchainLifecycle } from '@0xproject/dev-utils'; +import { BigNumber } from '@0xproject/utils'; +import { Web3Wrapper } from '@0xproject/web3-wrapper'; +import * as chai from 'chai'; + +import { WETH9Contract } from '../../generated-wrappers/weth9'; +import { artifacts } from '../../src/artifacts'; +import { expectInsufficientFundsAsync, expectTransactionFailedWithoutReasonAsync } from '../utils/assertions'; +import { chaiSetup } from '../utils/chai_setup'; +import { constants } from '../utils/constants'; +import { provider, txDefaults, web3Wrapper } from '../utils/web3_wrapper'; + +chaiSetup.configure(); +const expect = chai.expect; +const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper); + +describe('EtherToken', () => { + let account: string; + const gasPrice = Web3Wrapper.toBaseUnitAmount(new BigNumber(20), 9); + let etherToken: WETH9Contract; + + before(async () => { + await blockchainLifecycle.startAsync(); + }); + after(async () => { + await blockchainLifecycle.revertAsync(); + }); + before(async () => { + const accounts = await web3Wrapper.getAvailableAddressesAsync(); + account = accounts[0]; + + etherToken = await WETH9Contract.deployFrom0xArtifactAsync(artifacts.WETH9, provider, { + gasPrice, + ...txDefaults, + }); + }); + beforeEach(async () => { + await blockchainLifecycle.startAsync(); + }); + afterEach(async () => { + await blockchainLifecycle.revertAsync(); + }); + describe('deposit', () => { + it('should throw if caller attempts to deposit more Ether than caller balance', async () => { + const initEthBalance = await web3Wrapper.getBalanceInWeiAsync(account); + const ethToDeposit = initEthBalance.plus(1); + + return expectInsufficientFundsAsync(etherToken.deposit.sendTransactionAsync({ value: ethToDeposit })); + }); + + it('should convert deposited Ether to wrapped Ether tokens', async () => { + const initEthBalance = await web3Wrapper.getBalanceInWeiAsync(account); + const initEthTokenBalance = await etherToken.balanceOf.callAsync(account); + + const ethToDeposit = new BigNumber(Web3Wrapper.toWei(new BigNumber(1))); + + const txHash = await etherToken.deposit.sendTransactionAsync({ value: ethToDeposit }); + const receipt = await web3Wrapper.awaitTransactionSuccessAsync( + txHash, + constants.AWAIT_TRANSACTION_MINED_MS, + ); + + const ethSpentOnGas = gasPrice.times(receipt.gasUsed); + const finalEthBalance = await web3Wrapper.getBalanceInWeiAsync(account); + const finalEthTokenBalance = await etherToken.balanceOf.callAsync(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 etherToken.balanceOf.callAsync(account); + const ethTokensToWithdraw = initEthTokenBalance.plus(1); + + return expectTransactionFailedWithoutReasonAsync( + etherToken.withdraw.sendTransactionAsync(ethTokensToWithdraw), + ); + }); + + it('should convert ether tokens to ether with sufficient balance', async () => { + const ethToDeposit = new BigNumber(Web3Wrapper.toWei(new BigNumber(1))); + await web3Wrapper.awaitTransactionSuccessAsync( + await etherToken.deposit.sendTransactionAsync({ value: ethToDeposit }), + constants.AWAIT_TRANSACTION_MINED_MS, + ); + const initEthTokenBalance = await etherToken.balanceOf.callAsync(account); + const initEthBalance = await web3Wrapper.getBalanceInWeiAsync(account); + const ethTokensToWithdraw = initEthTokenBalance; + expect(ethTokensToWithdraw).to.not.be.bignumber.equal(0); + const txHash = await etherToken.withdraw.sendTransactionAsync(ethTokensToWithdraw, { + gas: constants.MAX_ETHERTOKEN_WITHDRAW_GAS, + }); + const receipt = await web3Wrapper.awaitTransactionSuccessAsync( + txHash, + constants.AWAIT_TRANSACTION_MINED_MS, + ); + + const ethSpentOnGas = gasPrice.times(receipt.gasUsed); + const finalEthBalance = await web3Wrapper.getBalanceInWeiAsync(account); + const finalEthTokenBalance = await etherToken.balanceOf.callAsync(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 web3Wrapper.getBalanceInWeiAsync(account); + const initEthTokenBalance = await etherToken.balanceOf.callAsync(account); + + const ethToDeposit = Web3Wrapper.toBaseUnitAmount(new BigNumber(1), 18); + + const txHash = await web3Wrapper.sendTransactionAsync({ + from: account, + to: etherToken.address, + value: ethToDeposit, + gasPrice, + }); + + const receipt = await web3Wrapper.awaitTransactionSuccessAsync( + txHash, + constants.AWAIT_TRANSACTION_MINED_MS, + ); + + const ethSpentOnGas = gasPrice.times(receipt.gasUsed); + const finalEthBalance = await web3Wrapper.getBalanceInWeiAsync(account); + const finalEthTokenBalance = await etherToken.balanceOf.callAsync(account); + + expect(finalEthBalance).to.be.bignumber.equal(initEthBalance.minus(ethToDeposit.plus(ethSpentOnGas))); + expect(finalEthTokenBalance).to.be.bignumber.equal(initEthTokenBalance.plus(ethToDeposit)); + }); + }); +}); diff --git a/packages/contracts/test/tokens/zrx_token.ts b/packages/contracts/test/tokens/zrx_token.ts index a0d77c924..8881aca77 100644 --- a/packages/contracts/test/tokens/zrx_token.ts +++ b/packages/contracts/test/tokens/zrx_token.ts @@ -3,8 +3,8 @@ import { BigNumber } from '@0xproject/utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; import * as chai from 'chai'; -import { ZRXTokenContract } from '../../generated_contract_wrappers/zrx_token'; -import { artifacts } from '../utils/artifacts'; +import { ZRXTokenContract } from '../../generated-wrappers/zrx_token'; +import { artifacts } from '../../src/artifacts'; import { chaiSetup } from '../utils/chai_setup'; import { constants } from '../utils/constants'; import { provider, txDefaults, web3Wrapper } from '../utils/web3_wrapper'; @@ -29,7 +29,7 @@ describe('ZRXToken', () => { const accounts = await web3Wrapper.getAvailableAddressesAsync(); owner = accounts[0]; spender = accounts[1]; - zrxToken = await ZRXTokenContract.deployFrom0xArtifactAsync(artifacts.ZRX, provider, txDefaults); + zrxToken = await ZRXTokenContract.deployFrom0xArtifactAsync(artifacts.ZRXToken, provider, txDefaults); MAX_UINT = constants.UNLIMITED_ALLOWANCE_IN_BASE_UNITS; }); beforeEach(async () => { -- cgit v1.2.3