-
Notifications
You must be signed in to change notification settings - Fork 715
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/deferred credits abs fixes (#3203)
* Roll selling code is now easier to read * Rework deferred credits when selling rolls * Remove some hardcoded values from roll_sell TU * Check that sold rolls are reimbursed in unit test * Fix balance checking after roll sell * Always set roll entry to 0 * Optimize fetch_all_deferred_credits_at * Use checked_mul_u64 + unwrap in roll sell unit test * Restore previous version of fetch_all_deferred_credits_at * Fix use of deferred credits in roll sell * Remove use of insert_entry feature * Add active history unit test * Add active history tu to mod.rs file * Fix some clippy warnings Co-authored-by: sydhds <[email protected]>
- Loading branch information
Showing
7 changed files
with
223 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
|
||
mod mock; | ||
mod scenarios_mandatories; | ||
mod tests_active_history; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
use std::collections::{BTreeMap, VecDeque}; | ||
use massa_execution_exports::ExecutionOutput; | ||
use crate::active_history::ActiveHistory; | ||
use massa_models::slot::Slot; | ||
|
||
use serial_test::serial; | ||
use massa_final_state::StateChanges; | ||
use massa_hash::Hash; | ||
use massa_models::address::Address; | ||
use massa_models::amount::Amount; | ||
use massa_models::prehash::{CapacityAllocator, PreHashMap}; | ||
use massa_pos_exports::{DeferredCredits, PoSChanges}; | ||
|
||
#[test] | ||
#[serial] | ||
fn test_active_history_deferred_credits() { | ||
|
||
let slot1 = Slot::new(2, 2); | ||
let slot2 = Slot::new(4, 11); | ||
|
||
let addr1 = Address(Hash::compute_from("A1".as_bytes())); | ||
let addr2 = Address(Hash::compute_from("A2".as_bytes())); | ||
|
||
let amount_a1_s1 = Amount::from_raw(500); | ||
let amount_a2_s1 = Amount::from_raw(2702); | ||
let amount_a1_s2 = Amount::from_raw(37); | ||
let amount_a2_s2 = Amount::from_raw(3); | ||
|
||
let mut ph1 = PreHashMap::with_capacity(2); | ||
ph1.insert(addr1, amount_a1_s1); | ||
ph1.insert(addr2, amount_a2_s1); | ||
let mut ph2 = PreHashMap::with_capacity(2); | ||
ph2.insert(addr1, amount_a1_s2); | ||
ph2.insert(addr2, amount_a2_s2); | ||
|
||
let credits = DeferredCredits { 0: BTreeMap::from( | ||
[ | ||
(slot1, ph1), | ||
(slot2, ph2) | ||
] | ||
)}; | ||
|
||
let exec_output_1 = ExecutionOutput { | ||
slot: Slot::new(1, 0), | ||
block_id: None, | ||
state_changes: StateChanges { | ||
ledger_changes: Default::default(), | ||
async_pool_changes: Default::default(), | ||
pos_changes: PoSChanges { | ||
seed_bits: Default::default(), | ||
roll_changes: Default::default(), | ||
production_stats: Default::default(), | ||
deferred_credits: credits | ||
}, | ||
executed_ops_changes: Default::default() | ||
}, | ||
events: Default::default() | ||
}; | ||
|
||
let active_history = ActiveHistory { 0: VecDeque::from([exec_output_1]) }; | ||
|
||
assert_eq!(active_history.get_adress_deferred_credit_for(&addr1, &slot2), Some(amount_a1_s2)); | ||
|
||
let deferred_credit_for_slot1 = active_history.get_all_deferred_credits_for(&slot1); | ||
assert_eq!(deferred_credit_for_slot1.get(&addr1), Some(&amount_a1_s1)); | ||
assert_eq!(deferred_credit_for_slot1.get(&addr2), Some(&amount_a2_s1)); | ||
} |
Oops, something went wrong.