Skip to content

Commit

Permalink
static wallets
Browse files Browse the repository at this point in the history
  • Loading branch information
CAGS295 committed Nov 3, 2023
1 parent a592e07 commit e651c91
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 29 deletions.
48 changes: 19 additions & 29 deletions romeo/tests/tests/deposit.rs
Original file line number Diff line number Diff line change
@@ -1,45 +1,35 @@
use std::{thread::sleep, time::Duration};

use anyhow::Result;
use bdk::bitcoin::psbt::serialize::Serialize;
use reqwest::blocking::Client;
use sbtc_cli::commands::{
broadcast::{broadcast_tx, BroadcastArgs},
deposit::{build_deposit_tx, DepositArgs},
};

use super::bitcoin_client::{electrs_url, generate_blocks};

const WALLET_0_P2TR_ADDRESS: &str =
"bcrt1pte5zmd7qzj4hdu45lh9mmdm0nwq3z35pwnxmzkwld6y0a8g83nnqhj6vc0";
const WALLET_0_P2WPKH_ADDRESS: &str =
"bcrt1q3tj2fr9scwmcw3rq5m6jslva65f2rqjxfrjz47";
const WALLET_0_P2WPKH_WIF: &str =
"cTyHitzs3VRnNxrpwxo3fXTTe569wHNUs57tQM7Z1FrzUDNB5mqm";
const WALLET_1_P2WPKH_WIF: &str =
"cNcXK2r8bNdWJQymtAW8tGS7QHNtFFvG5CdXqhhT752u29WspXRM";
const WALLET_1_STX_ADDRESS: &str = "ST2ST2H80NP5C9SPR4ENJ1Z9CDM9PKAJVPYWPQZ50";
const WALLET_1_P2WPKH_ADDRESS: &str =
"bcrt1q3zl64vadtuh3vnsuhdgv6pm93n82ye8q6cr4ch";

use bdk::{
bitcoin::PrivateKey,
bitcoin::{psbt::serialize::Serialize, PrivateKey},
blockchain::{
ConfigurableBlockchain, ElectrumBlockchain, ElectrumBlockchainConfig,
},
database::MemoryDatabase,
template::P2Wpkh,
SyncOptions, Wallet,
};
use reqwest::blocking::Client;
use sbtc_cli::commands::{
broadcast::{broadcast_tx, BroadcastArgs},
deposit::{build_deposit_tx, DepositArgs},
};

use super::{
bitcoin_client::{electrs_url, generate_blocks},
KeyType::*,
WALLETS,
};

#[test]
fn broadcast_deposit() -> Result<()> {
let client = Client::new();
{
generate_blocks(1, &client, WALLET_0_P2WPKH_ADDRESS);
generate_blocks(1, &client, WALLET_1_P2WPKH_ADDRESS);
generate_blocks(1, &client, WALLETS[0][P2wpkh].address);
generate_blocks(1, &client, WALLETS[1][P2wpkh].address);
// pads blocks to get rewards.
generate_blocks(100, &client, WALLET_0_P2WPKH_ADDRESS);
generate_blocks(100, &client, WALLETS[0][P2wpkh].address);
};

let electrum_url = electrs_url();
Expand All @@ -57,7 +47,7 @@ fn broadcast_deposit() -> Result<()> {
})
.unwrap();

let private_key = PrivateKey::from_wif(WALLET_0_P2WPKH_WIF)?;
let private_key = PrivateKey::from_wif(WALLETS[0][P2wpkh].wif)?;

let wallet = Wallet::new(
P2Wpkh(private_key),
Expand All @@ -82,11 +72,11 @@ fn broadcast_deposit() -> Result<()> {
let tx = {
let args = DepositArgs {
node_url: electrum_url.clone(),
wif: WALLET_1_P2WPKH_WIF.into(),
wif: WALLETS[1][P2wpkh].wif.into(),
network: bdk::bitcoin::Network::Regtest,
recipient: WALLET_1_STX_ADDRESS.into(),
recipient: WALLETS[1][Stacks].address.into(),
amount,
sbtc_wallet: WALLET_0_P2TR_ADDRESS.into(),
sbtc_wallet: WALLETS[0][P2tr].address.into(),
};

build_deposit_tx(&args).unwrap()
Expand Down
93 changes: 93 additions & 0 deletions romeo/tests/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,96 @@
pub mod bitcoin_client;
pub mod deposit;
pub mod stacks_client;
pub mod withdrawal;

use std::ops::Index;

struct KeyRing {
address: &'static str,
#[allow(unused)]
private_key: &'static str,
#[allow(unused)]
public_key: &'static str,
wif: &'static str,
}

#[repr(usize)]
pub(crate) enum KeyType {
#[allow(unused)]
P2pkh,
P2tr,
P2wpkh,
Stacks,
}

impl Index<KeyType> for [KeyRing] {
type Output = KeyRing;

fn index(&self, index: KeyType) -> &Self::Output {
&self[index as usize]
}
}

type FullRing = [KeyRing; 4];

const WALLETS: [FullRing; 2] = [[
KeyRing {
address: "n4dN5bVeriVW9gKZMfNqHn21aJkwTM8QPH",
private_key:
"a38cbb2ca77786b9d37fd0feb34df2e423130ec74d0189736bf52561562c9565",
public_key:
"03bcb048737cc2f239db2b3db6eae00263861bfbe5b2577e573e3c32f61a46ac8c",
wif: "cT4cy7eAKPjhaZ3h72GdpbrtrFzsUQShZEcM5eNCiHrfuzmoXvBt",
},
KeyRing {
address:
"bcrt1pte5zmd7qzj4hdu45lh9mmdm0nwq3z35pwnxmzkwld6y0a8g83nnqhj6vc0",
private_key:
"6596d84eef5b73430712dde88fbf6a1d96f97f5f241ab1bf247d04bc241dd28d",
public_key:
"034a45bd09cc815da165b8987a7263a2c4111b79951562fc5c0989e9cdf5ceded2",
wif: "cQzBGXC4YACb61oCwxDK9F1a8nxCjUiBZ5rBUaUJAeQvTytUBBFi",
},
KeyRing {
address: "bcrt1q3tj2fr9scwmcw3rq5m6jslva65f2rqjxfrjz47",
private_key:
"bea4ecfec5cfa1e965ee1b3465ca4deff4f04b36a1fb5286a07660d5158789fb",
public_key:
"03ab37f5b606931d7828855affe75199d952bc6174b4a23861b7ac94132210508c",
wif: "cTyHitzs3VRnNxrpwxo3fXTTe569wHNUs57tQM7Z1FrzUDNB5mqm",
},
KeyRing {
address: "ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM",
private_key:
"753b7cc01a1a2e86221266a154af739463fce51219d97e4f856cd7200c3bd2a6",
public_key:
"0390a5cac7c33fda49f70bc1b0866fa0ba7a9440d9de647fecb8132ceb76a94dfa",
wif: "cRWawjcDj2J28jczAtjJGKs1pzFxM6V6tJHNZp3WrYoLhr2PLMVB",
},
],[
KeyRing {
address: "mvTQYAcGa17CTxWcJhRPXn6qecBQLSWuaJ",
private_key: "a1fc751f0bb64c01adb7c60dbe966e2bb9e262aa23bf41158e64c2142fc4fa78",
public_key: "030ede1203e7873388f81a7801df5714152c72273507a0fe0609e3f223fb6f56ae",
wif: "cT1agfN8XrWY1bSW5DGWpXUWYFjrmKWeJHyU79Kk66dPnMC6fw3L"
},
KeyRing {
address: "bcrt1prm3lfhsgnnxe0def39n7xpa9etqrjfdxeqnar9xegqu4c044td0sfktyxq",
private_key: "73f560df660fb11c9aff8178971acd67e75ecb4e5683f5e9bdc52fb3c967c7a3",
public_key: "02aaed53527e3771645a050568a3cc9820361899c36f689cac15b57cc7885f3ca1",
wif: "cRU7KinnTuwaJ9N6WFDg2YdhtKcU5vxTSKFtgmT2gTtFvNfhnXx9"
},
KeyRing {
address: "bcrt1q3zl64vadtuh3vnsuhdgv6pm93n82ye8q6cr4ch",
private_key: "1ec64b686cf94a4d8c741ed34db074b86d91c0971a38fe6e161b402489d7a74e",
public_key: "03969ff3e2bf7f2f73dc903cd11442032c8c7811d57d96ce327ee89c9edea63fa8",
wif: "cNcXK2r8bNdWJQymtAW8tGS7QHNtFFvG5CdXqhhT752u29WspXRM"
},
KeyRing {
address: "ST2ST2H80NP5C9SPR4ENJ1Z9CDM9PKAJVPYWPQZ50",
private_key: "6a7c24ee77649c0cc314864596a6bd1addf3efb93bd63bcdb99be08437420847",
public_key: "038386f533650ff82714eeac9438faaa8a20ada5dd68a7eb8e00cf46cab5325a68",
wif: "cR9hENRFiuHzKpj9B3QCTBrt19c5ZCJKHJwYcqj5dfB6aKyf6ndm"
}

]];

0 comments on commit e651c91

Please sign in to comment.