diff --git a/controller/tests/common/mod.rs b/controller/tests/common/mod.rs index 435f2e0..262b059 100644 --- a/controller/tests/common/mod.rs +++ b/controller/tests/common/mod.rs @@ -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 { + 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); diff --git a/controller/tests/contract_early_proofs_rsr.rs b/controller/tests/contract_early_proofs_rsr.rs index 5e03fb4..2862b67 100644 --- a/controller/tests/contract_early_proofs_rsr.rs +++ b/controller/tests/contract_early_proofs_rsr.rs @@ -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); diff --git a/controller/tests/contract_early_proofs_srs.rs b/controller/tests/contract_early_proofs_srs.rs index 9151e83..1d358b2 100644 --- a/controller/tests/contract_early_proofs_srs.rs +++ b/controller/tests/contract_early_proofs_srs.rs @@ -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); diff --git a/controller/tests/contract_rsr.rs b/controller/tests/contract_rsr.rs index 9c1c0f3..cf61ee0 100644 --- a/controller/tests/contract_rsr.rs +++ b/controller/tests/contract_rsr.rs @@ -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); diff --git a/controller/tests/contract_self_spend.rs b/controller/tests/contract_self_spend.rs index 75dbf93..ea480d0 100644 --- a/controller/tests/contract_self_spend.rs +++ b/controller/tests/contract_self_spend.rs @@ -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); diff --git a/controller/tests/contract_self_spend_cancel.rs b/controller/tests/contract_self_spend_cancel.rs index 4226b2b..f1274bf 100644 --- a/controller/tests/contract_self_spend_cancel.rs +++ b/controller/tests/contract_self_spend_cancel.rs @@ -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 { diff --git a/controller/tests/contract_self_spend_custom.rs b/controller/tests/contract_self_spend_custom.rs index 6f888b2..ac703a3 100644 --- a/controller/tests/contract_self_spend_custom.rs +++ b/controller/tests/contract_self_spend_custom.rs @@ -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); diff --git a/controller/tests/contract_srs.rs b/controller/tests/contract_srs.rs index deafa93..7d8776d 100644 --- a/controller/tests/contract_srs.rs +++ b/controller/tests/contract_srs.rs @@ -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); diff --git a/libwallet/src/contract/actions/README.md b/libwallet/src/contract/actions/README.md index eb3c0b9..966771e 100644 --- a/libwallet/src/contract/actions/README.md +++ b/libwallet/src/contract/actions/README.md @@ -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