forked from arkade-os/rust-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathe2e_sub_dust.rs
More file actions
87 lines (67 loc) · 2.39 KB
/
e2e_sub_dust.rs
File metadata and controls
87 lines (67 loc) · 2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#![allow(clippy::unwrap_used)]
use crate::common::wait_until_balance;
use bitcoin::key::Secp256k1;
use bitcoin::Amount;
use common::init_tracing;
use common::set_up_client;
use common::Nigiri;
use rand::thread_rng;
use std::sync::Arc;
use std::time::Duration;
mod common;
#[tokio::test]
#[ignore]
pub async fn send_subdust_amount() {
init_tracing();
let nigiri = Arc::new(Nigiri::new());
let secp = Secp256k1::new();
let mut rng = thread_rng();
let (alice, _) = set_up_client("alice".to_string(), nigiri.clone(), secp.clone()).await;
let (bob, _) = set_up_client("bob".to_string(), nigiri.clone(), secp).await;
let alice_fund_amount = Amount::ONE_BTC;
nigiri
.faucet_fund(&alice.get_boarding_address().unwrap(), alice_fund_amount)
.await;
alice.settle(&mut rng, false).await.unwrap();
tokio::time::sleep(Duration::from_secs(2)).await;
let alice_offchain_balance = alice.offchain_balance().await.unwrap();
assert_eq!(alice_offchain_balance.confirmed(), alice_fund_amount);
// Send Bob a sub-dust amount.
let sub_dust_amount = Amount::ONE_SAT;
let (bob_offchain_address, _) = bob.get_offchain_address().unwrap();
alice
.send_vtxo(bob_offchain_address, sub_dust_amount)
.await
.unwrap();
// Available balance does not include sub-dust amounts, so we cannot wait on Bob's balance.
wait_until_balance(&alice, Amount::ZERO, alice_fund_amount - sub_dust_amount)
.await
.unwrap();
let (alice_offchain_address, _) = alice.get_offchain_address().unwrap();
bob.send_vtxo(alice_offchain_address, sub_dust_amount)
.await
.expect_err("should not be able to send sub-dust amount");
bob.settle(&mut rng, true)
.await
.expect_err("should not be able to board sub-dust amount");
// Send Bob a regular VTXO.
let regular_amount = Amount::from_sat(100_000);
alice
.send_vtxo(bob_offchain_address, regular_amount)
.await
.unwrap();
wait_until_balance(
&alice,
Amount::ZERO,
alice_fund_amount - regular_amount - sub_dust_amount,
)
.await
.unwrap();
wait_until_balance(&bob, Amount::ZERO, regular_amount)
.await
.unwrap();
bob.settle(&mut rng, true).await.unwrap();
wait_until_balance(&bob, regular_amount + sub_dust_amount, Amount::ZERO)
.await
.unwrap();
}