This repository has been archived by the owner on Nov 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add rust integration tests using cdk
- Loading branch information
Showing
12 changed files
with
149 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,4 +33,10 @@ priv/static/ | |
|
||
benchmarks/output | ||
|
||
.env | ||
.env | ||
|
||
# Rust related | ||
debug/ | ||
target/ | ||
Cargo.lock | ||
*.pdb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
[package] | ||
name = "integration-tests" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
cdk = { git = "https://github.com/cashubtc/cdk", tag = "v0.4.0" } | ||
rand = "0.8.5" | ||
assert_matches = "1.5.0" | ||
tokio = "1.41.0" | ||
url = "2.5.2" | ||
secp256k1 = {version = "0.30.0", features = ["rand", "hashes", "global-context"]} | ||
|
||
[[test]] | ||
name = "nut06" | ||
path = "nut06.rs" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
extern crate integration_tests; | ||
|
||
use assert_matches::assert_matches; | ||
use integration_tests::init_wallet; | ||
|
||
use cdk::nuts::{ | ||
ContactInfo, CurrencyUnit, MintInfo, MintMethodSettings, MintVersion, NUT04Settings, Nuts, | ||
PaymentMethod, PublicKey, | ||
}; | ||
|
||
#[tokio::test] | ||
pub async fn info() { | ||
const URL: &str = "http://localhost:4000"; | ||
let wallet = init_wallet(URL, CurrencyUnit::Sat).unwrap(); | ||
let mint_info = wallet.get_mint_info().await.unwrap().unwrap(); | ||
|
||
let expected_nuts = Nuts::new() | ||
.nut04(NUT04Settings::new( | ||
[MintMethodSettings { | ||
method: PaymentMethod::Bolt11, | ||
unit: CurrencyUnit::Sat, | ||
min_amount: None, | ||
max_amount: None, | ||
}] | ||
.to_vec(), | ||
false, | ||
)) | ||
.nut05(cdk::nuts::NUT05Settings { | ||
methods: [].to_vec(), | ||
disabled: true, | ||
}); | ||
println!("{:#?}", expected_nuts); | ||
let expected_name = "Cashubrew Cashu Mint"; | ||
let expected_pubkey = | ||
PublicKey::from_hex("0381094f72790bb014504dfc9213bd3c8450440f5d220560075dbf2f8113e9fa3e") | ||
.unwrap(); | ||
let expected_version = MintVersion::new("Cashubrew".to_string(), "0.1.0".to_string()); | ||
let expected_description = "An Elixir implementation of Cashu Mint"; | ||
let expected_contact = [ | ||
ContactInfo::new("twitter".to_string(), "@dimahledba".to_string()), | ||
ContactInfo::new( | ||
"nostr".to_string(), | ||
"npub1hr6v96g0phtxwys4x0tm3khawuuykz6s28uzwtj5j0zc7lunu99snw2e29".to_string(), | ||
), | ||
]; | ||
let now = std::time::SystemTime::now() | ||
.duration_since(std::time::UNIX_EPOCH) | ||
.unwrap() | ||
.as_secs(); | ||
|
||
assert_matches!( | ||
mint_info, | ||
MintInfo { | ||
name: Some(name) , | ||
pubkey: Some(pubkey), | ||
version: Some(version), | ||
description: Some(description), | ||
description_long: None, | ||
contact: Some(contact), | ||
nuts, | ||
icon_url: None, | ||
motd: None, | ||
time: Some(time) | ||
} if name == expected_name | ||
&& pubkey == expected_pubkey | ||
&& version == expected_version | ||
&& description == expected_description | ||
&& contact == expected_contact | ||
&& nuts == expected_nuts | ||
&& time <= now | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[toolchain] | ||
channel = "1.82.0" | ||
components = ["rustfmt", "clippy", "rust-analyzer"] | ||
profile = "minimal" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
use cdk::cdk_database::WalletMemoryDatabase; | ||
use cdk::nuts::CurrencyUnit; | ||
use cdk::wallet::Wallet; | ||
use rand::Rng; | ||
use std::sync::Arc; | ||
|
||
pub fn init_wallet(mint_url: &str, unit: CurrencyUnit) -> Result<Wallet, cdk::Error> { | ||
let seed = rand::thread_rng().gen::<[u8; 32]>(); | ||
|
||
let localstore = WalletMemoryDatabase::default(); | ||
Wallet::new(mint_url, unit, Arc::new(localstore), &seed, None) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.