Skip to content
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

test: consolidate unit/e2e test code #908

Merged
merged 13 commits into from
Jan 15, 2024
Prev Previous commit
Next Next commit
chore: simplify protocol deployment scripts
Signed-off-by: Tomás Migone <tomas@edgeandnode.com>
tmigone committed Jan 12, 2024
commit fbe6730bbf1d086cb3f4b80ed2e9c0468fffacb4
2 changes: 1 addition & 1 deletion packages/contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@ const SKIP_LOAD = process.env.SKIP_LOAD === 'true'

function loadTasks() {
require('@graphprotocol/sdk/gre')
;['contracts', 'bridge', 'deployment', 'verify', 'e2e'].forEach((folder) => {
;['contracts', 'bridge', 'deployment', 'migrate', 'verify', 'e2e'].forEach((folder) => {
const tasksPath = path.join(__dirname, 'tasks', folder)
fs.readdirSync(tasksPath)
.filter((pth) => pth.includes('.ts'))
57 changes: 8 additions & 49 deletions packages/contracts/scripts/e2e
Original file line number Diff line number Diff line change
@@ -45,23 +45,17 @@ if [[ "$L1_NETWORK" == "$L2_NETWORK" ]]; then
fi

### > SCRIPT AUX FUNCTIONS <
function pre_deploy() {
function deploy() {
local NETWORK=$1
local GRAPH_CONFIG=$2

# Create named accounts
npx hardhat migrate:accounts --network "$NETWORK" --graph-config "$GRAPH_CONFIG" --disable-secure-accounts

local ADDRESS_BOOK=$3

echo "Deploying protocol on $NETWORK"
# Fund accounts if using nitro test nodes
if [[ "$NETWORK" == *"localnitro"* ]]; then
npx hardhat nitro:fund-accounts --network "$NETWORK" --graph-config "$GRAPH_CONFIG" --disable-secure-accounts
npx hardhat migrate:nitro:fund-accounts --network "$NETWORK" --graph-config "$GRAPH_CONFIG" --disable-secure-accounts
fi
}

function deploy() {
local NETWORK=$1
local GRAPH_CONFIG=$2
local ADDRESS_BOOK=$3

# Deploy protocol
npx hardhat migrate \
@@ -73,18 +67,6 @@ function deploy() {
--address-book "$ADDRESS_BOOK"
}

function post_deploy () {
local NETWORK=$1
local GRAPH_CONFIG=$2
local ADDRESS_BOOK=$3

# Governor to accept contracts ownership
npx hardhat migrate:ownership --network "$NETWORK" --graph-config "$GRAPH_CONFIG" --address-book "$ADDRESS_BOOK" --disable-secure-accounts

# Unpause the protocol
npx hardhat migrate:unpause:protocol --network "$NETWORK" --graph-config "$GRAPH_CONFIG" --address-book "$ADDRESS_BOOK" --disable-secure-accounts
}

function configure_bridge () {
local L1_NETWORK=$1
local L1_GRAPH_CONFIG=$2
@@ -94,29 +76,12 @@ function configure_bridge () {
local ARBITRUM_ADDRESS_BOOK=$6
local ARBITRUM_DEPLOYMENT_FILE=$7

# These settings are only used for CLI bridge commands
# so we keep them here to avoid confusion with hardhat based tasks
local L1_CHAIN_ID=${L1_CHAIN_ID:-"1337"}
local L2_CHAIN_ID=${L2_CHAIN_ID:-"412346"}

local L1_RPC=${L1_RPC:-"http://127.0.0.1:8545"}
local L2_RPC=${L2_RPC:-"http://127.0.0.1:8547"}

local L1_MNEMONIC=${L1_MNEMONIC:-"myth like bonus scare over problem client lizard pioneer submit female collect"}
local L2_MNEMONIC=${L2_MNEMONIC:-"urge never interest human any economy gentle canvas anxiety pave unlock find"}

# Copy required arbitrum contract addresses to the local arbitrum address book
if [[ "$L1_NETWORK" == *"localnitro"* ]]; then
npx hardhat nitro:address-book-setup --deployment-file "$ARBITRUM_DEPLOYMENT_FILE" --arbitrum-address-book "$ARBITRUM_ADDRESS_BOOK"
npx hardhat migrate:nitro:address-book --deployment-file "$ARBITRUM_DEPLOYMENT_FILE" --arbitrum-address-book "$ARBITRUM_ADDRESS_BOOK"
fi

# Configure the bridge
npx hardhat bridge:configure:l1 --network "$L1_NETWORK" --graph-config "$L1_GRAPH_CONFIG" --address-book "$ADDRESS_BOOK" --arbitrum-address-book "$ARBITRUM_ADDRESS_BOOK" --disable-secure-accounts
npx hardhat bridge:configure:l2 --network "$L2_NETWORK" --graph-config "$L2_GRAPH_CONFIG" --address-book "$ADDRESS_BOOK" --arbitrum-address-book "$ARBITRUM_ADDRESS_BOOK" --disable-secure-accounts

# Unpause the bridge
npx hardhat migrate:unpause:bridge --network "$L2_NETWORK" --graph-config "$L2_GRAPH_CONFIG" --address-book "$ADDRESS_BOOK" --disable-secure-accounts
npx hardhat migrate:unpause:bridge --network "$L1_NETWORK" --graph-config "$L1_GRAPH_CONFIG" --address-book "$ADDRESS_BOOK" --disable-secure-accounts
npx hardhat migrate:bridge --network "$L1_NETWORK" --l1-graph-config "$L1_GRAPH_CONFIG" --l2-graph-config "$L2_GRAPH_CONFIG" --address-book "$ADDRESS_BOOK" --arbitrum-address-book "$ARBITRUM_ADDRESS_BOOK" --disable-secure-accounts
}

function test_e2e () {
@@ -188,18 +153,12 @@ fi
## DEPLOY
# Deploy L1
if [[ -n "$L1_NETWORK" ]]; then
echo "Deploying L1 protocol"
pre_deploy "$L1_NETWORK" "$L1_GRAPH_CONFIG"
deploy "$L1_NETWORK" "$L1_GRAPH_CONFIG" "$ADDRESS_BOOK"
post_deploy "$L1_NETWORK" "$L1_GRAPH_CONFIG" "$ADDRESS_BOOK"
fi

# Deploy L2
if [[ -n "$L2_NETWORK" ]]; then
echo "Deploying L2 protocol"
pre_deploy "$L2_NETWORK" "$L2_GRAPH_CONFIG"
deploy "$L2_NETWORK" "$L2_GRAPH_CONFIG" "$ADDRESS_BOOK"
post_deploy "$L2_NETWORK" "$L2_GRAPH_CONFIG" "$ADDRESS_BOOK"
fi

# Configure bridge
71 changes: 0 additions & 71 deletions packages/contracts/tasks/bridge/configure.ts

This file was deleted.

3 changes: 1 addition & 2 deletions packages/contracts/tasks/bridge/to-l2.ts
Original file line number Diff line number Diff line change
@@ -3,7 +3,6 @@ import { BigNumber } from 'ethers'
import { GRE_TASK_PARAMS } from '@graphprotocol/sdk/gre'
import { sendToL2 } from '@graphprotocol/sdk'
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers'
import { TASK_NITRO_SETUP_SDK } from '../deployment/nitro'

export const TASK_BRIDGE_TO_L2 = 'bridge:send-to-l2'

@@ -30,7 +29,7 @@ task(TASK_BRIDGE_TO_L2, 'Bridge GRT tokens from L1 to L2')
// If local, add nitro test node networks to sdk
if (taskArgs.deploymentFile) {
console.log('> Adding nitro test node network to sdk')
await hre.run(TASK_NITRO_SETUP_SDK, { deploymentFile: taskArgs.deploymentFile })
await hre.run('migrate:nitro:register', { deploymentFile: taskArgs.deploymentFile })
}

// Get the sender, use L1 deployer if not provided
40 changes: 0 additions & 40 deletions packages/contracts/tasks/deployment/accounts.ts

This file was deleted.

135 changes: 0 additions & 135 deletions packages/contracts/tasks/deployment/nitro.ts

This file was deleted.

Loading