Skip to content

Commit e6898e8

Browse files
committed
test: update updateExecutor and arbOwner test to anvil
1 parent 08e523d commit e6898e8

File tree

4 files changed

+100
-52
lines changed

4 files changed

+100
-52
lines changed

src/decorators/arbOwnerPublicActions.integration.test.ts

Lines changed: 39 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,58 +5,67 @@ import { generatePrivateKey, privateKeyToAccount } from 'viem/accounts';
55
import { nitroTestnodeL2 } from '../chains';
66
import { arbOwnerPublicActions } from './arbOwnerPublicActions';
77
import { getNitroTestnodePrivateKeyAccounts } from '../testHelpers';
8+
import { getAnvilTestStack, isAnvilTestMode } from '../integrationTestHelpers/injectedMode';
9+
import { PrivateKeyAccount } from 'viem/accounts';
810

9-
// l2 owner private key
10-
const devPrivateKey = getNitroTestnodePrivateKeyAccounts().l2RollupOwner.privateKey;
11+
const env = isAnvilTestMode() ? getAnvilTestStack() : undefined;
1112

12-
const owner = privateKeyToAccount(devPrivateKey);
1313
const randomAccount = privateKeyToAccount(generatePrivateKey());
1414

15-
const client = createPublicClient({
16-
chain: nitroTestnodeL2,
15+
let l2RollupOwner: PrivateKeyAccount;
16+
17+
if (env) {
18+
l2RollupOwner = env.l2.accounts.rollupOwner;
19+
} else {
20+
const devPrivateKey = getNitroTestnodePrivateKeyAccounts().l2RollupOwner.privateKey;
21+
l2RollupOwner = privateKeyToAccount(devPrivateKey);
22+
}
23+
24+
const l2Client = createPublicClient({
25+
chain: env ? env.l2.chain : nitroTestnodeL2,
1726
transport: http(),
1827
}).extend(arbOwnerPublicActions);
1928

2029
it('successfully fetches network fee receiver', async () => {
21-
const result = await client.arbOwnerReadContract({
30+
const result = await l2Client.arbOwnerReadContract({
2231
functionName: 'getNetworkFeeAccount',
2332
});
2433

25-
expect(result).toEqual(owner.address);
34+
expect(result).toEqual(l2RollupOwner.address);
2635
});
2736

2837
it('succesfully fetches chain owners', async () => {
29-
const result = await client.arbOwnerReadContract({
38+
const result = await l2Client.arbOwnerReadContract({
3039
functionName: 'getAllChainOwners',
3140
});
3241

33-
expect(result).toContain(owner.address);
42+
expect(result).toContain(l2RollupOwner.address);
3443
});
3544

3645
it('succesfully adds chain owner', async () => {
37-
const isOwnerInitially = await client.arbOwnerReadContract({
46+
const isOwnerInitially = await l2Client.arbOwnerReadContract({
3847
functionName: 'isChainOwner',
3948
args: [randomAccount.address],
4049
});
4150

4251
// assert account is not already an owner
4352
expect(isOwnerInitially).toEqual(false);
4453

45-
const transactionRequest = await client.arbOwnerPrepareTransactionRequest({
54+
const transactionRequest = await l2Client.arbOwnerPrepareTransactionRequest({
4655
functionName: 'addChainOwner',
4756
args: [randomAccount.address],
4857
upgradeExecutor: false,
49-
account: owner.address,
58+
account: l2RollupOwner.address,
5059
});
5160

5261
// submit tx to add chain owner
53-
const txHash = await client.sendRawTransaction({
54-
serializedTransaction: await owner.signTransaction(transactionRequest),
62+
const txHash = await l2Client.sendRawTransaction({
63+
serializedTransaction: await l2RollupOwner.signTransaction(transactionRequest),
5564
});
5665

57-
await client.waitForTransactionReceipt({ hash: txHash });
66+
await l2Client.waitForTransactionReceipt({ hash: txHash });
5867

59-
const isOwner = await client.arbOwnerReadContract({
68+
const isOwner = await l2Client.arbOwnerReadContract({
6069
functionName: 'isChainOwner',
6170
args: [randomAccount.address],
6271
});
@@ -66,29 +75,29 @@ it('succesfully adds chain owner', async () => {
6675
});
6776

6877
it('succesfully removes chain owner', async () => {
69-
const isOwnerInitially = await client.arbOwnerReadContract({
78+
const isOwnerInitially = await l2Client.arbOwnerReadContract({
7079
functionName: 'isChainOwner',
7180
args: [randomAccount.address],
7281
});
7382

7483
// assert account is an owner
7584
expect(isOwnerInitially).toEqual(true);
7685

77-
const transactionRequest = await client.arbOwnerPrepareTransactionRequest({
86+
const transactionRequest = await l2Client.arbOwnerPrepareTransactionRequest({
7887
functionName: 'removeChainOwner',
7988
args: [randomAccount.address],
8089
upgradeExecutor: false,
81-
account: owner.address,
90+
account: l2RollupOwner.address,
8291
});
8392

8493
// submit tx to remove chain owner
85-
const txHash = await client.sendRawTransaction({
86-
serializedTransaction: await owner.signTransaction(transactionRequest),
94+
const txHash = await l2Client.sendRawTransaction({
95+
serializedTransaction: await l2RollupOwner.signTransaction(transactionRequest),
8796
});
8897

89-
await client.waitForTransactionReceipt({ hash: txHash });
98+
await l2Client.waitForTransactionReceipt({ hash: txHash });
9099

91-
const isOwner = await client.arbOwnerReadContract({
100+
const isOwner = await l2Client.arbOwnerReadContract({
92101
functionName: 'isChainOwner',
93102
args: [randomAccount.address],
94103
});
@@ -98,28 +107,28 @@ it('succesfully removes chain owner', async () => {
98107
});
99108

100109
it('succesfully updates infra fee receiver', async () => {
101-
const initialInfraFeeReceiver = await client.arbOwnerReadContract({
110+
const initialInfraFeeReceiver = await l2Client.arbOwnerReadContract({
102111
functionName: 'getInfraFeeAccount',
103112
});
104113

105114
// assert account is not already infra fee receiver
106115
expect(initialInfraFeeReceiver).not.toEqual(randomAccount.address);
107116

108-
const transactionRequest = await client.arbOwnerPrepareTransactionRequest({
117+
const transactionRequest = await l2Client.arbOwnerPrepareTransactionRequest({
109118
functionName: 'setInfraFeeAccount',
110119
args: [randomAccount.address],
111120
upgradeExecutor: false,
112-
account: owner.address,
121+
account: l2RollupOwner.address,
113122
});
114123

115124
// submit tx to update infra fee receiver
116-
const txHash = await client.sendRawTransaction({
117-
serializedTransaction: await owner.signTransaction(transactionRequest),
125+
const txHash = await l2Client.sendRawTransaction({
126+
serializedTransaction: await l2RollupOwner.signTransaction(transactionRequest),
118127
});
119128

120-
await client.waitForTransactionReceipt({ hash: txHash });
129+
await l2Client.waitForTransactionReceipt({ hash: txHash });
121130

122-
const infraFeeReceiver = await client.arbOwnerReadContract({
131+
const infraFeeReceiver = await l2Client.arbOwnerReadContract({
123132
functionName: 'getInfraFeeAccount',
124133
});
125134

src/integrationTestHelpers/anvilHarness.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,17 @@ import type { CustomTimingParams, PrivateKeyAccountWithPrivateKey } from '../tes
6060
type RegisteredParentChain = Parameters<typeof registerCustomParentChain>[0];
6161

6262
type BaseStack<L2Accounts, L3Accounts> = {
63+
l1: {
64+
rpcUrl: string;
65+
chain: Chain;
66+
};
6367
l2: {
6468
rpcUrl: string;
6569
chain: Chain;
6670
accounts: L2Accounts;
6771
timingParams: CustomTimingParams;
6872
rollupCreatorVersion: RollupCreatorSupportedVersion;
73+
upgradeExecutor: Address;
6974
};
7075
l3: {
7176
accounts: L3Accounts;
@@ -81,6 +86,7 @@ type BaseStack<L2Accounts, L3Accounts> = {
8186

8287
export type AnvilTestStack = BaseStack<
8388
{
89+
rollupOwner: PrivateKeyAccountWithPrivateKey;
8490
deployer: PrivateKeyAccountWithPrivateKey;
8591
},
8692
{
@@ -91,6 +97,7 @@ export type AnvilTestStack = BaseStack<
9197

9298
export type InjectedAnvilTestStack = BaseStack<
9399
{
100+
rollupOwnerPrivateKey: Hex;
94101
deployerPrivateKey: Hex;
95102
},
96103
{
@@ -150,6 +157,7 @@ export function dehydrateAnvilTestStack(env: AnvilTestStack): InjectedAnvilTestS
150157
l2: {
151158
...env.l2,
152159
accounts: {
160+
rollupOwnerPrivateKey: env.l2.accounts.rollupOwner.privateKey,
153161
deployerPrivateKey: env.l2.accounts.deployer.privateKey,
154162
},
155163
},
@@ -173,6 +181,7 @@ export function hydrateAnvilTestStack(env: InjectedAnvilTestStack): AnvilTestSta
173181
...env.l2,
174182
chain: l2Chain,
175183
accounts: {
184+
rollupOwner: createAccount(env.l2.accounts.rollupOwnerPrivateKey),
176185
deployer: createAccount(env.l2.accounts.deployerPrivateKey),
177186
},
178187
},
@@ -258,8 +267,15 @@ export async function setupAnvilTestStack(): Promise<AnvilTestStack> {
258267
});
259268

260269
const l1RpcUrl = `http://127.0.0.1:${l1RpcPort}`;
270+
const l1Chain = defineChain({
271+
...sepolia,
272+
rpcUrls: {
273+
default: { http: [l1RpcUrl] },
274+
public: { http: [l1RpcUrl] },
275+
},
276+
});
261277
const l1Client = createPublicClient({
262-
chain: sepolia,
278+
chain: l1Chain,
263279
transport: http(l1RpcUrl),
264280
});
265281

@@ -537,14 +553,20 @@ export async function setupAnvilTestStack(): Promise<AnvilTestStack> {
537553
console.log('L3 rollup contracts deployed on L2\n');
538554

539555
initializedEnv = {
556+
l1: {
557+
rpcUrl: l1RpcUrl,
558+
chain: l1Chain,
559+
},
540560
l2: {
541561
rpcUrl: l2RpcUrl,
542562
chain: l2Chain,
543563
accounts: {
564+
rollupOwner: harnessDeployer,
544565
deployer: harnessDeployer,
545566
},
546567
timingParams: rollupTimingParams,
547568
rollupCreatorVersion,
569+
upgradeExecutor: l2Rollup.coreContracts.upgradeExecutor,
548570
},
549571
l3: {
550572
accounts: {

src/upgradeExecutor.integration.test.ts

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,38 @@
11
import { describe, it, expect } from 'vitest';
2-
import { createPublicClient, http, PublicClient } from 'viem';
2+
import { Address, createPublicClient, http, PublicClient } from 'viem';
33

44
import { nitroTestnodeL1 } from './chains';
5-
import { getInformationFromTestnode, getNitroTestnodePrivateKeyAccounts } from './testHelpers';
5+
import {
6+
getInformationFromTestnode,
7+
getNitroTestnodePrivateKeyAccounts,
8+
PrivateKeyAccountWithPrivateKey,
9+
} from './testHelpers';
610
import { upgradeExecutorPrepareAddExecutorTransactionRequest } from './upgradeExecutorPrepareAddExecutorTransactionRequest';
711
import { generatePrivateKey, privateKeyToAccount } from 'viem/accounts';
812
import { createRollupFetchTransactionHash } from './createRollupFetchTransactionHash';
913
import { createRollupPrepareTransactionReceipt } from './createRollupPrepareTransactionReceipt';
1014
import { upgradeExecutorFetchPrivilegedAccounts } from './upgradeExecutorFetchPrivilegedAccounts';
1115
import { UPGRADE_EXECUTOR_ROLE_EXECUTOR } from './upgradeExecutorEncodeFunctionData';
1216
import { upgradeExecutorPrepareRemoveExecutorTransactionRequest } from './upgradeExecutorPrepareRemoveExecutorTransactionRequest';
17+
import { isAnvilTestMode, getAnvilTestStack } from './integrationTestHelpers/injectedMode';
18+
19+
const env = isAnvilTestMode() ? getAnvilTestStack() : undefined;
1320

1421
// Generating random account
1522
const randomAccount = privateKeyToAccount(generatePrivateKey());
1623

17-
// Testnode accounts
18-
const testnodeAccounts = getNitroTestnodePrivateKeyAccounts();
19-
const l2RollupOwner = testnodeAccounts.l2RollupOwner;
24+
let l2RollupOwner: PrivateKeyAccountWithPrivateKey;
25+
26+
if (env) {
27+
l2RollupOwner = env.l2.accounts.rollupOwner;
28+
} else {
29+
const testnodeAccounts = getNitroTestnodePrivateKeyAccounts();
30+
l2RollupOwner = testnodeAccounts.l2RollupOwner;
31+
}
2032

21-
const nitroTestnodeL1Client = createPublicClient({
22-
chain: nitroTestnodeL1,
23-
transport: http(nitroTestnodeL1.rpcUrls.default.http[0]),
33+
const l1Client = createPublicClient({
34+
chain: env ? env.l1.chain : nitroTestnodeL1,
35+
transport: env ? http() : http(nitroTestnodeL1.rpcUrls.default.http[0]),
2436
});
2537

2638
async function getUpgradeExecutorOfRollup(rollup: `0x${string}`, publicClient: PublicClient) {
@@ -37,34 +49,37 @@ async function getUpgradeExecutorOfRollup(rollup: `0x${string}`, publicClient: P
3749

3850
describe('upgradeExecutor role management', () => {
3951
it(`successfully grants and revokes the executor role to a new account`, async () => {
40-
const testnodeInformation = getInformationFromTestnode();
41-
const upgradeExecutor = await getUpgradeExecutorOfRollup(
42-
testnodeInformation.rollup,
43-
nitroTestnodeL1Client,
44-
);
52+
let upgradeExecutor: Address;
53+
54+
if (env) {
55+
upgradeExecutor = env.l2.upgradeExecutor;
56+
} else {
57+
const testnodeInformation = getInformationFromTestnode();
58+
upgradeExecutor = await getUpgradeExecutorOfRollup(testnodeInformation.rollup, l1Client);
59+
}
4560

4661
// prepare the transaction to add the executor role
4762
const addExecutorTransactionRequest = await upgradeExecutorPrepareAddExecutorTransactionRequest(
4863
{
4964
account: randomAccount.address,
5065
upgradeExecutorAddress: upgradeExecutor,
5166
executorAccountAddress: l2RollupOwner.address,
52-
publicClient: nitroTestnodeL1Client,
67+
publicClient: l1Client,
5368
},
5469
);
5570

5671
// sign and send the transaction
57-
const addExecutorTransactionHash = await nitroTestnodeL1Client.sendRawTransaction({
72+
const addExecutorTransactionHash = await l1Client.sendRawTransaction({
5873
serializedTransaction: await l2RollupOwner.signTransaction(addExecutorTransactionRequest),
5974
});
6075

6176
// wait for transaction receipt
62-
await nitroTestnodeL1Client.waitForTransactionReceipt({ hash: addExecutorTransactionHash });
77+
await l1Client.waitForTransactionReceipt({ hash: addExecutorTransactionHash });
6378

6479
// verify that the account has been added to the list of privileged accounts
6580
const privilegedAccountsAfterAdding = await upgradeExecutorFetchPrivilegedAccounts({
6681
upgradeExecutorAddress: upgradeExecutor,
67-
publicClient: nitroTestnodeL1Client,
82+
publicClient: l1Client,
6883
});
6984
expect(privilegedAccountsAfterAdding).toHaveProperty(randomAccount.address);
7085
expect(privilegedAccountsAfterAdding[randomAccount.address]).toEqual([
@@ -77,21 +92,21 @@ describe('upgradeExecutor role management', () => {
7792
account: randomAccount.address,
7893
upgradeExecutorAddress: upgradeExecutor,
7994
executorAccountAddress: l2RollupOwner.address,
80-
publicClient: nitroTestnodeL1Client,
95+
publicClient: l1Client,
8196
});
8297

8398
// sign and send the transaction
84-
const removeExecutorTransactionHash = await nitroTestnodeL1Client.sendRawTransaction({
99+
const removeExecutorTransactionHash = await l1Client.sendRawTransaction({
85100
serializedTransaction: await l2RollupOwner.signTransaction(removeExecutorTransactionRequest),
86101
});
87102

88103
// wait for transaction receipt
89-
await nitroTestnodeL1Client.waitForTransactionReceipt({ hash: removeExecutorTransactionHash });
104+
await l1Client.waitForTransactionReceipt({ hash: removeExecutorTransactionHash });
90105

91106
// verify that the account has been removed from the list of privileged accounts
92107
const privilegedAccountsAfterRemoving = await upgradeExecutorFetchPrivilegedAccounts({
93108
upgradeExecutorAddress: upgradeExecutor,
94-
publicClient: nitroTestnodeL1Client,
109+
publicClient: l1Client,
95110
});
96111
expect(privilegedAccountsAfterRemoving).to.not.have.property(randomAccount.address);
97112
});

vitest.integration.anvil.config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ export default mergeConfig(
2323
'./src/getKeysets.integration.test.ts',
2424
'./src/decorators/rollupAdminLogicPublicActions.integration.test.ts',
2525
'./src/actions/sequencerInbox.integration.test.ts',
26+
'./src/decorators/arbOwnerPublicActions.integration.test.ts',
27+
'./src/upgradeExecutor.integration.test.ts',
2628
],
2729
fileParallelism: false,
2830
},

0 commit comments

Comments
 (0)