Skip to content

Commit

Permalink
Merge pull request #23 from soonlabs/reorg_test
Browse files Browse the repository at this point in the history
Resolve issue#12 and add the reason of issue#11
  • Loading branch information
raindust authored Aug 30, 2024
2 parents 2d136b3 + 50e1547 commit a7da0dc
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions storage/src/tests/reorg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ async fn reorg_works() -> Result<()> {
assert_eq!(bank0.slot(), 0);

// Slot 1
const SLOT1_TO_CHARLIE: u64 = 2_000_000; // FIXME: assert_eq! failed if balance is 200_000 or less
// FIXME: assert_eq! failed if transfer amount is 890_880 or less,
// FIXME: because 890_880 is minimum rent exempt amount,
// FIXME: should check this situation before `transfer` instruction.
const SLOT1_TO_CHARLIE: u64 = 2_000_000;
const SLOT1_TO_DAVE: u64 = 1_000_000;
store.bump()?;
let bank1 = store.bank.clone();
Expand Down Expand Up @@ -118,6 +121,11 @@ async fn reorg_works() -> Result<()> {
let bank3 = store.new_slot_with_parent(bank1.clone(), 3)?.clone();
assert_eq!(bank3.slot(), 3);
assert_eq!(bank3.parent_slot(), 1);
// + FEE here because bob is the leader of Slot 1, so it has the 50% tx fee of that Slot.
assert_eq!(
store.balance(&bob.pubkey()),
BOB_INIT_BALANCE - SLOT1_TO_DAVE - FEE + FEE
);
new_slot_with_two_txs(
bank3,
&mut store,
Expand All @@ -135,7 +143,7 @@ async fn reorg_works() -> Result<()> {
);
assert_eq!(
store.balance(&bob.pubkey()),
BOB_INIT_BALANCE - SLOT1_TO_DAVE - SLOT3_TO_DAVE - FEE // FIXME: fee is not calculated correctly
BOB_INIT_BALANCE - SLOT1_TO_DAVE - SLOT3_TO_DAVE - FEE
);
assert_eq!(store.balance(&charlie), SLOT1_TO_CHARLIE + SLOT3_TO_CHARLIE);
assert_eq!(store.balance(&dave), SLOT1_TO_DAVE + SLOT3_TO_DAVE);
Expand All @@ -146,6 +154,12 @@ async fn reorg_works() -> Result<()> {
let bank4 = store.new_slot_with_parent(bank2.clone(), 4)?.clone();
assert_eq!(bank4.slot(), 4);
assert_eq!(bank4.parent_slot(), 2);
// + FEE here because bob is the leader of Slot 2, so it has the 50% tx fee of that Slot.
assert_eq!(
store.balance(&bob.pubkey()),
BOB_INIT_BALANCE - SLOT2_TO_DAVE - FEE + FEE
);

new_slot_with_two_txs(
bank4,
&mut store,
Expand All @@ -163,7 +177,7 @@ async fn reorg_works() -> Result<()> {
);
assert_eq!(
store.balance(&bob.pubkey()),
BOB_INIT_BALANCE - SLOT2_TO_DAVE - SLOT4_TO_DAVE - FEE // FIXME: fee is not calculated correctly
BOB_INIT_BALANCE - SLOT2_TO_DAVE - SLOT4_TO_DAVE - FEE
);

assert_eq!(store.current_height(), 4);
Expand All @@ -186,9 +200,10 @@ async fn reorg_works() -> Result<()> {
store.balance(&alice.pubkey()),
ALICE_INIT_BALANCE - SLOT1_TO_CHARLIE - SLOT3_TO_CHARLIE - FEE * 2
);
// + FEE * 2 here because bob is the leader of Slot 1 & Slot 3, so it has the 50% tx fee of that 2 Slots.
assert_eq!(
store.balance(&bob.pubkey()),
BOB_INIT_BALANCE - SLOT1_TO_DAVE - SLOT3_TO_DAVE // FIXME: fee is not calculated correctly
BOB_INIT_BALANCE - SLOT1_TO_DAVE - SLOT3_TO_DAVE - FEE * 2 + FEE * 2
);
assert_eq!(store.balance(&charlie), SLOT1_TO_CHARLIE + SLOT3_TO_CHARLIE);
assert_eq!(store.balance(&dave), SLOT1_TO_DAVE + SLOT3_TO_DAVE);
Expand Down

0 comments on commit a7da0dc

Please sign in to comment.