浏览代码

fix: fake mint multiple units

thesimplekid 2 月之前
父节点
当前提交
47c5bb7465

+ 10 - 4
crates/cdk-fake-wallet/src/lib.rs

@@ -54,6 +54,7 @@ pub struct FakeWallet {
     wait_invoice_cancel_token: CancellationToken,
     wait_invoice_is_active: Arc<AtomicBool>,
     incoming_payments: Arc<RwLock<HashMap<PaymentIdentifier, Vec<WaitPaymentResponse>>>>,
+    unit: CurrencyUnit,
 }
 
 impl FakeWallet {
@@ -63,6 +64,7 @@ impl FakeWallet {
         payment_states: HashMap<String, MeltQuoteState>,
         fail_payment_check: HashSet<String>,
         payment_delay: u64,
+        unit: CurrencyUnit,
     ) -> Self {
         let (sender, receiver) = tokio::sync::mpsc::channel(8);
 
@@ -76,6 +78,7 @@ impl FakeWallet {
             wait_invoice_cancel_token: CancellationToken::new(),
             wait_invoice_is_active: Arc::new(AtomicBool::new(false)),
             incoming_payments: Arc::new(RwLock::new(HashMap::new())),
+            unit,
         }
     }
 }
@@ -112,7 +115,7 @@ impl MintPayment for FakeWallet {
     async fn get_settings(&self) -> Result<Value, Self::Err> {
         Ok(serde_json::to_value(Bolt11Settings {
             mpp: true,
-            unit: CurrencyUnit::Msat,
+            unit: self.unit.clone(),
             invoice_description: true,
             amountless: false,
             bolt12: false,
@@ -141,12 +144,13 @@ impl MintPayment for FakeWallet {
             .take()
             .ok_or(Error::NoReceiver)
             .unwrap();
+        let unit = self.unit.clone();
         let receiver_stream = ReceiverStream::new(receiver);
         Ok(Box::pin(receiver_stream.map(
-            |(request_lookup_id, payment_amount)| WaitPaymentResponse {
+            move |(request_lookup_id, payment_amount)| WaitPaymentResponse {
                 payment_identifier: request_lookup_id.clone(),
                 payment_amount,
-                unit: CurrencyUnit::Sat,
+                unit: unit.clone(),
                 payment_id: request_lookup_id.to_string(),
             },
         )))
@@ -389,6 +393,8 @@ impl MintPayment for FakeWallet {
 
         let incoming_payment = self.incoming_payments.clone();
 
+        let unit = self.unit.clone();
+
         tokio::spawn(async move {
             // Wait for the random delay to elapse
             time::sleep(duration).await;
@@ -396,7 +402,7 @@ impl MintPayment for FakeWallet {
             let response = WaitPaymentResponse {
                 payment_identifier: payment_hash_clone.clone(),
                 payment_amount: final_amount,
-                unit: CurrencyUnit::Sat,
+                unit,
                 payment_id: payment_hash_clone.to_string(),
             };
             let mut incoming = incoming_payment.write().await;

+ 7 - 1
crates/cdk-integration-tests/src/init_auth_mint.rs

@@ -29,7 +29,13 @@ where
         percent_fee_reserve: 1.0,
     };
 
-    let fake_wallet = FakeWallet::new(fee_reserve, HashMap::default(), HashSet::default(), 0);
+    let fake_wallet = FakeWallet::new(
+        fee_reserve,
+        HashMap::default(),
+        HashSet::default(),
+        0,
+        CurrencyUnit::Sat,
+    );
 
     let mut mint_builder = MintBuilder::new(Arc::new(database));
 

+ 1 - 0
crates/cdk-integration-tests/src/init_pure_tests.rs

@@ -253,6 +253,7 @@ pub async fn create_and_start_test_mint() -> Result<Mint> {
         HashMap::default(),
         HashSet::default(),
         0,
+        CurrencyUnit::Sat,
     );
 
     mint_builder

+ 3 - 0
crates/cdk-integration-tests/tests/fake_wallet.rs

@@ -684,6 +684,8 @@ async fn test_fake_mint_multiple_unit_swap() {
     )
     .expect("failed to create new wallet");
 
+    wallet.refresh_keysets().await.unwrap();
+
     let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
 
     wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60)
@@ -703,6 +705,7 @@ async fn test_fake_mint_multiple_unit_swap() {
         None,
     )
     .expect("failed to create usd wallet");
+    wallet_usd.refresh_keysets().await.unwrap();
 
     let mint_quote = wallet_usd.mint_quote(100.into(), None).await.unwrap();
 

+ 7 - 1
crates/cdk-integration-tests/tests/mint.rs

@@ -34,7 +34,13 @@ async fn test_correct_keyset() {
 
     let database = memory::empty().await.expect("valid db instance");
 
-    let fake_wallet = FakeWallet::new(fee_reserve, HashMap::default(), HashSet::default(), 0);
+    let fake_wallet = FakeWallet::new(
+        fee_reserve,
+        HashMap::default(),
+        HashSet::default(),
+        0,
+        CurrencyUnit::Sat,
+    );
 
     let localstore = Arc::new(database);
     let mut mint_builder = MintBuilder::new(localstore.clone());

+ 1 - 1
crates/cdk-mintd/src/lib.rs

@@ -322,7 +322,7 @@ async fn configure_lightning_backend(
 
             for unit in fake_wallet.clone().supported_units {
                 let fake = fake_wallet
-                    .setup(ln_routers, settings, CurrencyUnit::Sat)
+                    .setup(ln_routers, settings, unit.clone())
                     .await?;
 
                 mint_builder = configure_backend_for_unit(

+ 2 - 1
crates/cdk-mintd/src/setup.rs

@@ -161,7 +161,7 @@ impl LnBackendSetup for config::FakeWallet {
         &self,
         _router: &mut Vec<Router>,
         _settings: &Settings,
-        _unit: CurrencyUnit,
+        unit: CurrencyUnit,
     ) -> anyhow::Result<cdk_fake_wallet::FakeWallet> {
         let fee_reserve = FeeReserve {
             min_fee_reserve: self.reserve_fee_min,
@@ -177,6 +177,7 @@ impl LnBackendSetup for config::FakeWallet {
             HashMap::default(),
             HashSet::default(),
             delay_time,
+            unit,
         );
 
         Ok(fake_wallet)

+ 7 - 2
crates/cdk-payment-processor/src/bin/payment_processor.rs

@@ -115,8 +115,13 @@ async fn main() -> anyhow::Result<()> {
                         percent_fee_reserve: 0.0,
                     };
 
-                    let fake_wallet =
-                        FakeWallet::new(fee_reserve, HashMap::default(), HashSet::default(), 0);
+                    let fake_wallet = FakeWallet::new(
+                        fee_reserve,
+                        HashMap::default(),
+                        HashSet::default(),
+                        0,
+                        cashu::CurrencyUnit::Sat,
+                    );
 
                     Arc::new(fake_wallet)
                 }