fix: mint start with newest keyset

chore: test for newest keyset

chore: add pure tests to ci
This commit is contained in:
thesimplekid
2025-02-02 11:22:32 +00:00
parent 017f88e5bc
commit 65e07e37f1
5 changed files with 97 additions and 5 deletions

View File

@@ -180,6 +180,21 @@ jobs:
run: nix develop -i -L .#stable --command cargo clippy ${{ matrix.build-args }} -- -D warnings
- name: Test fake mint
run: nix develop -i -L .#stable --command just fake-mint-itest ${{ matrix.database }}
pure-itest:
name: "Integration fake wallet tests"
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v4
- name: Install Nix
uses: DeterminateSystems/nix-installer-action@v11
- name: Nix Cache
uses: DeterminateSystems/magic-nix-cache-action@v6
- name: Rust Cache
uses: Swatinem/rust-cache@v2
- name: Test fake mint
run: nix develop -i -L .#stable --command just test
msrv-build:
name: "MSRV build"

View File

@@ -32,7 +32,8 @@
* `Wallet::receive_raw` which receives raw binary tokens ([lollerfirst]).
### Fixed
* Multimint unit check when wallet receiving token ([thesimplekid])
* Multimint unit check when wallet receiving token ([thesimplekid]).
* Mint start up with most recent keyset after a rotation ([thesimplekid]).
### Removed

View File

@@ -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(())
}

View File

@@ -104,6 +104,7 @@ impl Mint {
} else if &highest_index_keyset.input_fee_ppk == input_fee_ppk
&& &highest_index_keyset.max_order == max_order
{
tracing::debug!("Current highest index keyset matches expect fee and max order. Setting active");
let id = highest_index_keyset.id;
let keyset = MintKeySet::generate_from_xpriv(
&secp_ctx,
@@ -116,6 +117,7 @@ impl Mint {
let mut keyset_info = highest_index_keyset;
keyset_info.active = true;
localstore.add_keyset_info(keyset_info).await?;
active_keyset_units.push(unit.clone());
localstore.set_active_keyset(unit, id).await?;
continue;
} else {

View File

@@ -49,6 +49,7 @@ test: build
# Run pure integration tests
cargo test -p cdk-integration-tests --test integration_tests_pure
cargo test -p cdk-integration-tests --test mint
# run `cargo clippy` on everything
clippy *ARGS="--locked --offline --workspace --all-targets":