Skip to content

Commit 2ff2ab6

Browse files
committed
add new entrypoint for testing ChannelDetails serialization
1 parent 2d0d114 commit 2ff2ab6

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

bindings/src/adaptors/primitives.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ macro_rules! array_struct{
213213
}
214214
}
215215

216+
/// Length-prefixed script.
216217
array_struct!(FFIScript);
217218
impl FFIScript {
218219
pub fn to_script(&self) -> Script {

bindings/src/ffi_test_utils.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ use hex;
66
use crate::adaptors::primitives::FFIEvents;
77
use crate::utils::into_fixed_buffer;
88
use crate::Out;
9-
use lightning::ln::channelmanager::{PaymentHash, PaymentSecret, PaymentPreimage};
9+
use lightning::ln::channelmanager::{PaymentHash, PaymentSecret, PaymentPreimage, ChannelDetails};
1010
use bitcoin_hashes::core::time::Duration;
1111
use lightning::chain::keysinterface::SpendableOutputDescriptor;
1212
use bitcoin::TxOut;
13+
use lightning::ln::features::InitFeatures;
1314

1415

1516
// These tests should be used for asserting that the wrapper can receive expected items from rust.
@@ -71,5 +72,27 @@ ffi! {
7172
let buf = unsafe_block!("The buffer lives as long as this function, the length is within the buffer and the buffer won't be read before initialization" => buf_out.as_uninit_bytes_mut(buf_len));
7273
into_fixed_buffer(&mut e, buf, &mut actual_len)
7374
}
75+
fn test_channel_details_serialization(buf_out: Out<u8>, buf_len: usize, actual_len: Out<usize>) -> FFIResult {
76+
let mut ret = Vec::with_capacity(1);
77+
let id_ref= &hex::decode("4141414141414141414141414141414141414141414141414141414141414142").unwrap();
78+
let mut id = [0u8;32];
79+
id.copy_from_slice(id_ref);
80+
let remote_network_id = bitcoin::secp256k1::key::PublicKey::from_slice(&hex::decode("02aca35d6de21baefaf65db590611fabd42ed4d52683c36caff58761d309314f65").unwrap()).unwrap();
81+
let counterparty_features = InitFeatures::known();
82+
let detail = ChannelDetails{
83+
channel_id: id,
84+
short_channel_id: Some(3),
85+
remote_network_id,
86+
counterparty_features: counterparty_features,
87+
channel_value_satoshis: 5454,
88+
user_id: 2223,
89+
outbound_capacity_msat: 2828,
90+
inbound_capacity_msat: 9292,
91+
is_live: false
92+
};
93+
ret.push(detail);
94+
let buf = unsafe_block!("The buffer lives as long as this function, the length is within the buffer and the buffer won't be read before initialization" => buf_out.as_uninit_bytes_mut(buf_len));
95+
into_fixed_buffer(&mut ret, buf, &mut actual_len)
96+
}
7497

7598
}

0 commit comments

Comments
 (0)