fix: refactor error cases into more tests

This commit is contained in:
Roman 2024-06-25 14:20:38 +02:00
parent afb7defa6d
commit c1ec5e54df
No known key found for this signature in database
GPG Key ID: B8FE070B54E11B75
1 changed files with 11 additions and 2 deletions

View File

@ -773,7 +773,7 @@ pub mod tests {
} }
#[test] #[test]
fn test_cryptarchia_ledger_error_cases() { fn test_update_epoch_state_with_outdated_slot_error() {
let coin = coin(0); let coin = coin(0);
let commitment = coin.commitment(); let commitment = coin.commitment();
let (ledger, genesis) = ledger(&[commitment]); let (ledger, genesis) = ledger(&[commitment]);
@ -797,8 +797,17 @@ pub mod tests {
if parent == slot && block == slot2 => {} if parent == slot && block == slot2 => {}
_ => panic!("error does not match the LedgerError::InvalidSlot pattern"), _ => panic!("error does not match the LedgerError::InvalidSlot pattern"),
}; };
}
#[test]
fn test_apply_proof_with_existing_commitment_error() {
let coin = coin(0);
let commitment = coin.commitment();
let (ledger, genesis) = ledger(&[commitment]);
let ledger_state = ledger.state(&genesis).unwrap().clone(); let ledger_state = ledger.state(&genesis).unwrap().clone();
let ledger_config = ledger.config();
let actual_slot = ledger_state.slot(); let actual_slot = ledger_state.slot();
let proof = LeaderProof::dummy(actual_slot, commitment, commitment); let proof = LeaderProof::dummy(actual_slot, commitment, commitment);
let epoch_state = ledger_state.epoch_state(); let epoch_state = ledger_state.epoch_state();
@ -814,7 +823,7 @@ pub mod tests {
.try_apply_proof::<HeaderId>(&proof, ledger_config) .try_apply_proof::<HeaderId>(&proof, ledger_config)
.err(); .err();
// Commitment cannot be spent twice // Same commitment value from another coin cannot be used again
assert!( assert!(
matches!(apply_proof_err, Some(LedgerError::CommitmentExists)), matches!(apply_proof_err, Some(LedgerError::CommitmentExists)),
"Error does not match LedgerError::CommitmentExists" "Error does not match LedgerError::CommitmentExists"