Skip to content

Commit

Permalink
add invoice_reuse test
Browse files Browse the repository at this point in the history
St333p committed Dec 18, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 10cf79f commit 69bf802
Showing 2 changed files with 70 additions and 29 deletions.
46 changes: 46 additions & 0 deletions tests/transfers.rs
Original file line number Diff line number Diff line change
@@ -569,6 +569,52 @@ fn same_transfer_twice_update_witnesses() {
let _ = wlt_1.transfer(invoice, None, Some(1000), true, None);
}

#[rstest]
#[ignore = "probably not a bug, but still unexpected"]
#[case(TT::Blinded)]
#[case(TT::Witness)]
fn invoice_reuse(#[case] transfer_type: TransferType) {
println!("transfer_type {transfer_type:?}");

initialize();

let mut wlt_1 = get_wallet(&DescriptorType::Wpkh);
let mut wlt_2 = get_wallet(&DescriptorType::Wpkh);

let asset_info = AssetInfo::default_nia(vec![500, 400]);
let (contract_id, iface_type_name) =
wlt_1.issue_with_info(asset_info, wlt_1.close_method(), vec![None, None]);

let amount = 300;
let invoice = wlt_2.invoice(
contract_id,
&iface_type_name,
amount,
wlt_2.close_method(),
transfer_type.into(),
);
wlt_1.send_to_invoice(&mut wlt_2, invoice.clone(), Some(500), None, None);
let (consignment, _) = wlt_1.send_to_invoice(&mut wlt_2, invoice, Some(600), None, None);

wlt_1.check_allocations(
contract_id,
&iface_type_name,
AssetSchema::Nia,
vec![200, 100],
false,
);
wlt_2.check_allocations(
contract_id,
&iface_type_name,
AssetSchema::Nia,
vec![amount, amount],
false,
);

// with TransferType::Blinded this fails: bundle for 1st transfer is also included
assert_eq!(consignment.bundles.len(), 1);
}

#[test]
fn accept_0conf() {
initialize();
53 changes: 24 additions & 29 deletions tests/utils/helpers.rs
Original file line number Diff line number Diff line change
@@ -107,6 +107,15 @@ pub enum InvoiceType {
Witness,
}

impl From<TransferType> for InvoiceType {
fn from(transfer_type: TransferType) -> Self {
match transfer_type {
TransferType::Blinded => InvoiceType::Blinded(None),
TransferType::Witness => InvoiceType::Witness,
}
}
}

/// RGB asset-specific information to color a transaction
#[derive(Clone, Debug)]
pub struct AssetColoringInfo {
@@ -1256,22 +1265,13 @@ impl TestWallet {
sats: u64,
report: Option<&Report>,
) -> (Transfer, Tx) {
let invoice = match transfer_type {
TransferType::Blinded => recv_wlt.invoice(
contract_id,
iface_type_name,
amount,
recv_wlt.close_method(),
InvoiceType::Blinded(None),
),
TransferType::Witness => recv_wlt.invoice(
contract_id,
iface_type_name,
amount,
recv_wlt.close_method(),
InvoiceType::Witness,
),
};
let invoice = recv_wlt.invoice(
contract_id,
iface_type_name,
amount,
recv_wlt.close_method(),
transfer_type.into(),
);
self.send_to_invoice(recv_wlt, invoice, Some(sats), None, report)
}

@@ -1302,22 +1302,17 @@ impl TestWallet {
AssetSchema::Nia | AssetSchema::Cfa => {
let allocations =
self.contract_fungible_allocations(contract_id, iface_type_name, false);
if allocations.len() != expected_fungible_allocations.len() {
println!("allocations: {allocations:?}");
assert_eq!(allocations.len(), expected_fungible_allocations.len());
}
let mut actual_fungible_allocations = allocations
.iter()
.map(|a| a.state.value())
.collect::<Vec<_>>();
let mut expected_fungible_allocations = expected_fungible_allocations.clone();
actual_fungible_allocations.sort();
expected_fungible_allocations.sort();
assert_eq!(actual_fungible_allocations, expected_fungible_allocations);
assert!(allocations
.iter()
.all(|a| a.seal.method() == self.close_method()));
for amount in expected_fungible_allocations {
assert_eq!(
allocations
.iter()
.filter(|a| a.state == Amount::from(amount))
.count(),
1
);
}
}
AssetSchema::Uda => {
let allocations = self.contract_data_allocations(contract_id, iface_type_name);

0 comments on commit 69bf802

Please sign in to comment.