Migrate all contract-related tooling and tests to accept a chain ID in domain separators.

This commit is contained in:
Lawrence Forman
2019-03-22 16:18:49 -04:00
committed by Amir Bandeali
parent 92fe720ac3
commit 2d28fde24d
39 changed files with 282 additions and 64 deletions

View File

@@ -2,7 +2,7 @@ import { ExchangeContract, ExchangeWrapper } from '@0x/contracts-exchange';
import { BlockchainLifecycle } from '@0x/dev-utils';
import { assetDataUtils } from '@0x/order-utils';
import { Order, RevertReason, SignedOrder } from '@0x/types';
import { BigNumber } from '@0x/utils';
import { BigNumber, providerUtils } from '@0x/utils';
import { Web3Wrapper } from '@0x/web3-wrapper';
import * as chai from 'chai';
import { TransactionReceiptWithDecodedLogs } from 'ethereum-types';
@@ -40,6 +40,7 @@ describe(ContractName.BalanceThresholdFilter, () => {
const makerAssetAmount = Web3Wrapper.toBaseUnitAmount(new BigNumber(1000), DECIMALS_DEFAULT);
const takerAssetFillAmount = Web3Wrapper.toBaseUnitAmount(new BigNumber(250), DECIMALS_DEFAULT);
let chainId: number;
let validMakerAddress: string;
let validMakerAddress2: string;
let owner: string;
@@ -88,6 +89,8 @@ describe(ContractName.BalanceThresholdFilter, () => {
};
before(async () => {
// Get the chain ID.
chainId = await providerUtils.getChainIdAsync(provider);
// Create accounts
await blockchainLifecycle.startAsync();
const accounts = await web3Wrapper.getAvailableAddressesAsync();
@@ -131,6 +134,7 @@ describe(ContractName.BalanceThresholdFilter, () => {
provider,
txDefaults,
zrxAssetData,
new BigNumber(chainId),
);
exchangeWrapper = new ExchangeWrapper(exchangeInstance, provider);
// Register proxies
@@ -164,6 +168,7 @@ describe(ContractName.BalanceThresholdFilter, () => {
// Default order parameters
defaultOrderParams = {
exchangeAddress: exchangeInstance.address,
chainId,
feeRecipientAddress,
makerAssetData: assetDataUtils.encodeERC20AssetData(defaultMakerAssetAddress),
takerAssetData: assetDataUtils.encodeERC20AssetData(defaultTakerAssetAddress),
@@ -197,25 +202,25 @@ describe(ContractName.BalanceThresholdFilter, () => {
erc20TakerBalanceThresholdWrapper = new BalanceThresholdWrapper(
erc20BalanceThresholdFilterInstance,
exchangeInstance,
new TransactionFactory(takerPrivateKey, exchangeInstance.address),
new TransactionFactory(takerPrivateKey, exchangeInstance.address, chainId),
provider,
);
erc721TakerBalanceThresholdWrapper = new BalanceThresholdWrapper(
erc721BalanceThresholdFilterInstance,
exchangeInstance,
new TransactionFactory(takerPrivateKey, exchangeInstance.address),
new TransactionFactory(takerPrivateKey, exchangeInstance.address, chainId),
provider,
);
erc721MakerBalanceThresholdWrapper = new BalanceThresholdWrapper(
erc721BalanceThresholdFilterInstance,
exchangeInstance,
new TransactionFactory(makerPrivateKey, exchangeInstance.address),
new TransactionFactory(makerPrivateKey, exchangeInstance.address, chainId),
provider,
);
erc721NonValidBalanceThresholdWrapper = new BalanceThresholdWrapper(
erc721BalanceThresholdFilterInstance,
exchangeInstance,
new TransactionFactory(invalidAddressPrivateKey, exchangeInstance.address),
new TransactionFactory(invalidAddressPrivateKey, exchangeInstance.address, chainId),
provider,
);
});

View File

@@ -18,7 +18,7 @@ import {
import { BlockchainLifecycle } from '@0x/dev-utils';
import { assetDataUtils, generatePseudoRandomSalt } from '@0x/order-utils';
import { RevertReason, SignedOrder } from '@0x/types';
import { BigNumber } from '@0x/utils';
import { BigNumber, providerUtils } from '@0x/utils';
import { Web3Wrapper } from '@0x/web3-wrapper';
import * as chai from 'chai';
import * as _ from 'lodash';
@@ -31,6 +31,7 @@ const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
const DECIMALS_DEFAULT = 18;
describe(ContractName.DutchAuction, () => {
let chainId: number;
let makerAddress: string;
let owner: string;
let takerAddress: string;
@@ -62,6 +63,8 @@ describe(ContractName.DutchAuction, () => {
before(async () => {
await blockchainLifecycle.startAsync();
chainId = await providerUtils.getChainIdAsync(provider);
const accounts = await web3Wrapper.getAvailableAddressesAsync();
const usedAddresses = ([owner, makerAddress, takerAddress, feeRecipientAddress] = accounts);
@@ -91,6 +94,7 @@ describe(ContractName.DutchAuction, () => {
provider,
txDefaults,
zrxAssetData,
new BigNumber(chainId),
);
const exchangeWrapper = new ExchangeWrapper(exchangeInstance, provider);
await exchangeWrapper.registerAssetProxyAsync(erc20Proxy.address, owner);
@@ -145,6 +149,7 @@ describe(ContractName.DutchAuction, () => {
const sellerDefaultOrderParams = {
salt: generatePseudoRandomSalt(),
exchangeAddress: exchangeInstance.address,
chainId,
makerAddress,
feeRecipientAddress,
// taker address or sender address should be set to the ducth auction contract

View File

@@ -23,7 +23,7 @@ import {
import { BlockchainLifecycle } from '@0x/dev-utils';
import { assetDataUtils } from '@0x/order-utils';
import { RevertReason } from '@0x/types';
import { BigNumber } from '@0x/utils';
import { BigNumber, providerUtils } from '@0x/utils';
import { Web3Wrapper } from '@0x/web3-wrapper';
import * as chai from 'chai';
import { LogWithDecodedArgs } from 'ethereum-types';
@@ -36,6 +36,7 @@ chaiSetup.configure();
const expect = chai.expect;
// tslint:disable:no-unnecessary-type-assertion
describe('OrderMatcher', () => {
let chainId: number;
let makerAddressLeft: string;
let makerAddressRight: string;
let owner: string;
@@ -69,6 +70,7 @@ describe('OrderMatcher', () => {
await blockchainLifecycle.revertAsync();
});
before(async () => {
chainId = await providerUtils.getChainIdAsync(provider);
// Create accounts
const accounts = await web3Wrapper.getAvailableAddressesAsync();
// Hack(albrow): Both Prettier and TSLint insert a trailing comma below
@@ -110,6 +112,7 @@ describe('OrderMatcher', () => {
provider,
txDefaults,
assetDataUtils.encodeERC20AssetData(zrxToken.address),
new BigNumber(chainId),
);
exchangeWrapper = new ExchangeWrapper(exchange, provider);
await exchangeWrapper.registerAssetProxyAsync(erc20Proxy.address, owner);
@@ -165,6 +168,7 @@ describe('OrderMatcher', () => {
...constants.STATIC_ORDER_PARAMS,
makerAddress: makerAddressLeft,
exchangeAddress: exchange.address,
chainId,
makerAssetData: leftMakerAssetData,
takerAssetData: leftTakerAssetData,
feeRecipientAddress: feeRecipientAddressLeft,
@@ -175,6 +179,7 @@ describe('OrderMatcher', () => {
...constants.STATIC_ORDER_PARAMS,
makerAddress: makerAddressRight,
exchangeAddress: exchange.address,
chainId,
makerAssetData: leftTakerAssetData,
takerAssetData: leftMakerAssetData,
feeRecipientAddress: feeRecipientAddressRight,
@@ -199,6 +204,7 @@ describe('OrderMatcher', () => {
provider,
txDefaults,
constants.NULL_BYTES,
new BigNumber(chainId),
);
return expectContractCreationFailedAsync(
(OrderMatcherContract.deployFrom0xArtifactAsync(