Skip to content

Optimism Forking with Hardhat #1656

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 25 commits into from
Jan 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
3f78a06
add support
dbeal-eth Jan 11, 2022
05769a1
fork tests are mostly working, but some tests fail for misc reasons
dbeal-eth Jan 14, 2022
63d2d06
test on ci
dbeal-eth Jan 20, 2022
390ceee
progress
dbeal-eth Jan 20, 2022
569e345
Merge remote-tracking branch 'origin/develop' into hardhat-fork-optimism
dbeal-eth Jan 20, 2022
a1566b2
more fixes
dbeal-eth Jan 21, 2022
b1c363c
fixes for ci
dbeal-eth Jan 21, 2022
6fb9e1e
fork tests ovm was msising from the mix
dbeal-eth Jan 21, 2022
ac6775f
fix infura key and ports
dbeal-eth Jan 21, 2022
e5b1bb1
reset deployment files
dbeal-eth Jan 21, 2022
e3909f0
Merge branch 'develop' into hardhat-fork-optimism
jjgonecrypto Jan 21, 2022
0ddab60
have to fix the build path
dbeal-eth Jan 21, 2022
8f42493
Merge branch 'hardhat-fork-optimism' of https://github.com/Synthetixi…
dbeal-eth Jan 21, 2022
ac40e49
add fixes
dbeal-eth Jan 21, 2022
a21fe89
fix WrapperFactory fail
dbeal-eth Jan 21, 2022
672bbbb
grr
dbeal-eth Jan 21, 2022
a306e66
fix build path for dual tests
dbeal-eth Jan 21, 2022
d591388
Merge branch 'develop' into hardhat-fork-optimism
jjgonecrypto Jan 21, 2022
60ceac1
fix deployer once again
dbeal-eth Jan 21, 2022
08b1355
Merge branch 'hardhat-fork-optimism' of https://github.com/Synthetixi…
dbeal-eth Jan 21, 2022
67c1c3c
fix final comments, change to use fork checks for skip
dbeal-eth Jan 24, 2022
205594e
fix fork things again
dbeal-eth Jan 24, 2022
950d018
going in circles
dbeal-eth Jan 24, 2022
a5d9530
apparently can't use arrow func
dbeal-eth Jan 24, 2022
7702c03
Merge branch 'develop' into hardhat-fork-optimism
jjgonecrypto Jan 25, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 31 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,31 @@ jobs:
- attach_workspace:
at: .
- run: npx hardhat compile --optimizer --fail-oversize
job-fork-tests-ovm:
working_directory: ~/repo
docker:
- image: synthetixio/docker-node:16.13-ubuntu
auth:
username: $DOCKERHUB_USERNAME
password: $DOCKERHUB_TOKEN
steps:
- checkout
- attach_workspace:
at: .
- run:
command: npm run fork:ovm
background: true
- cmd-wait-for-port:
port: 8545
- run:
name: Run integration tests on l2
command: |
NEW_CONTRACTS=$(node bin.js sips --layer=base --unreleased --with-sources)
if [ -z "$NEW_CONTRACTS" ]; then
npx hardhat test:integration:l2 --use-fork
else
npx hardhat test:integration:l2 --compile --deploy --use-sips --use-fork
fi;
job-fork-tests:
working_directory: ~/repo
docker:
Expand All @@ -57,15 +82,15 @@ jobs:
command: npm run fork:mainnet
background: true
- cmd-wait-for-port:
port: 8545
port: 9545
- run:
name: Run integration tests on l1
command: |
NEW_CONTRACTS=$(node bin.js sips --layer=base --unreleased --with-sources)
if [ -z "$NEW_CONTRACTS" ]; then
npx hardhat test:integration:l1 --use-fork
npx hardhat test:integration:l1 --use-fork --provider-port 9545
else
npx hardhat test:integration:l1 --compile --deploy --use-sips --use-fork
npx hardhat test:integration:l1 --compile --deploy --use-sips --use-fork --provider-port 9545
fi;
job-integration-tests:
working_directory: ~/repo
Expand Down Expand Up @@ -406,6 +431,9 @@ workflows:
- job-fork-tests:
requires:
- job-prepare
- job-fork-tests-ovm:
requires:
- job-prepare
- job-simulate-release:
requires:
- job-prepare
Expand Down
21 changes: 21 additions & 0 deletions .circleci/src/jobs/job-fork-tests-ovm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Starts a fork of OVM, deploys the latest release, and runs L2 integration tests
{{> job-header-node.yml}}
steps:
- checkout
- attach_workspace:
at: .
- run:
command: npm run fork:ovm
background: true
- cmd-wait-for-port:
port: 8545
- run:
name: Run integration tests on l2
command: |
# Only compile and deploy when there are new contracts
NEW_CONTRACTS=$(node bin.js sips --layer=base --unreleased --with-sources)
if [ -z "$NEW_CONTRACTS" ]; then
npx hardhat test:integration:l2 --use-fork
else
npx hardhat test:integration:l2 --compile --deploy --use-sips --use-fork
fi;
6 changes: 3 additions & 3 deletions .circleci/src/jobs/job-fork-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ steps:
command: npm run fork:mainnet
background: true
- cmd-wait-for-port:
port: 8545
port: 9545
- run:
name: Run integration tests on l1
command: |
# Only compile and deploy when there are new contracts
NEW_CONTRACTS=$(node bin.js sips --layer=base --unreleased --with-sources)
if [ -z "$NEW_CONTRACTS" ]; then
npx hardhat test:integration:l1 --use-fork
npx hardhat test:integration:l1 --use-fork --provider-port 9545
else
npx hardhat test:integration:l1 --compile --deploy --use-sips --use-fork
npx hardhat test:integration:l1 --compile --deploy --use-sips --use-fork --provider-port 9545
fi;
2 changes: 2 additions & 0 deletions .circleci/src/workflows/workflow-all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ jobs:
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- job-fork-tests:
{{> require-prepare.yml}}
- job-fork-tests-ovm:
{{> require-prepare.yml}}

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Simulate release on fork & test
Expand Down
6 changes: 6 additions & 0 deletions hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ module.exports = {
url: process.env.OVM_PROVIDER_URL || 'https://kovan.optimism.io/',
chainId: 69,
},
local: {
url: process.env.PROVIDER_URL || 'http://localhost:8545/',
},
'local-ovm': {
url: process.env.OVM_PROVIDER_URL || 'http://localhost:9545/',
},
},
gasReporter: {
enabled: false,
Expand Down
24 changes: 19 additions & 5 deletions hardhat/tasks/task-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const { TASK_NODE_SERVER_READY } = require('hardhat/builtin-tasks/task-names');

task('node', 'Run a node')
.addOptionalParam('targetNetwork', 'Target network to simulate, i.e. mainnet or local', 'local')
.addFlag('useOvm', 'Use OVM', false)
.setAction(async (taskArguments, hre, runSuper) => {
// Enable forking if necessary
if (taskArguments.fork) {
Expand All @@ -17,12 +18,18 @@ task('node', 'Run a node')
);
}
const network = taskArguments.targetNetwork;
const useOvm = taskArguments.useOvm;
if (network !== 'local') {
const networkHostReplace = (taskArguments.useOvm ? 'optimism-' : '') + network;

if (network === 'mainnet') {
taskArguments.fork = process.env.PROVIDER_URL_MAINNET;
taskArguments.fork = process.env.PROVIDER_URL_MAINNET.replace(
'network',
networkHostReplace
);
}
taskArguments.fork =
taskArguments.fork || process.env.PROVIDER_URL.replace('network', network);
taskArguments.fork || process.env.PROVIDER_URL.replace('network', networkHostReplace);

console.log(yellow(`Forking ${network}...`));
}
Expand All @@ -37,13 +44,20 @@ task('node', 'Run a node')
// Unlock any specified accounts, plus those
// known as protocol users of the target network.
const { getUsers } = wrap({ network, fs, path });
const accounts = getUsers({ network })
const accounts = getUsers({ network, useOvm })
.filter(account => account.name !== 'fee')
.filter(account => account.name !== 'zero')
.concat(knownAccounts[network] || []);
await Promise.all(
accounts.map(account => {
console.log(gray(` > Unlocking ${account.name}: ${account.address}`));
accounts.map(async account => {
console.log(gray(` > Unlocking & Funding ${account.name}: ${account.address}`));

// owner might not have eth when we impersonate them

await provider.request({
method: 'hardhat_setBalance',
params: [account.address, '0x10000000000000000000000'],
});

return provider.request({
method: 'hardhat_impersonateAccount',
Expand Down
63 changes: 45 additions & 18 deletions hardhat/tasks/task-test-integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ task('test:integration:l2', 'run isolated layer 2 production tests')
.addFlag('debugOptimism', 'Debug Optimism activity')
.addFlag('compile', 'Compile an l2 instance before running the tests')
.addFlag('deploy', 'Deploy an l2 instance before running the tests')
.addFlag('useSips', 'Use sources from SIPs directly, instead of releases')
.addFlag('useFork', 'Run the tests against a fork of mainnet')
.addOptionalParam(
'providerPort',
'The target port for the running local chain to test on',
'8545'
)
.setAction(async (taskArguments, hre) => {
hre.config.paths.tests = './test/integration/l2/';
hre.config.debugOptimism = taskArguments.debugOptimism;
Expand All @@ -89,25 +96,47 @@ task('test:integration:l2', 'run isolated layer 2 production tests')

const providerUrl = (hre.config.providerUrl = 'http://localhost');
hre.config.providerPortL1 = '9545';
const providerPortL2 = (hre.config.providerPortL2 = '8545');
const providerPortL2 = (hre.config.providerPortL2 = taskArguments.providerPort);
const useOvm = true;
const buildPath = path.join(__dirname, '..', '..', `${BUILD_FOLDER}-ovm`);
const buildPath = path.join(__dirname, '..', '..', BUILD_FOLDER);

if (taskArguments.compile) {
await compileInstance({ useOvm, buildPath });
}
if (taskArguments.useFork) {
hre.config.fork = true;
}

if (taskArguments.deploy) {
const network = 'local';
await prepareDeploy({ network, synthsToAdd, useOvm });
await deployInstance({
addNewSynths: true,
buildPath,
network,
providerPort: providerPortL2,
providerUrl,
useOvm,
});
if (taskArguments.useFork) {
await prepareDeploy({
network: 'mainnet',
synthsToAdd,
useOvm,
useSips: taskArguments.useSips,
});
await deployInstance({
addNewSynths: true,
buildPath,
freshDeploy: false,
network: 'mainnet',
providerPort: providerPortL2,
providerUrl,
useFork: true,
useOvm,
});
} else {
const network = 'local';
await prepareDeploy({ network, synthsToAdd, useOvm, useReleases: false, useSips: false });
await deployInstance({
addNewSynths: true,
buildPath,
network,
providerPort: providerPortL2,
providerUrl,
useOvm,
});
}
hre.config.addedSynths = synthsToAdd;
}

Expand All @@ -127,27 +156,25 @@ task('test:integration:dual', 'run integrated layer 1 and layer 2 production tes
const providerUrl = (hre.config.providerUrl = 'http://localhost');
const providerPortL1 = (hre.config.providerPortL1 = '9545');
const providerPortL2 = (hre.config.providerPortL2 = '8545');
const buildPathEvm = path.join(__dirname, '..', '..', BUILD_FOLDER);
const buildPathOvm = path.join(__dirname, '..', '..', `${BUILD_FOLDER}-ovm`);
const buildPath = path.join(__dirname, '..', '..', BUILD_FOLDER);

if (taskArguments.compile) {
await compileInstance({ useOvm: false, buildPath: buildPathEvm });
await compileInstance({ useOvm: true, buildPath: buildPathOvm });
await compileInstance({ useOvm: false, buildPath: buildPath });
}

if (taskArguments.deploy) {
await deployInstance({
useOvm: false,
providerUrl,
providerPort: providerPortL1,
buildPath: buildPathEvm,
buildPath: buildPath,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[np] can just use buildPath here as shorthand

});

await deployInstance({
useOvm: true,
providerUrl,
providerPort: providerPortL2,
buildPath: buildPathOvm,
buildPath: buildPath,
});
}

Expand Down
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,7 @@ const getUsers = ({ network = 'mainnet', user, useOvm = false } = {}) => {
}),
'mainnet-ovm': Object.assign({}, base, {
owner: '0x6d4a64C57612841c2C6745dB2a4E4db34F002D20',
deployer: '0xDe910777C787903F78C89e7a0bf7F4C435cBB1Fe',
}),
rinkeby: Object.assign({}, base),
ropsten: Object.assign({}, base),
Expand Down
Loading