|
@@ -1,6 +1,6 @@
|
|
|
//! Mint tests
|
|
|
|
|
|
-use std::collections::HashMap;
|
|
|
+use std::collections::{HashMap, HashSet};
|
|
|
use std::sync::Arc;
|
|
|
use std::time::Duration;
|
|
|
|
|
@@ -10,15 +10,17 @@ use cdk::amount::{Amount, SplitTarget};
|
|
|
use cdk::cdk_database::mint_memory::MintMemoryDatabase;
|
|
|
use cdk::cdk_database::MintDatabase;
|
|
|
use cdk::dhke::construct_proofs;
|
|
|
-use cdk::mint::MintQuote;
|
|
|
+use cdk::mint::{FeeReserve, MintBuilder, MintMeltLimits, MintQuote};
|
|
|
use cdk::nuts::nut00::ProofsMethods;
|
|
|
use cdk::nuts::{
|
|
|
- CurrencyUnit, Id, MintBolt11Request, MintInfo, NotificationPayload, Nuts, PreMintSecrets,
|
|
|
- ProofState, Proofs, SecretKey, SpendingConditions, State, SwapRequest,
|
|
|
+ CurrencyUnit, Id, MintBolt11Request, MintInfo, NotificationPayload, Nuts, PaymentMethod,
|
|
|
+ PreMintSecrets, ProofState, Proofs, SecretKey, SpendingConditions, State, SwapRequest,
|
|
|
};
|
|
|
use cdk::subscription::{IndexableParams, Params};
|
|
|
+use cdk::types::QuoteTTL;
|
|
|
use cdk::util::unix_time;
|
|
|
use cdk::Mint;
|
|
|
+use cdk_fake_wallet::FakeWallet;
|
|
|
use tokio::sync::OnceCell;
|
|
|
use tokio::time::sleep;
|
|
|
|
|
@@ -437,3 +439,74 @@ async fn test_mint_enforce_fee() -> Result<()> {
|
|
|
|
|
|
Ok(())
|
|
|
}
|
|
|
+
|
|
|
+#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
|
|
|
+async fn test_correct_keyset() -> Result<()> {
|
|
|
+ let mnemonic = Mnemonic::generate(12)?;
|
|
|
+ let fee_reserve = FeeReserve {
|
|
|
+ min_fee_reserve: 1.into(),
|
|
|
+ percent_fee_reserve: 1.0,
|
|
|
+ };
|
|
|
+
|
|
|
+ let database = MintMemoryDatabase::default();
|
|
|
+
|
|
|
+ let fake_wallet = FakeWallet::new(fee_reserve, HashMap::default(), HashSet::default(), 0);
|
|
|
+
|
|
|
+ let mut mint_builder = MintBuilder::new();
|
|
|
+ let localstore = Arc::new(database);
|
|
|
+ mint_builder = mint_builder.with_localstore(localstore.clone());
|
|
|
+
|
|
|
+ mint_builder = mint_builder.add_ln_backend(
|
|
|
+ CurrencyUnit::Sat,
|
|
|
+ PaymentMethod::Bolt11,
|
|
|
+ MintMeltLimits::new(1, 5_000),
|
|
|
+ Arc::new(fake_wallet),
|
|
|
+ );
|
|
|
+
|
|
|
+ mint_builder = mint_builder
|
|
|
+ .with_name("regtest mint".to_string())
|
|
|
+ .with_description("regtest mint".to_string())
|
|
|
+ .with_seed(mnemonic.to_seed_normalized("").to_vec());
|
|
|
+
|
|
|
+ let mint = mint_builder.build().await?;
|
|
|
+
|
|
|
+ localstore
|
|
|
+ .set_mint_info(mint_builder.mint_info.clone())
|
|
|
+ .await?;
|
|
|
+ let quote_ttl = QuoteTTL::new(10000, 10000);
|
|
|
+ localstore.set_quote_ttl(quote_ttl).await?;
|
|
|
+
|
|
|
+ mint.rotate_next_keyset(CurrencyUnit::Sat, 32, 0).await?;
|
|
|
+ mint.rotate_next_keyset(CurrencyUnit::Sat, 32, 0).await?;
|
|
|
+
|
|
|
+ let active = mint.localstore.get_active_keysets().await?;
|
|
|
+
|
|
|
+ let active = active
|
|
|
+ .get(&CurrencyUnit::Sat)
|
|
|
+ .expect("There is a keyset for unit");
|
|
|
+
|
|
|
+ let keyset_info = mint
|
|
|
+ .localstore
|
|
|
+ .get_keyset_info(active)
|
|
|
+ .await?
|
|
|
+ .expect("There is keyset");
|
|
|
+
|
|
|
+ assert!(keyset_info.derivation_path_index == Some(2));
|
|
|
+
|
|
|
+ let mint = mint_builder.build().await?;
|
|
|
+
|
|
|
+ let active = mint.localstore.get_active_keysets().await?;
|
|
|
+
|
|
|
+ let active = active
|
|
|
+ .get(&CurrencyUnit::Sat)
|
|
|
+ .expect("There is a keyset for unit");
|
|
|
+
|
|
|
+ let keyset_info = mint
|
|
|
+ .localstore
|
|
|
+ .get_keyset_info(active)
|
|
|
+ .await?
|
|
|
+ .expect("There is keyset");
|
|
|
+
|
|
|
+ assert!(keyset_info.derivation_path_index == Some(2));
|
|
|
+ Ok(())
|
|
|
+}
|