Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unit tests for ecash functions in client #5

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
cashu_escrow_common = { path = "../common" }
6 changes: 4 additions & 2 deletions client/src/ecash/mod.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
mod tests_ecash;

use super::*;

use escrow_client::EscrowUser;
use cdk::secp256k1::rand::Rng;
use cdk::{
amount::SplitTarget,
cdk_database::WalletMemoryDatabase,
nuts::{Conditions, CurrencyUnit, PublicKey, SecretKey, SigFlag, SpendingConditions, Token},
wallet::Wallet,
};
use escrow_client::EscrowUser;
use std::str::FromStr;
use std::sync::Arc;

Expand Down Expand Up @@ -50,7 +52,7 @@ impl EcashWallet {
Some(vec![buyer_pubkey]),
Some(2),
Some(SigFlag::SigAll),
)?)
)?),
);
Ok(spending_conditions)
}
Expand Down
53 changes: 53 additions & 0 deletions client/src/ecash/tests_ecash.rs
Original file line number Diff line number Diff line change
@@ -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;
}