Skip to content

Commit

Permalink
PR Review adjusments: enhance tests
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
3 people committed Jun 5, 2024
1 parent c80f17e commit 026f3d6
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,36 @@ mod tests {
);
}

#[tokio::test]
async fn repository_get_transaction_highest_chain_point_with_transactions_with_same_block_number_in_db(
) {
let connection = Arc::new(cardano_tx_db_connection().unwrap());
let repository = CardanoTransactionRepository::new(connection);

let cardano_transactions = vec![
CardanoTransaction::new("tx-hash-123", 10, 50, "block-hash-10", 50),
CardanoTransaction::new("tx-hash-456", 25, 51, "block-hash-25", 100),
CardanoTransaction::new("tx-hash-789", 25, 51, "block-hash-25", 100),
];
repository
.create_transactions(cardano_transactions)
.await
.unwrap();

let highest_beacon = repository
.get_transaction_highest_chain_point()
.await
.unwrap();
assert_eq!(
Some(ChainPoint {
slot_number: 51,
block_number: 25,
block_hash: "block-hash-25".to_string()
}),
highest_beacon
);
}

#[tokio::test]
async fn repository_get_transaction_highest_immutable_file_number_without_transactions_in_db() {
let connection = Arc::new(cardano_tx_db_connection().unwrap());
Expand Down
49 changes: 27 additions & 22 deletions mithril-aggregator/src/artifact_builder/cardano_transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,45 +66,50 @@ mod tests {

#[tokio::test]
async fn should_compute_valid_artifact_with_merkleroot() {
let certificate = {
let mut certificate = fake_data::certificate("certificate-123".to_string());
let mut message = ProtocolMessage::new();
message.set_message_part(
let mut mock_prover = MockProverService::new();
mock_prover.expect_compute_cache().returning(|_| Ok(()));
let cardano_transaction_artifact_builder =
CardanoTransactionsArtifactBuilder::new(Arc::new(mock_prover));

let certificate_with_merkle_root = {
let mut protocol_message = ProtocolMessage::new();
protocol_message.set_message_part(
ProtocolMessagePartKey::CardanoTransactionsMerkleRoot,
"merkleroot".to_string(),
);
certificate.protocol_message = message;
certificate
Certificate {
protocol_message,
..fake_data::certificate("certificate-123".to_string())
}
};

let beacon = 100;
let mut mock_prover = MockProverService::new();
mock_prover.expect_compute_cache().returning(|_| Ok(()));
let cardano_transaction_artifact_builder =
CardanoTransactionsArtifactBuilder::new(Arc::new(mock_prover));

let artifact = cardano_transaction_artifact_builder
.compute_artifact(beacon, &certificate)
.compute_artifact(beacon, &certificate_with_merkle_root)
.await
.unwrap();
let artifact_expected = CardanoTransactionsSnapshot::new("merkleroot".to_string(), beacon);
assert_eq!(artifact_expected, artifact);

assert_eq!(
CardanoTransactionsSnapshot::new("merkleroot".to_string(), beacon),
artifact
);
}

#[tokio::test]
async fn should_fail_to_compute_artifact_without_merkle_root() {
let certificate = {
let mut certificate = fake_data::certificate("certificate-123".to_string());
let message = ProtocolMessage::new();
certificate.protocol_message = message;
certificate
};

let mut mock_prover = MockProverService::new();
mock_prover.expect_compute_cache().returning(|_| Ok(()));
let cardano_transaction_artifact_builder =
CardanoTransactionsArtifactBuilder::new(Arc::new(mock_prover));

let certificate_without_merkle_root = Certificate {
protocol_message: ProtocolMessage::new(),
..fake_data::certificate("certificate-123".to_string())
};
let beacon = 100;

cardano_transaction_artifact_builder
.compute_artifact(12390, &certificate)
.compute_artifact(beacon, &certificate_without_merkle_root)
.await
.expect_err("The artifact building must fail since there is no CardanoTransactionsMerkleRoot part in its message.");
}
Expand Down

0 comments on commit 026f3d6

Please sign in to comment.