Skip to content

Commit eb97995

Browse files
e2e: adds e2e tests for the arknote
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
1 parent 2fedc9d commit eb97995

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed

e2e-tests/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ edition = "2021"
77
ark-bdk-wallet = { path = "../ark-bdk-wallet" }
88
ark-client = { path = "../ark-client" }
99
ark-core = { path = "../ark-core" }
10+
ark-grpc = { path = "../ark-grpc" }
1011
async-stream = "0.3"
1112
bdk_esplora = "0.19.0"
1213
bdk_wallet = "1.0.0-beta.5"

e2e-tests/tests/e2e_arknote.rs

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#![allow(clippy::unwrap_used)]
2+
3+
use ark_core::ArkNote;
4+
use bitcoin::key::Secp256k1;
5+
use bitcoin::Amount;
6+
use common::init_tracing;
7+
use common::set_up_client;
8+
use common::Nigiri;
9+
use rand::thread_rng;
10+
use std::sync::Arc;
11+
12+
mod common;
13+
14+
#[tokio::test]
15+
#[ignore]
16+
pub async fn e2e_arknote_redemption() {
17+
init_tracing();
18+
let nigiri = Arc::new(Nigiri::new());
19+
20+
let secp = Secp256k1::new();
21+
22+
let (alice, _) = set_up_client("alice".to_string(), nigiri.clone(), secp.clone()).await;
23+
let alice_offchain_address = alice.get_offchain_address().unwrap().0;
24+
25+
tracing::info!(
26+
?alice_offchain_address,
27+
"Created Alice's wallet for ArkNote redemption test"
28+
);
29+
30+
let fund_amount = Amount::from_sat(1000);
31+
32+
// Create ArkNote using gRPC API
33+
let note = alice.create_arknote(fund_amount).await.unwrap();
34+
35+
tracing::info!(
36+
arknote_string = %note.to_encoded_string(),
37+
value = %fund_amount,
38+
"Created ArkNote using gRPC API for redemption test"
39+
);
40+
41+
let parsed_note = ArkNote::from_string(&note.to_encoded_string()).unwrap();
42+
assert_eq!(parsed_note.value(), fund_amount);
43+
assert!(note.status().confirmed);
44+
assert!(note.extra_witness().is_some());
45+
46+
// Verify tap tree is not empty
47+
let tap_tree = note.tap_tree();
48+
assert!(!tap_tree.is_empty());
49+
50+
// Verify outpoint creation
51+
let outpoint = note.outpoint();
52+
assert_eq!(outpoint.vout, 0);
53+
54+
// Verify TxOut creation
55+
let tx_out = note.to_tx_out();
56+
assert_eq!(tx_out.value, fund_amount);
57+
58+
// Redeem the ArkNote using the new redeem_note method
59+
let mut rng = thread_rng();
60+
let txid_opt = alice.redeem_note(&mut rng, note).await.unwrap();
61+
62+
assert!(
63+
txid_opt.is_some(),
64+
"Expected a transaction ID from ArkNote redemption"
65+
);
66+
let txid = txid_opt.unwrap();
67+
68+
tracing::info!(
69+
%txid,
70+
"Successfully redeemed ArkNote"
71+
);
72+
73+
// Verify the balance has been updated
74+
let balance = alice.offchain_balance().await.unwrap();
75+
tracing::info!(
76+
confirmed_balance = %balance.confirmed(),
77+
pending_balance = %balance.pending(),
78+
"Balance after ArkNote redemption"
79+
);
80+
81+
tracing::info!("ArkNote redemption test completed successfully");
82+
}

0 commit comments

Comments
 (0)