From 4a242d69e435b4faf0f05767967ad77b24d03f03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zoe=20Faltib=C3=A0?= Date: Wed, 11 Sep 2024 11:57:39 +0200 Subject: [PATCH 1/6] tapret_wlt_receiving_opret: de-ignore and improve to show bug --- tests/transfers.rs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/tests/transfers.rs b/tests/transfers.rs index 4a0efa4..08187f1 100644 --- a/tests/transfers.rs +++ b/tests/transfers.rs @@ -736,7 +736,6 @@ fn mainnet_wlt_receiving_test_asset() { } #[test] -#[ignore = "this was working, fix needed"] fn tapret_wlt_receiving_opret() { initialize(); @@ -776,4 +775,26 @@ fn tapret_wlt_receiving_opret() { 1000, None, ); + + println!("4th transfer"); + wlt_2.send( + &mut wlt_1, + TransferType::Blinded, + contract_id, + &iface_type_name, + 560, + 1000, + None, + ); + + println!("5th transfer"); + wlt_1.send( + &mut wlt_2, + TransferType::Blinded, + contract_id, + &iface_type_name, + 600, + 1000, + None, + ); } From 305e50cf70e89bd494634886330d9efba00ce828 Mon Sep 17 00:00:00 2001 From: Dr Maxim Orlovsky Date: Tue, 8 Oct 2024 04:27:31 +0000 Subject: [PATCH 2/6] update branches to the most recent versions --- Cargo.lock | 72 ++++++++++++++++++++--------------------------- amplify-nonasync | 2 +- bp-esplora-client | 2 +- bp-wallet | 2 +- rgb | 2 +- rgb-core | 2 +- rgb-interfaces | 2 +- rgb-std | 2 +- 8 files changed, 37 insertions(+), 49 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0c075b6..a9d58ce 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -30,7 +30,7 @@ dependencies = [ name = "aluvm" version = "0.11.0-beta.8" dependencies = [ - "amplify 4.7.0", + "amplify", "ascii-armor", "baid64", "blake3", @@ -60,18 +60,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "amplify" -version = "5.0.0-beta.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d41888768802fc62c27b46427127b119e8a16e1f1f59495aced93a340f55eb25" -dependencies = [ - "amplify_derive", - "amplify_num", - "ascii", - "wasm-bindgen", -] - [[package]] name = "amplify_apfloat" version = "0.3.1" @@ -148,7 +136,7 @@ dependencies = [ name = "ascii-armor" version = "0.7.2" dependencies = [ - "amplify 4.7.0", + "amplify", "baid64", "base85", "sha2", @@ -207,7 +195,7 @@ dependencies = [ name = "baid64" version = "0.2.2" dependencies = [ - "amplify 4.7.0", + "amplify", "base64", "mnemonic", "sha2", @@ -317,7 +305,7 @@ dependencies = [ name = "bp-consensus" version = "0.11.0-beta.8" dependencies = [ - "amplify 4.7.0", + "amplify", "chrono", "commit_verify", "secp256k1", @@ -330,7 +318,7 @@ dependencies = [ name = "bp-core" version = "0.11.0-beta.8" dependencies = [ - "amplify 4.7.0", + "amplify", "bp-consensus", "bp-dbc", "bp-seals", @@ -347,7 +335,7 @@ dependencies = [ name = "bp-dbc" version = "0.11.0-beta.8" dependencies = [ - "amplify 4.7.0", + "amplify", "base85", "bp-consensus", "commit_verify", @@ -360,7 +348,7 @@ dependencies = [ name = "bp-derive" version = "0.11.0-beta.8" dependencies = [ - "amplify 4.7.0", + "amplify", "bp-consensus", "bp-invoice", "commit_verify", @@ -374,7 +362,7 @@ dependencies = [ name = "bp-electrum" version = "0.11.0-beta.8.1" dependencies = [ - "amplify 4.7.0", + "amplify", "bp-std", "byteorder", "libc", @@ -391,7 +379,7 @@ dependencies = [ name = "bp-esplora" version = "0.11.0-beta.8" dependencies = [ - "amplify 4.7.0", + "amplify", "bp-std", "log", "reqwest", @@ -405,7 +393,7 @@ dependencies = [ name = "bp-invoice" version = "0.11.0-beta.8" dependencies = [ - "amplify 4.7.0", + "amplify", "bech32", "bp-consensus", "commit_verify", @@ -416,7 +404,7 @@ dependencies = [ name = "bp-seals" version = "0.11.0-beta.8" dependencies = [ - "amplify 4.7.0", + "amplify", "baid64", "bp-consensus", "bp-dbc", @@ -431,7 +419,7 @@ dependencies = [ name = "bp-std" version = "0.11.0-beta.8" dependencies = [ - "amplify 4.7.0", + "amplify", "bp-consensus", "bp-derive", "bp-invoice", @@ -447,7 +435,7 @@ dependencies = [ name = "bp-wallet" version = "0.11.0-beta.8" dependencies = [ - "amplify 4.7.0", + "amplify", "bp-electrum", "bp-esplora", "bp-std", @@ -546,7 +534,7 @@ dependencies = [ name = "commit_encoding_derive" version = "0.11.0-beta.8" dependencies = [ - "amplify 4.7.0", + "amplify", "amplify_syn", "proc-macro2", "quote", @@ -557,7 +545,7 @@ dependencies = [ name = "commit_verify" version = "0.11.0-beta.8" dependencies = [ - "amplify 4.7.0", + "amplify", "commit_encoding_derive", "rand", "ripemd", @@ -673,7 +661,7 @@ dependencies = [ name = "descriptors" version = "0.11.0-beta.8" dependencies = [ - "amplify 4.7.0", + "amplify", "bp-derive", "indexmap 2.4.0", "serde", @@ -1303,9 +1291,9 @@ dependencies = [ [[package]] name = "nonasync" -version = "0.1.0" +version = "0.1.2" dependencies = [ - "amplify 5.0.0-beta.1", + "amplify", "log", ] @@ -1468,7 +1456,7 @@ dependencies = [ name = "psbt" version = "0.11.0-beta.8" dependencies = [ - "amplify 4.7.0", + "amplify", "base64", "bp-core", "bp-derive", @@ -1599,7 +1587,7 @@ name = "rgb-core" version = "0.11.0-beta.8" dependencies = [ "aluvm", - "amplify 4.7.0", + "amplify", "baid64", "bp-core", "chrono", @@ -1619,7 +1607,7 @@ name = "rgb-interfaces" version = "0.11.0-beta.8" dependencies = [ "aluvm", - "amplify 4.7.0", + "amplify", "bp-core", "chrono", "getrandom", @@ -1635,7 +1623,7 @@ dependencies = [ name = "rgb-invoice" version = "0.11.0-beta.8" dependencies = [ - "amplify 4.7.0", + "amplify", "baid64", "bp-core", "bp-invoice", @@ -1654,7 +1642,7 @@ dependencies = [ name = "rgb-psbt" version = "0.11.0-beta.8" dependencies = [ - "amplify 4.7.0", + "amplify", "baid64", "bp-core", "bp-std", @@ -1670,7 +1658,7 @@ dependencies = [ name = "rgb-runtime" version = "0.11.0-beta.8" dependencies = [ - "amplify 4.7.0", + "amplify", "baid64", "bp-core", "bp-electrum", @@ -1696,7 +1684,7 @@ name = "rgb-schemata" version = "0.11.0-beta.8" dependencies = [ "aluvm", - "amplify 4.7.0", + "amplify", "bp-core", "chrono", "rgb-interfaces", @@ -1713,7 +1701,7 @@ name = "rgb-std" version = "0.11.0-beta.8" dependencies = [ "aluvm", - "amplify 4.7.0", + "amplify", "ascii-armor", "baid64", "base85", @@ -1736,7 +1724,7 @@ dependencies = [ name = "rgb-tests" version = "0.1.0" dependencies = [ - "amplify 4.7.0", + "amplify", "bitcoin_hashes", "bp-core", "bp-electrum", @@ -2175,7 +2163,7 @@ checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" name = "strict_encoding" version = "2.7.0" dependencies = [ - "amplify 4.7.0", + "amplify", "half", "serde", "strict_encoding_derive", @@ -2197,7 +2185,7 @@ dependencies = [ name = "strict_types" version = "2.7.0" dependencies = [ - "amplify 4.7.0", + "amplify", "ascii-armor", "baid64", "half", @@ -2573,7 +2561,7 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" name = "vesper-lang" version = "0.1.0" dependencies = [ - "amplify 4.7.0", + "amplify", "strict_encoding", ] diff --git a/amplify-nonasync b/amplify-nonasync index b1bf354..1a5ecbf 160000 --- a/amplify-nonasync +++ b/amplify-nonasync @@ -1 +1 @@ -Subproject commit b1bf3542060beabe3dcdf66517be6ee3eb2ac302 +Subproject commit 1a5ecbf8d9eb8616cf0c091ceee6ff2fcc941780 diff --git a/bp-esplora-client b/bp-esplora-client index d930558..4cdad88 160000 --- a/bp-esplora-client +++ b/bp-esplora-client @@ -1 +1 @@ -Subproject commit d930558ab30ecc2cf6d76f268fbc94aea35c7a26 +Subproject commit 4cdad88d83e660a06aae5457cd2c7eeed369baa5 diff --git a/bp-wallet b/bp-wallet index 7487a1c..f850c3b 160000 --- a/bp-wallet +++ b/bp-wallet @@ -1 +1 @@ -Subproject commit 7487a1c10c07ec313f1b8d77ce5acf41a8389cea +Subproject commit f850c3b3f98e1ade4b720c3c0c6e4799bb3ccb7f diff --git a/rgb b/rgb index 56f8d4c..07c55b3 160000 --- a/rgb +++ b/rgb @@ -1 +1 @@ -Subproject commit 56f8d4cdedf85c728505d07d8452a3916cb70565 +Subproject commit 07c55b3aff4ba3d0763807ffb92e8e8af72c2ea6 diff --git a/rgb-core b/rgb-core index 8be4962..e2a451f 160000 --- a/rgb-core +++ b/rgb-core @@ -1 +1 @@ -Subproject commit 8be49626a968a45fc868db1e1454095b75349c17 +Subproject commit e2a451fa793fe5403b4114b5ed5e9e47c69674cd diff --git a/rgb-interfaces b/rgb-interfaces index 5acc09c..673e970 160000 --- a/rgb-interfaces +++ b/rgb-interfaces @@ -1 +1 @@ -Subproject commit 5acc09c2387f8d1f7eb0393983415d2d523225b4 +Subproject commit 673e970f5655ac5f7bd577a410ef4ad02bf3f62e diff --git a/rgb-std b/rgb-std index 94aeb57..94b5ebc 160000 --- a/rgb-std +++ b/rgb-std @@ -1 +1 @@ -Subproject commit 94aeb57a3db7dfe89b8c03bd4a90a8eabae09ff3 +Subproject commit 94b5ebc6b998b4aa2321513c08b4ff2aebfd2a56 From 828756cff74ac5427da7d514bd918ee3b713f08f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zoe=20Faltib=C3=A0?= Date: Tue, 8 Oct 2024 12:02:46 +0200 Subject: [PATCH 3/6] fixes to use develop branches --- tests/transfers.rs | 12 ++--- tests/utils/helpers.rs | 109 +++++++++++++++++++++++++++++++++++------ tests/utils/mod.rs | 5 +- 3 files changed, 103 insertions(+), 23 deletions(-) diff --git a/tests/transfers.rs b/tests/transfers.rs index 08187f1..ca9a0aa 100644 --- a/tests/transfers.rs +++ b/tests/transfers.rs @@ -551,7 +551,7 @@ fn ln_transfers() { }; let (fascia, _asset_beneficiaries) = wlt_1.color_psbt(&mut psbt, coloring_info.clone()); wlt_1.consume_fascia(fascia.clone(), psbt.txid()); - wlt_1.debug_logs(contract_id, &iface_type_name); + wlt_1.debug_logs(contract_id, &iface_type_name, AllocationFilter::WalletAll); let htlc_vout = 2; let htlc_rgb_amt = 200; @@ -580,7 +580,7 @@ fn ln_transfers() { }; let (fascia, _asset_beneficiaries) = wlt_1.color_psbt(&mut psbt, coloring_info.clone()); wlt_1.consume_fascia(fascia.clone(), psbt.txid()); - wlt_1.debug_logs(contract_id, &iface_type_name); + wlt_1.debug_logs(contract_id, &iface_type_name, AllocationFilter::WalletAll); println!("\n3. fake HTLC TX"); let witness_id = fascia.witness_id(); @@ -607,7 +607,7 @@ fn ln_transfers() { }; let (fascia, _asset_beneficiaries) = wlt_1.color_psbt(&mut psbt, coloring_info); wlt_1.consume_fascia(fascia.clone(), psbt.txid()); - wlt_1.debug_logs(contract_id, &iface_type_name); + wlt_1.debug_logs(contract_id, &iface_type_name, AllocationFilter::WalletAll); println!("\n4. fake commitment TX (no HTLCs)"); let beneficiaries = vec![ @@ -630,7 +630,7 @@ fn ln_transfers() { }; let (fascia, _asset_beneficiaries) = wlt_1.color_psbt(&mut psbt, coloring_info); wlt_1.consume_fascia(fascia.clone(), psbt.txid()); - wlt_1.debug_logs(contract_id, &iface_type_name); + wlt_1.debug_logs(contract_id, &iface_type_name, AllocationFilter::WalletAll); let mut old_psbt = psbt.clone(); println!("\n5. fake commitment TX (1 HTLC)"); @@ -656,7 +656,7 @@ fn ln_transfers() { }; let (fascia, _asset_beneficiaries) = wlt_1.color_psbt(&mut psbt, coloring_info.clone()); wlt_1.consume_fascia(fascia.clone(), psbt.txid()); - wlt_1.debug_logs(contract_id, &iface_type_name); + wlt_1.debug_logs(contract_id, &iface_type_name, AllocationFilter::WalletAll); println!("\n6. fake HTLC TX"); let witness_id = fascia.witness_id(); @@ -683,7 +683,7 @@ fn ln_transfers() { }; let (fascia, _asset_beneficiaries) = wlt_1.color_psbt(&mut psbt, coloring_info); wlt_1.consume_fascia(fascia.clone(), psbt.txid()); - wlt_1.debug_logs(contract_id, &iface_type_name); + wlt_1.debug_logs(contract_id, &iface_type_name, AllocationFilter::WalletAll); println!("\n7. broadcast old PSBT"); let tx = wlt_1.sign_finalize(&mut old_psbt); diff --git a/tests/utils/helpers.rs b/tests/utils/helpers.rs index 0c0d58e..45b004b 100644 --- a/tests/utils/helpers.rs +++ b/tests/utils/helpers.rs @@ -12,6 +12,44 @@ enum WalletAccount { Public(XpubAccount), } +pub enum AllocationFilter { + Stock, + Wallet, + WalletAll, +} + +enum Filter<'w> { + NoWallet, + Wallet(&'w RgbWallet>), + WalletAll(&'w RgbWallet>), +} + +impl<'w> AssignmentsFilter for Filter<'w> { + fn should_include(&self, outpoint: impl Into, id: Option) -> bool { + match self { + Filter::Wallet(wallet) => wallet + .wallet() + .filter_unspent() + .should_include(outpoint, id), + _ => true, + } + } +} +impl<'w> Filter<'w> { + fn comment(&self, outpoint: XOutpoint) -> &'static str { + let outpoint = outpoint + .into_bp() + .into_bitcoin() + .expect("liquid is not yet supported"); + match self { + Filter::Wallet(rgb) if rgb.wallet().is_unspent(outpoint) => "", + Filter::WalletAll(rgb) if rgb.wallet().is_unspent(outpoint) => "-- unspent", + Filter::WalletAll(rgb) if rgb.wallet().has_outpoint(outpoint) => "-- spent", + _ => "-- third-party", + } + } +} + #[derive(Debug, Copy, Clone, PartialEq, Eq)] pub enum DescriptorType { Wpkh, @@ -905,7 +943,7 @@ impl TestWallet { contract_iface: &ContractIface, ) -> Vec { contract_iface - .fungible(fname!("assetOwner"), &self.wallet.wallet().filter()) + .fungible(fname!("assetOwner"), Filter::Wallet(&self.wallet)) .unwrap() .collect() } @@ -915,12 +953,23 @@ impl TestWallet { contract_iface: &ContractIface, ) -> Vec { contract_iface - .data(fname!("assetOwner"), &self.wallet.wallet().filter()) + .data(fname!("assetOwner"), Filter::Wallet(&self.wallet)) .unwrap() .collect() } - pub fn debug_logs(&self, contract_id: ContractId, iface_type_name: &TypeName) { + pub fn debug_logs( + &self, + contract_id: ContractId, + iface_type_name: &TypeName, + filter: AllocationFilter, + ) { + let filter = match filter { + AllocationFilter::WalletAll => Filter::WalletAll(&self.wallet), + AllocationFilter::Wallet => Filter::Wallet(&self.wallet), + AllocationFilter::Stock => Filter::NoWallet, + }; + let contract = self.contract_iface(contract_id, iface_type_name); println!("Global:"); @@ -933,30 +982,60 @@ impl TestWallet { } println!("\nOwned:"); + fn witness( + allocation: &OutputAssignment, + contract: &ContractIface>, + ) -> String { + allocation + .witness + .and_then(|w| contract.witness_info(w)) + .map(|info| format!("{} ({})", info.id, info.ord)) + .unwrap_or_else(|| s!("~")) + } for owned in &contract.iface.assignments { + println!(" State \t{:78}\tWitness", "Seal"); println!(" {}:", owned.name); - if let Ok(allocations) = - contract.fungible(owned.name.clone(), &self.wallet.wallet().filter()) - { + if let Ok(allocations) = contract.fungible(owned.name.clone(), &filter) { for allocation in allocations { println!( - " amount={}, utxo={}, witness={:?} # owned by the wallet", + " {: >9}\t{}\t{} {}", allocation.state.value(), allocation.seal, - allocation.witness + witness(&allocation, &contract), + filter.comment(allocation.seal.to_outpoint()) ); } } - if let Ok(allocations) = contract.fungible( - owned.name.clone(), - &FilterExclude(&self.wallet.wallet().filter()), - ) { + if let Ok(allocations) = contract.data(owned.name.clone(), &filter) { for allocation in allocations { println!( - " amount={}, utxo={}, witness={:?} # owner unknown", - allocation.state.value(), + " {: >9}\t{}\t{} {}", + allocation.state, + allocation.seal, + witness(&allocation, &contract), + filter.comment(allocation.seal.to_outpoint()) + ); + } + } + if let Ok(allocations) = contract.attachments(owned.name.clone(), &filter) { + for allocation in allocations { + println!( + " {: >9}\t{}\t{} {}", + allocation.state, + allocation.seal, + witness(&allocation, &contract), + filter.comment(allocation.seal.to_outpoint()) + ); + } + } + if let Ok(allocations) = contract.rights(owned.name.clone(), &filter) { + for allocation in allocations { + println!( + " {: >9}\t{}\t{} {}", + "right", allocation.seal, - allocation.witness + witness(&allocation, &contract), + filter.comment(allocation.seal.to_outpoint()) ); } } diff --git a/tests/utils/mod.rs b/tests/utils/mod.rs index 136a0f4..7f9aa9b 100644 --- a/tests/utils/mod.rs +++ b/tests/utils/mod.rs @@ -62,6 +62,7 @@ pub use psbt::{ pub use psrgbt::{RgbExt, RgbInExt, RgbPsbt, TxParams}; pub use rand::RngCore; pub use rgb::{ + interface::AssignmentsFilter, invoice::Pay2Vout, persistence::{ContractStateRead, MemContract, MemContractState, Stock}, resolvers::AnyResolver, @@ -83,8 +84,8 @@ pub use rgbstd::{ stl::{ AssetSpec, Attachment, Details, MediaType, Name, ProofOfReserves, RicardianContract, Ticker, }, - Allocation, Amount, ContractId, GlobalStateType, Layer1, Operation, OwnedFraction, Precision, - Schema, TokenIndex, TxoSeal, XChain, + Allocation, Amount, ContractId, GlobalStateType, KnownState, Layer1, Operation, + OutputAssignment, OwnedFraction, Precision, Schema, TokenIndex, TxoSeal, XChain, }; pub use rstest::rstest; pub use schemata::{CollectibleFungibleAsset, NonInflatableAsset, UniqueDigitalAsset}; From 2f03be59133136cffc11d0c963f63e4cc4e37664 Mon Sep 17 00:00:00 2001 From: Dr Maxim Orlovsky Date: Tue, 8 Oct 2024 04:27:31 +0000 Subject: [PATCH 4/6] Update to new develop branches with rgb-std/275 fix --- bp-core | 2 +- bp-std | 2 +- bp-wallet | 2 +- rgb | 2 +- rgb-core | 2 +- rgb-interfaces | 2 +- rgb-schemata | 2 +- rgb-std | 2 +- tests/transfers.rs | 4 ++-- tests/utils/helpers.rs | 7 ++++--- tests/utils/mod.rs | 1 + tests/validation.rs | 12 ++++++------ 12 files changed, 21 insertions(+), 19 deletions(-) diff --git a/bp-core b/bp-core index 923f728..8f23033 160000 --- a/bp-core +++ b/bp-core @@ -1 +1 @@ -Subproject commit 923f728cefd2682462387e7f16b2967e22860237 +Subproject commit 8f230338300174f2d77c11c2879572a42115b53f diff --git a/bp-std b/bp-std index 6dd564c..eb393cd 160000 --- a/bp-std +++ b/bp-std @@ -1 +1 @@ -Subproject commit 6dd564c90452ad8b358a6f9f3262114227a88d58 +Subproject commit eb393cdb1c234cb76c100cea67b87c0cbc85fab8 diff --git a/bp-wallet b/bp-wallet index f850c3b..a6862d0 160000 --- a/bp-wallet +++ b/bp-wallet @@ -1 +1 @@ -Subproject commit f850c3b3f98e1ade4b720c3c0c6e4799bb3ccb7f +Subproject commit a6862d09db91dc7269111a1269380ce9b91bbe9e diff --git a/rgb b/rgb index 07c55b3..3111cd0 160000 --- a/rgb +++ b/rgb @@ -1 +1 @@ -Subproject commit 07c55b3aff4ba3d0763807ffb92e8e8af72c2ea6 +Subproject commit 3111cd0b3f98ff8b802325ee0739aa32b84b91ec diff --git a/rgb-core b/rgb-core index e2a451f..0450760 160000 --- a/rgb-core +++ b/rgb-core @@ -1 +1 @@ -Subproject commit e2a451fa793fe5403b4114b5ed5e9e47c69674cd +Subproject commit 0450760dbae554de0d7623691aed7630f1b60a60 diff --git a/rgb-interfaces b/rgb-interfaces index 673e970..a2ec738 160000 --- a/rgb-interfaces +++ b/rgb-interfaces @@ -1 +1 @@ -Subproject commit 673e970f5655ac5f7bd577a410ef4ad02bf3f62e +Subproject commit a2ec73876ee02180d04c86e88665f63cc52ab3da diff --git a/rgb-schemata b/rgb-schemata index 954cfd8..a42b9f8 160000 --- a/rgb-schemata +++ b/rgb-schemata @@ -1 +1 @@ -Subproject commit 954cfd867e963f1f4c39eea3067fd2183d26f896 +Subproject commit a42b9f8364e5c7723db72f4ab94525ad02c90a06 diff --git a/rgb-std b/rgb-std index 94b5ebc..08a8c95 160000 --- a/rgb-std +++ b/rgb-std @@ -1 +1 @@ -Subproject commit 94b5ebc6b998b4aa2321513c08b4ff2aebfd2a56 +Subproject commit 08a8c95e675186fb1e99283293c15554f2ff8882 diff --git a/tests/transfers.rs b/tests/transfers.rs index ca9a0aa..bb33278 100644 --- a/tests/transfers.rs +++ b/tests/transfers.rs @@ -771,7 +771,7 @@ fn tapret_wlt_receiving_opret() { TransferType::Blinded, contract_id, &iface_type_name, - 300, + 290, 1000, None, ); @@ -793,7 +793,7 @@ fn tapret_wlt_receiving_opret() { TransferType::Blinded, contract_id, &iface_type_name, - 600, + 570, 1000, None, ); diff --git a/tests/utils/helpers.rs b/tests/utils/helpers.rs index 45b004b..51cfb80 100644 --- a/tests/utils/helpers.rs +++ b/tests/utils/helpers.rs @@ -859,7 +859,8 @@ impl TestWallet { let mut cs_path = self.wallet_dir.join("consignments"); std::fs::create_dir_all(&cs_path).unwrap(); - cs_path.push(consignment.consignment_id().to_string()); + let consignment_id = consignment.consignment_id(); + cs_path.push(consignment_id.to_string()); cs_path.set_extension("yaml"); let mut file = std::fs::File::options() .read(true) @@ -872,7 +873,7 @@ impl TestWallet { let tx = self.sign_finalize(&mut psbt); let txid = tx.txid().to_string(); - println!("transfer txid: {txid}"); + println!("transfer txid: {txid}, consignment: {consignment_id}"); let mut tx_path = self.wallet_dir.join("transactions"); std::fs::create_dir_all(&tx_path).unwrap(); @@ -897,7 +898,7 @@ impl TestWallet { self.sync(); let resolver = self.get_resolver(); let validate_start = Instant::now(); - let validated_consignment = consignment.validate(&resolver, self.testnet()).unwrap(); + let validated_consignment = consignment.validate(&resolver, self.testnet()).map_err(|(status, _)| status).unwrap(); let validate_duration = validate_start.elapsed(); if let Some(report) = report { report.write_duration(validate_duration); diff --git a/tests/utils/mod.rs b/tests/utils/mod.rs index 7f9aa9b..8203483 100644 --- a/tests/utils/mod.rs +++ b/tests/utils/mod.rs @@ -21,6 +21,7 @@ pub use std::{ fmt::{self, Display}, fs::OpenOptions, io::Write, + num::NonZeroU32, path::{PathBuf, MAIN_SEPARATOR}, process::{Command, Stdio}, str::FromStr, diff --git a/tests/validation.rs b/tests/validation.rs index c43df13..4fb7f19 100644 --- a/tests/validation.rs +++ b/tests/validation.rs @@ -76,9 +76,9 @@ impl Scenario { witness_id_3 => MockResolvePubWitness::Success(tx_3), ], pub_witness_ords: map![ - witness_id_1 => MockResolvePubWitnessOrd::Success(WitnessOrd::Mined(WitnessPos::new(106, 1726062111).unwrap())), - witness_id_2 => MockResolvePubWitnessOrd::Success(WitnessOrd::Mined(WitnessPos::new(108, 1726062111).unwrap())), - witness_id_3 => MockResolvePubWitnessOrd::Success(WitnessOrd::Mined(WitnessPos::new(110, 1726062112).unwrap())), + witness_id_1 => MockResolvePubWitnessOrd::Success(WitnessOrd::Mined(WitnessPos::bitcoin(NonZeroU32::new(106).unwrap(), 1726062111).unwrap())), + witness_id_2 => MockResolvePubWitnessOrd::Success(WitnessOrd::Mined(WitnessPos::bitcoin(NonZeroU32::new(108).unwrap(), 1726062111).unwrap())), + witness_id_3 => MockResolvePubWitnessOrd::Success(WitnessOrd::Mined(WitnessPos::bitcoin(NonZeroU32::new(110).unwrap(), 1726062112).unwrap())), ], } } @@ -96,9 +96,9 @@ impl Scenario { witness_id_3 => MockResolvePubWitness::Success(tx_3), ], pub_witness_ords: map![ - witness_id_1 => MockResolvePubWitnessOrd::Success(WitnessOrd::Mined(WitnessPos::new(105, 1726062423).unwrap())), - witness_id_2 => MockResolvePubWitnessOrd::Success(WitnessOrd::Mined(WitnessPos::new(106, 1726062423).unwrap())), - witness_id_3 => MockResolvePubWitnessOrd::Success(WitnessOrd::Mined(WitnessPos::new(106, 1726062423).unwrap())), + witness_id_1 => MockResolvePubWitnessOrd::Success(WitnessOrd::Mined(WitnessPos::bitcoin(NonZeroU32::new(105).unwrap(), 1726062423).unwrap())), + witness_id_2 => MockResolvePubWitnessOrd::Success(WitnessOrd::Mined(WitnessPos::bitcoin(NonZeroU32::new(106).unwrap(), 1726062423).unwrap())), + witness_id_3 => MockResolvePubWitnessOrd::Success(WitnessOrd::Mined(WitnessPos::bitcoin(NonZeroU32::new(106).unwrap(), 1726062423).unwrap())), ], } } From 709c20d2256b3c65ecc537fa97ba12eb7ba671fb Mon Sep 17 00:00:00 2001 From: k0k0ne Date: Wed, 18 Sep 2024 12:07:47 +0800 Subject: [PATCH 5/6] feat: add check_fungible_history check_send_to_oneself --- tests/transfers.rs | 130 +++++++++++++++++++++++++++++++++++++++++ tests/utils/helpers.rs | 36 ++++++++++++ tests/utils/mod.rs | 5 +- 3 files changed, 169 insertions(+), 2 deletions(-) diff --git a/tests/transfers.rs b/tests/transfers.rs index bb33278..4e7ce79 100644 --- a/tests/transfers.rs +++ b/tests/transfers.rs @@ -798,3 +798,133 @@ fn tapret_wlt_receiving_opret() { None, ); } + +#[test] +fn check_fungible_history() { + initialize(); + + let mut wlt_1 = get_wallet(&DescriptorType::Wpkh); + let mut wlt_2 = get_wallet(&DescriptorType::Wpkh); + + println!("Wallets created: wlt_1 and wlt_2"); + + let amount = 100000; + println!("Initial amount: {}", amount); + + let (contract_id, iface_type_name) = wlt_1.issue_nia(amount, wlt_1.close_method(), None); + println!( + "Contract issued - ID: {:?}, Interface type: {}", + contract_id, iface_type_name + ); + + let initial_height = get_height(); + println!("Initial height: {}", initial_height); + + let history = wlt_1.fungible_history(contract_id, iface_type_name.clone()); + TestWallet::debug_fungible_history(&history); + assert_eq!(history.len(), 0); + + let amount_transfer = 200; + println!("Transfer amount: {}", amount_transfer); + + let invoice = wlt_2.invoice( + contract_id, + &iface_type_name, + amount_transfer, + wlt_2.close_method(), + InvoiceType::Witness, + ); + println!("Invoice created: {:?}", invoice); + + let (consignment, _) = wlt_1.transfer(invoice.clone(), None, Some(1234)); + + let height = get_height(); + println!("Height: {}", height); + + wlt_2.accept_transfer(consignment); + + mine(false); + wlt_1.sync(); + wlt_2.sync(); + + let height = get_height(); + println!("Height: {}", height); + + let history = wlt_1.fungible_history(contract_id, iface_type_name.clone()); + println!("History 1:"); + TestWallet::debug_fungible_history(&history); + + assert_eq!( + history.values().next().unwrap().state_change, + AmountChange::Dec(Amount::from(200_u64)) + ); + + println!("Balance 1:"); + wlt_1.debug_logs(contract_id, &iface_type_name.clone()); + + let history = wlt_2.fungible_history(contract_id, iface_type_name.clone()); + println!("History 2:"); + TestWallet::debug_fungible_history(&history); + assert_eq!( + history.values().next().unwrap().state_change, + AmountChange::Inc(Amount::from(200_u64)) + ); + + println!("Balance 2:"); + wlt_2.debug_logs(contract_id, &iface_type_name.clone()); +} + +#[test] +fn send_to_oneself() { + println!("Starting test: self_transfer_example"); + initialize(); + + let mut wlt = get_wallet(&DescriptorType::Wpkh); + println!("Wallet created: wlt"); + + let initial_amount = 100000; + println!("Initial amount: {}", initial_amount); + + let (contract_id, iface_type_name) = wlt.issue_nia(initial_amount, wlt.close_method(), None); + println!( + "Contract issued - ID: {:?}, Interface type: {}", + contract_id, iface_type_name + ); + + let history = wlt.fungible_history(contract_id, iface_type_name.clone()); + + TestWallet::debug_fungible_history(&history); + + let amount_transfer = 300; // Amount to transfer to self + println!("Transfer amount: {}", amount_transfer); + + let invoice = wlt.invoice( + contract_id, + &iface_type_name, + amount_transfer, + wlt.close_method(), + InvoiceType::Witness, + ); + println!("Invoice created: {:?}", invoice); + + let (consignment, _) = wlt.transfer(invoice.clone(), None, None); + + let height = get_height(); + println!("Height: {}", height); + + wlt.accept_transfer(consignment); // Accepting transfer to self + + mine(false); + wlt.sync(); + + let height = get_height(); + println!("Height after sync: {}", height); + + let history = wlt.fungible_history(contract_id, iface_type_name.clone()); + println!("Final History:"); + TestWallet::debug_fungible_history(&history); + assert!(!history.is_empty()); + + println!("Balance:"); + wlt.debug_logs(contract_id, &iface_type_name.clone()); +} diff --git a/tests/utils/helpers.rs b/tests/utils/helpers.rs index 51cfb80..46bfa0c 100644 --- a/tests/utils/helpers.rs +++ b/tests/utils/helpers.rs @@ -959,6 +959,14 @@ impl TestWallet { .collect() } + pub fn fungible_history( + &self, + contract_id: ContractId, + iface: impl Into, + ) -> HashMap> { + self.wallet.fungible_history(contract_id, iface).unwrap() + } + pub fn debug_logs( &self, contract_id: ContractId, @@ -1055,6 +1063,34 @@ impl TestWallet { println!("\nWallet total balance: {} ṩ", bp_runtime.balance()); } + pub fn debug_fungible_history(history: &HashMap>) { + println!("Amount\tCounterparty\tWitness Id"); + for (id, op) in history { + let (amount, cparty, more) = match op.state_change { + AmountChange::Dec(amt) => ( + format!("-{}", amt.value()), + op.beneficiaries.first(), + op.beneficiaries.len().saturating_sub(1), + ), + AmountChange::Zero => continue, + AmountChange::Inc(amt) => ( + format!("{}", amt.value()), + op.payers.first(), + op.payers.len().saturating_sub(1), + ), + }; + let more = if more > 0 { + format!(" (+{more})") + } else { + s!("") + }; + let cparty = cparty + .map(XOutputSeal::to_string) + .unwrap_or_else(|| s!("none")); + println!("{},{}\t{}{}\t{}", amount, op.state_change, cparty, more, id); + } + } + #[allow(clippy::too_many_arguments)] pub fn send( &mut self, diff --git a/tests/utils/mod.rs b/tests/utils/mod.rs index 8203483..d6edeff 100644 --- a/tests/utils/mod.rs +++ b/tests/utils/mod.rs @@ -63,7 +63,7 @@ pub use psbt::{ pub use psrgbt::{RgbExt, RgbInExt, RgbPsbt, TxParams}; pub use rand::RngCore; pub use rgb::{ - interface::AssignmentsFilter, + interface::{AmountChange, IfaceOp, IfaceRef}, invoice::Pay2Vout, persistence::{ContractStateRead, MemContract, MemContractState, Stock}, resolvers::AnyResolver, @@ -71,7 +71,8 @@ pub use rgb::{ validation::{Failure, ResolveWitness, Scripts, Validity, WitnessResolverError}, vm::{WitnessOrd, WitnessPos, XWitnessTx}, BlindingFactor, DescriptorRgb, GenesisSeal, GraphSeal, Identity, RgbDescr, RgbKeychain, - RgbWallet, TapretKey, TransferParams, Transition, WalletProvider, XOutpoint, XWitnessId, + RgbWallet, TapretKey, TransferParams, Transition, WalletProvider, XOutpoint, XOutputSeal, + XWitnessId, }; pub use rgbstd::{ containers::{BuilderSeal, ConsignmentExt, Fascia, FileContent, Kit, Transfer, ValidKit}, From de79df859041ea4e453dcb1f6abb40522544f6a2 Mon Sep 17 00:00:00 2001 From: k0k0ne Date: Mon, 23 Sep 2024 12:29:46 +0800 Subject: [PATCH 6/6] new history api test demo --- tests/transfers.rs | 62 +++++++++++++---------- tests/utils/helpers.rs | 112 ++++++++++++++++++++++++++++++----------- tests/utils/mod.rs | 3 +- 3 files changed, 122 insertions(+), 55 deletions(-) diff --git a/tests/transfers.rs b/tests/transfers.rs index 4e7ce79..ddc01d6 100644 --- a/tests/transfers.rs +++ b/tests/transfers.rs @@ -1,5 +1,6 @@ pub mod utils; +use rgb::interface::OpDirection; use utils::*; type TT = TransferType; @@ -817,12 +818,21 @@ fn check_fungible_history() { contract_id, iface_type_name ); + mine(false); + wlt_1.sync(); + wlt_2.sync(); + let initial_height = get_height(); println!("Initial height: {}", initial_height); - let history = wlt_1.fungible_history(contract_id, iface_type_name.clone()); - TestWallet::debug_fungible_history(&history); - assert_eq!(history.len(), 0); + println!("Contracts:"); + wlt_1.debug_contracts(); + + println!("History before transfer:"); + let history: Vec = wlt_1.history(contract_id, Some(iface_type_name.to_string())); + TestWallet::debug_history(&history, true); + assert_eq!(history.len(), 1); + assert_eq!(history[0].direction, OpDirection::Issued); let amount_transfer = 200; println!("Transfer amount: {}", amount_transfer); @@ -836,12 +846,12 @@ fn check_fungible_history() { ); println!("Invoice created: {:?}", invoice); - let (consignment, _) = wlt_1.transfer(invoice.clone(), None, Some(1234)); + let (consignment, _) = wlt_1.transfer(invoice.clone(), None, Some(1234), None); let height = get_height(); println!("Height: {}", height); - wlt_2.accept_transfer(consignment); + wlt_2.accept_transfer(consignment, None); mine(false); wlt_1.sync(); @@ -850,28 +860,28 @@ fn check_fungible_history() { let height = get_height(); println!("Height: {}", height); - let history = wlt_1.fungible_history(contract_id, iface_type_name.clone()); + let history = wlt_1.history(contract_id, Some(iface_type_name.to_string())); println!("History 1:"); - TestWallet::debug_fungible_history(&history); + TestWallet::debug_history(&history, true); - assert_eq!( - history.values().next().unwrap().state_change, - AmountChange::Dec(Amount::from(200_u64)) - ); + // assert_eq!( + // history.iter().next().unwrap().state, + // AmountChange::Dec(Amount::from(200_u64)) + // ); println!("Balance 1:"); - wlt_1.debug_logs(contract_id, &iface_type_name.clone()); + wlt_1.debug_logs(contract_id, &iface_type_name.clone(), AllocationFilter::WalletAll); - let history = wlt_2.fungible_history(contract_id, iface_type_name.clone()); + let history = wlt_2.history(contract_id, Some(iface_type_name.to_string())); println!("History 2:"); - TestWallet::debug_fungible_history(&history); - assert_eq!( - history.values().next().unwrap().state_change, - AmountChange::Inc(Amount::from(200_u64)) - ); + TestWallet::debug_history(&history, true); + // assert_eq!( + // history.values().next().unwrap().state_change, + // AmountChange::Inc(Amount::from(200_u64)) + // ); println!("Balance 2:"); - wlt_2.debug_logs(contract_id, &iface_type_name.clone()); + wlt_2.debug_logs(contract_id, &iface_type_name.clone(), AllocationFilter::WalletAll); } #[test] @@ -891,9 +901,9 @@ fn send_to_oneself() { contract_id, iface_type_name ); - let history = wlt.fungible_history(contract_id, iface_type_name.clone()); + let history = wlt.history(contract_id, Some(iface_type_name.to_string())); - TestWallet::debug_fungible_history(&history); + TestWallet::debug_history(&history, true); let amount_transfer = 300; // Amount to transfer to self println!("Transfer amount: {}", amount_transfer); @@ -907,12 +917,12 @@ fn send_to_oneself() { ); println!("Invoice created: {:?}", invoice); - let (consignment, _) = wlt.transfer(invoice.clone(), None, None); + let (consignment, _) = wlt.transfer(invoice.clone(), None, None, None); let height = get_height(); println!("Height: {}", height); - wlt.accept_transfer(consignment); // Accepting transfer to self + wlt.accept_transfer(consignment, None); // Accepting transfer to self mine(false); wlt.sync(); @@ -920,11 +930,11 @@ fn send_to_oneself() { let height = get_height(); println!("Height after sync: {}", height); - let history = wlt.fungible_history(contract_id, iface_type_name.clone()); + let history = wlt.history(contract_id, Some(iface_type_name.to_string())); println!("Final History:"); - TestWallet::debug_fungible_history(&history); + TestWallet::debug_history(&history, true); assert!(!history.is_empty()); println!("Balance:"); - wlt.debug_logs(contract_id, &iface_type_name.clone()); + wlt.debug_logs(contract_id, &iface_type_name.clone(), AllocationFilter::WalletAll); } diff --git a/tests/utils/helpers.rs b/tests/utils/helpers.rs index 46bfa0c..2056346 100644 --- a/tests/utils/helpers.rs +++ b/tests/utils/helpers.rs @@ -959,12 +959,55 @@ impl TestWallet { .collect() } - pub fn fungible_history( + pub fn history( &self, contract_id: ContractId, - iface: impl Into, - ) -> HashMap> { - self.wallet.fungible_history(contract_id, iface).unwrap() + iface: Option, + ) -> Vec { + let wallet = &self.wallet; + let iface: TypeName = match iface { + Some(iface) => tn!(iface.clone()), + None => { + let stock = wallet.stock(); + let info = stock.contract_info(contract_id).unwrap(); + let schema = stock.schema(info.schema_id).unwrap(); + match schema.iimpls.len() { + 0 => { + panic!( + "contract doesn't implement any interface and thus can't be \ + read\n" + ); + } + 1 => schema + .iimpls + .first_key_value() + .expect("one interface is present") + .0 + .clone(), + _ => { + eprintln!( + "contract implements multiple interface, please select one of \ + them to read the contract:" + ); + for iface in schema.iimpls.keys() { + eprintln!("{iface}"); + } + panic!(); + } + } + } + }; + wallet.history(contract_id, iface).unwrap() + + } + + pub fn debug_contracts( + &self, + ) { + let stock = self.wallet.stock(); + for info in stock.contracts().unwrap() { + print!("{info}"); + } } pub fn debug_logs( @@ -1063,31 +1106,44 @@ impl TestWallet { println!("\nWallet total balance: {} ṩ", bp_runtime.balance()); } - pub fn debug_fungible_history(history: &HashMap>) { - println!("Amount\tCounterparty\tWitness Id"); - for (id, op) in history { - let (amount, cparty, more) = match op.state_change { - AmountChange::Dec(amt) => ( - format!("-{}", amt.value()), - op.beneficiaries.first(), - op.beneficiaries.len().saturating_sub(1), - ), - AmountChange::Zero => continue, - AmountChange::Inc(amt) => ( - format!("{}", amt.value()), - op.payers.first(), - op.payers.len().saturating_sub(1), - ), - }; - let more = if more > 0 { - format!(" (+{more})") + pub fn debug_history(history: &Vec, details: bool) { + if details { + println!("Operation\tValue\tState\tSeal\tWitness\tOpIds"); + } else { + println!("Operation\tValue\tSeal\tWitness"); + } + for ContractOp { + direction, + ty, + opids, + state, + to, + witness, + } in history + { + print!("{direction}\t{state}"); + if details { + print!("\t{ty}"); + } + print!( + "\t{}\t{}", + to.first().expect("at least one receiver is always present"), + witness + .map(|info| format!("{} ({})", info.id, info.ord)) + .unwrap_or_else(|| s!("~")) + ); + if details { + println!( + "{}", + opids + .iter() + .map(OpId::to_string) + .collect::>() + .join(", ") + ) } else { - s!("") - }; - let cparty = cparty - .map(XOutputSeal::to_string) - .unwrap_or_else(|| s!("none")); - println!("{},{}\t{}{}\t{}", amount, op.state_change, cparty, more, id); + println!(); + } } } diff --git a/tests/utils/mod.rs b/tests/utils/mod.rs index d6edeff..c27475e 100644 --- a/tests/utils/mod.rs +++ b/tests/utils/mod.rs @@ -63,7 +63,8 @@ pub use psbt::{ pub use psrgbt::{RgbExt, RgbInExt, RgbPsbt, TxParams}; pub use rand::RngCore; pub use rgb::{ - interface::{AmountChange, IfaceOp, IfaceRef}, + OpId, + interface::{AssignmentsFilter, IfaceRef, ContractOp}, invoice::Pay2Vout, persistence::{ContractStateRead, MemContract, MemContractState, Stock}, resolvers::AnyResolver,