Skip to content

Commit

Permalink
add regtest network parameter to be used in int-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rajarshimaitra committed Feb 28, 2024
1 parent 43887a1 commit 95cbf45
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/network/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pub mod electrum;
pub enum Chain {
Bitcoin,
BitcoinTestnet,
BitcoinRegtest,
Liquid,
LiquidTestnet,
}
12 changes: 7 additions & 5 deletions src/swaps/bitcoin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,12 +237,14 @@ impl BtcSwapScript {
let script = self.to_script()?;
let mut network = match network {
Chain::Bitcoin => Network::Bitcoin,
_ => Network::Testnet,
Chain::BitcoinRegtest => Network::Regtest,
Chain::BitcoinTestnet => Network::Testnet,
_ => {
return Err(Error::Protocol(
"Liquid chain used for Bitcoin operations".to_string(),
))
}
};
// Use regtest for integration tests
if cfg!(test) {
network = Network::Regtest;
}
match self.swap_type {
SwapType::Submarine => Ok(Address::p2shwsh(&script, network)),
SwapType::ReverseSubmarine => Ok(Address::p2wsh(&script, network)),
Expand Down
4 changes: 2 additions & 2 deletions src/swaps/boltz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@ impl CreateSwapResponse {
chain: Chain,
) -> Result<(), Error> {
match chain {
Chain::Bitcoin | Chain::BitcoinTestnet => {
Chain::Bitcoin | Chain::BitcoinTestnet | Chain::BitcoinRegtest => {
let boltz_sub_script =
BtcSwapScript::submarine_from_str(&self.get_redeem_script()?)?;

Expand Down Expand Up @@ -847,7 +847,7 @@ impl CreateSwapResponse {
}
}
match chain {
Chain::Bitcoin | Chain::BitcoinTestnet => {
Chain::Bitcoin | Chain::BitcoinTestnet | Chain::BitcoinRegtest => {
let boltz_rev_script = BtcSwapScript::reverse_from_str(&self.get_redeem_script()?)?;

let constructed_rev_script = BtcSwapScript {
Expand Down
2 changes: 1 addition & 1 deletion tests/regtest-claim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ fn test_reverse_claim_regtest() {
};

// Send coin the swapscript address and confirm tx
let swap_addrs = swap_script.to_address(Chain::BitcoinTestnet).unwrap();
let swap_addrs = swap_script.to_address(Chain::BitcoinRegtest).unwrap();
let spk = swap_addrs.script_pubkey();
println!("spk: {}", spk);
test_framework.send_coins(&swap_addrs, Amount::from_sat(10000));
Expand Down
2 changes: 1 addition & 1 deletion tests/regtest-refund.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ fn test_submarine_refund_regtest() {
};

// Send coin the swapscript address and confirm tx
let swap_addrs = swap_script.to_address(Chain::BitcoinTestnet).unwrap();
let swap_addrs = swap_script.to_address(Chain::BitcoinRegtest).unwrap();
test_framework.send_coins(&swap_addrs, Amount::from_sat(10000));
test_framework.generate_blocks(1);

Expand Down

0 comments on commit 95cbf45

Please sign in to comment.