aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contracts/test
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2018-08-22 18:41:42 +0800
committerFabio Berger <me@fabioberger.com>2018-08-22 18:41:42 +0800
commit0248add542ac801bcb021fa7b13c182baec5612e (patch)
tree1d04404632ee381621b384f1e82ade97c06c9b92 /packages/contracts/test
parentc12f0d04bb2f0d5ad73943d02a592a110423a423 (diff)
parent80e52464a6fdf9576776214f77e46d441b959b06 (diff)
downloaddexon-sol-tools-0248add542ac801bcb021fa7b13c182baec5612e.tar
dexon-sol-tools-0248add542ac801bcb021fa7b13c182baec5612e.tar.gz
dexon-sol-tools-0248add542ac801bcb021fa7b13c182baec5612e.tar.bz2
dexon-sol-tools-0248add542ac801bcb021fa7b13c182baec5612e.tar.lz
dexon-sol-tools-0248add542ac801bcb021fa7b13c182baec5612e.tar.xz
dexon-sol-tools-0248add542ac801bcb021fa7b13c182baec5612e.tar.zst
dexon-sol-tools-0248add542ac801bcb021fa7b13c182baec5612e.zip
Merge development branch
Diffstat (limited to 'packages/contracts/test')
-rw-r--r--packages/contracts/test/asset_proxy/proxies.ts4
-rw-r--r--packages/contracts/test/exchange/core.ts133
-rw-r--r--packages/contracts/test/exchange/dispatcher.ts2
-rw-r--r--packages/contracts/test/exchange/fill_order.ts2
-rw-r--r--packages/contracts/test/exchange/signature_validator.ts2
-rw-r--r--packages/contracts/test/extensions/forwarder.ts (renamed from packages/contracts/test/forwarder/forwarder.ts)2
-rw-r--r--packages/contracts/test/extensions/order_validator.ts600
-rw-r--r--packages/contracts/test/multisig/asset_proxy_owner.ts4
-rw-r--r--packages/contracts/test/tokens/erc721_token.ts279
-rw-r--r--packages/contracts/test/tokens/unlimited_allowance_token.ts2
-rw-r--r--packages/contracts/test/utils/artifacts.ts6
-rw-r--r--packages/contracts/test/utils/erc721_wrapper.ts3
-rw-r--r--packages/contracts/test/utils/exchange_wrapper.ts5
-rw-r--r--packages/contracts/test/utils/fill_order_combinatorial_utils.ts6
-rw-r--r--packages/contracts/test/utils/forwarder_wrapper.ts2
-rw-r--r--packages/contracts/test/utils/log_decoder.ts5
-rw-r--r--packages/contracts/test/utils/multi_sig_wrapper.ts2
17 files changed, 1040 insertions, 19 deletions
diff --git a/packages/contracts/test/asset_proxy/proxies.ts b/packages/contracts/test/asset_proxy/proxies.ts
index 62215f08d..76a020222 100644
--- a/packages/contracts/test/asset_proxy/proxies.ts
+++ b/packages/contracts/test/asset_proxy/proxies.ts
@@ -261,7 +261,7 @@ describe('Asset Transfer Proxies', () => {
erc721Receiver.address,
amount,
);
- const logDecoder = new LogDecoder(web3Wrapper, erc721Receiver.address);
+ const logDecoder = new LogDecoder(web3Wrapper);
const tx = await logDecoder.getTxWithDecodedLogsAsync(
await web3Wrapper.sendTransactionAsync({
to: erc721Proxy.address,
@@ -271,7 +271,7 @@ describe('Asset Transfer Proxies', () => {
}),
);
// Verify that no log was emitted by erc721 receiver
- expect(tx.logs.length).to.be.equal(0);
+ expect(tx.logs.length).to.be.equal(1);
// Verify transfer was successful
const newOwnerMakerAsset = await erc721Token.ownerOf.callAsync(erc721MakerTokenId);
expect(newOwnerMakerAsset).to.be.bignumber.equal(erc721Receiver.address);
diff --git a/packages/contracts/test/exchange/core.ts b/packages/contracts/test/exchange/core.ts
index b324988cc..bc2bad749 100644
--- a/packages/contracts/test/exchange/core.ts
+++ b/packages/contracts/test/exchange/core.ts
@@ -10,6 +10,7 @@ import * as _ from 'lodash';
import { DummyERC20TokenContract } from '../../generated_contract_wrappers/dummy_erc20_token';
import { DummyERC721TokenContract } from '../../generated_contract_wrappers/dummy_erc721_token';
+import { DummyNoReturnERC20TokenContract } from '../../generated_contract_wrappers/dummy_no_return_erc20_token';
import { ERC20ProxyContract } from '../../generated_contract_wrappers/erc20_proxy';
import { ERC721ProxyContract } from '../../generated_contract_wrappers/erc721_proxy';
import { ExchangeCancelEventArgs, ExchangeContract } from '../../generated_contract_wrappers/exchange';
@@ -39,6 +40,7 @@ describe('Exchange core', () => {
let erc20TokenB: DummyERC20TokenContract;
let zrxToken: DummyERC20TokenContract;
let erc721Token: DummyERC721TokenContract;
+ let noReturnErc20Token: DummyNoReturnERC20TokenContract;
let exchange: ExchangeContract;
let erc20Proxy: ERC20ProxyContract;
let erc721Proxy: ERC721ProxyContract;
@@ -161,6 +163,137 @@ describe('Exchange core', () => {
});
});
+ describe('Testing exchange of ERC20 tokens with no return values', () => {
+ before(async () => {
+ noReturnErc20Token = await DummyNoReturnERC20TokenContract.deployFrom0xArtifactAsync(
+ artifacts.DummyNoReturnERC20Token,
+ provider,
+ txDefaults,
+ constants.DUMMY_TOKEN_NAME,
+ constants.DUMMY_TOKEN_SYMBOL,
+ constants.DUMMY_TOKEN_DECIMALS,
+ constants.DUMMY_TOKEN_TOTAL_SUPPLY,
+ );
+ await web3Wrapper.awaitTransactionSuccessAsync(
+ await noReturnErc20Token.setBalance.sendTransactionAsync(makerAddress, constants.INITIAL_ERC20_BALANCE),
+ constants.AWAIT_TRANSACTION_MINED_MS,
+ );
+ await web3Wrapper.awaitTransactionSuccessAsync(
+ await noReturnErc20Token.approve.sendTransactionAsync(
+ erc20Proxy.address,
+ constants.INITIAL_ERC20_ALLOWANCE,
+ { from: makerAddress },
+ ),
+ constants.AWAIT_TRANSACTION_MINED_MS,
+ );
+ });
+ it('should transfer the correct amounts when makerAssetAmount === takerAssetAmount', async () => {
+ signedOrder = await orderFactory.newSignedOrderAsync({
+ makerAssetData: assetDataUtils.encodeERC20AssetData(noReturnErc20Token.address),
+ makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(100), 18),
+ takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(100), 18),
+ });
+
+ const initialMakerBalanceA = await noReturnErc20Token.balanceOf.callAsync(makerAddress);
+ const initialMakerBalanceB = await erc20TokenB.balanceOf.callAsync(makerAddress);
+ const initialMakerZrxBalance = await zrxToken.balanceOf.callAsync(makerAddress);
+ const initialTakerBalanceA = await noReturnErc20Token.balanceOf.callAsync(takerAddress);
+ const initialTakerBalanceB = await erc20TokenB.balanceOf.callAsync(takerAddress);
+ const initialTakerZrxBalance = await zrxToken.balanceOf.callAsync(takerAddress);
+ const initialFeeRecipientZrxBalance = await zrxToken.balanceOf.callAsync(feeRecipientAddress);
+
+ await exchangeWrapper.fillOrderAsync(signedOrder, takerAddress);
+
+ const finalMakerBalanceA = await noReturnErc20Token.balanceOf.callAsync(makerAddress);
+ const finalMakerBalanceB = await erc20TokenB.balanceOf.callAsync(makerAddress);
+ const finalMakerZrxBalance = await zrxToken.balanceOf.callAsync(makerAddress);
+ const finalTakerBalanceA = await noReturnErc20Token.balanceOf.callAsync(takerAddress);
+ const finalTakerBalanceB = await erc20TokenB.balanceOf.callAsync(takerAddress);
+ const finalTakerZrxBalance = await zrxToken.balanceOf.callAsync(takerAddress);
+ const finalFeeRecipientZrxBalance = await zrxToken.balanceOf.callAsync(feeRecipientAddress);
+
+ expect(finalMakerBalanceA).to.be.bignumber.equal(initialMakerBalanceA.minus(signedOrder.makerAssetAmount));
+ expect(finalMakerBalanceB).to.be.bignumber.equal(initialMakerBalanceB.plus(signedOrder.takerAssetAmount));
+ expect(finalTakerBalanceA).to.be.bignumber.equal(initialTakerBalanceA.plus(signedOrder.makerAssetAmount));
+ expect(finalTakerBalanceB).to.be.bignumber.equal(initialTakerBalanceB.minus(signedOrder.takerAssetAmount));
+ expect(finalMakerZrxBalance).to.be.bignumber.equal(initialMakerZrxBalance.minus(signedOrder.makerFee));
+ expect(finalTakerZrxBalance).to.be.bignumber.equal(initialTakerZrxBalance.minus(signedOrder.takerFee));
+ expect(finalFeeRecipientZrxBalance).to.be.bignumber.equal(
+ initialFeeRecipientZrxBalance.plus(signedOrder.makerFee.plus(signedOrder.takerFee)),
+ );
+ });
+ it('should transfer the correct amounts when makerAssetAmount > takerAssetAmount', async () => {
+ signedOrder = await orderFactory.newSignedOrderAsync({
+ makerAssetData: assetDataUtils.encodeERC20AssetData(noReturnErc20Token.address),
+ makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(200), 18),
+ takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(100), 18),
+ });
+
+ const initialMakerBalanceA = await noReturnErc20Token.balanceOf.callAsync(makerAddress);
+ const initialMakerBalanceB = await erc20TokenB.balanceOf.callAsync(makerAddress);
+ const initialMakerZrxBalance = await zrxToken.balanceOf.callAsync(makerAddress);
+ const initialTakerBalanceA = await noReturnErc20Token.balanceOf.callAsync(takerAddress);
+ const initialTakerBalanceB = await erc20TokenB.balanceOf.callAsync(takerAddress);
+ const initialTakerZrxBalance = await zrxToken.balanceOf.callAsync(takerAddress);
+ const initialFeeRecipientZrxBalance = await zrxToken.balanceOf.callAsync(feeRecipientAddress);
+
+ await exchangeWrapper.fillOrderAsync(signedOrder, takerAddress);
+
+ const finalMakerBalanceA = await noReturnErc20Token.balanceOf.callAsync(makerAddress);
+ const finalMakerBalanceB = await erc20TokenB.balanceOf.callAsync(makerAddress);
+ const finalMakerZrxBalance = await zrxToken.balanceOf.callAsync(makerAddress);
+ const finalTakerBalanceA = await noReturnErc20Token.balanceOf.callAsync(takerAddress);
+ const finalTakerBalanceB = await erc20TokenB.balanceOf.callAsync(takerAddress);
+ const finalTakerZrxBalance = await zrxToken.balanceOf.callAsync(takerAddress);
+ const finalFeeRecipientZrxBalance = await zrxToken.balanceOf.callAsync(feeRecipientAddress);
+
+ expect(finalMakerBalanceA).to.be.bignumber.equal(initialMakerBalanceA.minus(signedOrder.makerAssetAmount));
+ expect(finalMakerBalanceB).to.be.bignumber.equal(initialMakerBalanceB.plus(signedOrder.takerAssetAmount));
+ expect(finalTakerBalanceA).to.be.bignumber.equal(initialTakerBalanceA.plus(signedOrder.makerAssetAmount));
+ expect(finalTakerBalanceB).to.be.bignumber.equal(initialTakerBalanceB.minus(signedOrder.takerAssetAmount));
+ expect(finalMakerZrxBalance).to.be.bignumber.equal(initialMakerZrxBalance.minus(signedOrder.makerFee));
+ expect(finalTakerZrxBalance).to.be.bignumber.equal(initialTakerZrxBalance.minus(signedOrder.takerFee));
+ expect(finalFeeRecipientZrxBalance).to.be.bignumber.equal(
+ initialFeeRecipientZrxBalance.plus(signedOrder.makerFee.plus(signedOrder.takerFee)),
+ );
+ });
+ it('should transfer the correct amounts when makerAssetAmount < takerAssetAmount', async () => {
+ signedOrder = await orderFactory.newSignedOrderAsync({
+ makerAssetData: assetDataUtils.encodeERC20AssetData(noReturnErc20Token.address),
+ makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(100), 18),
+ takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(200), 18),
+ });
+
+ const initialMakerBalanceA = await noReturnErc20Token.balanceOf.callAsync(makerAddress);
+ const initialMakerBalanceB = await erc20TokenB.balanceOf.callAsync(makerAddress);
+ const initialMakerZrxBalance = await zrxToken.balanceOf.callAsync(makerAddress);
+ const initialTakerBalanceA = await noReturnErc20Token.balanceOf.callAsync(takerAddress);
+ const initialTakerBalanceB = await erc20TokenB.balanceOf.callAsync(takerAddress);
+ const initialTakerZrxBalance = await zrxToken.balanceOf.callAsync(takerAddress);
+ const initialFeeRecipientZrxBalance = await zrxToken.balanceOf.callAsync(feeRecipientAddress);
+
+ await exchangeWrapper.fillOrderAsync(signedOrder, takerAddress);
+
+ const finalMakerBalanceA = await noReturnErc20Token.balanceOf.callAsync(makerAddress);
+ const finalMakerBalanceB = await erc20TokenB.balanceOf.callAsync(makerAddress);
+ const finalMakerZrxBalance = await zrxToken.balanceOf.callAsync(makerAddress);
+ const finalTakerBalanceA = await noReturnErc20Token.balanceOf.callAsync(takerAddress);
+ const finalTakerBalanceB = await erc20TokenB.balanceOf.callAsync(takerAddress);
+ const finalTakerZrxBalance = await zrxToken.balanceOf.callAsync(takerAddress);
+ const finalFeeRecipientZrxBalance = await zrxToken.balanceOf.callAsync(feeRecipientAddress);
+
+ expect(finalMakerBalanceA).to.be.bignumber.equal(initialMakerBalanceA.minus(signedOrder.makerAssetAmount));
+ expect(finalMakerBalanceB).to.be.bignumber.equal(initialMakerBalanceB.plus(signedOrder.takerAssetAmount));
+ expect(finalTakerBalanceA).to.be.bignumber.equal(initialTakerBalanceA.plus(signedOrder.makerAssetAmount));
+ expect(finalTakerBalanceB).to.be.bignumber.equal(initialTakerBalanceB.minus(signedOrder.takerAssetAmount));
+ expect(finalMakerZrxBalance).to.be.bignumber.equal(initialMakerZrxBalance.minus(signedOrder.makerFee));
+ expect(finalTakerZrxBalance).to.be.bignumber.equal(initialTakerZrxBalance.minus(signedOrder.takerFee));
+ expect(finalFeeRecipientZrxBalance).to.be.bignumber.equal(
+ initialFeeRecipientZrxBalance.plus(signedOrder.makerFee.plus(signedOrder.takerFee)),
+ );
+ });
+ });
+
describe('cancelOrder', () => {
beforeEach(async () => {
erc20Balances = await erc20Wrapper.getBalancesAsync();
diff --git a/packages/contracts/test/exchange/dispatcher.ts b/packages/contracts/test/exchange/dispatcher.ts
index 81d142ca4..81871a680 100644
--- a/packages/contracts/test/exchange/dispatcher.ts
+++ b/packages/contracts/test/exchange/dispatcher.ts
@@ -145,7 +145,7 @@ describe('AssetProxyDispatcher', () => {
});
it('should log an event with correct arguments when an asset proxy is registered', async () => {
- const logDecoder = new LogDecoder(web3Wrapper, assetProxyDispatcher.address);
+ const logDecoder = new LogDecoder(web3Wrapper);
const txReceipt = await logDecoder.getTxWithDecodedLogsAsync(
await assetProxyDispatcher.registerAssetProxy.sendTransactionAsync(erc20Proxy.address, { from: owner }),
);
diff --git a/packages/contracts/test/exchange/fill_order.ts b/packages/contracts/test/exchange/fill_order.ts
index e79e2239e..b1e08324f 100644
--- a/packages/contracts/test/exchange/fill_order.ts
+++ b/packages/contracts/test/exchange/fill_order.ts
@@ -231,7 +231,7 @@ describe('FillOrder Tests', () => {
});
});
- describe('Testing Exchange of ERC721 Tokens', () => {
+ describe('Testing exchange of ERC721 Tokens', () => {
it('should successfully exchange a single token between the maker and taker (via fillOrder)', async () => {
const fillScenario = {
...defaultFillScenario,
diff --git a/packages/contracts/test/exchange/signature_validator.ts b/packages/contracts/test/exchange/signature_validator.ts
index 7bac2bdef..e95b70b62 100644
--- a/packages/contracts/test/exchange/signature_validator.ts
+++ b/packages/contracts/test/exchange/signature_validator.ts
@@ -65,7 +65,7 @@ describe('MixinSignatureValidator', () => {
txDefaults,
signerAddress,
);
- signatureValidatorLogDecoder = new LogDecoder(web3Wrapper, signatureValidator.address);
+ signatureValidatorLogDecoder = new LogDecoder(web3Wrapper);
await web3Wrapper.awaitTransactionSuccessAsync(
await signatureValidator.setSignatureValidatorApproval.sendTransactionAsync(testValidator.address, true, {
from: signerAddress,
diff --git a/packages/contracts/test/forwarder/forwarder.ts b/packages/contracts/test/extensions/forwarder.ts
index 28ffdeabe..18101d684 100644
--- a/packages/contracts/test/forwarder/forwarder.ts
+++ b/packages/contracts/test/extensions/forwarder.ts
@@ -131,8 +131,6 @@ describe(ContractName.Forwarder, () => {
provider,
txDefaults,
exchangeInstance.address,
- wethContract.address,
- zrxToken.address,
zrxAssetData,
wethAssetData,
);
diff --git a/packages/contracts/test/extensions/order_validator.ts b/packages/contracts/test/extensions/order_validator.ts
new file mode 100644
index 000000000..3a57cfc37
--- /dev/null
+++ b/packages/contracts/test/extensions/order_validator.ts
@@ -0,0 +1,600 @@
+import { BlockchainLifecycle } from '@0xproject/dev-utils';
+import { assetDataUtils, orderHashUtils } from '@0xproject/order-utils';
+import { SignedOrder } from '@0xproject/types';
+import { BigNumber } from '@0xproject/utils';
+import * as chai from 'chai';
+import * as _ from 'lodash';
+
+import { DummyERC20TokenContract } from '../../generated_contract_wrappers/dummy_erc20_token';
+import { DummyERC721TokenContract } from '../../generated_contract_wrappers/dummy_erc721_token';
+import { ERC20ProxyContract } from '../../generated_contract_wrappers/erc20_proxy';
+import { ERC721ProxyContract } from '../../generated_contract_wrappers/erc721_proxy';
+import { ExchangeContract } from '../../generated_contract_wrappers/exchange';
+import { OrderValidatorContract } from '../../generated_contract_wrappers/order_validator';
+import { artifacts } from '../utils/artifacts';
+import { chaiSetup } from '../utils/chai_setup';
+import { constants } from '../utils/constants';
+import { ERC20Wrapper } from '../utils/erc20_wrapper';
+import { ERC721Wrapper } from '../utils/erc721_wrapper';
+import { ExchangeWrapper } from '../utils/exchange_wrapper';
+import { OrderFactory } from '../utils/order_factory';
+import { OrderStatus } from '../utils/types';
+import { provider, txDefaults, web3Wrapper } from '../utils/web3_wrapper';
+
+chaiSetup.configure();
+const expect = chai.expect;
+const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
+
+describe('OrderValidator', () => {
+ let makerAddress: string;
+ let owner: string;
+ let takerAddress: string;
+ let erc20AssetData: string;
+ let erc721AssetData: string;
+
+ let erc20Token: DummyERC20TokenContract;
+ let zrxToken: DummyERC20TokenContract;
+ let erc721Token: DummyERC721TokenContract;
+ let exchange: ExchangeContract;
+ let orderValidator: OrderValidatorContract;
+ let erc20Proxy: ERC20ProxyContract;
+ let erc721Proxy: ERC721ProxyContract;
+
+ let signedOrder: SignedOrder;
+ let signedOrder2: SignedOrder;
+ let orderFactory: OrderFactory;
+
+ const tokenId = new BigNumber(123456789);
+ const tokenId2 = new BigNumber(987654321);
+ const ERC721_BALANCE = new BigNumber(1);
+ const ERC721_ALLOWANCE = new BigNumber(1);
+
+ before(async () => {
+ await blockchainLifecycle.startAsync();
+ });
+ after(async () => {
+ await blockchainLifecycle.revertAsync();
+ });
+
+ before(async () => {
+ const accounts = await web3Wrapper.getAvailableAddressesAsync();
+ const usedAddresses = ([owner, makerAddress, takerAddress] = _.slice(accounts, 0, 3));
+
+ const erc20Wrapper = new ERC20Wrapper(provider, usedAddresses, owner);
+ const erc721Wrapper = new ERC721Wrapper(provider, usedAddresses, owner);
+
+ const numDummyErc20ToDeploy = 2;
+ [erc20Token, zrxToken] = await erc20Wrapper.deployDummyTokensAsync(
+ numDummyErc20ToDeploy,
+ constants.DUMMY_TOKEN_DECIMALS,
+ );
+ erc20Proxy = await erc20Wrapper.deployProxyAsync();
+
+ [erc721Token] = await erc721Wrapper.deployDummyTokensAsync();
+ erc721Proxy = await erc721Wrapper.deployProxyAsync();
+
+ const zrxAssetData = assetDataUtils.encodeERC20AssetData(zrxToken.address);
+ exchange = await ExchangeContract.deployFrom0xArtifactAsync(
+ artifacts.Exchange,
+ provider,
+ txDefaults,
+ zrxAssetData,
+ );
+ const exchangeWrapper = new ExchangeWrapper(exchange, provider);
+ await exchangeWrapper.registerAssetProxyAsync(erc20Proxy.address, owner);
+ await exchangeWrapper.registerAssetProxyAsync(erc721Proxy.address, owner);
+
+ orderValidator = await OrderValidatorContract.deployFrom0xArtifactAsync(
+ artifacts.OrderValidator,
+ provider,
+ txDefaults,
+ exchange.address,
+ zrxAssetData,
+ );
+
+ erc20AssetData = assetDataUtils.encodeERC20AssetData(erc20Token.address);
+ erc721AssetData = assetDataUtils.encodeERC721AssetData(erc721Token.address, tokenId);
+ const defaultOrderParams = {
+ ...constants.STATIC_ORDER_PARAMS,
+ exchangeAddress: exchange.address,
+ makerAddress,
+ feeRecipientAddress: constants.NULL_ADDRESS,
+ makerAssetData: erc20AssetData,
+ takerAssetData: erc721AssetData,
+ };
+ const privateKey = constants.TESTRPC_PRIVATE_KEYS[accounts.indexOf(makerAddress)];
+ orderFactory = new OrderFactory(privateKey, defaultOrderParams);
+ });
+
+ beforeEach(async () => {
+ await blockchainLifecycle.startAsync();
+ });
+ afterEach(async () => {
+ await blockchainLifecycle.revertAsync();
+ });
+
+ describe('getBalanceAndAllowance', () => {
+ describe('getERC721TokenOwner', async () => {
+ it('should return the null address when tokenId is not owned', async () => {
+ const tokenOwner = await orderValidator.getERC721TokenOwner.callAsync(makerAddress, tokenId);
+ expect(tokenOwner).to.be.equal(constants.NULL_ADDRESS);
+ });
+ it('should return the owner address when tokenId is owned', async () => {
+ await web3Wrapper.awaitTransactionSuccessAsync(
+ await erc721Token.mint.sendTransactionAsync(makerAddress, tokenId),
+ constants.AWAIT_TRANSACTION_MINED_MS,
+ );
+ const tokenOwner = await orderValidator.getERC721TokenOwner.callAsync(erc721Token.address, tokenId);
+ expect(tokenOwner).to.be.equal(makerAddress);
+ });
+ });
+ describe('ERC20 assetData', () => {
+ it('should return the correct balances and allowances when both values are 0', async () => {
+ const [newBalance, newAllowance] = await orderValidator.getBalanceAndAllowance.callAsync(
+ makerAddress,
+ erc20AssetData,
+ );
+ expect(constants.ZERO_AMOUNT).to.be.bignumber.equal(newBalance);
+ expect(constants.ZERO_AMOUNT).to.be.bignumber.equal(newAllowance);
+ });
+ it('should return the correct balance and allowance when both values are non-zero', async () => {
+ const balance = new BigNumber(123);
+ const allowance = new BigNumber(456);
+ await web3Wrapper.awaitTransactionSuccessAsync(
+ await erc20Token.setBalance.sendTransactionAsync(makerAddress, balance),
+ constants.AWAIT_TRANSACTION_MINED_MS,
+ );
+ await web3Wrapper.awaitTransactionSuccessAsync(
+ await erc20Token.approve.sendTransactionAsync(erc20Proxy.address, allowance, {
+ from: makerAddress,
+ }),
+ constants.AWAIT_TRANSACTION_MINED_MS,
+ );
+ const [newBalance, newAllowance] = await orderValidator.getBalanceAndAllowance.callAsync(
+ makerAddress,
+ erc20AssetData,
+ );
+ expect(balance).to.be.bignumber.equal(newBalance);
+ expect(allowance).to.be.bignumber.equal(newAllowance);
+ });
+ });
+ describe('ERC721 assetData', () => {
+ it('should return a balance of 0 when the tokenId is not owned by target', async () => {
+ const [newBalance] = await orderValidator.getBalanceAndAllowance.callAsync(
+ makerAddress,
+ erc721AssetData,
+ );
+ expect(newBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
+ });
+ it('should return an allowance of 0 when no approval is set', async () => {
+ const [, newAllowance] = await orderValidator.getBalanceAndAllowance.callAsync(
+ makerAddress,
+ erc721AssetData,
+ );
+ expect(newAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
+ });
+ it('should return a balance of 1 when the tokenId is owned by target', async () => {
+ await web3Wrapper.awaitTransactionSuccessAsync(
+ await erc721Token.mint.sendTransactionAsync(makerAddress, tokenId),
+ constants.AWAIT_TRANSACTION_MINED_MS,
+ );
+ const [newBalance] = await orderValidator.getBalanceAndAllowance.callAsync(
+ makerAddress,
+ erc721AssetData,
+ );
+ expect(newBalance).to.be.bignumber.equal(ERC721_BALANCE);
+ });
+ it('should return an allowance of 1 when ERC721Proxy is approved for all', async () => {
+ const isApproved = true;
+ await web3Wrapper.awaitTransactionSuccessAsync(
+ await erc721Token.setApprovalForAll.sendTransactionAsync(erc721Proxy.address, isApproved, {
+ from: makerAddress,
+ }),
+ constants.AWAIT_TRANSACTION_MINED_MS,
+ );
+ const [, newAllowance] = await orderValidator.getBalanceAndAllowance.callAsync(
+ makerAddress,
+ erc721AssetData,
+ );
+ expect(newAllowance).to.be.bignumber.equal(ERC721_ALLOWANCE);
+ });
+ it('should return an allowance of 1 when ERC721Proxy is approved for specific tokenId', async () => {
+ await web3Wrapper.awaitTransactionSuccessAsync(
+ await erc721Token.mint.sendTransactionAsync(makerAddress, tokenId),
+ constants.AWAIT_TRANSACTION_MINED_MS,
+ );
+ await web3Wrapper.awaitTransactionSuccessAsync(
+ await erc721Token.approve.sendTransactionAsync(erc721Proxy.address, tokenId, {
+ from: makerAddress,
+ }),
+ constants.AWAIT_TRANSACTION_MINED_MS,
+ );
+ const [, newAllowance] = await orderValidator.getBalanceAndAllowance.callAsync(
+ makerAddress,
+ erc721AssetData,
+ );
+ expect(newAllowance).to.be.bignumber.equal(ERC721_ALLOWANCE);
+ });
+ });
+ });
+ describe('getBalancesAndAllowances', () => {
+ it('should return the correct balances and allowances when all values are 0', async () => {
+ const [
+ [erc20Balance, erc721Balance],
+ [erc20Allowance, erc721Allowance],
+ ] = await orderValidator.getBalancesAndAllowances.callAsync(makerAddress, [
+ erc20AssetData,
+ erc721AssetData,
+ ]);
+ expect(erc20Balance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
+ expect(erc721Balance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
+ expect(erc20Allowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
+ expect(erc721Allowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
+ });
+ it('should return the correct balances and allowances when balances and allowances are non-zero', async () => {
+ const balance = new BigNumber(123);
+ const allowance = new BigNumber(456);
+ await web3Wrapper.awaitTransactionSuccessAsync(
+ await erc20Token.setBalance.sendTransactionAsync(makerAddress, balance),
+ constants.AWAIT_TRANSACTION_MINED_MS,
+ );
+ await web3Wrapper.awaitTransactionSuccessAsync(
+ await erc20Token.approve.sendTransactionAsync(erc20Proxy.address, allowance, {
+ from: makerAddress,
+ }),
+ constants.AWAIT_TRANSACTION_MINED_MS,
+ );
+ await web3Wrapper.awaitTransactionSuccessAsync(
+ await erc721Token.mint.sendTransactionAsync(makerAddress, tokenId),
+ constants.AWAIT_TRANSACTION_MINED_MS,
+ );
+ await web3Wrapper.awaitTransactionSuccessAsync(
+ await erc721Token.approve.sendTransactionAsync(erc721Proxy.address, tokenId, {
+ from: makerAddress,
+ }),
+ constants.AWAIT_TRANSACTION_MINED_MS,
+ );
+ const [
+ [erc20Balance, erc721Balance],
+ [erc20Allowance, erc721Allowance],
+ ] = await orderValidator.getBalancesAndAllowances.callAsync(makerAddress, [
+ erc20AssetData,
+ erc721AssetData,
+ ]);
+ expect(erc20Balance).to.be.bignumber.equal(balance);
+ expect(erc721Balance).to.be.bignumber.equal(ERC721_BALANCE);
+ expect(erc20Allowance).to.be.bignumber.equal(allowance);
+ expect(erc721Allowance).to.be.bignumber.equal(ERC721_ALLOWANCE);
+ });
+ });
+ describe('getTraderInfo', () => {
+ beforeEach(async () => {
+ signedOrder = await orderFactory.newSignedOrderAsync();
+ });
+ it('should return the correct info when no balances or allowances are set', async () => {
+ const traderInfo = await orderValidator.getTraderInfo.callAsync(signedOrder, takerAddress);
+ expect(traderInfo.makerBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
+ expect(traderInfo.makerAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
+ expect(traderInfo.takerBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
+ expect(traderInfo.takerAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
+ expect(traderInfo.makerZrxBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
+ expect(traderInfo.makerZrxAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
+ expect(traderInfo.takerZrxBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
+ expect(traderInfo.takerZrxAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
+ });
+ it('should return the correct info when balances and allowances are set', async () => {
+ const makerBalance = new BigNumber(123);
+ const makerAllowance = new BigNumber(456);
+ const makerZrxBalance = new BigNumber(789);
+ const takerZrxAllowance = new BigNumber(987);
+ await web3Wrapper.awaitTransactionSuccessAsync(
+ await erc20Token.setBalance.sendTransactionAsync(makerAddress, makerBalance),
+ constants.AWAIT_TRANSACTION_MINED_MS,
+ );
+ await web3Wrapper.awaitTransactionSuccessAsync(
+ await erc20Token.approve.sendTransactionAsync(erc20Proxy.address, makerAllowance, {
+ from: makerAddress,
+ }),
+ constants.AWAIT_TRANSACTION_MINED_MS,
+ );
+ await web3Wrapper.awaitTransactionSuccessAsync(
+ await zrxToken.setBalance.sendTransactionAsync(makerAddress, makerZrxBalance),
+ constants.AWAIT_TRANSACTION_MINED_MS,
+ );
+ await web3Wrapper.awaitTransactionSuccessAsync(
+ await zrxToken.approve.sendTransactionAsync(erc20Proxy.address, takerZrxAllowance, {
+ from: takerAddress,
+ }),
+ constants.AWAIT_TRANSACTION_MINED_MS,
+ );
+ await web3Wrapper.awaitTransactionSuccessAsync(
+ await erc721Token.mint.sendTransactionAsync(takerAddress, tokenId),
+ constants.AWAIT_TRANSACTION_MINED_MS,
+ );
+ await web3Wrapper.awaitTransactionSuccessAsync(
+ await erc721Token.approve.sendTransactionAsync(erc721Proxy.address, tokenId, {
+ from: takerAddress,
+ }),
+ constants.AWAIT_TRANSACTION_MINED_MS,
+ );
+ const traderInfo = await orderValidator.getTraderInfo.callAsync(signedOrder, takerAddress);
+ expect(traderInfo.makerBalance).to.be.bignumber.equal(makerBalance);
+ expect(traderInfo.makerAllowance).to.be.bignumber.equal(makerAllowance);
+ expect(traderInfo.takerBalance).to.be.bignumber.equal(ERC721_BALANCE);
+ expect(traderInfo.takerAllowance).to.be.bignumber.equal(ERC721_ALLOWANCE);
+ expect(traderInfo.makerZrxBalance).to.be.bignumber.equal(makerZrxBalance);
+ expect(traderInfo.makerZrxAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
+ expect(traderInfo.takerZrxBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
+ expect(traderInfo.takerZrxAllowance).to.be.bignumber.equal(takerZrxAllowance);
+ });
+ });
+ describe('getTradersInfo', () => {
+ beforeEach(async () => {
+ signedOrder = await orderFactory.newSignedOrderAsync();
+ signedOrder2 = await orderFactory.newSignedOrderAsync({
+ takerAssetData: assetDataUtils.encodeERC721AssetData(erc721Token.address, tokenId2),
+ });
+ });
+ it('should return the correct info when no balances or allowances have been set', async () => {
+ const orders = [signedOrder, signedOrder2];
+ const takers = [takerAddress, takerAddress];
+ const [traderInfo1, traderInfo2] = await orderValidator.getTradersInfo.callAsync(orders, takers);
+ expect(traderInfo1.makerBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
+ expect(traderInfo1.makerAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
+ expect(traderInfo1.takerBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
+ expect(traderInfo1.takerAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
+ expect(traderInfo1.makerZrxBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
+ expect(traderInfo1.makerZrxAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
+ expect(traderInfo1.takerZrxBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
+ expect(traderInfo1.takerZrxAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
+ expect(traderInfo2.makerBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
+ expect(traderInfo2.makerAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
+ expect(traderInfo2.takerBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
+ expect(traderInfo2.takerAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
+ expect(traderInfo2.makerZrxBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
+ expect(traderInfo2.makerZrxAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
+ expect(traderInfo2.takerZrxBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
+ expect(traderInfo2.takerZrxAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
+ });
+ it('should return the correct info when balances and allowances are set', async () => {
+ const makerBalance = new BigNumber(123);
+ const makerAllowance = new BigNumber(456);
+ const makerZrxBalance = new BigNumber(789);
+ const takerZrxAllowance = new BigNumber(987);
+ await web3Wrapper.awaitTransactionSuccessAsync(
+ await erc20Token.setBalance.sendTransactionAsync(makerAddress, makerBalance),
+ constants.AWAIT_TRANSACTION_MINED_MS,
+ );
+ await web3Wrapper.awaitTransactionSuccessAsync(
+ await erc20Token.approve.sendTransactionAsync(erc20Proxy.address, makerAllowance, {
+ from: makerAddress,
+ }),
+ constants.AWAIT_TRANSACTION_MINED_MS,
+ );
+ await web3Wrapper.awaitTransactionSuccessAsync(
+ await zrxToken.setBalance.sendTransactionAsync(makerAddress, makerZrxBalance),
+ constants.AWAIT_TRANSACTION_MINED_MS,
+ );
+ await web3Wrapper.awaitTransactionSuccessAsync(
+ await zrxToken.approve.sendTransactionAsync(erc20Proxy.address, takerZrxAllowance, {
+ from: takerAddress,
+ }),
+ constants.AWAIT_TRANSACTION_MINED_MS,
+ );
+ const isApproved = true;
+ await web3Wrapper.awaitTransactionSuccessAsync(
+ await erc721Token.setApprovalForAll.sendTransactionAsync(erc721Proxy.address, isApproved, {
+ from: takerAddress,
+ }),
+ constants.AWAIT_TRANSACTION_MINED_MS,
+ );
+ await web3Wrapper.awaitTransactionSuccessAsync(
+ await erc721Token.mint.sendTransactionAsync(takerAddress, tokenId2),
+ constants.AWAIT_TRANSACTION_MINED_MS,
+ );
+ const orders = [signedOrder, signedOrder2];
+ const takers = [takerAddress, takerAddress];
+ const [traderInfo1, traderInfo2] = await orderValidator.getTradersInfo.callAsync(orders, takers);
+
+ expect(traderInfo1.makerBalance).to.be.bignumber.equal(makerBalance);
+ expect(traderInfo1.makerAllowance).to.be.bignumber.equal(makerAllowance);
+ expect(traderInfo1.takerBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
+ expect(traderInfo1.takerAllowance).to.be.bignumber.equal(ERC721_ALLOWANCE);
+ expect(traderInfo1.makerZrxBalance).to.be.bignumber.equal(makerZrxBalance);
+ expect(traderInfo1.makerZrxAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
+ expect(traderInfo1.takerZrxBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
+ expect(traderInfo1.takerZrxAllowance).to.be.bignumber.equal(takerZrxAllowance);
+ expect(traderInfo2.makerBalance).to.be.bignumber.equal(makerBalance);
+ expect(traderInfo2.makerAllowance).to.be.bignumber.equal(makerAllowance);
+ expect(traderInfo2.takerBalance).to.be.bignumber.equal(ERC721_BALANCE);
+ expect(traderInfo2.takerAllowance).to.be.bignumber.equal(ERC721_ALLOWANCE);
+ expect(traderInfo2.makerZrxBalance).to.be.bignumber.equal(makerZrxBalance);
+ expect(traderInfo2.makerZrxAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
+ expect(traderInfo2.takerZrxBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
+ expect(traderInfo2.takerZrxAllowance).to.be.bignumber.equal(takerZrxAllowance);
+ });
+ });
+ describe('getOrderAndTraderInfo', () => {
+ beforeEach(async () => {
+ signedOrder = await orderFactory.newSignedOrderAsync();
+ });
+ it('should return the correct info when no balances or allowances are set', async () => {
+ const [orderInfo, traderInfo] = await orderValidator.getOrderAndTraderInfo.callAsync(
+ signedOrder,
+ takerAddress,
+ );
+ const expectedOrderHash = orderHashUtils.getOrderHashHex(signedOrder);
+ expect(orderInfo.orderStatus).to.be.equal(OrderStatus.FILLABLE);
+ expect(orderInfo.orderHash).to.be.equal(expectedOrderHash);
+ expect(orderInfo.orderTakerAssetFilledAmount).to.be.bignumber.equal(constants.ZERO_AMOUNT);
+ expect(traderInfo.makerBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
+ expect(traderInfo.makerAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
+ expect(traderInfo.takerBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
+ expect(traderInfo.takerAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
+ expect(traderInfo.makerZrxBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
+ expect(traderInfo.makerZrxAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
+ expect(traderInfo.takerZrxBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
+ expect(traderInfo.takerZrxAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
+ });
+ it('should return the correct info when balances and allowances are set', async () => {
+ const makerBalance = new BigNumber(123);
+ const makerAllowance = new BigNumber(456);
+ const makerZrxBalance = new BigNumber(789);
+ const takerZrxAllowance = new BigNumber(987);
+ await web3Wrapper.awaitTransactionSuccessAsync(
+ await erc20Token.setBalance.sendTransactionAsync(makerAddress, makerBalance),
+ constants.AWAIT_TRANSACTION_MINED_MS,
+ );
+ await web3Wrapper.awaitTransactionSuccessAsync(
+ await erc20Token.approve.sendTransactionAsync(erc20Proxy.address, makerAllowance, {
+ from: makerAddress,
+ }),
+ constants.AWAIT_TRANSACTION_MINED_MS,
+ );
+ await web3Wrapper.awaitTransactionSuccessAsync(
+ await zrxToken.setBalance.sendTransactionAsync(makerAddress, makerZrxBalance),
+ constants.AWAIT_TRANSACTION_MINED_MS,
+ );
+ await web3Wrapper.awaitTransactionSuccessAsync(
+ await zrxToken.approve.sendTransactionAsync(erc20Proxy.address, takerZrxAllowance, {
+ from: takerAddress,
+ }),
+ constants.AWAIT_TRANSACTION_MINED_MS,
+ );
+ await web3Wrapper.awaitTransactionSuccessAsync(
+ await erc721Token.mint.sendTransactionAsync(takerAddress, tokenId),
+ constants.AWAIT_TRANSACTION_MINED_MS,
+ );
+ await web3Wrapper.awaitTransactionSuccessAsync(
+ await erc721Token.approve.sendTransactionAsync(erc721Proxy.address, tokenId, {
+ from: takerAddress,
+ }),
+ constants.AWAIT_TRANSACTION_MINED_MS,
+ );
+ const [orderInfo, traderInfo] = await orderValidator.getOrderAndTraderInfo.callAsync(
+ signedOrder,
+ takerAddress,
+ );
+ const expectedOrderHash = orderHashUtils.getOrderHashHex(signedOrder);
+ expect(orderInfo.orderStatus).to.be.equal(OrderStatus.FILLABLE);
+ expect(orderInfo.orderHash).to.be.equal(expectedOrderHash);
+ expect(orderInfo.orderTakerAssetFilledAmount).to.be.bignumber.equal(constants.ZERO_AMOUNT);
+ expect(traderInfo.makerBalance).to.be.bignumber.equal(makerBalance);
+ expect(traderInfo.makerAllowance).to.be.bignumber.equal(makerAllowance);
+ expect(traderInfo.takerBalance).to.be.bignumber.equal(ERC721_BALANCE);
+ expect(traderInfo.takerAllowance).to.be.bignumber.equal(ERC721_ALLOWANCE);
+ expect(traderInfo.makerZrxBalance).to.be.bignumber.equal(makerZrxBalance);
+ expect(traderInfo.makerZrxAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
+ expect(traderInfo.takerZrxBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
+ expect(traderInfo.takerZrxAllowance).to.be.bignumber.equal(takerZrxAllowance);
+ });
+ });
+ describe('getOrdersAndTradersInfo', () => {
+ beforeEach(async () => {
+ signedOrder = await orderFactory.newSignedOrderAsync();
+ signedOrder2 = await orderFactory.newSignedOrderAsync({
+ takerAssetData: assetDataUtils.encodeERC721AssetData(erc721Token.address, tokenId2),
+ });
+ });
+ it('should return the correct info when no balances or allowances have been set', async () => {
+ const orders = [signedOrder, signedOrder2];
+ const takers = [takerAddress, takerAddress];
+ const [
+ [orderInfo1, orderInfo2],
+ [traderInfo1, traderInfo2],
+ ] = await orderValidator.getOrdersAndTradersInfo.callAsync(orders, takers);
+ const expectedOrderHash1 = orderHashUtils.getOrderHashHex(signedOrder);
+ const expectedOrderHash2 = orderHashUtils.getOrderHashHex(signedOrder2);
+ expect(orderInfo1.orderStatus).to.be.equal(OrderStatus.FILLABLE);
+ expect(orderInfo1.orderHash).to.be.equal(expectedOrderHash1);
+ expect(orderInfo1.orderTakerAssetFilledAmount).to.be.bignumber.equal(constants.ZERO_AMOUNT);
+ expect(orderInfo2.orderStatus).to.be.equal(OrderStatus.FILLABLE);
+ expect(orderInfo2.orderHash).to.be.equal(expectedOrderHash2);
+ expect(orderInfo2.orderTakerAssetFilledAmount).to.be.bignumber.equal(constants.ZERO_AMOUNT);
+ expect(traderInfo1.makerBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
+ expect(traderInfo1.makerAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
+ expect(traderInfo1.takerBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
+ expect(traderInfo1.takerAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
+ expect(traderInfo1.makerZrxBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
+ expect(traderInfo1.makerZrxAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
+ expect(traderInfo1.takerZrxBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
+ expect(traderInfo1.takerZrxAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
+ expect(traderInfo2.makerBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
+ expect(traderInfo2.makerAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
+ expect(traderInfo2.takerBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
+ expect(traderInfo2.takerAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
+ expect(traderInfo2.makerZrxBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
+ expect(traderInfo2.makerZrxAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
+ expect(traderInfo2.takerZrxBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
+ expect(traderInfo2.takerZrxAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
+ });
+ it('should return the correct info when balances and allowances are set', async () => {
+ const makerBalance = new BigNumber(123);
+ const makerAllowance = new BigNumber(456);
+ const makerZrxBalance = new BigNumber(789);
+ const takerZrxAllowance = new BigNumber(987);
+ await web3Wrapper.awaitTransactionSuccessAsync(
+ await erc20Token.setBalance.sendTransactionAsync(makerAddress, makerBalance),
+ constants.AWAIT_TRANSACTION_MINED_MS,
+ );
+ await web3Wrapper.awaitTransactionSuccessAsync(
+ await erc20Token.approve.sendTransactionAsync(erc20Proxy.address, makerAllowance, {
+ from: makerAddress,
+ }),
+ constants.AWAIT_TRANSACTION_MINED_MS,
+ );
+ await web3Wrapper.awaitTransactionSuccessAsync(
+ await zrxToken.setBalance.sendTransactionAsync(makerAddress, makerZrxBalance),
+ constants.AWAIT_TRANSACTION_MINED_MS,
+ );
+ await web3Wrapper.awaitTransactionSuccessAsync(
+ await zrxToken.approve.sendTransactionAsync(erc20Proxy.address, takerZrxAllowance, {
+ from: takerAddress,
+ }),
+ constants.AWAIT_TRANSACTION_MINED_MS,
+ );
+ const isApproved = true;
+ await web3Wrapper.awaitTransactionSuccessAsync(
+ await erc721Token.setApprovalForAll.sendTransactionAsync(erc721Proxy.address, isApproved, {
+ from: takerAddress,
+ }),
+ constants.AWAIT_TRANSACTION_MINED_MS,
+ );
+ await web3Wrapper.awaitTransactionSuccessAsync(
+ await erc721Token.mint.sendTransactionAsync(takerAddress, tokenId2),
+ constants.AWAIT_TRANSACTION_MINED_MS,
+ );
+ const orders = [signedOrder, signedOrder2];
+ const takers = [takerAddress, takerAddress];
+ const [
+ [orderInfo1, orderInfo2],
+ [traderInfo1, traderInfo2],
+ ] = await orderValidator.getOrdersAndTradersInfo.callAsync(orders, takers);
+ const expectedOrderHash1 = orderHashUtils.getOrderHashHex(signedOrder);
+ const expectedOrderHash2 = orderHashUtils.getOrderHashHex(signedOrder2);
+ expect(orderInfo1.orderStatus).to.be.equal(OrderStatus.FILLABLE);
+ expect(orderInfo1.orderHash).to.be.equal(expectedOrderHash1);
+ expect(orderInfo1.orderTakerAssetFilledAmount).to.be.bignumber.equal(constants.ZERO_AMOUNT);
+ expect(orderInfo2.orderStatus).to.be.equal(OrderStatus.FILLABLE);
+ expect(orderInfo2.orderHash).to.be.equal(expectedOrderHash2);
+ expect(orderInfo2.orderTakerAssetFilledAmount).to.be.bignumber.equal(constants.ZERO_AMOUNT);
+ expect(traderInfo1.makerBalance).to.be.bignumber.equal(makerBalance);
+ expect(traderInfo1.makerAllowance).to.be.bignumber.equal(makerAllowance);
+ expect(traderInfo1.takerBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
+ expect(traderInfo1.takerAllowance).to.be.bignumber.equal(ERC721_ALLOWANCE);
+ expect(traderInfo1.makerZrxBalance).to.be.bignumber.equal(makerZrxBalance);
+ expect(traderInfo1.makerZrxAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
+ expect(traderInfo1.takerZrxBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
+ expect(traderInfo1.takerZrxAllowance).to.be.bignumber.equal(takerZrxAllowance);
+ expect(traderInfo2.makerBalance).to.be.bignumber.equal(makerBalance);
+ expect(traderInfo2.makerAllowance).to.be.bignumber.equal(makerAllowance);
+ expect(traderInfo2.takerBalance).to.be.bignumber.equal(ERC721_BALANCE);
+ expect(traderInfo2.takerAllowance).to.be.bignumber.equal(ERC721_ALLOWANCE);
+ expect(traderInfo2.makerZrxBalance).to.be.bignumber.equal(makerZrxBalance);
+ expect(traderInfo2.makerZrxAllowance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
+ expect(traderInfo2.takerZrxBalance).to.be.bignumber.equal(constants.ZERO_AMOUNT);
+ expect(traderInfo2.takerZrxAllowance).to.be.bignumber.equal(takerZrxAllowance);
+ });
+ });
+});
+// tslint:disable:max-file-line-count
diff --git a/packages/contracts/test/multisig/asset_proxy_owner.ts b/packages/contracts/test/multisig/asset_proxy_owner.ts
index 6b98605d3..9515941ff 100644
--- a/packages/contracts/test/multisig/asset_proxy_owner.ts
+++ b/packages/contracts/test/multisig/asset_proxy_owner.ts
@@ -422,7 +422,7 @@ describe('AssetProxyOwner', () => {
await multiSigWrapper.confirmTransactionAsync(txId, owners[1]);
const execRes = await multiSigWrapper.executeRemoveAuthorizedAddressAtIndexAsync(txId, owners[0]);
- const execLog = execRes.logs[0] as LogWithDecodedArgs<AssetProxyOwnerExecutionEventArgs>;
+ const execLog = execRes.logs[1] as LogWithDecodedArgs<AssetProxyOwnerExecutionEventArgs>;
expect(execLog.args.transactionId).to.be.bignumber.equal(txId);
const tx = await testAssetProxyOwner.transactions.callAsync(txId);
@@ -449,7 +449,7 @@ describe('AssetProxyOwner', () => {
await multiSigWrapper.confirmTransactionAsync(txId, owners[1]);
const execRes = await multiSigWrapper.executeRemoveAuthorizedAddressAtIndexAsync(txId, owners[0]);
- const execLog = execRes.logs[0] as LogWithDecodedArgs<AssetProxyOwnerExecutionEventArgs>;
+ const execLog = execRes.logs[1] as LogWithDecodedArgs<AssetProxyOwnerExecutionEventArgs>;
expect(execLog.args.transactionId).to.be.bignumber.equal(txId);
const tx = await testAssetProxyOwner.transactions.callAsync(txId);
diff --git a/packages/contracts/test/tokens/erc721_token.ts b/packages/contracts/test/tokens/erc721_token.ts
new file mode 100644
index 000000000..e61fd7d51
--- /dev/null
+++ b/packages/contracts/test/tokens/erc721_token.ts
@@ -0,0 +1,279 @@
+import { BlockchainLifecycle } from '@0xproject/dev-utils';
+import { RevertReason } from '@0xproject/types';
+import { BigNumber } from '@0xproject/utils';
+import * as chai from 'chai';
+import { LogWithDecodedArgs } from 'ethereum-types';
+
+import {
+ DummyERC721ReceiverContract,
+ DummyERC721ReceiverTokenReceivedEventArgs,
+} from '../../generated_contract_wrappers/dummy_erc721_receiver';
+import {
+ DummyERC721TokenContract,
+ DummyERC721TokenTransferEventArgs,
+} from '../../generated_contract_wrappers/dummy_erc721_token';
+import { InvalidERC721ReceiverContract } from '../../generated_contract_wrappers/invalid_erc721_receiver';
+import { artifacts } from '../utils/artifacts';
+import { expectTransactionFailedAsync, expectTransactionFailedWithoutReasonAsync } from '../utils/assertions';
+import { chaiSetup } from '../utils/chai_setup';
+import { constants } from '../utils/constants';
+import { LogDecoder } from '../utils/log_decoder';
+import { provider, txDefaults, web3Wrapper } from '../utils/web3_wrapper';
+
+chaiSetup.configure();
+const expect = chai.expect;
+const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
+// tslint:disable:no-unnecessary-type-assertion
+describe('ERC721Token', () => {
+ let owner: string;
+ let spender: string;
+ let token: DummyERC721TokenContract;
+ let erc721Receiver: DummyERC721ReceiverContract;
+ let logDecoder: LogDecoder;
+ const tokenId = new BigNumber(1);
+ before(async () => {
+ await blockchainLifecycle.startAsync();
+ });
+ after(async () => {
+ await blockchainLifecycle.revertAsync();
+ });
+ before(async () => {
+ const accounts = await web3Wrapper.getAvailableAddressesAsync();
+ owner = accounts[0];
+ spender = accounts[1];
+ token = await DummyERC721TokenContract.deployFrom0xArtifactAsync(
+ artifacts.DummyERC721Token,
+ provider,
+ txDefaults,
+ constants.DUMMY_TOKEN_NAME,
+ constants.DUMMY_TOKEN_SYMBOL,
+ );
+ erc721Receiver = await DummyERC721ReceiverContract.deployFrom0xArtifactAsync(
+ artifacts.DummyERC721Receiver,
+ provider,
+ txDefaults,
+ );
+ logDecoder = new LogDecoder(web3Wrapper);
+ await web3Wrapper.awaitTransactionSuccessAsync(
+ await token.mint.sendTransactionAsync(owner, tokenId, { from: owner }),
+ constants.AWAIT_TRANSACTION_MINED_MS,
+ );
+ });
+ beforeEach(async () => {
+ await blockchainLifecycle.startAsync();
+ });
+ afterEach(async () => {
+ await blockchainLifecycle.revertAsync();
+ });
+
+ describe('transferFrom', () => {
+ it('should revert if the tokenId is not owner', async () => {
+ const from = owner;
+ const to = erc721Receiver.address;
+ const unownedTokenId = new BigNumber(2);
+ await expectTransactionFailedAsync(
+ token.transferFrom.sendTransactionAsync(from, to, unownedTokenId),
+ RevertReason.Erc721ZeroOwner,
+ );
+ });
+ it('should revert if transferring to a null address', async () => {
+ const from = owner;
+ const to = constants.NULL_ADDRESS;
+ await expectTransactionFailedAsync(
+ token.transferFrom.sendTransactionAsync(from, to, tokenId),
+ RevertReason.Erc721ZeroToAddress,
+ );
+ });
+ it('should revert if the from address does not own the token', async () => {
+ const from = spender;
+ const to = erc721Receiver.address;
+ await expectTransactionFailedAsync(
+ token.transferFrom.sendTransactionAsync(from, to, tokenId),
+ RevertReason.Erc721OwnerMismatch,
+ );
+ });
+ it('should revert if spender does not own the token, is not approved, and is not approved for all', async () => {
+ const from = owner;
+ const to = erc721Receiver.address;
+ await expectTransactionFailedAsync(
+ token.transferFrom.sendTransactionAsync(from, to, tokenId, { from: spender }),
+ RevertReason.Erc721InvalidSpender,
+ );
+ });
+ it('should transfer the token if called by owner', async () => {
+ const from = owner;
+ const to = erc721Receiver.address;
+ const txReceipt = await logDecoder.getTxWithDecodedLogsAsync(
+ await token.transferFrom.sendTransactionAsync(from, to, tokenId),
+ );
+ const newOwner = await token.ownerOf.callAsync(tokenId);
+ expect(newOwner).to.be.equal(to);
+ const log = txReceipt.logs[0] as LogWithDecodedArgs<DummyERC721TokenTransferEventArgs>;
+ expect(log.args._from).to.be.equal(from);
+ expect(log.args._to).to.be.equal(to);
+ expect(log.args._tokenId).to.be.bignumber.equal(tokenId);
+ });
+ it('should transfer the token if spender is approved for all', async () => {
+ const isApproved = true;
+ await web3Wrapper.awaitTransactionSuccessAsync(
+ await token.setApprovalForAll.sendTransactionAsync(spender, isApproved),
+ constants.AWAIT_TRANSACTION_MINED_MS,
+ );
+
+ const from = owner;
+ const to = erc721Receiver.address;
+ const txReceipt = await logDecoder.getTxWithDecodedLogsAsync(
+ await token.transferFrom.sendTransactionAsync(from, to, tokenId),
+ );
+ const newOwner = await token.ownerOf.callAsync(tokenId);
+ expect(newOwner).to.be.equal(to);
+ const log = txReceipt.logs[0] as LogWithDecodedArgs<DummyERC721TokenTransferEventArgs>;
+ expect(log.args._from).to.be.equal(from);
+ expect(log.args._to).to.be.equal(to);
+ expect(log.args._tokenId).to.be.bignumber.equal(tokenId);
+ });
+ it('should transfer the token if spender is individually approved', async () => {
+ await web3Wrapper.awaitTransactionSuccessAsync(
+ await token.approve.sendTransactionAsync(spender, tokenId),
+ constants.AWAIT_TRANSACTION_MINED_MS,
+ );
+
+ const from = owner;
+ const to = erc721Receiver.address;
+ const txReceipt = await logDecoder.getTxWithDecodedLogsAsync(
+ await token.transferFrom.sendTransactionAsync(from, to, tokenId),
+ );
+ const newOwner = await token.ownerOf.callAsync(tokenId);
+ expect(newOwner).to.be.equal(to);
+
+ const approvedAddress = await token.getApproved.callAsync(tokenId);
+ expect(approvedAddress).to.be.equal(constants.NULL_ADDRESS);
+ const log = txReceipt.logs[0] as LogWithDecodedArgs<DummyERC721TokenTransferEventArgs>;
+ expect(log.args._from).to.be.equal(from);
+ expect(log.args._to).to.be.equal(to);
+ expect(log.args._tokenId).to.be.bignumber.equal(tokenId);
+ });
+ });
+ describe('safeTransferFrom without data', () => {
+ it('should transfer token to a non-contract address if called by owner', async () => {
+ const from = owner;
+ const to = spender;
+ const txReceipt = await logDecoder.getTxWithDecodedLogsAsync(
+ await token.safeTransferFrom1.sendTransactionAsync(from, to, tokenId),
+ );
+ const newOwner = await token.ownerOf.callAsync(tokenId);
+ expect(newOwner).to.be.equal(to);
+ const log = txReceipt.logs[0] as LogWithDecodedArgs<DummyERC721TokenTransferEventArgs>;
+ expect(log.args._from).to.be.equal(from);
+ expect(log.args._to).to.be.equal(to);
+ expect(log.args._tokenId).to.be.bignumber.equal(tokenId);
+ });
+ it('should revert if transferring to a contract address without onERC721Received', async () => {
+ const contract = await DummyERC721TokenContract.deployFrom0xArtifactAsync(
+ artifacts.DummyERC721Token,
+ provider,
+ txDefaults,
+ constants.DUMMY_TOKEN_NAME,
+ constants.DUMMY_TOKEN_SYMBOL,
+ );
+ const from = owner;
+ const to = contract.address;
+ await expectTransactionFailedWithoutReasonAsync(
+ token.safeTransferFrom1.sendTransactionAsync(from, to, tokenId),
+ );
+ });
+ it('should revert if onERC721Received does not return the correct value', async () => {
+ const invalidErc721Receiver = await InvalidERC721ReceiverContract.deployFrom0xArtifactAsync(
+ artifacts.InvalidERC721Receiver,
+ provider,
+ txDefaults,
+ );
+ const from = owner;
+ const to = invalidErc721Receiver.address;
+ await expectTransactionFailedAsync(
+ token.safeTransferFrom1.sendTransactionAsync(from, to, tokenId),
+ RevertReason.Erc721InvalidSelector,
+ );
+ });
+ it('should transfer to contract and call onERC721Received with correct return value', async () => {
+ const from = owner;
+ const to = erc721Receiver.address;
+ const txReceipt = await logDecoder.getTxWithDecodedLogsAsync(
+ await token.safeTransferFrom1.sendTransactionAsync(from, to, tokenId),
+ );
+ const newOwner = await token.ownerOf.callAsync(tokenId);
+ expect(newOwner).to.be.equal(to);
+ const transferLog = txReceipt.logs[0] as LogWithDecodedArgs<DummyERC721TokenTransferEventArgs>;
+ const receiverLog = txReceipt.logs[1] as LogWithDecodedArgs<DummyERC721ReceiverTokenReceivedEventArgs>;
+ expect(transferLog.args._from).to.be.equal(from);
+ expect(transferLog.args._to).to.be.equal(to);
+ expect(transferLog.args._tokenId).to.be.bignumber.equal(tokenId);
+ expect(receiverLog.args.operator).to.be.equal(owner);
+ expect(receiverLog.args.from).to.be.equal(from);
+ expect(receiverLog.args.tokenId).to.be.bignumber.equal(tokenId);
+ expect(receiverLog.args.data).to.be.equal(constants.NULL_BYTES);
+ });
+ });
+ describe('safeTransferFrom with data', () => {
+ const data = '0x0102030405060708090a0b0c0d0e0f';
+ it('should transfer token to a non-contract address if called by owner', async () => {
+ const from = owner;
+ const to = spender;
+ const txReceipt = await logDecoder.getTxWithDecodedLogsAsync(
+ await token.safeTransferFrom2.sendTransactionAsync(from, to, tokenId, data),
+ );
+ const newOwner = await token.ownerOf.callAsync(tokenId);
+ expect(newOwner).to.be.equal(to);
+ const log = txReceipt.logs[0] as LogWithDecodedArgs<DummyERC721TokenTransferEventArgs>;
+ expect(log.args._from).to.be.equal(from);
+ expect(log.args._to).to.be.equal(to);
+ expect(log.args._tokenId).to.be.bignumber.equal(tokenId);
+ });
+ it('should revert if transferring to a contract address without onERC721Received', async () => {
+ const contract = await DummyERC721TokenContract.deployFrom0xArtifactAsync(
+ artifacts.DummyERC721Token,
+ provider,
+ txDefaults,
+ constants.DUMMY_TOKEN_NAME,
+ constants.DUMMY_TOKEN_SYMBOL,
+ );
+ const from = owner;
+ const to = contract.address;
+ await expectTransactionFailedWithoutReasonAsync(
+ token.safeTransferFrom2.sendTransactionAsync(from, to, tokenId, data),
+ );
+ });
+ it('should revert if onERC721Received does not return the correct value', async () => {
+ const invalidErc721Receiver = await InvalidERC721ReceiverContract.deployFrom0xArtifactAsync(
+ artifacts.InvalidERC721Receiver,
+ provider,
+ txDefaults,
+ );
+ const from = owner;
+ const to = invalidErc721Receiver.address;
+ await expectTransactionFailedAsync(
+ token.safeTransferFrom2.sendTransactionAsync(from, to, tokenId, data),
+ RevertReason.Erc721InvalidSelector,
+ );
+ });
+ it('should transfer to contract and call onERC721Received with correct return value', async () => {
+ const from = owner;
+ const to = erc721Receiver.address;
+ const txReceipt = await logDecoder.getTxWithDecodedLogsAsync(
+ await token.safeTransferFrom2.sendTransactionAsync(from, to, tokenId, data),
+ );
+ const newOwner = await token.ownerOf.callAsync(tokenId);
+ expect(newOwner).to.be.equal(to);
+ const transferLog = txReceipt.logs[0] as LogWithDecodedArgs<DummyERC721TokenTransferEventArgs>;
+ const receiverLog = txReceipt.logs[1] as LogWithDecodedArgs<DummyERC721ReceiverTokenReceivedEventArgs>;
+ expect(transferLog.args._from).to.be.equal(from);
+ expect(transferLog.args._to).to.be.equal(to);
+ expect(transferLog.args._tokenId).to.be.bignumber.equal(tokenId);
+ expect(receiverLog.args.operator).to.be.equal(owner);
+ expect(receiverLog.args.from).to.be.equal(from);
+ expect(receiverLog.args.tokenId).to.be.bignumber.equal(tokenId);
+ expect(receiverLog.args.data).to.be.equal(data);
+ });
+ });
+});
+// tslint:enable:no-unnecessary-type-assertion
diff --git a/packages/contracts/test/tokens/unlimited_allowance_token.ts b/packages/contracts/test/tokens/unlimited_allowance_token.ts
index 81d931fc5..f2725b408 100644
--- a/packages/contracts/test/tokens/unlimited_allowance_token.ts
+++ b/packages/contracts/test/tokens/unlimited_allowance_token.ts
@@ -17,7 +17,7 @@ const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
describe('UnlimitedAllowanceToken', () => {
let owner: string;
let spender: string;
- const MAX_MINT_VALUE = new BigNumber(100000000000000000000);
+ const MAX_MINT_VALUE = new BigNumber(10000000000000000000000);
let token: DummyERC20TokenContract;
before(async () => {
diff --git a/packages/contracts/test/utils/artifacts.ts b/packages/contracts/test/utils/artifacts.ts
index 1d5728cba..e8a7585ac 100644
--- a/packages/contracts/test/utils/artifacts.ts
+++ b/packages/contracts/test/utils/artifacts.ts
@@ -4,15 +4,18 @@ import * as AssetProxyOwner from '../../artifacts/AssetProxyOwner.json';
import * as DummyERC20Token from '../../artifacts/DummyERC20Token.json';
import * as DummyERC721Receiver from '../../artifacts/DummyERC721Receiver.json';
import * as DummyERC721Token from '../../artifacts/DummyERC721Token.json';
+import * as DummyNoReturnERC20Token from '../../artifacts/DummyNoReturnERC20Token.json';
import * as ERC20Proxy from '../../artifacts/ERC20Proxy.json';
import * as ERC721Proxy from '../../artifacts/ERC721Proxy.json';
import * as Exchange from '../../artifacts/Exchange.json';
import * as ExchangeWrapper from '../../artifacts/ExchangeWrapper.json';
import * as Forwarder from '../../artifacts/Forwarder.json';
import * as IAssetProxy from '../../artifacts/IAssetProxy.json';
+import * as InvalidERC721Receiver from '../../artifacts/InvalidERC721Receiver.json';
import * as MixinAuthorizable from '../../artifacts/MixinAuthorizable.json';
import * as MultiSigWallet from '../../artifacts/MultiSigWallet.json';
import * as MultiSigWalletWithTimeLock from '../../artifacts/MultiSigWalletWithTimeLock.json';
+import * as OrderValidator from '../../artifacts/OrderValidator.json';
import * as TestAssetProxyDispatcher from '../../artifacts/TestAssetProxyDispatcher.json';
import * as TestAssetProxyOwner from '../../artifacts/TestAssetProxyOwner.json';
import * as TestConstants from '../../artifacts/TestConstants.json';
@@ -32,6 +35,7 @@ export const artifacts = {
DummyERC20Token: (DummyERC20Token as any) as ContractArtifact,
DummyERC721Receiver: (DummyERC721Receiver as any) as ContractArtifact,
DummyERC721Token: (DummyERC721Token as any) as ContractArtifact,
+ DummyNoReturnERC20Token: (DummyNoReturnERC20Token as any) as ContractArtifact,
ERC20Proxy: (ERC20Proxy as any) as ContractArtifact,
ERC721Proxy: (ERC721Proxy as any) as ContractArtifact,
Exchange: (Exchange as any) as ContractArtifact,
@@ -39,9 +43,11 @@ export const artifacts = {
EtherToken: (EtherToken as any) as ContractArtifact,
Forwarder: (Forwarder as any) as ContractArtifact,
IAssetProxy: (IAssetProxy as any) as ContractArtifact,
+ InvalidERC721Receiver: (InvalidERC721Receiver as any) as ContractArtifact,
MixinAuthorizable: (MixinAuthorizable as any) as ContractArtifact,
MultiSigWallet: (MultiSigWallet as any) as ContractArtifact,
MultiSigWalletWithTimeLock: (MultiSigWalletWithTimeLock as any) as ContractArtifact,
+ OrderValidator: (OrderValidator as any) as ContractArtifact,
TestAssetProxyOwner: (TestAssetProxyOwner as any) as ContractArtifact,
TestAssetProxyDispatcher: (TestAssetProxyDispatcher as any) as ContractArtifact,
TestConstants: (TestConstants as any) as ContractArtifact,
diff --git a/packages/contracts/test/utils/erc721_wrapper.ts b/packages/contracts/test/utils/erc721_wrapper.ts
index d023b4d02..743d10706 100644
--- a/packages/contracts/test/utils/erc721_wrapper.ts
+++ b/packages/contracts/test/utils/erc721_wrapper.ts
@@ -81,7 +81,8 @@ export class ERC721Wrapper {
}
public async doesTokenExistAsync(tokenAddress: string, tokenId: BigNumber): Promise<boolean> {
const tokenContract = this._getTokenContractFromAssetData(tokenAddress);
- const doesExist = await tokenContract.exists.callAsync(tokenId);
+ const owner = await tokenContract.ownerOf.callAsync(tokenId);
+ const doesExist = owner !== constants.NULL_ADDRESS;
return doesExist;
}
public async approveProxyAsync(tokenAddress: string, tokenId: BigNumber): Promise<void> {
diff --git a/packages/contracts/test/utils/exchange_wrapper.ts b/packages/contracts/test/utils/exchange_wrapper.ts
index d57592d6d..619d43994 100644
--- a/packages/contracts/test/utils/exchange_wrapper.ts
+++ b/packages/contracts/test/utils/exchange_wrapper.ts
@@ -17,7 +17,7 @@ export class ExchangeWrapper {
constructor(exchangeContract: ExchangeContract, provider: Provider) {
this._exchange = exchangeContract;
this._web3Wrapper = new Web3Wrapper(provider);
- this._logDecoder = new LogDecoder(this._web3Wrapper, this._exchange.address);
+ this._logDecoder = new LogDecoder(this._web3Wrapper);
}
public async fillOrderAsync(
signedOrder: SignedOrder,
@@ -266,4 +266,7 @@ export class ExchangeWrapper {
);
return data;
}
+ public getExchangeAddress(): string {
+ return this._exchange.address;
+ }
}
diff --git a/packages/contracts/test/utils/fill_order_combinatorial_utils.ts b/packages/contracts/test/utils/fill_order_combinatorial_utils.ts
index f18ad0dd3..a9318571c 100644
--- a/packages/contracts/test/utils/fill_order_combinatorial_utils.ts
+++ b/packages/contracts/test/utils/fill_order_combinatorial_utils.ts
@@ -504,7 +504,11 @@ export class FillOrderCombinatorialUtils {
const actFilledTakerAmount = await this.exchangeWrapper.getTakerAssetFilledAmountAsync(orderHash);
expect(actFilledTakerAmount).to.be.bignumber.equal(expFilledTakerAmount, 'filledTakerAmount');
- expect(txReceipt.logs.length).to.be.equal(1, 'logs length');
+ const exchangeLogs = _.filter(
+ txReceipt.logs,
+ txLog => txLog.address === this.exchangeWrapper.getExchangeAddress(),
+ );
+ expect(exchangeLogs.length).to.be.equal(1, 'logs length');
// tslint:disable-next-line:no-unnecessary-type-assertion
const log = txReceipt.logs[0] as LogWithDecodedArgs<ExchangeFillEventArgs>;
expect(log.args.makerAddress).to.be.equal(makerAddress, 'log.args.makerAddress');
diff --git a/packages/contracts/test/utils/forwarder_wrapper.ts b/packages/contracts/test/utils/forwarder_wrapper.ts
index 5b9a63ddf..de247a878 100644
--- a/packages/contracts/test/utils/forwarder_wrapper.ts
+++ b/packages/contracts/test/utils/forwarder_wrapper.ts
@@ -58,7 +58,7 @@ export class ForwarderWrapper {
constructor(contractInstance: ForwarderContract, provider: Provider) {
this._forwarderContract = contractInstance;
this._web3Wrapper = new Web3Wrapper(provider);
- this._logDecoder = new LogDecoder(this._web3Wrapper, this._forwarderContract.address);
+ this._logDecoder = new LogDecoder(this._web3Wrapper);
}
public async marketSellOrdersWithEthAsync(
orders: SignedOrder[],
diff --git a/packages/contracts/test/utils/log_decoder.ts b/packages/contracts/test/utils/log_decoder.ts
index 92e9185d8..77211d357 100644
--- a/packages/contracts/test/utils/log_decoder.ts
+++ b/packages/contracts/test/utils/log_decoder.ts
@@ -16,7 +16,6 @@ import { constants } from './constants';
export class LogDecoder {
private readonly _web3Wrapper: Web3Wrapper;
- private readonly _contractAddress: string;
private readonly _abiDecoder: AbiDecoder;
public static wrapLogBigNumbers(log: any): any {
const argNames = _.keys(log.args);
@@ -27,9 +26,8 @@ export class LogDecoder {
}
}
}
- constructor(web3Wrapper: Web3Wrapper, contractAddress: string) {
+ constructor(web3Wrapper: Web3Wrapper) {
this._web3Wrapper = web3Wrapper;
- this._contractAddress = contractAddress;
const abiArrays: AbiDefinition[][] = [];
_.forEach(artifacts, (artifact: ContractArtifact) => {
const compilerOutput = artifact.compilerOutput;
@@ -48,7 +46,6 @@ export class LogDecoder {
}
public async getTxWithDecodedLogsAsync(txHash: string): Promise<TransactionReceiptWithDecodedLogs> {
const tx = await this._web3Wrapper.awaitTransactionSuccessAsync(txHash, constants.AWAIT_TRANSACTION_MINED_MS);
- tx.logs = _.filter(tx.logs, log => log.address === this._contractAddress);
tx.logs = _.map(tx.logs, log => this.decodeLogOrThrow(log));
return tx;
}
diff --git a/packages/contracts/test/utils/multi_sig_wrapper.ts b/packages/contracts/test/utils/multi_sig_wrapper.ts
index 8c8055d4a..e0c27b839 100644
--- a/packages/contracts/test/utils/multi_sig_wrapper.ts
+++ b/packages/contracts/test/utils/multi_sig_wrapper.ts
@@ -16,7 +16,7 @@ export class MultiSigWrapper {
constructor(multiSigContract: MultiSigWalletContract, provider: Provider) {
this._multiSig = multiSigContract;
this._web3Wrapper = new Web3Wrapper(provider);
- this._logDecoder = new LogDecoder(this._web3Wrapper, this._multiSig.address);
+ this._logDecoder = new LogDecoder(this._web3Wrapper);
}
public async submitTransactionAsync(
destination: string,