@@ -74,11 +74,11 @@ impl VerifiedCardanoTransactions {
74
74
ProtocolMessagePartKey :: CardanoTransactionsMerkleRoot ,
75
75
self . merkle_root . clone ( ) ,
76
76
) ;
77
- // TODO: uncommment once tests are created.
78
- // message.set_message_part(
79
- // ProtocolMessagePartKey::LatestImmutableFileNumber,
80
- // self.latest_immutable_file_number.to_string(),
81
- // );
77
+
78
+ message. set_message_part (
79
+ ProtocolMessagePartKey :: LatestImmutableFileNumber ,
80
+ self . latest_immutable_file_number . to_string ( ) ,
81
+ ) ;
82
82
}
83
83
}
84
84
@@ -180,8 +180,19 @@ impl CardanoTransactionsProofsMessage {
180
180
181
181
#[ cfg( test) ]
182
182
mod tests {
183
+ use std:: { path:: Path , sync:: Arc } ;
184
+
185
+ use slog:: Logger ;
186
+
183
187
use super :: * ;
184
- use crate :: crypto_helper:: MKProof ;
188
+ use crate :: {
189
+ cardano_transaction_parser:: DumbTransactionParser ,
190
+ crypto_helper:: MKProof ,
191
+ entities:: { Beacon , CardanoTransaction } ,
192
+ signable_builder:: {
193
+ CardanoTransactionsSignableBuilder , MockTransactionStore , SignableBuilder ,
194
+ } ,
195
+ } ;
185
196
186
197
#[ test]
187
198
fn verify_malformed_proofs_fail ( ) {
@@ -310,4 +321,59 @@ mod tests {
310
321
error
311
322
) ;
312
323
}
324
+
325
+ #[ tokio:: test]
326
+ async fn verify_hashes_from_verified_cardano_transaction_and_from_signable_builder_are_equals ( )
327
+ {
328
+ let transaction_1 = CardanoTransaction :: new ( "tx-hash-123" , 1 , 1 ) ;
329
+ let transaction_2 = CardanoTransaction :: new ( "tx-hash-456" , 2 , 1 ) ;
330
+ let transaction_3 = CardanoTransaction :: new ( "tx-hash-789" , 3 , 1 ) ;
331
+ let transaction_4 = CardanoTransaction :: new ( "tx-hash-abc" , 4 , 1 ) ;
332
+
333
+ let transactions = vec ! [ transaction_1, transaction_2, transaction_3, transaction_4] ;
334
+ let transactions_hashes = transactions
335
+ . iter ( )
336
+ . map ( |t| t. transaction_hash . clone ( ) )
337
+ . collect :: < Vec < _ > > ( ) ;
338
+ let latest_immutable_file_number = 99999 ;
339
+
340
+ let message = {
341
+ let proof = MKProof :: from_leaves ( & transactions) . unwrap ( ) ;
342
+ let set_proof = CardanoTransactionsSetProof :: new ( transactions_hashes, proof) ;
343
+
344
+ let verified_transactions_fake = VerifiedCardanoTransactions {
345
+ certificate_hash : "whatever" . to_string ( ) ,
346
+ merkle_root : set_proof. merkle_root ( ) ,
347
+ certified_transactions : set_proof. transactions_hashes ( ) . to_vec ( ) ,
348
+ latest_immutable_file_number,
349
+ } ;
350
+
351
+ let mut message = ProtocolMessage :: new ( ) ;
352
+ verified_transactions_fake. fill_protocol_message ( & mut message) ;
353
+ message
354
+ } ;
355
+
356
+ let from_signable_builder = {
357
+ let mut mock_transaction_store = MockTransactionStore :: new ( ) ;
358
+ mock_transaction_store
359
+ . expect_store_transactions ( )
360
+ . returning ( |_| Ok ( ( ) ) ) ;
361
+
362
+ let cardano_transaction_signable_builder = CardanoTransactionsSignableBuilder :: new (
363
+ Arc :: new ( DumbTransactionParser :: new ( transactions. clone ( ) ) ) ,
364
+ Arc :: new ( mock_transaction_store) ,
365
+ Path :: new ( "/tmp" ) ,
366
+ Logger :: root ( slog:: Discard , slog:: o!( ) ) ,
367
+ ) ;
368
+ cardano_transaction_signable_builder
369
+ . compute_protocol_message ( Beacon {
370
+ immutable_file_number : latest_immutable_file_number,
371
+ ..Beacon :: default ( )
372
+ } )
373
+ . await
374
+ . unwrap ( )
375
+ } ;
376
+
377
+ assert ! ( message. compute_hash( ) == from_signable_builder. compute_hash( ) ) ;
378
+ }
313
379
}
0 commit comments