Skip to content

Commit 51c0b62

Browse files
committed
test: update get batch posters test to anvil
1 parent a093ab7 commit 51c0b62

File tree

4 files changed

+115
-33
lines changed

4 files changed

+115
-33
lines changed

src/getBatchPosters.integration.test.ts

Lines changed: 44 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,37 @@ import { generatePrivateKey, privateKeyToAccount } from 'viem/accounts';
44

55
import { nitroTestnodeL2 } from './chains';
66
import { sequencerInboxActions } from './decorators/sequencerInboxActions';
7-
import { getInformationFromTestnode, getNitroTestnodePrivateKeyAccounts } from './testHelpers';
7+
import {
8+
getInformationFromTestnode,
9+
getNitroTestnodePrivateKeyAccounts,
10+
PrivateKeyAccountWithPrivateKey,
11+
} from './testHelpers';
812
import { getBatchPosters } from './getBatchPosters';
13+
import { isAnvilTestMode, getAnvilTestStack } from './integrationTestHelpers/injectedMode';
14+
15+
const env = isAnvilTestMode() ? getAnvilTestStack() : undefined;
16+
17+
let l3RollupOwner: PrivateKeyAccountWithPrivateKey;
18+
let l3Rollup: Address;
19+
let l3UpgradeExecutor: Address;
20+
let l3SequencerInbox: Address;
21+
22+
if (env) {
23+
l3RollupOwner = env.l3.accounts.rollupOwner;
24+
l3Rollup = env.l3.rollup;
25+
l3UpgradeExecutor = env.l3.upgradeExecutor;
26+
l3SequencerInbox = env.l3.sequencerInbox;
27+
} else {
28+
l3RollupOwner = getNitroTestnodePrivateKeyAccounts().l3RollupOwner;
29+
30+
const testNodeInformation = getInformationFromTestnode();
31+
l3Rollup = testNodeInformation.l3Rollup;
32+
l3UpgradeExecutor = testNodeInformation.l3UpgradeExecutor;
33+
l3SequencerInbox = testNodeInformation.l3SequencerInbox;
34+
}
935

10-
const { l3RollupOwner } = getNitroTestnodePrivateKeyAccounts();
11-
const { l3Rollup, l3UpgradeExecutor, l3SequencerInbox } = getInformationFromTestnode();
12-
13-
const client = createPublicClient({
14-
chain: nitroTestnodeL2,
36+
const l2Client = createPublicClient({
37+
chain: env ? env.l2.chain : nitroTestnodeL2,
1538
transport: http(),
1639
}).extend(
1740
sequencerInboxActions({
@@ -20,19 +43,19 @@ const client = createPublicClient({
2043
);
2144

2245
async function setBatchPoster(batchPoster: Address, state: boolean) {
23-
const tx = await client.sequencerInboxPrepareTransactionRequest({
46+
const tx = await l2Client.sequencerInboxPrepareTransactionRequest({
2447
functionName: 'setIsBatchPoster',
2548
args: [batchPoster, state],
2649
account: l3RollupOwner.address,
2750
upgradeExecutor: l3UpgradeExecutor,
2851
sequencerInbox: l3SequencerInbox,
2952
});
3053

31-
const txHash = await client.sendRawTransaction({
54+
const txHash = await l2Client.sendRawTransaction({
3255
serializedTransaction: await l3RollupOwner.signTransaction(tx),
3356
});
3457

35-
await client.waitForTransactionReceipt({
58+
await l2Client.waitForTransactionReceipt({
3659
hash: txHash,
3760
});
3861
}
@@ -43,7 +66,7 @@ describe('successfully get batch posters', () => {
4366
const randomAccount = privateKeyToAccount(generatePrivateKey()).address;
4467

4568
const { isAccurate: isAccurateInitially, batchPosters: initialBatchPosters } =
46-
await getBatchPosters(client, {
69+
await getBatchPosters(l2Client, {
4770
rollup: l3Rollup,
4871
sequencerInbox: l3SequencerInbox,
4972
});
@@ -56,7 +79,7 @@ describe('successfully get batch posters', () => {
5679
await setBatchPoster(randomAccount, false);
5780

5881
const { isAccurate: isStillAccurate, batchPosters: newBatchPosters } = await getBatchPosters(
59-
client,
82+
l2Client,
6083
{
6184
rollup: l3Rollup,
6285
sequencerInbox: l3SequencerInbox,
@@ -67,7 +90,7 @@ describe('successfully get batch posters', () => {
6790
expect(isStillAccurate).toBeTruthy();
6891

6992
await setBatchPoster(randomAccount, true);
70-
const { batchPosters, isAccurate } = await getBatchPosters(client, {
93+
const { batchPosters, isAccurate } = await getBatchPosters(l2Client, {
7194
rollup: l3Rollup,
7295
sequencerInbox: l3SequencerInbox,
7396
});
@@ -78,7 +101,7 @@ describe('successfully get batch posters', () => {
78101
// Reset state for future tests
79102
await setBatchPoster(randomAccount, false);
80103
const { isAccurate: isAccurateFinal, batchPosters: batchPostersFinal } = await getBatchPosters(
81-
client,
104+
l2Client,
82105
{
83106
rollup: l3Rollup,
84107
sequencerInbox: l3SequencerInbox,
@@ -92,7 +115,7 @@ describe('successfully get batch posters', () => {
92115
const randomAccount = privateKeyToAccount(generatePrivateKey()).address;
93116

94117
const { isAccurate: isAccurateInitially, batchPosters: initialBatchPosters } =
95-
await getBatchPosters(client, {
118+
await getBatchPosters(l2Client, {
96119
rollup: l3Rollup,
97120
sequencerInbox: l3SequencerInbox,
98121
});
@@ -103,7 +126,7 @@ describe('successfully get batch posters', () => {
103126
await setBatchPoster(randomAccount, true);
104127
await setBatchPoster(randomAccount, true);
105128
const { isAccurate: isStillAccurate, batchPosters: newBatchPosters } = await getBatchPosters(
106-
client,
129+
l2Client,
107130
{
108131
rollup: l3Rollup,
109132
sequencerInbox: l3SequencerInbox,
@@ -115,7 +138,7 @@ describe('successfully get batch posters', () => {
115138

116139
// Reset state for futures tests
117140
await setBatchPoster(randomAccount, false);
118-
const { batchPosters, isAccurate } = await getBatchPosters(client, {
141+
const { batchPosters, isAccurate } = await getBatchPosters(l2Client, {
119142
rollup: l3Rollup,
120143
sequencerInbox: l3SequencerInbox,
121144
});
@@ -125,14 +148,14 @@ describe('successfully get batch posters', () => {
125148

126149
it('when adding an existing batch poster', async () => {
127150
const { isAccurate: isAccurateInitially, batchPosters: initialBatchPosters } =
128-
await getBatchPosters(client, { rollup: l3Rollup, sequencerInbox: l3SequencerInbox });
151+
await getBatchPosters(l2Client, { rollup: l3Rollup, sequencerInbox: l3SequencerInbox });
129152
expect(initialBatchPosters).toHaveLength(1);
130153
expect(isAccurateInitially).toBeTruthy();
131154

132155
const firstBatchPoster = initialBatchPosters[0];
133156
await setBatchPoster(firstBatchPoster, true);
134157

135-
const { isAccurate, batchPosters } = await getBatchPosters(client, {
158+
const { isAccurate, batchPosters } = await getBatchPosters(l2Client, {
136159
rollup: l3Rollup,
137160
sequencerInbox: l3SequencerInbox,
138161
});
@@ -142,13 +165,13 @@ describe('successfully get batch posters', () => {
142165

143166
it('when removing an existing batch poster', async () => {
144167
const { isAccurate: isAccurateInitially, batchPosters: initialBatchPosters } =
145-
await getBatchPosters(client, { rollup: l3Rollup, sequencerInbox: l3SequencerInbox });
168+
await getBatchPosters(l2Client, { rollup: l3Rollup, sequencerInbox: l3SequencerInbox });
146169
expect(initialBatchPosters).toHaveLength(1);
147170
expect(isAccurateInitially).toBeTruthy();
148171

149172
const lastBatchPoster = initialBatchPosters[initialBatchPosters.length - 1];
150173
await setBatchPoster(lastBatchPoster, false);
151-
const { isAccurate, batchPosters } = await getBatchPosters(client, {
174+
const { isAccurate, batchPosters } = await getBatchPosters(l2Client, {
152175
rollup: l3Rollup,
153176
sequencerInbox: l3SequencerInbox,
154177
});
@@ -157,7 +180,7 @@ describe('successfully get batch posters', () => {
157180

158181
await setBatchPoster(lastBatchPoster, true);
159182
const { isAccurate: isAccurateFinal, batchPosters: batchPostersFinal } = await getBatchPosters(
160-
client,
183+
l2Client,
161184
{ rollup: l3Rollup, sequencerInbox: l3SequencerInbox },
162185
);
163186
expect(batchPostersFinal).toEqual(initialBatchPosters);

src/integrationTestHelpers/anvilHarness.ts

Lines changed: 69 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import {
1212
http,
1313
parseEther,
1414
parseGwei,
15+
PublicClient,
16+
Transport,
1517
zeroAddress,
1618
} from 'viem';
1719
import { sepolia } from 'viem/chains';
@@ -62,7 +64,13 @@ type BaseStack<L2Accounts, L3Accounts> = {
6264
};
6365
l3: {
6466
accounts: L3Accounts;
67+
timingParams: CustomTimingParams;
6568
nativeToken: Address;
69+
rollup: Address;
70+
bridge: Address;
71+
sequencerInbox: Address;
72+
upgradeExecutor: Address;
73+
batchPoster: Address;
6674
};
6775
};
6876

@@ -71,6 +79,7 @@ export type AnvilTestStack = BaseStack<
7179
deployer: PrivateKeyAccountWithPrivateKey;
7280
},
7381
{
82+
rollupOwner: PrivateKeyAccountWithPrivateKey;
7483
tokenBridgeDeployer: PrivateKeyAccountWithPrivateKey;
7584
}
7685
>;
@@ -80,6 +89,7 @@ export type InjectedAnvilTestStack = BaseStack<
8089
deployerPrivateKey: Hex;
8190
},
8291
{
92+
rollupOwnerPrivateKey: Hex;
8393
tokenBridgeDeployerPrivateKey: Hex;
8494
}
8595
>;
@@ -112,6 +122,7 @@ export function dehydrateAnvilTestStack(env: AnvilTestStack): InjectedAnvilTestS
112122
l3: {
113123
...env.l3,
114124
accounts: {
125+
rollupOwnerPrivateKey: env.l3.accounts.rollupOwner.privateKey,
115126
tokenBridgeDeployerPrivateKey: env.l3.accounts.tokenBridgeDeployer.privateKey,
116127
},
117128
},
@@ -134,6 +145,7 @@ export function hydrateAnvilTestStack(env: InjectedAnvilTestStack): AnvilTestSta
134145
l3: {
135146
...env.l3,
136147
accounts: {
148+
rollupOwner: createAccount(env.l3.accounts.rollupOwnerPrivateKey),
137149
tokenBridgeDeployer: createAccount(env.l3.accounts.tokenBridgeDeployerPrivateKey),
138150
},
139151
},
@@ -165,14 +177,15 @@ export async function setupAnvilTestStack(): Promise<AnvilTestStack> {
165177
createDockerNetwork(dockerNetworkName);
166178

167179
const l2ChainId = testConstants.DEFAULT_L2_CHAIN_ID;
180+
const l3ChainId = l2ChainId + 1;
168181
const l1RpcPort = testConstants.DEFAULT_L1_RPC_PORT;
169182
const l2RpcPort = testConstants.DEFAULT_L2_RPC_PORT;
170183
const anvilImage = testConstants.DEFAULT_ANVIL_IMAGE;
171184
const nitroImage = testConstants.DEFAULT_NITRO_IMAGE;
172185
const sepoliaBeaconRpc = testConstants.DEFAULT_SEPOLIA_BEACON_RPC;
173186
const anvilForkUrl = testConstants.DEFAULT_SEPOLIA_RPC;
174187
const rollupCreatorVersion: RollupCreatorSupportedVersion = 'v3.2';
175-
const L2TimingParams: CustomTimingParams = {
188+
const rollupTimingParams: CustomTimingParams = {
176189
confirmPeriodBlocks: 150n,
177190
challengeGracePeriodBlocks: 14_400n,
178191
minimumAssertionPeriod: 75n,
@@ -233,11 +246,11 @@ export async function setupAnvilTestStack(): Promise<AnvilTestStack> {
233246
{
234247
chainId: BigInt(l2ChainId),
235248
owner: harnessDeployer.address,
236-
sequencerInboxMaxTimeVariation: L2TimingParams.sequencerInboxMaxTimeVariation,
237-
confirmPeriodBlocks: L2TimingParams.confirmPeriodBlocks,
238-
challengeGracePeriodBlocks: L2TimingParams.challengeGracePeriodBlocks,
239-
minimumAssertionPeriod: L2TimingParams.minimumAssertionPeriod,
240-
validatorAfkBlocks: L2TimingParams.validatorAfkBlocks,
249+
sequencerInboxMaxTimeVariation: rollupTimingParams.sequencerInboxMaxTimeVariation,
250+
confirmPeriodBlocks: rollupTimingParams.confirmPeriodBlocks,
251+
challengeGracePeriodBlocks: rollupTimingParams.challengeGracePeriodBlocks,
252+
minimumAssertionPeriod: rollupTimingParams.minimumAssertionPeriod,
253+
validatorAfkBlocks: rollupTimingParams.validatorAfkBlocks,
241254
chainConfig: prepareChainConfig({
242255
chainId: l2ChainId,
243256
arbitrum: {
@@ -338,7 +351,7 @@ export async function setupAnvilTestStack(): Promise<AnvilTestStack> {
338351
});
339352
console.log('Deployer funded on L2');
340353

341-
const l2PublicClient = createPublicClient({
354+
let l2Client: PublicClient<Transport, Chain> = createPublicClient({
342355
chain: l2BootstrapChain,
343356
transport: http(l2RpcUrl),
344357
});
@@ -356,12 +369,12 @@ export async function setupAnvilTestStack(): Promise<AnvilTestStack> {
356369
});
357370

358371
console.log('Configuring L2 fee settings...');
359-
await configureL2Fees(l2PublicClient, l2WalletClient, harnessDeployer);
372+
await configureL2Fees(l2Client, l2WalletClient, harnessDeployer);
360373
console.log('L2 fee settings updated\n');
361374

362375
console.log('Ensuring L2 create2 factory...');
363376
await ensureCreate2Factory({
364-
publicClient: l2PublicClient,
377+
publicClient: l2Client,
365378
walletClient: l2WalletClient,
366379
fundingAccount: harnessDeployer,
367380
});
@@ -396,7 +409,7 @@ export async function setupAnvilTestStack(): Promise<AnvilTestStack> {
396409
chainId: l2ChainId,
397410
},
398411
{
399-
publicClient: l2PublicClient,
412+
publicClient: l2Client,
400413
walletClient: blockAdvancerWalletClient,
401414
account: blockAdvancerAccount,
402415
},
@@ -425,27 +438,71 @@ export async function setupAnvilTestStack(): Promise<AnvilTestStack> {
425438
contracts: {
426439
rollupCreator: { address: l2RollupCreator },
427440
tokenBridgeCreator: { address: harnessDeployer.address },
428-
weth: { address: harnessDeployer.address },
441+
weth: { address: customGasToken.address as Address },
429442
},
430443
});
431444
registerCustomParentChain(l2Chain);
432445
console.log('L1 & L2 chains ready\n');
433446

447+
l2Client = createPublicClient({
448+
chain: l2Chain,
449+
transport: http(l2RpcUrl),
450+
});
451+
452+
console.log('Deploying L3 rollup contracts on L2...');
453+
const l3RollupConfig = createRollupPrepareDeploymentParamsConfig(l2Client, {
454+
chainId: BigInt(l3ChainId),
455+
owner: harnessDeployer.address,
456+
sequencerInboxMaxTimeVariation: rollupTimingParams.sequencerInboxMaxTimeVariation,
457+
confirmPeriodBlocks: rollupTimingParams.confirmPeriodBlocks,
458+
challengeGracePeriodBlocks: rollupTimingParams.challengeGracePeriodBlocks,
459+
minimumAssertionPeriod: rollupTimingParams.minimumAssertionPeriod,
460+
validatorAfkBlocks: rollupTimingParams.validatorAfkBlocks,
461+
chainConfig: prepareChainConfig({
462+
chainId: l3ChainId,
463+
arbitrum: {
464+
InitialChainOwner: harnessDeployer.address,
465+
DataAvailabilityCommittee: true,
466+
},
467+
}),
468+
});
469+
470+
const l3Rollup = await createRollup({
471+
params: {
472+
config: l3RollupConfig,
473+
batchPosters: [harnessDeployer.address],
474+
validators: [harnessDeployer.address],
475+
nativeToken: customGasToken.address as Address,
476+
maxDataSize: 104_857n,
477+
} as CreateRollupParams<'v3.2'>,
478+
account: harnessDeployer,
479+
parentChainPublicClient: l2Client,
480+
rollupCreatorVersion,
481+
});
482+
console.log('L3 rollup contracts deployed on L2\n');
483+
434484
initializedEnv = {
435485
l2: {
436486
rpcUrl: l2RpcUrl,
437487
chain: l2Chain,
438488
accounts: {
439489
deployer: harnessDeployer,
440490
},
441-
timingParams: L2TimingParams,
491+
timingParams: rollupTimingParams,
442492
rollupCreatorVersion,
443493
},
444494
l3: {
445495
accounts: {
496+
rollupOwner: harnessDeployer,
446497
tokenBridgeDeployer: harnessDeployer,
447498
},
499+
timingParams: rollupTimingParams,
448500
nativeToken: customGasToken.address as Address,
501+
rollup: l3Rollup.coreContracts.rollup,
502+
bridge: l3Rollup.coreContracts.bridge,
503+
sequencerInbox: l3Rollup.coreContracts.sequencerInbox,
504+
upgradeExecutor: l3Rollup.coreContracts.upgradeExecutor,
505+
batchPoster: harnessDeployer.address,
449506
},
450507
};
451508

src/integrationTestHelpers/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export const testConstants = {
66
DEFAULT_NITRO_IMAGE: 'offchainlabs/nitro-node:v3.9.5-66e42c4',
77
DEFAULT_NITRO_CONTRACTS_REF: 'v3.2.0-2f747c7',
88
DEFAULT_L2_CHAIN_ID: 421_337,
9+
DEFAULT_L3_CHAIN_ID: 421_338,
910
DEFAULT_L1_RPC_PORT: 9645,
1011
DEFAULT_L2_RPC_PORT: 8747,
1112
DEFAULT_SEPOLIA_FORK_BLOCK_NUMBER: 10_490_000,

vitest.integration.anvil.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export default mergeConfig(
1717
include: [
1818
'./src/createRollup.integration.test.ts',
1919
'./src/decorators/arbAggregatorActions.integration.test.ts',
20+
'./src/getBatchPosters.integration.test.ts',
2021
],
2122
fileParallelism: false,
2223
},

0 commit comments

Comments
 (0)