Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions chain-impl-mockchain/src/accounting/account/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
Expand Down
5 changes: 4 additions & 1 deletion chain-impl-mockchain/src/accounting/account/spending.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
Expand Down
1 change: 1 addition & 0 deletions chain-impl-mockchain/src/ledger/tests/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
17 changes: 10 additions & 7 deletions chain-impl-mockchain/src/ledger/tests/transaction_tests.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![cfg(test)]

use crate::{
accounting::account::LedgerError::NonExistent,
accounting::account::{LedgerError::NonExistent, SpendingCounter},
date::BlockDate,
ledger::{
self,
Expand Down Expand Up @@ -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"),
},
}
}

Expand Down