Skip to content

Commit

Permalink
Fix tests after redefining behavior of set_new_tip
Browse files Browse the repository at this point in the history
After redefining the behavior of the `set_new_tip` to update global state
with a new block, the function formerly known as `store_block`,  we need
to rearrange the order in which blocks are added in a few tests. With these
changes, all tests pass, and #143 is closed.
  • Loading branch information
Sword-Smith committed May 7, 2024
1 parent 3de0e42 commit dde2420
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
13 changes: 7 additions & 6 deletions src/models/state/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -804,10 +804,6 @@ mod wallet_tests {
#[traced_test]
#[tokio::test]
async fn wallet_state_maintanence_multiple_inputs_outputs_test() -> Result<()> {
// An archival state is needed for how we currently add inputs to a transaction.
// So it's just used to generate test data, not in any of the functions that are
// actually tested.

let mut rng = thread_rng();
let network = Network::RegTest;
let own_wallet_secret = WalletSecret::new_random();
Expand All @@ -820,10 +816,10 @@ mod wallet_tests {
let premine_wallet = mock_genesis_wallet_state(WalletSecret::devnet_wallet(), network)
.await
.wallet_secret;
let premine_receiver_global_state_lock =
let premine_receiver_global_state =
mock_genesis_global_state(network, 2, premine_wallet).await;
let mut premine_receiver_global_state =
premine_receiver_global_state_lock.lock_guard_mut().await;
premine_receiver_global_state.lock_guard_mut().await;
let launch = genesis_block.kernel.header.timestamp;
let seven_months = Timestamp::months(7);
let preminers_original_balance = premine_receiver_global_state
Expand Down Expand Up @@ -921,6 +917,11 @@ mod wallet_tests {
"Preminer must have spent 15: 12 + 1 for sent, 2 for fees"
);

own_wallet_state
.update_wallet_state_with_new_block(&previous_msa, &block_1)
.await
.unwrap();

// Verify that update added 4 UTXOs to list of monitored transactions:
// three as regular outputs, and one as coinbase UTXO
monitored_utxos = get_monitored_utxos(&own_wallet_state).await;
Expand Down
15 changes: 9 additions & 6 deletions src/peer_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1601,8 +1601,9 @@ mod peer_loop_tests {
#[traced_test]
#[tokio::test]
async fn block_request_batch_out_of_order_test() -> Result<()> {
// Scenario: Same as above, but the peer supplies their hashes in a wrong order.
// Ensure that the correct blocks are returned, in the right order.
// Scenario: A fork began at block 2, node knows two blocks of height 2 and two of height 3.
// A peer requests a batch of blocks starting from block 1, but the peer supplies their
// hashes in a wrong order. Ensure that the correct blocks are returned, in the right order.

let mut rng = thread_rng();
let network = Network::Alpha;
Expand All @@ -1626,9 +1627,9 @@ mod peer_loop_tests {

global_state_mut.set_new_tip(block_1.clone()).await?;
global_state_mut.set_new_tip(block_2_a.clone()).await?;
global_state_mut.set_new_tip(block_3_a.clone()).await?;
global_state_mut.set_new_tip(block_2_b.clone()).await?;
global_state_mut.set_new_tip(block_3_b.clone()).await?;
global_state_mut.set_new_tip(block_3_a.clone()).await?;

drop(global_state_mut);

Expand Down Expand Up @@ -1664,9 +1665,11 @@ mod peer_loop_tests {
#[traced_test]
#[tokio::test]
async fn find_canonical_chain_when_multiple_blocks_at_same_height_test() -> Result<()> {
let mut rng = thread_rng();
// Scenario: A fork began at block 2, node knows two blocks of height 2 and two of height 3.
// A peer requests a block at height 2. Verify that the correct block at height 2 is returned.
// A peer requests a block at height 2. Verify that the correct block at height 2 is
// returned.

let mut rng = thread_rng();
let network = Network::Alpha;
let (_peer_broadcast_tx, from_main_rx_clone, to_main_tx, _to_main_rx1, state_lock, hsd) =
get_test_genesis_setup(network, 0).await?;
Expand All @@ -1688,9 +1691,9 @@ mod peer_loop_tests {

global_state_mut.set_new_tip(block_1.clone()).await?;
global_state_mut.set_new_tip(block_2_a.clone()).await?;
global_state_mut.set_new_tip(block_3_a.clone()).await?;
global_state_mut.set_new_tip(block_2_b.clone()).await?;
global_state_mut.set_new_tip(block_3_b.clone()).await?;
global_state_mut.set_new_tip(block_3_a.clone()).await?;

drop(global_state_mut);

Expand Down

0 comments on commit dde2420

Please sign in to comment.