Skip to content

Commit 1fb0fbb

Browse files
committed
test: Add upgradeExecutor integration tests
1 parent 0b9f6cf commit 1fb0fbb

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
import { describe, it, expect } from 'vitest';
2+
import { getInformationFromTestnode, getNitroTestnodePrivateKeyAccounts } from '../testHelpers';
3+
import { Address, createPublicClient, http } from 'viem';
4+
import { nitroTestnodeL2 } from '../chains';
5+
import { generatePrivateKey, privateKeyToAccount } from 'viem/accounts';
6+
import { upgradeExecutorFetchPrivilegedAccounts } from '../upgradeExecutorFetchPrivilegedAccounts';
7+
import { buildAddExecutor } from './buildAddExecutor';
8+
import { UPGRADE_EXECUTOR_ROLE_EXECUTOR } from '../upgradeExecutorEncodeFunctionData';
9+
import { buildRemoveExecutor } from './buildRemoveExecutor';
10+
import { hasRole } from './hasRole';
11+
12+
const { l3UpgradeExecutor } = getInformationFromTestnode();
13+
const { l3RollupOwner } = getNitroTestnodePrivateKeyAccounts();
14+
15+
const client = createPublicClient({
16+
chain: nitroTestnodeL2,
17+
transport: http(),
18+
});
19+
20+
describe('Upgrade executor', () => {
21+
it('buildAddExecutor and buildRemoveExecutor update upgradeExecutor', async () => {
22+
async function changeUpgradeExecutor(address: Address, add: boolean) {
23+
const fn = add ? buildAddExecutor : buildRemoveExecutor;
24+
const transactionRequest = await fn(client, {
25+
account: l3RollupOwner.address,
26+
upgradeExecutor: l3UpgradeExecutor,
27+
params: {
28+
address,
29+
},
30+
});
31+
const txHash = await client.sendRawTransaction({
32+
serializedTransaction: await l3RollupOwner.signTransaction(transactionRequest),
33+
});
34+
await client.waitForTransactionReceipt({ hash: txHash });
35+
}
36+
const addUpgradeExecutor = (address: Address) => changeUpgradeExecutor(address, true);
37+
const removeUpgradeExecutor = (address: Address) => changeUpgradeExecutor(address, false);
38+
39+
const randomAddress = privateKeyToAccount(generatePrivateKey()).address;
40+
41+
const initialState = await upgradeExecutorFetchPrivilegedAccounts({
42+
upgradeExecutorAddress: l3UpgradeExecutor,
43+
publicClient: client,
44+
});
45+
46+
expect(
47+
await hasRole(client, {
48+
params: {
49+
role: UPGRADE_EXECUTOR_ROLE_EXECUTOR,
50+
address: randomAddress,
51+
},
52+
upgradeExecutor: l3UpgradeExecutor,
53+
}),
54+
).toBeFalsy();
55+
56+
await addUpgradeExecutor(randomAddress);
57+
expect(
58+
await upgradeExecutorFetchPrivilegedAccounts({
59+
upgradeExecutorAddress: l3UpgradeExecutor,
60+
publicClient: client,
61+
}),
62+
).toEqual({
63+
...initialState,
64+
[randomAddress]: [UPGRADE_EXECUTOR_ROLE_EXECUTOR],
65+
});
66+
expect(
67+
await hasRole(client, {
68+
params: {
69+
role: UPGRADE_EXECUTOR_ROLE_EXECUTOR,
70+
address: randomAddress,
71+
},
72+
upgradeExecutor: l3UpgradeExecutor,
73+
}),
74+
).toBeTruthy();
75+
76+
await removeUpgradeExecutor(randomAddress);
77+
expect(
78+
await upgradeExecutorFetchPrivilegedAccounts({
79+
upgradeExecutorAddress: l3UpgradeExecutor,
80+
publicClient: client,
81+
}),
82+
).toEqual(initialState);
83+
expect(
84+
await hasRole(client, {
85+
params: {
86+
role: UPGRADE_EXECUTOR_ROLE_EXECUTOR,
87+
address: randomAddress,
88+
},
89+
upgradeExecutor: l3UpgradeExecutor,
90+
}),
91+
).toBeFalsy();
92+
});
93+
});

0 commit comments

Comments
 (0)