Skip to content

Commit d372172

Browse files
committed
feat(e2e): run L1 and L2 together in e2e tests
Signed-off-by: Tomás Migone <[email protected]>
1 parent bc381b8 commit d372172

File tree

15 files changed

+460
-115
lines changed

15 files changed

+460
-115
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,7 @@ bin/
1919
# Coverage and other reports
2020
/reports
2121
coverage.json
22+
23+
# Local test files
24+
addresses-local.json
25+
arbitrum-addresses-local.json

cli/commands/bridge/to-l2.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ export const sendToL2 = async (cli: CLIEnvironment, cliArgs: CLIArgs): Promise<v
4545

4646
// parse provider
4747
const l1Provider = cli.wallet.provider
48-
const l2Provider = getProvider(cliArgs.l2ProviderUrl)
48+
// TODO: fix this hack for usage with hardhat
49+
const l2Provider = cliArgs.l2Provider ? cliArgs.l2Provider : getProvider(cliArgs.l2ProviderUrl)
4950
const l1ChainId = cli.chainId
5051
const l2ChainId = (await l2Provider.getNetwork()).chainId
5152
if (chainIdIsL2(l1ChainId) || !chainIdIsL2(l2ChainId)) {
@@ -100,6 +101,7 @@ export const sendToL2 = async (cli: CLIEnvironment, cliArgs: CLIArgs): Promise<v
100101
const txReceipt = await sendTransaction(cli.wallet, l1Gateway, 'outboundTransfer', txParams, {
101102
value: ethValue,
102103
})
104+
103105
// get l2 ticket status
104106
if (txReceipt.status == 1) {
105107
logger.info('Waiting for message to propagate to L2...')

config/graph.arbitrum-localhost.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
general:
2-
arbitrator: &arbitrator "0xFFcf8FDEE72ac11b5c542428B35EEF5769C409f0" # Arbitration Council
3-
governor: &governor "0x22d491Bde2303f2f43325b2108D26f1eAbA1e32b" # Graph Council
4-
authority: &authority "0xE11BA2b4D45Eaed5996Cd0823791E0C93114882d" # Authority that signs payment vouchers
5-
availabilityOracle: &availabilityOracle "0xd03ea8624C8C5987235048901fB614fDcA89b117" # Subgraph Availability Oracle
6-
pauseGuardian: &pauseGuardian "0x95cED938F7991cd0dFcb48F0a06a40FA1aF46EBC" # Protocol pause guardian
7-
allocationExchangeOwner: &allocationExchangeOwner "0x3E5e9111Ae8eB78Fe1CC3bb8915d5D461F3Ef9A9" # Allocation Exchange owner
2+
arbitrator: &arbitrator "0x4237154FE0510FdE3575656B60c68a01B9dCDdF8" # Arbitration Council
3+
governor: &governor "0x1257227a2ECA34834940110f7B5e341A5143A2c4" # Graph Council
4+
authority: &authority "0x12B8D08b116E1E3cc29eE9Cf42bB0AA8129C3215" # Authority that signs payment vouchers
5+
availabilityOracle: &availabilityOracle "0x7694a48065f063a767a962610C6717c59F36b445" # Subgraph Availability Oracle
6+
pauseGuardian: &pauseGuardian "0x601060e0DC5349AA55EC73df5A58cB0FC1cD2e3C" # Protocol pause guardian
7+
allocationExchangeOwner: &allocationExchangeOwner "0xbD38F7b67a591A5cc7D642e1026E5095B819d952" # Allocation Exchange owner
88

99
contracts:
1010
Controller:

e2e/deployment/config/l1/l1GraphTokenGateway.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ describe('[L1] L1GraphTokenGateway configuration', function () {
7777
'0x00',
7878
)
7979

80-
await expect(tx).revertedWith('INBOX_NOT_SET')
80+
await expect(tx).revertedWith('NOT_FROM_BRIDGE')
8181
})
8282
})
8383
})

e2e/scenarios/fixtures/bridge.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers'
2+
import { BigNumber } from 'ethers'
3+
import { toGRT } from '../../../cli/network'
4+
5+
export interface BridgeFixture {
6+
deploymentFile: string
7+
funder: SignerWithAddress
8+
accountsToFund: {
9+
signer: SignerWithAddress
10+
amount: BigNumber
11+
}[]
12+
}
13+
14+
// Signers
15+
// 0: l1Deployer
16+
// 1: l2Deployer
17+
18+
export const getBridgeFixture = (signers: SignerWithAddress[]): BridgeFixture => {
19+
return {
20+
deploymentFile: '../arbitrum-sdk/localNetwork.json',
21+
funder: signers[0],
22+
accountsToFund: [
23+
{
24+
signer: signers[1],
25+
amount: toGRT(10_000_000),
26+
},
27+
],
28+
}
29+
}

e2e/scenarios/lib/helpers.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
export function getGraphOptsFromArgv(): {
2-
graphConfig: string | undefined
32
addressBook: string | undefined
3+
graphConfig: string | undefined
4+
l1GraphConfig: string | undefined
5+
l2GraphConfig: string | undefined
46
} {
57
const argv = process.argv.slice(2)
68

79
const getArgv = (index: number) =>
810
argv[index] && argv[index] !== 'undefined' ? argv[index] : undefined
911

1012
return {
11-
graphConfig: getArgv(0),
12-
addressBook: getArgv(1),
13+
addressBook: getArgv(0),
14+
graphConfig: getArgv(1),
15+
l1GraphConfig: getArgv(2),
16+
l2GraphConfig: getArgv(3),
1317
}
1418
}

e2e/scenarios/lib/staking.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export const allocateFrom = async (
4242
'allocateFrom',
4343
[indexer.address, subgraphDeploymentID, amount, allocationId, metadata, proof],
4444
{
45-
gasLimit: 2000000,
45+
gasLimit: 4_000_000,
4646
},
4747
)
4848
}
@@ -56,6 +56,6 @@ export const closeAllocation = async (
5656

5757
console.log(`\nClosing ${allocationId}...`)
5858
await sendTransaction(indexer, contracts.Staking, 'closeAllocation', [allocationId, poi], {
59-
gasLimit: 2000000,
59+
gasLimit: 4_000_000,
6060
})
6161
}

e2e/scenarios/send-grt-to-l2.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { expect } from 'chai'
2+
import hre from 'hardhat'
3+
import { getBridgeFixture, BridgeFixture } from './fixtures/bridge'
4+
5+
describe('Bridge GRT to L2', () => {
6+
const graph = hre.graph()
7+
let bridgeFixture: BridgeFixture
8+
9+
before(async () => {
10+
const l1Deployer = await graph.l1.getDeployer()
11+
const l2Deployer = await graph.l2.getDeployer()
12+
bridgeFixture = getBridgeFixture([l1Deployer, l2Deployer])
13+
})
14+
15+
describe('GRT balances', () => {
16+
it(`L2 balances should match bridged amount`, async function () {
17+
for (const account of bridgeFixture.accountsToFund) {
18+
const l2GrtBalance = await graph.l2.contracts.GraphToken.balanceOf(account.signer.address)
19+
expect(l2GrtBalance).eq(account.amount)
20+
}
21+
})
22+
})
23+
})

e2e/scenarios/send-grt-to-l2.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// ### Scenario description ###
2+
// Bridge action > Bridge GRT tokens from L1 to L2
3+
// This scenario will bridge GRT tokens from L1 to L2. See fixtures for details.
4+
// Run with:
5+
// npx hardhat e2e:scenario send-grt-to-l2 --network <network> --graph-config config/graph.<network>.yml
6+
7+
import hre from 'hardhat'
8+
import { TASK_BRIDGE_TO_L2 } from '../../tasks/bridge/to-l2'
9+
import { getGraphOptsFromArgv } from './lib/helpers'
10+
import { getBridgeFixture } from './fixtures/bridge'
11+
12+
async function main() {
13+
const graphOpts = getGraphOptsFromArgv()
14+
const graph = hre.graph(graphOpts)
15+
16+
const l1Deployer = await graph.l1.getDeployer()
17+
const l2Deployer = await graph.l2.getDeployer()
18+
19+
const bridgeFixture = getBridgeFixture([l1Deployer, l2Deployer])
20+
21+
// == Send GRT to L2 accounts
22+
for (const account of bridgeFixture.accountsToFund) {
23+
await hre.run(TASK_BRIDGE_TO_L2, {
24+
...graphOpts,
25+
amount: account.amount.toString(),
26+
sender: bridgeFixture.funder.address,
27+
recipient: account.signer.address,
28+
deploymentFile: bridgeFixture.deploymentFile,
29+
})
30+
}
31+
}
32+
33+
// We recommend this pattern to be able to use async/await everywhere
34+
// and properly handle errors.
35+
main()
36+
.then(() => process.exit(0))
37+
.catch((error) => {
38+
console.error(error)
39+
process.exitCode = 1
40+
})

hardhat.config.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const SKIP_LOAD = process.env.SKIP_LOAD === 'true'
2929

3030
function loadTasks() {
3131
require('./gre/gre')
32-
;['contracts', 'misc', 'deployment', 'actions', 'verify', 'e2e'].forEach((folder) => {
32+
;['contracts', 'bridge', 'misc', 'deployment', 'actions', 'verify', 'e2e'].forEach((folder) => {
3333
const tasksPath = path.join(__dirname, 'tasks', folder)
3434
fs.readdirSync(tasksPath)
3535
.filter((pth) => pth.includes('.ts'))
@@ -101,6 +101,9 @@ function setupNetworkProviders(hardhatConfig) {
101101
const DEFAULT_TEST_MNEMONIC =
102102
'myth like bonus scare over problem client lizard pioneer submit female collect'
103103

104+
const DEFAULT_L2_TEST_MNEMONIC =
105+
'urge never interest human any economy gentle canvas anxiety pave unlock find'
106+
104107
const config: HardhatUserConfig = {
105108
paths: {
106109
sources: './contracts',
@@ -160,7 +163,7 @@ const config: HardhatUserConfig = {
160163
localnitrol2: {
161164
chainId: 412346,
162165
url: 'http://localhost:8547',
163-
accounts: { mnemonic: DEFAULT_TEST_MNEMONIC },
166+
accounts: { mnemonic: DEFAULT_L2_TEST_MNEMONIC },
164167
},
165168
},
166169
graph: {

0 commit comments

Comments
 (0)