From 610571d05bb1be73597c64a0bf755f6c39be74fa Mon Sep 17 00:00:00 2001 From: thesimplekid Date: Mon, 30 Sep 2024 17:17:32 +0200 Subject: [PATCH] fix: itest change ordering --- crates/cdk-integration-tests/tests/fake_wallet.rs | 11 ++++++++++- crates/cdk/src/nuts/nut00/mod.rs | 12 ++++++++++++ crates/cdk/src/nuts/nut02.rs | 4 ++-- misc/fake_itests.sh | 2 +- 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/crates/cdk-integration-tests/tests/fake_wallet.rs b/crates/cdk-integration-tests/tests/fake_wallet.rs index f4516433..da505d3e 100644 --- a/crates/cdk-integration-tests/tests/fake_wallet.rs +++ b/crates/cdk-integration-tests/tests/fake_wallet.rs @@ -355,6 +355,15 @@ async fn test_fake_melt_change_in_quote() -> Result<()> { let check = wallet.melt_quote_status(&melt_quote.id).await?; - assert_eq!(melt_response.change, check.change); + assert_eq!( + melt_response + .change + .unwrap() + .sort_by(|a, b| a.amount.cmp(&b.amount)), + check + .change + .unwrap() + .sort_by(|a, b| a.amount.cmp(&b.amount)) + ); Ok(()) } diff --git a/crates/cdk/src/nuts/nut00/mod.rs b/crates/cdk/src/nuts/nut00/mod.rs index 58fbce99..58fff63a 100644 --- a/crates/cdk/src/nuts/nut00/mod.rs +++ b/crates/cdk/src/nuts/nut00/mod.rs @@ -146,6 +146,18 @@ pub struct BlindSignature { pub dleq: Option, } +impl Ord for BlindSignature { + fn cmp(&self, other: &Self) -> Ordering { + self.amount.cmp(&other.amount) + } +} + +impl PartialOrd for BlindSignature { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } +} + /// Witness #[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)] #[serde(untagged)] diff --git a/crates/cdk/src/nuts/nut02.rs b/crates/cdk/src/nuts/nut02.rs index e0e4fd15..fbe12ba7 100644 --- a/crates/cdk/src/nuts/nut02.rs +++ b/crates/cdk/src/nuts/nut02.rs @@ -48,7 +48,7 @@ pub enum Error { } /// Keyset version -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] pub enum KeySetVersion { /// Current Version 00 Version00, @@ -83,7 +83,7 @@ impl fmt::Display for KeySetVersion { /// anyone who knows the set of public keys of a mint. The keyset ID **CAN** /// be stored in a Cashu token such that the token can be used to identify /// which mint or keyset it was generated from. -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct Id { version: KeySetVersion, id: [u8; Self::BYTELEN], diff --git a/misc/fake_itests.sh b/misc/fake_itests.sh index 1ae08ed5..802b75bc 100755 --- a/misc/fake_itests.sh +++ b/misc/fake_itests.sh @@ -76,7 +76,7 @@ done # Run cargo test -cargo test -p cdk-integration-tests --test fake_wallet "test_fake_melt_change_in_quote" +cargo test -p cdk-integration-tests --test fake_wallet # cargo test -p cdk-integration-tests --test mint # Capture the exit status of cargo test