Skip to content

Commit 6bdd6e0

Browse files
committed
f Adapt upstream payment store tests
Use the bounded policy when constructing the payment store in wallet tests. Preserve race tests that count persisted records by inspecting the payment namespace instead of relying on a complete in-memory cache. Co-Authored-By: HAL 9000
1 parent e97dcd4 commit 6bdd6e0

1 file changed

Lines changed: 32 additions & 13 deletions

File tree

src/wallet/mod.rs

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ use lightning_invoice::RawBolt11Invoice;
5454
use persist::KVStoreWalletPersister;
5555

5656
use crate::config::{Config, ADDRESS_POOL_SIZE};
57-
#[cfg(test)]
58-
use crate::data_store::KeepAllEntries;
5957
use crate::data_store::StorableObject;
58+
#[cfg(test)]
59+
use crate::data_store::{KeepAllEntries, KeepLeastRecentlyUsed};
6060
use crate::fee_estimator::{ConfirmationTarget, FeeEstimator, OnchainFeeEstimator};
6161
use crate::logger::{log_debug, log_error, log_info, log_trace, LdkLogger, Logger};
6262
use crate::payment::pending_payment_store::PendingPaymentDetailsUpdate;
@@ -2626,7 +2626,7 @@ mod tests {
26262626
use lightning::util::persist::{KVStore, PageToken, PaginatedKVStore, PaginatedListResponse};
26272627

26282628
use super::*;
2629-
use crate::config::EsploraSyncConfig;
2629+
use crate::config::{EsploraSyncConfig, PAYMENT_CACHE_CAPACITY};
26302630
use crate::io::test_utils::InMemoryStore;
26312631
use crate::io::{
26322632
BDK_WALLET_ADDRESS_POOL_KEY, BDK_WALLET_ADDRESS_POOL_PRIMARY_NAMESPACE,
@@ -2752,7 +2752,7 @@ mod tests {
27522752
.unwrap();
27532753
let payment_store = Arc::new(PaymentStore::new(
27542754
Vec::new(),
2755-
KeepAllEntries,
2755+
KeepLeastRecentlyUsed::new(PAYMENT_CACHE_CAPACITY),
27562756
PAYMENT_INFO_PERSISTENCE_PRIMARY_NAMESPACE.to_string(),
27572757
PAYMENT_INFO_PERSISTENCE_SECONDARY_NAMESPACE.to_string(),
27582758
Arc::clone(&store),
@@ -3853,7 +3853,7 @@ mod tests {
38533853
async fn funding_confirmation_waits_for_classification() {
38543854
let gated = NamespaceGatedStore::new(PENDING_PAYMENT_INFO_PERSISTENCE_PRIMARY_NAMESPACE);
38553855
let store: Arc<DynStore> = Arc::new(DynStoreWrapper(gated.clone()));
3856-
let wallet = new_test_wallet(store, false).await;
3856+
let wallet = new_test_wallet(Arc::clone(&store), false).await;
38573857

38583858
let txid1 = Txid::from_byte_array([1u8; 32]);
38593859
let txid2 = Txid::from_byte_array([2u8; 32]);
@@ -3898,7 +3898,14 @@ mod tests {
38983898
// Liveness sanity only (both pre- and post-fix stall here): while classification is
38993899
// parked, no second record may have been committed.
39003900
tokio::time::sleep(Duration::from_millis(250)).await;
3901-
assert!(wallet.payment_store.list_filter(|_| true).await.len() <= 1);
3901+
let payment_keys = KVStore::list(
3902+
&*store,
3903+
PAYMENT_INFO_PERSISTENCE_PRIMARY_NAMESPACE,
3904+
PAYMENT_INFO_PERSISTENCE_SECONDARY_NAMESPACE,
3905+
)
3906+
.await
3907+
.unwrap();
3908+
assert!(payment_keys.len() <= 1);
39023909

39033910
drop(gate_guard);
39043911
classification.await.unwrap().unwrap();
@@ -3907,9 +3914,15 @@ mod tests {
39073914
// Both writers converge on the classified record: the confirmation refreshes it in
39083915
// place with the confirmed candidate's figures rather than minting a second record
39093916
// keyed by the event txid.
3910-
let payments = wallet.payment_store.list_filter(|_| true).await;
3911-
assert_eq!(payments.len(), 1, "the confirmation must not mint a duplicate record");
3912-
let payment = &payments[0];
3917+
let payment_keys = KVStore::list(
3918+
&*store,
3919+
PAYMENT_INFO_PERSISTENCE_PRIMARY_NAMESPACE,
3920+
PAYMENT_INFO_PERSISTENCE_SECONDARY_NAMESPACE,
3921+
)
3922+
.await
3923+
.unwrap();
3924+
assert_eq!(payment_keys.len(), 1, "the confirmation must not mint a duplicate record");
3925+
let payment = wallet.payment_store.get(&payment_id).await.unwrap().unwrap();
39133926
assert_eq!(payment.id, payment_id);
39143927
assert_eq!(payment.amount_msat, Some(2_000_000));
39153928
assert_eq!(payment.fee_paid_msat, Some(999));
@@ -3932,7 +3945,7 @@ mod tests {
39323945
#[tokio::test(flavor = "multi_thread")]
39333946
async fn funding_classification_waits_for_wallet_sync() {
39343947
let store: Arc<DynStore> = Arc::new(DynStoreWrapper(InMemoryStore::new()));
3935-
let wallet = new_test_wallet(store, false).await;
3948+
let wallet = new_test_wallet(Arc::clone(&store), false).await;
39363949

39373950
let txid = Txid::from_byte_array([3u8; 32]);
39383951
let payment_id = PaymentId(txid.to_byte_array());
@@ -3971,9 +3984,15 @@ mod tests {
39713984
// Both writers converge on one record carrying the classification: the generic
39723985
// fallback must not clobber the contribution-derived figures with its wallet-derived
39733986
// view of the transaction.
3974-
let payments = wallet.payment_store.list_filter(|_| true).await;
3975-
assert_eq!(payments.len(), 1);
3976-
let payment = &payments[0];
3987+
let payment_keys = KVStore::list(
3988+
&*store,
3989+
PAYMENT_INFO_PERSISTENCE_PRIMARY_NAMESPACE,
3990+
PAYMENT_INFO_PERSISTENCE_SECONDARY_NAMESPACE,
3991+
)
3992+
.await
3993+
.unwrap();
3994+
assert_eq!(payment_keys.len(), 1);
3995+
let payment = wallet.payment_store.get(&payment_id).await.unwrap().unwrap();
39773996
assert_eq!(payment.id, payment_id);
39783997
assert_eq!(
39793998
payment.amount_msat,

0 commit comments

Comments
 (0)