Fix and cleanup tests
This commit is contained in:
12
packages/contracts/src/utils/address_utils.ts
Normal file
12
packages/contracts/src/utils/address_utils.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { ZeroEx } from '0x.js';
|
||||
|
||||
import { crypto } from './crypto';
|
||||
|
||||
export const addressUtils = {
|
||||
generatePseudoRandomAddress(): string {
|
||||
const randomBigNum = ZeroEx.generatePseudoRandomSalt();
|
||||
const randomBuff = crypto.solSHA3([randomBigNum]);
|
||||
const randomAddress = `0x${randomBuff.slice(0, 20).toString('hex')}`;
|
||||
return randomAddress;
|
||||
},
|
||||
};
|
||||
@@ -4,7 +4,7 @@ import * as _ from 'lodash';
|
||||
|
||||
import { orderUtils } from './order_utils';
|
||||
import { signingUtils } from './signing_utils';
|
||||
import { DefaultOrderParams, SignatureType, SignedOrder, UnsignedOrder } from './types';
|
||||
import { SignatureType, SignedOrder, UnsignedOrder } from './types';
|
||||
|
||||
export class OrderFactory {
|
||||
private _defaultOrderParams: Partial<UnsignedOrder>;
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
import { LogWithDecodedArgs, TransactionReceiptWithDecodedLogs, ZeroEx } from '0x.js';
|
||||
import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils';
|
||||
import { LogWithDecodedArgs, 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 ethUtil = require('ethereumjs-util');
|
||||
import * as _ from 'lodash';
|
||||
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';
|
||||
@@ -19,18 +17,19 @@ import {
|
||||
FillContractEventArgs,
|
||||
} from '../../src/contract_wrappers/generated/exchange';
|
||||
import { assetProxyUtils } from '../../src/utils/asset_proxy_utils';
|
||||
import { Balances } from '../../src/utils/balances';
|
||||
import { constants } from '../../src/utils/constants';
|
||||
import { crypto } from '../../src/utils/crypto';
|
||||
import { ERC20Wrapper } from '../../src/utils/erc20_wrapper';
|
||||
import { ERC721Wrapper } from '../../src/utils/erc721_wrapper';
|
||||
import { ExchangeWrapper } from '../../src/utils/exchange_wrapper';
|
||||
import { OrderFactory } from '../../src/utils/order_factory';
|
||||
import { orderUtils } from '../../src/utils/order_utils';
|
||||
import {
|
||||
AssetProxyId,
|
||||
BalancesByOwner,
|
||||
ContractName,
|
||||
ERC20BalancesByOwner,
|
||||
ERC721BalancesByOwner,
|
||||
ExchangeContractErrs,
|
||||
SignatureType,
|
||||
SignedOrder,
|
||||
} from '../../src/utils/types';
|
||||
import { chaiSetup } from '../utils/chai_setup';
|
||||
@@ -41,16 +40,14 @@ chaiSetup.configure();
|
||||
const expect = chai.expect;
|
||||
const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
|
||||
|
||||
describe('Exchange', () => {
|
||||
describe('Exchange core', () => {
|
||||
let makerAddress: string;
|
||||
let tokenOwner: string;
|
||||
let owner: string;
|
||||
let takerAddress: string;
|
||||
let feeRecipientAddress: string;
|
||||
const INITIAL_BALANCE = ZeroEx.toBaseUnitAmount(new BigNumber(10000), 18);
|
||||
const INITIAL_ALLOWANCE = ZeroEx.toBaseUnitAmount(new BigNumber(10000), 18);
|
||||
|
||||
let rep: DummyERC20TokenContract;
|
||||
let dgd: DummyERC20TokenContract;
|
||||
let erc20TokenA: DummyERC20TokenContract;
|
||||
let erc20TokenB: DummyERC20TokenContract;
|
||||
let zrx: DummyERC20TokenContract;
|
||||
let erc721Token: DummyERC721TokenContract;
|
||||
let exchange: ExchangeContract;
|
||||
@@ -59,20 +56,14 @@ describe('Exchange', () => {
|
||||
let erc721Proxy: ERC721ProxyContract;
|
||||
|
||||
let signedOrder: SignedOrder;
|
||||
let balances: BalancesByOwner;
|
||||
let exWrapper: ExchangeWrapper;
|
||||
let dmyBalances: Balances;
|
||||
let erc20Balances: ERC20BalancesByOwner;
|
||||
let exchangeWrapper: ExchangeWrapper;
|
||||
let erc20Wrapper: ERC20Wrapper;
|
||||
let erc721Wrapper: ERC721Wrapper;
|
||||
let orderFactory: OrderFactory;
|
||||
|
||||
const erc721MakerAssetIds = [
|
||||
new BigNumber('0x1010101010101010101010101010101010101010101010101010101010101010'),
|
||||
new BigNumber('0x2020202020202020202020202020202020202020202020202020202020202020'),
|
||||
];
|
||||
|
||||
const erc721TakerAssetIds = [
|
||||
new BigNumber('0x3030303030303030303030303030303030303030303030303030303030303030'),
|
||||
new BigNumber('0x4040404040404040404040404040404040404040404040404040404040404040'),
|
||||
];
|
||||
let erc721MakerAssetIds: BigNumber[];
|
||||
let erc721TakerAssetIds: BigNumber[];
|
||||
|
||||
let defaultMakerAssetAddress: string;
|
||||
let defaultTakerAssetAddress: string;
|
||||
@@ -81,32 +72,28 @@ describe('Exchange', () => {
|
||||
|
||||
before(async () => {
|
||||
const accounts = await web3Wrapper.getAvailableAddressesAsync();
|
||||
makerAddress = accounts[0];
|
||||
[tokenOwner, takerAddress, feeRecipientAddress] = accounts;
|
||||
const owner = tokenOwner;
|
||||
const [repInstance, dgdInstance, zrxInstance, erc721TokenInstance] = await Promise.all([
|
||||
deployer.deployAsync(ContractName.DummyERC20Token, constants.DUMMY_TOKEN_ARGS),
|
||||
deployer.deployAsync(ContractName.DummyERC20Token, constants.DUMMY_TOKEN_ARGS),
|
||||
deployer.deployAsync(ContractName.DummyERC20Token, constants.DUMMY_TOKEN_ARGS),
|
||||
deployer.deployAsync(ContractName.DummyERC721Token, constants.DUMMY_ERC721TOKEN_ARGS),
|
||||
]);
|
||||
rep = new DummyERC20TokenContract(repInstance.abi, repInstance.address, provider);
|
||||
dgd = new DummyERC20TokenContract(dgdInstance.abi, dgdInstance.address, provider);
|
||||
zrx = new DummyERC20TokenContract(zrxInstance.abi, zrxInstance.address, provider);
|
||||
erc721Token = new DummyERC721TokenContract(erc721TokenInstance.abi, erc721TokenInstance.address, provider);
|
||||
// Deploy Asset Proxy Dispatcher
|
||||
const usedAddresses = ([owner, makerAddress, takerAddress, feeRecipientAddress] = accounts);
|
||||
|
||||
erc20Wrapper = new ERC20Wrapper(deployer, provider, usedAddresses, owner);
|
||||
erc721Wrapper = new ERC721Wrapper(deployer, provider, usedAddresses, owner);
|
||||
|
||||
[erc20TokenA, erc20TokenB, zrx] = await erc20Wrapper.deployDummyERC20TokensAsync();
|
||||
erc20Proxy = await erc20Wrapper.deployERC20ProxyAsync();
|
||||
await erc20Wrapper.setBalancesAndAllowancesAsync();
|
||||
|
||||
[erc721Token] = await erc721Wrapper.deployDummyERC721TokensAsync();
|
||||
erc721Proxy = await erc721Wrapper.deployERC721ProxyAsync();
|
||||
await erc721Wrapper.setBalancesAndAllowancesAsync();
|
||||
const erc721Balances = await erc721Wrapper.getBalancesAsync();
|
||||
erc721MakerAssetIds = erc721Balances[makerAddress][erc721Token.address];
|
||||
erc721TakerAssetIds = erc721Balances[takerAddress][erc721Token.address];
|
||||
|
||||
const assetProxyDispatcherInstance = await deployer.deployAsync(ContractName.AssetProxyDispatcher);
|
||||
assetProxyDispatcher = new AssetProxyDispatcherContract(
|
||||
assetProxyDispatcherInstance.abi,
|
||||
assetProxyDispatcherInstance.address,
|
||||
provider,
|
||||
);
|
||||
// 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,
|
||||
});
|
||||
const prevERC20ProxyAddress = ZeroEx.NULL_ADDRESS;
|
||||
await assetProxyDispatcher.registerAssetProxy.sendTransactionAsync(
|
||||
AssetProxyId.ERC20,
|
||||
@@ -114,12 +101,6 @@ describe('Exchange', () => {
|
||||
prevERC20ProxyAddress,
|
||||
{ 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,
|
||||
});
|
||||
const prevERC721ProxyAddress = ZeroEx.NULL_ADDRESS;
|
||||
await assetProxyDispatcher.registerAssetProxy.sendTransactionAsync(
|
||||
AssetProxyId.ERC721,
|
||||
@@ -127,7 +108,13 @@ describe('Exchange', () => {
|
||||
prevERC721ProxyAddress,
|
||||
{ from: owner },
|
||||
);
|
||||
// Deploy and configure Exchange
|
||||
await erc20Proxy.addAuthorizedAddress.sendTransactionAsync(assetProxyDispatcher.address, {
|
||||
from: owner,
|
||||
});
|
||||
await erc721Proxy.addAuthorizedAddress.sendTransactionAsync(assetProxyDispatcher.address, {
|
||||
from: owner,
|
||||
});
|
||||
|
||||
const exchangeInstance = await deployer.deployAsync(ContractName.Exchange, [
|
||||
assetProxyDispatcher.address,
|
||||
assetProxyUtils.encodeERC20ProxyData(zrx.address),
|
||||
@@ -138,61 +125,21 @@ describe('Exchange', () => {
|
||||
exchangeContractAddress: exchange.address,
|
||||
networkId: constants.TESTRPC_NETWORK_ID,
|
||||
});
|
||||
exWrapper = new ExchangeWrapper(exchange, zeroEx);
|
||||
exchangeWrapper = new ExchangeWrapper(exchange, zeroEx);
|
||||
|
||||
defaultMakerAssetAddress = rep.address;
|
||||
defaultTakerAssetAddress = dgd.address;
|
||||
defaultMakerAssetAddress = erc20TokenA.address;
|
||||
defaultTakerAssetAddress = erc20TokenB.address;
|
||||
|
||||
const defaultOrderParams = {
|
||||
...constants.STATIC_ORDER_PARAMS,
|
||||
exchangeAddress: exchange.address,
|
||||
makerAddress,
|
||||
feeRecipientAddress,
|
||||
makerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100), 18),
|
||||
takerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(200), 18),
|
||||
makerFee: ZeroEx.toBaseUnitAmount(new BigNumber(1), 18),
|
||||
takerFee: ZeroEx.toBaseUnitAmount(new BigNumber(1), 18),
|
||||
makerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultMakerAssetAddress),
|
||||
takerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultTakerAssetAddress),
|
||||
};
|
||||
const privateKey = constants.TESTRPC_PRIVATE_KEYS[0];
|
||||
const privateKey = constants.TESTRPC_PRIVATE_KEYS[accounts.indexOf(makerAddress)];
|
||||
orderFactory = new OrderFactory(privateKey, defaultOrderParams);
|
||||
dmyBalances = new Balances([rep, dgd, zrx], [makerAddress, takerAddress, feeRecipientAddress]);
|
||||
await Promise.all([
|
||||
rep.approve.sendTransactionAsync(erc20Proxy.address, INITIAL_ALLOWANCE, {
|
||||
from: makerAddress,
|
||||
}),
|
||||
rep.approve.sendTransactionAsync(erc20Proxy.address, INITIAL_ALLOWANCE, {
|
||||
from: takerAddress,
|
||||
}),
|
||||
rep.setBalance.sendTransactionAsync(makerAddress, INITIAL_BALANCE, { from: tokenOwner }),
|
||||
rep.setBalance.sendTransactionAsync(takerAddress, INITIAL_BALANCE, { from: tokenOwner }),
|
||||
dgd.approve.sendTransactionAsync(erc20Proxy.address, INITIAL_ALLOWANCE, {
|
||||
from: makerAddress,
|
||||
}),
|
||||
dgd.approve.sendTransactionAsync(erc20Proxy.address, INITIAL_ALLOWANCE, {
|
||||
from: takerAddress,
|
||||
}),
|
||||
dgd.setBalance.sendTransactionAsync(makerAddress, INITIAL_BALANCE, { from: tokenOwner }),
|
||||
dgd.setBalance.sendTransactionAsync(takerAddress, INITIAL_BALANCE, { from: tokenOwner }),
|
||||
zrx.approve.sendTransactionAsync(erc20Proxy.address, INITIAL_ALLOWANCE, {
|
||||
from: makerAddress,
|
||||
}),
|
||||
zrx.approve.sendTransactionAsync(erc20Proxy.address, INITIAL_ALLOWANCE, {
|
||||
from: takerAddress,
|
||||
}),
|
||||
zrx.setBalance.sendTransactionAsync(makerAddress, INITIAL_BALANCE, { from: tokenOwner }),
|
||||
zrx.setBalance.sendTransactionAsync(takerAddress, INITIAL_BALANCE, { from: tokenOwner }),
|
||||
erc721Token.setApprovalForAll.sendTransactionAsync(erc721Proxy.address, true, {
|
||||
from: makerAddress,
|
||||
}),
|
||||
erc721Token.setApprovalForAll.sendTransactionAsync(erc721Proxy.address, true, {
|
||||
from: takerAddress,
|
||||
}),
|
||||
erc721Token.mint.sendTransactionAsync(makerAddress, erc721MakerAssetIds[0], { from: tokenOwner }),
|
||||
erc721Token.mint.sendTransactionAsync(makerAddress, erc721MakerAssetIds[1], { from: tokenOwner }),
|
||||
erc721Token.mint.sendTransactionAsync(takerAddress, erc721TakerAssetIds[0], { from: tokenOwner }),
|
||||
erc721Token.mint.sendTransactionAsync(takerAddress, erc721TakerAssetIds[1], { from: tokenOwner }),
|
||||
]);
|
||||
});
|
||||
beforeEach(async () => {
|
||||
await blockchainLifecycle.startAsync();
|
||||
@@ -208,7 +155,7 @@ describe('Exchange', () => {
|
||||
|
||||
describe('fillOrder', () => {
|
||||
beforeEach(async () => {
|
||||
balances = await dmyBalances.getAsync();
|
||||
erc20Balances = await erc20Wrapper.getBalancesAsync();
|
||||
signedOrder = orderFactory.newSignedOrder();
|
||||
});
|
||||
|
||||
@@ -218,27 +165,27 @@ describe('Exchange', () => {
|
||||
takerAssetAmount: new BigNumber(3),
|
||||
});
|
||||
|
||||
const takerAssetFilledAmountBefore = await exWrapper.getTakerAssetFilledAmountAsync(
|
||||
const takerAssetFilledAmountBefore = await exchangeWrapper.getTakerAssetFilledAmountAsync(
|
||||
orderUtils.getOrderHashHex(signedOrder),
|
||||
);
|
||||
expect(takerAssetFilledAmountBefore).to.be.bignumber.equal(0);
|
||||
|
||||
const fillTakerAssetAmount1 = new BigNumber(2);
|
||||
await exWrapper.fillOrderAsync(signedOrder, takerAddress, {
|
||||
await exchangeWrapper.fillOrderAsync(signedOrder, takerAddress, {
|
||||
takerAssetFillAmount: fillTakerAssetAmount1,
|
||||
});
|
||||
|
||||
const takerAssetFilledAmountAfter1 = await exWrapper.getTakerAssetFilledAmountAsync(
|
||||
const takerAssetFilledAmountAfter1 = await exchangeWrapper.getTakerAssetFilledAmountAsync(
|
||||
orderUtils.getOrderHashHex(signedOrder),
|
||||
);
|
||||
expect(takerAssetFilledAmountAfter1).to.be.bignumber.equal(fillTakerAssetAmount1);
|
||||
|
||||
const fillTakerAssetAmount2 = new BigNumber(1);
|
||||
await exWrapper.fillOrderAsync(signedOrder, takerAddress, {
|
||||
await exchangeWrapper.fillOrderAsync(signedOrder, takerAddress, {
|
||||
takerAssetFillAmount: fillTakerAssetAmount2,
|
||||
});
|
||||
|
||||
const takerAssetFilledAmountAfter2 = await exWrapper.getTakerAssetFilledAmountAsync(
|
||||
const takerAssetFilledAmountAfter2 = await exchangeWrapper.getTakerAssetFilledAmountAsync(
|
||||
orderUtils.getOrderHashHex(signedOrder),
|
||||
);
|
||||
expect(takerAssetFilledAmountAfter2).to.be.bignumber.equal(takerAssetFilledAmountAfter1);
|
||||
@@ -250,20 +197,20 @@ describe('Exchange', () => {
|
||||
takerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100), 18),
|
||||
});
|
||||
|
||||
const takerAssetFilledAmountBefore = await exWrapper.getTakerAssetFilledAmountAsync(
|
||||
const takerAssetFilledAmountBefore = await exchangeWrapper.getTakerAssetFilledAmountAsync(
|
||||
orderUtils.getOrderHashHex(signedOrder),
|
||||
);
|
||||
expect(takerAssetFilledAmountBefore).to.be.bignumber.equal(0);
|
||||
|
||||
const takerAssetFillAmount = signedOrder.takerAssetAmount.div(2);
|
||||
await exWrapper.fillOrderAsync(signedOrder, takerAddress, { takerAssetFillAmount });
|
||||
await exchangeWrapper.fillOrderAsync(signedOrder, takerAddress, { takerAssetFillAmount });
|
||||
|
||||
const makerAmountBoughtAfter = await exWrapper.getTakerAssetFilledAmountAsync(
|
||||
const makerAmountBoughtAfter = await exchangeWrapper.getTakerAssetFilledAmountAsync(
|
||||
orderUtils.getOrderHashHex(signedOrder),
|
||||
);
|
||||
expect(makerAmountBoughtAfter).to.be.bignumber.equal(takerAssetFillAmount);
|
||||
|
||||
const newBalances = await dmyBalances.getAsync();
|
||||
const newBalances = await erc20Wrapper.getBalancesAsync();
|
||||
|
||||
const makerAssetFilledAmount = takerAssetFillAmount
|
||||
.times(signedOrder.makerAssetAmount)
|
||||
@@ -275,25 +222,25 @@ describe('Exchange', () => {
|
||||
.times(makerAssetFilledAmount)
|
||||
.dividedToIntegerBy(signedOrder.makerAssetAmount);
|
||||
expect(newBalances[makerAddress][defaultMakerAssetAddress]).to.be.bignumber.equal(
|
||||
balances[makerAddress][defaultMakerAssetAddress].minus(makerAssetFilledAmount),
|
||||
erc20Balances[makerAddress][defaultMakerAssetAddress].minus(makerAssetFilledAmount),
|
||||
);
|
||||
expect(newBalances[makerAddress][defaultTakerAssetAddress]).to.be.bignumber.equal(
|
||||
balances[makerAddress][defaultTakerAssetAddress].add(takerAssetFillAmount),
|
||||
erc20Balances[makerAddress][defaultTakerAssetAddress].add(takerAssetFillAmount),
|
||||
);
|
||||
expect(newBalances[makerAddress][zrx.address]).to.be.bignumber.equal(
|
||||
balances[makerAddress][zrx.address].minus(makerFeePaid),
|
||||
erc20Balances[makerAddress][zrx.address].minus(makerFeePaid),
|
||||
);
|
||||
expect(newBalances[takerAddress][defaultTakerAssetAddress]).to.be.bignumber.equal(
|
||||
balances[takerAddress][defaultTakerAssetAddress].minus(takerAssetFillAmount),
|
||||
erc20Balances[takerAddress][defaultTakerAssetAddress].minus(takerAssetFillAmount),
|
||||
);
|
||||
expect(newBalances[takerAddress][defaultMakerAssetAddress]).to.be.bignumber.equal(
|
||||
balances[takerAddress][defaultMakerAssetAddress].add(makerAssetFilledAmount),
|
||||
erc20Balances[takerAddress][defaultMakerAssetAddress].add(makerAssetFilledAmount),
|
||||
);
|
||||
expect(newBalances[takerAddress][zrx.address]).to.be.bignumber.equal(
|
||||
balances[takerAddress][zrx.address].minus(takerFeePaid),
|
||||
erc20Balances[takerAddress][zrx.address].minus(takerFeePaid),
|
||||
);
|
||||
expect(newBalances[feeRecipientAddress][zrx.address]).to.be.bignumber.equal(
|
||||
balances[feeRecipientAddress][zrx.address].add(makerFeePaid.add(takerFeePaid)),
|
||||
erc20Balances[feeRecipientAddress][zrx.address].add(makerFeePaid.add(takerFeePaid)),
|
||||
);
|
||||
});
|
||||
|
||||
@@ -303,20 +250,20 @@ describe('Exchange', () => {
|
||||
takerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100), 18),
|
||||
});
|
||||
|
||||
const takerAssetFilledAmountBefore = await exWrapper.getTakerAssetFilledAmountAsync(
|
||||
const takerAssetFilledAmountBefore = await exchangeWrapper.getTakerAssetFilledAmountAsync(
|
||||
orderUtils.getOrderHashHex(signedOrder),
|
||||
);
|
||||
expect(takerAssetFilledAmountBefore).to.be.bignumber.equal(0);
|
||||
|
||||
const takerAssetFillAmount = signedOrder.takerAssetAmount.div(2);
|
||||
await exWrapper.fillOrderAsync(signedOrder, takerAddress, { takerAssetFillAmount });
|
||||
await exchangeWrapper.fillOrderAsync(signedOrder, takerAddress, { takerAssetFillAmount });
|
||||
|
||||
const makerAmountBoughtAfter = await exWrapper.getTakerAssetFilledAmountAsync(
|
||||
const makerAmountBoughtAfter = await exchangeWrapper.getTakerAssetFilledAmountAsync(
|
||||
orderUtils.getOrderHashHex(signedOrder),
|
||||
);
|
||||
expect(makerAmountBoughtAfter).to.be.bignumber.equal(takerAssetFillAmount);
|
||||
|
||||
const newBalances = await dmyBalances.getAsync();
|
||||
const newBalances = await erc20Wrapper.getBalancesAsync();
|
||||
|
||||
const makerAssetFilledAmount = takerAssetFillAmount
|
||||
.times(signedOrder.makerAssetAmount)
|
||||
@@ -328,25 +275,25 @@ describe('Exchange', () => {
|
||||
.times(makerAssetFilledAmount)
|
||||
.dividedToIntegerBy(signedOrder.makerAssetAmount);
|
||||
expect(newBalances[makerAddress][defaultMakerAssetAddress]).to.be.bignumber.equal(
|
||||
balances[makerAddress][defaultMakerAssetAddress].minus(makerAssetFilledAmount),
|
||||
erc20Balances[makerAddress][defaultMakerAssetAddress].minus(makerAssetFilledAmount),
|
||||
);
|
||||
expect(newBalances[makerAddress][defaultTakerAssetAddress]).to.be.bignumber.equal(
|
||||
balances[makerAddress][defaultTakerAssetAddress].add(takerAssetFillAmount),
|
||||
erc20Balances[makerAddress][defaultTakerAssetAddress].add(takerAssetFillAmount),
|
||||
);
|
||||
expect(newBalances[makerAddress][zrx.address]).to.be.bignumber.equal(
|
||||
balances[makerAddress][zrx.address].minus(makerFeePaid),
|
||||
erc20Balances[makerAddress][zrx.address].minus(makerFeePaid),
|
||||
);
|
||||
expect(newBalances[takerAddress][defaultTakerAssetAddress]).to.be.bignumber.equal(
|
||||
balances[takerAddress][defaultTakerAssetAddress].minus(takerAssetFillAmount),
|
||||
erc20Balances[takerAddress][defaultTakerAssetAddress].minus(takerAssetFillAmount),
|
||||
);
|
||||
expect(newBalances[takerAddress][defaultMakerAssetAddress]).to.be.bignumber.equal(
|
||||
balances[takerAddress][defaultMakerAssetAddress].add(makerAssetFilledAmount),
|
||||
erc20Balances[takerAddress][defaultMakerAssetAddress].add(makerAssetFilledAmount),
|
||||
);
|
||||
expect(newBalances[takerAddress][zrx.address]).to.be.bignumber.equal(
|
||||
balances[takerAddress][zrx.address].minus(takerFeePaid),
|
||||
erc20Balances[takerAddress][zrx.address].minus(takerFeePaid),
|
||||
);
|
||||
expect(newBalances[feeRecipientAddress][zrx.address]).to.be.bignumber.equal(
|
||||
balances[feeRecipientAddress][zrx.address].add(makerFeePaid.add(takerFeePaid)),
|
||||
erc20Balances[feeRecipientAddress][zrx.address].add(makerFeePaid.add(takerFeePaid)),
|
||||
);
|
||||
});
|
||||
|
||||
@@ -356,20 +303,20 @@ describe('Exchange', () => {
|
||||
takerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(200), 18),
|
||||
});
|
||||
|
||||
const takerAssetFilledAmountBefore = await exWrapper.getTakerAssetFilledAmountAsync(
|
||||
const takerAssetFilledAmountBefore = await exchangeWrapper.getTakerAssetFilledAmountAsync(
|
||||
orderUtils.getOrderHashHex(signedOrder),
|
||||
);
|
||||
expect(takerAssetFilledAmountBefore).to.be.bignumber.equal(0);
|
||||
|
||||
const takerAssetFillAmount = signedOrder.takerAssetAmount.div(2);
|
||||
await exWrapper.fillOrderAsync(signedOrder, takerAddress, { takerAssetFillAmount });
|
||||
await exchangeWrapper.fillOrderAsync(signedOrder, takerAddress, { takerAssetFillAmount });
|
||||
|
||||
const makerAmountBoughtAfter = await exWrapper.getTakerAssetFilledAmountAsync(
|
||||
const makerAmountBoughtAfter = await exchangeWrapper.getTakerAssetFilledAmountAsync(
|
||||
orderUtils.getOrderHashHex(signedOrder),
|
||||
);
|
||||
expect(makerAmountBoughtAfter).to.be.bignumber.equal(takerAssetFillAmount);
|
||||
|
||||
const newBalances = await dmyBalances.getAsync();
|
||||
const newBalances = await erc20Wrapper.getBalancesAsync();
|
||||
|
||||
const makerAssetFilledAmount = takerAssetFillAmount
|
||||
.times(signedOrder.makerAssetAmount)
|
||||
@@ -381,25 +328,25 @@ describe('Exchange', () => {
|
||||
.times(makerAssetFilledAmount)
|
||||
.dividedToIntegerBy(signedOrder.makerAssetAmount);
|
||||
expect(newBalances[makerAddress][defaultMakerAssetAddress]).to.be.bignumber.equal(
|
||||
balances[makerAddress][defaultMakerAssetAddress].minus(makerAssetFilledAmount),
|
||||
erc20Balances[makerAddress][defaultMakerAssetAddress].minus(makerAssetFilledAmount),
|
||||
);
|
||||
expect(newBalances[makerAddress][defaultTakerAssetAddress]).to.be.bignumber.equal(
|
||||
balances[makerAddress][defaultTakerAssetAddress].add(takerAssetFillAmount),
|
||||
erc20Balances[makerAddress][defaultTakerAssetAddress].add(takerAssetFillAmount),
|
||||
);
|
||||
expect(newBalances[makerAddress][zrx.address]).to.be.bignumber.equal(
|
||||
balances[makerAddress][zrx.address].minus(makerFeePaid),
|
||||
erc20Balances[makerAddress][zrx.address].minus(makerFeePaid),
|
||||
);
|
||||
expect(newBalances[takerAddress][defaultTakerAssetAddress]).to.be.bignumber.equal(
|
||||
balances[takerAddress][defaultTakerAssetAddress].minus(takerAssetFillAmount),
|
||||
erc20Balances[takerAddress][defaultTakerAssetAddress].minus(takerAssetFillAmount),
|
||||
);
|
||||
expect(newBalances[takerAddress][defaultMakerAssetAddress]).to.be.bignumber.equal(
|
||||
balances[takerAddress][defaultMakerAssetAddress].add(makerAssetFilledAmount),
|
||||
erc20Balances[takerAddress][defaultMakerAssetAddress].add(makerAssetFilledAmount),
|
||||
);
|
||||
expect(newBalances[takerAddress][zrx.address]).to.be.bignumber.equal(
|
||||
balances[takerAddress][zrx.address].minus(takerFeePaid),
|
||||
erc20Balances[takerAddress][zrx.address].minus(takerFeePaid),
|
||||
);
|
||||
expect(newBalances[feeRecipientAddress][zrx.address]).to.be.bignumber.equal(
|
||||
balances[feeRecipientAddress][zrx.address].add(makerFeePaid.add(takerFeePaid)),
|
||||
erc20Balances[feeRecipientAddress][zrx.address].add(makerFeePaid.add(takerFeePaid)),
|
||||
);
|
||||
});
|
||||
|
||||
@@ -410,21 +357,21 @@ describe('Exchange', () => {
|
||||
takerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(200), 18),
|
||||
});
|
||||
|
||||
const takerAssetFilledAmountBefore = await exWrapper.getTakerAssetFilledAmountAsync(
|
||||
const takerAssetFilledAmountBefore = await exchangeWrapper.getTakerAssetFilledAmountAsync(
|
||||
orderUtils.getOrderHashHex(signedOrder),
|
||||
);
|
||||
expect(takerAssetFilledAmountBefore).to.be.bignumber.equal(0);
|
||||
|
||||
const takerAssetFillAmount = signedOrder.takerAssetAmount.div(2);
|
||||
await exWrapper.fillOrderAsync(signedOrder, takerAddress, { takerAssetFillAmount });
|
||||
await exchangeWrapper.fillOrderAsync(signedOrder, takerAddress, { takerAssetFillAmount });
|
||||
|
||||
const makerAmountBoughtAfter = await exWrapper.getTakerAssetFilledAmountAsync(
|
||||
const makerAmountBoughtAfter = await exchangeWrapper.getTakerAssetFilledAmountAsync(
|
||||
orderUtils.getOrderHashHex(signedOrder),
|
||||
);
|
||||
const expectedMakerAmountBoughtAfter = takerAssetFillAmount.add(takerAssetFilledAmountBefore);
|
||||
expect(makerAmountBoughtAfter).to.be.bignumber.equal(expectedMakerAmountBoughtAfter);
|
||||
|
||||
const newBalances = await dmyBalances.getAsync();
|
||||
const newBalances = await erc20Wrapper.getBalancesAsync();
|
||||
|
||||
const makerAssetFilledAmount = takerAssetFillAmount
|
||||
.times(signedOrder.makerAssetAmount)
|
||||
@@ -436,67 +383,67 @@ describe('Exchange', () => {
|
||||
.times(makerAssetFilledAmount)
|
||||
.dividedToIntegerBy(signedOrder.makerAssetAmount);
|
||||
expect(newBalances[makerAddress][defaultMakerAssetAddress]).to.be.bignumber.equal(
|
||||
balances[makerAddress][defaultMakerAssetAddress].minus(makerAssetFilledAmount),
|
||||
erc20Balances[makerAddress][defaultMakerAssetAddress].minus(makerAssetFilledAmount),
|
||||
);
|
||||
expect(newBalances[makerAddress][defaultTakerAssetAddress]).to.be.bignumber.equal(
|
||||
balances[makerAddress][defaultTakerAssetAddress].add(takerAssetFillAmount),
|
||||
erc20Balances[makerAddress][defaultTakerAssetAddress].add(takerAssetFillAmount),
|
||||
);
|
||||
expect(newBalances[makerAddress][zrx.address]).to.be.bignumber.equal(
|
||||
balances[makerAddress][zrx.address].minus(makerFeePaid),
|
||||
erc20Balances[makerAddress][zrx.address].minus(makerFeePaid),
|
||||
);
|
||||
expect(newBalances[takerAddress][defaultTakerAssetAddress]).to.be.bignumber.equal(
|
||||
balances[takerAddress][defaultTakerAssetAddress].minus(takerAssetFillAmount),
|
||||
erc20Balances[takerAddress][defaultTakerAssetAddress].minus(takerAssetFillAmount),
|
||||
);
|
||||
expect(newBalances[takerAddress][defaultMakerAssetAddress]).to.be.bignumber.equal(
|
||||
balances[takerAddress][defaultMakerAssetAddress].add(makerAssetFilledAmount),
|
||||
erc20Balances[takerAddress][defaultMakerAssetAddress].add(makerAssetFilledAmount),
|
||||
);
|
||||
expect(newBalances[takerAddress][zrx.address]).to.be.bignumber.equal(
|
||||
balances[takerAddress][zrx.address].minus(takerFeePaid),
|
||||
erc20Balances[takerAddress][zrx.address].minus(takerFeePaid),
|
||||
);
|
||||
expect(newBalances[feeRecipientAddress][zrx.address]).to.be.bignumber.equal(
|
||||
balances[feeRecipientAddress][zrx.address].add(makerFeePaid.add(takerFeePaid)),
|
||||
erc20Balances[feeRecipientAddress][zrx.address].add(makerFeePaid.add(takerFeePaid)),
|
||||
);
|
||||
});
|
||||
|
||||
it('should fill remaining value if takerAssetFillAmount > remaining takerAssetAmount', async () => {
|
||||
const takerAssetFillAmount = signedOrder.takerAssetAmount.div(2);
|
||||
await exWrapper.fillOrderAsync(signedOrder, takerAddress, { takerAssetFillAmount });
|
||||
await exchangeWrapper.fillOrderAsync(signedOrder, takerAddress, { takerAssetFillAmount });
|
||||
|
||||
const res = await exWrapper.fillOrderAsync(signedOrder, takerAddress, {
|
||||
const res = await exchangeWrapper.fillOrderAsync(signedOrder, takerAddress, {
|
||||
takerAssetFillAmount: signedOrder.takerAssetAmount,
|
||||
});
|
||||
const log = res.logs[0] as LogWithDecodedArgs<FillContractEventArgs>;
|
||||
expect(log.args.takerAssetFilledAmount).to.be.bignumber.equal(
|
||||
signedOrder.takerAssetAmount.minus(takerAssetFillAmount),
|
||||
);
|
||||
const newBalances = await dmyBalances.getAsync();
|
||||
const newBalances = await erc20Wrapper.getBalancesAsync();
|
||||
|
||||
expect(newBalances[makerAddress][defaultMakerAssetAddress]).to.be.bignumber.equal(
|
||||
balances[makerAddress][defaultMakerAssetAddress].minus(signedOrder.makerAssetAmount),
|
||||
erc20Balances[makerAddress][defaultMakerAssetAddress].minus(signedOrder.makerAssetAmount),
|
||||
);
|
||||
expect(newBalances[makerAddress][defaultTakerAssetAddress]).to.be.bignumber.equal(
|
||||
balances[makerAddress][defaultTakerAssetAddress].add(signedOrder.takerAssetAmount),
|
||||
erc20Balances[makerAddress][defaultTakerAssetAddress].add(signedOrder.takerAssetAmount),
|
||||
);
|
||||
expect(newBalances[makerAddress][zrx.address]).to.be.bignumber.equal(
|
||||
balances[makerAddress][zrx.address].minus(signedOrder.makerFee),
|
||||
erc20Balances[makerAddress][zrx.address].minus(signedOrder.makerFee),
|
||||
);
|
||||
expect(newBalances[takerAddress][defaultTakerAssetAddress]).to.be.bignumber.equal(
|
||||
balances[takerAddress][defaultTakerAssetAddress].minus(signedOrder.takerAssetAmount),
|
||||
erc20Balances[takerAddress][defaultTakerAssetAddress].minus(signedOrder.takerAssetAmount),
|
||||
);
|
||||
expect(newBalances[takerAddress][defaultMakerAssetAddress]).to.be.bignumber.equal(
|
||||
balances[takerAddress][defaultMakerAssetAddress].add(signedOrder.makerAssetAmount),
|
||||
erc20Balances[takerAddress][defaultMakerAssetAddress].add(signedOrder.makerAssetAmount),
|
||||
);
|
||||
expect(newBalances[takerAddress][zrx.address]).to.be.bignumber.equal(
|
||||
balances[takerAddress][zrx.address].minus(signedOrder.takerFee),
|
||||
erc20Balances[takerAddress][zrx.address].minus(signedOrder.takerFee),
|
||||
);
|
||||
expect(newBalances[feeRecipientAddress][zrx.address]).to.be.bignumber.equal(
|
||||
balances[feeRecipientAddress][zrx.address].add(signedOrder.makerFee.add(signedOrder.takerFee)),
|
||||
erc20Balances[feeRecipientAddress][zrx.address].add(signedOrder.makerFee.add(signedOrder.takerFee)),
|
||||
);
|
||||
});
|
||||
|
||||
it('should log 1 event with the correct arguments when order has a feeRecipient', async () => {
|
||||
const divisor = 2;
|
||||
const res = await exWrapper.fillOrderAsync(signedOrder, takerAddress, {
|
||||
const res = await exchangeWrapper.fillOrderAsync(signedOrder, takerAddress, {
|
||||
takerAssetFillAmount: signedOrder.takerAssetAmount.div(divisor),
|
||||
});
|
||||
expect(res.logs).to.have.length(1);
|
||||
@@ -525,7 +472,7 @@ describe('Exchange', () => {
|
||||
feeRecipientAddress: ZeroEx.NULL_ADDRESS,
|
||||
});
|
||||
const divisor = 2;
|
||||
const res = await exWrapper.fillOrderAsync(signedOrder, takerAddress, {
|
||||
const res = await exchangeWrapper.fillOrderAsync(signedOrder, takerAddress, {
|
||||
takerAssetFillAmount: signedOrder.takerAssetAmount.div(divisor),
|
||||
});
|
||||
expect(res.logs).to.have.length(1);
|
||||
@@ -555,7 +502,9 @@ describe('Exchange', () => {
|
||||
makerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100), 18),
|
||||
takerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(200), 18),
|
||||
});
|
||||
return expect(exWrapper.fillOrderAsync(signedOrder, takerAddress)).to.be.rejectedWith(constants.REVERT);
|
||||
return expect(exchangeWrapper.fillOrderAsync(signedOrder, takerAddress)).to.be.rejectedWith(
|
||||
constants.REVERT,
|
||||
);
|
||||
});
|
||||
|
||||
it('should throw if signature is invalid', async () => {
|
||||
@@ -569,7 +518,9 @@ describe('Exchange', () => {
|
||||
const invalidSigBuff = Buffer.concat([ethUtil.toBuffer(signatureTypeAndV), invalidR, invalidS]);
|
||||
const invalidSigHex = `0x${invalidSigBuff.toString('hex')}`;
|
||||
signedOrder.signature = invalidSigHex;
|
||||
return expect(exWrapper.fillOrderAsync(signedOrder, takerAddress)).to.be.rejectedWith(constants.REVERT);
|
||||
return expect(exchangeWrapper.fillOrderAsync(signedOrder, takerAddress)).to.be.rejectedWith(
|
||||
constants.REVERT,
|
||||
);
|
||||
});
|
||||
|
||||
it('should throw if makerAssetAmount is 0', async () => {
|
||||
@@ -577,7 +528,9 @@ describe('Exchange', () => {
|
||||
makerAssetAmount: new BigNumber(0),
|
||||
});
|
||||
|
||||
return expect(exWrapper.fillOrderAsync(signedOrder, takerAddress)).to.be.rejectedWith(constants.REVERT);
|
||||
return expect(exchangeWrapper.fillOrderAsync(signedOrder, takerAddress)).to.be.rejectedWith(
|
||||
constants.REVERT,
|
||||
);
|
||||
});
|
||||
|
||||
it('should throw if takerAssetAmount is 0', async () => {
|
||||
@@ -585,63 +538,69 @@ describe('Exchange', () => {
|
||||
takerAssetAmount: new BigNumber(0),
|
||||
});
|
||||
|
||||
return expect(exWrapper.fillOrderAsync(signedOrder, takerAddress)).to.be.rejectedWith(constants.REVERT);
|
||||
return expect(exchangeWrapper.fillOrderAsync(signedOrder, takerAddress)).to.be.rejectedWith(
|
||||
constants.REVERT,
|
||||
);
|
||||
});
|
||||
|
||||
it('should throw if takerAssetFillAmount is 0', async () => {
|
||||
signedOrder = orderFactory.newSignedOrder();
|
||||
|
||||
return expect(
|
||||
exWrapper.fillOrderAsync(signedOrder, takerAddress, {
|
||||
exchangeWrapper.fillOrderAsync(signedOrder, takerAddress, {
|
||||
takerAssetFillAmount: new BigNumber(0),
|
||||
}),
|
||||
).to.be.rejectedWith(constants.REVERT);
|
||||
});
|
||||
|
||||
it('should throw if maker balances are too low to fill order', async () => {
|
||||
it('should throw if maker erc20Balances are too low to fill order', async () => {
|
||||
signedOrder = orderFactory.newSignedOrder({
|
||||
makerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100000), 18),
|
||||
});
|
||||
|
||||
return expect(exWrapper.fillOrderAsync(signedOrder, takerAddress)).to.be.rejectedWith(constants.REVERT);
|
||||
return expect(exchangeWrapper.fillOrderAsync(signedOrder, takerAddress)).to.be.rejectedWith(
|
||||
constants.REVERT,
|
||||
);
|
||||
});
|
||||
|
||||
it('should throw if taker balances are too low to fill order', async () => {
|
||||
it('should throw if taker erc20Balances are too low to fill order', async () => {
|
||||
signedOrder = orderFactory.newSignedOrder({
|
||||
takerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100000), 18),
|
||||
});
|
||||
|
||||
return expect(exWrapper.fillOrderAsync(signedOrder, takerAddress)).to.be.rejectedWith(constants.REVERT);
|
||||
return expect(exchangeWrapper.fillOrderAsync(signedOrder, takerAddress)).to.be.rejectedWith(
|
||||
constants.REVERT,
|
||||
);
|
||||
});
|
||||
|
||||
it('should throw if maker allowances are too low to fill order', async () => {
|
||||
await rep.approve.sendTransactionAsync(erc20Proxy.address, new BigNumber(0), {
|
||||
await erc20TokenA.approve.sendTransactionAsync(erc20Proxy.address, new BigNumber(0), {
|
||||
from: makerAddress,
|
||||
});
|
||||
expect(exWrapper.fillOrderAsync(signedOrder, takerAddress)).to.be.rejectedWith(constants.REVERT);
|
||||
await rep.approve.sendTransactionAsync(erc20Proxy.address, INITIAL_ALLOWANCE, {
|
||||
expect(exchangeWrapper.fillOrderAsync(signedOrder, takerAddress)).to.be.rejectedWith(constants.REVERT);
|
||||
await erc20TokenA.approve.sendTransactionAsync(erc20Proxy.address, constants.INITIAL_ERC20_ALLOWANCE, {
|
||||
from: makerAddress,
|
||||
});
|
||||
});
|
||||
|
||||
it('should throw if taker allowances are too low to fill order', async () => {
|
||||
await dgd.approve.sendTransactionAsync(erc20Proxy.address, new BigNumber(0), {
|
||||
await erc20TokenB.approve.sendTransactionAsync(erc20Proxy.address, new BigNumber(0), {
|
||||
from: takerAddress,
|
||||
});
|
||||
expect(exWrapper.fillOrderAsync(signedOrder, takerAddress)).to.be.rejectedWith(constants.REVERT);
|
||||
await dgd.approve.sendTransactionAsync(erc20Proxy.address, INITIAL_ALLOWANCE, {
|
||||
expect(exchangeWrapper.fillOrderAsync(signedOrder, takerAddress)).to.be.rejectedWith(constants.REVERT);
|
||||
await erc20TokenB.approve.sendTransactionAsync(erc20Proxy.address, constants.INITIAL_ERC20_ALLOWANCE, {
|
||||
from: takerAddress,
|
||||
});
|
||||
});
|
||||
|
||||
it('should not change balances if an order is expired', async () => {
|
||||
it('should not change erc20Balances if an order is expired', async () => {
|
||||
signedOrder = orderFactory.newSignedOrder({
|
||||
expirationTimeSeconds: new BigNumber(Math.floor((Date.now() - 10000) / 1000)),
|
||||
});
|
||||
await exWrapper.fillOrderAsync(signedOrder, takerAddress);
|
||||
await exchangeWrapper.fillOrderAsync(signedOrder, takerAddress);
|
||||
|
||||
const newBalances = await dmyBalances.getAsync();
|
||||
expect(newBalances).to.be.deep.equal(balances);
|
||||
const newBalances = await erc20Wrapper.getBalancesAsync();
|
||||
expect(newBalances).to.be.deep.equal(erc20Balances);
|
||||
});
|
||||
|
||||
it('should log an error event if an order is expired', async () => {
|
||||
@@ -649,7 +608,7 @@ describe('Exchange', () => {
|
||||
expirationTimeSeconds: new BigNumber(Math.floor((Date.now() - 10000) / 1000)),
|
||||
});
|
||||
|
||||
const res = await exWrapper.fillOrderAsync(signedOrder, takerAddress);
|
||||
const res = await exchangeWrapper.fillOrderAsync(signedOrder, takerAddress);
|
||||
expect(res.logs).to.have.length(1);
|
||||
const log = res.logs[0] as LogWithDecodedArgs<ExchangeErrorContractEventArgs>;
|
||||
const errCode = log.args.errorId;
|
||||
@@ -658,9 +617,9 @@ describe('Exchange', () => {
|
||||
|
||||
it('should log an error event if no value is filled', async () => {
|
||||
signedOrder = orderFactory.newSignedOrder({});
|
||||
await exWrapper.fillOrderAsync(signedOrder, takerAddress);
|
||||
await exchangeWrapper.fillOrderAsync(signedOrder, takerAddress);
|
||||
|
||||
const res = await exWrapper.fillOrderAsync(signedOrder, takerAddress);
|
||||
const res = await exchangeWrapper.fillOrderAsync(signedOrder, takerAddress);
|
||||
expect(res.logs).to.have.length(1);
|
||||
const log = res.logs[0] as LogWithDecodedArgs<ExchangeErrorContractEventArgs>;
|
||||
const errCode = log.args.errorId;
|
||||
@@ -670,12 +629,14 @@ describe('Exchange', () => {
|
||||
|
||||
describe('cancelOrder', () => {
|
||||
beforeEach(async () => {
|
||||
balances = await dmyBalances.getAsync();
|
||||
erc20Balances = await erc20Wrapper.getBalancesAsync();
|
||||
signedOrder = orderFactory.newSignedOrder();
|
||||
});
|
||||
|
||||
it('should throw if not sent by maker', async () => {
|
||||
return expect(exWrapper.cancelOrderAsync(signedOrder, takerAddress)).to.be.rejectedWith(constants.REVERT);
|
||||
return expect(exchangeWrapper.cancelOrderAsync(signedOrder, takerAddress)).to.be.rejectedWith(
|
||||
constants.REVERT,
|
||||
);
|
||||
});
|
||||
|
||||
it('should throw if makerAssetAmount is 0', async () => {
|
||||
@@ -683,7 +644,9 @@ describe('Exchange', () => {
|
||||
makerAssetAmount: new BigNumber(0),
|
||||
});
|
||||
|
||||
return expect(exWrapper.cancelOrderAsync(signedOrder, makerAddress)).to.be.rejectedWith(constants.REVERT);
|
||||
return expect(exchangeWrapper.cancelOrderAsync(signedOrder, makerAddress)).to.be.rejectedWith(
|
||||
constants.REVERT,
|
||||
);
|
||||
});
|
||||
|
||||
it('should throw if takerAssetAmount is 0', async () => {
|
||||
@@ -691,22 +654,24 @@ describe('Exchange', () => {
|
||||
takerAssetAmount: new BigNumber(0),
|
||||
});
|
||||
|
||||
return expect(exWrapper.cancelOrderAsync(signedOrder, makerAddress)).to.be.rejectedWith(constants.REVERT);
|
||||
return expect(exchangeWrapper.cancelOrderAsync(signedOrder, makerAddress)).to.be.rejectedWith(
|
||||
constants.REVERT,
|
||||
);
|
||||
});
|
||||
|
||||
it('should be able to cancel a full order', async () => {
|
||||
await exWrapper.cancelOrderAsync(signedOrder, makerAddress);
|
||||
await exWrapper.fillOrderAsync(signedOrder, takerAddress, {
|
||||
await exchangeWrapper.cancelOrderAsync(signedOrder, makerAddress);
|
||||
await exchangeWrapper.fillOrderAsync(signedOrder, takerAddress, {
|
||||
takerAssetFillAmount: signedOrder.takerAssetAmount.div(2),
|
||||
});
|
||||
|
||||
const newBalances = await dmyBalances.getAsync();
|
||||
expect(newBalances).to.be.deep.equal(balances);
|
||||
const newBalances = await erc20Wrapper.getBalancesAsync();
|
||||
expect(newBalances).to.be.deep.equal(erc20Balances);
|
||||
});
|
||||
|
||||
it('should log 1 event with correct arguments', async () => {
|
||||
const divisor = 2;
|
||||
const res = await exWrapper.cancelOrderAsync(signedOrder, makerAddress);
|
||||
const res = await exchangeWrapper.cancelOrderAsync(signedOrder, makerAddress);
|
||||
expect(res.logs).to.have.length(1);
|
||||
|
||||
const log = res.logs[0] as LogWithDecodedArgs<CancelContractEventArgs>;
|
||||
@@ -720,9 +685,9 @@ describe('Exchange', () => {
|
||||
});
|
||||
|
||||
it('should log an error if already cancelled', async () => {
|
||||
await exWrapper.cancelOrderAsync(signedOrder, makerAddress);
|
||||
await exchangeWrapper.cancelOrderAsync(signedOrder, makerAddress);
|
||||
|
||||
const res = await exWrapper.cancelOrderAsync(signedOrder, makerAddress);
|
||||
const res = await exchangeWrapper.cancelOrderAsync(signedOrder, makerAddress);
|
||||
expect(res.logs).to.have.length(1);
|
||||
const log = res.logs[0] as LogWithDecodedArgs<ExchangeErrorContractEventArgs>;
|
||||
const errCode = log.args.errorId;
|
||||
@@ -734,7 +699,7 @@ describe('Exchange', () => {
|
||||
expirationTimeSeconds: new BigNumber(Math.floor((Date.now() - 10000) / 1000)),
|
||||
});
|
||||
|
||||
const res = await exWrapper.cancelOrderAsync(signedOrder, makerAddress);
|
||||
const res = await exchangeWrapper.cancelOrderAsync(signedOrder, makerAddress);
|
||||
expect(res.logs).to.have.length(1);
|
||||
const log = res.logs[0] as LogWithDecodedArgs<ExchangeErrorContractEventArgs>;
|
||||
const errCode = log.args.errorId;
|
||||
@@ -745,17 +710,17 @@ describe('Exchange', () => {
|
||||
describe('cancelOrdersUpTo', () => {
|
||||
it('should fail to set makerEpoch less than current makerEpoch', async () => {
|
||||
const makerEpoch = new BigNumber(1);
|
||||
await exWrapper.cancelOrdersUpToAsync(makerEpoch, makerAddress);
|
||||
await exchangeWrapper.cancelOrdersUpToAsync(makerEpoch, makerAddress);
|
||||
const lesserMakerEpoch = new BigNumber(0);
|
||||
return expect(exWrapper.cancelOrdersUpToAsync(lesserMakerEpoch, makerAddress)).to.be.rejectedWith(
|
||||
return expect(exchangeWrapper.cancelOrdersUpToAsync(lesserMakerEpoch, makerAddress)).to.be.rejectedWith(
|
||||
constants.REVERT,
|
||||
);
|
||||
});
|
||||
|
||||
it('should fail to set makerEpoch equal to existing makerEpoch', async () => {
|
||||
const makerEpoch = new BigNumber(1);
|
||||
await exWrapper.cancelOrdersUpToAsync(makerEpoch, makerAddress);
|
||||
return expect(exWrapper.cancelOrdersUpToAsync(makerEpoch, makerAddress)).to.be.rejectedWith(
|
||||
await exchangeWrapper.cancelOrdersUpToAsync(makerEpoch, makerAddress);
|
||||
return expect(exchangeWrapper.cancelOrdersUpToAsync(makerEpoch, makerAddress)).to.be.rejectedWith(
|
||||
constants.REVERT,
|
||||
);
|
||||
});
|
||||
@@ -763,11 +728,11 @@ describe('Exchange', () => {
|
||||
it('should cancel only orders with a makerEpoch less than existing makerEpoch', async () => {
|
||||
// Cancel all transactions with a makerEpoch less than 1
|
||||
const makerEpoch = new BigNumber(1);
|
||||
await exWrapper.cancelOrdersUpToAsync(makerEpoch, makerAddress);
|
||||
await exchangeWrapper.cancelOrdersUpToAsync(makerEpoch, makerAddress);
|
||||
|
||||
// Create 3 orders with makerEpoch values: 0,1,2,3
|
||||
// Since we cancelled with makerEpoch=1, orders with makerEpoch<=1 will not be processed
|
||||
balances = await dmyBalances.getAsync();
|
||||
erc20Balances = await erc20Wrapper.getBalancesAsync();
|
||||
const signedOrders = await Promise.all([
|
||||
orderFactory.newSignedOrder({
|
||||
makerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(9), 18),
|
||||
@@ -790,33 +755,33 @@ describe('Exchange', () => {
|
||||
salt: new BigNumber(3),
|
||||
}),
|
||||
]);
|
||||
await exWrapper.batchFillOrdersNoThrowAsync(signedOrders, takerAddress);
|
||||
await exchangeWrapper.batchFillOrdersNoThrowAsync(signedOrders, takerAddress);
|
||||
|
||||
const newBalances = await dmyBalances.getAsync();
|
||||
const newBalances = await erc20Wrapper.getBalancesAsync();
|
||||
const fillMakerAssetAmount = signedOrders[2].makerAssetAmount.add(signedOrders[3].makerAssetAmount);
|
||||
const fillTakerAssetAmount = signedOrders[2].takerAssetAmount.add(signedOrders[3].takerAssetAmount);
|
||||
const makerFee = signedOrders[2].makerFee.add(signedOrders[3].makerFee);
|
||||
const takerFee = signedOrders[2].takerFee.add(signedOrders[3].takerFee);
|
||||
expect(newBalances[makerAddress][defaultMakerAssetAddress]).to.be.bignumber.equal(
|
||||
balances[makerAddress][defaultMakerAssetAddress].minus(fillMakerAssetAmount),
|
||||
erc20Balances[makerAddress][defaultMakerAssetAddress].minus(fillMakerAssetAmount),
|
||||
);
|
||||
expect(newBalances[makerAddress][defaultTakerAssetAddress]).to.be.bignumber.equal(
|
||||
balances[makerAddress][defaultTakerAssetAddress].add(fillTakerAssetAmount),
|
||||
erc20Balances[makerAddress][defaultTakerAssetAddress].add(fillTakerAssetAmount),
|
||||
);
|
||||
expect(newBalances[makerAddress][zrx.address]).to.be.bignumber.equal(
|
||||
balances[makerAddress][zrx.address].minus(makerFee),
|
||||
erc20Balances[makerAddress][zrx.address].minus(makerFee),
|
||||
);
|
||||
expect(newBalances[takerAddress][defaultTakerAssetAddress]).to.be.bignumber.equal(
|
||||
balances[takerAddress][defaultTakerAssetAddress].minus(fillTakerAssetAmount),
|
||||
erc20Balances[takerAddress][defaultTakerAssetAddress].minus(fillTakerAssetAmount),
|
||||
);
|
||||
expect(newBalances[takerAddress][defaultMakerAssetAddress]).to.be.bignumber.equal(
|
||||
balances[takerAddress][defaultMakerAssetAddress].add(fillMakerAssetAmount),
|
||||
erc20Balances[takerAddress][defaultMakerAssetAddress].add(fillMakerAssetAmount),
|
||||
);
|
||||
expect(newBalances[takerAddress][zrx.address]).to.be.bignumber.equal(
|
||||
balances[takerAddress][zrx.address].minus(takerFee),
|
||||
erc20Balances[takerAddress][zrx.address].minus(takerFee),
|
||||
);
|
||||
expect(newBalances[feeRecipientAddress][zrx.address]).to.be.bignumber.equal(
|
||||
balances[feeRecipientAddress][zrx.address].add(makerFee.add(takerFee)),
|
||||
erc20Balances[feeRecipientAddress][zrx.address].add(makerFee.add(takerFee)),
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -839,7 +804,7 @@ describe('Exchange', () => {
|
||||
expect(initialOwnerTakerAsset).to.be.bignumber.equal(takerAddress);
|
||||
// Call Exchange
|
||||
const takerAssetFillAmount = signedOrder.takerAssetAmount;
|
||||
const res = await exWrapper.fillOrderAsync(signedOrder, takerAddress, { takerAssetFillAmount });
|
||||
const res = await exchangeWrapper.fillOrderAsync(signedOrder, takerAddress, { takerAssetFillAmount });
|
||||
// Verify post-conditions
|
||||
const newOwnerMakerAsset = await erc721Token.ownerOf.callAsync(makerAssetId);
|
||||
expect(newOwnerMakerAsset).to.be.bignumber.equal(takerAddress);
|
||||
@@ -865,7 +830,7 @@ describe('Exchange', () => {
|
||||
// Call Exchange
|
||||
const takerAssetFillAmount = signedOrder.takerAssetAmount;
|
||||
return expect(
|
||||
exWrapper.fillOrderAsync(signedOrder, takerAddress, { takerAssetFillAmount }),
|
||||
exchangeWrapper.fillOrderAsync(signedOrder, takerAddress, { takerAssetFillAmount }),
|
||||
).to.be.rejectedWith(constants.REVERT);
|
||||
});
|
||||
|
||||
@@ -887,7 +852,7 @@ describe('Exchange', () => {
|
||||
// Call Exchange
|
||||
const takerAssetFillAmount = signedOrder.takerAssetAmount;
|
||||
return expect(
|
||||
exWrapper.fillOrderAsync(signedOrder, takerAddress, { takerAssetFillAmount }),
|
||||
exchangeWrapper.fillOrderAsync(signedOrder, takerAddress, { takerAssetFillAmount }),
|
||||
).to.be.rejectedWith(constants.REVERT);
|
||||
});
|
||||
|
||||
@@ -909,7 +874,7 @@ describe('Exchange', () => {
|
||||
// Call Exchange
|
||||
const takerAssetFillAmount = signedOrder.takerAssetAmount;
|
||||
return expect(
|
||||
exWrapper.fillOrderAsync(signedOrder, takerAddress, { takerAssetFillAmount }),
|
||||
exchangeWrapper.fillOrderAsync(signedOrder, takerAddress, { takerAssetFillAmount }),
|
||||
).to.be.rejectedWith(constants.REVERT);
|
||||
});
|
||||
|
||||
@@ -931,7 +896,7 @@ describe('Exchange', () => {
|
||||
// Call Exchange
|
||||
const takerAssetFillAmount = signedOrder.takerAssetAmount;
|
||||
return expect(
|
||||
exWrapper.fillOrderAsync(signedOrder, takerAddress, { takerAssetFillAmount }),
|
||||
exchangeWrapper.fillOrderAsync(signedOrder, takerAddress, { takerAssetFillAmount }),
|
||||
).to.be.rejectedWith(constants.REVERT);
|
||||
});
|
||||
|
||||
@@ -953,7 +918,7 @@ describe('Exchange', () => {
|
||||
// Call Exchange
|
||||
const takerAssetFillAmount = signedOrder.takerAssetAmount;
|
||||
return expect(
|
||||
exWrapper.fillOrderAsync(signedOrder, takerAddress, { takerAssetFillAmount }),
|
||||
exchangeWrapper.fillOrderAsync(signedOrder, takerAddress, { takerAssetFillAmount }),
|
||||
).to.be.rejectedWith(constants.REVERT);
|
||||
});
|
||||
|
||||
@@ -970,28 +935,28 @@ describe('Exchange', () => {
|
||||
const initialOwnerMakerAsset = await erc721Token.ownerOf.callAsync(makerAssetId);
|
||||
expect(initialOwnerMakerAsset).to.be.bignumber.equal(makerAddress);
|
||||
// Call Exchange
|
||||
balances = await dmyBalances.getAsync();
|
||||
erc20Balances = await erc20Wrapper.getBalancesAsync();
|
||||
const takerAssetFillAmount = signedOrder.takerAssetAmount;
|
||||
await exWrapper.fillOrderAsync(signedOrder, takerAddress, { takerAssetFillAmount });
|
||||
await exchangeWrapper.fillOrderAsync(signedOrder, takerAddress, { takerAssetFillAmount });
|
||||
// Verify ERC721 token was transferred from Maker to Taker
|
||||
const newOwnerMakerAsset = await erc721Token.ownerOf.callAsync(makerAssetId);
|
||||
expect(newOwnerMakerAsset).to.be.bignumber.equal(takerAddress);
|
||||
// Verify ERC20 tokens were transferred from Taker to Maker & fees were paid correctly
|
||||
const newBalances = await dmyBalances.getAsync();
|
||||
const newBalances = await erc20Wrapper.getBalancesAsync();
|
||||
expect(newBalances[makerAddress][defaultTakerAssetAddress]).to.be.bignumber.equal(
|
||||
balances[makerAddress][defaultTakerAssetAddress].add(takerAssetFillAmount),
|
||||
erc20Balances[makerAddress][defaultTakerAssetAddress].add(takerAssetFillAmount),
|
||||
);
|
||||
expect(newBalances[takerAddress][defaultTakerAssetAddress]).to.be.bignumber.equal(
|
||||
balances[takerAddress][defaultTakerAssetAddress].minus(takerAssetFillAmount),
|
||||
erc20Balances[takerAddress][defaultTakerAssetAddress].minus(takerAssetFillAmount),
|
||||
);
|
||||
expect(newBalances[makerAddress][zrx.address]).to.be.bignumber.equal(
|
||||
balances[makerAddress][zrx.address].minus(signedOrder.makerFee),
|
||||
erc20Balances[makerAddress][zrx.address].minus(signedOrder.makerFee),
|
||||
);
|
||||
expect(newBalances[takerAddress][zrx.address]).to.be.bignumber.equal(
|
||||
balances[takerAddress][zrx.address].minus(signedOrder.takerFee),
|
||||
erc20Balances[takerAddress][zrx.address].minus(signedOrder.takerFee),
|
||||
);
|
||||
expect(newBalances[feeRecipientAddress][zrx.address]).to.be.bignumber.equal(
|
||||
balances[feeRecipientAddress][zrx.address].add(signedOrder.makerFee.add(signedOrder.takerFee)),
|
||||
erc20Balances[feeRecipientAddress][zrx.address].add(signedOrder.makerFee.add(signedOrder.takerFee)),
|
||||
);
|
||||
});
|
||||
|
||||
@@ -1008,28 +973,28 @@ describe('Exchange', () => {
|
||||
const initialOwnerTakerAsset = await erc721Token.ownerOf.callAsync(takerAssetId);
|
||||
expect(initialOwnerTakerAsset).to.be.bignumber.equal(takerAddress);
|
||||
// Call Exchange
|
||||
balances = await dmyBalances.getAsync();
|
||||
erc20Balances = await erc20Wrapper.getBalancesAsync();
|
||||
const takerAssetFillAmount = signedOrder.takerAssetAmount;
|
||||
await exWrapper.fillOrderAsync(signedOrder, takerAddress, { takerAssetFillAmount });
|
||||
await exchangeWrapper.fillOrderAsync(signedOrder, takerAddress, { takerAssetFillAmount });
|
||||
// Verify ERC721 token was transferred from Taker to Maker
|
||||
const newOwnerTakerAsset = await erc721Token.ownerOf.callAsync(takerAssetId);
|
||||
expect(newOwnerTakerAsset).to.be.bignumber.equal(makerAddress);
|
||||
// Verify ERC20 tokens were transferred from Maker to Taker & fees were paid correctly
|
||||
const newBalances = await dmyBalances.getAsync();
|
||||
const newBalances = await erc20Wrapper.getBalancesAsync();
|
||||
expect(newBalances[takerAddress][defaultMakerAssetAddress]).to.be.bignumber.equal(
|
||||
balances[takerAddress][defaultMakerAssetAddress].add(signedOrder.makerAssetAmount),
|
||||
erc20Balances[takerAddress][defaultMakerAssetAddress].add(signedOrder.makerAssetAmount),
|
||||
);
|
||||
expect(newBalances[makerAddress][defaultMakerAssetAddress]).to.be.bignumber.equal(
|
||||
balances[makerAddress][defaultMakerAssetAddress].minus(signedOrder.makerAssetAmount),
|
||||
erc20Balances[makerAddress][defaultMakerAssetAddress].minus(signedOrder.makerAssetAmount),
|
||||
);
|
||||
expect(newBalances[makerAddress][zrx.address]).to.be.bignumber.equal(
|
||||
balances[makerAddress][zrx.address].minus(signedOrder.makerFee),
|
||||
erc20Balances[makerAddress][zrx.address].minus(signedOrder.makerFee),
|
||||
);
|
||||
expect(newBalances[takerAddress][zrx.address]).to.be.bignumber.equal(
|
||||
balances[takerAddress][zrx.address].minus(signedOrder.takerFee),
|
||||
erc20Balances[takerAddress][zrx.address].minus(signedOrder.takerFee),
|
||||
);
|
||||
expect(newBalances[feeRecipientAddress][zrx.address]).to.be.bignumber.equal(
|
||||
balances[feeRecipientAddress][zrx.address].add(signedOrder.makerFee.add(signedOrder.takerFee)),
|
||||
erc20Balances[feeRecipientAddress][zrx.address].add(signedOrder.makerFee.add(signedOrder.takerFee)),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
import { ZeroEx } from '0x.js';
|
||||
import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils';
|
||||
import { BlockchainLifecycle } from '@0xproject/dev-utils';
|
||||
import { BigNumber } from '@0xproject/utils';
|
||||
import { Web3Wrapper } from '@0xproject/web3-wrapper';
|
||||
import * as chai from 'chai';
|
||||
import ethUtil = require('ethereumjs-util');
|
||||
|
||||
import { ERC20ProxyContract } from '../../src/contract_wrappers/generated/e_r_c20_proxy';
|
||||
import { ExchangeContract } from '../../src/contract_wrappers/generated/exchange';
|
||||
import { addressUtils } from '../../src/utils/address_utils';
|
||||
import { assetProxyUtils } from '../../src/utils/asset_proxy_utils';
|
||||
import { constants } from '../../src/utils/constants';
|
||||
import { ExchangeWrapper } from '../../src/utils/exchange_wrapper';
|
||||
@@ -22,56 +21,42 @@ const expect = chai.expect;
|
||||
|
||||
const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
|
||||
|
||||
describe('Exchange', () => {
|
||||
let makerAddress: string;
|
||||
let feeRecipientAddress: string;
|
||||
|
||||
describe('Exchange helpers', () => {
|
||||
let signedOrder: SignedOrder;
|
||||
let exchangeWrapper: ExchangeWrapper;
|
||||
let orderFactory: OrderFactory;
|
||||
|
||||
before(async () => {
|
||||
const accounts = await web3Wrapper.getAvailableAddressesAsync();
|
||||
[makerAddress, feeRecipientAddress] = accounts;
|
||||
const owner = accounts[0];
|
||||
const tokenRegistry = await deployer.deployAsync(ContractName.TokenRegistry);
|
||||
const [rep, dgd, zrx] = await Promise.all([
|
||||
deployer.deployAsync(ContractName.DummyERC20Token, constants.DUMMY_TOKEN_ARGS),
|
||||
deployer.deployAsync(ContractName.DummyERC20Token, constants.DUMMY_TOKEN_ARGS),
|
||||
deployer.deployAsync(ContractName.DummyERC20Token, constants.DUMMY_TOKEN_ARGS),
|
||||
]);
|
||||
const assetProxyDispatcher = await deployer.deployAsync(ContractName.AssetProxyDispatcher);
|
||||
// Deploy and configure Exchange
|
||||
const makerAddress = accounts[0];
|
||||
const exchangeInstance = await deployer.deployAsync(ContractName.Exchange, [
|
||||
assetProxyDispatcher.address,
|
||||
ZeroEx.NULL_ADDRESS,
|
||||
AssetProxyId.ERC20,
|
||||
]);
|
||||
const exchange = new ExchangeContract(exchangeInstance.abi, exchangeInstance.address, provider);
|
||||
await assetProxyDispatcher.addAuthorizedAddress.sendTransactionAsync(exchange.address, { from: owner });
|
||||
const zeroEx = new ZeroEx(provider, { networkId: constants.TESTRPC_NETWORK_ID });
|
||||
exchangeWrapper = new ExchangeWrapper(exchange, zeroEx);
|
||||
|
||||
const defaultOrderParams = {
|
||||
...constants.STATIC_ORDER_PARAMS,
|
||||
exchangeAddress: exchange.address,
|
||||
makerAddress,
|
||||
feeRecipientAddress,
|
||||
makerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100), 18),
|
||||
takerAssetAmount: ZeroEx.toBaseUnitAmount(new BigNumber(200), 18),
|
||||
makerFee: ZeroEx.toBaseUnitAmount(new BigNumber(1), 18),
|
||||
takerFee: ZeroEx.toBaseUnitAmount(new BigNumber(1), 18),
|
||||
makerAssetData: assetProxyUtils.encodeERC20ProxyData(rep.address),
|
||||
takerAssetData: assetProxyUtils.encodeERC20ProxyData(dgd.address),
|
||||
feeRecipientAddress: addressUtils.generatePseudoRandomAddress(),
|
||||
makerAssetData: assetProxyUtils.encodeERC20ProxyData(addressUtils.generatePseudoRandomAddress()),
|
||||
takerAssetData: assetProxyUtils.encodeERC20ProxyData(addressUtils.generatePseudoRandomAddress()),
|
||||
};
|
||||
const privateKey = constants.TESTRPC_PRIVATE_KEYS[0];
|
||||
const privateKey = constants.TESTRPC_PRIVATE_KEYS[accounts.indexOf(makerAddress)];
|
||||
orderFactory = new OrderFactory(privateKey, defaultOrderParams);
|
||||
signedOrder = orderFactory.newSignedOrder();
|
||||
});
|
||||
|
||||
beforeEach(async () => {
|
||||
await blockchainLifecycle.startAsync();
|
||||
signedOrder = orderFactory.newSignedOrder();
|
||||
});
|
||||
afterEach(async () => {
|
||||
await blockchainLifecycle.revertAsync();
|
||||
});
|
||||
|
||||
describe('getOrderHash', () => {
|
||||
it('should output the correct orderHash', async () => {
|
||||
const orderHashHex = await exchangeWrapper.getOrderHashAsync(signedOrder);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -20,10 +20,9 @@ const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
|
||||
describe('UnlimitedAllowanceToken', () => {
|
||||
let owner: string;
|
||||
let spender: string;
|
||||
const config = {
|
||||
const zeroEx = new ZeroEx(provider, {
|
||||
networkId: constants.TESTRPC_NETWORK_ID,
|
||||
};
|
||||
const zeroEx = new ZeroEx(provider, config);
|
||||
});
|
||||
|
||||
const MAX_MINT_VALUE = new BigNumber(100000000000000000000);
|
||||
let tokenAddress: string;
|
||||
@@ -33,7 +32,10 @@ describe('UnlimitedAllowanceToken', () => {
|
||||
const accounts = await web3Wrapper.getAvailableAddressesAsync();
|
||||
owner = accounts[0];
|
||||
spender = accounts[1];
|
||||
const tokenInstance = await deployer.deployAsync(ContractName.DummyERC20Token, constants.DUMMY_TOKEN_ARGS);
|
||||
const tokenInstance = await deployer.deployAsync(
|
||||
ContractName.DummyERC20Token,
|
||||
constants.DUMMY_ERC20_TOKEN_ARGS,
|
||||
);
|
||||
token = new DummyERC20TokenContract(tokenInstance.abi, tokenInstance.address, provider);
|
||||
await token.mint.sendTransactionAsync(MAX_MINT_VALUE, { from: owner });
|
||||
tokenAddress = token.address;
|
||||
|
||||
Reference in New Issue
Block a user