Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: refactor(rm spending counter): audit tooling | NPG-000 #663

Closed
wants to merge 20 commits into from
Closed
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
Original file line number Diff line number Diff line change
@@ -58,35 +58,14 @@ impl SpendingCounterIncreasing {
/// an error reported.
///
/// If the counter match succesfully, then the counter at this lane is incremented by one.
pub fn next_verify(&mut self, counter: SpendingCounter) -> Result<(), Error> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe make explicit in the comment why this function it just returns Ok() ?

let actual_counter = self.nexts[counter.lane()];

if actual_counter != counter {
Err(Error::SpendingCredentialInvalid {
expected: actual_counter,
actual: counter,
})
} else {
self.next_unchecked(counter);
Ok(())
}
pub fn next_verify(&mut self, _counter: SpendingCounter) -> Result<(), Error> {
// spending counter logic has been removed throughout, returning OK is the least invasive action at the moment.
// Prod chain-libs = https://github.com/input-output-hk/chain-libs/tree/catalyst-fund9-gold
Ok(())
}

/// Increases the spending counter on the given lane.
pub(crate) fn next_unchecked(&mut self, unchecked_counter: SpendingCounter) {
let lane = unchecked_counter.lane();
let counter_to_update = self.nexts[lane];
if counter_to_update != unchecked_counter {
tracing::warn!(
"Invalid spending counter, {}",
Error::SpendingCredentialInvalid {
expected: counter_to_update,
actual: unchecked_counter,
}
);
}
self.nexts[lane] = counter_to_update.increment();
}
pub(crate) fn next_unchecked(&mut self, _unchecked_counter: SpendingCounter) {}
}

// only used to print the account's ledger
@@ -204,19 +183,22 @@ mod tests {
use quickcheck::TestResult;

#[quickcheck_macros::quickcheck]
#[ignore]
fn spending_counter_serialization_bijection(sc: SpendingCounter) -> TestResult {
let bytes = sc.to_bytes();
TestResult::from_bool(SpendingCounter::from_bytes(bytes) == sc)
}

#[test]
#[ignore]
fn new_invalid_spending_counter() {
let lane: usize = (1 << LANES_BITS) + 1;
let counter: u32 = 1 << UNLANES_BITS;
assert!(SpendingCounter::new(lane, counter).is_err());
}

#[quickcheck_macros::quickcheck]
#[ignore]
fn new_spending_counter(mut lane: usize, mut counter: u32) {
lane %= 1 << LANES_BITS;
counter %= 1 << UNLANES_BITS;
@@ -227,6 +209,7 @@ mod tests {
}

#[quickcheck_macros::quickcheck]
#[ignore]
fn increment_counter(mut spending_counter: SpendingCounter) -> TestResult {
if spending_counter.unlaned_counter().checked_add(1).is_none() {
return TestResult::discard();
@@ -239,6 +222,7 @@ mod tests {
}

#[quickcheck_macros::quickcheck]
#[ignore]
pub fn increment_nth(mut spending_counter: SpendingCounter, n: u32) -> TestResult {
if spending_counter.unlaned_counter().checked_add(n).is_none() {
return TestResult::discard();
@@ -252,18 +236,21 @@ mod tests {

#[test]
#[should_panic]
#[ignore]
#[cfg(debug_assertions)]
fn increment_counter_overflow_debug() {
let _ = SpendingCounter::new(8, u32::MAX).unwrap().increment();
}

#[test]
#[ignore]
#[should_panic]
#[cfg(debug_assertions)]
pub fn increment_nth_overflow_debug() {
let _ = SpendingCounter::new(0, 1).unwrap().increment_nth(u32::MAX);
}

#[ignore]
#[quickcheck_macros::quickcheck]
pub fn spending_counter_is_set_on_correct_lane(
spending_counter: SpendingCounter,
@@ -275,6 +262,7 @@ mod tests {
}

#[test]
#[ignore]
pub fn spending_counters_duplication() {
let counters = [
SpendingCounter::zero(),
@@ -290,6 +278,7 @@ mod tests {
}

#[test]
#[ignore]
pub fn spending_counters_incorrect_order() {
let counters = [
SpendingCounter::new(1, 0).unwrap(),
@@ -304,6 +293,7 @@ mod tests {
assert!(SpendingCounterIncreasing::new_from_counters(counters).is_err());
}

#[ignore]
#[quickcheck_macros::quickcheck]
pub fn spending_counter_increasing_increment(mut index: usize) -> TestResult {
let mut sc_increasing = SpendingCounterIncreasing::default();
@@ -316,12 +306,14 @@ mod tests {
}

#[test]
#[ignore]
pub fn spending_counter_increasing_wrong_counter() {
let mut sc_increasing = SpendingCounterIncreasing::default();
let incorrect_sc = SpendingCounter::new(0, 100).unwrap();
assert!(sc_increasing.next_verify(incorrect_sc).is_err());
}

#[ignore]
#[test]
pub fn spending_counter_increasing_wrong_lane() {
let mut sc_increasing = SpendingCounterIncreasing::default();
1 change: 1 addition & 0 deletions src/chain-libs/chain-impl-mockchain/src/ledger/ledger.rs
Original file line number Diff line number Diff line change
@@ -2885,6 +2885,7 @@ mod tests {
.is_err());
}

#[ignore]
#[test]
fn test_internal_apply_transaction_wrong_spending_counter() {
let faucet =
Original file line number Diff line number Diff line change
@@ -97,6 +97,7 @@ pub fn transaction_nonexisting_account_input() {
}

#[test]
#[ignore]
pub fn transaction_with_incorrect_account_spending_counter() {
let faucet =
AddressDataValue::account_with_spending_counter(Discrimination::Test, 1, Value(1000));
1 change: 0 additions & 1 deletion src/chain-libs/chain-impl-mockchain/src/testing/e2e/mod.rs
Original file line number Diff line number Diff line change
@@ -4,7 +4,6 @@ pub mod mint_token;
pub mod owner_delegation;
pub mod pool_update;
pub mod rewards;
pub mod spending_counter_lanes;
pub mod stake_distribution;
pub mod transactions;
pub mod update_proposal;
Original file line number Diff line number Diff line change
@@ -283,6 +283,7 @@ pub fn test_mempool_log_max_entries_equals_0() {
.unwrap();
}

#[ignore]
#[test]
pub fn test_mempool_pool_max_entries_overrides_log_max_entries() {
let temp_dir = TempDir::new().unwrap();
Original file line number Diff line number Diff line change
@@ -351,6 +351,7 @@ pub fn test_mempool_log_max_entries_equals_0() {
.unwrap();
}

#[ignore]
#[test]
pub fn test_mempool_pool_max_entries_overrides_log_max_entries() {
let temp_dir = TempDir::new().unwrap();
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@ use jortestkit::process::Wait;
use std::time::Duration;
use thor::TransactionHash;

#[ignore]
#[test]
pub fn explorer_transaction_test() {
let jcli: JCli = Default::default();
Original file line number Diff line number Diff line change
@@ -1020,6 +1020,7 @@ pub fn explorer_all_vote_plans_public_flow_test() {
);
}

#[ignore]
#[test]
pub fn explorer_all_vote_plans_private_flow_test() {
let temp_dir = TempDir::new().unwrap().into_persistent();
Original file line number Diff line number Diff line change
@@ -104,6 +104,7 @@ pub fn dump_send_correct_fragments() {
assert_all_fragment_are_persisted(dump_folder.path(), persistent_log_path.path());
}

#[ignore]
#[test]
pub fn dump_send_invalid_fragments() {
let temp_dir = TempDir::new().unwrap();
@@ -258,6 +259,7 @@ pub fn fragment_which_reached_mempool_should_be_persisted() {
assert_all_fragment_are_persisted(dump_folder.path(), persistent_log_path.path());
}

#[ignore]
#[test]
pub fn fragment_which_is_not_in_fragment_log_should_be_persisted() {
let temp_dir = TempDir::new().unwrap();
@@ -351,6 +353,7 @@ pub fn pending_fragment_should_be_persisted() {
assert!(fragment_logs.values().next().unwrap().is_pending());
}

#[ignore]
#[test]
pub fn node_should_pickup_log_after_restart() {
let mut temp_dir = TempDir::new().unwrap();