11import { describe , it , expect } from 'vitest' ;
2- import { createPublicClient , http , zeroAddress } from 'viem' ;
2+ import { Address , createPublicClient , http , zeroAddress } from 'viem' ;
33import { generatePrivateKey , privateKeyToAccount } from 'viem/accounts' ;
44
55import { nitroTestnodeL2 } from '../chains' ;
66import {
77 getNitroTestnodePrivateKeyAccounts ,
8- getInformationFromTestnode ,
98 createRollupHelper ,
9+ PrivateKeyAccountWithPrivateKey ,
10+ getInformationFromTestnode ,
1011} from '../testHelpers' ;
1112import { sequencerInboxActions } from './sequencerInboxActions' ;
1213import { sequencerInboxABI } from '../contracts/SequencerInbox' ;
14+ import { getAnvilTestStack , isAnvilTestMode } from '../integrationTestHelpers/injectedMode' ;
1315
14- const { l3RollupOwner , l3TokenBridgeDeployer , deployer } = getNitroTestnodePrivateKeyAccounts ( ) ;
16+ const env = isAnvilTestMode ( ) ? getAnvilTestStack ( ) : undefined ;
1517
1618const randomAccount = privateKeyToAccount ( generatePrivateKey ( ) ) ;
1719
18- const { l3SequencerInbox, l3Bridge, l3Rollup, l3BatchPoster, l3UpgradeExecutor } =
19- getInformationFromTestnode ( ) ;
20-
21- const client = createPublicClient ( {
22- chain : nitroTestnodeL2 ,
20+ let l3RollupOwner : PrivateKeyAccountWithPrivateKey ;
21+ let l3TokenBridgeDeployer : PrivateKeyAccountWithPrivateKey ;
22+ let deployer : PrivateKeyAccountWithPrivateKey ;
23+ let l3SequencerInbox : Address ;
24+ let l3Bridge : Address ;
25+ let l3Rollup : Address ;
26+ let l3BatchPoster : Address ;
27+ let l3UpgradeExecutor : Address ;
28+
29+ if ( env ) {
30+ l3RollupOwner = env . l3 . accounts . rollupOwner ;
31+ l3TokenBridgeDeployer = env . l3 . accounts . tokenBridgeDeployer ;
32+ deployer = env . l2 . accounts . deployer ;
33+ l3SequencerInbox = env . l3 . sequencerInbox ;
34+ l3Bridge = env . l3 . bridge ;
35+ l3Rollup = env . l3 . rollup ;
36+ l3BatchPoster = env . l3 . batchPoster ;
37+ l3UpgradeExecutor = env . l3 . upgradeExecutor ;
38+ } else {
39+ const testnodeAccounts = getNitroTestnodePrivateKeyAccounts ( ) ;
40+ l3RollupOwner = testnodeAccounts . l3RollupOwner ;
41+ l3TokenBridgeDeployer = testnodeAccounts . l3TokenBridgeDeployer ;
42+ deployer = testnodeAccounts . deployer ;
43+
44+ const testNodeInformation = getInformationFromTestnode ( ) ;
45+ l3SequencerInbox = testNodeInformation . l3SequencerInbox ;
46+ l3Bridge = testNodeInformation . l3Bridge ;
47+ l3Rollup = testNodeInformation . l3Rollup ;
48+ l3BatchPoster = testNodeInformation . l3BatchPoster ;
49+ l3UpgradeExecutor = testNodeInformation . l3UpgradeExecutor ;
50+ }
51+
52+ const l2Client = createPublicClient ( {
53+ chain : env ? env . l2 . chain : nitroTestnodeL2 ,
2354 transport : http ( ) ,
2455} ) . extend ( sequencerInboxActions ( { sequencerInbox : l3SequencerInbox } ) ) ;
2556
2657describe ( 'sequencerInboxReadContract' , ( ) => {
2758 it ( 'successfully fetches batchCount' , async ( ) => {
28- const batchCount = await client . sequencerInboxReadContract ( {
59+ const batchCount = await l2Client . sequencerInboxReadContract ( {
2960 functionName : 'batchCount' ,
3061 } ) ;
3162 expect ( Number ( batchCount ) ) . greaterThan ( 0 ) ;
3263 } ) ;
3364
3465 it ( 'successfully fetches bridge' , async ( ) => {
35- const result = await client . sequencerInboxReadContract ( {
66+ const result = await l2Client . sequencerInboxReadContract ( {
3667 functionName : 'bridge' ,
3768 sequencerInbox : l3SequencerInbox ,
3869 } ) ;
@@ -41,7 +72,7 @@ describe('sequencerInboxReadContract', () => {
4172 } ) ;
4273
4374 it ( 'successfully fetches dasKeySetInfo' , async ( ) => {
44- const [ isValidKeyset , creationBlock ] = await client . sequencerInboxReadContract ( {
75+ const [ isValidKeyset , creationBlock ] = await l2Client . sequencerInboxReadContract ( {
4576 functionName : 'dasKeySetInfo' ,
4677 sequencerInbox : l3SequencerInbox ,
4778 args : [ '0x0000000000000000000000000000000000000000000000000000000000000000' ] ,
@@ -52,7 +83,7 @@ describe('sequencerInboxReadContract', () => {
5283 } ) ;
5384
5485 it ( 'successfully call inboxAccs' , async ( ) => {
55- const result = await client . sequencerInboxReadContract ( {
86+ const result = await l2Client . sequencerInboxReadContract ( {
5687 functionName : 'inboxAccs' ,
5788 sequencerInbox : l3SequencerInbox ,
5889 args : [ 0n ] ,
@@ -62,12 +93,12 @@ describe('sequencerInboxReadContract', () => {
6293 } ) ;
6394
6495 it ( 'successfully call isBatchPoster' , async ( ) => {
65- const result = await client . sequencerInboxReadContract ( {
96+ const result = await l2Client . sequencerInboxReadContract ( {
6697 functionName : 'isBatchPoster' ,
6798 sequencerInbox : l3SequencerInbox ,
6899 args : [ randomAccount . address ] ,
69100 } ) ;
70- const resultWithBatchPoster = await client . sequencerInboxReadContract ( {
101+ const resultWithBatchPoster = await l2Client . sequencerInboxReadContract ( {
71102 functionName : 'isBatchPoster' ,
72103 sequencerInbox : l3SequencerInbox ,
73104 args : [ l3BatchPoster ] ,
@@ -78,7 +109,7 @@ describe('sequencerInboxReadContract', () => {
78109 } ) ;
79110
80111 it ( 'successfully call isValidKeysetHash' , async ( ) => {
81- const result = await client . sequencerInboxReadContract ( {
112+ const result = await l2Client . sequencerInboxReadContract ( {
82113 functionName : 'isValidKeysetHash' ,
83114 sequencerInbox : l3SequencerInbox ,
84115 args : [ '0x0000000000000000000000000000000000000000000000000000000000000000' ] ,
@@ -88,7 +119,7 @@ describe('sequencerInboxReadContract', () => {
88119 } ) ;
89120
90121 it ( 'successfully call maxTimeVariation' , async ( ) => {
91- const result = await client . sequencerInboxReadContract ( {
122+ const result = await l2Client . sequencerInboxReadContract ( {
92123 functionName : 'maxTimeVariation' ,
93124 sequencerInbox : l3SequencerInbox ,
94125 } ) ;
@@ -97,7 +128,7 @@ describe('sequencerInboxReadContract', () => {
97128 } ) ;
98129
99130 it ( 'successfully call rollup' , async ( ) => {
100- const result = await client . sequencerInboxReadContract ( {
131+ const result = await l2Client . sequencerInboxReadContract ( {
101132 functionName : 'rollup' ,
102133 sequencerInbox : l3SequencerInbox ,
103134 } ) ;
@@ -106,7 +137,7 @@ describe('sequencerInboxReadContract', () => {
106137 } ) ;
107138
108139 it ( 'successfully call totalDelayedMessagesRead' , async ( ) => {
109- const result = await client . sequencerInboxReadContract ( {
140+ const result = await l2Client . sequencerInboxReadContract ( {
110141 functionName : 'totalDelayedMessagesRead' ,
111142 sequencerInbox : l3SequencerInbox ,
112143 } ) ;
@@ -126,33 +157,35 @@ describe('sequencerInboxPrepareTransactionRequest', () => {
126157 batchPosters,
127158 validators,
128159 nativeToken : zeroAddress ,
129- client,
160+ client : l2Client ,
161+ customParentTimingParams : env ? env . l2 . timingParams : undefined ,
162+ maxDataSize : env ? 104_857n : undefined ,
130163 } ) ;
131164
132165 const { sequencerInbox, upgradeExecutor } = createRollupInformation . coreContracts ;
133166
134167 const keyset =
135168 '0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000002560000000000000002000000000000000201216006dcb5e56764bb72e6a45e6deb301ca85d8c4315c1da2efa29927f2ac8fb25571ce31d2d603735fe03196f6d56bcbf9a1999a89a74d5369822c4445d676c15ed52e5008daa775dc9a839c99ff963a19946ac740579874dac4f639907ae1bc69f0c6694955b524d718ca445831c5375393773401f33725a79661379dddabd5fff28619dc070befd9ed73d699e5c236c1a163be58ba81002b6130709bc064af5d7ba947130b72056bf17263800f1a3ab2269c6a510ef8e7412fd56d1ef1b916a1306e3b1d9c82c099371bd9861582acaada3a16e9dfee5d0ebce61096598a82f112d0a935e8cab5c48d82e3104b0c7ba79157dad1a019a3e7f6ad077b8e6308b116fec0f58239622463c3631fa01e2b4272409215b8009422c16715dbede5909060121600835f995f2478f24892d050daa289f8b6b9c1b185bcd28532f88d610c2642a2dc6f3509740236d33c3e2d9136aab17f819c8c671293bba277717762e8d1c1f7bac9e17dd28d2939a959bb38e500f9c11c38cebbc426e2dea97c40175a655d17400ae6c75ff49e884c79469249e70953258854b64fa8445c585ad45dc6dc6975501c6af7cff7074202c687f8a7bf1a3ac192689755f232275b4c8421b1a5669e9b904c29a292cdf961b783a7c0b4ce736900de4d8c63c5f85a65cb44af34bef840acef84ab75f44c4c9137610b68107aff3bbdcc19119c7a927c115b7b9bfb27d85c500ee77d13ec5a97a3ae6bf51d3b70a5502e8416de7b5eb8e9feee376411ca35c8a7f3f597c7606578cf96a4715ce5a35cf48e39c0a1faa2dee22d74e681900000000000000000000' ;
136- const transactionRequest = await client . sequencerInboxPrepareTransactionRequest ( {
169+ const transactionRequest = await l2Client . sequencerInboxPrepareTransactionRequest ( {
137170 functionName : 'setValidKeyset' ,
138171 sequencerInbox : sequencerInbox ,
139172 args : [ keyset ] ,
140173 account : l3TokenBridgeDeployer . address ,
141174 upgradeExecutor : upgradeExecutor ,
142175 } ) ;
143- const transactionHash = await client . sendRawTransaction ( {
176+ const transactionHash = await l2Client . sendRawTransaction ( {
144177 serializedTransaction : await l3TokenBridgeDeployer . signTransaction ( transactionRequest ) ,
145178 } ) ;
146179
147- await client . waitForTransactionReceipt ( { hash : transactionHash } ) ;
148- const logs = await client . getContractEvents ( {
180+ await l2Client . waitForTransactionReceipt ( { hash : transactionHash } ) ;
181+ const logs = await l2Client . getContractEvents ( {
149182 address : sequencerInbox ,
150183 abi : sequencerInboxABI ,
151184 eventName : 'SetValidKeyset' ,
152185 } ) ;
153186 const keysetHash = logs [ 0 ] . args . keysetHash ;
154187
155- const result = await client . sequencerInboxReadContract ( {
188+ const result = await l2Client . sequencerInboxReadContract ( {
156189 functionName : 'isValidKeysetHash' ,
157190 sequencerInbox,
158191 args : [ keysetHash ! ] ,
@@ -162,49 +195,49 @@ describe('sequencerInboxPrepareTransactionRequest', () => {
162195 } ) ;
163196
164197 it ( 'successfully call setIsBatchPoster' , async ( ) => {
165- const resultBefore = await client . sequencerInboxReadContract ( {
198+ const resultBefore = await l2Client . sequencerInboxReadContract ( {
166199 functionName : 'isBatchPoster' ,
167200 sequencerInbox : l3SequencerInbox ,
168201 args : [ randomAccount . address ] ,
169202 } ) ;
170203 expect ( resultBefore ) . toEqual ( false ) ;
171204
172- const transactionRequest = await client . sequencerInboxPrepareTransactionRequest ( {
205+ const transactionRequest = await l2Client . sequencerInboxPrepareTransactionRequest ( {
173206 functionName : 'setIsBatchPoster' ,
174207 sequencerInbox : l3SequencerInbox ,
175208 args : [ randomAccount . address , true ] ,
176209 account : l3RollupOwner . address ,
177210 upgradeExecutor : l3UpgradeExecutor ,
178211 } ) ;
179212
180- const txHash = await client . sendRawTransaction ( {
213+ const txHash = await l2Client . sendRawTransaction ( {
181214 serializedTransaction : await l3RollupOwner . signTransaction ( transactionRequest ) ,
182215 } ) ;
183216
184- await client . waitForTransactionReceipt ( { hash : txHash } ) ;
217+ await l2Client . waitForTransactionReceipt ( { hash : txHash } ) ;
185218
186- const result = await client . sequencerInboxReadContract ( {
219+ const result = await l2Client . sequencerInboxReadContract ( {
187220 functionName : 'isBatchPoster' ,
188221 sequencerInbox : l3SequencerInbox ,
189222 args : [ randomAccount . address ] ,
190223 } ) ;
191224 expect ( result ) . toEqual ( true ) ;
192225
193226 // Revert the change and assert
194- const revertTransactionRequest = await client . sequencerInboxPrepareTransactionRequest ( {
227+ const revertTransactionRequest = await l2Client . sequencerInboxPrepareTransactionRequest ( {
195228 functionName : 'setIsBatchPoster' ,
196229 sequencerInbox : l3SequencerInbox ,
197230 args : [ randomAccount . address , false ] ,
198231 account : l3RollupOwner . address ,
199232 upgradeExecutor : l3UpgradeExecutor ,
200233 } ) ;
201- const revertTxHash = await client . sendRawTransaction ( {
234+ const revertTxHash = await l2Client . sendRawTransaction ( {
202235 serializedTransaction : await l3RollupOwner . signTransaction ( revertTransactionRequest ) ,
203236 } ) ;
204237
205- await client . waitForTransactionReceipt ( { hash : revertTxHash } ) ;
238+ await l2Client . waitForTransactionReceipt ( { hash : revertTxHash } ) ;
206239
207- const resultAfterReverting = await client . sequencerInboxReadContract ( {
240+ const resultAfterReverting = await l2Client . sequencerInboxReadContract ( {
208241 functionName : 'isBatchPoster' ,
209242 sequencerInbox : l3SequencerInbox ,
210243 args : [ randomAccount . address ] ,
@@ -213,12 +246,12 @@ describe('sequencerInboxPrepareTransactionRequest', () => {
213246 } ) ;
214247
215248 it ( 'successfully call setMaxTimeVariation' , async ( ) => {
216- const resultBefore = await client . sequencerInboxReadContract ( {
249+ const resultBefore = await l2Client . sequencerInboxReadContract ( {
217250 functionName : 'maxTimeVariation' ,
218251 sequencerInbox : l3SequencerInbox ,
219252 } ) ;
220253
221- const transactionRequest = await client . sequencerInboxPrepareTransactionRequest ( {
254+ const transactionRequest = await l2Client . sequencerInboxPrepareTransactionRequest ( {
222255 functionName : 'setMaxTimeVariation' ,
223256 sequencerInbox : l3SequencerInbox ,
224257 upgradeExecutor : l3UpgradeExecutor ,
@@ -232,20 +265,20 @@ describe('sequencerInboxPrepareTransactionRequest', () => {
232265 ] ,
233266 account : l3RollupOwner . address ,
234267 } ) ;
235- const txHash = await client . sendRawTransaction ( {
268+ const txHash = await l2Client . sendRawTransaction ( {
236269 serializedTransaction : await l3RollupOwner . signTransaction ( transactionRequest ) ,
237270 } ) ;
238271
239- await client . waitForTransactionReceipt ( { hash : txHash } ) ;
272+ await l2Client . waitForTransactionReceipt ( { hash : txHash } ) ;
240273
241- const result = await client . sequencerInboxReadContract ( {
274+ const result = await l2Client . sequencerInboxReadContract ( {
242275 functionName : 'maxTimeVariation' ,
243276 sequencerInbox : l3SequencerInbox ,
244277 } ) ;
245278 expect ( result ) . toEqual ( [ 2_880n , 6n , 43_200n , 1_800n ] ) ;
246279
247280 // Revert the change, so read test still work
248- const transactionRequestRevert = await client . sequencerInboxPrepareTransactionRequest ( {
281+ const transactionRequestRevert = await l2Client . sequencerInboxPrepareTransactionRequest ( {
249282 functionName : 'setMaxTimeVariation' ,
250283 sequencerInbox : l3SequencerInbox ,
251284 upgradeExecutor : l3UpgradeExecutor ,
@@ -259,10 +292,10 @@ describe('sequencerInboxPrepareTransactionRequest', () => {
259292 ] ,
260293 account : l3RollupOwner . address ,
261294 } ) ;
262- const revertTxHash = await client . sendRawTransaction ( {
295+ const revertTxHash = await l2Client . sendRawTransaction ( {
263296 serializedTransaction : await l3RollupOwner . signTransaction ( transactionRequestRevert ) ,
264297 } ) ;
265298
266- await client . waitForTransactionReceipt ( { hash : revertTxHash } ) ;
299+ await l2Client . waitForTransactionReceipt ( { hash : revertTxHash } ) ;
267300 } ) ;
268301} ) ;
0 commit comments