aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contracts/test/asset_proxy_dispatcher
diff options
context:
space:
mode:
authorAmir Bandeali <abandeali1@gmail.com>2018-04-23 06:18:55 +0800
committerAmir Bandeali <abandeali1@gmail.com>2018-04-24 00:57:13 +0800
commitafb02b8bd16758f00d630c9ce6cf3bbc49ab307d (patch)
treefd7a80ae1451818d9794e21d265e84ed793720c8 /packages/contracts/test/asset_proxy_dispatcher
parent48b44342ab1642a78d0485e111019acfdbbfdfd5 (diff)
downloaddexon-sol-tools-afb02b8bd16758f00d630c9ce6cf3bbc49ab307d.tar.gz
dexon-sol-tools-afb02b8bd16758f00d630c9ce6cf3bbc49ab307d.tar.zst
dexon-sol-tools-afb02b8bd16758f00d630c9ce6cf3bbc49ab307d.zip
Fix and cleanup tests
Diffstat (limited to 'packages/contracts/test/asset_proxy_dispatcher')
-rw-r--r--packages/contracts/test/asset_proxy_dispatcher/dispatcher.ts66
-rw-r--r--packages/contracts/test/asset_proxy_dispatcher/proxies.ts119
2 files changed, 80 insertions, 105 deletions
diff --git a/packages/contracts/test/asset_proxy_dispatcher/dispatcher.ts b/packages/contracts/test/asset_proxy_dispatcher/dispatcher.ts
index 5cbe11e53..b5630d807 100644
--- a/packages/contracts/test/asset_proxy_dispatcher/dispatcher.ts
+++ b/packages/contracts/test/asset_proxy_dispatcher/dispatcher.ts
@@ -1,18 +1,17 @@
-import { LogWithDecodedArgs, TransactionReceiptWithDecodedLogs, ZeroEx } from '0x.js';
-import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils';
+import { ZeroEx } from '0x.js';
+import { BlockchainLifecycle } 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 { AssetProxyDispatcherContract } from '../../src/contract_wrappers/generated/asset_proxy_dispatcher';
import { DummyERC20TokenContract } from '../../src/contract_wrappers/generated/dummy_e_r_c20_token';
-import { DummyERC721TokenContract } from '../../src/contract_wrappers/generated/dummy_e_r_c721_token';
import { ERC20ProxyContract } from '../../src/contract_wrappers/generated/e_r_c20_proxy';
import { ERC721ProxyContract } from '../../src/contract_wrappers/generated/e_r_c721_proxy';
import { assetProxyUtils } from '../../src/utils/asset_proxy_utils';
-import { Balances } from '../../src/utils/balances';
import { constants } from '../../src/utils/constants';
+import { ERC20Wrapper } from '../../src/utils/erc20_wrapper';
+import { ERC721Wrapper } from '../../src/utils/erc721_wrapper';
import { AssetProxyId, ContractName } from '../../src/utils/types';
import { chaiSetup } from '../utils/chai_setup';
import { deployer } from '../utils/deployer';
@@ -27,25 +26,32 @@ describe('AssetProxyDispatcher', () => {
let notOwner: string;
let notAuthorized: string;
let exchangeAddress: string;
- let tokenOwner: string;
let makerAddress: string;
let takerAddress: string;
+
let zrx: DummyERC20TokenContract;
- let dmyBalances: Balances;
- let assetProxyDispatcher: AssetProxyDispatcherContract;
let erc20Proxy: ERC20ProxyContract;
let erc721Proxy: ERC721ProxyContract;
- const INITIAL_BALANCE = new BigNumber(10000);
+ let assetProxyDispatcher: AssetProxyDispatcherContract;
+
+ let erc20Wrapper: ERC20Wrapper;
+ let erc721Wrapper: ERC721Wrapper;
before(async () => {
// Setup accounts & addresses
const accounts = await web3Wrapper.getAvailableAddressesAsync();
- owner = tokenOwner = accounts[0];
- notOwner = notAuthorized = accounts[1];
- exchangeAddress = accounts[2];
- makerAddress = accounts[3];
- takerAddress = accounts[4];
- // Deploy Asset Proxy Dispatcher
+ const usedAddresses = ([owner, notOwner, exchangeAddress, makerAddress, takerAddress] = accounts);
+ notAuthorized = notOwner;
+
+ erc20Wrapper = new ERC20Wrapper(deployer, provider, usedAddresses, owner);
+ erc721Wrapper = new ERC721Wrapper(deployer, provider, usedAddresses, owner);
+
+ [zrx] = await erc20Wrapper.deployDummyERC20TokensAsync();
+ erc20Proxy = await erc20Wrapper.deployERC20ProxyAsync();
+ await erc20Wrapper.setBalancesAndAllowancesAsync();
+
+ erc721Proxy = await erc721Wrapper.deployERC721ProxyAsync();
+
const assetProxyDispatcherInstance = await deployer.deployAsync(ContractName.AssetProxyDispatcher);
assetProxyDispatcher = new AssetProxyDispatcherContract(
assetProxyDispatcherInstance.abi,
@@ -55,30 +61,12 @@ describe('AssetProxyDispatcher', () => {
await assetProxyDispatcher.addAuthorizedAddress.sendTransactionAsync(exchangeAddress, {
from: owner,
});
- // Deploy ERC20 Proxy
- const erc20ProxyInstance = await deployer.deployAsync(ContractName.ERC20Proxy);
- erc20Proxy = new ERC20ProxyContract(erc20ProxyInstance.abi, erc20ProxyInstance.address, provider);
await erc20Proxy.addAuthorizedAddress.sendTransactionAsync(assetProxyDispatcher.address, {
from: owner,
});
- // Deploy ERC721 Proxy
- const erc721ProxyInstance = await deployer.deployAsync(ContractName.ERC721Proxy);
- erc721Proxy = new ERC721ProxyContract(erc721ProxyInstance.abi, erc721ProxyInstance.address, provider);
await erc721Proxy.addAuthorizedAddress.sendTransactionAsync(assetProxyDispatcher.address, {
from: owner,
});
- // Deploy zrx and set initial balances
- const zrxInstance = await deployer.deployAsync(ContractName.DummyERC20Token, constants.DUMMY_TOKEN_ARGS);
- zrx = new DummyERC20TokenContract(zrxInstance.abi, zrxInstance.address, provider);
- await zrx.setBalance.sendTransactionAsync(makerAddress, INITIAL_BALANCE, { from: tokenOwner });
- await zrx.setBalance.sendTransactionAsync(takerAddress, INITIAL_BALANCE, { from: tokenOwner });
- dmyBalances = new Balances([zrx], [makerAddress, takerAddress]);
- await zrx.approve.sendTransactionAsync(erc20Proxy.address, INITIAL_BALANCE, {
- from: takerAddress,
- });
- await zrx.approve.sendTransactionAsync(erc20Proxy.address, INITIAL_BALANCE, {
- from: makerAddress,
- });
});
beforeEach(async () => {
await blockchainLifecycle.startAsync();
@@ -244,7 +232,7 @@ describe('AssetProxyDispatcher', () => {
// Construct metadata for ERC20 proxy
const encodedProxyMetadata = assetProxyUtils.encodeERC20ProxyData(zrx.address);
// Perform a transfer from makerAddress to takerAddress
- const balances = await dmyBalances.getAsync();
+ const erc20Balances = await erc20Wrapper.getBalancesAsync();
const amount = new BigNumber(10);
await assetProxyDispatcher.transferFrom.sendTransactionAsync(
encodedProxyMetadata,
@@ -254,12 +242,12 @@ describe('AssetProxyDispatcher', () => {
{ from: exchangeAddress },
);
// Verify transfer was successful
- const newBalances = await dmyBalances.getAsync();
+ const newBalances = await erc20Wrapper.getBalancesAsync();
expect(newBalances[makerAddress][zrx.address]).to.be.bignumber.equal(
- balances[makerAddress][zrx.address].minus(amount),
+ erc20Balances[makerAddress][zrx.address].minus(amount),
);
expect(newBalances[takerAddress][zrx.address]).to.be.bignumber.equal(
- balances[takerAddress][zrx.address].add(amount),
+ erc20Balances[takerAddress][zrx.address].add(amount),
);
});
@@ -267,7 +255,7 @@ describe('AssetProxyDispatcher', () => {
// Construct metadata for ERC20 proxy
const encodedProxyMetadata = assetProxyUtils.encodeERC20ProxyData(zrx.address);
// Perform a transfer from makerAddress to takerAddress
- const balances = await dmyBalances.getAsync();
+ const erc20Balances = await erc20Wrapper.getBalancesAsync();
const amount = new BigNumber(10);
return expect(
assetProxyDispatcher.transferFrom.sendTransactionAsync(
@@ -292,7 +280,7 @@ describe('AssetProxyDispatcher', () => {
// Construct metadata for ERC20 proxy
const encodedProxyMetadata = assetProxyUtils.encodeERC20ProxyData(zrx.address);
// Perform a transfer from makerAddress to takerAddress
- const balances = await dmyBalances.getAsync();
+ const erc20Balances = await erc20Wrapper.getBalancesAsync();
const amount = new BigNumber(10);
return expect(
assetProxyDispatcher.transferFrom.sendTransactionAsync(
diff --git a/packages/contracts/test/asset_proxy_dispatcher/proxies.ts b/packages/contracts/test/asset_proxy_dispatcher/proxies.ts
index 9437fcbf0..830f40e13 100644
--- a/packages/contracts/test/asset_proxy_dispatcher/proxies.ts
+++ b/packages/contracts/test/asset_proxy_dispatcher/proxies.ts
@@ -1,7 +1,6 @@
-import { LogWithDecodedArgs, TransactionReceiptWithDecodedLogs, ZeroEx } from '0x.js';
-import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils';
+import { ZeroEx } from '0x.js';
+import { BlockchainLifecycle } 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';
@@ -11,8 +10,9 @@ import { DummyERC721TokenContract } from '../../src/contract_wrappers/generated/
import { ERC20ProxyContract } from '../../src/contract_wrappers/generated/e_r_c20_proxy';
import { ERC721ProxyContract } from '../../src/contract_wrappers/generated/e_r_c721_proxy';
import { assetProxyUtils } from '../../src/utils/asset_proxy_utils';
-import { Balances } from '../../src/utils/balances';
import { constants } from '../../src/utils/constants';
+import { ERC20Wrapper } from '../../src/utils/erc20_wrapper';
+import { ERC721Wrapper } from '../../src/utils/erc721_wrapper';
import { AssetProxyId, ContractName } from '../../src/utils/types';
import { chaiSetup } from '../utils/chai_setup';
import { deployer } from '../utils/deployer';
@@ -26,63 +26,46 @@ describe('Asset Transfer Proxies', () => {
let owner: string;
let notAuthorized: string;
let assetProxyDispatcherAddress: string;
- let tokenOwner: string;
let makerAddress: string;
let takerAddress: string;
+
let zrx: DummyERC20TokenContract;
let erc721Token: DummyERC721TokenContract;
- let dmyBalances: Balances;
let erc20Proxy: ERC20ProxyContract;
let erc721Proxy: ERC721ProxyContract;
- const makerAssetId = new BigNumber('0x1010101010101010101010101010101010101010101010101010101010101010');
- const testAddressPaddedWithZeros = '0x0000000000000000056000000000000000000010';
- const INITIAL_BALANCE = new BigNumber(10000);
+
+ let erc20Wrapper: ERC20Wrapper;
+ let erc721Wrapper: ERC721Wrapper;
+ let erc721MakerTokenId: BigNumber;
before(async () => {
- // Setup accounts & addresses
const accounts = await web3Wrapper.getAvailableAddressesAsync();
- owner = tokenOwner = accounts[0];
- notAuthorized = accounts[1];
- assetProxyDispatcherAddress = accounts[2];
- makerAddress = accounts[3];
- takerAddress = accounts[4];
- // Deploy ERC20 Proxy
- const erc20ProxyInstance = await deployer.deployAsync(ContractName.ERC20Proxy);
- erc20Proxy = new ERC20ProxyContract(erc20ProxyInstance.abi, erc20ProxyInstance.address, provider);
+ const usedAddresses = ([
+ owner,
+ notAuthorized,
+ assetProxyDispatcherAddress,
+ makerAddress,
+ takerAddress,
+ ] = accounts);
+
+ erc20Wrapper = new ERC20Wrapper(deployer, provider, usedAddresses, owner);
+ erc721Wrapper = new ERC721Wrapper(deployer, provider, usedAddresses, owner);
+
+ [zrx] = await erc20Wrapper.deployDummyERC20TokensAsync();
+ erc20Proxy = await erc20Wrapper.deployERC20ProxyAsync();
+ await erc20Wrapper.setBalancesAndAllowancesAsync();
await erc20Proxy.addAuthorizedAddress.sendTransactionAsync(assetProxyDispatcherAddress, {
from: owner,
});
- // Deploy ERC721 Proxy
- const erc721ProxyInstance = await deployer.deployAsync(ContractName.ERC721Proxy);
- erc721Proxy = new ERC721ProxyContract(erc721ProxyInstance.abi, erc721ProxyInstance.address, provider);
+
+ [erc721Token] = await erc721Wrapper.deployDummyERC721TokensAsync();
+ erc721Proxy = await erc721Wrapper.deployERC721ProxyAsync();
+ await erc721Wrapper.setBalancesAndAllowancesAsync();
+ const erc721Balances = await erc721Wrapper.getBalancesAsync();
+ erc721MakerTokenId = erc721Balances[makerAddress][erc721Token.address][0];
await erc721Proxy.addAuthorizedAddress.sendTransactionAsync(assetProxyDispatcherAddress, {
from: owner,
});
- // Deploy zrx and set initial balances
- const zrxInstance = await deployer.deployAsync(ContractName.DummyERC20Token, constants.DUMMY_TOKEN_ARGS);
- zrx = new DummyERC20TokenContract(zrxInstance.abi, zrxInstance.address, provider);
- await zrx.setBalance.sendTransactionAsync(makerAddress, INITIAL_BALANCE, { from: tokenOwner });
- await zrx.setBalance.sendTransactionAsync(takerAddress, INITIAL_BALANCE, { from: tokenOwner });
- dmyBalances = new Balances([zrx], [makerAddress, takerAddress]);
- await zrx.approve.sendTransactionAsync(erc20Proxy.address, INITIAL_BALANCE, {
- from: takerAddress,
- });
- await zrx.approve.sendTransactionAsync(erc20Proxy.address, INITIAL_BALANCE, {
- from: makerAddress,
- });
- // Deploy erc721Token and set initial balances
- const erc721TokenInstance = await deployer.deployAsync(
- ContractName.DummyERC721Token,
- constants.DUMMY_ERC721TOKEN_ARGS,
- );
- erc721Token = new DummyERC721TokenContract(erc721TokenInstance.abi, erc721TokenInstance.address, provider);
- await erc721Token.setApprovalForAll.sendTransactionAsync(erc721Proxy.address, true, {
- from: makerAddress,
- });
- await erc721Token.setApprovalForAll.sendTransactionAsync(erc721Proxy.address, true, {
- from: takerAddress,
- });
- await erc721Token.mint.sendTransactionAsync(makerAddress, makerAssetId, { from: tokenOwner });
});
beforeEach(async () => {
await blockchainLifecycle.startAsync();
@@ -95,7 +78,7 @@ describe('Asset Transfer Proxies', () => {
// Construct metadata for ERC20 proxy
const encodedProxyMetadata = assetProxyUtils.encodeERC20ProxyData(zrx.address);
// Perform a transfer from makerAddress to takerAddress
- const balances = await dmyBalances.getAsync();
+ const erc20Balances = await erc20Wrapper.getBalancesAsync();
const amount = new BigNumber(10);
await erc20Proxy.transferFrom.sendTransactionAsync(
encodedProxyMetadata,
@@ -105,12 +88,12 @@ describe('Asset Transfer Proxies', () => {
{ from: assetProxyDispatcherAddress },
);
// Verify transfer was successful
- const newBalances = await dmyBalances.getAsync();
+ const newBalances = await erc20Wrapper.getBalancesAsync();
expect(newBalances[makerAddress][zrx.address]).to.be.bignumber.equal(
- balances[makerAddress][zrx.address].minus(amount),
+ erc20Balances[makerAddress][zrx.address].minus(amount),
);
expect(newBalances[takerAddress][zrx.address]).to.be.bignumber.equal(
- balances[takerAddress][zrx.address].add(amount),
+ erc20Balances[takerAddress][zrx.address].add(amount),
);
});
@@ -118,7 +101,7 @@ describe('Asset Transfer Proxies', () => {
// Construct metadata for ERC20 proxy
const encodedProxyMetadata = assetProxyUtils.encodeERC20ProxyData(zrx.address);
// Perform a transfer from makerAddress to takerAddress
- const balances = await dmyBalances.getAsync();
+ const erc20Balances = await erc20Wrapper.getBalancesAsync();
const amount = new BigNumber(0);
await erc20Proxy.transferFrom.sendTransactionAsync(
encodedProxyMetadata,
@@ -128,9 +111,13 @@ describe('Asset Transfer Proxies', () => {
{ from: assetProxyDispatcherAddress },
);
// Verify transfer was successful
- const newBalances = await dmyBalances.getAsync();
- expect(newBalances[makerAddress][zrx.address]).to.be.bignumber.equal(balances[makerAddress][zrx.address]);
- expect(newBalances[takerAddress][zrx.address]).to.be.bignumber.equal(balances[takerAddress][zrx.address]);
+ const newBalances = await erc20Wrapper.getBalancesAsync();
+ expect(newBalances[makerAddress][zrx.address]).to.be.bignumber.equal(
+ erc20Balances[makerAddress][zrx.address],
+ );
+ expect(newBalances[takerAddress][zrx.address]).to.be.bignumber.equal(
+ erc20Balances[takerAddress][zrx.address],
+ );
});
it('should throw if allowances are too low', async () => {
@@ -170,12 +157,12 @@ describe('Asset Transfer Proxies', () => {
describe('Transfer Proxy - ERC721', () => {
it('should successfully transfer tokens', async () => {
// Construct metadata for ERC721 proxy
- const encodedProxyMetadata = assetProxyUtils.encodeERC721ProxyData(erc721Token.address, makerAssetId);
+ const encodedProxyMetadata = assetProxyUtils.encodeERC721ProxyData(erc721Token.address, erc721MakerTokenId);
// Verify pre-condition
- const ownerMakerAsset = await erc721Token.ownerOf.callAsync(makerAssetId);
+ const ownerMakerAsset = await erc721Token.ownerOf.callAsync(erc721MakerTokenId);
expect(ownerMakerAsset).to.be.bignumber.equal(makerAddress);
// Perform a transfer from makerAddress to takerAddress
- const balances = await dmyBalances.getAsync();
+ const erc20Balances = await erc20Wrapper.getBalancesAsync();
const amount = new BigNumber(1);
await erc721Proxy.transferFrom.sendTransactionAsync(
encodedProxyMetadata,
@@ -185,18 +172,18 @@ describe('Asset Transfer Proxies', () => {
{ from: assetProxyDispatcherAddress },
);
// Verify transfer was successful
- const newOwnerMakerAsset = await erc721Token.ownerOf.callAsync(makerAssetId);
+ const newOwnerMakerAsset = await erc721Token.ownerOf.callAsync(erc721MakerTokenId);
expect(newOwnerMakerAsset).to.be.bignumber.equal(takerAddress);
});
it('should throw if transferring 0 amount of a token', async () => {
// Construct metadata for ERC721 proxy
- const encodedProxyMetadata = assetProxyUtils.encodeERC721ProxyData(erc721Token.address, makerAssetId);
+ const encodedProxyMetadata = assetProxyUtils.encodeERC721ProxyData(erc721Token.address, erc721MakerTokenId);
// Verify pre-condition
- const ownerMakerAsset = await erc721Token.ownerOf.callAsync(makerAssetId);
+ const ownerMakerAsset = await erc721Token.ownerOf.callAsync(erc721MakerTokenId);
expect(ownerMakerAsset).to.be.bignumber.equal(makerAddress);
// Perform a transfer from makerAddress to takerAddress
- const balances = await dmyBalances.getAsync();
+ const erc20Balances = await erc20Wrapper.getBalancesAsync();
const amount = new BigNumber(0);
return expect(
erc721Proxy.transferFrom.sendTransactionAsync(
@@ -211,12 +198,12 @@ describe('Asset Transfer Proxies', () => {
it('should throw if transferring > 1 amount of a token', async () => {
// Construct metadata for ERC721 proxy
- const encodedProxyMetadata = assetProxyUtils.encodeERC721ProxyData(erc721Token.address, makerAssetId);
+ const encodedProxyMetadata = assetProxyUtils.encodeERC721ProxyData(erc721Token.address, erc721MakerTokenId);
// Verify pre-condition
- const ownerMakerAsset = await erc721Token.ownerOf.callAsync(makerAssetId);
+ const ownerMakerAsset = await erc721Token.ownerOf.callAsync(erc721MakerTokenId);
expect(ownerMakerAsset).to.be.bignumber.equal(makerAddress);
// Perform a transfer from makerAddress to takerAddress
- const balances = await dmyBalances.getAsync();
+ const erc20Balances = await erc20Wrapper.getBalancesAsync();
const amount = new BigNumber(500);
return expect(
erc721Proxy.transferFrom.sendTransactionAsync(
@@ -231,7 +218,7 @@ describe('Asset Transfer Proxies', () => {
it('should throw if allowances are too low', async () => {
// Construct metadata for ERC721 proxy
- const encodedProxyMetadata = assetProxyUtils.encodeERC721ProxyData(erc721Token.address, makerAssetId);
+ const encodedProxyMetadata = assetProxyUtils.encodeERC721ProxyData(erc721Token.address, erc721MakerTokenId);
// Remove transfer approval for makerAddress.
await erc721Token.setApprovalForAll.sendTransactionAsync(erc721Proxy.address, false, {
from: makerAddress,
@@ -247,7 +234,7 @@ describe('Asset Transfer Proxies', () => {
it('should throw if requesting address is not authorized', async () => {
// Construct metadata for ERC721 proxy
- const encodedProxyMetadata = assetProxyUtils.encodeERC721ProxyData(erc721Token.address, makerAssetId);
+ const encodedProxyMetadata = assetProxyUtils.encodeERC721ProxyData(erc721Token.address, erc721MakerTokenId);
// Perform a transfer from makerAddress to takerAddress
const amount = new BigNumber(1);
return expect(