diff --git a/Cargo.lock b/Cargo.lock index 6475d9a3..5af63b9e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -129,18 +129,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "client_side_validation" -version = "1.0.0-rc.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc54cd31c720c00385a36ee2fe817fede66958e349f582e3354980503d75248a" -dependencies = [ - "amplify", - "amplify_derive", - "bitcoin_hashes", - "strict_encoding 1.0.0-rc.3 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "client_side_validation" version = "1.0.0-rc.2" @@ -362,7 +350,7 @@ dependencies = [ "amplify_derive", "bitcoin", "bitcoin_hashes", - "client_side_validation 1.0.0-rc.1", + "client_side_validation", "descriptor-wallet", "lazy_static", "miniscript", diff --git a/Cargo.toml b/Cargo.toml index 8be22f9a..59d4763f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,7 +37,7 @@ crate-type = ["rlib", "staticlib"] amplify = { version = "3", features = ["stringly_conversions"] } amplify_derive = "2.4.3" strict_encoding = { version = "1.0.0-rc.3", features = ["miniscript", "derive"] } -client_side_validation = { version = "1.0.0-rc.1" } +client_side_validation = { version = "1.0.0-rc.2", path = "client_side_validation" } # Dependencies on core rust-bitcoin ecosystem projects # ---------------------------------------------------- bitcoin = { version = "~0.26.0", features = ["rand"] } @@ -52,8 +52,8 @@ descriptor-wallet = "~0.3.0-rc.1" # features for a dependency. See # for the explanation # and references. -serde_crate = { package = "serde", version = "~1.0.106", features = ["derive"], optional = true } -serde_with = { version = "~1.5.1", features = ["hex"], optional = true } +serde_crate = { package = "serde", version = "1.0", features = ["derive"], optional = true } +serde_with = { version = "1.5", features = ["hex"], optional = true } serde_with_macros = { version = "~1.2.0", optional = true } # Fix for the problem in 1.3.0 # Core rust projects # ------------------ diff --git a/client_side_validation/src/commit_verify.rs b/client_side_validation/src/commit_verify.rs index 25292d8f..7cb12593 100644 --- a/client_side_validation/src/commit_verify.rs +++ b/client_side_validation/src/commit_verify.rs @@ -117,50 +117,16 @@ where } } -#[cfg(test)] -pub(crate) mod test { +pub mod test_helpers { use super::*; - use bitcoin_hashes::{hex::FromHex, sha256d}; + use bitcoin_hashes::hex::FromHex; use core::fmt::Debug; use core::hash::Hash; use std::collections::HashSet; - #[derive(Debug, Display, Error)] - #[display(Debug)] - struct Error; - #[derive(Clone, PartialEq, Eq, Debug, Hash)] - struct DummyHashCommitment(sha256d::Hash); - impl CommitVerify for DummyHashCommitment - where - T: AsRef<[u8]>, - { - fn commit(msg: &T) -> Self { - Self(bitcoin_hashes::Hash::hash(msg.as_ref())) - } - } - - #[derive(Clone, PartialEq, Eq, Debug, Hash)] - struct DummyVec(Vec); - impl EmbedCommitVerify for DummyVec - where - T: AsRef<[u8]>, - { - type Container = DummyVec; - type Error = Error; - - fn embed_commit( - container: &mut Self::Container, - msg: &T, - ) -> Result { - let mut result = container.0.clone(); - result.extend(msg.as_ref()); - Ok(DummyVec(result)) - } - } - /// All of these messages MUST produce different commitments, otherwise the /// commitment algorithm is not collision-resistant - pub(crate) fn gen_messages() -> Vec> { + pub fn gen_messages() -> Vec> { vec![ // empty message b"".to_vec(), @@ -187,7 +153,7 @@ pub(crate) mod test { ] } - pub(crate) fn commit_verify_suite(messages: Vec) + pub fn commit_verify_suite(messages: Vec) where MSG: AsRef<[u8]> + Eq, CMT: CommitVerify + Eq + Hash + Debug, @@ -226,7 +192,7 @@ pub(crate) mod test { ); } - pub(crate) fn embed_commit_verify_suite( + pub fn embed_commit_verify_suite( messages: Vec, container: &mut CMT::Container, ) where @@ -272,6 +238,48 @@ pub(crate) mod test { }, ); } +} + +#[cfg(test)] +mod test { + use super::test_helpers::*; + use super::*; + use bitcoin_hashes::sha256d; + use core::fmt::Debug; + use core::hash::Hash; + + #[derive(Debug, Display, Error)] + #[display(Debug)] + struct Error; + #[derive(Clone, PartialEq, Eq, Debug, Hash)] + struct DummyHashCommitment(sha256d::Hash); + impl CommitVerify for DummyHashCommitment + where + T: AsRef<[u8]>, + { + fn commit(msg: &T) -> Self { + Self(bitcoin_hashes::Hash::hash(msg.as_ref())) + } + } + + #[derive(Clone, PartialEq, Eq, Debug, Hash)] + struct DummyVec(Vec); + impl EmbedCommitVerify for DummyVec + where + T: AsRef<[u8]>, + { + type Container = DummyVec; + type Error = Error; + + fn embed_commit( + container: &mut Self::Container, + msg: &T, + ) -> Result { + let mut result = container.0.clone(); + result.extend(msg.as_ref()); + Ok(DummyVec(result)) + } + } #[test] fn test_commit_verify() { diff --git a/client_side_validation/src/digests.rs b/client_side_validation/src/digests.rs index 88dd424d..1e934a69 100644 --- a/client_side_validation/src/digests.rs +++ b/client_side_validation/src/digests.rs @@ -100,7 +100,7 @@ where #[cfg(test)] mod test { - use crate::commit_verify::test::*; + use crate::commit_verify::test_helpers::*; use bitcoin_hashes::*; #[test] diff --git a/client_side_validation/src/lib.rs b/client_side_validation/src/lib.rs index 4f41b980..e87e4e21 100644 --- a/client_side_validation/src/lib.rs +++ b/client_side_validation/src/lib.rs @@ -47,7 +47,7 @@ pub mod commit_verify; mod digests; pub mod single_use_seals; -pub use client_side_validation::{ +pub use crate::client_side_validation::{ commit_strategy, merklize, CommitEncode, CommitEncodeWithStrategy, Conceal, ConsensusCommit, MerkleNode, }; diff --git a/src/chain.rs b/src/chain.rs index 19fe2c85..3af1ce67 100644 --- a/src/chain.rs +++ b/src/chain.rs @@ -938,7 +938,7 @@ impl FromStr for Chain { #[cfg(test)] mod test { use super::*; - use crate::test_helpers::test_suite; + use strict_encoding::test_helpers::test_suite; #[test] fn test_p2p_magic_number_byteorder() { @@ -1093,6 +1093,8 @@ mod test { bitcoin::Network::try_from(P2pNetworkId::Other(0xA1A2A3A4)).unwrap(); } + // TODO: Test must be rewritten + /* #[test] fn test_chain_param_enums() { test_enum_u8_exhaustive!(ChainFormat; @@ -1111,6 +1113,7 @@ mod test { AssetSystem::RgbContract => 2 ); } + */ #[test] fn test_asset_params_eq() { diff --git a/src/dbc/keyset.rs b/src/dbc/keyset.rs index b3a13940..eba27ec9 100644 --- a/src/dbc/keyset.rs +++ b/src/dbc/keyset.rs @@ -132,12 +132,14 @@ where #[cfg(test)] mod test { use super::*; - use crate::bp::dbc::pubkey::*; - use crate::bp::test::*; - use crate::commit_verify::test::*; + use crate::dbc::pubkey::*; + use crate::test::gen_secp_pubkeys; use amplify::Wrapper; use bitcoin::hashes::{hex::ToHex, sha256, Hash}; use bitcoin::secp256k1; + use client_side_validation::commit_verify::test_helpers::{ + embed_commit_verify_suite, gen_messages, + }; use std::iter::FromIterator; use std::str::FromStr; diff --git a/src/dbc/pubkey.rs b/src/dbc/pubkey.rs index abd78279..db1cc88c 100644 --- a/src/dbc/pubkey.rs +++ b/src/dbc/pubkey.rs @@ -125,11 +125,11 @@ where #[cfg(test)] mod test { use super::*; - use crate::bp::test::*; - use crate::commit_verify::test::*; + use crate::test::*; use amplify::Wrapper; use bitcoin::hashes::{hex::ToHex, sha256, Hash}; use bitcoin::secp256k1; + use client_side_validation::commit_verify::test_helpers::*; use std::str::FromStr; #[test] diff --git a/src/dbc/tx.rs b/src/dbc/tx.rs index 95d58432..9d8f7dad 100644 --- a/src/dbc/tx.rs +++ b/src/dbc/tx.rs @@ -155,7 +155,7 @@ where #[cfg(test)] mod test { use super::*; - use crate::bp::dbc::{ScriptEncodeData, ScriptEncodeMethod, SpkContainer}; + use crate::dbc::{ScriptEncodeData, ScriptEncodeMethod, SpkContainer}; use bitcoin::consensus::encode::deserialize; use bitcoin::hashes::hex::FromHex; use std::str::FromStr; diff --git a/src/lib.rs b/src/lib.rs index 678d4284..951bda13 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -65,8 +65,8 @@ pub use tagged_hash::TaggedHash; #[cfg(test)] pub mod test { - use crate::SECP256K1; use bitcoin::secp256k1; + use wallet::SECP256K1; pub fn gen_secp_pubkeys(n: usize) -> Vec { let mut ret = Vec::with_capacity(n); diff --git a/src/seals/lnpbp1.rs b/src/seals/lnpbp1.rs index 5e89ec2e..36877917 100644 --- a/src/seals/lnpbp1.rs +++ b/src/seals/lnpbp1.rs @@ -218,8 +218,8 @@ mod test { use std::str::FromStr; use super::*; - use crate::bp::test::*; - use crate::paradigms::commit_verify::test::*; + use crate::test::*; + use client_side_validation::commit_verify::test_helpers::*; #[test] fn test_lnpbp1_tag() {