mirror of
https://github.com/jwinterm/grin-wallet.git
synced 2026-10-17 07:11:36 +02:00
find contract tx logs by slate
This commit is contained in:
@@ -185,6 +185,22 @@ pub fn wallet_progress(
|
||||
})
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn tx_log_for_slate(
|
||||
api: &TestOwner,
|
||||
keychain_mask: Option<&SecretKey>,
|
||||
slate: &libwallet::Slate,
|
||||
) -> Result<libwallet::TxLogEntry, libwallet::Error> {
|
||||
let (_, mut txs) = api.retrieve_txs(keychain_mask, false, None, Some(slate.id), None)?;
|
||||
assert_eq!(
|
||||
txs.len(),
|
||||
1,
|
||||
"expected one tx log entry for slate {}",
|
||||
slate.id
|
||||
);
|
||||
Ok(txs.pop().unwrap())
|
||||
}
|
||||
|
||||
pub fn setup(test_dir: &str) {
|
||||
util::init_test_logger();
|
||||
clean_output_dir(test_dir);
|
||||
|
||||
@@ -171,7 +171,7 @@ fn contract_early_proofs_rsr_test_impl(
|
||||
assert_eq!(wallet_info.last_confirmed_height, bh);
|
||||
assert!(refreshed);
|
||||
assert_eq!(txs.len(), 5); // 4 mined and 1 received
|
||||
let tx_log = txs[4].clone();
|
||||
let tx_log = common::tx_log_for_slate(api, m, &slate)?;
|
||||
assert_eq!(tx_log.tx_type, TxLogEntryType::TxReceived);
|
||||
assert_eq!(tx_log.amount_credited, 5_000_000_000);
|
||||
assert_eq!(tx_log.amount_debited, 0);
|
||||
@@ -198,7 +198,7 @@ fn contract_early_proofs_rsr_test_impl(
|
||||
assert_eq!(wallet_info.last_confirmed_height, bh);
|
||||
assert!(refreshed);
|
||||
assert_eq!(txs.len() as u64, bh - 4 + 1); // send wallet didn't mine 4 blocks and made 1 tx
|
||||
let tx_log = txs[txs.len() - 5].clone(); // TODO: why -5 and not -4?
|
||||
let tx_log = common::tx_log_for_slate(api, m, &slate)?;
|
||||
assert_eq!(tx_log.tx_type, TxLogEntryType::TxSent);
|
||||
assert_eq!(tx_log.amount_credited, 0);
|
||||
assert_eq!(tx_log.amount_debited, 5_000_000_000);
|
||||
|
||||
@@ -171,7 +171,7 @@ fn contract_early_proofs_srs_test_impl(test_dir: &'static str) -> Result<(), lib
|
||||
assert_eq!(wallet_info.last_confirmed_height, bh);
|
||||
assert!(refreshed);
|
||||
assert_eq!(txs.len(), 5); // 4 mined and 1 received
|
||||
let tx_log = txs[4].clone();
|
||||
let tx_log = common::tx_log_for_slate(api, m, &slate)?;
|
||||
assert_eq!(tx_log.tx_type, TxLogEntryType::TxReceived);
|
||||
assert_eq!(tx_log.amount_credited, 5_000_000_000);
|
||||
assert_eq!(tx_log.amount_debited, 0);
|
||||
@@ -198,7 +198,7 @@ fn contract_early_proofs_srs_test_impl(test_dir: &'static str) -> Result<(), lib
|
||||
assert_eq!(wallet_info.last_confirmed_height, bh);
|
||||
assert!(refreshed);
|
||||
assert_eq!(txs.len() as u64, bh - 4 + 1); // send wallet didn't mine 4 blocks and made 1 tx
|
||||
let tx_log = txs[txs.len() - 5].clone(); // TODO: why -5 and not -4?
|
||||
let tx_log = common::tx_log_for_slate(api, m, &slate)?;
|
||||
assert_eq!(tx_log.tx_type, TxLogEntryType::TxSent);
|
||||
assert_eq!(tx_log.amount_credited, 0);
|
||||
assert_eq!(tx_log.amount_debited, 5_000_000_000);
|
||||
|
||||
@@ -222,7 +222,7 @@ fn contract_rsr_tx_impl(test_dir: &'static str) -> Result<(), libwallet::Error>
|
||||
assert_eq!(wallet_info.last_confirmed_height, bh);
|
||||
assert!(refreshed);
|
||||
assert_eq!(txs.len(), 5); // 4 mined and 1 received
|
||||
let tx_log = txs[4].clone();
|
||||
let tx_log = common::tx_log_for_slate(api, m, &slate)?;
|
||||
assert_eq!(tx_log.tx_type, TxLogEntryType::TxReceived);
|
||||
assert_eq!(tx_log.amount_credited, 5_000_000_000);
|
||||
assert_eq!(tx_log.amount_debited, 0);
|
||||
@@ -254,7 +254,7 @@ fn contract_rsr_tx_impl(test_dir: &'static str) -> Result<(), libwallet::Error>
|
||||
assert_eq!(wallet_info.last_confirmed_height, bh);
|
||||
assert!(refreshed);
|
||||
assert_eq!(txs.len() as u64, bh - 4 + 1); // send_wallet didn't mine 4 blocks and made 1 tx
|
||||
let tx_log = txs[txs.len() - 5].clone(); // TODO: why -5 and not -4?
|
||||
let tx_log = common::tx_log_for_slate(api, m, &slate)?;
|
||||
assert_eq!(tx_log.tx_type, TxLogEntryType::TxSent);
|
||||
assert_eq!(tx_log.amount_credited, 0);
|
||||
assert_eq!(tx_log.amount_debited, 5_000_000_000);
|
||||
|
||||
@@ -106,7 +106,7 @@ fn contract_self_spend_tx_impl(test_dir: &'static str) -> Result<(), libwallet::
|
||||
assert_eq!(wallet_info.last_confirmed_height, bh);
|
||||
assert!(refreshed);
|
||||
assert_eq!(txs.len() as u64, bh + 1); // send wallet didn't mine 4 blocks and made 1 tx
|
||||
let tx_log = txs[txs.len() - 5].clone(); // TODO: why -5 and not -4?
|
||||
let tx_log = common::tx_log_for_slate(api, m, &slate)?;
|
||||
assert_eq!(tx_log.tx_type, TxLogEntryType::TxSelfSpend);
|
||||
assert_eq!(tx_log.amount_credited, 0);
|
||||
assert_eq!(tx_log.amount_debited, 0);
|
||||
|
||||
@@ -85,7 +85,7 @@ fn contract_self_spend_cancel_impl(test_dir: &'static str) -> Result<(), libwall
|
||||
let (refreshed, txs) = api.retrieve_txs(m, true, None, None, Some(query_args))?;
|
||||
assert!(refreshed);
|
||||
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?
|
||||
let tx_log = common::tx_log_for_slate(api, m, &slate)?;
|
||||
assert_eq!(tx_log.tx_type, TxLogEntryType::TxSelfSpendCancelled);
|
||||
for query in [
|
||||
RetrieveTxQueryArgs {
|
||||
|
||||
@@ -141,7 +141,7 @@ fn contract_self_spend_custom_tx_impl(test_dir: &'static str) -> Result<(), libw
|
||||
assert_eq!(wallet_info.last_confirmed_height, bh);
|
||||
assert!(refreshed);
|
||||
assert_eq!(txs.len() as u64, bh + 1); // send wallet didn't mine 4 blocks and made 1 tx
|
||||
let tx_log = txs[txs.len() - 5].clone(); // TODO: why -5 and not -4?
|
||||
let tx_log = common::tx_log_for_slate(api, m, &slate)?;
|
||||
assert_eq!(tx_log.tx_type, TxLogEntryType::TxSelfSpend);
|
||||
assert_eq!(tx_log.amount_credited, 0);
|
||||
assert_eq!(tx_log.amount_debited, 0);
|
||||
|
||||
@@ -124,8 +124,8 @@ fn contract_srs_tx_impl(test_dir: &'static str) -> Result<(), libwallet::Error>
|
||||
args.setup_args.fee_rate = None;
|
||||
assert_eq!(common::wallet_progress(api, m)?, progress);
|
||||
slate = api.contract_new(m, &mut args)?;
|
||||
let (_, txs) = api.retrieve_txs(m, false, None, Some(slate.id), None)?;
|
||||
assert_eq!(txs[0].ttl_cutoff_height, Some(ttl_cutoff));
|
||||
let tx_log = common::tx_log_for_slate(api, m, &slate)?;
|
||||
assert_eq!(tx_log.ttl_cutoff_height, Some(ttl_cutoff));
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
@@ -630,7 +630,7 @@ fn contract_srs_tx_impl(test_dir: &'static str) -> Result<(), libwallet::Error>
|
||||
assert_eq!(wallet_info.last_confirmed_height, bh);
|
||||
assert!(refreshed);
|
||||
assert_eq!(txs.len(), 5); // 4 mined and 1 received
|
||||
let tx_log = txs[4].clone();
|
||||
let tx_log = common::tx_log_for_slate(api, m, &slate)?;
|
||||
assert_eq!(tx_log.tx_type, TxLogEntryType::TxReceived);
|
||||
assert_eq!(tx_log.amount_credited, 5_000_000_000);
|
||||
assert_eq!(tx_log.amount_debited, 0);
|
||||
@@ -656,7 +656,7 @@ fn contract_srs_tx_impl(test_dir: &'static str) -> Result<(), libwallet::Error>
|
||||
assert_eq!(wallet_info.last_confirmed_height, bh);
|
||||
assert!(refreshed);
|
||||
assert_eq!(txs.len() as u64, bh - 4 + 1); // send wallet didn't mine 4 blocks and made 1 tx
|
||||
let tx_log = txs[txs.len() - 5].clone(); // TODO: why -5 and not -4?
|
||||
let tx_log = common::tx_log_for_slate(api, m, &slate)?;
|
||||
assert_eq!(tx_log.tx_type, TxLogEntryType::TxSent);
|
||||
assert_eq!(tx_log.amount_credited, 0);
|
||||
assert_eq!(tx_log.amount_debited, 5_000_000_000);
|
||||
|
||||
@@ -53,7 +53,6 @@ without a user confirmation step.
|
||||
- Revisit automatic receive signing once there is a user confirmation step.
|
||||
- Infer `--receive` and `--send` from the slate state.
|
||||
- Revisit `remove_other_sigdata` before allowing more than two participants.
|
||||
- Stop relying on TxLog offsets in contract tests.
|
||||
|
||||
### Side-effects
|
||||
|
||||
|
||||
Reference in New Issue
Block a user