Skip to content

Commit cddcd28

Browse files
committed
test: update getKeysets, sequencerInbox and rollupAdminLogic tests to anvil
1 parent 6ea503d commit cddcd28

File tree

4 files changed

+161
-76
lines changed

4 files changed

+161
-76
lines changed

src/actions/sequencerInbox.integration.test.ts

Lines changed: 71 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ import {
33
createRollupHelper,
44
getInformationFromTestnode,
55
getNitroTestnodePrivateKeyAccounts,
6+
PrivateKeyAccountWithPrivateKey,
67
} from '../testHelpers';
7-
import { Hex, createPublicClient, http, zeroAddress } from 'viem';
8+
import { Address, Hex, createPublicClient, http, zeroAddress } from 'viem';
89
import { nitroTestnodeL2 } from '../chains';
910
import { getMaxTimeVariation } from './getMaxTimeVariation';
1011
import { isBatchPoster } from './isBatchPoster';
@@ -15,12 +16,46 @@ import { buildSetMaxTimeVariation } from './buildSetMaxTimeVariation';
1516
import { buildDisableBatchPoster, buildEnableBatchPoster } from './buildSetIsBatchPoster';
1617
import { generatePrivateKey, privateKeyToAccount } from 'viem/accounts';
1718
import { buildInvalidateKeysetHash } from './buildInvalidateKeysetHash';
19+
import { getAnvilTestStack, isAnvilTestMode } from '../integrationTestHelpers/injectedMode';
1820

19-
const { l3SequencerInbox, l3BatchPoster, l3UpgradeExecutor } = getInformationFromTestnode();
20-
const { l3TokenBridgeDeployer, deployer, l3RollupOwner } = getNitroTestnodePrivateKeyAccounts();
21+
// const { l3SequencerInbox, l3BatchPoster, l3UpgradeExecutor } = getInformationFromTestnode();
22+
// const { l3TokenBridgeDeployer, deployer, l3RollupOwner } = getNitroTestnodePrivateKeyAccounts();
2123

22-
const client = createPublicClient({
23-
chain: nitroTestnodeL2,
24+
// const client = createPublicClient({
25+
// chain: nitroTestnodeL2,
26+
// transport: http(),
27+
// });
28+
29+
const env = isAnvilTestMode() ? getAnvilTestStack() : undefined;
30+
31+
let l3RollupOwner: PrivateKeyAccountWithPrivateKey;
32+
let l3TokenBridgeDeployer: PrivateKeyAccountWithPrivateKey;
33+
let deployer: PrivateKeyAccountWithPrivateKey;
34+
let l3SequencerInbox: Address;
35+
let l3BatchPoster: Address;
36+
let l3UpgradeExecutor: Address;
37+
38+
if (env) {
39+
l3RollupOwner = env.l3.accounts.rollupOwner;
40+
l3TokenBridgeDeployer = env.l3.accounts.tokenBridgeDeployer;
41+
deployer = env.l2.accounts.deployer;
42+
l3SequencerInbox = env.l3.sequencerInbox;
43+
l3BatchPoster = env.l3.batchPoster;
44+
l3UpgradeExecutor = env.l3.upgradeExecutor;
45+
} else {
46+
const testnodeAccounts = getNitroTestnodePrivateKeyAccounts();
47+
l3RollupOwner = testnodeAccounts.l3RollupOwner;
48+
l3TokenBridgeDeployer = testnodeAccounts.l3TokenBridgeDeployer;
49+
deployer = testnodeAccounts.deployer;
50+
51+
const testNodeInformation = getInformationFromTestnode();
52+
l3SequencerInbox = testNodeInformation.l3SequencerInbox;
53+
l3BatchPoster = testNodeInformation.l3BatchPoster;
54+
l3UpgradeExecutor = testNodeInformation.l3UpgradeExecutor;
55+
}
56+
57+
const l2Client = createPublicClient({
58+
chain: env ? env.l2.chain : nitroTestnodeL2,
2459
transport: http(),
2560
});
2661

@@ -32,7 +67,7 @@ describe('max time variation management', () => {
3267
futureSeconds: 3_600n,
3368
};
3469
it('getMaxTimeVariation successfully fetches max time variation', async () => {
35-
const result = await getMaxTimeVariation(client, {
70+
const result = await getMaxTimeVariation(l2Client, {
3671
sequencerInbox: l3SequencerInbox,
3772
});
3873
expect(result).toEqual(defaultMaxTimeVariation);
@@ -45,17 +80,17 @@ describe('max time variation management', () => {
4580
delaySeconds: bigint;
4681
futureSeconds: bigint;
4782
}) {
48-
const transactionRequest = await buildSetMaxTimeVariation(client, {
83+
const transactionRequest = await buildSetMaxTimeVariation(l2Client, {
4984
sequencerInbox: l3SequencerInbox,
5085
upgradeExecutor: l3UpgradeExecutor,
5186
account: l3RollupOwner.address,
5287
params: changes,
5388
});
54-
const txHash = await client.sendRawTransaction({
89+
const txHash = await l2Client.sendRawTransaction({
5590
serializedTransaction: await l3RollupOwner.signTransaction(transactionRequest),
5691
});
5792

58-
await client.waitForTransactionReceipt({ hash: txHash });
93+
await l2Client.waitForTransactionReceipt({ hash: txHash });
5994
}
6095

6196
const changes = {
@@ -65,13 +100,13 @@ describe('max time variation management', () => {
65100
futureSeconds: 1_800n,
66101
};
67102
await setMaxTimeVariation(changes);
68-
const newResult = await getMaxTimeVariation(client, {
103+
const newResult = await getMaxTimeVariation(l2Client, {
69104
sequencerInbox: l3SequencerInbox,
70105
});
71106
expect(newResult).toEqual(changes);
72107

73108
await setMaxTimeVariation(defaultMaxTimeVariation);
74-
const finalResult = await getMaxTimeVariation(client, {
109+
const finalResult = await getMaxTimeVariation(l2Client, {
75110
sequencerInbox: l3SequencerInbox,
76111
});
77112
expect(finalResult).toEqual(defaultMaxTimeVariation);
@@ -80,14 +115,14 @@ describe('max time variation management', () => {
80115

81116
describe('batch poster management', () => {
82117
it('isBatchPoster successfully fetches whether or an address is a batch poster', async () => {
83-
const isNotBatchPosterAddress = await isBatchPoster(client, {
118+
const isNotBatchPosterAddress = await isBatchPoster(l2Client, {
84119
sequencerInbox: l3SequencerInbox,
85120
params: {
86121
batchPoster: zeroAddress,
87122
},
88123
});
89124
expect(isNotBatchPosterAddress).toBeFalsy();
90-
const isBatchPosterAddress = await isBatchPoster(client, {
125+
const isBatchPosterAddress = await isBatchPoster(l2Client, {
91126
sequencerInbox: l3SequencerInbox,
92127
params: {
93128
batchPoster: l3BatchPoster,
@@ -98,47 +133,47 @@ describe('batch poster management', () => {
98133

99134
it('successfully enable or disable an address as batch poster', async () => {
100135
const randomAddress = privateKeyToAccount(generatePrivateKey()).address;
101-
const isRandomAddressBatchPoster = await isBatchPoster(client, {
136+
const isRandomAddressBatchPoster = await isBatchPoster(l2Client, {
102137
sequencerInbox: l3SequencerInbox,
103138
params: {
104139
batchPoster: randomAddress,
105140
},
106141
});
107142
expect(isRandomAddressBatchPoster).toBeFalsy();
108143

109-
const enableTransactionRequest = await buildEnableBatchPoster(client, {
144+
const enableTransactionRequest = await buildEnableBatchPoster(l2Client, {
110145
sequencerInbox: l3SequencerInbox,
111146
upgradeExecutor: l3UpgradeExecutor,
112147
account: l3RollupOwner.address,
113148
params: {
114149
batchPoster: randomAddress,
115150
},
116151
});
117-
const enableTxHash = await client.sendRawTransaction({
152+
const enableTxHash = await l2Client.sendRawTransaction({
118153
serializedTransaction: await l3RollupOwner.signTransaction(enableTransactionRequest),
119154
});
120-
await client.waitForTransactionReceipt({ hash: enableTxHash });
121-
const isRandomAddressBatchPosterAfterEnabling = await isBatchPoster(client, {
155+
await l2Client.waitForTransactionReceipt({ hash: enableTxHash });
156+
const isRandomAddressBatchPosterAfterEnabling = await isBatchPoster(l2Client, {
122157
sequencerInbox: l3SequencerInbox,
123158
params: {
124159
batchPoster: randomAddress,
125160
},
126161
});
127162
expect(isRandomAddressBatchPosterAfterEnabling).toBeTruthy();
128163

129-
const disableTransactionRequest = await buildDisableBatchPoster(client, {
164+
const disableTransactionRequest = await buildDisableBatchPoster(l2Client, {
130165
sequencerInbox: l3SequencerInbox,
131166
upgradeExecutor: l3UpgradeExecutor,
132167
account: l3RollupOwner.address,
133168
params: {
134169
batchPoster: randomAddress,
135170
},
136171
});
137-
const disableTxHash = await client.sendRawTransaction({
172+
const disableTxHash = await l2Client.sendRawTransaction({
138173
serializedTransaction: await l3RollupOwner.signTransaction(disableTransactionRequest),
139174
});
140-
await client.waitForTransactionReceipt({ hash: disableTxHash });
141-
const isRandomAddressBatchPosterAfterDisabling = await isBatchPoster(client, {
175+
await l2Client.waitForTransactionReceipt({ hash: disableTxHash });
176+
const isRandomAddressBatchPosterAfterDisabling = await isBatchPoster(l2Client, {
142177
sequencerInbox: l3SequencerInbox,
143178
params: {
144179
batchPoster: randomAddress,
@@ -160,23 +195,25 @@ describe('keyset management', () => {
160195
batchPosters,
161196
validators,
162197
nativeToken: zeroAddress,
163-
client,
198+
client: l2Client,
199+
customParentTimingParams: env ? env.l2.timingParams : undefined,
200+
maxDataSize: env ? 104_857n : undefined,
164201
});
165202

166203
const { sequencerInbox, upgradeExecutor } = createRollupInformation.coreContracts;
167-
const transactionRequest = await buildSetValidKeyset(client, {
204+
const transactionRequest = await buildSetValidKeyset(l2Client, {
168205
sequencerInbox: sequencerInbox,
169206
account: l3TokenBridgeDeployer.address,
170207
upgradeExecutor,
171208
params: {
172209
keyset,
173210
},
174211
});
175-
const transactionHash = await client.sendRawTransaction({
212+
const transactionHash = await l2Client.sendRawTransaction({
176213
serializedTransaction: await l3TokenBridgeDeployer.signTransaction(transactionRequest),
177214
});
178-
await client.waitForTransactionReceipt({ hash: transactionHash });
179-
const logs = await client.getContractEvents({
215+
await l2Client.waitForTransactionReceipt({ hash: transactionHash });
216+
const logs = await l2Client.getContractEvents({
180217
address: sequencerInbox,
181218
abi: sequencerInboxABI,
182219
eventName: 'SetValidKeyset',
@@ -192,7 +229,7 @@ describe('keyset management', () => {
192229
}
193230

194231
it('isValidKeysetHash successfully fetches whether a hash is a valid keyset hash', async () => {
195-
const invalidKeysetHash = await isValidKeysetHash(client, {
232+
const invalidKeysetHash = await isValidKeysetHash(l2Client, {
196233
sequencerInbox: l3SequencerInbox,
197234
params: {
198235
keysetHash: '0x0000000000000000000000000000000000000000000000000000000000000000',
@@ -202,7 +239,7 @@ describe('keyset management', () => {
202239

203240
const { sequencerInbox, keysetHash } = await deployAnyTrustChainWithKeyset(keysetBytes);
204241

205-
const result = await isValidKeysetHash(client, {
242+
const result = await isValidKeysetHash(l2Client, {
206243
sequencerInbox,
207244
params: {
208245
keysetHash: keysetHash!,
@@ -216,28 +253,28 @@ describe('keyset management', () => {
216253
keysetBytes,
217254
);
218255

219-
const result = await isValidKeysetHash(client, {
256+
const result = await isValidKeysetHash(l2Client, {
220257
sequencerInbox,
221258
params: {
222259
keysetHash: keysetHash!,
223260
},
224261
});
225262
expect(result).toBeTruthy();
226263

227-
const transactionRequest = await buildInvalidateKeysetHash(client, {
264+
const transactionRequest = await buildInvalidateKeysetHash(l2Client, {
228265
sequencerInbox,
229266
account: l3TokenBridgeDeployer.address,
230267
upgradeExecutor,
231268
params: {
232269
keysetHash: keysetHash!,
233270
},
234271
});
235-
const txHash = await client.sendRawTransaction({
272+
const txHash = await l2Client.sendRawTransaction({
236273
serializedTransaction: await l3TokenBridgeDeployer.signTransaction(transactionRequest),
237274
});
238-
await client.waitForTransactionReceipt({ hash: txHash });
275+
await l2Client.waitForTransactionReceipt({ hash: txHash });
239276

240-
const resultAfterChange = await isValidKeysetHash(client, {
277+
const resultAfterChange = await isValidKeysetHash(l2Client, {
241278
sequencerInbox,
242279
params: {
243280
keysetHash: keysetHash!,

0 commit comments

Comments
 (0)