Migrate all contract-related tooling and tests to accept a chain ID in domain separators.
This commit is contained in:
committed by
Amir Bandeali
parent
92fe720ac3
commit
2d28fde24d
@@ -33,7 +33,7 @@ import {
|
||||
import { BlockchainLifecycle } from '@0x/dev-utils';
|
||||
import { assetDataUtils, orderHashUtils } from '@0x/order-utils';
|
||||
import { RevertReason, SignatureType, 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 { LogWithDecodedArgs } from 'ethereum-types';
|
||||
@@ -55,6 +55,7 @@ const expect = chai.expect;
|
||||
const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
|
||||
// tslint:disable:no-unnecessary-type-assertion
|
||||
describe('Exchange core', () => {
|
||||
let chainId: number;
|
||||
let makerAddress: string;
|
||||
let owner: string;
|
||||
let takerAddress: string;
|
||||
@@ -102,6 +103,7 @@ describe('Exchange core', () => {
|
||||
await blockchainLifecycle.revertAsync();
|
||||
});
|
||||
before(async () => {
|
||||
chainId = await providerUtils.getChainIdAsync(provider);
|
||||
const accounts = await web3Wrapper.getAvailableAddressesAsync();
|
||||
const usedAddresses = ([owner, makerAddress, takerAddress, feeRecipientAddress] = _.slice(accounts, 0, 4));
|
||||
|
||||
@@ -136,6 +138,7 @@ describe('Exchange core', () => {
|
||||
provider,
|
||||
txDefaults,
|
||||
assetDataUtils.encodeERC20AssetData(zrxToken.address),
|
||||
new BigNumber(chainId),
|
||||
);
|
||||
maliciousWallet = maliciousValidator = await TestStaticCallReceiverContract.deployFrom0xArtifactAsync(
|
||||
artifacts.TestStaticCallReceiver,
|
||||
@@ -206,6 +209,7 @@ describe('Exchange core', () => {
|
||||
const defaultOrderParams = {
|
||||
...constants.STATIC_ORDER_PARAMS,
|
||||
exchangeAddress: exchange.address,
|
||||
chainId,
|
||||
makerAddress,
|
||||
feeRecipientAddress,
|
||||
makerAssetData: assetDataUtils.encodeERC20AssetData(defaultMakerAssetAddress),
|
||||
|
@@ -12,7 +12,7 @@ import {
|
||||
} from '@0x/contracts-test-utils';
|
||||
import { BlockchainLifecycle } from '@0x/dev-utils';
|
||||
import { Order, RevertReason, SignedOrder } from '@0x/types';
|
||||
import { BigNumber } from '@0x/utils';
|
||||
import { BigNumber, providerUtils } from '@0x/utils';
|
||||
import * as chai from 'chai';
|
||||
import * as _ from 'lodash';
|
||||
|
||||
@@ -37,6 +37,7 @@ const emptyOrder: Order = {
|
||||
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),
|
||||
};
|
||||
@@ -49,6 +50,7 @@ const emptySignedOrder: SignedOrder = {
|
||||
const overflowErrorForCall = new Error(RevertReason.Uint256Overflow);
|
||||
|
||||
describe('Exchange core internal functions', () => {
|
||||
let chainId: number;
|
||||
let testExchange: TestExchangeInternalsContract;
|
||||
let overflowErrorForSendTransaction: Error | undefined;
|
||||
let divisionByZeroErrorForCall: Error | undefined;
|
||||
@@ -61,10 +63,15 @@ describe('Exchange core internal functions', () => {
|
||||
await blockchainLifecycle.revertAsync();
|
||||
});
|
||||
before(async () => {
|
||||
chainId = await providerUtils.getChainIdAsync(provider);
|
||||
emptyOrder.chainId = chainId;
|
||||
emptySignedOrder.chainId = chainId;
|
||||
|
||||
testExchange = await TestExchangeInternalsContract.deployFrom0xArtifactAsync(
|
||||
artifacts.TestExchangeInternals,
|
||||
provider,
|
||||
txDefaults,
|
||||
new BigNumber(chainId),
|
||||
);
|
||||
overflowErrorForSendTransaction = new Error(
|
||||
await getRevertReasonOrErrorMessageForSendTransactionAsync(RevertReason.Uint256Overflow),
|
||||
|
@@ -15,7 +15,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 * as _ from 'lodash';
|
||||
@@ -34,6 +34,7 @@ chaiSetup.configure();
|
||||
const expect = chai.expect;
|
||||
|
||||
describe('matchOrders', () => {
|
||||
let chainId: number;
|
||||
let makerAddressLeft: string;
|
||||
let makerAddressRight: string;
|
||||
let owner: string;
|
||||
@@ -76,6 +77,8 @@ describe('matchOrders', () => {
|
||||
await blockchainLifecycle.revertAsync();
|
||||
});
|
||||
before(async () => {
|
||||
// Get the chain ID.
|
||||
chainId = await providerUtils.getChainIdAsync(provider);
|
||||
// Create accounts
|
||||
const accounts = await web3Wrapper.getAvailableAddressesAsync();
|
||||
// Hack(albrow): Both Prettier and TSLint insert a trailing comma below
|
||||
@@ -119,6 +122,7 @@ describe('matchOrders', () => {
|
||||
provider,
|
||||
txDefaults,
|
||||
assetDataUtils.encodeERC20AssetData(zrxToken.address),
|
||||
new BigNumber(chainId)
|
||||
);
|
||||
exchangeWrapper = new ExchangeWrapper(exchange, provider);
|
||||
await exchangeWrapper.registerAssetProxyAsync(erc20Proxy.address, owner);
|
||||
@@ -153,6 +157,7 @@ describe('matchOrders', () => {
|
||||
...constants.STATIC_ORDER_PARAMS,
|
||||
makerAddress: makerAddressLeft,
|
||||
exchangeAddress: exchange.address,
|
||||
chainId,
|
||||
makerAssetData: assetDataUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress),
|
||||
takerAssetData: assetDataUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress),
|
||||
feeRecipientAddress: feeRecipientAddressLeft,
|
||||
@@ -161,6 +166,7 @@ describe('matchOrders', () => {
|
||||
...constants.STATIC_ORDER_PARAMS,
|
||||
makerAddress: makerAddressRight,
|
||||
exchangeAddress: exchange.address,
|
||||
chainId,
|
||||
makerAssetData: assetDataUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress),
|
||||
takerAssetData: assetDataUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress),
|
||||
feeRecipientAddress: feeRecipientAddressRight,
|
||||
@@ -175,6 +181,7 @@ describe('matchOrders', () => {
|
||||
artifacts.TestExchangeInternals,
|
||||
provider,
|
||||
txDefaults,
|
||||
new BigNumber(chainId),
|
||||
);
|
||||
});
|
||||
beforeEach(async () => {
|
||||
|
@@ -12,6 +12,7 @@ import {
|
||||
import { BlockchainLifecycle } from '@0x/dev-utils';
|
||||
import { assetDataUtils, orderHashUtils, signatureUtils } from '@0x/order-utils';
|
||||
import { RevertReason, SignatureType, SignedOrder } from '@0x/types';
|
||||
import { BigNumber, providerUtils } from '@0x/utils';
|
||||
import * as chai from 'chai';
|
||||
import { LogWithDecodedArgs } from 'ethereum-types';
|
||||
import ethUtil = require('ethereumjs-util');
|
||||
@@ -31,6 +32,7 @@ const expect = chai.expect;
|
||||
const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
|
||||
// tslint:disable:no-unnecessary-type-assertion
|
||||
describe('MixinSignatureValidator', () => {
|
||||
let chainId: number;
|
||||
let signedOrder: SignedOrder;
|
||||
let orderFactory: OrderFactory;
|
||||
let signatureValidator: TestSignatureValidatorContract;
|
||||
@@ -51,6 +53,7 @@ describe('MixinSignatureValidator', () => {
|
||||
await blockchainLifecycle.revertAsync();
|
||||
});
|
||||
before(async () => {
|
||||
chainId = await providerUtils.getChainIdAsync(provider);
|
||||
const accounts = await web3Wrapper.getAvailableAddressesAsync();
|
||||
const makerAddress = accounts[0];
|
||||
signerAddress = makerAddress;
|
||||
@@ -59,6 +62,7 @@ describe('MixinSignatureValidator', () => {
|
||||
artifacts.TestSignatureValidator,
|
||||
provider,
|
||||
txDefaults,
|
||||
new BigNumber(chainId),
|
||||
);
|
||||
testWallet = await WalletContract.deployFrom0xArtifactAsync(
|
||||
artifacts.Wallet,
|
||||
@@ -98,6 +102,7 @@ describe('MixinSignatureValidator', () => {
|
||||
const defaultOrderParams = {
|
||||
...constants.STATIC_ORDER_PARAMS,
|
||||
exchangeAddress: signatureValidator.address,
|
||||
chainId,
|
||||
makerAddress,
|
||||
feeRecipientAddress: addressUtils.generatePseudoRandomAddress(),
|
||||
makerAssetData: assetDataUtils.encodeERC20AssetData(addressUtils.generatePseudoRandomAddress()),
|
||||
|
@@ -15,7 +15,7 @@ import {
|
||||
import { BlockchainLifecycle } from '@0x/dev-utils';
|
||||
import { assetDataUtils, generatePseudoRandomSalt } from '@0x/order-utils';
|
||||
import { OrderWithoutExchangeAddress, RevertReason, SignedOrder, SignedZeroExTransaction } from '@0x/types';
|
||||
import { BigNumber } from '@0x/utils';
|
||||
import { BigNumber, providerUtils } from '@0x/utils';
|
||||
import * as chai from 'chai';
|
||||
import * as _ from 'lodash';
|
||||
|
||||
@@ -26,6 +26,7 @@ const expect = chai.expect;
|
||||
const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
|
||||
|
||||
describe('Exchange transactions', () => {
|
||||
let chainId: number;
|
||||
let senderAddress: string;
|
||||
let owner: string;
|
||||
let makerAddress: string;
|
||||
@@ -66,6 +67,7 @@ describe('Exchange transactions', () => {
|
||||
await blockchainLifecycle.revertAsync();
|
||||
});
|
||||
before(async () => {
|
||||
chainId = await providerUtils.getChainIdAsync(provider);
|
||||
const accounts = await web3Wrapper.getAvailableAddressesAsync();
|
||||
const usedAddresses = ([owner, senderAddress, makerAddress, takerAddress, feeRecipientAddress] = _.slice(
|
||||
accounts,
|
||||
@@ -88,6 +90,7 @@ describe('Exchange transactions', () => {
|
||||
provider,
|
||||
txDefaults,
|
||||
assetDataUtils.encodeERC20AssetData(zrxToken.address),
|
||||
new BigNumber(chainId)
|
||||
);
|
||||
exchangeWrapper = new ExchangeWrapper(exchange, provider);
|
||||
await exchangeWrapper.registerAssetProxyAsync(erc20Proxy.address, owner);
|
||||
@@ -104,6 +107,7 @@ describe('Exchange transactions', () => {
|
||||
...constants.STATIC_ORDER_PARAMS,
|
||||
senderAddress,
|
||||
exchangeAddress: exchange.address,
|
||||
chainId,
|
||||
makerAddress,
|
||||
feeRecipientAddress,
|
||||
makerAssetData: assetDataUtils.encodeERC20AssetData(defaultMakerTokenAddress),
|
||||
@@ -112,8 +116,16 @@ describe('Exchange transactions', () => {
|
||||
makerPrivateKey = constants.TESTRPC_PRIVATE_KEYS[accounts.indexOf(makerAddress)];
|
||||
takerPrivateKey = constants.TESTRPC_PRIVATE_KEYS[accounts.indexOf(takerAddress)];
|
||||
orderFactory = new OrderFactory(makerPrivateKey, defaultOrderParams);
|
||||
makerTransactionFactory = new TransactionFactory(makerPrivateKey, exchange.address);
|
||||
takerTransactionFactory = new TransactionFactory(takerPrivateKey, exchange.address);
|
||||
makerTransactionFactory = new TransactionFactory(
|
||||
makerPrivateKey,
|
||||
exchange.address,
|
||||
chainId,
|
||||
);
|
||||
takerTransactionFactory = new TransactionFactory(
|
||||
takerPrivateKey,
|
||||
exchange.address,
|
||||
chainId,
|
||||
);
|
||||
});
|
||||
describe('executeTransaction', () => {
|
||||
describe('fillOrder', () => {
|
||||
@@ -346,6 +358,7 @@ describe('Exchange transactions', () => {
|
||||
...constants.STATIC_ORDER_PARAMS,
|
||||
senderAddress: whitelist.address,
|
||||
exchangeAddress: exchange.address,
|
||||
chainId,
|
||||
makerAddress,
|
||||
feeRecipientAddress,
|
||||
makerAssetData: assetDataUtils.encodeERC20AssetData(defaultMakerTokenAddress),
|
||||
|
@@ -63,6 +63,7 @@ export async function fillOrderCombinatorialUtilsFactoryAsync(
|
||||
|
||||
const supportedProvider = web3Wrapper.getProvider();
|
||||
const provider = providerUtils.standardizeOrThrow(supportedProvider);
|
||||
const chainId = await providerUtils.getChainIdAsync(provider);
|
||||
const erc20Wrapper = new ERC20Wrapper(provider, userAddresses, ownerAddress);
|
||||
const erc721Wrapper = new ERC721Wrapper(provider, userAddresses, ownerAddress);
|
||||
|
||||
@@ -102,6 +103,7 @@ export async function fillOrderCombinatorialUtilsFactoryAsync(
|
||||
provider,
|
||||
txDefaults,
|
||||
zrxAssetData,
|
||||
new BigNumber(chainId)
|
||||
);
|
||||
const exchangeWrapper = new ExchangeWrapper(exchangeContract, provider);
|
||||
await exchangeWrapper.registerAssetProxyAsync(erc20Proxy.address, ownerAddress);
|
||||
@@ -129,12 +131,14 @@ export async function fillOrderCombinatorialUtilsFactoryAsync(
|
||||
erc721Token,
|
||||
erc721Balances,
|
||||
exchangeContract.address,
|
||||
chainId
|
||||
);
|
||||
|
||||
const testLibsContract = await TestLibsContract.deployFrom0xArtifactAsync(
|
||||
libsArtifacts.TestLibs,
|
||||
provider,
|
||||
txDefaults,
|
||||
new BigNumber(chainId),
|
||||
);
|
||||
|
||||
const fillOrderCombinatorialUtils = new FillOrderCombinatorialUtils(
|
||||
@@ -404,7 +408,6 @@ export class FillOrderCombinatorialUtils {
|
||||
try {
|
||||
await orderValidationUtils.validateFillOrderThrowIfInvalidAsync(
|
||||
exchangeTransferSimulator,
|
||||
provider,
|
||||
signedOrder,
|
||||
takerAssetFillAmount,
|
||||
this.takerAddress,
|
||||
@@ -627,7 +630,11 @@ export class FillOrderCombinatorialUtils {
|
||||
balanceAndProxyAllowanceFetcher: SimpleAssetBalanceAndProxyAllowanceFetcher,
|
||||
orderFilledCancelledFetcher: SimpleOrderFilledCancelledFetcher,
|
||||
): Promise<BigNumber> {
|
||||
const orderStateUtils = new OrderStateUtils(balanceAndProxyAllowanceFetcher, orderFilledCancelledFetcher);
|
||||
const orderStateUtils = new OrderStateUtils(
|
||||
balanceAndProxyAllowanceFetcher,
|
||||
orderFilledCancelledFetcher,
|
||||
signedOrder.chainId,
|
||||
);
|
||||
const fillableTakerAssetAmount = await orderStateUtils.getMaxFillableTakerAssetAmountAsync(
|
||||
signedOrder,
|
||||
this.takerAddress,
|
||||
|
@@ -32,6 +32,7 @@ export class OrderFactoryFromScenario {
|
||||
private readonly _erc721Token: DummyERC721TokenContract;
|
||||
private readonly _erc721Balances: ERC721TokenIdsByOwner;
|
||||
private readonly _exchangeAddress: string;
|
||||
private readonly _chainId: number;
|
||||
constructor(
|
||||
userAddresses: string[],
|
||||
zrxAddress: string,
|
||||
@@ -41,6 +42,7 @@ export class OrderFactoryFromScenario {
|
||||
erc721Token: DummyERC721TokenContract,
|
||||
erc721Balances: ERC721TokenIdsByOwner,
|
||||
exchangeAddress: string,
|
||||
chainId: number
|
||||
) {
|
||||
this._userAddresses = userAddresses;
|
||||
this._zrxAddress = zrxAddress;
|
||||
@@ -50,6 +52,7 @@ export class OrderFactoryFromScenario {
|
||||
this._erc721Token = erc721Token;
|
||||
this._erc721Balances = erc721Balances;
|
||||
this._exchangeAddress = exchangeAddress;
|
||||
this._chainId = chainId;
|
||||
}
|
||||
public generateOrder(orderScenario: OrderScenario): Order {
|
||||
const makerAddress = this._userAddresses[1];
|
||||
@@ -285,6 +288,7 @@ export class OrderFactoryFromScenario {
|
||||
takerAssetData,
|
||||
salt: generatePseudoRandomSalt(),
|
||||
exchangeAddress: this._exchangeAddress,
|
||||
chainId: this._chainId,
|
||||
feeRecipientAddress,
|
||||
expirationTimeSeconds,
|
||||
};
|
||||
|
@@ -17,7 +17,7 @@ import {
|
||||
import { BlockchainLifecycle } from '@0x/dev-utils';
|
||||
import { assetDataUtils, orderHashUtils } 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';
|
||||
@@ -29,6 +29,7 @@ const expect = chai.expect;
|
||||
const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
|
||||
|
||||
describe('Exchange wrappers', () => {
|
||||
let chainId: number;
|
||||
let makerAddress: string;
|
||||
let owner: string;
|
||||
let takerAddress: string;
|
||||
@@ -62,6 +63,7 @@ describe('Exchange wrappers', () => {
|
||||
await blockchainLifecycle.revertAsync();
|
||||
});
|
||||
before(async () => {
|
||||
chainId = await providerUtils.getChainIdAsync(provider);
|
||||
const accounts = await web3Wrapper.getAvailableAddressesAsync();
|
||||
const usedAddresses = ([owner, makerAddress, takerAddress, feeRecipientAddress] = _.slice(accounts, 0, 4));
|
||||
|
||||
@@ -88,6 +90,7 @@ describe('Exchange wrappers', () => {
|
||||
provider,
|
||||
txDefaults,
|
||||
assetDataUtils.encodeERC20AssetData(zrxToken.address),
|
||||
new BigNumber(chainId)
|
||||
);
|
||||
exchangeWrapper = new ExchangeWrapper(exchange, provider);
|
||||
await exchangeWrapper.registerAssetProxyAsync(erc20Proxy.address, owner);
|
||||
@@ -119,6 +122,7 @@ describe('Exchange wrappers', () => {
|
||||
const defaultOrderParams = {
|
||||
...constants.STATIC_ORDER_PARAMS,
|
||||
exchangeAddress: exchange.address,
|
||||
chainId,
|
||||
makerAddress,
|
||||
feeRecipientAddress,
|
||||
makerAssetData: assetDataUtils.encodeERC20AssetData(defaultMakerAssetAddress),
|
||||
|
Reference in New Issue
Block a user