Skip to content

Commit

Permalink
XC-229: Fix bitcoin_get_utxos mock network assert
Browse files Browse the repository at this point in the history
  • Loading branch information
lpahlavi committed Dec 3, 2024
1 parent f55087f commit 38ec6a7
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions rs/bitcoin/mock/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use candid::candid_method;
use ic_btc_interface::{
Address, GetCurrentFeePercentilesRequest, GetUtxosRequest, GetUtxosResponse,
MillisatoshiPerByte, Network, Utxo, UtxosFilterInRequest,
MillisatoshiPerByte, Network, NetworkInRequest, Utxo, UtxosFilterInRequest,
};
use ic_cdk::api::management_canister::bitcoin::{BitcoinNetwork, SendTransactionRequest};
use ic_cdk_macros::{init, update};
Expand Down Expand Up @@ -87,7 +87,7 @@ fn set_tip_height(tip_height: u32) {
#[update]
fn bitcoin_get_utxos(utxos_request: GetUtxosRequest) -> GetUtxosResponse {
read_state(|s| {
assert_eq!(utxos_request.network, s.network.into());
assert_network_equivalent(&utxos_request.network, &s.network);

let mut utxos = s
.address_to_utxos
Expand Down Expand Up @@ -238,3 +238,17 @@ fn check_candid_interface_compatibility() {
candid_parser::utils::CandidSource::File(old_interface.as_path()),
);
}

fn assert_network_equivalent(lhs: &NetworkInRequest, rhs: &Network) {
match lhs {
&NetworkInRequest::Mainnet | &NetworkInRequest::mainnet => {
assert_eq!(rhs, &Network::Mainnet)
}
&NetworkInRequest::Testnet | &NetworkInRequest::testnet => {
assert_eq!(rhs, &Network::Testnet)
}
&NetworkInRequest::Regtest | &NetworkInRequest::regtest => {
assert_eq!(rhs, &Network::Regtest)
}
}
}

0 comments on commit 38ec6a7

Please sign in to comment.