diff --git a/Cargo.lock b/Cargo.lock index f026b845..d1204c24 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3430,7 +3430,6 @@ version = "0.22.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "295642060261c80709ac034f52fca8e5a9fa2c7d341ded5cdb164b7c33768b2a" dependencies = [ - "rand 0.6.5", "secp256k1-sys", "serde", ] diff --git a/canister/Cargo.toml b/canister/Cargo.toml index ee1c144b..49a4e327 100644 --- a/canister/Cargo.toml +++ b/canister/Cargo.toml @@ -35,7 +35,7 @@ bench = false [dev-dependencies] assert_matches = { workspace = true } async-std = { version = "1.12.0", features = ["attributes"] } -bitcoin = { workspace = true, features = ["rand"] } # needed for generating secp256k1 keys. +bitcoin = { workspace = true } byteorder = { workspace = true } candid_parser = { workspace = true } ic-btc-test-utils = { workspace = true } diff --git a/canister/proptest-regressions/api/get_utxos.txt b/canister/proptest-regressions/api/get_utxos.txt new file mode 100644 index 00000000..ebbc3ada --- /dev/null +++ b/canister/proptest-regressions/api/get_utxos.txt @@ -0,0 +1,7 @@ +# Seeds for failure cases proptest has generated in the past. It is +# automatically read and these particular cases re-run before any +# novel cases are generated. +# +# It is recommended to check this file in to source control so that +# everyone who runs the test benefits from these saved cases. +cc 4fb046840a47349fe7c8517cf3b45e933e8f90657d7050598605d8e7ad6364b4 # shrinks to num_transactions = 1, num_blocks = 1, utxo_limit = 10 diff --git a/canister/proptest-regressions/tests/confirmation_counts.txt b/canister/proptest-regressions/tests/confirmation_counts.txt new file mode 100644 index 00000000..c98b9510 --- /dev/null +++ b/canister/proptest-regressions/tests/confirmation_counts.txt @@ -0,0 +1,8 @@ +# Seeds for failure cases proptest has generated in the past. It is +# automatically read and these particular cases re-run before any +# novel cases are generated. +# +# It is recommended to check this file in to source control so that +# everyone who runs the test benefits from these saved cases. +cc d4ae143d926026c4c35660945d703ae75c588984ae466120a9be524d22e9f455 # shrinks to chain_len = 2 +cc ac900a0fc39aca9433b9d13fe624a86ff91c797726eabd8ae3a2e2109f2834bf # shrinks to chain_len = 9, fork_idx = 0 diff --git a/canister/proptest-regressions/utxo_set.txt b/canister/proptest-regressions/utxo_set.txt new file mode 100644 index 00000000..5f7e4e3e --- /dev/null +++ b/canister/proptest-regressions/utxo_set.txt @@ -0,0 +1,7 @@ +# Seeds for failure cases proptest has generated in the past. It is +# automatically read and these particular cases re-run before any +# novel cases are generated. +# +# It is recommended to check this file in to source control so that +# everyone who runs the test benefits from these saved cases. +cc 7cf105bd410b167fa9eb7f08bdad6c46c1e5a1ef960837293d9c21e837891654 # shrinks to ingestion_rate = 1, tx_cardinality = 1, network = Mainnet diff --git a/canister/src/address_utxoset.rs b/canister/src/address_utxoset.rs index 929013d6..4714161a 100644 --- a/canister/src/address_utxoset.rs +++ b/canister/src/address_utxoset.rs @@ -116,16 +116,19 @@ impl<'a> AddressUtxoSet<'a> { #[cfg(test)] mod test { use super::*; - use crate::test_utils::{random_p2pkh_address, BlockBuilder, TransactionBuilder}; + use crate::test_utils::{BlockBuilder, TransactionBuilder}; + use crate::types::into_bitcoin_network; use crate::unstable_blocks; use ic_btc_interface::Network; + use ic_btc_test_utils::random_p2pkh_address; use ic_btc_types::OutPoint; #[test] fn add_tx_to_empty_utxo() { let network = Network::Mainnet; + let btc_network = into_bitcoin_network(network); // Create some BTC addresses. - let address_1 = random_p2pkh_address(network); + let address_1 = random_p2pkh_address(btc_network).into(); let utxo_set = UtxoSet::new(network); @@ -161,9 +164,10 @@ mod test { #[test] fn add_tx_then_transfer() { let network = Network::Mainnet; + let btc_network = into_bitcoin_network(network); // Create some BTC addresses. - let address_1 = random_p2pkh_address(network); - let address_2 = random_p2pkh_address(network); + let address_1 = random_p2pkh_address(btc_network).into(); + let address_2 = random_p2pkh_address(btc_network).into(); let utxo_set = UtxoSet::new(network); @@ -213,10 +217,11 @@ mod test { #[test] fn spending_multiple_inputs() { let network = Network::Mainnet; + let btc_network = into_bitcoin_network(network); // Create some BTC addresses. - let address_1 = random_p2pkh_address(network); - let address_2 = random_p2pkh_address(network); + let address_1 = random_p2pkh_address(btc_network).into(); + let address_2 = random_p2pkh_address(btc_network).into(); // Create a genesis block where 2000 satoshis are given to address 1 // in two different outputs. diff --git a/canister/src/api/fee_percentiles.rs b/canister/src/api/fee_percentiles.rs index ef3a11f4..61370b8b 100644 --- a/canister/src/api/fee_percentiles.rs +++ b/canister/src/api/fee_percentiles.rs @@ -164,14 +164,16 @@ fn percentiles(mut values: Vec) -> Vec { #[cfg(test)] mod test { use super::*; + use crate::types::into_bitcoin_network; use crate::{ genesis_block, heartbeat, state, - test_utils::{random_p2pkh_address, BlockBuilder, TransactionBuilder}, + test_utils::{BlockBuilder, TransactionBuilder}, with_state, }; use async_std::task::block_on; use bitcoin::Witness; use ic_btc_interface::{Fees, InitConfig, Network, Satoshi}; + use ic_btc_test_utils::random_p2pkh_address; use ic_btc_types::OutPoint; use std::iter::FromIterator; @@ -246,11 +248,12 @@ mod test { // Fee is choosen to be a multiple of transaction size to have round values of fee. fn generate_blocks(initial_balance: Satoshi, number_of_blocks: u32) -> Vec { let network = Network::Regtest; + let btc_network = into_bitcoin_network(network); let mut blocks = Vec::new(); let pay: Satoshi = 1; - let address_1 = random_p2pkh_address(network); - let address_2 = random_p2pkh_address(network); + let address_1 = random_p2pkh_address(btc_network).into(); + let address_2 = random_p2pkh_address(btc_network).into(); let coinbase_tx = TransactionBuilder::coinbase() .with_output(&address_1, initial_balance) @@ -355,11 +358,17 @@ mod test { let fee_in_millisatoshi = fee * 1000; let tx_1 = TransactionBuilder::coinbase() - .with_output(&random_p2pkh_address(Network::Regtest), balance) + .with_output( + &random_p2pkh_address(bitcoin::Network::Regtest).into(), + balance, + ) .build(); let tx_2 = TransactionBuilder::new() .with_input(OutPoint::new(tx_1.txid(), 0)) - .with_output(&random_p2pkh_address(Network::Regtest), balance - fee) + .with_output( + &random_p2pkh_address(bitcoin::Network::Regtest).into(), + balance - fee, + ) .build(); let blocks = vec![ @@ -399,11 +408,17 @@ mod test { let balance = 1000; let tx_1 = TransactionBuilder::coinbase() - .with_output(&random_p2pkh_address(Network::Regtest), balance) + .with_output( + &random_p2pkh_address(bitcoin::Network::Regtest).into(), + balance, + ) .build(); let tx_2 = TransactionBuilder::new() .with_input(OutPoint::new(tx_1.txid(), 0)) - .with_output(&random_p2pkh_address(Network::Regtest), balance - fee) + .with_output( + &random_p2pkh_address(bitcoin::Network::Regtest).into(), + balance - fee, + ) .build(); BlockBuilder::with_prev_header(genesis_block(network).header()) @@ -599,7 +614,10 @@ mod test { let fee_in_millisatoshi = 1000; let coinbase_tx = TransactionBuilder::coinbase() - .with_output(&random_p2pkh_address(Network::Regtest), balance) + .with_output( + &random_p2pkh_address(bitcoin::Network::Regtest).into(), + balance, + ) .build(); let witness = Witness::from_vec(vec![ @@ -610,12 +628,18 @@ mod test { ]); let tx = TransactionBuilder::new() .with_input_and_witness(OutPoint::new(coinbase_tx.txid(), 0), witness) - .with_output(&random_p2pkh_address(Network::Regtest), balance - fee) + .with_output( + &random_p2pkh_address(bitcoin::Network::Regtest).into(), + balance - fee, + ) .build(); let tx_without_witness = TransactionBuilder::new() .with_input(OutPoint::new(coinbase_tx.txid(), 0)) - .with_output(&random_p2pkh_address(Network::Regtest), balance - fee) + .with_output( + &random_p2pkh_address(bitcoin::Network::Regtest).into(), + balance - fee, + ) .build(); // Check that vsize() is not the same as size() of a transaction. diff --git a/canister/src/api/get_balance.rs b/canister/src/api/get_balance.rs index 0a9acdb1..b883b97f 100644 --- a/canister/src/api/get_balance.rs +++ b/canister/src/api/get_balance.rs @@ -106,12 +106,14 @@ fn get_balance_private(request: GetBalanceRequest) -> Result = None; let mut value = 1; @@ -1236,7 +1253,7 @@ mod test { }); get_utxos(GetUtxosRequest { - address: random_p2pkh_address(Network::Regtest).to_string(), + address: random_p2pkh_address(bitcoin::Network::Regtest).to_string(), filter: None, }) .unwrap(); @@ -1260,7 +1277,7 @@ mod test { runtime::inc_performance_counter(); get_utxos(GetUtxosRequest { - address: random_p2pkh_address(Network::Regtest).to_string(), + address: random_p2pkh_address(bitcoin::Network::Regtest).to_string(), filter: None, }) .unwrap(); @@ -1286,7 +1303,7 @@ mod test { runtime::inc_performance_counter(); get_utxos(GetUtxosRequest { - address: random_p2pkh_address(Network::Regtest).to_string(), + address: random_p2pkh_address(bitcoin::Network::Regtest).to_string(), filter: None, }) .unwrap(); @@ -1383,7 +1400,7 @@ mod test { // Asserts that the given block hash is the tip at the given number of confirmations. fn assert_tip_at_confirmations(confirmations: u32, expected_tip: BlockHash) { // To fetch the tip, we call `get_utxos` using a random address. - let address = random_p2pkh_address(Network::Regtest).to_string(); + let address = random_p2pkh_address(bitcoin::Network::Regtest).to_string(); assert_eq!( get_utxos(GetUtxosRequest { address, diff --git a/canister/src/heartbeat.rs b/canister/src/heartbeat.rs index 66f8bb72..3b922416 100644 --- a/canister/src/heartbeat.rs +++ b/canister/src/heartbeat.rs @@ -266,12 +266,16 @@ mod test { use crate::{ genesis_block, init, runtime::{self, GetSuccessorsReply}, - test_utils::{random_p2pkh_address, BlockBuilder, BlockChainBuilder, TransactionBuilder}, - types::{Address, BlockBlob, GetSuccessorsCompleteResponse, GetSuccessorsPartialResponse}, + test_utils::{BlockBuilder, BlockChainBuilder, TransactionBuilder}, + types::{ + into_bitcoin_network, Address, BlockBlob, GetSuccessorsCompleteResponse, + GetSuccessorsPartialResponse, + }, utxo_set::IngestingBlock, }; use bitcoin::BlockHeader as Header; use ic_btc_interface::{InitConfig, Network}; + use ic_btc_test_utils::random_p2pkh_address; fn build_block(prev_header: &Header, address: Address, num_transactions: u128) -> Block { let mut block = BlockBuilder::with_prev_header(prev_header); @@ -371,6 +375,7 @@ mod test { #[async_std::test] async fn time_slices_large_blocks() { let network = Network::Regtest; + let btc_network = into_bitcoin_network(network); init(InitConfig { stability_threshold: Some(0), @@ -379,7 +384,7 @@ mod test { }); // Setup a chain of two blocks. - let address = random_p2pkh_address(network); + let address: Address = random_p2pkh_address(btc_network).into(); let block_1 = build_block(genesis_block(network).header(), address.clone(), 6); let block_2 = build_block(block_1.header(), address, 1); @@ -456,6 +461,8 @@ mod test { #[async_std::test] async fn time_slices_large_transactions() { let network = Network::Regtest; + let btc_network = into_bitcoin_network(network); + // The number of inputs/outputs in a transaction. let tx_cardinality = 6; @@ -465,8 +472,8 @@ mod test { ..Default::default() }); - let address_1 = random_p2pkh_address(network); - let address_2 = random_p2pkh_address(network); + let address_1 = random_p2pkh_address(btc_network).into(); + let address_2 = random_p2pkh_address(btc_network).into(); // Create a transaction where a few inputs are given to address 1. let mut tx_1 = TransactionBuilder::coinbase(); @@ -610,6 +617,7 @@ mod test { #[async_std::test] async fn fetches_and_processes_responses_paginated() { let network = Network::Regtest; + let btc_network = into_bitcoin_network(network); init(InitConfig { stability_threshold: Some(0), @@ -617,7 +625,7 @@ mod test { ..Default::default() }); - let address = random_p2pkh_address(network); + let address = random_p2pkh_address(btc_network).into(); let block = BlockBuilder::with_prev_header(genesis_block(network).header()) .with_transaction( TransactionBuilder::coinbase() diff --git a/canister/src/test_utils.rs b/canister/src/test_utils.rs index 32cf2675..a71a22bb 100644 --- a/canister/src/test_utils.rs +++ b/canister/src/test_utils.rs @@ -2,60 +2,19 @@ use crate::{ genesis_block, types::{into_bitcoin_network, Address}, }; -use bitcoin::{ - hashes::Hash, secp256k1::rand::rngs::OsRng, secp256k1::Secp256k1, Address as BitcoinAddress, - BlockHeader as Header, PublicKey, Script, WScriptHash, Witness, -}; +use bitcoin::{Address as BitcoinAddress, BlockHeader as Header, Witness}; use ic_btc_interface::Network; use ic_btc_test_utils::{ - BlockBuilder as ExternalBlockBuilder, TransactionBuilder as ExternalTransactionBuilder, + random_p2pkh_address, BlockBuilder as ExternalBlockBuilder, + TransactionBuilder as ExternalTransactionBuilder, }; use ic_btc_types::{Block, OutPoint, Transaction}; use ic_stable_structures::{Memory, StableBTreeMap, Storable}; -use proptest::prelude::RngCore; use std::{ ops::{Bound, RangeBounds}, str::FromStr, }; -/// Generates a random P2PKH address. -pub fn random_p2pkh_address(network: Network) -> Address { - let secp = Secp256k1::new(); - let mut rng = OsRng::new().unwrap(); - - BitcoinAddress::p2pkh( - &PublicKey::new(secp.generate_keypair(&mut rng).1), - into_bitcoin_network(network), - ) - .into() -} - -pub fn random_p2tr_address(network: Network) -> Address { - ic_btc_test_utils::random_p2tr_address(into_bitcoin_network(network)).into() -} - -pub fn random_p2wpkh_address(network: Network) -> Address { - let secp = Secp256k1::new(); - let mut rng = OsRng::new().unwrap(); - BitcoinAddress::p2wpkh( - &PublicKey::new(secp.generate_keypair(&mut rng).1), - into_bitcoin_network(network), - ) - .expect("failed to create p2wpkh address") - .into() -} - -pub fn random_p2wsh_address(network: Network) -> Address { - let mut rng = OsRng::new().unwrap(); - let mut hash = [0u8; 32]; - rng.fill_bytes(&mut hash); - BitcoinAddress::p2wsh( - &Script::new_v0_p2wsh(&WScriptHash::from_hash(Hash::from_slice(&hash).unwrap())), - into_bitcoin_network(network), - ) - .into() -} - /// Builds a random chain with the given number of block and transactions. /// The genesis block used in the chain is also random. pub fn build_chain( @@ -77,7 +36,8 @@ fn build_chain_with_genesis_block( num_blocks: u32, num_transactions_per_block: u32, ) -> Vec { - let address = random_p2pkh_address(network); + let btc_network = into_bitcoin_network(network); + let address = random_p2pkh_address(btc_network).into(); let mut blocks = vec![genesis_block.clone()]; let mut prev_block: Block = genesis_block; let mut value = 1; diff --git a/canister/src/tests.rs b/canister/src/tests.rs index 59d6427e..06a0cec4 100644 --- a/canister/src/tests.rs +++ b/canister/src/tests.rs @@ -1,27 +1,28 @@ use crate::{ api::{get_balance, get_current_fee_percentiles, get_utxos}, - genesis_block, heartbeat, + genesis_block, heartbeat, init, runtime::{self, GetSuccessorsReply}, state::main_chain_height, test_utils::{BlockBuilder, BlockChainBuilder, TransactionBuilder}, types::{ - BlockBlob, BlockHeaderBlob, GetBalanceRequest, GetSuccessorsCompleteResponse, - GetSuccessorsResponse, GetUtxosRequest, + into_bitcoin_network, BlockBlob, BlockHeaderBlob, GetBalanceRequest, + GetSuccessorsCompleteResponse, GetSuccessorsResponse, GetUtxosRequest, }, utxo_set::{IngestingBlock, DUPLICATE_TX_IDS}, verify_synced, with_state, SYNCED_THRESHOLD, }; -use crate::{init, test_utils::random_p2pkh_address}; use bitcoin::consensus::{Decodable, Encodable}; use bitcoin::{Block as BitcoinBlock, BlockHeader as Header}; use byteorder::{LittleEndian, ReadBytesExt}; use ic_btc_interface::{Flag, GetUtxosResponse, InitConfig, Network, Txid, UtxosFilter}; use ic_btc_interface::{OutPoint, Utxo}; +use ic_btc_test_utils::random_p2pkh_address; use ic_btc_types::{Block, BlockHash}; use ic_cdk::api::call::RejectionCode; use std::str::FromStr; use std::{collections::HashMap, io::BufReader, path::PathBuf}; use std::{fs::File, panic::catch_unwind}; + mod confirmation_counts; async fn process_chain(network: Network, blocks_file: &str, num_blocks: u32) { @@ -415,14 +416,15 @@ async fn testnet_10k_blocks() { #[async_std::test] async fn time_slices_large_block_with_multiple_transactions() { let network = Network::Regtest; + let btc_network = into_bitcoin_network(network); init(InitConfig { stability_threshold: Some(0), network: Some(network), ..Default::default() }); - let address_1 = random_p2pkh_address(network); - let address_2 = random_p2pkh_address(network); + let address_1 = random_p2pkh_address(btc_network).into(); + let address_2 = random_p2pkh_address(btc_network).into(); let tx_1 = TransactionBuilder::coinbase() .with_output(&address_1, 1000) @@ -779,19 +781,21 @@ async fn fee_percentiles_evaluation_helper() { let block_0 = { let fee = 1; let balance = 1000; + let network = Network::Regtest; + let btc_newtork = into_bitcoin_network(network); let tx_1 = TransactionBuilder::coinbase() - .with_output(&random_p2pkh_address(Network::Regtest), balance) + .with_output(&random_p2pkh_address(btc_newtork).into(), balance) .build(); let tx_2 = TransactionBuilder::new() .with_input(ic_btc_types::OutPoint { txid: tx_1.txid(), vout: 0, }) - .with_output(&random_p2pkh_address(Network::Regtest), balance - fee) + .with_output(&random_p2pkh_address(btc_newtork).into(), balance - fee) .build(); - BlockBuilder::with_prev_header(genesis_block(Network::Regtest).header()) + BlockBuilder::with_prev_header(genesis_block(network).header()) .with_transaction(tx_1) .with_transaction(tx_2.clone()) .build() diff --git a/canister/src/unstable_blocks/outpoints_cache.rs b/canister/src/unstable_blocks/outpoints_cache.rs index 455861cb..0b5555fd 100644 --- a/canister/src/unstable_blocks/outpoints_cache.rs +++ b/canister/src/unstable_blocks/outpoints_cache.rs @@ -234,8 +234,10 @@ struct TxOutInfo { #[cfg(test)] mod test { use super::*; - use crate::test_utils::{random_p2pkh_address, BlockBuilder, TransactionBuilder}; + use crate::test_utils::{BlockBuilder, TransactionBuilder}; + use crate::types::into_bitcoin_network; use ic_btc_interface::Network; + use ic_btc_test_utils::random_p2pkh_address; #[test] fn empty_when_initialized() { @@ -246,8 +248,9 @@ mod test { #[test] fn caches_outpoint_info_of_blocks() { let network = Network::Mainnet; - let address_1 = random_p2pkh_address(network); - let address_2 = random_p2pkh_address(network); + let btc_network = into_bitcoin_network(network); + let address_1 = random_p2pkh_address(btc_network).into(); + let address_2 = random_p2pkh_address(btc_network).into(); let tx_0 = TransactionBuilder::coinbase() .with_output(&address_1, 1000) @@ -373,8 +376,9 @@ mod test { #[test] fn errors_if_tx_out_is_not_found() { let network = Network::Mainnet; - let address_1 = random_p2pkh_address(network); - let address_2 = random_p2pkh_address(network); + let btc_network = into_bitcoin_network(network); + let address_1 = random_p2pkh_address(btc_network).into(); + let address_2 = random_p2pkh_address(btc_network).into(); let tx_0 = TransactionBuilder::coinbase() .with_output(&address_1, 1000) @@ -411,8 +415,9 @@ mod test { #[test] fn inserting_a_block_is_atomic() { let network = Network::Mainnet; - let address_1 = random_p2pkh_address(network); - let address_2 = random_p2pkh_address(network); + let btc_network = into_bitcoin_network(network); + let address_1 = random_p2pkh_address(btc_network).into(); + let address_2 = random_p2pkh_address(btc_network).into(); let tx_0 = TransactionBuilder::coinbase() .with_output(&address_1, 1000) diff --git a/canister/src/utxo_set.rs b/canister/src/utxo_set.rs index 4bd5c45a..f51f967c 100644 --- a/canister/src/utxo_set.rs +++ b/canister/src/utxo_set.rs @@ -569,10 +569,12 @@ fn default_should_time_slice() -> Box bool> { mod test { use super::*; use crate::runtime; - use crate::test_utils::{random_p2pkh_address, BlockBuilder, TransactionBuilder}; + use crate::test_utils::{BlockBuilder, TransactionBuilder}; + use crate::types::into_bitcoin_network; use crate::{address_utxoset::AddressUtxoSet, unstable_blocks::UnstableBlocks}; use bitcoin::blockdata::{opcodes::all::OP_RETURN, script::Builder}; use ic_btc_interface::Network; + use ic_btc_test_utils::random_p2pkh_address; use proptest::prelude::*; use std::collections::BTreeSet; @@ -658,8 +660,9 @@ mod test { } fn spending(network: Network) { - let address_1 = random_p2pkh_address(network); - let address_2 = random_p2pkh_address(network); + let btc_network = into_bitcoin_network(network); + let address_1 = random_p2pkh_address(btc_network).into(); + let address_2 = random_p2pkh_address(btc_network).into(); let mut utxo = UtxoSet::new(network); @@ -744,9 +747,11 @@ mod test { #[test] fn utxos_are_sorted_by_height() { - let address = random_p2pkh_address(Network::Testnet); + let network = Network::Testnet; + let btc_network = into_bitcoin_network(network); + let address: Address = random_p2pkh_address(btc_network).into(); - let mut utxo = UtxoSet::new(Network::Testnet); + let mut utxo = UtxoSet::new(network); // Insert some entries into the map with different heights in some random order. for height in [17u32, 0, 31, 4, 2].iter() { @@ -784,8 +789,9 @@ mod test { #[should_panic] fn inserting_same_outpoint_panics() { let network = Network::Testnet; + let btc_network = into_bitcoin_network(network); let mut utxo_set = UtxoSet::new(network); - let address = random_p2pkh_address(network); + let address = random_p2pkh_address(btc_network).into(); let tx_out_1 = TransactionBuilder::coinbase() .with_output(&address, 1000) @@ -810,9 +816,10 @@ mod test { #[test] fn addresses_with_empty_balances_are_removed() { let network = Network::Testnet; + let btc_network = into_bitcoin_network(network); let mut utxo_set = UtxoSet::new(network); - let address_1 = random_p2pkh_address(network); - let address_2 = random_p2pkh_address(network); + let address_1 = random_p2pkh_address(btc_network).into(); + let address_2 = random_p2pkh_address(btc_network).into(); let tx_1 = TransactionBuilder::coinbase() .with_output(&address_1, 1000) @@ -846,9 +853,10 @@ mod test { #[test] fn consuming_an_input_with_value_zero() { let network = Network::Testnet; + let btc_network = into_bitcoin_network(network); let mut utxo_set = UtxoSet::new(network); - let address_1 = random_p2pkh_address(network); - let address_2 = random_p2pkh_address(network); + let address_1 = random_p2pkh_address(btc_network).into(); + let address_2 = random_p2pkh_address(btc_network).into(); let tx_1 = TransactionBuilder::coinbase() .with_output(&address_1, 1000) @@ -891,9 +899,10 @@ mod test { #[test] fn ingest_block_test_block_ingestion_stats() { let network = Network::Testnet; + let btc_network = into_bitcoin_network(network); let mut utxo_set = UtxoSet::new(network); - let address_1 = random_p2pkh_address(network); - let address_2 = random_p2pkh_address(network); + let address_1 = random_p2pkh_address(btc_network).into(); + let address_2 = random_p2pkh_address(btc_network).into(); let tx_1 = TransactionBuilder::coinbase() .with_output(&address_1, 1000) .with_output(&address_1, 0) // an input with zero value @@ -946,10 +955,11 @@ mod test { Just(Network::Testnet), Just(Network::Regtest), ]) { + let btc_network = into_bitcoin_network(network); - let address_1 = random_p2pkh_address(network); - let address_2 = random_p2pkh_address(network); - let address_3 = random_p2pkh_address(network); + let address_1 = random_p2pkh_address(btc_network).into(); + let address_2 = random_p2pkh_address(btc_network).into(); + let address_3 = random_p2pkh_address(btc_network).into(); let mut utxo_set = UtxoSet::new(network); diff --git a/test-utils/src/lib.rs b/test-utils/src/lib.rs index 1360744f..a5662cbb 100644 --- a/test-utils/src/lib.rs +++ b/test-utils/src/lib.rs @@ -226,7 +226,7 @@ impl TransactionBuilder { // Use default of 50 BTC. vec![TxOut { value: 50_0000_0000, - script_pubkey: random_p2pkh_address(Network::Regtest).script_pubkey(), + script_pubkey: random_p2pkh_address(bitcoin::Network::Regtest).script_pubkey(), }] } else { self.output @@ -274,8 +274,10 @@ fn solve(header: &mut Header) { #[cfg(test)] mod test { mod transaction_builder { - use crate::{random_p2pkh_address, TransactionBuilder}; + use crate::types::into_bitcoin_network; + use crate::TransactionBuilder; use bitcoin::{Network, OutPoint}; + use ic_btc_test_utils::random_p2pkh_address; #[test] fn new_build() { @@ -302,7 +304,9 @@ mod test { expected = "A call `with_input` should not be possible if `coinbase` was called" )] fn with_input_panic() { - let address = random_p2pkh_address(Network::Regtest); + let network = Network::Regtest; + let btc_network = into_bitcoin_network(network); + let address = random_p2pkh_address(btc_network); let coinbase_tx = TransactionBuilder::coinbase() .with_output(&address, 1000) .build(); @@ -313,7 +317,9 @@ mod test { #[test] fn with_output() { - let address = random_p2pkh_address(Network::Regtest); + let network = Network::Regtest; + let btc_network = into_bitcoin_network(network); + let address = random_p2pkh_address(btc_network); let tx = TransactionBuilder::coinbase() .with_output(&address, 1000) .build(); @@ -328,8 +334,10 @@ mod test { #[test] fn with_output_2() { - let address_0 = random_p2pkh_address(Network::Regtest); - let address_1 = random_p2pkh_address(Network::Regtest); + let network = Network::Regtest; + let btc_network = into_bitcoin_network(network); + let address_0 = random_p2pkh_address(btc_network); + let address_1 = random_p2pkh_address(btc_network); let tx = TransactionBuilder::coinbase() .with_output(&address_0, 1000) .with_output(&address_1, 2000) @@ -347,7 +355,9 @@ mod test { #[test] fn with_input() { - let address = random_p2pkh_address(Network::Regtest); + let network = Network::Regtest; + let btc_network = into_bitcoin_network(network); + let address = random_p2pkh_address(btc_network); let coinbase_tx = TransactionBuilder::coinbase() .with_output(&address, 1000) .build(); @@ -367,7 +377,9 @@ mod test { #[test] fn with_input_2() { - let address = random_p2pkh_address(Network::Regtest); + let network = Network::Regtest; + let btc_network = into_bitcoin_network(network); + let address = random_p2pkh_address(btc_network); let coinbase_tx_0 = TransactionBuilder::coinbase() .with_output(&address, 1000) .build();