@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: {
senderAddress: coordinator.address,
feeRecipientAddress: feeRecipient.address,
makerAssetData: await devUtils.encodeERC20AssetData(makerToken.address).callAsync(),
takerAssetData: await devUtils.encodeERC20AssetData(takerToken.address).callAsync(),
makerFeeAssetData: await devUtils.encodeERC20AssetData(makerFeeToken.address).callAsync(),
takerFeeAssetData: await devUtils.encodeERC20AssetData(takerFeeToken.address).callAsync(),
makerAssetData: deployment.assetDataEncoder.ERC20Token.getABIEncodedTransactionData(makerToken.address),
takerAssetData: deployment.assetDataEncoder.ERC20Token.getABIEncodedTransactionData(takerToken.address),
makerFeeAssetData: deployment.assetDataEncoder.ERC20Token.getABIEncodedTransactionData(
makerFeeToken.address,
),
takerFeeAssetData: deployment.assetDataEncoder.ERC20Token.getABIEncodedTransactionData(
takerFeeToken.address,
),
makerAssetData: deployment.assetDataEncoder
.ERC20Token(makerToken.address)
.getABIEncodedTransactionData(),
takerAssetData: deployment.assetDataEncoder
.ERC20Token(takerToken.address)
.getABIEncodedTransactionData(),
makerFeeAssetData: deployment.assetDataEncoder
.ERC20Token(makerFeeToken.address)
.getABIEncodedTransactionData(),
takerFeeAssetData: deployment.assetDataEncoder
.ERC20Token(takerFeeToken.address)
.getABIEncodedTransactionData(),
},
});
@ -152,7 +152,9 @@ blockchainTests.resets('Coordinator integration tests', env => {
taker.address,
deployment.staking.stakingProxy.address,
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 { ERC20TokenEvents, ERC20TokenTransferEventArgs } from '@0x/contracts-erc20';
import { DummyERC20TokenContract, ERC20TokenEvents, ERC20TokenTransferEventArgs } from '@0x/contracts-erc20';
import { ExchangeRevertErrors, IExchangeEvents, IExchangeFillEventArgs } from '@0x/contracts-exchange';
import { ReferenceFunctions } from '@0x/contracts-exchange-libs';
import {
@ -10,7 +9,6 @@ import {
getLatestBlockTimestampAsync,
Numberish,
orderHashUtils,
provider,
toBaseUnitAmount,
verifyEvents,
} from '@0x/contracts-test-utils';
@ -27,13 +25,16 @@ import { DeploymentManager } from '../framework/deployment_manager';
const { addFillResults, safeGetPartialAmountFloor } = ReferenceFunctions;
const devUtils = new DevUtilsContract(constants.NULL_ADDRESS, provider);
// tslint:disable:no-unnecessary-type-assertion
blockchainTests.resets('Exchange wrappers', env => {
let maker: Maker;
let taker: Actor;
let feeRecipient: string;
let makerToken: DummyERC20TokenContract;
let takerToken: DummyERC20TokenContract;
let feeToken: DummyERC20TokenContract;
const nullFillResults: FillResults = {
makerAssetFilledAmount: constants.ZERO_AMOUNT,
takerAssetFilledAmount: constants.ZERO_AMOUNT,
@ -58,22 +59,24 @@ blockchainTests.resets('Exchange wrappers', env => {
numErc1155TokensToDeploy: 0,
});
[makerToken, takerToken, feeToken] = deployment.tokens.erc20;
maker = new Maker({
name: 'market maker',
deployment,
orderConfig: {
makerAssetData: deployment.assetDataEncoder.ERC20Token.getABIEncodedTransactionData(
deployment.tokens.erc20[0].address,
),
takerAssetData: deployment.assetDataEncoder.ERC20Token.getABIEncodedTransactionData(
deployment.tokens.erc20[1].address,
),
makerFeeAssetData: deployment.assetDataEncoder.ERC20Token.getABIEncodedTransactionData(
deployment.tokens.erc20[2].address,
),
takerFeeAssetData: deployment.assetDataEncoder.ERC20Token.getABIEncodedTransactionData(
deployment.tokens.erc20[2].address,
),
makerAssetData: deployment.assetDataEncoder
.ERC20Token(makerToken.address)
.getABIEncodedTransactionData(),
takerAssetData: deployment.assetDataEncoder
.ERC20Token(takerToken.address)
.getABIEncodedTransactionData(),
makerFeeAssetData: deployment.assetDataEncoder
.ERC20Token(feeToken.address)
.getABIEncodedTransactionData(),
takerFeeAssetData: deployment.assetDataEncoder
.ERC20Token(feeToken.address)
.getABIEncodedTransactionData(),
feeRecipientAddress: feeRecipient,
},
});
@ -98,9 +101,9 @@ blockchainTests.resets('Exchange wrappers', env => {
},
{
erc20: {
makerAsset: deployment.tokens.erc20[0],
takerAsset: deployment.tokens.erc20[1],
feeAsset: deployment.tokens.erc20[2],
makerToken,
takerToken,
feeToken,
weth: deployment.tokens.weth,
},
},
@ -109,22 +112,15 @@ blockchainTests.resets('Exchange wrappers', env => {
await blockchainBalances.updateBalancesAsync();
initialLocalBalances = LocalBalanceStore.create(devUtils, blockchainBalances);
initialLocalBalances = LocalBalanceStore.create(deployment.devUtils, blockchainBalances);
wethAssetData = deployment.assetDataEncoder.ERC20Token.getABIEncodedTransactionData(
deployment.tokens.weth.address,
);
txHelper = new TransactionHelper(env.web3Wrapper, {
...assetProxyArtifacts,
...exchangeArtifacts,
...stakingArtifacts,
...erc20Artifacts,
});
wethAssetData = deployment.assetDataEncoder
.ERC20Token(deployment.tokens.weth.address)
.getABIEncodedTransactionData();
});
beforeEach(async () => {
localBalances = LocalBalanceStore.create(devUtils, initialLocalBalances);
localBalances = LocalBalanceStore.create(deployment.devUtils, initialLocalBalances);
});
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 () => {
const differentTakerAssetData = deployment.assetDataEncoder.ERC20Token.getABIEncodedTransactionData(
deployment.tokens.erc20[2].address,
);
const differentTakerAssetData = deployment.assetDataEncoder
.ERC20Token(feeToken.address)
.getABIEncodedTransactionData();
signedOrders = [
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 () => {
const differentTakerAssetData = deployment.assetDataEncoder.ERC20Token.getABIEncodedTransactionData(
deployment.tokens.erc20[2].address,
);
const differentTakerAssetData = deployment.assetDataEncoder
.ERC20Token(feeToken.address)
.getABIEncodedTransactionData();
signedOrders = [
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 () => {
const differentMakerAssetData = deployment.assetDataEncoder.ERC20Token.getABIEncodedTransactionData(
deployment.tokens.erc20[2].address,
);
const differentMakerAssetData = deployment.assetDataEncoder
.ERC20Token(feeToken.address)
.getABIEncodedTransactionData();
signedOrders = [
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 () => {
const differentMakerAssetData = deployment.assetDataEncoder.ERC20Token.getABIEncodedTransactionData(
deployment.tokens.erc20[2].address,
);
const differentMakerAssetData = deployment.assetDataEncoder
.ERC20Token(feeToken.address)
.getABIEncodedTransactionData();
signedOrders = [
await maker.signOrderAsync(),

View File

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

View File

@ -1,7 +1,6 @@
import { artifacts as exchangeArtifacts } from '@0x/contracts-exchange';
import { artifacts, ForwarderContract } from '@0x/contracts-exchange-forwarder';
import { BlockchainTestsEnvironment } from '@0x/contracts-test-utils';
import { assetDataUtils } from '@0x/order-utils';
import { DeploymentManager } from '../framework/deployment_manager';
@ -18,6 +17,6 @@ export async function deployForwarderAsync(
deployment.txDefaults,
{ ...exchangeArtifacts, ...artifacts },
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;
[erc721Token] = deployment.tokens.erc721;
wethAssetData = deployment.assetDataEncoder.ERC20Token.getABIEncodedTransactionData(
deployment.tokens.weth.address,
);
makerAssetData = deployment.assetDataEncoder.ERC20Token.getABIEncodedTransactionData(makerToken.address);
wethAssetData = deployment.assetDataEncoder
.ERC20Token(deployment.tokens.weth.address)
.getABIEncodedTransactionData();
makerAssetData = deployment.assetDataEncoder.ERC20Token(makerToken.address).getABIEncodedTransactionData();
taker = new Taker({ name: 'Taker', deployment });
orderFeeRecipient = new FeeRecipient({
@ -80,9 +80,9 @@ blockchainTests('Forwarder integration tests', env => {
makerAssetData,
takerAssetData: wethAssetData,
takerFee: constants.ZERO_AMOUNT,
makerFeeAssetData: deployment.assetDataEncoder.ERC20Token.getABIEncodedTransactionData(
makerFeeToken.address,
),
makerFeeAssetData: deployment.assetDataEncoder
.ERC20Token(makerFeeToken.address)
.getABIEncodedTransactionData(),
takerFeeAssetData: wethAssetData,
},
});
@ -174,9 +174,9 @@ blockchainTests('Forwarder integration tests', env => {
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 () => {
const unapprovedAsset = deployment.assetDataEncoder.ERC20Token.getABIEncodedTransactionData(
anotherErc20Token.address,
);
const unapprovedAsset = deployment.assetDataEncoder
.ERC20Token(anotherErc20Token.address)
.getABIEncodedTransactionData();
const order = await maker.signOrderAsync({
makerAssetData: unapprovedAsset,
takerFee: toBaseUnitAmount(2),
@ -248,9 +248,9 @@ blockchainTests('Forwarder integration tests', env => {
});
it('should fill orders with different makerAssetData', async () => {
const firstOrder = await maker.signOrderAsync();
const secondOrderMakerAssetData = deployment.assetDataEncoder.ERC20Token.getABIEncodedTransactionData(
anotherErc20Token.address,
);
const secondOrderMakerAssetData = deployment.assetDataEncoder
.ERC20Token(anotherErc20Token.address)
.getABIEncodedTransactionData();
const secondOrder = await maker.signOrderAsync({
makerAssetData: secondOrderMakerAssetData,
});
@ -259,9 +259,9 @@ blockchainTests('Forwarder integration tests', env => {
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 () => {
const takerFeeAssetData = deployment.assetDataEncoder.ERC20Token.getABIEncodedTransactionData(
anotherErc20Token.address,
);
const takerFeeAssetData = deployment.assetDataEncoder
.ERC20Token(anotherErc20Token.address)
.getABIEncodedTransactionData();
const order = await maker.signOrderAsync({
takerFeeAssetData,
takerFee: toBaseUnitAmount(1),
@ -352,9 +352,9 @@ blockchainTests('Forwarder integration tests', env => {
});
it('should buy exactly makerAssetBuyAmount in orders with different makerAssetData', async () => {
const firstOrder = await maker.signOrderAsync();
const secondOrderMakerAssetData = deployment.assetDataEncoder.ERC20Token.getABIEncodedTransactionData(
anotherErc20Token.address,
);
const secondOrderMakerAssetData = deployment.assetDataEncoder
.ERC20Token(anotherErc20Token.address)
.getABIEncodedTransactionData();
const secondOrder = await maker.signOrderAsync({
makerAssetData: secondOrderMakerAssetData,
});
@ -403,10 +403,9 @@ blockchainTests('Forwarder integration tests', env => {
it('should buy an ERC721 asset from a single order', async () => {
const erc721Order = await maker.signOrderAsync({
makerAssetAmount: new BigNumber(1),
makerAssetData: deployment.assetDataEncoder.ERC721Token.getABIEncodedTransactionData(
erc721Token.address,
nftId,
),
makerAssetData: deployment.assetDataEncoder
.ERC721Token(erc721Token.address, nftId)
.getABIEncodedTransactionData(),
takerFeeAssetData: wethAssetData,
});
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 () => {
const erc721orderWithWethFee = await maker.signOrderAsync({
makerAssetAmount: new BigNumber(1),
makerAssetData: deployment.assetDataEncoder.ERC721Token.getABIEncodedTransactionData(
erc721Token.address,
nftId,
),
makerAssetData: deployment.assetDataEncoder
.ERC721Token(erc721Token.address, nftId)
.getABIEncodedTransactionData(),
takerFee: toBaseUnitAmount(1),
takerFeeAssetData: wethAssetData,
});
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 () => {
const takerFeeAssetData = deployment.assetDataEncoder.ERC20Token.getABIEncodedTransactionData(
anotherErc20Token.address,
);
const takerFeeAssetData = deployment.assetDataEncoder
.ERC20Token(anotherErc20Token.address)
.getABIEncodedTransactionData();
const order = await maker.signOrderAsync({
takerFeeAssetData,
takerFee: toBaseUnitAmount(1),

View File

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

View File

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

View File

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

View File

@ -19,7 +19,7 @@ import {
TestStakingContract,
ZrxVaultContract,
} 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 { TxData } from 'ethereum-types';
import * as _ from 'lodash';
@ -196,16 +196,6 @@ export class DeploymentManager {
const devUtils = new DevUtilsContract(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.
return new DeploymentManager(
assetProxies,
@ -218,7 +208,6 @@ export class DeploymentManager {
txDefaults,
devUtils,
assetDataEncoder,
txHelper,
);
}
@ -510,7 +499,6 @@ export class DeploymentManager {
public txDefaults: Partial<TxData>,
public devUtils: DevUtilsContract,
public assetDataEncoder: IAssetDataContract,
public txHelper: TransactionHelper,
) {}
}
// tslint:disable:max-file-line-count

View File

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

View File

@ -1,6 +1,5 @@
import { BlockchainBalanceStore, LocalBalanceStore } from '@0x/contracts-exchange';
import { constants, expect, OrderStatus } from '@0x/contracts-test-utils';
import { orderHashUtils } from '@0x/order-utils';
import { constants, expect, orderHashUtils, OrderStatus } from '@0x/contracts-test-utils';
import { BatchMatchedFillResults, FillResults, MatchedFillResults, SignedOrder } from '@0x/types';
import { BigNumber } from '@0x/utils';
import { LogWithDecodedArgs, TransactionReceiptWithDecodedLogs } from 'ethereum-types';
@ -115,23 +114,39 @@ export class MatchOrderTester {
let actualBatchMatchResults;
let transactionReceipt;
if (withMaximalFill) {
[actualBatchMatchResults, transactionReceipt] = await this._deployment.txHelper.getResultAndReceiptAsync(
this._deployment.exchange.batchMatchOrdersWithMaximalFill,
const tx = this._deployment.exchange.batchMatchOrdersWithMaximalFill(
orders.leftOrders,
orders.rightOrders,
orders.leftOrders.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 {
[actualBatchMatchResults, transactionReceipt] = await this._deployment.txHelper.getResultAndReceiptAsync(
this._deployment.exchange.batchMatchOrders,
const tx = this._deployment.exchange.batchMatchOrders(
orders.leftOrders,
orders.rightOrders,
orders.leftOrders.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.
@ -184,23 +199,39 @@ export class MatchOrderTester {
let actualMatchResults;
let transactionReceipt;
if (withMaximalFill) {
[actualMatchResults, transactionReceipt] = await this._deployment.txHelper.getResultAndReceiptAsync(
this._deployment.exchange.matchOrdersWithMaximalFill,
const tx = this._deployment.exchange.matchOrdersWithMaximalFill(
orders.leftOrder,
orders.rightOrder,
orders.leftOrder.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 {
[actualMatchResults, transactionReceipt] = await this._deployment.txHelper.getResultAndReceiptAsync(
this._deployment.exchange.matchOrders,
const tx = this._deployment.exchange.matchOrders(
orders.leftOrder,
orders.rightOrder,
orders.leftOrder.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));
@ -320,9 +351,9 @@ export class MatchOrderTester {
);
// Protocol Fee
const wethAssetData = this._deployment.assetDataEncoder.ERC20Token.getABIEncodedTransactionData(
this._deployment.tokens.weth.address,
);
const wethAssetData = this._deployment.assetDataEncoder
.ERC20Token(this._deployment.tokens.weth.address)
.getABIEncodedTransactionData();
localBalanceStore.sendEth(
takerAddress,
this._deployment.staking.stakingProxy.address,
@ -616,7 +647,7 @@ export class MatchOrderTester {
expectedFilledAmount: BigNumber,
side: string,
): 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.
const actualFilledAmount = orderInfo.orderTakerAssetFilledAmount;
expect(actualFilledAmount, `${side} order final filled amount`).to.be.bignumber.equal(expectedFilledAmount);