Created
December 21, 2018 12:50
-
-
Save Siimone/cbb5b6a199e7da7fe40dae55fa628464 to your computer and use it in GitHub Desktop.
redeem_htlc_with_secret - Bitcoin HTLC - COMIT
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[test] | |
fn redeem_htlc_with_secret() { | |
let _ = pretty_env_logger::try_init(); | |
let docker = Cli::default(); | |
let container = docker.run(BitcoinCore::default()); | |
let client = tc_bitcoincore_client::new(&container); | |
client.generate(432).unwrap().unwrap(); | |
let (txid, vout, input_amount, htlc, _, secret, keypair, _) = fund_htlc(&client); | |
assert!( | |
htlc.can_be_unlocked_with(secret, keypair).is_ok(), | |
"Should be unlockable with the given secret and secret_key" | |
); | |
let alice_addr: Address = client.get_new_address().unwrap().unwrap().into(); | |
let fee = BitcoinQuantity::from_satoshi(1000); | |
let redeem_tx = PrimedTransaction { | |
inputs: vec![PrimedInput::new( | |
OutPoint { txid, vout: vout.n }, | |
input_amount, | |
htlc.unlock_with_secret(keypair, &secret), | |
)], | |
output_address: alice_addr.clone(), | |
locktime: 0, | |
} | |
.sign_with_fee(fee); | |
let redeem_tx_hex = serialize_hex(&redeem_tx).unwrap(); | |
let raw_redeem_tx = rpc::SerializedRawTransaction(redeem_tx_hex); | |
let rpc_redeem_txid = client.send_raw_transaction(raw_redeem_tx).unwrap().unwrap(); | |
client.generate(1).unwrap().unwrap(); | |
assert!( | |
client | |
.find_utxo_at_tx_for_address(&rpc_redeem_txid, &alice_addr) | |
.is_some(), | |
"utxo should exist after redeeming htlc" | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment