diff --git a/client/Cargo.toml b/client/Cargo.toml index f704f37..b1db26e 100644 --- a/client/Cargo.toml +++ b/client/Cargo.toml @@ -10,10 +10,10 @@ nostr-sdk = { version = "0.32.0", features = ["nip04"] } cdk = "0.1.1" dotenv = "0.15.0" anyhow = "1.0.86" -tokio = "1.38.0" +tokio = { version = "1.38.0", features = ["test-util"] } rand = "0.8.5" serde = "1.0.203" serde_json = "1.0.117" sha2 = "0.10.8" -cashu_escrow_common = { path = "../common" } \ No newline at end of file +cashu_escrow_common = { path = "../common" } diff --git a/client/src/ecash/mod.rs b/client/src/ecash/mod.rs index a8e10f5..09699cf 100644 --- a/client/src/ecash/mod.rs +++ b/client/src/ecash/mod.rs @@ -1,6 +1,7 @@ +mod tests_ecash; + use super::*; -use escrow_client::EscrowUser; use cdk::secp256k1::rand::Rng; use cdk::{ amount::SplitTarget, @@ -8,6 +9,7 @@ use cdk::{ nuts::{Conditions, CurrencyUnit, PublicKey, SecretKey, SigFlag, SpendingConditions, Token}, wallet::Wallet, }; +use escrow_client::EscrowUser; use std::str::FromStr; use std::sync::Arc; @@ -50,7 +52,7 @@ impl EcashWallet { Some(vec![buyer_pubkey]), Some(2), Some(SigFlag::SigAll), - )?) + )?), ); Ok(spending_conditions) } diff --git a/client/src/ecash/tests_ecash.rs b/client/src/ecash/tests_ecash.rs new file mode 100644 index 0000000..393941d --- /dev/null +++ b/client/src/ecash/tests_ecash.rs @@ -0,0 +1,53 @@ +use cdk::wallet; + +#[cfg(test)] +use super::super::EcashWallet; +use super::*; + +async fn _new_testing_wallet() -> EcashWallet { + let secret = SecretKey::generate(); + let trade_pubkey: String = secret.public_key().to_string(); + EcashWallet { + secret, + wallet: Wallet::new( + "", + CurrencyUnit::Sat, + Arc::new(WalletMemoryDatabase::default()), + &rand::thread_rng().gen::<[u8; 32]>(), + ), + trade_pubkey, + } +} + +async fn _get_dummy_escrow_user() -> EscrowUser { + let trade_beginning_ts = Timestamp::from(1720724405); + let escrow_coordintor_npub = ""; + let escrow_coordinator_cashu_pk = PublicKey::from_hex("").unwrap(); + let contract = TradeContract { + trade_id: 0, + buyer_ecash_public_key: "".to_string(), + seller_ecash_public_key: "".to_string(), + trade_amount_sat: 0, + trade_description: "".to_string(), + time_limit: 0, + trade_beginning_ts: 0, + }; + let wallet = _new_testing_wallet().await; + let nostr_client = NostrClient::new().await.unwrap(); + EscrowUser {} +} + +#[tokio::test] +async fn test_escrow_token_creation() { + let wallet = _new_testing_wallet().await; +} + +#[tokio::test] +async fn test_invalid_escrow_token_validation() { + let wallet = _new_testing_wallet().await; +} + +#[tokio::test] +async fn test_valid_escrow_token_validation() { + let wallet = _new_testing_wallet().await; +}