Skip to content

Commit

Permalink
test(GlobalState): Verify setting new tip clears block proposal data
Browse files Browse the repository at this point in the history
Add a test ensuring that block proposal and the set of exported block
proposal for external guessers is cleared when a new block is
set as tip.
  • Loading branch information
Sword-Smith committed Mar 5, 2025
1 parent 0640e39 commit b693014
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/models/state/block_proposal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ impl BlockProposal {
}

pub(crate) fn is_some(&self) -> bool {
!matches!(self, BlockProposal::None)
!self.is_none()
}

pub(crate) fn is_none(&self) -> bool {
matches!(self, BlockProposal::None)
}

pub(crate) fn unwrap(&self) -> &Block {
Expand Down
30 changes: 30 additions & 0 deletions src/models/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1739,6 +1739,7 @@ mod global_state_tests {
use crate::models::blockchain::block::Block;
use crate::models::state::wallet::address::hash_lock_key::HashLockKey;
use crate::tests::shared::fake_valid_successor_for_tests;
use crate::tests::shared::invalid_empty_block;
use crate::tests::shared::make_mock_block;
use crate::tests::shared::make_mock_block_guesser_preimage_and_guesser_fraction;
use crate::tests::shared::mock_genesis_global_state;
Expand Down Expand Up @@ -1810,6 +1811,35 @@ mod global_state_tests {
}
}

#[tokio::test]
async fn set_new_tip_clears_block_proposal_related_data() {
let network = Network::Main;
let mut bob = mock_genesis_global_state(
network,
2,
WalletSecret::devnet_wallet(),
cli_args::Args::default(),
)
.await;
let mut bob = bob.global_state_lock.lock_guard_mut().await;
let block1 = invalid_empty_block(&Block::genesis(network));

bob.mining_state.block_proposal = BlockProposal::ForeignComposition(block1.clone());
bob.mining_state
.exported_block_proposals
.insert(random(), block1.clone());

bob.set_new_tip(block1).await.unwrap();
assert!(
bob.mining_state.block_proposal.is_none(),
"block proposal must be reset after setting new tip."
);
assert!(
bob.mining_state.exported_block_proposals.is_empty(),
"Set of exported block proposals must be empty after registering new block"
);
}

#[traced_test]
#[tokio::test]
async fn premine_recipient_cannot_spend_premine_before_and_can_after_release_date() {
Expand Down

0 comments on commit b693014

Please sign in to comment.