Add more contract configs tests

This commit is contained in:
Amir Bandeali 2019-10-01 22:18:09 -07:00
parent ffcd297e5b
commit 650efb95e2
3 changed files with 207 additions and 109 deletions

View File

@ -97,7 +97,7 @@ const networkToAddresses: { [networkId: number]: ContractAddresses } = {
devUtils: '0x2d4a9abda7b8b3605c8dbd34e3550a7467c78287',
zrxVault: '0xa5bf6ac73bc40790fc6ffc9dbbbce76c9176e224',
readOnlyProxy: '0xffd161026865ad8b4ab28a76840474935eec4dfa',
staking: '0x725bc2f8c85ed0289d3da79cde3125d33fc1d7e6',
staking: '0x8ec5a989a06432dace637c8d592727627a45a592',
stakingProxy: '0xb2ca5824630e526f0f3181a4ea0447c795a84411',
},
42: {
@ -119,7 +119,7 @@ const networkToAddresses: { [networkId: number]: ContractAddresses } = {
devUtils: '0xb1863ac46ae23ec55d6eeb8ecc8815655ee638a8',
zrxVault: '0xf36eabdfe986b35b62c8fd5a98a7f2aebb79b291',
readOnlyProxy: '0x25397d8aa7e6844dae70ee658fe072d45d6cf528',
staking: '0xa9290221e4632394e0209abe893a90f5445e1f23',
staking: '0xd67f2f346f6e85db70632d9f18f50e04192ab54d',
stakingProxy: '0x9e7eef766702c3d9056a3de779e5d9d976bc3bdb',
},
// NetworkId 50 represents our Ganache snapshot generated from migrations.

View File

@ -1,6 +1,8 @@
#!/usr/bin/env node
import * as wrappers from '@0x/abi-gen-wrappers';
import { getContractAddressesForNetworkOrThrow } from '@0x/contract-addresses';
import { ExchangeContract } from '@0x/contracts-exchange';
import { StakingContract, StakingProxyContract, ZrxVaultContract } from '@0x/contracts-staking';
import { EmptyWalletSubprovider, RPCSubprovider, Web3ProviderEngine } from '@0x/subproviders';
import { AssetProxyId } from '@0x/types';
import { logUtils, providerUtils } from '@0x/utils';
@ -8,11 +10,13 @@ import { Web3Wrapper } from '@0x/web3-wrapper';
import { SupportedProvider } from 'ethereum-types';
// NOTE: add your own Infura Project ID to RPC urls before running
const INFURA_PROJECT_ID = '';
const networkIdToRpcUrl = {
1: 'https://mainnet.infura.io/v3/',
3: 'https://ropsten.infura.io/v3/',
4: 'https://rinkeby.infura.io/v3/',
42: 'https://kovan.infura.io/v3/',
1: `https://mainnet.infura.io/v3/${INFURA_PROJECT_ID}`,
3: `https://ropsten.infura.io/v3/${INFURA_PROJECT_ID}`,
4: `https://rinkeby.infura.io/v3/${INFURA_PROJECT_ID}`,
42: `https://kovan.infura.io/v3/${INFURA_PROJECT_ID}`,
};
async function testContractConfigsAsync(provider: SupportedProvider): Promise<void> {
@ -26,14 +30,50 @@ async function testContractConfigsAsync(provider: SupportedProvider): Promise<vo
}
}
const exchange = new wrappers.ExchangeContract(addresses.exchange, provider);
const exchange = new ExchangeContract(addresses.exchange, provider);
const exchangeV2 = new ExchangeContract(addresses.exchangeV2, provider);
const erc20Proxy = new wrappers.ERC20ProxyContract(addresses.erc20Proxy, provider);
const erc721Proxy = new wrappers.ERC721ProxyContract(addresses.erc721Proxy, provider);
const erc1155Proxy = new wrappers.ERC1155ProxyContract(addresses.erc1155Proxy, provider);
const multiAssetProxy = new wrappers.MultiAssetProxyContract(addresses.multiAssetProxy, provider);
const assetProxyOwner = new wrappers.AssetProxyOwnerContract(addresses.assetProxyOwner, provider);
const stakingProxy = new StakingProxyContract(addresses.stakingProxy, provider);
const stakingContract = new StakingContract(addresses.staking, provider);
const zrxVault = new ZrxVaultContract(addresses.zrxVault, provider);
// Verify Exchange configs
async function verifyExchangeV2ConfigsAsync(): Promise<void> {
const exchangeOwner = await exchangeV2.owner.callAsync();
warnIfMismatch(exchangeOwner, assetProxyOwner.address, 'Unexpected ExchangeV2 owner');
const registeredERC20Proxy = await exchangeV2.getAssetProxy.callAsync(AssetProxyId.ERC20);
warnIfMismatch(registeredERC20Proxy, erc20Proxy.address, 'Unexpected ERC20Proxy registered in ExchangeV2');
const registeredERC721Proxy = await exchangeV2.getAssetProxy.callAsync(AssetProxyId.ERC721);
warnIfMismatch(registeredERC721Proxy, erc721Proxy.address, 'Unexpected ERC721Proxy registered in ExchangeV2');
const registeredERC1155Proxy = await exchangeV2.getAssetProxy.callAsync(AssetProxyId.ERC1155);
warnIfMismatch(
registeredERC1155Proxy,
erc1155Proxy.address,
'Unexpected ERC1155Proxy registered in ExchangeV2',
);
const registeredMultiAssetProxy = await exchangeV2.getAssetProxy.callAsync(AssetProxyId.MultiAsset);
warnIfMismatch(
registeredMultiAssetProxy,
multiAssetProxy.address,
'Unexpected MultiAssetProxy registered in ExchangeV2',
);
const registeredStaticCallProxy = await exchangeV2.getAssetProxy.callAsync(AssetProxyId.StaticCall);
warnIfMismatch(
registeredStaticCallProxy,
addresses.staticCallProxy,
'Unexpected StaticCallProxy registered in ExchangeV2',
);
}
async function verifyExchangeV3ConfigsAsync(): Promise<void> {
const exchangeOwner = await exchange.owner.callAsync();
warnIfMismatch(exchangeOwner, assetProxyOwner.address, 'Unexpected Exchange owner');
@ -60,12 +100,23 @@ async function testContractConfigsAsync(provider: SupportedProvider): Promise<vo
'Unexpected StaticCallProxy registered in Exchange',
);
const protocolFeeCollector = await exchange.protocolFeeCollector.callAsync();
warnIfMismatch(protocolFeeCollector, addresses.stakingProxy, 'Unexpected StakingProxy attached to Exchange');
const protocolFeeMultiplier = await exchange.protocolFeeMultiplier.callAsync();
warnIfMismatch(protocolFeeMultiplier.toString(), '150000', 'Unexpected protocolFeeMultiplier in Exchange');
}
async function verifyAssetProxyConfigsAsync(): Promise<void> {
// Verify ERC20Proxy configs
const erc20ProxyOwner = await erc20Proxy.owner.callAsync();
warnIfMismatch(erc20ProxyOwner, assetProxyOwner.address, 'Unexpected ERC20Proxy owner');
const erc20AuthorizedAddresses = await erc20Proxy.getAuthorizedAddresses.callAsync();
warnIfMismatch(erc20AuthorizedAddresses.length, 2, 'Unexpected number of authorized addresses in ERC20Proxy');
warnIfMismatch(erc20AuthorizedAddresses.length, 4, 'Unexpected number of authorized addresses in ERC20Proxy');
const isExchangeV2AuthorizedInERC20Proxy = await erc20Proxy.authorized.callAsync(exchangeV2.address);
warnIfMismatch(isExchangeV2AuthorizedInERC20Proxy, true, 'ExchangeV2 not authorized in ERC20Proxy');
const isExchangeAuthorizedInERC20Proxy = await erc20Proxy.authorized.callAsync(exchange.address);
warnIfMismatch(isExchangeAuthorizedInERC20Proxy, true, 'Exchange not authorized in ERC20Proxy');
@ -73,12 +124,18 @@ async function testContractConfigsAsync(provider: SupportedProvider): Promise<vo
const isMAPAuthorizedInER20Proxy = await erc20Proxy.authorized.callAsync(multiAssetProxy.address);
warnIfMismatch(isMAPAuthorizedInER20Proxy, true, 'MultiAssetProxy not authorized in ERC20Proxy');
const isZrxVaultAuthorizedInER20Proxy = await erc20Proxy.authorized.callAsync(zrxVault.address);
warnIfMismatch(isZrxVaultAuthorizedInER20Proxy, true, 'ZrxVault not authorized in ERC20Proxy');
// Verify ERC721Proxy configs
const erc721ProxyOwner = await erc721Proxy.owner.callAsync();
warnIfMismatch(erc721ProxyOwner, assetProxyOwner.address, 'Unexpected ERC721Proxy owner');
const erc721AuthorizedAddresses = await erc721Proxy.getAuthorizedAddresses.callAsync();
warnIfMismatch(erc721AuthorizedAddresses.length, 2, 'Unexpected number of authorized addresses in ERC721Proxy');
warnIfMismatch(erc721AuthorizedAddresses.length, 3, 'Unexpected number of authorized addresses in ERC721Proxy');
const isExchangeV2AuthorizedInERC721Proxy = await erc721Proxy.authorized.callAsync(exchangeV2.address);
warnIfMismatch(isExchangeV2AuthorizedInERC721Proxy, true, 'ExchangeV2 not authorized in ERC721Proxy');
const isExchangeAuthorizedInERC721Proxy = await erc721Proxy.authorized.callAsync(exchange.address);
warnIfMismatch(isExchangeAuthorizedInERC721Proxy, true, 'Exchange not authorized in ERC721Proxy');
@ -91,7 +148,14 @@ async function testContractConfigsAsync(provider: SupportedProvider): Promise<vo
warnIfMismatch(erc1155ProxyOwner, assetProxyOwner.address, 'Unexpected ERC1155Proxy owner');
const erc1155AuthorizedAddresses = await erc1155Proxy.getAuthorizedAddresses.callAsync();
warnIfMismatch(erc1155AuthorizedAddresses.length, 2, 'Unexpected number of authorized addresses in ERC1155Proxy');
warnIfMismatch(
erc1155AuthorizedAddresses.length,
3,
'Unexpected number of authorized addresses in ERC1155Proxy',
);
const isExchangeV2AuthorizedInERC1155Proxy = await erc1155Proxy.authorized.callAsync(exchangeV2.address);
warnIfMismatch(isExchangeV2AuthorizedInERC1155Proxy, true, 'ExchangeV2 not authorized in ERC1155Proxy');
const isExchangeAuthorizedInERC1155Proxy = await erc1155Proxy.authorized.callAsync(exchange.address);
warnIfMismatch(isExchangeAuthorizedInERC1155Proxy, true, 'Exchange not authorized in ERC1155Proxy');
@ -106,60 +170,94 @@ async function testContractConfigsAsync(provider: SupportedProvider): Promise<vo
const multiAssetProxyAuthorizedAddresses = await multiAssetProxy.getAuthorizedAddresses.callAsync();
warnIfMismatch(
multiAssetProxyAuthorizedAddresses.length,
1,
2,
'Unexpected number of authorized addresses in MultiAssetProxy',
);
const isExchangeV2AuthorizedInMultiAssetProxy = await multiAssetProxy.authorized.callAsync(exchangeV2.address);
warnIfMismatch(isExchangeV2AuthorizedInMultiAssetProxy, true, 'ExchangeV2 not authorized in MultiAssetProxy');
const isExchangeAuthorizedInMultiAssetProxy = await multiAssetProxy.authorized.callAsync(exchange.address);
warnIfMismatch(isExchangeAuthorizedInMultiAssetProxy, true, 'Exchange not authorized in MultiAssetProxy');
const registeredERC20ProxyInMAP = await exchange.getAssetProxy.callAsync(AssetProxyId.ERC20);
const registeredERC20ProxyInMAP = await multiAssetProxy.getAssetProxy.callAsync(AssetProxyId.ERC20);
warnIfMismatch(
registeredERC20ProxyInMAP,
erc20Proxy.address,
'Unexpected ERC20Proxy registered in MultiAssetProxy',
);
const registeredERC721ProxyInMAP = await exchange.getAssetProxy.callAsync(AssetProxyId.ERC721);
const registeredERC721ProxyInMAP = await multiAssetProxy.getAssetProxy.callAsync(AssetProxyId.ERC721);
warnIfMismatch(
registeredERC721ProxyInMAP,
erc721Proxy.address,
'Unexpected ERC721Proxy registered in MultiAssetProxy',
);
const registeredERC1155ProxyInMAP = await exchange.getAssetProxy.callAsync(AssetProxyId.ERC1155);
const registeredERC1155ProxyInMAP = await multiAssetProxy.getAssetProxy.callAsync(AssetProxyId.ERC1155);
warnIfMismatch(
registeredERC1155ProxyInMAP,
erc1155Proxy.address,
'Unexpected ERC1155Proxy registered in MultiAssetProxy',
);
const registeredStaticCallProxyInMAP = await exchange.getAssetProxy.callAsync(AssetProxyId.StaticCall);
const registeredStaticCallProxyInMAP = await multiAssetProxy.getAssetProxy.callAsync(AssetProxyId.StaticCall);
warnIfMismatch(
registeredStaticCallProxyInMAP,
addresses.staticCallProxy,
'Unexpected StaticCallProxy registered in MultiAssetProxy',
);
}
// Verify AssetProxyOwner configs
// TODO (xianny): re-enable when AssetProxyOwner contract is finalised
// const isERC20ProxyRegisteredInAPOwner = await assetProxyOwner.getAssetProxy.callAsync(erc20Proxy.address);
// warnIfMismatch(isERC20ProxyRegisteredInAPOwner, true, 'ERC20Proxy not registered in AssetProxyOwner');
async function verifyStakingConfigsAsync(): Promise<void> {
const stakingLogicAddress = await stakingProxy.stakingContract.callAsync();
warnIfMismatch(stakingLogicAddress, addresses.staking, 'Unexpected Staking contract attached to StakingProxy');
// const isERC721ProxyRegisteredInAPOwner = await assetProxyOwner.getAssetProxy.callAsync(
// erc721Proxy.address,
// );
// warnIfMismatch(isERC721ProxyRegisteredInAPOwner, true, 'ERC721Proxy not registered in AssetProxyOwner');
const readOnlyProxy = await stakingProxy.readOnlyProxy.callAsync();
warnIfMismatch(readOnlyProxy, addresses.readOnlyProxy, 'Unexpected ReadOnlyProxy set in StakingProxy');
// const isERC1155ProxyRegisteredInAPOwner = await assetProxyOwner.getAssetProxy.callAsync(
// erc1155Proxy.address,
// );
// warnIfMismatch(isERC1155ProxyRegisteredInAPOwner, true, 'ERC1155Proxy not registered in AssetProxyOwner');
const readOnlyCallee = await stakingProxy.readOnlyProxyCallee.callAsync();
warnIfMismatch(readOnlyCallee, addresses.staking, 'Unexpected readOnlyProxyCallee');
// const isMultiAssetProxyRegisteredInAPOwner = await assetProxyOwner.getAssetProxy.callAsync(
// multiAssetProxy.address,
// );
// warnIfMismatch(isMultiAssetProxyRegisteredInAPOwner, true, 'MultiAssetProxy not registered in AssetProxyOwner');
const zrxVaultAddress = await stakingContract.getZrxVault.callAsync();
warnIfMismatch(zrxVaultAddress, addresses.zrxVault, 'Unexpected ZrxVault set in Staking contract');
const wethAddress = await stakingContract.getWethContract.callAsync();
warnIfMismatch(wethAddress, addresses.etherToken, 'Unexpected WETH contract set in Staking contract');
const stakingProxyOwner = await stakingProxy.owner.callAsync();
warnIfMismatch(stakingProxyOwner, addresses.assetProxyOwner, 'Unexpected StakingProxy owner');
const zrxVaultOwner = await zrxVault.owner.callAsync();
warnIfMismatch(zrxVaultOwner, addresses.assetProxyOwner, 'Unexpected ZrxVault owner');
const stakingProxyAuthorizedAddresses = await stakingProxy.getAuthorizedAddresses.callAsync();
warnIfMismatch(
stakingProxyAuthorizedAddresses.length,
1,
'Unexpected number of authorized addresses in StakingProxy',
);
const isAssetProxyOwnerAuthorizedInStakingProxy = await stakingProxy.authorized.callAsync(
addresses.assetProxyOwner,
);
warnIfMismatch(
isAssetProxyOwnerAuthorizedInStakingProxy,
true,
'AssetProxyOwner not authorized in StakingProxy',
);
const zrxVaultAuthorizedAddresses = await zrxVault.getAuthorizedAddresses.callAsync();
warnIfMismatch(zrxVaultAuthorizedAddresses.length, 1, 'Unexpected number of authorized addresses in ZrxVault');
const isAssetProxyOwnerAuthorizedInZrxVault = await zrxVault.authorized.callAsync(addresses.assetProxyOwner);
warnIfMismatch(isAssetProxyOwnerAuthorizedInZrxVault, true, 'AssetProxyOwner not authorized in ZrxVault');
}
async function verifyAssetProxyOwnerConfigsAsync(): Promise<void> {}
await verifyExchangeV2ConfigsAsync();
await verifyExchangeV3ConfigsAsync();
await verifyAssetProxyConfigsAsync();
await verifyStakingConfigsAsync();
}
(async () => {

View File

@ -249,10 +249,10 @@ export async function runMigrationsAsync(supportedProvider: SupportedProvider, t
}
(async () => {
const networkId = 3;
const rpcUrl = 'https://ropsten.infura.io/v3/';
const networkId = 4;
const rpcUrl = 'https://rinkeby.infura.io/v3/';
const provider = await providerFactory.getLedgerProviderAsync(networkId, rpcUrl);
await runMigrationsAsync(provider, { from: constants.ASSET_PROXY_OWNER_OWNERS[0], gasPrice: 40000000000 });
await runMigrationsAsync(provider, { from: constants.ASSET_PROXY_OWNER_OWNERS[0], gasPrice: 60000000000 });
})().catch(err => {
logUtils.log(err);
process.exit(1);