mirror of
https://github.com/jwinterm/grin-wallet.git
synced 2026-10-17 07:11:36 +02:00
test self spend filters
This commit is contained in:
@@ -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(())
|
||||
},
|
||||
)?;
|
||||
|
||||
@@ -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(())
|
||||
},
|
||||
)?;
|
||||
|
||||
@@ -200,9 +200,9 @@ pub struct RetrieveTxQueryArgs {
|
||||
pub include_outstanding_only: Option<bool>,
|
||||
/// whether to only consider confirmed-only transactions
|
||||
pub include_confirmed_only: Option<bool>,
|
||||
/// whether to only consider sent transactions
|
||||
/// whether to only consider sent transactions, including self spends
|
||||
pub include_sent_only: Option<bool>,
|
||||
/// whether to only consider received transactions
|
||||
/// whether to only consider received transactions, including self spends
|
||||
pub include_received_only: Option<bool>,
|
||||
/// whether to only consider coinbase transactions
|
||||
pub include_coinbase_only: Option<bool>,
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user