@@ -60,6 +60,15 @@ pub type ScrollNetworkHandle =
6060pub type TestBlockChainProvider =
6161 BlockchainProvider < NodeTypesWithDBAdapter < ScrollRollupNode , TmpDB > > ;
6262
63+ /// The node type (sequencer or follower).
64+ #[ derive( Debug ) ]
65+ pub enum NodeType {
66+ /// A sequencer node.
67+ Sequencer ,
68+ /// A follower node.
69+ Follower ,
70+ }
71+
6372/// Handle to a single test node with its components.
6473pub struct NodeHandle {
6574 /// The underlying node context.
@@ -74,6 +83,20 @@ pub struct NodeHandle {
7483 pub rollup_manager_handle : ChainOrchestratorHandle < ScrollNetworkHandle > ,
7584 /// Node index in the test setup.
7685 pub index : usize ,
86+ /// The type of the node.
87+ pub typ : NodeType ,
88+ }
89+
90+ impl NodeHandle {
91+ /// Returns true if this is a handle to the sequencer.
92+ pub fn is_sequencer ( & self ) -> bool {
93+ matches ! ( self . typ, NodeType :: Sequencer )
94+ }
95+
96+ /// Returns true if this is a handle to a follower.
97+ pub fn is_follower ( & self ) -> bool {
98+ matches ! ( self . typ, NodeType :: Follower )
99+ }
77100}
78101
79102impl Debug for NodeHandle {
@@ -95,18 +118,25 @@ impl TestFixture {
95118 }
96119
97120 /// Get the sequencer node (assumes first node is sequencer).
98- pub fn sequencer_node ( & mut self ) -> & mut NodeHandle {
99- & mut self . nodes [ 0 ]
121+ pub fn sequencer ( & mut self ) -> & mut NodeHandle {
122+ let handle = & mut self . nodes [ 0 ] ;
123+ if !handle. is_sequencer ( ) {
124+ panic ! ( "expected sequencer, got follower" )
125+ }
126+ handle
100127 }
101128
102129 /// Get a follower node by index.
103- pub fn follower_node ( & mut self , index : usize ) -> & mut NodeHandle {
104- & mut self . nodes [ index + 1 ]
130+ pub fn follower ( & mut self , index : usize ) -> & mut NodeHandle {
131+ if index == 0 && self . nodes [ 0 ] . is_sequencer ( ) {
132+ return & mut self . nodes [ index + 1 ] ;
133+ }
134+ & mut self . nodes [ index]
105135 }
106136
107- /// Get the wallet address .
108- pub fn wallet_address ( & self ) -> Address {
109- self . wallet . blocking_lock ( ) . inner . address ( )
137+ /// Get the wallet.
138+ pub fn wallet ( & self ) -> Arc < Mutex < Wallet > > {
139+ self . wallet . clone ( )
110140 }
111141
112142 /// Start building a block using the sequencer.
@@ -246,7 +276,7 @@ impl TestFixtureBuilder {
246276 pub fn new ( ) -> Self {
247277 Self {
248278 config : Self :: default_config ( ) ,
249- num_nodes : 1 ,
279+ num_nodes : 0 ,
250280 chain_spec : None ,
251281 is_dev : false ,
252282 no_local_transactions_propagation : false ,
@@ -289,12 +319,14 @@ impl TestFixtureBuilder {
289319 L1MessageInclusionMode :: BlockDepth ( 0 ) ;
290320 self . config . sequencer_args . allow_empty_blocks = true ;
291321 self . config . database_args . rn_db_path = Some ( PathBuf :: from ( "sqlite::memory:" ) ) ;
322+
323+ self . num_nodes += 1 ;
292324 self
293325 }
294326
295327 /// Adds `count`s follower nodes to the test.
296328 pub fn followers ( mut self , count : usize ) -> TestFixtureBuilder {
297- self . num_nodes = count;
329+ self . num_nodes + = count;
298330 self
299331 }
300332
@@ -459,7 +491,7 @@ impl TestFixtureBuilder {
459491 let chain_spec = self . chain_spec . unwrap_or_else ( || SCROLL_DEV . clone ( ) ) ;
460492
461493 let ( nodes, _tasks, wallet) = setup_engine (
462- config,
494+ config. clone ( ) ,
463495 self . num_nodes ,
464496 chain_spec. clone ( ) ,
465497 self . is_dev ,
@@ -495,6 +527,11 @@ impl TestFixtureBuilder {
495527 l1_watcher_tx,
496528 rollup_manager_handle,
497529 index,
530+ typ : if config. sequencer_args . sequencer_enabled && index == 0 {
531+ NodeType :: Sequencer
532+ } else {
533+ NodeType :: Follower
534+ } ,
498535 } ) ;
499536 }
500537
0 commit comments