diff --git a/chain-impl-mockchain/src/accounting/account/mod.rs b/chain-impl-mockchain/src/accounting/account/mod.rs index 88c9361e2..002918198 100644 --- a/chain-impl-mockchain/src/accounting/account/mod.rs +++ b/chain-impl-mockchain/src/accounting/account/mod.rs @@ -31,8 +31,11 @@ pub enum LedgerError { AlreadyExists, #[error("Removed account is not empty")] NonZero, - #[error("Spending credential invalid")] - SpendingCredentialInvalid, + #[error("Spending credential invalid, expected {} got {} in lane {}", .expected.unlaned_counter(), .actual.unlaned_counter(), .actual.lane())] + SpendingCredentialInvalid { + expected: SpendingCounter, + actual: SpendingCounter, + }, #[error("Value calculation failed")] ValueError(#[from] ValueError), } diff --git a/chain-impl-mockchain/src/accounting/account/spending.rs b/chain-impl-mockchain/src/accounting/account/spending.rs index 41f4eccf4..a200a3e63 100644 --- a/chain-impl-mockchain/src/accounting/account/spending.rs +++ b/chain-impl-mockchain/src/accounting/account/spending.rs @@ -53,7 +53,10 @@ impl SpendingCounterIncreasing { let actual_counter = self.nexts[counter.lane()]; if actual_counter != counter { - Err(LedgerError::SpendingCredentialInvalid) + Err(LedgerError::SpendingCredentialInvalid { + expected: actual_counter, + actual: counter, + }) } else { self.nexts[counter.lane()] = actual_counter.increment(); Ok(()) diff --git a/chain-impl-mockchain/src/ledger/tests/macros.rs b/chain-impl-mockchain/src/ledger/tests/macros.rs index 81b037023..508a56b6a 100644 --- a/chain-impl-mockchain/src/ledger/tests/macros.rs +++ b/chain-impl-mockchain/src/ledger/tests/macros.rs @@ -29,6 +29,7 @@ macro_rules! assert_err { // // succeed if Expression's value a Err(E) where E match the ExpectedErrorPattern, // otherwise panic!() with some diagnostic +#[allow(unused_macros)] macro_rules! assert_err_match { ($left: pat, $right: expr) => { match &($right) { diff --git a/chain-impl-mockchain/src/ledger/tests/transaction_tests.rs b/chain-impl-mockchain/src/ledger/tests/transaction_tests.rs index f5accbcf6..ffcf15b4d 100644 --- a/chain-impl-mockchain/src/ledger/tests/transaction_tests.rs +++ b/chain-impl-mockchain/src/ledger/tests/transaction_tests.rs @@ -1,7 +1,7 @@ #![cfg(test)] use crate::{ - accounting::account::LedgerError::NonExistent, + accounting::account::{LedgerError::NonExistent, SpendingCounter}, date::BlockDate, ledger::{ self, @@ -129,12 +129,15 @@ pub fn duplicated_account_transaction() { match result { Err(err) => panic!("first transaction should be succesful but {}", err), - Ok(_) => { - assert_err_match!( - ledger::Error::Account(crate::account::LedgerError::SpendingCredentialInvalid), - test_ledger.apply_transaction(fragment2, BlockDate::first()) - ); - } + Ok(_) => match test_ledger.apply_transaction(fragment2, BlockDate::first()) { + Err(ledger::Error::Account( + crate::account::LedgerError::SpendingCredentialInvalid { expected, actual }, + )) => { + assert_eq!(expected, SpendingCounter::zero().increment()); + assert_eq!(actual, SpendingCounter::zero()); + } + _ => panic!("duplicated transaction should fail spending counter validation"), + }, } }