diff options
author | Brandon Millman <brandon.millman@gmail.com> | 2018-02-06 05:16:46 +0800 |
---|---|---|
committer | Brandon Millman <brandon.millman@gmail.com> | 2018-02-06 05:16:46 +0800 |
commit | 99b1f81e89e3ac929c7829552ea7ae19998524e9 (patch) | |
tree | 534161a9fa8bcf8bb5572d7ef0aa311fe9b9d116 /packages/contracts/test | |
parent | 6577d607332e2fb1a442d663e260ecb969457c36 (diff) | |
parent | 46ad7b1b38df0f302821258629ffa749e7dd00b9 (diff) | |
download | dexon-sol-tools-99b1f81e89e3ac929c7829552ea7ae19998524e9.tar dexon-sol-tools-99b1f81e89e3ac929c7829552ea7ae19998524e9.tar.gz dexon-sol-tools-99b1f81e89e3ac929c7829552ea7ae19998524e9.tar.bz2 dexon-sol-tools-99b1f81e89e3ac929c7829552ea7ae19998524e9.tar.lz dexon-sol-tools-99b1f81e89e3ac929c7829552ea7ae19998524e9.tar.xz dexon-sol-tools-99b1f81e89e3ac929c7829552ea7ae19998524e9.tar.zst dexon-sol-tools-99b1f81e89e3ac929c7829552ea7ae19998524e9.zip |
Merge branch 'development' into feature/testnet-faucets/order-dispenser
* development: (37 commits)
Add dates to CHANGELOGs
Change CHANGELOGs
Add .editorconfig
Fix a typo
Temp
Use forEach instead of map
Add PR number
Fix an exception when a signature collision happens
Fix prettier
Add regression tests
Improve the comment and fix an exception
Add missing comas
Lerna-ignore tslint and tsconfig
Update contract versions, fix tests
Rename directories
Rename previous contracts, fix imports, add nested file structure
Move all contracts into a single directory
Update import
Fix import
Get rid of suffixed contract versioning and replace it with a poor-mans package manager. Versions are stored locally, and are generated in a copy-on-write basis as required
...
Diffstat (limited to 'packages/contracts/test')
-rw-r--r-- | packages/contracts/test/exchange/core.ts | 2 | ||||
-rw-r--r-- | packages/contracts/test/unlimited_allowance_token.ts | 26 | ||||
-rw-r--r-- | packages/contracts/test/unlimited_allowance_token_v2.ts | 152 | ||||
-rw-r--r-- | packages/contracts/test/utils/deployer.ts | 2 |
4 files changed, 22 insertions, 160 deletions
diff --git a/packages/contracts/test/exchange/core.ts b/packages/contracts/test/exchange/core.ts index e9182dd1b..10816d2d6 100644 --- a/packages/contracts/test/exchange/core.ts +++ b/packages/contracts/test/exchange/core.ts @@ -678,7 +678,7 @@ describe('Exchange', () => { exWrapper.fillOrderAsync(order, taker, { shouldThrowOnInsufficientBalanceOrAllowance: false, }), - ).to.be.rejectedWith(constants.INVALID_OPCODE); + ).to.be.rejectedWith(constants.REVERT); }); it('should not change balances if an order is expired', async () => { diff --git a/packages/contracts/test/unlimited_allowance_token.ts b/packages/contracts/test/unlimited_allowance_token.ts index 7f4fef987..34d2ba33b 100644 --- a/packages/contracts/test/unlimited_allowance_token.ts +++ b/packages/contracts/test/unlimited_allowance_token.ts @@ -44,6 +44,14 @@ describe('UnlimitedAllowanceToken', () => { await blockchainLifecycle.revertAsync(); }); describe('transfer', () => { + it('should throw if owner has insufficient balance', async () => { + const ownerBalance = await zeroEx.token.getBalanceAsync(tokenAddress, owner); + const amountToTransfer = ownerBalance.plus(1); + return expect(token.transfer.call(spender, amountToTransfer, { from: owner })).to.be.rejectedWith( + constants.REVERT, + ); + }); + it('should transfer balance from sender to receiver', async () => { const receiver = spender; const initOwnerBalance = await zeroEx.token.getBalanceAsync(tokenAddress, owner); @@ -67,15 +75,18 @@ describe('UnlimitedAllowanceToken', () => { }); describe('transferFrom', () => { - it('should return false if owner has insufficient balance', async () => { + it('should throw if owner has insufficient balance', async () => { const ownerBalance = await zeroEx.token.getBalanceAsync(tokenAddress, owner); const amountToTransfer = ownerBalance.plus(1); await zeroEx.token.setAllowanceAsync(tokenAddress, owner, spender, amountToTransfer); - const didReturnTrue = await token.transferFrom.call(owner, spender, amountToTransfer, { from: spender }); - expect(didReturnTrue).to.be.false(); + return expect( + token.transferFrom.call(owner, spender, amountToTransfer, { + from: spender, + }), + ).to.be.rejectedWith(constants.REVERT); }); - it('should return false if spender has insufficient allowance', async () => { + it('should throw if spender has insufficient allowance', async () => { const ownerBalance = await zeroEx.token.getBalanceAsync(tokenAddress, owner); const amountToTransfer = ownerBalance; @@ -83,8 +94,11 @@ describe('UnlimitedAllowanceToken', () => { const spenderAllowanceIsInsufficient = spenderAllowance.cmp(amountToTransfer) < 0; expect(spenderAllowanceIsInsufficient).to.be.true(); - const didReturnTrue = await token.transferFrom.call(owner, spender, amountToTransfer, { from: spender }); - expect(didReturnTrue).to.be.false(); + return expect( + token.transferFrom.call(owner, spender, amountToTransfer, { + from: spender, + }), + ).to.be.rejectedWith(constants.REVERT); }); it('should return true on a 0 value transfer', async () => { diff --git a/packages/contracts/test/unlimited_allowance_token_v2.ts b/packages/contracts/test/unlimited_allowance_token_v2.ts deleted file mode 100644 index 440cc11ac..000000000 --- a/packages/contracts/test/unlimited_allowance_token_v2.ts +++ /dev/null @@ -1,152 +0,0 @@ -import { ZeroEx } from '0x.js'; -import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils'; -import { BigNumber } from '@0xproject/utils'; -import { Web3Wrapper } from '@0xproject/web3-wrapper'; -import * as chai from 'chai'; -import * as Web3 from 'web3'; - -import { constants } from '../util/constants'; -import { ContractName } from '../util/types'; - -import { chaiSetup } from './utils/chai_setup'; -import { deployer } from './utils/deployer'; - -chaiSetup.configure(); -const expect = chai.expect; -const web3 = web3Factory.create(); -const web3Wrapper = new Web3Wrapper(web3.currentProvider); -const blockchainLifecycle = new BlockchainLifecycle(); - -describe('UnlimitedAllowanceTokenV2', () => { - const config = { - networkId: constants.TESTRPC_NETWORK_ID, - }; - const zeroEx = new ZeroEx(web3.currentProvider, config); - let owner: string; - let spender: string; - - const MAX_MINT_VALUE = new BigNumber(100000000000000000000); - let tokenAddress: string; - let token: Web3.ContractInstance; - - before(async () => { - const accounts = await web3Wrapper.getAvailableAddressesAsync(); - owner = accounts[0]; - spender = accounts[1]; - token = await deployer.deployAsync(ContractName.DummyToken_v2); - await token.mint(MAX_MINT_VALUE, { from: owner }); - tokenAddress = token.address; - }); - beforeEach(async () => { - await blockchainLifecycle.startAsync(); - }); - afterEach(async () => { - await blockchainLifecycle.revertAsync(); - }); - describe('transfer', () => { - it('should throw if owner has insufficient balance', async () => { - const ownerBalance = await zeroEx.token.getBalanceAsync(tokenAddress, owner); - const amountToTransfer = ownerBalance.plus(1); - return expect(token.transfer.call(spender, amountToTransfer, { from: owner })).to.be.rejectedWith( - constants.REVERT, - ); - }); - - it('should transfer balance from sender to receiver', async () => { - const receiver = spender; - const initOwnerBalance = await zeroEx.token.getBalanceAsync(tokenAddress, owner); - const amountToTransfer = new BigNumber(1); - await zeroEx.token.transferAsync(tokenAddress, owner, receiver, amountToTransfer); - const finalOwnerBalance = await zeroEx.token.getBalanceAsync(tokenAddress, owner); - const finalReceiverBalance = await zeroEx.token.getBalanceAsync(tokenAddress, receiver); - - const expectedFinalOwnerBalance = initOwnerBalance.minus(amountToTransfer); - const expectedFinalReceiverBalance = amountToTransfer; - expect(finalOwnerBalance).to.be.bignumber.equal(expectedFinalOwnerBalance); - expect(finalReceiverBalance).to.be.bignumber.equal(expectedFinalReceiverBalance); - }); - - it('should return true on a 0 value transfer', async () => { - const didReturnTrue = await token.transfer.call(spender, 0, { - from: owner, - }); - expect(didReturnTrue).to.be.true(); - }); - }); - - describe('transferFrom', () => { - it('should throw if owner has insufficient balance', async () => { - const ownerBalance = await zeroEx.token.getBalanceAsync(tokenAddress, owner); - const amountToTransfer = ownerBalance.plus(1); - await zeroEx.token.setAllowanceAsync(tokenAddress, owner, spender, amountToTransfer); - return expect( - token.transferFrom.call(owner, spender, amountToTransfer, { - from: spender, - }), - ).to.be.rejectedWith(constants.REVERT); - }); - - it('should throw if spender has insufficient allowance', async () => { - const ownerBalance = await zeroEx.token.getBalanceAsync(tokenAddress, owner); - const amountToTransfer = ownerBalance; - - const spenderAllowance = await zeroEx.token.getAllowanceAsync(tokenAddress, owner, spender); - const spenderAllowanceIsInsufficient = spenderAllowance.cmp(amountToTransfer) < 0; - expect(spenderAllowanceIsInsufficient).to.be.true(); - - return expect( - token.transferFrom.call(owner, spender, amountToTransfer, { - from: spender, - }), - ).to.be.rejectedWith(constants.REVERT); - }); - - it('should return true on a 0 value transfer', async () => { - const amountToTransfer = 0; - const didReturnTrue = await token.transferFrom.call(owner, spender, amountToTransfer, { from: spender }); - expect(didReturnTrue).to.be.true(); - }); - - it('should not modify spender allowance if spender allowance is 2^256 - 1', async () => { - const initOwnerBalance = await zeroEx.token.getBalanceAsync(tokenAddress, owner); - const amountToTransfer = initOwnerBalance; - const initSpenderAllowance = zeroEx.token.UNLIMITED_ALLOWANCE_IN_BASE_UNITS; - await zeroEx.token.setAllowanceAsync(tokenAddress, owner, spender, initSpenderAllowance); - await zeroEx.token.transferFromAsync(tokenAddress, owner, spender, spender, amountToTransfer, { - gasLimit: constants.MAX_TOKEN_TRANSFERFROM_GAS, - }); - - const newSpenderAllowance = await zeroEx.token.getAllowanceAsync(tokenAddress, owner, spender); - expect(initSpenderAllowance).to.be.bignumber.equal(newSpenderAllowance); - }); - - it('should transfer the correct balances if spender has sufficient allowance', async () => { - const initOwnerBalance = await zeroEx.token.getBalanceAsync(tokenAddress, owner); - const amountToTransfer = initOwnerBalance; - const initSpenderAllowance = initOwnerBalance; - await zeroEx.token.setAllowanceAsync(tokenAddress, owner, spender, initSpenderAllowance); - await zeroEx.token.transferFromAsync(tokenAddress, owner, spender, spender, amountToTransfer, { - gasLimit: constants.MAX_TOKEN_TRANSFERFROM_GAS, - }); - - const newOwnerBalance = await zeroEx.token.getBalanceAsync(tokenAddress, owner); - const newSpenderBalance = await zeroEx.token.getBalanceAsync(tokenAddress, spender); - - expect(newOwnerBalance).to.be.bignumber.equal(0); - expect(newSpenderBalance).to.be.bignumber.equal(initOwnerBalance); - }); - - it('should modify allowance if spender has sufficient allowance less than 2^256 - 1', async () => { - const initOwnerBalance = await zeroEx.token.getBalanceAsync(tokenAddress, owner); - const amountToTransfer = initOwnerBalance; - const initSpenderAllowance = initOwnerBalance; - await zeroEx.token.setAllowanceAsync(tokenAddress, owner, spender, initSpenderAllowance); - await zeroEx.token.transferFromAsync(tokenAddress, owner, spender, spender, amountToTransfer, { - gasLimit: constants.MAX_TOKEN_TRANSFERFROM_GAS, - }); - - const newSpenderAllowance = await zeroEx.token.getAllowanceAsync(tokenAddress, owner, spender); - expect(newSpenderAllowance).to.be.bignumber.equal(0); - }); - }); -}); diff --git a/packages/contracts/test/utils/deployer.ts b/packages/contracts/test/utils/deployer.ts index 4c6eeff2b..dc41e41e2 100644 --- a/packages/contracts/test/utils/deployer.ts +++ b/packages/contracts/test/utils/deployer.ts @@ -5,7 +5,7 @@ import * as path from 'path'; import { constants } from '../../util/constants'; const deployerOpts = { - artifactsDir: `${path.resolve('build')}/artifacts`, + artifactsDir: path.resolve('artifacts'), jsonrpcPort: devConstants.RPC_PORT, networkId: constants.TESTRPC_NETWORK_ID, defaults: { |