Massage the migrations to match contract-addresses

This commit is contained in:
Jacob Evans 2019-11-22 09:54:59 +11:00
parent 379a31ece6
commit 2705bcce15
No known key found for this signature in database
GPG Key ID: 2036DA2ADDFB0842
5 changed files with 51 additions and 22 deletions

View File

@ -5,18 +5,21 @@
"node": ">=6.12"
},
"description": "0x smart contract migrations",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"main": "lib/src/index.js",
"types": "lib/src/index.d.ts",
"scripts": {
"build": "tsc -b",
"build:ci": "yarn build",
"clean": "shx rm -rf lib ${npm_package_config_snapshot_name} ${npm_package_config_snapshot_name}-*.zip",
"lint": "tslint --format stylish --project .",
"fix": "tslint --fix --format stylish --project .",
"test": "yarn run_mocha",
"test:circleci": "yarn test",
"run_mocha": "mocha --require source-map-support/register --require make-promises-safe lib/test/**/*_test.js --bail --timeout 30000 --exit",
"migrate:v2": "run-s build script:migrate:v2",
"migrate:v2:snapshot": "run-s build script:migrate:v2:snapshot",
"script:migrate:v2": "node ./lib/migrate.js",
"script:migrate:v2:snapshot": "node ./lib/migrate_snapshot.js",
"script:migrate:v2": "node ./lib/src/migrate.js",
"script:migrate:v2:snapshot": "node ./lib/src/migrate_snapshot.js",
"diff_docs": "git diff --exit-code ./docs",
"s3:sync_md_docs": "aws s3 sync ./docs s3://docs-markdown/${npm_package_name}/v${npm_package_version} --profile 0xproject --region us-east-1 --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers",
"docs:md": "ts-doc-gen --sourceDir='$PROJECT_FILES' --output=$MD_FILE_DIR --fileExtension=mdx --tsconfig=./typedoc-tsconfig.json",
@ -48,6 +51,9 @@
"make-promises-safe": "^1.1.0",
"npm-run-all": "^4.1.2",
"shx": "^0.2.2",
"dirty-chai": "^2.0.1",
"mocha": "^6.2.0",
"chai": "^4.0.1",
"tslint": "5.11.0",
"typedoc": "^0.15.0",
"typescript": "3.0.1",

View File

@ -12,7 +12,7 @@ import { runMigrationsAsync } from './migration';
let providerConfigs;
let provider: Web3ProviderEngine;
let txDefaults;
const packageJsonPath = path.join(__dirname, '..', 'package.json');
const packageJsonPath = path.join(__dirname, '../..', 'package.json');
const packageJsonString = fs.readFileSync(packageJsonPath, 'utf8');
const packageJson = JSON.parse(packageJsonString);
if (packageJson.config === undefined || packageJson.config.snapshot_name === undefined) {

View File

@ -176,10 +176,19 @@ export async function runMigrationsAsync(
await exchange.registerAssetProxy(multiAssetProxy.address).awaitTransactionSuccessAsync(txDefaults);
await exchange.registerAssetProxy(staticCallProxy.address).awaitTransactionSuccessAsync(txDefaults);
// Forwarder
const forwarder = await ForwarderContract.deployFrom0xArtifactAsync(
artifacts.Forwarder,
provider,
txDefaults,
artifacts,
exchange.address,
encodeERC20AssetData(etherToken.address),
);
// Fake the above transactions so our nonce increases and we result with the same addresses
// while AssetProxyOwner is disabled (TODO: @dekz remove)
const dummyTransactionCount = 8;
for (let index = 0; index < dummyTransactionCount; index++) {
const dummyTransactionCount = 7;
for (let index = 0; index <= dummyTransactionCount; index++) {
await web3Wrapper.sendTransactionAsync({ to: txDefaults.from, from: txDefaults.from, value: new BigNumber(0) });
}
@ -238,7 +247,6 @@ export async function runMigrationsAsync(
zrxProxy,
zrxToken.address,
);
await erc20Proxy.addAuthorizedAddress(zrxVault.address).awaitTransactionSuccessAsync(txDefaults);
// Note we use TestStakingContract as the deployed bytecode of a StakingContract
// has the tokens hardcoded
@ -259,6 +267,8 @@ export async function runMigrationsAsync(
stakingLogic.address,
);
await erc20Proxy.addAuthorizedAddress(zrxVault.address).awaitTransactionSuccessAsync(txDefaults);
// Reference the Proxy as the StakingContract for setup
const stakingDel = await new TestStakingContract(stakingProxy.address, provider, txDefaults);
await stakingProxy.addAuthorizedAddress(txDefaults.from).awaitTransactionSuccessAsync(txDefaults);
@ -271,16 +281,6 @@ export async function runMigrationsAsync(
await stakingLogic.addAuthorizedAddress(txDefaults.from).awaitTransactionSuccessAsync(txDefaults);
await stakingLogic.addExchangeAddress(exchange.address).awaitTransactionSuccessAsync(txDefaults);
// Forwarder
const forwarder = await ForwarderContract.deployFrom0xArtifactAsync(
artifacts.Forwarder,
provider,
txDefaults,
artifacts,
exchange.address,
encodeERC20AssetData(etherToken.address),
);
const contractAddresses = {
erc20Proxy: erc20Proxy.address,
erc721Proxy: erc721Proxy.address,
@ -299,14 +299,13 @@ export async function runMigrationsAsync(
multiAssetProxy: multiAssetProxy.address,
staticCallProxy: staticCallProxy.address,
devUtils: devUtils.address,
exchangeV2: constants.NULL_ADDRESS,
exchangeV2: exchange.address,
zrxVault: zrxVault.address,
staking: stakingLogic.address,
stakingProxy: stakingProxy.address,
uniswapBridge: constants.NULL_ADDRESS,
eth2DaiBridge: constants.NULL_ADDRESS,
};
return contractAddresses;
}

View File

@ -0,0 +1,24 @@
import { ChainId, getContractAddressesForChainOrThrow } from '@0x/contract-addresses';
import { devConstants, web3Factory } from '@0x/dev-utils';
import * as chai from 'chai';
import * as dirtyChai from 'dirty-chai';
import 'mocha';
import { runMigrationsAsync } from '../src/migration';
chai.use(dirtyChai);
const expect = chai.expect;
describe('addresses', () => {
it('should contain the same addresses as contract-addresses', async () => {
const providerConfigs = { shouldUseInProcessGanache: true };
const provider = web3Factory.getRpcProvider(providerConfigs);
const txDefaults = {
from: devConstants.TESTRPC_FIRST_ADDRESS,
};
const migrationAddresses = await runMigrationsAsync(provider, txDefaults);
const expectedAddresses = getContractAddressesForChainOrThrow(ChainId.Ganache);
expect(migrationAddresses).to.include(expectedAddresses);
});
});

View File

@ -2,7 +2,7 @@
"extends": "../../tsconfig",
"compilerOptions": {
"outDir": "lib",
"rootDir": "src"
"rootDir": "."
},
"include": ["src/**/*"]
"include": ["src/**/*", "test/**/*"]
}