diff --git a/controller/tests/contract_self_spend.rs b/controller/tests/contract_self_spend.rs index b252073..75dbf93 100644 --- a/controller/tests/contract_self_spend.rs +++ b/controller/tests/contract_self_spend.rs @@ -22,7 +22,7 @@ use grin_wallet_libwallet as libwallet; use impls::test_framework::{self}; use libwallet::contract::my_fee_contribution; use libwallet::contract::types::{ContractNewArgsAPI, ContractSetupArgsAPI}; -use libwallet::{Slate, SlateState, TxLogEntryType}; +use libwallet::{RetrieveTxQueryArgs, Slate, SlateState, TxLogEntryType}; use std::sync::atomic::Ordering; use std::thread; use std::time::Duration; @@ -113,6 +113,25 @@ fn contract_self_spend_tx_impl(test_dir: &'static str) -> Result<(), libwallet:: assert_eq!(tx_log.num_inputs, 1); assert_eq!(tx_log.num_outputs, 1); assert_eq!(tx_log.fee, Some(my_fee_contribution(1, 1, 1, 1)?)); + + for query in [ + RetrieveTxQueryArgs { + include_sent_only: Some(true), + ..Default::default() + }, + RetrieveTxQueryArgs { + include_received_only: Some(true), + ..Default::default() + }, + RetrieveTxQueryArgs { + include_self_spend_only: Some(true), + ..Default::default() + }, + ] { + let (_, filtered) = api.retrieve_txs(m, false, None, None, Some(query))?; + assert_eq!(filtered.len(), 1); + assert_eq!(filtered[0].tx_type, TxLogEntryType::TxSelfSpend); + } Ok(()) }, )?; diff --git a/controller/tests/contract_self_spend_cancel.rs b/controller/tests/contract_self_spend_cancel.rs index e3b17cd..4226b2b 100644 --- a/controller/tests/contract_self_spend_cancel.rs +++ b/controller/tests/contract_self_spend_cancel.rs @@ -20,7 +20,7 @@ extern crate log; use grin_wallet_libwallet as libwallet; use libwallet::contract::types::{ContractNewArgsAPI, ContractSetupArgsAPI}; -use libwallet::{Slate, SlateState, TxLogEntryType}; +use libwallet::{RetrieveTxQueryArgs, Slate, SlateState, TxLogEntryType}; use std::sync::atomic::Ordering; use std::thread; use std::time::Duration; @@ -87,6 +87,24 @@ fn contract_self_spend_cancel_impl(test_dir: &'static str) -> Result<(), libwall assert_eq!(txs.len() as u64, 5); // send wallet didn't mine 4 blocks and made 1 tx let tx_log = txs[4].clone(); // TODO: why -5 and not -4? assert_eq!(tx_log.tx_type, TxLogEntryType::TxSelfSpendCancelled); + for query in [ + RetrieveTxQueryArgs { + include_sent_only: Some(true), + ..Default::default() + }, + RetrieveTxQueryArgs { + include_received_only: Some(true), + ..Default::default() + }, + RetrieveTxQueryArgs { + include_self_spend_only: Some(true), + ..Default::default() + }, + ] { + let (_, filtered) = api.retrieve_txs(m, false, None, None, Some(query))?; + assert_eq!(filtered.len(), 1); + assert_eq!(filtered[0].tx_type, TxLogEntryType::TxSelfSpendCancelled); + } Ok(()) }, )?; diff --git a/libwallet/src/api_impl/types.rs b/libwallet/src/api_impl/types.rs index 4e59873..9ab2f47 100644 --- a/libwallet/src/api_impl/types.rs +++ b/libwallet/src/api_impl/types.rs @@ -200,9 +200,9 @@ pub struct RetrieveTxQueryArgs { pub include_outstanding_only: Option, /// whether to only consider confirmed-only transactions pub include_confirmed_only: Option, - /// whether to only consider sent transactions + /// whether to only consider sent transactions, including self spends pub include_sent_only: Option, - /// whether to only consider received transactions + /// whether to only consider received transactions, including self spends pub include_received_only: Option, /// whether to only consider coinbase transactions pub include_coinbase_only: Option, diff --git a/libwallet/src/contract/actions/README.md b/libwallet/src/contract/actions/README.md index 13bff3b..b1bcbad 100644 --- a/libwallet/src/contract/actions/README.md +++ b/libwallet/src/contract/actions/README.md @@ -56,7 +56,6 @@ without a user confirmation step. - Stop relying on TxLog offsets in contract tests. - Finish the account-switching tests in `contract_accounts.rs`. - Reuse the workspace `serde_with` version. - - Define and test how self-spends are handled by the sent and received filters. ### Side-effects diff --git a/libwallet/src/internal/updater.rs b/libwallet/src/internal/updater.rs index f9dbf9c..4d63592 100644 --- a/libwallet/src/internal/updater.rs +++ b/libwallet/src/internal/updater.rs @@ -156,6 +156,7 @@ where tx_entry.tx_type == TxLogEntryType::TxSent || tx_entry.tx_type == TxLogEntryType::TxSentCancelled || tx_entry.tx_type == TxLogEntryType::TxSelfSpend + || tx_entry.tx_type == TxLogEntryType::TxSelfSpendCancelled } else { true } @@ -169,6 +170,7 @@ where tx_entry.tx_type == TxLogEntryType::TxReceived || tx_entry.tx_type == TxLogEntryType::TxReceivedCancelled || tx_entry.tx_type == TxLogEntryType::TxSelfSpend + || tx_entry.tx_type == TxLogEntryType::TxSelfSpendCancelled } else { true } @@ -191,6 +193,7 @@ where if let Some(v) = query_args.include_self_spend_only { if v { tx_entry.tx_type == TxLogEntryType::TxSelfSpend + || tx_entry.tx_type == TxLogEntryType::TxSelfSpendCancelled } else { true }