mirror of
https://github.com/aljazceru/cdk.git
synced 2026-01-05 05:55:30 +01:00
Merge pull request #558 from thesimplekid/fix_example
chore: add ci tests to ci
This commit is contained in:
26
.github/workflows/ci.yml
vendored
26
.github/workflows/ci.yml
vendored
@@ -40,7 +40,31 @@ jobs:
|
||||
cargo fmt --check
|
||||
'
|
||||
- name: typos
|
||||
run: nix develop -i -L .#nightly --command typos
|
||||
run: nix develop -i -L .#nightly --command typos
|
||||
|
||||
examples:
|
||||
name: "Run examples"
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
build-args:
|
||||
[
|
||||
mint-token,
|
||||
p2pk,
|
||||
proof-selection,
|
||||
wallet
|
||||
]
|
||||
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: Run example
|
||||
run: nix develop -i -L .#stable --command cargo r --example ${{ matrix.build-args }}
|
||||
|
||||
clippy:
|
||||
name: "Stable build, clippy and test"
|
||||
|
||||
@@ -100,6 +100,7 @@ required-features = ["wallet"]
|
||||
[dev-dependencies]
|
||||
rand = "0.8.5"
|
||||
bip39 = "2.0"
|
||||
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
|
||||
criterion = "0.5.1"
|
||||
|
||||
[[bench]]
|
||||
|
||||
@@ -8,9 +8,19 @@ use cdk::wallet::types::SendKind;
|
||||
use cdk::wallet::{Wallet, WalletSubscription};
|
||||
use cdk::Amount;
|
||||
use rand::Rng;
|
||||
use tracing_subscriber::EnvFilter;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), Error> {
|
||||
let default_filter = "debug";
|
||||
|
||||
let sqlx_filter = "sqlx=warn,hyper_util=warn,reqwest=warn,rustls=warn";
|
||||
|
||||
let env_filter = EnvFilter::new(format!("{},{}", default_filter, sqlx_filter));
|
||||
|
||||
// Parse input
|
||||
tracing_subscriber::fmt().with_env_filter(env_filter).init();
|
||||
|
||||
// Initialize the memory store for the wallet
|
||||
let localstore = WalletMemoryDatabase::default();
|
||||
|
||||
@@ -20,7 +30,7 @@ async fn main() -> Result<(), Error> {
|
||||
// Define the mint URL and currency unit
|
||||
let mint_url = "https://testnut.cashu.space";
|
||||
let unit = CurrencyUnit::Sat;
|
||||
let amount = Amount::from(10);
|
||||
let amount = Amount::from(50);
|
||||
|
||||
// Create a new wallet
|
||||
let wallet = Wallet::new(mint_url, unit, Arc::new(localstore), &seed, None)?;
|
||||
@@ -62,7 +72,7 @@ async fn main() -> Result<(), Error> {
|
||||
// Send a token with the specified amount and spending conditions
|
||||
let token = wallet
|
||||
.send(
|
||||
amount,
|
||||
10.into(),
|
||||
None,
|
||||
Some(spending_conditions),
|
||||
&SplitTarget::default(),
|
||||
|
||||
@@ -161,8 +161,11 @@ impl Wallet {
|
||||
proofs: Proofs,
|
||||
include_fees: bool,
|
||||
) -> Result<Proofs, Error> {
|
||||
// TODO: Check all proofs are same unit
|
||||
|
||||
tracing::debug!(
|
||||
"Selecting proofs to send {} from {}",
|
||||
amount,
|
||||
proofs.total_amount()?
|
||||
);
|
||||
if proofs.total_amount()? < amount {
|
||||
return Err(Error::InsufficientFunds);
|
||||
}
|
||||
@@ -228,6 +231,11 @@ impl Wallet {
|
||||
amount: Amount,
|
||||
proofs: Proofs,
|
||||
) -> Result<Proofs, Error> {
|
||||
tracing::debug!(
|
||||
"Selecting proofs to swap {} from {}",
|
||||
amount,
|
||||
proofs.total_amount()?
|
||||
);
|
||||
let active_keyset_id = self.get_active_mint_keyset().await?.id;
|
||||
|
||||
let (mut active_proofs, mut inactive_proofs): (Proofs, Proofs) = proofs
|
||||
@@ -259,6 +267,11 @@ impl Wallet {
|
||||
}
|
||||
}
|
||||
|
||||
tracing::debug!(
|
||||
"Could not select proofs to swap: total selected: {}",
|
||||
selected_proofs.total_amount()?
|
||||
);
|
||||
|
||||
Err(Error::InsufficientFunds)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,19 +52,13 @@ impl Wallet {
|
||||
)
|
||||
.await?;
|
||||
|
||||
let (available_proofs, proofs_sum) = available_proofs.into_iter().fold(
|
||||
(Vec::new(), Amount::ZERO),
|
||||
|(mut acc1, mut acc2), p| {
|
||||
acc2 += p.amount;
|
||||
acc1.push(p);
|
||||
(acc1, acc2)
|
||||
},
|
||||
);
|
||||
let proofs_sum = available_proofs.total_amount()?;
|
||||
|
||||
let available_proofs = if proofs_sum < amount {
|
||||
match &conditions {
|
||||
Some(conditions) => {
|
||||
tracing::debug!("Insufficient prrofs matching conditions attempting swap");
|
||||
let unspent_proofs = self.get_unspent_proofs().await?;
|
||||
|
||||
let proofs_to_swap = self.select_proofs_to_swap(amount, unspent_proofs).await?;
|
||||
|
||||
let proofs_with_conditions = self
|
||||
|
||||
Reference in New Issue
Block a user