Skip to content

Commit

Permalink
fix race condition for claim burn in cucmbers
Browse files Browse the repository at this point in the history
  • Loading branch information
sdbondi committed Sep 4, 2024
1 parent 66ff95e commit db4f2a6
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 17 deletions.
6 changes: 2 additions & 4 deletions integration_tests/tests/features/claim_burn.feature
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Feature: Claim Burn
Then VN has scanned to height 30

When I convert commitment COMMITMENT into COMM_ADDRESS address
Then validator node VN has state at COMM_ADDRESS
Then validator node VN has state at COMM_ADDRESS within 20 seconds

When I claim burn COMMITMENT with PROOF, RANGEPROOF and CLAIM_PUBKEY and spend it into account ACC via the wallet daemon WALLET_D
# Then account ACC has one confidential bucket in it
Expand Down Expand Up @@ -73,10 +73,8 @@ Feature: Claim Burn
When miner MINER mines 13 new blocks
Then VN has scanned to height 30

# TODO: remove sleep - this is needed to allow validators enough time to propose the UTXO
When I wait 20 seconds
When I convert commitment COMMITMENT into COMM_ADDRESS address
Then validator node VN has state at COMM_ADDRESS
Then validator node VN has state at COMM_ADDRESS within 20 seconds

When I claim burn COMMITMENT with PROOF, RANGEPROOF and CLAIM_PUBKEY and spend it into account ACC via the wallet daemon WALLET_D
When I claim burn COMMITMENT with PROOF, RANGEPROOF and CLAIM_PUBKEY and spend it into account ACC via the wallet daemon WALLET_D, it fails
Expand Down
4 changes: 2 additions & 2 deletions integration_tests/tests/features/transfer.feature
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Feature: Account transfers
Then indexer IDX has scanned to height 45

When I convert commitment COMMITMENT into COMM_ADDRESS address
Then validator node VN has state at COMM_ADDRESS
Then validator node VN has state at COMM_ADDRESS within 20 seconds
When I claim burn COMMITMENT with PROOF, RANGEPROOF and CLAIM_PUBKEY and spend it into account ACCOUNT via the wallet daemon WALLET_D

# Wait for the wallet daemon account monitor to update the sender account information
Expand Down Expand Up @@ -129,7 +129,7 @@ Feature: Account transfers
Then indexer IDX has scanned to height 45

When I convert commitment COMMITMENT into COMM_ADDRESS address
Then validator node VN has state at COMM_ADDRESS
Then validator node VN has state at COMM_ADDRESS within 20 seconds
When I claim burn COMMITMENT with PROOF, RANGEPROOF and CLAIM_PUBKEY and spend it into account ACCOUNT_1 via the wallet daemon WALLET_D

# Wait for the wallet daemon account monitor to update the sender account information
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/tests/features/wallet_daemon.feature
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ Feature: Wallet Daemon
Then VN has scanned to height 30

When I convert commitment COMMITMENT into COMM_ADDRESS address
Then validator node VN has state at COMM_ADDRESS
Then validator node VN has state at COMM_ADDRESS within 20 seconds

When I claim burn COMMITMENT with PROOF, RANGEPROOF and CLAIM_PUBKEY and spend it into account ACCOUNT_1 via the wallet daemon WALLET_D
When I print the cucumber world
Expand Down
36 changes: 26 additions & 10 deletions integration_tests/tests/steps/validator_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,13 @@ async fn assert_template_is_registered_by_all(world: &mut TariWorld, template_na
}
}

#[then(expr = "validator node {word} has state at {word}")]
async fn then_validator_node_has_state_at(world: &mut TariWorld, vn_name: String, state_address_name: String) {
#[then(expr = "validator node {word} has state at {word} within {int} seconds")]
async fn then_validator_node_has_state_at(
world: &mut TariWorld,
vn_name: String,
state_address_name: String,
timeout_secs: u64,
) {
let state_address = world
.addresses
.get(&state_address_name)
Expand All @@ -330,14 +335,25 @@ async fn then_validator_node_has_state_at(world: &mut TariWorld, vn_name: String
let mut client = vn.create_client();
let substate_address =
SubstateAddress::from_substate_id(&SubstateId::from_str(state_address).expect("Invalid state address"), 0);
if let Err(e) = client
.get_state(GetStateRequest {
address: substate_address,
})
.await
{
println!("Failed to get state: {}", e);
panic!("Failed to get state: {}", e);
let mut attempts = 0;
loop {
match client
.get_state(GetStateRequest {
address: substate_address,
})
.await
{
Ok(_) => return,
Err(e) => {
attempts += 1;
if attempts == timeout_secs {
println!("Failed to get state: {}", e);
panic!("Failed to get state: {}", e);
}
},
}

tokio::time::sleep(Duration::from_secs(1)).await;
}
}

Expand Down

0 comments on commit db4f2a6

Please sign in to comment.