From 43ea342979b5df69d3041f7953585cd22e1b3fb3 Mon Sep 17 00:00:00 2001 From: vnprc Date: Mon, 12 Aug 2024 18:33:17 -0400 Subject: [PATCH] refactor(mint): restructure test to use MintConfig struct --- crates/cdk/src/mint/mod.rs | 67 +++++++++++++++++++++++--------------- 1 file changed, 40 insertions(+), 27 deletions(-) diff --git a/crates/cdk/src/mint/mod.rs b/crates/cdk/src/mint/mod.rs index 0bcb53f5..566d0cb0 100644 --- a/crates/cdk/src/mint/mod.rs +++ b/crates/cdk/src/mint/mod.rs @@ -1421,41 +1421,52 @@ mod tests { use cdk_database::mint_memory::MintMemoryDatabase; - #[tokio::test] - async fn mint_mod_new_mint() { - // mock DB settings - let active_keysets: HashMap = HashMap::new(); - let keysets: Vec = Vec::new(); - let mint_quotes: Vec = Vec::new(); - let melt_quotes: Vec = Vec::new(); - let pending_proofs: Proofs = Proofs::new(); - let spent_proofs: Proofs = Proofs::new(); - let blinded_signatures: HashMap<[u8; 33], BlindSignature> = HashMap::new(); + #[derive(Default)] + struct MintConfig<'a> { + active_keysets: HashMap, + keysets: Vec, + mint_quotes: Vec, + melt_quotes: Vec, + pending_proofs: Proofs, + spent_proofs: Proofs, + blinded_signatures: HashMap<[u8; 33], BlindSignature>, + mint_url: &'a str, + seed: &'a [u8], + mint_info: MintInfo, + supported_units: HashMap, + } - // Mock data - let mint_url = "http://example.com"; - let seed = b"some_random_seed"; - let mint_info = MintInfo::default(); + async fn create_mint(config: MintConfig<'_>) -> Result { let localstore = Arc::new( MintMemoryDatabase::new( - active_keysets, - keysets, - mint_quotes, - melt_quotes, - pending_proofs, - spent_proofs, - blinded_signatures, + config.active_keysets, + config.keysets, + config.mint_quotes, + config.melt_quotes, + config.pending_proofs, + config.spent_proofs, + config.blinded_signatures, ) .unwrap(), ); - let supported_units: HashMap = HashMap::new(); - // Instantiate a new Mint - let mint = Mint::new(mint_url, seed, mint_info, localstore, supported_units).await; + Mint::new( + config.mint_url, + config.seed, + config.mint_info, + localstore, + config.supported_units, + ) + .await + } - // Assert the mint was created successfully - assert!(mint.is_ok()); - let mint = mint.unwrap(); + #[tokio::test] + async fn mint_mod_new_mint() -> Result<(), Error> { + let config = MintConfig::<'_> { + mint_url: "http://example.com", + ..Default::default() + }; + let mint = create_mint(config).await?; assert_eq!(mint.get_mint_url().to_string(), "http://example.com"); let info = mint.mint_info(); @@ -1484,5 +1495,7 @@ mod tests { mint.total_redeemed().await.unwrap(), HashMap::::new() ); + + Ok(()) } }