mirror of
https://github.com/RoboSats/taptrade-core.git
synced 2025-07-21 18:23:43 +00:00
add taproot descriptor test
This commit is contained in:
@ -205,6 +205,7 @@ async fn test_move_offer_to_active() -> Result<()> {
|
|||||||
payout_address: "1PayoutAddress".to_string(),
|
payout_address: "1PayoutAddress".to_string(),
|
||||||
musig_pub_nonce_hex: "musigPubNonceHex".to_string(),
|
musig_pub_nonce_hex: "musigPubNonceHex".to_string(),
|
||||||
musig_pubkey_hex: "musigPubkeyHex".to_string(),
|
musig_pubkey_hex: "musigPubkeyHex".to_string(),
|
||||||
|
taproot_pubkey_hex: "taprootPubkeyHex".to_string(),
|
||||||
};
|
};
|
||||||
|
|
||||||
// Call the move_offer_to_active function
|
// Call the move_offer_to_active function
|
||||||
|
@ -15,9 +15,16 @@ pub struct EscrowPsbtConstructionData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn aggregate_musig_pubkeys(maker_musig_pubkey: &str, taker_musig_pubkey: &str) -> Result<String> {
|
fn aggregate_musig_pubkeys(maker_musig_pubkey: &str, taker_musig_pubkey: &str) -> Result<String> {
|
||||||
let pubkeys: [MuSig2PubKey; 2] = [maker_musig_pubkey.parse()?, taker_musig_pubkey.parse()?];
|
let pubkeys: [MuSig2PubKey; 2] = [
|
||||||
|
maker_musig_pubkey
|
||||||
|
.parse()
|
||||||
|
.context("Error parsing musig pk 1")?,
|
||||||
|
taker_musig_pubkey
|
||||||
|
.parse()
|
||||||
|
.context("Error parsing musig pk 2")?,
|
||||||
|
];
|
||||||
|
|
||||||
let key_agg_ctx = KeyAggContext::new(pubkeys)?;
|
let key_agg_ctx = KeyAggContext::new(pubkeys).context("Error aggregating musig pubkeys")?;
|
||||||
let agg_pk: MuSig2PubKey = key_agg_ctx.aggregated_pubkey();
|
let agg_pk: MuSig2PubKey = key_agg_ctx.aggregated_pubkey();
|
||||||
|
|
||||||
Ok(agg_pk.to_string())
|
Ok(agg_pk.to_string())
|
||||||
@ -39,15 +46,27 @@ pub fn build_escrow_transaction_output_descriptor(
|
|||||||
// );
|
// );
|
||||||
let script_c: String = format!("and(pk({}),pk({}))", maker_pk, coordinator_pk);
|
let script_c: String = format!("and(pk({}),pk({}))", maker_pk, coordinator_pk);
|
||||||
let script_d = format!("and(pk({}),pk({}))", taker_pk, coordinator_pk);
|
let script_d = format!("and(pk({}),pk({}))", taker_pk, coordinator_pk);
|
||||||
let script_e = format!("and({},after(12228))", maker_pk);
|
let script_e = format!("and(pk({}),after(12228))", maker_pk);
|
||||||
let script_f = format!("and_v(and_v(v:{},v:{}),after(2048))", maker_pk, taker_pk);
|
let script_f = format!("and(and(pk({}),pk({})),after(2048))", maker_pk, taker_pk);
|
||||||
|
|
||||||
// let compiled_a = Concrete::<String>::from_str(&script_a)?.compile::<Tap>()?;
|
// let compiled_a = Concrete::<String>::from_str(&script_a)?.compile::<Tap>()?;
|
||||||
// let compiled_b = Concrete::<String>::from_str(&script_b)?.compile()?;
|
// let compiled_b = Concrete::<String>::from_str(&script_b)?.compile()?;
|
||||||
let compiled_c = Concrete::<String>::from_str(&script_c)?.compile::<Tap>()?;
|
let compiled_c = Concrete::<String>::from_str(&script_c)
|
||||||
let compiled_d = Concrete::<String>::from_str(&script_d)?.compile::<Tap>()?;
|
.context("Failed to parse script_c")?
|
||||||
let compiled_e = Concrete::<String>::from_str(&script_e)?.compile::<Tap>()?;
|
.compile::<Tap>()
|
||||||
let compiled_f = Concrete::<String>::from_str(&script_f)?.compile::<Tap>()?;
|
.context("Failed to compile script_c")?;
|
||||||
|
let compiled_d = Concrete::<String>::from_str(&script_d)
|
||||||
|
.context("Failed to parse script_d")?
|
||||||
|
.compile::<Tap>()
|
||||||
|
.context("Failed to compile script_d")?;
|
||||||
|
let compiled_e = Concrete::<String>::from_str(&script_e)
|
||||||
|
.context("Failed to parse script_e")?
|
||||||
|
.compile::<Tap>()
|
||||||
|
.context("Failed to compile script_e")?;
|
||||||
|
let compiled_f = Concrete::<String>::from_str(&script_f)
|
||||||
|
.context("Failed to parse script_f")?
|
||||||
|
.compile::<Tap>()
|
||||||
|
.context("Failed to compile script_f")?;
|
||||||
|
|
||||||
// Create TapTree leaves
|
// Create TapTree leaves
|
||||||
// let tap_leaf_a = TapTree::Leaf(Arc::new(compiled_a));
|
// let tap_leaf_a = TapTree::Leaf(Arc::new(compiled_a));
|
||||||
@ -70,7 +89,8 @@ pub fn build_escrow_transaction_output_descriptor(
|
|||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Create the descriptor
|
// Create the descriptor
|
||||||
let descriptor = Descriptor::new_tr(internal_agg_musig_key, Some(final_tap_tree))?;
|
let descriptor = Descriptor::new_tr(internal_agg_musig_key, Some(final_tap_tree))
|
||||||
|
.context("Error assembling escrow output descriptor")?;
|
||||||
|
|
||||||
debug!("Escrow descriptor: {}", descriptor.to_string());
|
debug!("Escrow descriptor: {}", descriptor.to_string());
|
||||||
Ok(descriptor.to_string())
|
Ok(descriptor.to_string())
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
|
use std::collections::btree_map::Range;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use bdk::bitcoin::Network;
|
use bdk::bitcoin::Network;
|
||||||
use bdk::database::MemoryDatabase;
|
use bdk::database::MemoryDatabase;
|
||||||
|
use bdk::keys::GeneratableKey;
|
||||||
use bdk::{blockchain::RpcBlockchain, Wallet};
|
use bdk::{blockchain::RpcBlockchain, Wallet};
|
||||||
async fn new_test_wallet(wallet_xprv: &str) -> CoordinatorWallet<MemoryDatabase> {
|
async fn new_test_wallet(wallet_xprv: &str) -> CoordinatorWallet<MemoryDatabase> {
|
||||||
dotenv().ok();
|
dotenv().ok();
|
||||||
@ -163,3 +165,36 @@ async fn test_invalid_bond_tx_low_fee_rate() {
|
|||||||
.to_string()
|
.to_string()
|
||||||
.contains("Bond fee rate too low"));
|
.contains("Bond fee rate too low"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_build_escrow_transaction_output_descriptor() {
|
||||||
|
// let seed: [u8; 32] = [
|
||||||
|
// 0x1b, 0x2d, 0x3d, 0x4d, 0x5d, 0x6d, 0x7d, 0x8d, 0x9d, 0xad, 0xbd, 0xcd, 0xdd, 0xed, 0xfd,
|
||||||
|
// 0x0d, 0x1d, 0x2d, 0x3d, 0x4d, 0x5d, 0x6d, 0x8d, 0x8d, 0x9d, 0xbd, 0xbd, 0xcd, 0xdd, 0xed,
|
||||||
|
// 0xfd, 0x0d,
|
||||||
|
// ];
|
||||||
|
// let xprv = ExtendedPrivKey::new_master(Network::Testnet, &seed).unwrap();
|
||||||
|
// let pubkey = xprv
|
||||||
|
// .to_keypair(&secp256k1::Secp256k1::new())
|
||||||
|
// .x_only_public_key()
|
||||||
|
// .0
|
||||||
|
// .to_string();
|
||||||
|
// dbg!(&pubkey);
|
||||||
|
let escrow_data = EscrowPsbtConstructionData {
|
||||||
|
taproot_pubkey_hex_maker:
|
||||||
|
"b709f64da734e04e35b129a65a7fae361cad8a9458d1abc4f0b45b7661a42fca".to_string(),
|
||||||
|
taproot_pubkey_hex_taker:
|
||||||
|
"4987f3de20a9b1fa6f76c6758934953a8d615e415f1a656f0f6563694b53107d".to_string(),
|
||||||
|
musig_pubkey_hex_maker: "b943789a0c9a16e27d7a9d27077eacd0fc664f01ff795f64e0f5fd257b4019e9"
|
||||||
|
.to_string(),
|
||||||
|
musig_pubkey_hex_taker: "a2e78a076b9ecfec8a8eb71ad5f0f29592d1559424f35ac25a0130d1a2880733"
|
||||||
|
.to_string(),
|
||||||
|
};
|
||||||
|
let coordinator_pk = XOnlyPublicKey::from_str(
|
||||||
|
"d8e204cdaebec4c5a637311072c865858dc4f142b3848b8e6dde4143476535b5",
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
let result = build_escrow_transaction_output_descriptor(&escrow_data, &coordinator_pk);
|
||||||
|
dbg!(&result);
|
||||||
|
assert!(result.is_ok());
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user