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