@@ -15,7 +15,7 @@ pub struct SignedEntityConfig {
1515 /// List of discriminants that the node is allowed to sign
1616 pub allowed_discriminants : BTreeSet < SignedEntityTypeDiscriminants > ,
1717 /// Cardano transactions signing configuration
18- pub cardano_transactions_signing_config : CardanoTransactionsSigningConfig ,
18+ pub cardano_transactions_signing_config : Option < CardanoTransactionsSigningConfig > ,
1919}
2020
2121impl SignedEntityConfig {
@@ -66,11 +66,18 @@ impl SignedEntityConfig {
6666 ) )
6767 }
6868 SignedEntityTypeDiscriminants :: CardanoTransactions => {
69- SignedEntityType :: CardanoTransactions (
70- time_point. epoch ,
71- self . cardano_transactions_signing_config
72- . compute_block_number_to_be_signed ( time_point. chain_point . block_number ) ,
73- )
69+ match & self . cardano_transactions_signing_config {
70+ Some ( config) => SignedEntityType :: CardanoTransactions (
71+ time_point. epoch ,
72+ config
73+ . compute_block_number_to_be_signed ( time_point. chain_point . block_number ) ,
74+ ) ,
75+ None => {
76+ anyhow:: bail!(
77+ "Can't derive a CardanoTransactions signed entity type from a time point without a `CardanoTransactionsSigningConfig`"
78+ )
79+ }
80+ }
7481 }
7582 SignedEntityTypeDiscriminants :: CardanoDatabase => SignedEntityType :: CardanoDatabase (
7683 CardanoDbBeacon :: new ( * time_point. epoch , time_point. immutable_file_number ) ,
@@ -163,10 +170,10 @@ mod tests {
163170 } ;
164171 let config = SignedEntityConfig {
165172 allowed_discriminants : SignedEntityTypeDiscriminants :: all ( ) ,
166- cardano_transactions_signing_config : CardanoTransactionsSigningConfig {
173+ cardano_transactions_signing_config : Some ( CardanoTransactionsSigningConfig {
167174 security_parameter : BlockNumber ( 0 ) ,
168175 step : BlockNumber ( 15 ) ,
169- } ,
176+ } ) ,
170177 } ;
171178
172179 assert_eq ! (
@@ -224,6 +231,36 @@ mod tests {
224231 ) ;
225232 }
226233
234+ #[ test]
235+ fn can_not_convert_time_point_to_cardano_transaction_without_the_associated_config ( ) {
236+ let time_point = TimePoint {
237+ epoch : Epoch ( 1 ) ,
238+ immutable_file_number : 5 ,
239+ chain_point : ChainPoint {
240+ slot_number : SlotNumber ( 73 ) ,
241+ block_number : BlockNumber ( 20 ) ,
242+ block_hash : "block_hash-20" . to_string ( ) ,
243+ } ,
244+ } ;
245+ let config = SignedEntityConfig {
246+ allowed_discriminants : SignedEntityTypeDiscriminants :: all ( ) ,
247+ cardano_transactions_signing_config : None ,
248+ } ;
249+
250+ let error = config
251+ . time_point_to_signed_entity (
252+ SignedEntityTypeDiscriminants :: CardanoTransactions ,
253+ & time_point,
254+ )
255+ . unwrap_err ( ) ;
256+
257+ let expected_error = "Can't derive a CardanoTransactions signed entity type from a time point without a `CardanoTransactionsSigningConfig`" ;
258+ assert ! (
259+ error. to_string( ) . contains( expected_error) ,
260+ "Error message: {error:?}\n should contains: {expected_error}\n "
261+ ) ;
262+ }
263+
227264 #[ test]
228265 fn computing_block_number_to_be_signed ( ) {
229266 // **block_number = ((tip.block_number - k') / n) × n**
@@ -422,10 +459,10 @@ mod tests {
422459 SignedEntityTypeDiscriminants :: CardanoStakeDistribution ,
423460 SignedEntityTypeDiscriminants :: CardanoTransactions ,
424461 ] ) ,
425- cardano_transactions_signing_config : CardanoTransactionsSigningConfig {
462+ cardano_transactions_signing_config : Some ( CardanoTransactionsSigningConfig {
426463 security_parameter : BlockNumber ( 0 ) ,
427464 step : BlockNumber ( 15 ) ,
428- } ,
465+ } ) ,
429466 } ;
430467
431468 let signed_entity_types = config. list_allowed_signed_entity_types ( & time_point) . unwrap ( ) ;
0 commit comments