@@ -7,21 +7,38 @@ import { rollupAdminLogicPublicActions } from './decorators/rollupAdminLogicPubl
77import {
88 getInformationFromTestnode ,
99 getNitroTestnodePrivateKeyAccounts ,
10+ PrivateKeyAccountWithPrivateKey ,
1011 testHelper_getRollupCreatorVersionFromEnv ,
1112} from './testHelpers' ;
1213import { getValidators } from './getValidators' ;
14+ import { getAnvilTestStack , isAnvilTestMode } from './integrationTestHelpers/injectedMode' ;
1315
14- const { l3RollupOwner } = getNitroTestnodePrivateKeyAccounts ( ) ;
15- const { l3Rollup, l3UpgradeExecutor } = getInformationFromTestnode ( ) ;
16+ const env = isAnvilTestMode ( ) ? getAnvilTestStack ( ) : undefined ;
1617
1718const rollupCreatorVersion = testHelper_getRollupCreatorVersionFromEnv ( ) ;
1819// https://github.com/OffchainLabs/nitro-testnode/blob/release/test-node.bash#L634
1920// https://github.com/OffchainLabs/nitro-contracts/blob/v3.2.0/scripts/rollupCreation.ts#L254-L261
2021// https://github.com/OffchainLabs/nitro-contracts/blob/v2.1.3/scripts/rollupCreation.ts#L237-L243
2122const expectedInitialValidators = rollupCreatorVersion === 'v3.2' ? 11 : 10 ;
2223
23- const client = createPublicClient ( {
24- chain : nitroTestnodeL2 ,
24+ let l3RollupOwner : PrivateKeyAccountWithPrivateKey ;
25+ let l3Rollup : Address ;
26+ let l3UpgradeExecutor : Address ;
27+
28+ if ( env ) {
29+ l3RollupOwner = env . l3 . accounts . rollupOwner ;
30+ l3Rollup = env . l3 . rollup ;
31+ l3UpgradeExecutor = env . l3 . upgradeExecutor ;
32+ } else {
33+ l3RollupOwner = getNitroTestnodePrivateKeyAccounts ( ) . l3RollupOwner ;
34+
35+ const testNodeInformation = getInformationFromTestnode ( ) ;
36+ l3Rollup = testNodeInformation . l3Rollup ;
37+ l3UpgradeExecutor = testNodeInformation . l3UpgradeExecutor ;
38+ }
39+
40+ const l2Client = createPublicClient ( {
41+ chain : env ? env . l2 . chain : nitroTestnodeL2 ,
2542 transport : http ( ) ,
2643} ) . extend (
2744 rollupAdminLogicPublicActions ( {
@@ -30,19 +47,19 @@ const client = createPublicClient({
3047) ;
3148
3249async function setValidator ( validator : Address , state : boolean ) {
33- const tx = await client . rollupAdminLogicPrepareTransactionRequest ( {
50+ const tx = await l2Client . rollupAdminLogicPrepareTransactionRequest ( {
3451 functionName : 'setValidator' ,
3552 args : [ [ validator ] , [ state ] ] ,
3653 account : l3RollupOwner . address ,
3754 upgradeExecutor : l3UpgradeExecutor ,
3855 rollup : l3Rollup ,
3956 } ) ;
4057
41- const txHash = await client . sendRawTransaction ( {
58+ const txHash = await l2Client . sendRawTransaction ( {
4259 serializedTransaction : await l3RollupOwner . signTransaction ( tx ) ,
4360 } ) ;
4461
45- await client . waitForTransactionReceipt ( {
62+ await l2Client . waitForTransactionReceipt ( {
4663 hash : txHash ,
4764 } ) ;
4865}
@@ -53,7 +70,7 @@ describe('successfully get validators', () => {
5370 const randomAccount = privateKeyToAccount ( generatePrivateKey ( ) ) . address ;
5471
5572 const { isAccurate : isAccurateInitially , validators : initialValidators } = await getValidators (
56- client ,
73+ l2Client ,
5774 {
5875 rollup : l3Rollup ,
5976 } ,
@@ -65,22 +82,25 @@ describe('successfully get validators', () => {
6582 await setValidator ( randomAccount , false ) ;
6683 await setValidator ( randomAccount , false ) ;
6784
68- const { isAccurate : isStillAccurate , validators : newValidators } = await getValidators ( client , {
69- rollup : l3Rollup ,
70- } ) ;
85+ const { isAccurate : isStillAccurate , validators : newValidators } = await getValidators (
86+ l2Client ,
87+ {
88+ rollup : l3Rollup ,
89+ } ,
90+ ) ;
7191 // Setting the same validator multiple time to false doesn't add new validators
7292 expect ( newValidators ) . toEqual ( initialValidators ) ;
7393 expect ( isStillAccurate ) . toBeTruthy ( ) ;
7494
7595 await setValidator ( randomAccount , true ) ;
76- const { validators, isAccurate } = await getValidators ( client , { rollup : l3Rollup } ) ;
96+ const { validators, isAccurate } = await getValidators ( l2Client , { rollup : l3Rollup } ) ;
7797 expect ( validators ) . toEqual ( initialValidators . concat ( randomAccount ) ) ;
7898 expect ( isAccurate ) . toBeTruthy ( ) ;
7999
80100 // Reset state for future tests
81101 await setValidator ( randomAccount , false ) ;
82102 const { isAccurate : isAccurateFinal , validators : validatorsFinal } = await getValidators (
83- client ,
103+ l2Client ,
84104 {
85105 rollup : l3Rollup ,
86106 } ,
@@ -93,7 +113,7 @@ describe('successfully get validators', () => {
93113 const randomAccount = privateKeyToAccount ( generatePrivateKey ( ) ) . address ;
94114
95115 const { isAccurate : isAccurateInitially , validators : initialValidators } = await getValidators (
96- client ,
116+ l2Client ,
97117 {
98118 rollup : l3Rollup ,
99119 } ,
@@ -104,23 +124,26 @@ describe('successfully get validators', () => {
104124
105125 await setValidator ( randomAccount , true ) ;
106126 await setValidator ( randomAccount , true ) ;
107- const { isAccurate : isStillAccurate , validators : newValidators } = await getValidators ( client , {
108- rollup : l3Rollup ,
109- } ) ;
127+ const { isAccurate : isStillAccurate , validators : newValidators } = await getValidators (
128+ l2Client ,
129+ {
130+ rollup : l3Rollup ,
131+ } ,
132+ ) ;
110133
111134 expect ( newValidators ) . toEqual ( initialValidators . concat ( randomAccount ) ) ;
112135 expect ( isStillAccurate ) . toBeTruthy ( ) ;
113136
114137 // Reset state for futures tests
115138 await setValidator ( randomAccount , false ) ;
116- const { validators, isAccurate } = await getValidators ( client , { rollup : l3Rollup } ) ;
139+ const { validators, isAccurate } = await getValidators ( l2Client , { rollup : l3Rollup } ) ;
117140 expect ( validators ) . toEqual ( initialValidators ) ;
118141 expect ( isAccurate ) . toBeTruthy ( ) ;
119142 } ) ;
120143
121144 it ( 'when adding an existing validator' , async ( ) => {
122145 const { isAccurate : isAccurateInitially , validators : initialValidators } = await getValidators (
123- client ,
146+ l2Client ,
124147 { rollup : l3Rollup } ,
125148 ) ;
126149
@@ -130,14 +153,14 @@ describe('successfully get validators', () => {
130153 const firstValidator = initialValidators [ 0 ] ;
131154 await setValidator ( firstValidator , true ) ;
132155
133- const { isAccurate, validators } = await getValidators ( client , { rollup : l3Rollup } ) ;
156+ const { isAccurate, validators } = await getValidators ( l2Client , { rollup : l3Rollup } ) ;
134157 expect ( validators ) . toEqual ( initialValidators ) ;
135158 expect ( isAccurate ) . toBeTruthy ( ) ;
136159 } ) ;
137160
138161 it ( 'when removing an existing validator' , async ( ) => {
139162 const { isAccurate : isAccurateInitially , validators : initialValidators } = await getValidators (
140- client ,
163+ l2Client ,
141164 { rollup : l3Rollup } ,
142165 ) ;
143166
@@ -146,13 +169,13 @@ describe('successfully get validators', () => {
146169
147170 const lastValidator = initialValidators [ initialValidators . length - 1 ] ;
148171 await setValidator ( lastValidator , false ) ;
149- const { isAccurate, validators } = await getValidators ( client , { rollup : l3Rollup } ) ;
172+ const { isAccurate, validators } = await getValidators ( l2Client , { rollup : l3Rollup } ) ;
150173 expect ( validators ) . toEqual ( initialValidators . slice ( 0 , - 1 ) ) ;
151174 expect ( isAccurate ) . toBeTruthy ( ) ;
152175
153176 await setValidator ( lastValidator , true ) ;
154177 const { isAccurate : isAccurateFinal , validators : validatorsFinal } = await getValidators (
155- client ,
178+ l2Client ,
156179 { rollup : l3Rollup } ,
157180 ) ;
158181 expect ( validatorsFinal ) . toEqual ( initialValidators ) ;
0 commit comments