Skip to content

Commit 33b2738

Browse files
committed
test: Add RollupAdmin integration tests
1 parent a140b31 commit 33b2738

File tree

1 file changed

+229
-0
lines changed

1 file changed

+229
-0
lines changed
Lines changed: 229 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
1+
import { describe, it, expect } from 'vitest';
2+
import { getInformationFromTestnode, getNitroTestnodePrivateKeyAccounts } from '../testHelpers';
3+
import { Address, Hex, createPublicClient, http } from 'viem';
4+
import { constants } from 'ethers';
5+
import { nitroTestnodeL2 } from '../chains';
6+
import { generatePrivateKey, privateKeyToAccount } from 'viem/accounts';
7+
import { getConfirmPeriodBlocks } from './getConfirmPeriodBlocks';
8+
import { buildSetConfirmPeriodBlocks } from './buildSetConfirmPeriodBlocks';
9+
import { getWasmModuleRoot } from './getWasmModuleRoot';
10+
import { buildSetWasmModuleRoot } from './buildSetWasmModuleRoot';
11+
import { buildSetExtraChallengeTimeBlocks } from './buildSetExtraChallengeTimeBlocks';
12+
import { getExtraChallengeTimeBlocks } from './getExtraChallengeTimeBlocks';
13+
import { buildSetMinimumAssertionPeriod } from './buildSetMinimumAssertionPeriod';
14+
import { getMinimumAssertionPeriod } from './getMinimumAssertionPeriod';
15+
import { buildSetValidators } from './buildSetValidator';
16+
import { getValidators } from '../getValidators';
17+
import { rollupABI } from '../contracts/Rollup';
18+
import {
19+
buildDisableValidatorWhitelist,
20+
buildEnableValidatorWhitelist,
21+
} from './buildSetValidatorWhitelistDisabled';
22+
23+
const { l3Rollup, l3UpgradeExecutor } = getInformationFromTestnode();
24+
const { l3RollupOwner } = getNitroTestnodePrivateKeyAccounts();
25+
26+
const client = createPublicClient({
27+
chain: nitroTestnodeL2,
28+
transport: http(),
29+
});
30+
31+
describe('Confirm period blocks', () => {
32+
it('getConfirmPeriodBlocks and buildSetConfirmPeriodBlocks get and update confirm period blocks', async () => {
33+
async function changePeriodBlocks(newPeriod: bigint) {
34+
const transactionRequest = await buildSetConfirmPeriodBlocks(client, {
35+
rollupAdminLogic: l3Rollup,
36+
account: l3RollupOwner.address,
37+
upgradeExecutor: l3UpgradeExecutor,
38+
params: {
39+
newPeriod,
40+
},
41+
});
42+
const txHash = await client.sendRawTransaction({
43+
serializedTransaction: await l3RollupOwner.signTransaction(transactionRequest),
44+
});
45+
await client.waitForTransactionReceipt({ hash: txHash });
46+
}
47+
48+
expect(await getConfirmPeriodBlocks(client, { rollupAdminLogic: l3Rollup })).toEqual(20n);
49+
50+
await changePeriodBlocks(40n);
51+
expect(await getConfirmPeriodBlocks(client, { rollupAdminLogic: l3Rollup })).toEqual(40n);
52+
53+
await changePeriodBlocks(20n);
54+
expect(await getConfirmPeriodBlocks(client, { rollupAdminLogic: l3Rollup })).toEqual(20n);
55+
});
56+
57+
it('getExtraChallengeTimeBlocks and buildSetExtraChallengeTimeBlocks get and update extra challenge time blocks', async () => {
58+
async function changeExtraChallengeTimeBlocks(newExtraTimeBlocks: bigint) {
59+
const transactionRequest = await buildSetExtraChallengeTimeBlocks(client, {
60+
rollupAdminLogic: l3Rollup,
61+
account: l3RollupOwner.address,
62+
upgradeExecutor: l3UpgradeExecutor,
63+
params: {
64+
newExtraTimeBlocks,
65+
},
66+
});
67+
const txHash = await client.sendRawTransaction({
68+
serializedTransaction: await l3RollupOwner.signTransaction(transactionRequest),
69+
});
70+
await client.waitForTransactionReceipt({ hash: txHash });
71+
}
72+
73+
expect(await getExtraChallengeTimeBlocks(client, { rollupAdminLogic: l3Rollup })).toEqual(200n);
74+
75+
await changeExtraChallengeTimeBlocks(400n);
76+
expect(await getExtraChallengeTimeBlocks(client, { rollupAdminLogic: l3Rollup })).toEqual(400n);
77+
78+
await changeExtraChallengeTimeBlocks(200n);
79+
expect(await getExtraChallengeTimeBlocks(client, { rollupAdminLogic: l3Rollup })).toEqual(200n);
80+
});
81+
});
82+
83+
describe('WASM module root', () => {
84+
it('getWasmModuleRoot and buildSetWasmModuleRoot get and update confirm period blocks', async () => {
85+
async function changeWasmModuleRoot(newWasmModuleRoot: Hex) {
86+
const transactionRequest = await buildSetWasmModuleRoot(client, {
87+
rollupAdminLogic: l3Rollup,
88+
account: l3RollupOwner.address,
89+
upgradeExecutor: l3UpgradeExecutor,
90+
params: {
91+
newWasmModuleRoot,
92+
},
93+
});
94+
const txHash = await client.sendRawTransaction({
95+
serializedTransaction: await l3RollupOwner.signTransaction(transactionRequest),
96+
});
97+
await client.waitForTransactionReceipt({ hash: txHash });
98+
}
99+
const initialWasmModuleRoot = await getWasmModuleRoot(client, { rollupAdminLogic: l3Rollup });
100+
101+
await changeWasmModuleRoot(constants.HashZero);
102+
expect(await getWasmModuleRoot(client, { rollupAdminLogic: l3Rollup })).toEqual(
103+
constants.HashZero,
104+
);
105+
106+
await changeWasmModuleRoot(initialWasmModuleRoot);
107+
expect(await getWasmModuleRoot(client, { rollupAdminLogic: l3Rollup })).toEqual(
108+
initialWasmModuleRoot,
109+
);
110+
});
111+
});
112+
113+
describe('Minimum assertion period', () => {
114+
it('getMinimumAssertionPeriod and buildSetMinimumAssertionPeriod get and update minimum assertion period', async () => {
115+
async function changeMinimumAssertionPeriod(newPeriod: bigint) {
116+
const transactionRequest = await buildSetMinimumAssertionPeriod(client, {
117+
rollupAdminLogic: l3Rollup,
118+
account: l3RollupOwner.address,
119+
upgradeExecutor: l3UpgradeExecutor,
120+
params: {
121+
newPeriod,
122+
},
123+
});
124+
const txHash = await client.sendRawTransaction({
125+
serializedTransaction: await l3RollupOwner.signTransaction(transactionRequest),
126+
});
127+
await client.waitForTransactionReceipt({ hash: txHash });
128+
}
129+
130+
expect(await getMinimumAssertionPeriod(client, { rollupAdminLogic: l3Rollup })).toEqual(75n);
131+
132+
await changeMinimumAssertionPeriod(150n);
133+
expect(await getMinimumAssertionPeriod(client, { rollupAdminLogic: l3Rollup })).toEqual(150n);
134+
135+
await changeMinimumAssertionPeriod(75n);
136+
expect(await getMinimumAssertionPeriod(client, { rollupAdminLogic: l3Rollup })).toEqual(75n);
137+
});
138+
});
139+
140+
describe('Validators', () => {
141+
it('getValidators and buildSetValidators get and update validators', async () => {
142+
async function changeValidators({
143+
newValidators,
144+
deletedValidators,
145+
}: {
146+
newValidators: Address[];
147+
deletedValidators: Address[];
148+
}) {
149+
const transactionRequest = await buildSetValidators(client, {
150+
rollupAdminLogic: l3Rollup,
151+
account: l3RollupOwner.address,
152+
upgradeExecutor: l3UpgradeExecutor,
153+
params: {
154+
add: newValidators,
155+
remove: deletedValidators,
156+
},
157+
});
158+
const txHash = await client.sendRawTransaction({
159+
serializedTransaction: await l3RollupOwner.signTransaction(transactionRequest),
160+
});
161+
await client.waitForTransactionReceipt({ hash: txHash });
162+
}
163+
164+
const { validators: initialValidators } = await getValidators(client, { rollup: l3Rollup });
165+
expect(initialValidators).toEqual([
166+
'0x09a51aAcd25f79D7955d2060320Ca1A7dBbCf361',
167+
'0xB6b3A591C68422dFFeeB2beC93a5d7CF36a9E7ca',
168+
'0xb02B307C54Dc6f68885739DB101115b26cb5cD2C',
169+
'0xdB19208f4184dcA5f9C448C3ECafDAba5F0a4C07',
170+
'0x99e9FaE46fC914f875c180C618c2248b28077806',
171+
'0xD7Eb2ca8a71edbdFC8e694e0c95d255F48D4c8b1',
172+
'0x24E8cf09bDB46997E865cFFD3bbCC3aDB8D4CFBd',
173+
'0x5eB70c2B0603A7567CD0426FC04a2fCbAcc1AEd5',
174+
'0xFe079d3Ed5fdA9070423B409dE0bbaFe14C64147',
175+
'0x7c7535AC6268F06FCA544d0b5C584265055ED4eF',
176+
]);
177+
178+
const randomAddress = privateKeyToAccount(generatePrivateKey()).address;
179+
await changeValidators({
180+
newValidators: [randomAddress],
181+
deletedValidators: ['0x7c7535AC6268F06FCA544d0b5C584265055ED4eF'],
182+
});
183+
184+
expect((await getValidators(client, { rollup: l3Rollup })).validators).toEqual([
185+
...initialValidators.slice(0, -1),
186+
randomAddress,
187+
]);
188+
189+
await changeValidators({
190+
newValidators: ['0x7c7535ac6268f06fca544d0b5c584265055ed4ef'],
191+
deletedValidators: [randomAddress],
192+
});
193+
expect((await getValidators(client, { rollup: l3Rollup })).validators).toEqual(
194+
initialValidators,
195+
);
196+
});
197+
});
198+
199+
describe('Validators whitelist', () => {
200+
it('Enable and disable validators whitelist', async () => {
201+
function getValidatorWhitelist() {
202+
return client.readContract({
203+
address: l3Rollup,
204+
abi: rollupABI,
205+
functionName: 'validatorWhitelistDisabled',
206+
});
207+
}
208+
async function updateWhitelist(whitelist: boolean) {
209+
const fn = whitelist ? buildEnableValidatorWhitelist : buildDisableValidatorWhitelist;
210+
const transactionRequest = await fn(client, {
211+
rollupAdminLogic: l3Rollup,
212+
account: l3RollupOwner.address,
213+
upgradeExecutor: l3UpgradeExecutor,
214+
});
215+
const txHash = await client.sendRawTransaction({
216+
serializedTransaction: await l3RollupOwner.signTransaction(transactionRequest),
217+
});
218+
await client.waitForTransactionReceipt({ hash: txHash });
219+
}
220+
221+
expect(await getValidatorWhitelist()).toBeFalsy();
222+
223+
await updateWhitelist(true);
224+
expect(await getValidatorWhitelist()).toBeTruthy();
225+
226+
await updateWhitelist(false);
227+
expect(await getValidatorWhitelist()).toBeFalsy();
228+
});
229+
});

0 commit comments

Comments
 (0)