@0x:contracts-integrations Addressed review comments

This commit is contained in:
Alex Towle 2019-11-16 01:30:59 -08:00
parent 2818e56932
commit 4fe57ba025
11 changed files with 301 additions and 309 deletions

View File

@ -67,18 +67,18 @@ blockchainTests.resets('Coordinator integration tests', env => {
orderConfig: { orderConfig: {
senderAddress: coordinator.address, senderAddress: coordinator.address,
feeRecipientAddress: feeRecipient.address, feeRecipientAddress: feeRecipient.address,
makerAssetData: await devUtils.encodeERC20AssetData(makerToken.address).callAsync(), makerAssetData: deployment.assetDataEncoder
takerAssetData: await devUtils.encodeERC20AssetData(takerToken.address).callAsync(), .ERC20Token(makerToken.address)
makerFeeAssetData: await devUtils.encodeERC20AssetData(makerFeeToken.address).callAsync(), .getABIEncodedTransactionData(),
takerFeeAssetData: await devUtils.encodeERC20AssetData(takerFeeToken.address).callAsync(), takerAssetData: deployment.assetDataEncoder
makerAssetData: deployment.assetDataEncoder.ERC20Token.getABIEncodedTransactionData(makerToken.address), .ERC20Token(takerToken.address)
takerAssetData: deployment.assetDataEncoder.ERC20Token.getABIEncodedTransactionData(takerToken.address), .getABIEncodedTransactionData(),
makerFeeAssetData: deployment.assetDataEncoder.ERC20Token.getABIEncodedTransactionData( makerFeeAssetData: deployment.assetDataEncoder
makerFeeToken.address, .ERC20Token(makerFeeToken.address)
), .getABIEncodedTransactionData(),
takerFeeAssetData: deployment.assetDataEncoder.ERC20Token.getABIEncodedTransactionData( takerFeeAssetData: deployment.assetDataEncoder
takerFeeToken.address, .ERC20Token(takerFeeToken.address)
), .getABIEncodedTransactionData(),
}, },
}); });
@ -152,7 +152,9 @@ blockchainTests.resets('Coordinator integration tests', env => {
taker.address, taker.address,
deployment.staking.stakingProxy.address, deployment.staking.stakingProxy.address,
DeploymentManager.protocolFee, DeploymentManager.protocolFee,
deployment.assetDataEncoder.ERC20Token.getABIEncodedTransactionData(deployment.tokens.weth.address), deployment.assetDataEncoder
.ERC20Token(deployment.tokens.weth.address)
.getABIEncodedTransactionData(),
); );
} }
} }

View File

@ -1,5 +1,4 @@
import { DevUtilsContract } from '@0x/contracts-dev-utils'; import { DummyERC20TokenContract, ERC20TokenEvents, ERC20TokenTransferEventArgs } from '@0x/contracts-erc20';
import { ERC20TokenEvents, ERC20TokenTransferEventArgs } from '@0x/contracts-erc20';
import { ExchangeRevertErrors, IExchangeEvents, IExchangeFillEventArgs } from '@0x/contracts-exchange'; import { ExchangeRevertErrors, IExchangeEvents, IExchangeFillEventArgs } from '@0x/contracts-exchange';
import { ReferenceFunctions } from '@0x/contracts-exchange-libs'; import { ReferenceFunctions } from '@0x/contracts-exchange-libs';
import { import {
@ -10,7 +9,6 @@ import {
getLatestBlockTimestampAsync, getLatestBlockTimestampAsync,
Numberish, Numberish,
orderHashUtils, orderHashUtils,
provider,
toBaseUnitAmount, toBaseUnitAmount,
verifyEvents, verifyEvents,
} from '@0x/contracts-test-utils'; } from '@0x/contracts-test-utils';
@ -27,13 +25,16 @@ import { DeploymentManager } from '../framework/deployment_manager';
const { addFillResults, safeGetPartialAmountFloor } = ReferenceFunctions; const { addFillResults, safeGetPartialAmountFloor } = ReferenceFunctions;
const devUtils = new DevUtilsContract(constants.NULL_ADDRESS, provider);
// tslint:disable:no-unnecessary-type-assertion // tslint:disable:no-unnecessary-type-assertion
blockchainTests.resets('Exchange wrappers', env => { blockchainTests.resets('Exchange wrappers', env => {
let maker: Maker; let maker: Maker;
let taker: Actor; let taker: Actor;
let feeRecipient: string; let feeRecipient: string;
let makerToken: DummyERC20TokenContract;
let takerToken: DummyERC20TokenContract;
let feeToken: DummyERC20TokenContract;
const nullFillResults: FillResults = { const nullFillResults: FillResults = {
makerAssetFilledAmount: constants.ZERO_AMOUNT, makerAssetFilledAmount: constants.ZERO_AMOUNT,
takerAssetFilledAmount: constants.ZERO_AMOUNT, takerAssetFilledAmount: constants.ZERO_AMOUNT,
@ -58,22 +59,24 @@ blockchainTests.resets('Exchange wrappers', env => {
numErc1155TokensToDeploy: 0, numErc1155TokensToDeploy: 0,
}); });
[makerToken, takerToken, feeToken] = deployment.tokens.erc20;
maker = new Maker({ maker = new Maker({
name: 'market maker', name: 'market maker',
deployment, deployment,
orderConfig: { orderConfig: {
makerAssetData: deployment.assetDataEncoder.ERC20Token.getABIEncodedTransactionData( makerAssetData: deployment.assetDataEncoder
deployment.tokens.erc20[0].address, .ERC20Token(makerToken.address)
), .getABIEncodedTransactionData(),
takerAssetData: deployment.assetDataEncoder.ERC20Token.getABIEncodedTransactionData( takerAssetData: deployment.assetDataEncoder
deployment.tokens.erc20[1].address, .ERC20Token(takerToken.address)
), .getABIEncodedTransactionData(),
makerFeeAssetData: deployment.assetDataEncoder.ERC20Token.getABIEncodedTransactionData( makerFeeAssetData: deployment.assetDataEncoder
deployment.tokens.erc20[2].address, .ERC20Token(feeToken.address)
), .getABIEncodedTransactionData(),
takerFeeAssetData: deployment.assetDataEncoder.ERC20Token.getABIEncodedTransactionData( takerFeeAssetData: deployment.assetDataEncoder
deployment.tokens.erc20[2].address, .ERC20Token(feeToken.address)
), .getABIEncodedTransactionData(),
feeRecipientAddress: feeRecipient, feeRecipientAddress: feeRecipient,
}, },
}); });
@ -98,9 +101,9 @@ blockchainTests.resets('Exchange wrappers', env => {
}, },
{ {
erc20: { erc20: {
makerAsset: deployment.tokens.erc20[0], makerToken,
takerAsset: deployment.tokens.erc20[1], takerToken,
feeAsset: deployment.tokens.erc20[2], feeToken,
weth: deployment.tokens.weth, weth: deployment.tokens.weth,
}, },
}, },
@ -109,22 +112,15 @@ blockchainTests.resets('Exchange wrappers', env => {
await blockchainBalances.updateBalancesAsync(); await blockchainBalances.updateBalancesAsync();
initialLocalBalances = LocalBalanceStore.create(devUtils, blockchainBalances); initialLocalBalances = LocalBalanceStore.create(deployment.devUtils, blockchainBalances);
wethAssetData = deployment.assetDataEncoder.ERC20Token.getABIEncodedTransactionData( wethAssetData = deployment.assetDataEncoder
deployment.tokens.weth.address, .ERC20Token(deployment.tokens.weth.address)
); .getABIEncodedTransactionData();
txHelper = new TransactionHelper(env.web3Wrapper, {
...assetProxyArtifacts,
...exchangeArtifacts,
...stakingArtifacts,
...erc20Artifacts,
});
}); });
beforeEach(async () => { beforeEach(async () => {
localBalances = LocalBalanceStore.create(devUtils, initialLocalBalances); localBalances = LocalBalanceStore.create(deployment.devUtils, initialLocalBalances);
}); });
interface SignedOrderWithValidity { interface SignedOrderWithValidity {
@ -792,9 +788,9 @@ blockchainTests.resets('Exchange wrappers', env => {
}); });
it('should fill a signedOrder that does not use the same takerAssetAddress (eth protocol fee)', async () => { it('should fill a signedOrder that does not use the same takerAssetAddress (eth protocol fee)', async () => {
const differentTakerAssetData = deployment.assetDataEncoder.ERC20Token.getABIEncodedTransactionData( const differentTakerAssetData = deployment.assetDataEncoder
deployment.tokens.erc20[2].address, .ERC20Token(feeToken.address)
); .getABIEncodedTransactionData();
signedOrders = [ signedOrders = [
await maker.signOrderAsync(), await maker.signOrderAsync(),
@ -815,9 +811,9 @@ blockchainTests.resets('Exchange wrappers', env => {
}); });
it('should fill a signedOrder that does not use the same takerAssetAddress (weth protocol fee)', async () => { it('should fill a signedOrder that does not use the same takerAssetAddress (weth protocol fee)', async () => {
const differentTakerAssetData = deployment.assetDataEncoder.ERC20Token.getABIEncodedTransactionData( const differentTakerAssetData = deployment.assetDataEncoder
deployment.tokens.erc20[2].address, .ERC20Token(feeToken.address)
); .getABIEncodedTransactionData();
signedOrders = [ signedOrders = [
await maker.signOrderAsync(), await maker.signOrderAsync(),
@ -990,9 +986,9 @@ blockchainTests.resets('Exchange wrappers', env => {
}); });
it('should fill a signedOrder that does not use the same makerAssetAddress (eth protocol fee)', async () => { it('should fill a signedOrder that does not use the same makerAssetAddress (eth protocol fee)', async () => {
const differentMakerAssetData = deployment.assetDataEncoder.ERC20Token.getABIEncodedTransactionData( const differentMakerAssetData = deployment.assetDataEncoder
deployment.tokens.erc20[2].address, .ERC20Token(feeToken.address)
); .getABIEncodedTransactionData();
signedOrders = [ signedOrders = [
await maker.signOrderAsync(), await maker.signOrderAsync(),
@ -1014,9 +1010,9 @@ blockchainTests.resets('Exchange wrappers', env => {
}); });
it('should fill a signedOrder that does not use the same makerAssetAddress (weth protocol fee)', async () => { it('should fill a signedOrder that does not use the same makerAssetAddress (weth protocol fee)', async () => {
const differentMakerAssetData = deployment.assetDataEncoder.ERC20Token.getABIEncodedTransactionData( const differentMakerAssetData = deployment.assetDataEncoder
deployment.tokens.erc20[2].address, .ERC20Token(feeToken.address)
); .getABIEncodedTransactionData();
signedOrders = [ signedOrders = [
await maker.signOrderAsync(), await maker.signOrderAsync(),

View File

@ -1,4 +1,3 @@
import { DevUtilsContract } from '@0x/contracts-dev-utils';
import { ERC20TokenEvents, ERC20TokenTransferEventArgs } from '@0x/contracts-erc20'; import { ERC20TokenEvents, ERC20TokenTransferEventArgs } from '@0x/contracts-erc20';
import { ExchangeEvents, ExchangeFillEventArgs } from '@0x/contracts-exchange'; import { ExchangeEvents, ExchangeFillEventArgs } from '@0x/contracts-exchange';
import { ReferenceFunctions } from '@0x/contracts-exchange-libs'; import { ReferenceFunctions } from '@0x/contracts-exchange-libs';
@ -15,7 +14,6 @@ import {
constants, constants,
expect, expect,
orderHashUtils, orderHashUtils,
provider,
toBaseUnitAmount, toBaseUnitAmount,
verifyEvents, verifyEvents,
} from '@0x/contracts-test-utils'; } from '@0x/contracts-test-utils';
@ -32,7 +30,6 @@ import { BlockchainBalanceStore } from '../framework/balances/blockchain_balance
import { LocalBalanceStore } from '../framework/balances/local_balance_store'; import { LocalBalanceStore } from '../framework/balances/local_balance_store';
import { DeploymentManager } from '../framework/deployment_manager'; import { DeploymentManager } from '../framework/deployment_manager';
const devUtils = new DevUtilsContract(constants.NULL_ADDRESS, provider);
blockchainTests.resets('fillOrder integration tests', env => { blockchainTests.resets('fillOrder integration tests', env => {
let deployment: DeploymentManager; let deployment: DeploymentManager;
let balanceStore: BlockchainBalanceStore; let balanceStore: BlockchainBalanceStore;
@ -60,10 +57,14 @@ blockchainTests.resets('fillOrder integration tests', env => {
}); });
const orderConfig = { const orderConfig = {
feeRecipientAddress: feeRecipient.address, feeRecipientAddress: feeRecipient.address,
makerAssetData: deployment.assetDataEncoder.ERC20Token.getABIEncodedTransactionData(makerToken.address), makerAssetData: deployment.assetDataEncoder.ERC20Token(makerToken.address).getABIEncodedTransactionData(),
takerAssetData: deployment.assetDataEncoder.ERC20Token.getABIEncodedTransactionData(takerToken.address), takerAssetData: deployment.assetDataEncoder.ERC20Token(takerToken.address).getABIEncodedTransactionData(),
makerFeeAssetData: deployment.assetDataEncoder.ERC20Token.getABIEncodedTransactionData(makerToken.address), makerFeeAssetData: deployment.assetDataEncoder
takerFeeAssetData: deployment.assetDataEncoder.ERC20Token.getABIEncodedTransactionData(takerToken.address), .ERC20Token(makerToken.address)
.getABIEncodedTransactionData(),
takerFeeAssetData: deployment.assetDataEncoder
.ERC20Token(takerToken.address)
.getABIEncodedTransactionData(),
makerFee: constants.ZERO_AMOUNT, makerFee: constants.ZERO_AMOUNT,
takerFee: constants.ZERO_AMOUNT, takerFee: constants.ZERO_AMOUNT,
}; };
@ -112,7 +113,7 @@ blockchainTests.resets('fillOrder integration tests', env => {
msgValue?: BigNumber, msgValue?: BigNumber,
): Promise<LocalBalanceStore> { ): Promise<LocalBalanceStore> {
let remainingValue = msgValue !== undefined ? msgValue : DeploymentManager.protocolFee; let remainingValue = msgValue !== undefined ? msgValue : DeploymentManager.protocolFee;
const localBalanceStore = LocalBalanceStore.create(devUtils, balanceStore); const localBalanceStore = LocalBalanceStore.create(deployment.devUtils, balanceStore);
// Transaction gas cost // Transaction gas cost
localBalanceStore.burnGas(txReceipt.from, DeploymentManager.gasPrice.times(txReceipt.gasUsed)); localBalanceStore.burnGas(txReceipt.from, DeploymentManager.gasPrice.times(txReceipt.gasUsed));
@ -144,7 +145,7 @@ blockchainTests.resets('fillOrder integration tests', env => {
taker.address, taker.address,
deployment.staking.stakingProxy.address, deployment.staking.stakingProxy.address,
DeploymentManager.protocolFee, DeploymentManager.protocolFee,
deployment.assetDataEncoder.ERC20Token.getABIEncodedTransactionData(deployment.tokens.weth.address), deployment.assetDataEncoder.ERC20Token(deployment.tokens.weth.address).getABIEncodedTransactionData(),
); );
} }
@ -260,7 +261,7 @@ blockchainTests.resets('fillOrder integration tests', env => {
// Fetch the current balances // Fetch the current balances
await balanceStore.updateBalancesAsync(); await balanceStore.updateBalancesAsync();
const expectedBalances = LocalBalanceStore.create(devUtils, balanceStore); const expectedBalances = LocalBalanceStore.create(deployment.devUtils, balanceStore);
// End the epoch. This should wrap the staking proxy's ETH balance. // End the epoch. This should wrap the staking proxy's ETH balance.
const endEpochReceipt = await delegator.endEpochAsync(); const endEpochReceipt = await delegator.endEpochAsync();
@ -308,7 +309,7 @@ blockchainTests.resets('fillOrder integration tests', env => {
deployment.staking.stakingProxy.address, deployment.staking.stakingProxy.address,
operator.address, operator.address,
operatorReward, operatorReward,
deployment.assetDataEncoder.ERC20Token.getABIEncodedTransactionData(deployment.tokens.weth.address), deployment.assetDataEncoder.ERC20Token(deployment.tokens.weth.address).getABIEncodedTransactionData(),
); );
expectedBalances.burnGas(delegator.address, DeploymentManager.gasPrice.times(finalizePoolReceipt.gasUsed)); expectedBalances.burnGas(delegator.address, DeploymentManager.gasPrice.times(finalizePoolReceipt.gasUsed));
await balanceStore.updateBalancesAsync(); await balanceStore.updateBalancesAsync();
@ -390,7 +391,7 @@ blockchainTests.resets('fillOrder integration tests', env => {
deployment.staking.stakingProxy.address, deployment.staking.stakingProxy.address,
operator.address, operator.address,
operatorReward, operatorReward,
deployment.assetDataEncoder.ERC20Token.getABIEncodedTransactionData(deployment.tokens.weth.address), deployment.assetDataEncoder.ERC20Token(deployment.tokens.weth.address).getABIEncodedTransactionData(),
); );
expectedBalances.burnGas(delegator.address, DeploymentManager.gasPrice.times(finalizePoolReceipt.gasUsed)); expectedBalances.burnGas(delegator.address, DeploymentManager.gasPrice.times(finalizePoolReceipt.gasUsed));
await balanceStore.updateBalancesAsync(); await balanceStore.updateBalancesAsync();

View File

@ -1,7 +1,6 @@
import { artifacts as exchangeArtifacts } from '@0x/contracts-exchange'; import { artifacts as exchangeArtifacts } from '@0x/contracts-exchange';
import { artifacts, ForwarderContract } from '@0x/contracts-exchange-forwarder'; import { artifacts, ForwarderContract } from '@0x/contracts-exchange-forwarder';
import { BlockchainTestsEnvironment } from '@0x/contracts-test-utils'; import { BlockchainTestsEnvironment } from '@0x/contracts-test-utils';
import { assetDataUtils } from '@0x/order-utils';
import { DeploymentManager } from '../framework/deployment_manager'; import { DeploymentManager } from '../framework/deployment_manager';
@ -18,6 +17,6 @@ export async function deployForwarderAsync(
deployment.txDefaults, deployment.txDefaults,
{ ...exchangeArtifacts, ...artifacts }, { ...exchangeArtifacts, ...artifacts },
deployment.exchange.address, deployment.exchange.address,
assetDataUtils.encodeERC20AssetData(deployment.tokens.weth.address), deployment.assetDataEncoder.ERC20Token(deployment.tokens.weth.address).getABIEncodedTransactionData(),
); );
} }

View File

@ -56,10 +56,10 @@ blockchainTests('Forwarder integration tests', env => {
[makerToken, makerFeeToken, anotherErc20Token] = deployment.tokens.erc20; [makerToken, makerFeeToken, anotherErc20Token] = deployment.tokens.erc20;
[erc721Token] = deployment.tokens.erc721; [erc721Token] = deployment.tokens.erc721;
wethAssetData = deployment.assetDataEncoder.ERC20Token.getABIEncodedTransactionData( wethAssetData = deployment.assetDataEncoder
deployment.tokens.weth.address, .ERC20Token(deployment.tokens.weth.address)
); .getABIEncodedTransactionData();
makerAssetData = deployment.assetDataEncoder.ERC20Token.getABIEncodedTransactionData(makerToken.address); makerAssetData = deployment.assetDataEncoder.ERC20Token(makerToken.address).getABIEncodedTransactionData();
taker = new Taker({ name: 'Taker', deployment }); taker = new Taker({ name: 'Taker', deployment });
orderFeeRecipient = new FeeRecipient({ orderFeeRecipient = new FeeRecipient({
@ -80,9 +80,9 @@ blockchainTests('Forwarder integration tests', env => {
makerAssetData, makerAssetData,
takerAssetData: wethAssetData, takerAssetData: wethAssetData,
takerFee: constants.ZERO_AMOUNT, takerFee: constants.ZERO_AMOUNT,
makerFeeAssetData: deployment.assetDataEncoder.ERC20Token.getABIEncodedTransactionData( makerFeeAssetData: deployment.assetDataEncoder
makerFeeToken.address, .ERC20Token(makerFeeToken.address)
), .getABIEncodedTransactionData(),
takerFeeAssetData: wethAssetData, takerFeeAssetData: wethAssetData,
}, },
}); });
@ -174,9 +174,9 @@ blockchainTests('Forwarder integration tests', env => {
await testFactory.marketSellTestAsync(orders, 1.34); await testFactory.marketSellTestAsync(orders, 1.34);
}); });
it('should fail to fill an order with a percentage fee if the asset proxy is not yet approved', async () => { it('should fail to fill an order with a percentage fee if the asset proxy is not yet approved', async () => {
const unapprovedAsset = deployment.assetDataEncoder.ERC20Token.getABIEncodedTransactionData( const unapprovedAsset = deployment.assetDataEncoder
anotherErc20Token.address, .ERC20Token(anotherErc20Token.address)
); .getABIEncodedTransactionData();
const order = await maker.signOrderAsync({ const order = await maker.signOrderAsync({
makerAssetData: unapprovedAsset, makerAssetData: unapprovedAsset,
takerFee: toBaseUnitAmount(2), takerFee: toBaseUnitAmount(2),
@ -248,9 +248,9 @@ blockchainTests('Forwarder integration tests', env => {
}); });
it('should fill orders with different makerAssetData', async () => { it('should fill orders with different makerAssetData', async () => {
const firstOrder = await maker.signOrderAsync(); const firstOrder = await maker.signOrderAsync();
const secondOrderMakerAssetData = deployment.assetDataEncoder.ERC20Token.getABIEncodedTransactionData( const secondOrderMakerAssetData = deployment.assetDataEncoder
anotherErc20Token.address, .ERC20Token(anotherErc20Token.address)
); .getABIEncodedTransactionData();
const secondOrder = await maker.signOrderAsync({ const secondOrder = await maker.signOrderAsync({
makerAssetData: secondOrderMakerAssetData, makerAssetData: secondOrderMakerAssetData,
}); });
@ -259,9 +259,9 @@ blockchainTests('Forwarder integration tests', env => {
await testFactory.marketSellTestAsync(orders, 1.5); await testFactory.marketSellTestAsync(orders, 1.5);
}); });
it('should fail to fill an order with a fee denominated in an asset other than makerAsset or WETH', async () => { it('should fail to fill an order with a fee denominated in an asset other than makerAsset or WETH', async () => {
const takerFeeAssetData = deployment.assetDataEncoder.ERC20Token.getABIEncodedTransactionData( const takerFeeAssetData = deployment.assetDataEncoder
anotherErc20Token.address, .ERC20Token(anotherErc20Token.address)
); .getABIEncodedTransactionData();
const order = await maker.signOrderAsync({ const order = await maker.signOrderAsync({
takerFeeAssetData, takerFeeAssetData,
takerFee: toBaseUnitAmount(1), takerFee: toBaseUnitAmount(1),
@ -352,9 +352,9 @@ blockchainTests('Forwarder integration tests', env => {
}); });
it('should buy exactly makerAssetBuyAmount in orders with different makerAssetData', async () => { it('should buy exactly makerAssetBuyAmount in orders with different makerAssetData', async () => {
const firstOrder = await maker.signOrderAsync(); const firstOrder = await maker.signOrderAsync();
const secondOrderMakerAssetData = deployment.assetDataEncoder.ERC20Token.getABIEncodedTransactionData( const secondOrderMakerAssetData = deployment.assetDataEncoder
anotherErc20Token.address, .ERC20Token(anotherErc20Token.address)
); .getABIEncodedTransactionData();
const secondOrder = await maker.signOrderAsync({ const secondOrder = await maker.signOrderAsync({
makerAssetData: secondOrderMakerAssetData, makerAssetData: secondOrderMakerAssetData,
}); });
@ -403,10 +403,9 @@ blockchainTests('Forwarder integration tests', env => {
it('should buy an ERC721 asset from a single order', async () => { it('should buy an ERC721 asset from a single order', async () => {
const erc721Order = await maker.signOrderAsync({ const erc721Order = await maker.signOrderAsync({
makerAssetAmount: new BigNumber(1), makerAssetAmount: new BigNumber(1),
makerAssetData: deployment.assetDataEncoder.ERC721Token.getABIEncodedTransactionData( makerAssetData: deployment.assetDataEncoder
erc721Token.address, .ERC721Token(erc721Token.address, nftId)
nftId, .getABIEncodedTransactionData(),
),
takerFeeAssetData: wethAssetData, takerFeeAssetData: wethAssetData,
}); });
await testFactory.marketBuyTestAsync([erc721Order], 1); await testFactory.marketBuyTestAsync([erc721Order], 1);
@ -414,19 +413,18 @@ blockchainTests('Forwarder integration tests', env => {
it('should buy an ERC721 asset and pay a WETH fee', async () => { it('should buy an ERC721 asset and pay a WETH fee', async () => {
const erc721orderWithWethFee = await maker.signOrderAsync({ const erc721orderWithWethFee = await maker.signOrderAsync({
makerAssetAmount: new BigNumber(1), makerAssetAmount: new BigNumber(1),
makerAssetData: deployment.assetDataEncoder.ERC721Token.getABIEncodedTransactionData( makerAssetData: deployment.assetDataEncoder
erc721Token.address, .ERC721Token(erc721Token.address, nftId)
nftId, .getABIEncodedTransactionData(),
),
takerFee: toBaseUnitAmount(1), takerFee: toBaseUnitAmount(1),
takerFeeAssetData: wethAssetData, takerFeeAssetData: wethAssetData,
}); });
await testFactory.marketBuyTestAsync([erc721orderWithWethFee], 1); await testFactory.marketBuyTestAsync([erc721orderWithWethFee], 1);
}); });
it('should fail to fill an order with a fee denominated in an asset other than makerAsset or WETH', async () => { it('should fail to fill an order with a fee denominated in an asset other than makerAsset or WETH', async () => {
const takerFeeAssetData = deployment.assetDataEncoder.ERC20Token.getABIEncodedTransactionData( const takerFeeAssetData = deployment.assetDataEncoder
anotherErc20Token.address, .ERC20Token(anotherErc20Token.address)
); .getABIEncodedTransactionData();
const order = await maker.signOrderAsync({ const order = await maker.signOrderAsync({
takerFeeAssetData, takerFeeAssetData,
takerFee: toBaseUnitAmount(1), takerFee: toBaseUnitAmount(1),

View File

@ -106,23 +106,18 @@ export class Actor {
amount?: BigNumber, amount?: BigNumber,
): Promise<BigNumber> { ): Promise<BigNumber> {
// Create a fungible token. // Create a fungible token.
const id = await token.create.callAsync('', false, { from: this.address }); const id = await token.create('', false).callAsync({ from: this.address });
await token.create.awaitTransactionSuccessAsync('', false, { from: this.address }); await token.create('', false).awaitTransactionSuccessAsync({ from: this.address });
// Mint the token // Mint the token
await token.mintFungible.awaitTransactionSuccessAsync( await token
id, .mintFungible(id, [this.address], [amount || new BigNumber(constants.NUM_ERC1155_FUNGIBLE_TOKENS_MINT)])
[this.address], .awaitTransactionSuccessAsync({ from: this.address });
[amount || new BigNumber(constants.NUM_ERC1155_FUNGIBLE_TOKENS_MINT)],
{ from: this.address },
);
// Set approval for all token types for the spender. // Set approval for all token types for the spender.
await token.setApprovalForAll.awaitTransactionSuccessAsync( await token
spender || this.deployment.assetProxies.erc1155Proxy.address, .setApprovalForAll(spender || this.deployment.assetProxies.erc1155Proxy.address, true)
true, .awaitTransactionSuccessAsync({ from: this.address });
{ from: this.address },
);
return id; return id;
} }

View File

@ -41,7 +41,7 @@ export function validStakeAssertion(
txData.from as string, txData.from as string,
zrxVault.address, zrxVault.address,
amount, amount,
deployment.assetDataEncoder.ERC20Token.getABIEncodedTransactionData(deployment.tokens.zrx.address), deployment.assetDataEncoder.ERC20Token(deployment.tokens.zrx.address).getABIEncodedTransactionData(),
); );
return expectedBalances; return expectedBalances;
}, },

View File

@ -41,7 +41,7 @@ export function validUnstakeAssertion(
zrxVault.address, zrxVault.address,
txData.from as string, txData.from as string,
amount, amount,
await deployment.devUtils.encodeERC20AssetData(deployment.tokens.zrx.address).callAsync(), deployment.assetDataEncoder.ERC20Token(deployment.tokens.zrx.address).getABIEncodedTransactionData(),
); );
return expectedBalances; return expectedBalances;
}, },

View File

@ -19,7 +19,7 @@ import {
TestStakingContract, TestStakingContract,
ZrxVaultContract, ZrxVaultContract,
} from '@0x/contracts-staking'; } from '@0x/contracts-staking';
import { BlockchainTestsEnvironment, constants, TransactionHelper } from '@0x/contracts-test-utils'; import { BlockchainTestsEnvironment, constants } from '@0x/contracts-test-utils';
import { BigNumber } from '@0x/utils'; import { BigNumber } from '@0x/utils';
import { TxData } from 'ethereum-types'; import { TxData } from 'ethereum-types';
import * as _ from 'lodash'; import * as _ from 'lodash';
@ -196,16 +196,6 @@ export class DeploymentManager {
const devUtils = new DevUtilsContract(constants.NULL_ADDRESS, environment.provider); const devUtils = new DevUtilsContract(constants.NULL_ADDRESS, environment.provider);
const assetDataEncoder = new IAssetDataContract(constants.NULL_ADDRESS, environment.provider); const assetDataEncoder = new IAssetDataContract(constants.NULL_ADDRESS, environment.provider);
// Create a `TransactionHelper` object that uses all of the packages artifacts.
const txHelper = new TransactionHelper(environment.web3Wrapper, {
...assetProxyArtifacts,
...ERC20Artifacts,
...ERC721Artifacts,
...ERC1155Artifacts,
...exchangeArtifacts,
...stakingArtifacts,
});
// Construct the new instance and return it. // Construct the new instance and return it.
return new DeploymentManager( return new DeploymentManager(
assetProxies, assetProxies,
@ -218,7 +208,6 @@ export class DeploymentManager {
txDefaults, txDefaults,
devUtils, devUtils,
assetDataEncoder, assetDataEncoder,
txHelper,
); );
} }
@ -510,7 +499,6 @@ export class DeploymentManager {
public txDefaults: Partial<TxData>, public txDefaults: Partial<TxData>,
public devUtils: DevUtilsContract, public devUtils: DevUtilsContract,
public assetDataEncoder: IAssetDataContract, public assetDataEncoder: IAssetDataContract,
public txHelper: TransactionHelper,
) {} ) {}
} }
// tslint:disable:max-file-line-count // tslint:disable:max-file-line-count

View File

@ -1,8 +1,7 @@
import { DummyERC20TokenContract } from '@0x/contracts-erc20'; import { DummyERC20TokenContract } from '@0x/contracts-erc20';
import { BlockchainBalanceStore, TokenIds } from '@0x/contracts-exchange'; import { BlockchainBalanceStore, ExchangeRevertErrors, TokenIds } from '@0x/contracts-exchange';
import { ReferenceFunctions as LibReferenceFunctions } from '@0x/contracts-exchange-libs'; import { ReferenceFunctions as LibReferenceFunctions } from '@0x/contracts-exchange-libs';
import { blockchainTests, constants, expect, toBaseUnitAmount } from '@0x/contracts-test-utils'; import { blockchainTests, constants, expect, orderHashUtils, toBaseUnitAmount } from '@0x/contracts-test-utils';
import { ExchangeRevertErrors, orderHashUtils } from '@0x/order-utils';
import { Order, OrderStatus, SignedOrder } from '@0x/types'; import { Order, OrderStatus, SignedOrder } from '@0x/types';
import { BigNumber } from '@0x/utils'; import { BigNumber } from '@0x/utils';
@ -60,13 +59,13 @@ blockchainTests.resets('matchOrders integration tests', env => {
}); });
// Encode the asset data. // Encode the asset data.
makerAssetDataLeft = deployment.assetDataEncoder.ERC20Token.getABIEncodedTransactionData( makerAssetDataLeft = deployment.assetDataEncoder
makerAssetLeft.address, .ERC20Token(makerAssetLeft.address)
); .getABIEncodedTransactionData();
makerAssetDataRight = deployment.assetDataEncoder.ERC20Token.getABIEncodedTransactionData( makerAssetDataRight = deployment.assetDataEncoder
makerAssetRight.address, .ERC20Token(makerAssetRight.address)
); .getABIEncodedTransactionData();
feeAssetData = deployment.assetDataEncoder.ERC20Token.getABIEncodedTransactionData(feeAsset.address); feeAssetData = deployment.assetDataEncoder.ERC20Token(feeAsset.address).getABIEncodedTransactionData();
// Create two market makers with compatible orders for matching. // Create two market makers with compatible orders for matching.
makerLeft = new Maker({ makerLeft = new Maker({
@ -132,10 +131,10 @@ blockchainTests.resets('matchOrders integration tests', env => {
weth: deployment.tokens.weth, weth: deployment.tokens.weth,
}, },
erc721: { erc721: {
token: deployment.tokens.erc721[0], nft: deployment.tokens.erc721[0],
}, },
erc1155: { erc1155: {
token: deployment.tokens.erc1155[0], fungible: deployment.tokens.erc1155[0],
}, },
}, },
tokenIds, tokenIds,
@ -996,13 +995,9 @@ blockchainTests.resets('matchOrders integration tests', env => {
// Match orders // Match orders
const expectedError = new ExchangeRevertErrors.OrderStatusError(orderHashHexLeft, OrderStatus.Cancelled); const expectedError = new ExchangeRevertErrors.OrderStatusError(orderHashHexLeft, OrderStatus.Cancelled);
const tx = deployment.exchange.matchOrders.awaitTransactionSuccessAsync( const tx = deployment.exchange
signedOrderLeft, .matchOrders(signedOrderLeft, signedOrderRight, signedOrderLeft.signature, signedOrderRight.signature)
signedOrderRight, .awaitTransactionSuccessAsync({ from: matcher.address });
signedOrderLeft.signature,
signedOrderRight.signature,
{ from: matcher.address },
);
return expect(tx).to.revertWith(expectedError); return expect(tx).to.revertWith(expectedError);
}); });
@ -1023,13 +1018,9 @@ blockchainTests.resets('matchOrders integration tests', env => {
// Match orders // Match orders
const expectedError = new ExchangeRevertErrors.OrderStatusError(orderHashHexRight, OrderStatus.Cancelled); const expectedError = new ExchangeRevertErrors.OrderStatusError(orderHashHexRight, OrderStatus.Cancelled);
const tx = deployment.exchange.matchOrders.awaitTransactionSuccessAsync( const tx = deployment.exchange
signedOrderLeft, .matchOrders(signedOrderLeft, signedOrderRight, signedOrderLeft.signature, signedOrderRight.signature)
signedOrderRight, .awaitTransactionSuccessAsync({ from: matcher.address });
signedOrderLeft.signature,
signedOrderRight.signature,
{ from: matcher.address },
);
return expect(tx).to.revertWith(expectedError); return expect(tx).to.revertWith(expectedError);
}); });
@ -1048,13 +1039,9 @@ blockchainTests.resets('matchOrders integration tests', env => {
// Match orders // Match orders
const expectedError = new ExchangeRevertErrors.NegativeSpreadError(orderHashHexLeft, orderHashHexRight); const expectedError = new ExchangeRevertErrors.NegativeSpreadError(orderHashHexLeft, orderHashHexRight);
const tx = deployment.exchange.matchOrders.awaitTransactionSuccessAsync( const tx = deployment.exchange
signedOrderLeft, .matchOrders(signedOrderLeft, signedOrderRight, signedOrderLeft.signature, signedOrderRight.signature)
signedOrderRight, .awaitTransactionSuccessAsync({ from: matcher.address });
signedOrderLeft.signature,
signedOrderRight.signature,
{ from: matcher.address },
);
return expect(tx).to.revertWith(expectedError); return expect(tx).to.revertWith(expectedError);
}); });
@ -1065,9 +1052,9 @@ blockchainTests.resets('matchOrders integration tests', env => {
takerAssetAmount: toBaseUnitAmount(10, 18), takerAssetAmount: toBaseUnitAmount(10, 18),
}); });
const signedOrderRight = await makerRight.signOrderAsync({ const signedOrderRight = await makerRight.signOrderAsync({
takerAssetData: deployment.assetDataEncoder.ERC20Token.getABIEncodedTransactionData( takerAssetData: deployment.assetDataEncoder
makerAssetRight.address, .ERC20Token(makerAssetRight.address)
), .getABIEncodedTransactionData(),
makerAssetAmount: toBaseUnitAmount(10, 18), makerAssetAmount: toBaseUnitAmount(10, 18),
takerAssetAmount: toBaseUnitAmount(2, 18), takerAssetAmount: toBaseUnitAmount(2, 18),
}); });
@ -1089,22 +1076,18 @@ blockchainTests.resets('matchOrders integration tests', env => {
); );
// Match orders // Match orders
const tx = deployment.exchange.matchOrders.awaitTransactionSuccessAsync( const tx = deployment.exchange
signedOrderLeft, .matchOrders(signedOrderLeft, signedOrderRight, signedOrderLeft.signature, signedOrderRight.signature)
signedOrderRight, .awaitTransactionSuccessAsync({ from: matcher.address });
signedOrderLeft.signature,
signedOrderRight.signature,
{ from: matcher.address },
);
return expect(tx).to.revertWith(expectedError); return expect(tx).to.revertWith(expectedError);
}); });
it('should revert if the right maker asset is not equal to the left taker asset', async () => { it('should revert if the right maker asset is not equal to the left taker asset', async () => {
// Create orders to match // Create orders to match
const signedOrderLeft = await makerLeft.signOrderAsync({ const signedOrderLeft = await makerLeft.signOrderAsync({
takerAssetData: deployment.assetDataEncoder.ERC20Token.getABIEncodedTransactionData( takerAssetData: deployment.assetDataEncoder
makerAssetLeft.address, .ERC20Token(makerAssetLeft.address)
), .getABIEncodedTransactionData(),
makerAssetAmount: toBaseUnitAmount(5, 18), makerAssetAmount: toBaseUnitAmount(5, 18),
takerAssetAmount: toBaseUnitAmount(10, 18), takerAssetAmount: toBaseUnitAmount(10, 18),
}); });
@ -1124,13 +1107,9 @@ blockchainTests.resets('matchOrders integration tests', env => {
signedOrderRight.signature, signedOrderRight.signature,
); );
// Match orders // Match orders
const tx = deployment.exchange.matchOrders.awaitTransactionSuccessAsync( const tx = deployment.exchange
signedOrderLeft, .matchOrders(signedOrderLeft, signedOrderRight, signedOrderLeft.signature, signedOrderRight.signature)
signedOrderRight, .awaitTransactionSuccessAsync({ from: matcher.address });
signedOrderLeft.signature,
signedOrderRight.signature,
{ from: matcher.address },
);
return expect(tx).to.revertWith(expectedError); return expect(tx).to.revertWith(expectedError);
}); });
}); });
@ -1907,13 +1886,14 @@ blockchainTests.resets('matchOrders integration tests', env => {
// Match orders // Match orders
const expectedError = new ExchangeRevertErrors.OrderStatusError(orderHashHexLeft, OrderStatus.Cancelled); const expectedError = new ExchangeRevertErrors.OrderStatusError(orderHashHexLeft, OrderStatus.Cancelled);
const tx = deployment.exchange.matchOrdersWithMaximalFill.awaitTransactionSuccessAsync( const tx = deployment.exchange
signedOrderLeft, .matchOrdersWithMaximalFill(
signedOrderRight, signedOrderLeft,
signedOrderLeft.signature, signedOrderRight,
signedOrderRight.signature, signedOrderLeft.signature,
{ from: matcher.address }, signedOrderRight.signature,
); )
.awaitTransactionSuccessAsync({ from: matcher.address });
return expect(tx).to.revertWith(expectedError); return expect(tx).to.revertWith(expectedError);
}); });
@ -1933,13 +1913,14 @@ blockchainTests.resets('matchOrders integration tests', env => {
// Match orders // Match orders
const expectedError = new ExchangeRevertErrors.OrderStatusError(orderHashHexRight, OrderStatus.Cancelled); const expectedError = new ExchangeRevertErrors.OrderStatusError(orderHashHexRight, OrderStatus.Cancelled);
const tx = deployment.exchange.matchOrdersWithMaximalFill.awaitTransactionSuccessAsync( const tx = deployment.exchange
signedOrderLeft, .matchOrdersWithMaximalFill(
signedOrderRight, signedOrderLeft,
signedOrderLeft.signature, signedOrderRight,
signedOrderRight.signature, signedOrderLeft.signature,
{ from: matcher.address }, signedOrderRight.signature,
); )
.awaitTransactionSuccessAsync({ from: matcher.address });
return expect(tx).to.revertWith(expectedError); return expect(tx).to.revertWith(expectedError);
}); });
@ -1957,13 +1938,14 @@ blockchainTests.resets('matchOrders integration tests', env => {
const orderHashHexRight = orderHashUtils.getOrderHashHex(signedOrderRight); const orderHashHexRight = orderHashUtils.getOrderHashHex(signedOrderRight);
// Match orders // Match orders
const expectedError = new ExchangeRevertErrors.NegativeSpreadError(orderHashHexLeft, orderHashHexRight); const expectedError = new ExchangeRevertErrors.NegativeSpreadError(orderHashHexLeft, orderHashHexRight);
const tx = deployment.exchange.matchOrdersWithMaximalFill.awaitTransactionSuccessAsync( const tx = deployment.exchange
signedOrderLeft, .matchOrdersWithMaximalFill(
signedOrderRight, signedOrderLeft,
signedOrderLeft.signature, signedOrderRight,
signedOrderRight.signature, signedOrderLeft.signature,
{ from: matcher.address }, signedOrderRight.signature,
); )
.awaitTransactionSuccessAsync({ from: matcher.address });
return expect(tx).to.revertWith(expectedError); return expect(tx).to.revertWith(expectedError);
}); });
@ -1974,9 +1956,9 @@ blockchainTests.resets('matchOrders integration tests', env => {
takerAssetAmount: toBaseUnitAmount(10, 18), takerAssetAmount: toBaseUnitAmount(10, 18),
}); });
const signedOrderRight = await makerRight.signOrderAsync({ const signedOrderRight = await makerRight.signOrderAsync({
takerAssetData: deployment.assetDataEncoder.ERC20Token.getABIEncodedTransactionData( takerAssetData: deployment.assetDataEncoder
makerAssetRight.address, .ERC20Token(makerAssetRight.address)
), .getABIEncodedTransactionData(),
makerAssetAmount: toBaseUnitAmount(10, 18), makerAssetAmount: toBaseUnitAmount(10, 18),
takerAssetAmount: toBaseUnitAmount(2, 18), takerAssetAmount: toBaseUnitAmount(2, 18),
}); });
@ -1996,22 +1978,23 @@ blockchainTests.resets('matchOrders integration tests', env => {
signedOrderRight.signature, signedOrderRight.signature,
); );
// Match orders // Match orders
const tx = deployment.exchange.matchOrdersWithMaximalFill.awaitTransactionSuccessAsync( const tx = deployment.exchange
signedOrderLeft, .matchOrdersWithMaximalFill(
signedOrderRight, signedOrderLeft,
signedOrderLeft.signature, signedOrderRight,
signedOrderRight.signature, signedOrderLeft.signature,
{ from: matcher.address }, signedOrderRight.signature,
); )
.awaitTransactionSuccessAsync({ from: matcher.address });
return expect(tx).to.revertWith(expectedError); return expect(tx).to.revertWith(expectedError);
}); });
it('should revert if the right maker asset is not equal to the left taker asset', async () => { it('should revert if the right maker asset is not equal to the left taker asset', async () => {
// Create orders to match // Create orders to match
const signedOrderLeft = await makerLeft.signOrderAsync({ const signedOrderLeft = await makerLeft.signOrderAsync({
takerAssetData: deployment.assetDataEncoder.ERC20Token.getABIEncodedTransactionData( takerAssetData: deployment.assetDataEncoder
makerAssetLeft.address, .ERC20Token(makerAssetLeft.address)
), .getABIEncodedTransactionData(),
makerAssetAmount: toBaseUnitAmount(5, 18), makerAssetAmount: toBaseUnitAmount(5, 18),
takerAssetAmount: toBaseUnitAmount(10, 18), takerAssetAmount: toBaseUnitAmount(10, 18),
}); });
@ -2031,13 +2014,14 @@ blockchainTests.resets('matchOrders integration tests', env => {
signedOrderRight.signature, signedOrderRight.signature,
); );
// Match orders // Match orders
const tx = deployment.exchange.matchOrdersWithMaximalFill.awaitTransactionSuccessAsync( const tx = deployment.exchange
signedOrderLeft, .matchOrdersWithMaximalFill(
signedOrderRight, signedOrderLeft,
signedOrderLeft.signature, signedOrderRight,
signedOrderRight.signature, signedOrderLeft.signature,
{ from: matcher.address }, signedOrderRight.signature,
); )
.awaitTransactionSuccessAsync({ from: matcher.address });
return expect(tx).to.revertWith(expectedError); return expect(tx).to.revertWith(expectedError);
}); });
}); });
@ -2054,21 +2038,23 @@ blockchainTests.resets('matchOrders integration tests', env => {
const expectedError = new ExchangeRevertErrors.BatchMatchOrdersError( const expectedError = new ExchangeRevertErrors.BatchMatchOrdersError(
ExchangeRevertErrors.BatchMatchOrdersErrorCodes.ZeroLeftOrders, ExchangeRevertErrors.BatchMatchOrdersErrorCodes.ZeroLeftOrders,
); );
let tx = deployment.exchange.batchMatchOrders.awaitTransactionSuccessAsync( let tx = deployment.exchange
leftOrders, .batchMatchOrders(
rightOrders, leftOrders,
leftOrders.map(order => order.signature), rightOrders,
rightOrders.map(order => order.signature), leftOrders.map(order => order.signature),
{ from: matcher.address }, rightOrders.map(order => order.signature),
); )
.awaitTransactionSuccessAsync({ from: matcher.address });
await expect(tx).to.revertWith(expectedError); await expect(tx).to.revertWith(expectedError);
tx = deployment.exchange.batchMatchOrdersWithMaximalFill.awaitTransactionSuccessAsync( tx = deployment.exchange
leftOrders, .batchMatchOrdersWithMaximalFill(
rightOrders, leftOrders,
leftOrders.map(order => order.signature), rightOrders,
rightOrders.map(order => order.signature), leftOrders.map(order => order.signature),
{ from: matcher.address }, rightOrders.map(order => order.signature),
); )
.awaitTransactionSuccessAsync({ from: matcher.address });
return expect(tx).to.revertWith(expectedError); return expect(tx).to.revertWith(expectedError);
}); });
@ -2083,21 +2069,23 @@ blockchainTests.resets('matchOrders integration tests', env => {
const expectedError = new ExchangeRevertErrors.BatchMatchOrdersError( const expectedError = new ExchangeRevertErrors.BatchMatchOrdersError(
ExchangeRevertErrors.BatchMatchOrdersErrorCodes.ZeroRightOrders, ExchangeRevertErrors.BatchMatchOrdersErrorCodes.ZeroRightOrders,
); );
let tx = deployment.exchange.batchMatchOrders.awaitTransactionSuccessAsync( let tx = deployment.exchange
leftOrders, .batchMatchOrders(
rightOrders, leftOrders,
leftOrders.map(order => order.signature), rightOrders,
rightOrders.map(order => order.signature), leftOrders.map(order => order.signature),
{ from: matcher.address }, rightOrders.map(order => order.signature),
); )
.awaitTransactionSuccessAsync({ from: matcher.address });
await expect(tx).to.revertWith(expectedError); await expect(tx).to.revertWith(expectedError);
tx = deployment.exchange.batchMatchOrdersWithMaximalFill.awaitTransactionSuccessAsync( tx = deployment.exchange
leftOrders, .batchMatchOrdersWithMaximalFill(
rightOrders, leftOrders,
leftOrders.map(order => order.signature), rightOrders,
rightOrders.map(order => order.signature), leftOrders.map(order => order.signature),
{ from: matcher.address }, rightOrders.map(order => order.signature),
); )
.awaitTransactionSuccessAsync({ from: matcher.address });
return expect(tx).to.revertWith(expectedError); return expect(tx).to.revertWith(expectedError);
}); });
@ -2125,21 +2113,23 @@ blockchainTests.resets('matchOrders integration tests', env => {
const expectedError = new ExchangeRevertErrors.BatchMatchOrdersError( const expectedError = new ExchangeRevertErrors.BatchMatchOrdersError(
ExchangeRevertErrors.BatchMatchOrdersErrorCodes.InvalidLengthLeftSignatures, ExchangeRevertErrors.BatchMatchOrdersErrorCodes.InvalidLengthLeftSignatures,
); );
let tx = deployment.exchange.batchMatchOrders.awaitTransactionSuccessAsync( let tx = deployment.exchange
leftOrders, .batchMatchOrders(
rightOrders, leftOrders,
[leftOrders[0].signature], rightOrders,
rightOrders.map(order => order.signature), [leftOrders[0].signature],
{ from: matcher.address }, rightOrders.map(order => order.signature),
); )
.awaitTransactionSuccessAsync({ from: matcher.address });
await expect(tx).to.revertWith(expectedError); await expect(tx).to.revertWith(expectedError);
tx = deployment.exchange.batchMatchOrdersWithMaximalFill.awaitTransactionSuccessAsync( tx = deployment.exchange
leftOrders, .batchMatchOrdersWithMaximalFill(
rightOrders, leftOrders,
[leftOrders[0].signature], rightOrders,
rightOrders.map(order => order.signature), [leftOrders[0].signature],
{ from: matcher.address }, rightOrders.map(order => order.signature),
); )
.awaitTransactionSuccessAsync({ from: matcher.address });
return expect(tx).to.revertWith(expectedError); return expect(tx).to.revertWith(expectedError);
}); });
@ -2167,21 +2157,17 @@ blockchainTests.resets('matchOrders integration tests', env => {
const expectedError = new ExchangeRevertErrors.BatchMatchOrdersError( const expectedError = new ExchangeRevertErrors.BatchMatchOrdersError(
ExchangeRevertErrors.BatchMatchOrdersErrorCodes.InvalidLengthRightSignatures, ExchangeRevertErrors.BatchMatchOrdersErrorCodes.InvalidLengthRightSignatures,
); );
let tx = deployment.exchange.batchMatchOrders.awaitTransactionSuccessAsync( let tx = deployment.exchange
leftOrders, .batchMatchOrders(leftOrders, rightOrders, leftOrders.map(order => order.signature), [
rightOrders, rightOrders[0].signature,
leftOrders.map(order => order.signature), ])
[rightOrders[0].signature], .awaitTransactionSuccessAsync({ from: matcher.address });
{ from: matcher.address },
);
await expect(tx).to.revertWith(expectedError); await expect(tx).to.revertWith(expectedError);
tx = deployment.exchange.batchMatchOrdersWithMaximalFill.awaitTransactionSuccessAsync( tx = deployment.exchange
leftOrders, .batchMatchOrdersWithMaximalFill(leftOrders, rightOrders, leftOrders.map(order => order.signature), [
rightOrders, rightOrders[0].signature,
leftOrders.map(order => order.signature), ])
[rightOrders[0].signature], .awaitTransactionSuccessAsync({ from: matcher.address });
{ from: matcher.address },
);
return expect(tx).to.revertWith(expectedError); return expect(tx).to.revertWith(expectedError);
}); });
}); });
@ -2703,33 +2689,29 @@ blockchainTests.resets('matchOrders integration tests', env => {
describe('token sanity checks', () => { describe('token sanity checks', () => {
it('should be able to match ERC721 tokens with ERC1155 tokens', async () => { it('should be able to match ERC721 tokens with ERC1155 tokens', async () => {
const leftMakerAssetData = deployment.assetDataEncoder.ERC1155Assets.getABIEncodedTransactionData( const leftMakerAssetData = deployment.assetDataEncoder
deployment.tokens.erc1155[0].address, .ERC1155Assets(deployment.tokens.erc1155[0].address, [leftId], [new BigNumber(1)], '0x')
[leftId], .getABIEncodedTransactionData();
[new BigNumber(1)], const rightMakerAssetData = deployment.assetDataEncoder
'0x', .ERC721Token(deployment.tokens.erc721[0].address, rightId)
); .getABIEncodedTransactionData();
const rightMakerAssetData = deployment.assetDataEncoder.ERC721Token.getABIEncodedTransactionData(
deployment.tokens.erc721[0].address,
rightId,
);
const signedOrderLeft = await makerLeft.signOrderAsync({ const signedOrderLeft = await makerLeft.signOrderAsync({
makerAssetAmount: new BigNumber(100), makerAssetAmount: new BigNumber(4),
takerAssetAmount: new BigNumber(1), takerAssetAmount: new BigNumber(1),
makerAssetData: leftMakerAssetData, makerAssetData: leftMakerAssetData,
takerAssetData: rightMakerAssetData, takerAssetData: rightMakerAssetData,
}); });
const signedOrderRight = await makerRight.signOrderAsync({ const signedOrderRight = await makerRight.signOrderAsync({
makerAssetAmount: new BigNumber(1), makerAssetAmount: new BigNumber(1),
takerAssetAmount: new BigNumber(100), takerAssetAmount: new BigNumber(4),
makerAssetData: rightMakerAssetData, makerAssetData: rightMakerAssetData,
takerAssetData: leftMakerAssetData, takerAssetData: leftMakerAssetData,
}); });
const expectedTransferAmounts = { const expectedTransferAmounts = {
// Left Maker // Left Maker
leftMakerAssetSoldByLeftMakerAmount: new BigNumber(100), leftMakerAssetSoldByLeftMakerAmount: new BigNumber(4),
leftMakerFeeAssetPaidByLeftMakerAmount: toBaseUnitAmount(100, 16), // 100% leftMakerFeeAssetPaidByLeftMakerAmount: toBaseUnitAmount(100, 16), // 100%
// Right Maker // Right Maker
rightMakerAssetSoldByRightMakerAmount: new BigNumber(1), rightMakerAssetSoldByRightMakerAmount: new BigNumber(1),

View File

@ -1,6 +1,5 @@
import { BlockchainBalanceStore, LocalBalanceStore } from '@0x/contracts-exchange'; import { BlockchainBalanceStore, LocalBalanceStore } from '@0x/contracts-exchange';
import { constants, expect, OrderStatus } from '@0x/contracts-test-utils'; import { constants, expect, orderHashUtils, OrderStatus } from '@0x/contracts-test-utils';
import { orderHashUtils } from '@0x/order-utils';
import { BatchMatchedFillResults, FillResults, MatchedFillResults, SignedOrder } from '@0x/types'; import { BatchMatchedFillResults, FillResults, MatchedFillResults, SignedOrder } from '@0x/types';
import { BigNumber } from '@0x/utils'; import { BigNumber } from '@0x/utils';
import { LogWithDecodedArgs, TransactionReceiptWithDecodedLogs } from 'ethereum-types'; import { LogWithDecodedArgs, TransactionReceiptWithDecodedLogs } from 'ethereum-types';
@ -115,23 +114,39 @@ export class MatchOrderTester {
let actualBatchMatchResults; let actualBatchMatchResults;
let transactionReceipt; let transactionReceipt;
if (withMaximalFill) { if (withMaximalFill) {
[actualBatchMatchResults, transactionReceipt] = await this._deployment.txHelper.getResultAndReceiptAsync( const tx = this._deployment.exchange.batchMatchOrdersWithMaximalFill(
this._deployment.exchange.batchMatchOrdersWithMaximalFill,
orders.leftOrders, orders.leftOrders,
orders.rightOrders, orders.rightOrders,
orders.leftOrders.map(order => order.signature), orders.leftOrders.map(order => order.signature),
orders.rightOrders.map(order => order.signature), orders.rightOrders.map(order => order.signature),
{ from: takerAddress, gasPrice: DeploymentManager.gasPrice, value },
); );
actualBatchMatchResults = await tx.callAsync({
from: takerAddress,
gasPrice: DeploymentManager.gasPrice,
value,
});
transactionReceipt = await tx.awaitTransactionSuccessAsync({
from: takerAddress,
gasPrice: DeploymentManager.gasPrice,
value,
});
} else { } else {
[actualBatchMatchResults, transactionReceipt] = await this._deployment.txHelper.getResultAndReceiptAsync( const tx = this._deployment.exchange.batchMatchOrders(
this._deployment.exchange.batchMatchOrders,
orders.leftOrders, orders.leftOrders,
orders.rightOrders, orders.rightOrders,
orders.leftOrders.map(order => order.signature), orders.leftOrders.map(order => order.signature),
orders.rightOrders.map(order => order.signature), orders.rightOrders.map(order => order.signature),
{ from: takerAddress, gasPrice: DeploymentManager.gasPrice, value },
); );
actualBatchMatchResults = await tx.callAsync({
from: takerAddress,
gasPrice: DeploymentManager.gasPrice,
value,
});
transactionReceipt = await tx.awaitTransactionSuccessAsync({
from: takerAddress,
gasPrice: DeploymentManager.gasPrice,
value,
});
} }
// Burn the gas used to execute the transaction in the local balance store. // Burn the gas used to execute the transaction in the local balance store.
@ -184,23 +199,39 @@ export class MatchOrderTester {
let actualMatchResults; let actualMatchResults;
let transactionReceipt; let transactionReceipt;
if (withMaximalFill) { if (withMaximalFill) {
[actualMatchResults, transactionReceipt] = await this._deployment.txHelper.getResultAndReceiptAsync( const tx = this._deployment.exchange.matchOrdersWithMaximalFill(
this._deployment.exchange.matchOrdersWithMaximalFill,
orders.leftOrder, orders.leftOrder,
orders.rightOrder, orders.rightOrder,
orders.leftOrder.signature, orders.leftOrder.signature,
orders.rightOrder.signature, orders.rightOrder.signature,
{ from: takerAddress, gasPrice: DeploymentManager.gasPrice, value },
); );
actualMatchResults = await tx.callAsync({
from: takerAddress,
gasPrice: DeploymentManager.gasPrice,
value,
});
transactionReceipt = await tx.awaitTransactionSuccessAsync({
from: takerAddress,
gasPrice: DeploymentManager.gasPrice,
value,
});
} else { } else {
[actualMatchResults, transactionReceipt] = await this._deployment.txHelper.getResultAndReceiptAsync( const tx = this._deployment.exchange.matchOrders(
this._deployment.exchange.matchOrders,
orders.leftOrder, orders.leftOrder,
orders.rightOrder, orders.rightOrder,
orders.leftOrder.signature, orders.leftOrder.signature,
orders.rightOrder.signature, orders.rightOrder.signature,
{ from: takerAddress, gasPrice: DeploymentManager.gasPrice, value },
); );
actualMatchResults = await tx.callAsync({
from: takerAddress,
gasPrice: DeploymentManager.gasPrice,
value,
});
transactionReceipt = await tx.awaitTransactionSuccessAsync({
from: takerAddress,
gasPrice: DeploymentManager.gasPrice,
value,
});
} }
localBalanceStore.burnGas(takerAddress, DeploymentManager.gasPrice.times(transactionReceipt.gasUsed)); localBalanceStore.burnGas(takerAddress, DeploymentManager.gasPrice.times(transactionReceipt.gasUsed));
@ -320,9 +351,9 @@ export class MatchOrderTester {
); );
// Protocol Fee // Protocol Fee
const wethAssetData = this._deployment.assetDataEncoder.ERC20Token.getABIEncodedTransactionData( const wethAssetData = this._deployment.assetDataEncoder
this._deployment.tokens.weth.address, .ERC20Token(this._deployment.tokens.weth.address)
); .getABIEncodedTransactionData();
localBalanceStore.sendEth( localBalanceStore.sendEth(
takerAddress, takerAddress,
this._deployment.staking.stakingProxy.address, this._deployment.staking.stakingProxy.address,
@ -616,7 +647,7 @@ export class MatchOrderTester {
expectedFilledAmount: BigNumber, expectedFilledAmount: BigNumber,
side: string, side: string,
): Promise<void> { ): Promise<void> {
const orderInfo = await this._deployment.exchange.getOrderInfo.callAsync(order); const orderInfo = await this._deployment.exchange.getOrderInfo(order).callAsync();
// Check filled amount of order. // Check filled amount of order.
const actualFilledAmount = orderInfo.orderTakerAssetFilledAmount; const actualFilledAmount = orderInfo.orderTakerAssetFilledAmount;
expect(actualFilledAmount, `${side} order final filled amount`).to.be.bignumber.equal(expectedFilledAmount); expect(actualFilledAmount, `${side} order final filled amount`).to.be.bignumber.equal(expectedFilledAmount);