Skip to content

Commit 026f3d6

Browse files
Alenarsfauveldlachaume
committed
PR Review adjusments: enhance tests
Add a test that check the `get_transaction_highest_chain_point` of the `CardanoTransactionRepository` handle correcly the common case of multiple transaction with the same chain point. Clarify cardano transactions artificat builder tests. Co-authored-by: Sébastien Fauvel <[email protected]> Co-authored-by: Damien Lachaume <[email protected]>
1 parent c80f17e commit 026f3d6

File tree

2 files changed

+57
-22
lines changed

2 files changed

+57
-22
lines changed

internal/mithril-persistence/src/database/repository/cardano_transaction_repository.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,36 @@ mod tests {
521521
);
522522
}
523523

524+
#[tokio::test]
525+
async fn repository_get_transaction_highest_chain_point_with_transactions_with_same_block_number_in_db(
526+
) {
527+
let connection = Arc::new(cardano_tx_db_connection().unwrap());
528+
let repository = CardanoTransactionRepository::new(connection);
529+
530+
let cardano_transactions = vec![
531+
CardanoTransaction::new("tx-hash-123", 10, 50, "block-hash-10", 50),
532+
CardanoTransaction::new("tx-hash-456", 25, 51, "block-hash-25", 100),
533+
CardanoTransaction::new("tx-hash-789", 25, 51, "block-hash-25", 100),
534+
];
535+
repository
536+
.create_transactions(cardano_transactions)
537+
.await
538+
.unwrap();
539+
540+
let highest_beacon = repository
541+
.get_transaction_highest_chain_point()
542+
.await
543+
.unwrap();
544+
assert_eq!(
545+
Some(ChainPoint {
546+
slot_number: 51,
547+
block_number: 25,
548+
block_hash: "block-hash-25".to_string()
549+
}),
550+
highest_beacon
551+
);
552+
}
553+
524554
#[tokio::test]
525555
async fn repository_get_transaction_highest_immutable_file_number_without_transactions_in_db() {
526556
let connection = Arc::new(cardano_tx_db_connection().unwrap());

mithril-aggregator/src/artifact_builder/cardano_transactions.rs

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -66,45 +66,50 @@ mod tests {
6666

6767
#[tokio::test]
6868
async fn should_compute_valid_artifact_with_merkleroot() {
69-
let certificate = {
70-
let mut certificate = fake_data::certificate("certificate-123".to_string());
71-
let mut message = ProtocolMessage::new();
72-
message.set_message_part(
69+
let mut mock_prover = MockProverService::new();
70+
mock_prover.expect_compute_cache().returning(|_| Ok(()));
71+
let cardano_transaction_artifact_builder =
72+
CardanoTransactionsArtifactBuilder::new(Arc::new(mock_prover));
73+
74+
let certificate_with_merkle_root = {
75+
let mut protocol_message = ProtocolMessage::new();
76+
protocol_message.set_message_part(
7377
ProtocolMessagePartKey::CardanoTransactionsMerkleRoot,
7478
"merkleroot".to_string(),
7579
);
76-
certificate.protocol_message = message;
77-
certificate
80+
Certificate {
81+
protocol_message,
82+
..fake_data::certificate("certificate-123".to_string())
83+
}
7884
};
79-
8085
let beacon = 100;
81-
let mut mock_prover = MockProverService::new();
82-
mock_prover.expect_compute_cache().returning(|_| Ok(()));
83-
let cardano_transaction_artifact_builder =
84-
CardanoTransactionsArtifactBuilder::new(Arc::new(mock_prover));
86+
8587
let artifact = cardano_transaction_artifact_builder
86-
.compute_artifact(beacon, &certificate)
88+
.compute_artifact(beacon, &certificate_with_merkle_root)
8789
.await
8890
.unwrap();
89-
let artifact_expected = CardanoTransactionsSnapshot::new("merkleroot".to_string(), beacon);
90-
assert_eq!(artifact_expected, artifact);
91+
92+
assert_eq!(
93+
CardanoTransactionsSnapshot::new("merkleroot".to_string(), beacon),
94+
artifact
95+
);
9196
}
9297

9398
#[tokio::test]
9499
async fn should_fail_to_compute_artifact_without_merkle_root() {
95-
let certificate = {
96-
let mut certificate = fake_data::certificate("certificate-123".to_string());
97-
let message = ProtocolMessage::new();
98-
certificate.protocol_message = message;
99-
certificate
100-
};
101-
102100
let mut mock_prover = MockProverService::new();
103101
mock_prover.expect_compute_cache().returning(|_| Ok(()));
104102
let cardano_transaction_artifact_builder =
105103
CardanoTransactionsArtifactBuilder::new(Arc::new(mock_prover));
104+
105+
let certificate_without_merkle_root = Certificate {
106+
protocol_message: ProtocolMessage::new(),
107+
..fake_data::certificate("certificate-123".to_string())
108+
};
109+
let beacon = 100;
110+
106111
cardano_transaction_artifact_builder
107-
.compute_artifact(12390, &certificate)
112+
.compute_artifact(beacon, &certificate_without_merkle_root)
108113
.await
109114
.expect_err("The artifact building must fail since there is no CardanoTransactionsMerkleRoot part in its message.");
110115
}

0 commit comments

Comments
 (0)