Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(PocketIC): retry in PocketIC bitcoin integration tests #3491

Merged
merged 3 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions packages/pocket-ic/HOWTO.md
Original file line number Diff line number Diff line change
Expand Up @@ -585,9 +585,20 @@ To mine blocks with rewards credited to a given `bitcoin_address: String`, you c
.unwrap();

let mut n = 101; // must be more than 100 (Coinbase maturity rule)
btc_rpc
.generate_to_address(n, &Address::from_str(&bitcoin_address).unwrap())
.unwrap();
// retry generating blocks until the bitcoind is up and running
let start = std::time::Instant::now();
loop {
mraszyk marked this conversation as resolved.
Show resolved Hide resolved
match btc_rpc.generate_to_address(n, &Address::from_str(&bitcoin_address).unwrap()) {
Ok(_) => break,
Err(bitcoincore_rpc::Error::JsonRpc(err)) => {
if start.elapsed() > std::time::Duration::from_secs(30) {
panic!("Timed out when waiting for bitcoind; last error: {}", err);
}
std::thread::sleep(std::time::Duration::from_millis(100));
}
Err(err) => panic!("Unexpected error when talking to bitcoind: {}", err),
}
}
```

For an example of a test canister that can be deployed to an application subnet of the PocketIC instance,
Expand Down
17 changes: 14 additions & 3 deletions rs/pocket_ic_server/tests/bitcoin_integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,20 @@ rpcauth=ic-btc-integration:cdf2741387f3a12438f69092f0fdad8e$62081498c98bee09a0dc

// `n` must be more than 100 (Coinbase maturity rule) so that the reward for the first block can be sent out
let mut n = 101;
btc_rpc
.generate_to_address(n, &Address::from_str(&bitcoin_address).unwrap())
.unwrap();
// retry generating blocks until the bitcoind is up and running
let start = std::time::Instant::now();
loop {
match btc_rpc.generate_to_address(n, &Address::from_str(&bitcoin_address).unwrap()) {
Ok(_) => break,
Err(bitcoincore_rpc::Error::JsonRpc(err)) => {
if start.elapsed() > std::time::Duration::from_secs(30) {
panic!("Timed out when waiting for bitcoind; last error: {}", err);
}
std::thread::sleep(std::time::Duration::from_millis(100));
}
Err(err) => panic!("Unexpected error when talking to bitcoind: {}", err),
}
}

let reward = 50 * 100_000_000; // 50 BTC

Expand Down
Loading