Update coordinator, exchange-forwarder, exchange-libs, exchange, and extensions contract tests to use new order and transaction structure

This commit is contained in:
Lawrence Forman
2019-04-01 13:27:17 -04:00
committed by Amir Bandeali
parent 259b463b73
commit b8f056b82f
17 changed files with 110 additions and 60 deletions

View File

@@ -208,12 +208,14 @@ describe('Exchange core', () => {
defaultTakerAssetAddress = erc20TokenB.address;
const defaultOrderParams = {
...constants.STATIC_ORDER_PARAMS,
exchangeAddress: exchange.address,
chainId,
makerAddress,
feeRecipientAddress,
makerAssetData: assetDataUtils.encodeERC20AssetData(defaultMakerAssetAddress),
takerAssetData: assetDataUtils.encodeERC20AssetData(defaultTakerAssetAddress),
domain: {
verifyingContractAddress: exchange.address,
chainId,
},
};
const privateKey = constants.TESTRPC_PRIVATE_KEYS[accounts.indexOf(makerAddress)];
orderFactory = new OrderFactory(privateKey, defaultOrderParams);

View File

@@ -36,10 +36,12 @@ const emptyOrder: Order = {
makerAssetData: '0x',
takerAssetData: '0x',
salt: new BigNumber(0),
exchangeAddress: constants.NULL_ADDRESS,
chainId: 0, // To be filled in later.
feeRecipientAddress: constants.NULL_ADDRESS,
expirationTimeSeconds: new BigNumber(0),
domain: {
verifyingContractAddress: constants.NULL_ADDRESS,
chainId: 0, // To be filled in later.
},
};
const emptySignedOrder: SignedOrder = {
@@ -64,8 +66,8 @@ describe('Exchange core internal functions', () => {
});
before(async () => {
chainId = await providerUtils.getChainIdAsync(provider);
emptyOrder.chainId = chainId;
emptySignedOrder.chainId = chainId;
emptyOrder.domain.chainId = chainId;
emptySignedOrder.domain.chainId = chainId;
testExchange = await TestExchangeInternalsContract.deployFrom0xArtifactAsync(
artifacts.TestExchangeInternals,

View File

@@ -152,24 +152,26 @@ describe('matchOrders', () => {
defaultERC20MakerAssetAddress = erc20TokenA.address;
defaultERC20TakerAssetAddress = erc20TokenB.address;
defaultERC721AssetAddress = erc721Token.address;
const domain = {
verifyingContractAddress: exchange.address,
chainId,
};
// Create default order parameters
const defaultOrderParamsLeft = {
...constants.STATIC_ORDER_PARAMS,
makerAddress: makerAddressLeft,
exchangeAddress: exchange.address,
chainId,
makerAssetData: assetDataUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress),
takerAssetData: assetDataUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress),
feeRecipientAddress: feeRecipientAddressLeft,
domain,
};
const defaultOrderParamsRight = {
...constants.STATIC_ORDER_PARAMS,
makerAddress: makerAddressRight,
exchangeAddress: exchange.address,
chainId,
makerAssetData: assetDataUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress),
takerAssetData: assetDataUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress),
feeRecipientAddress: feeRecipientAddressRight,
domain,
};
const privateKeyLeft = constants.TESTRPC_PRIVATE_KEYS[accounts.indexOf(makerAddressLeft)];
orderFactoryLeft = new OrderFactory(privateKeyLeft, defaultOrderParamsLeft);

View File

@@ -101,12 +101,14 @@ describe('MixinSignatureValidator', () => {
const defaultOrderParams = {
...constants.STATIC_ORDER_PARAMS,
exchangeAddress: signatureValidator.address,
chainId,
makerAddress,
feeRecipientAddress: addressUtils.generatePseudoRandomAddress(),
makerAssetData: assetDataUtils.encodeERC20AssetData(addressUtils.generatePseudoRandomAddress()),
takerAssetData: assetDataUtils.encodeERC20AssetData(addressUtils.generatePseudoRandomAddress()),
domain: {
verifyingContractAddress: signatureValidator.address,
chainId,
},
};
signerPrivateKey = constants.TESTRPC_PRIVATE_KEYS[accounts.indexOf(makerAddress)];
notSignerPrivateKey = constants.TESTRPC_PRIVATE_KEYS[accounts.indexOf(notSignerAddress)];

View File

@@ -14,7 +14,13 @@ import {
} from '@0x/contracts-test-utils';
import { BlockchainLifecycle } from '@0x/dev-utils';
import { assetDataUtils, generatePseudoRandomSalt } from '@0x/order-utils';
import { OrderWithoutExchangeAddress, RevertReason, SignedOrder, SignedZeroExTransaction } from '@0x/types';
import {
EIP712DomainWithDefaultSchema,
OrderWithoutDomain,
RevertReason,
SignedOrder,
SignedZeroExTransaction
} from '@0x/types';
import { BigNumber, providerUtils } from '@0x/utils';
import * as chai from 'chai';
import * as _ from 'lodash';
@@ -40,9 +46,10 @@ describe('Exchange transactions', () => {
let erc20Proxy: ERC20ProxyContract;
let erc20Balances: ERC20BalancesByOwner;
let domain: EIP712DomainWithDefaultSchema;
let signedOrder: SignedOrder;
let signedTx: SignedZeroExTransaction;
let orderWithoutExchangeAddress: OrderWithoutExchangeAddress;
let orderWithoutExchangeAddress: OrderWithoutDomain;
let orderFactory: OrderFactory;
let makerTransactionFactory: TransactionFactory;
let takerTransactionFactory: TransactionFactory;
@@ -103,15 +110,19 @@ describe('Exchange transactions', () => {
defaultMakerTokenAddress = erc20TokenA.address;
defaultTakerTokenAddress = erc20TokenB.address;
domain = {
verifyingContractAddress: exchange.address,
chainId,
};
const defaultOrderParams = {
...constants.STATIC_ORDER_PARAMS,
senderAddress,
exchangeAddress: exchange.address,
chainId,
makerAddress,
feeRecipientAddress,
makerAssetData: assetDataUtils.encodeERC20AssetData(defaultMakerTokenAddress),
takerAssetData: assetDataUtils.encodeERC20AssetData(defaultTakerTokenAddress),
domain,
};
makerPrivateKey = constants.TESTRPC_PRIVATE_KEYS[accounts.indexOf(makerAddress)];
takerPrivateKey = constants.TESTRPC_PRIVATE_KEYS[accounts.indexOf(takerAddress)];
@@ -125,7 +136,7 @@ describe('Exchange transactions', () => {
beforeEach(async () => {
erc20Balances = await erc20Wrapper.getBalancesAsync();
signedOrder = await orderFactory.newSignedOrderAsync();
orderWithoutExchangeAddress = orderUtils.getOrderWithoutExchangeAddress(signedOrder);
orderWithoutExchangeAddress = orderUtils.getOrderWithoutDomain(signedOrder);
takerAssetFillAmount = signedOrder.takerAssetAmount.div(2);
const data = exchange.fillOrder.getABIEncodedTransactionData(
@@ -246,7 +257,7 @@ describe('Exchange transactions', () => {
);
const takerAssetFillAmount = signedOrder.takerAssetAmount;
orderWithoutExchangeAddress = orderUtils.getOrderWithoutExchangeAddress(signedOrder);
orderWithoutExchangeAddress = orderUtils.getOrderWithoutDomain(signedOrder);
const fillData = exchange.fillOrder.getABIEncodedTransactionData(
orderWithoutExchangeAddress,
takerAssetFillAmount,
@@ -277,7 +288,7 @@ describe('Exchange transactions', () => {
erc20Balances = await erc20Wrapper.getBalancesAsync();
const takerAssetFillAmount = signedOrder.takerAssetAmount;
orderWithoutExchangeAddress = orderUtils.getOrderWithoutExchangeAddress(signedOrder);
orderWithoutExchangeAddress = orderUtils.getOrderWithoutDomain(signedOrder);
const data = exchange.fillOrder.getABIEncodedTransactionData(
orderWithoutExchangeAddress,
takerAssetFillAmount,
@@ -349,12 +360,11 @@ describe('Exchange transactions', () => {
const defaultOrderParams = {
...constants.STATIC_ORDER_PARAMS,
senderAddress: whitelist.address,
exchangeAddress: exchange.address,
chainId,
makerAddress,
feeRecipientAddress,
makerAssetData: assetDataUtils.encodeERC20AssetData(defaultMakerTokenAddress),
takerAssetData: assetDataUtils.encodeERC20AssetData(defaultTakerTokenAddress),
domain,
};
whitelistOrderFactory = new OrderFactory(makerPrivateKey, defaultOrderParams);
});
@@ -371,7 +381,7 @@ describe('Exchange transactions', () => {
constants.AWAIT_TRANSACTION_MINED_MS,
);
orderWithoutExchangeAddress = orderUtils.getOrderWithoutExchangeAddress(signedOrder);
orderWithoutExchangeAddress = orderUtils.getOrderWithoutDomain(signedOrder);
const takerAssetFillAmount = signedOrder.takerAssetAmount;
const salt = generatePseudoRandomSalt();
return expectTransactionFailedAsync(
@@ -393,7 +403,7 @@ describe('Exchange transactions', () => {
constants.AWAIT_TRANSACTION_MINED_MS,
);
orderWithoutExchangeAddress = orderUtils.getOrderWithoutExchangeAddress(signedOrder);
orderWithoutExchangeAddress = orderUtils.getOrderWithoutDomain(signedOrder);
const takerAssetFillAmount = signedOrder.takerAssetAmount;
const salt = generatePseudoRandomSalt();
return expectTransactionFailedAsync(
@@ -420,7 +430,7 @@ describe('Exchange transactions', () => {
constants.AWAIT_TRANSACTION_MINED_MS,
);
orderWithoutExchangeAddress = orderUtils.getOrderWithoutExchangeAddress(signedOrder);
orderWithoutExchangeAddress = orderUtils.getOrderWithoutDomain(signedOrder);
const takerAssetFillAmount = signedOrder.takerAssetAmount;
const salt = generatePseudoRandomSalt();
await web3Wrapper.awaitTransactionSuccessAsync(

View File

@@ -287,10 +287,12 @@ export class OrderFactoryFromScenario {
makerAssetData,
takerAssetData,
salt: generatePseudoRandomSalt(),
exchangeAddress: this._exchangeAddress,
chainId: this._chainId,
feeRecipientAddress,
expirationTimeSeconds,
domain: {
verifyingContractAddress: this._exchangeAddress,
chainId: this._chainId,
},
};
return order;

View File

@@ -121,12 +121,14 @@ describe('Exchange wrappers', () => {
const defaultOrderParams = {
...constants.STATIC_ORDER_PARAMS,
exchangeAddress: exchange.address,
chainId,
makerAddress,
feeRecipientAddress,
makerAssetData: assetDataUtils.encodeERC20AssetData(defaultMakerAssetAddress),
takerAssetData: assetDataUtils.encodeERC20AssetData(defaultTakerAssetAddress),
domain: {
verifyingContractAddress: exchange.address,
chainId,
},
};
const privateKey = constants.TESTRPC_PRIVATE_KEYS[accounts.indexOf(makerAddress)];
orderFactory = new OrderFactory(privateKey, defaultOrderParams);