11use assert_matches:: assert_matches;
2+ use itertools:: Itertools ;
23use pretty_assertions:: assert_eq;
34use starknet_api:: block:: BlockNumber ;
45use starknet_api:: test_utils:: l1_handler:: executable_l1_handler_tx;
56use starknet_api:: transaction:: TransactionHash ;
67use starknet_api:: { l1_handler_tx_args, tx_hash} ;
78use starknet_l1_provider_types:: errors:: L1ProviderError ;
9+ use starknet_l1_provider_types:: SessionState :: {
10+ self ,
11+ Propose as ProposeSession ,
12+ Validate as ValidateSession ,
13+ } ;
814use starknet_l1_provider_types:: ValidationStatus ;
915
1016use crate :: l1_provider:: L1Provider ;
1117use crate :: test_utils:: L1ProviderContentBuilder ;
12- use crate :: ProviderState :: { Pending , Propose , Uninitialized , Validate } ;
18+ use crate :: ProviderState ;
1319
1420macro_rules! tx {
1521 ( tx_hash: $tx_hash: expr) => { {
@@ -27,7 +33,7 @@ fn get_txs_happy_flow() {
2733 let txs = [ tx ! ( tx_hash: 0 ) , tx ! ( tx_hash: 1 ) , tx ! ( tx_hash: 2 ) ] ;
2834 let mut l1_provider = L1ProviderContentBuilder :: new ( )
2935 . with_txs ( txs. clone ( ) )
30- . with_state ( Propose )
36+ . with_state ( ProviderState :: Propose )
3137 . build_into_l1_provider ( ) ;
3238
3339 // Test.
@@ -43,7 +49,7 @@ fn validate_happy_flow() {
4349 let mut l1_provider = L1ProviderContentBuilder :: new ( )
4450 . with_txs ( [ tx ! ( tx_hash: 1 ) ] )
4551 . with_committed ( [ tx_hash ! ( 2 ) ] )
46- . with_state ( Validate )
52+ . with_state ( ProviderState :: Validate )
4753 . build_into_l1_provider ( ) ;
4854
4955 // Test.
@@ -70,7 +76,7 @@ fn validate_happy_flow() {
7076fn pending_state_errors ( ) {
7177 // Setup.
7278 let mut l1_provider = L1ProviderContentBuilder :: new ( )
73- . with_state ( Pending )
79+ . with_state ( ProviderState :: Pending )
7480 . with_txs ( [ tx ! ( tx_hash: 1 ) ] )
7581 . build_into_l1_provider ( ) ;
7682
@@ -90,7 +96,7 @@ fn pending_state_errors() {
9096#[ should_panic( expected = "Uninitialized L1 provider" ) ]
9197fn uninitialized_get_txs ( ) {
9298 let mut uninitialized_l1_provider = L1Provider :: default ( ) ;
93- assert_eq ! ( uninitialized_l1_provider. state, Uninitialized ) ;
99+ assert_eq ! ( uninitialized_l1_provider. state, ProviderState :: Uninitialized ) ;
94100
95101 uninitialized_l1_provider. get_txs ( 1 , BlockNumber ( 1 ) ) . unwrap ( ) ;
96102}
@@ -99,44 +105,21 @@ fn uninitialized_get_txs() {
99105#[ should_panic( expected = "Uninitialized L1 provider" ) ]
100106fn uninitialized_validate ( ) {
101107 let mut uninitialized_l1_provider = L1Provider :: default ( ) ;
102- assert_eq ! ( uninitialized_l1_provider. state, Uninitialized ) ;
108+ assert_eq ! ( uninitialized_l1_provider. state, ProviderState :: Uninitialized ) ;
103109
104110 uninitialized_l1_provider. validate ( TransactionHash :: default ( ) , BlockNumber ( 1 ) ) . unwrap ( ) ;
105111}
106112
107113#[ test]
108- fn proposal_start_errors ( ) {
114+ fn proposal_start_multiple_proposals_same_height ( ) {
109115 // Setup.
110116 let mut l1_provider =
111- L1ProviderContentBuilder :: new ( ) . with_state ( Pending ) . build_into_l1_provider ( ) ;
112- // Test.
113- l1_provider. proposal_start ( BlockNumber ( 1 ) ) . unwrap ( ) ;
114-
115- assert_eq ! (
116- l1_provider. proposal_start( BlockNumber ( 1 ) ) . unwrap_err( ) ,
117- L1ProviderError :: unexpected_transition( Propose , Propose )
118- ) ;
119- assert_eq ! (
120- l1_provider. validation_start( BlockNumber ( 1 ) ) . unwrap_err( ) ,
121- L1ProviderError :: unexpected_transition( Propose , Validate )
122- ) ;
123- }
124-
125- #[ test]
126- fn validation_start_errors ( ) {
127- // Setup.
128- let mut l1_provider =
129- L1ProviderContentBuilder :: new ( ) . with_state ( Pending ) . build_into_l1_provider ( ) ;
130-
131- // Test.
132- l1_provider. validation_start ( BlockNumber ( 1 ) ) . unwrap ( ) ;
133-
134- assert_eq ! (
135- l1_provider. validation_start( BlockNumber ( 1 ) ) . unwrap_err( ) ,
136- L1ProviderError :: unexpected_transition( Validate , Validate )
137- ) ;
138- assert_eq ! (
139- l1_provider. proposal_start( BlockNumber ( 1 ) ) . unwrap_err( ) ,
140- L1ProviderError :: unexpected_transition( Validate , Propose )
141- ) ;
117+ L1ProviderContentBuilder :: new ( ) . with_state ( ProviderState :: Pending ) . build_into_l1_provider ( ) ;
118+
119+ // Test all single-height combinations.
120+ const SESSION_TYPES : [ SessionState ; 2 ] = [ ProposeSession , ValidateSession ] ;
121+ for ( session_1, session_2) in SESSION_TYPES . into_iter ( ) . cartesian_product ( SESSION_TYPES ) {
122+ l1_provider. start_block ( BlockNumber ( 1 ) , session_1) . unwrap ( ) ;
123+ l1_provider. start_block ( BlockNumber ( 1 ) , session_2) . unwrap ( ) ;
124+ }
142125}
0 commit comments