From b03602bfaabf20f809f0ce7df2eb8275b4235cc1 Mon Sep 17 00:00:00 2001 From: Andrew Poelstra Date: Sat, 18 Mar 2023 16:00:56 +0000 Subject: [PATCH] tests: replace cbor with more-recently-deprecated serde_cbor The `cbor` crate has been unmaintained for several years, and depends on the ancient `rustc_serialize` crate which (a) doesn't build on WASM, and (b) doesn't build when we use a minimal-dep Cargo.lock. (The latter is because cbor specifies rustc_serialize 0.3.0 when it should specify 0.3.1, but there is nothing we can do to fix that when cbor is unmaintained.) This changes a hardcoded value in a regression test, but it's because we're replacing the serialization engine rather than changing our code, so this is not actually a change. --- Cargo.toml | 6 +----- tests/serde.rs | 16 ++++++---------- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 09743c0..68f11dd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -47,14 +47,10 @@ rand = { version = "0.8", default-features = false, optional = true } [dev-dependencies] rand_core = "0.6" +serde_cbor = "0.10.0" serde_test = "1.0" bincode = "1.3.3" -# cbor does not build on WASM, we use it in a single trivial test (an example of when -# fixed-width-serde breaks down). Just run the test when on an x86_64 machine. -[target.'cfg(target_arch = "x86_64")'.dev-dependencies] -cbor = "0.4.1" - [target.wasm32-unknown-unknown.dev-dependencies] wasm-bindgen-test = "0.3" getrandom = { version = "0.2", features = ["js"] } diff --git a/tests/serde.rs b/tests/serde.rs index c3c5d2b..e68fcfd 100644 --- a/tests/serde.rs +++ b/tests/serde.rs @@ -1,8 +1,7 @@ #![cfg(feature = "serde")] extern crate bincode; -#[cfg(target_arch = "x86_64")] -extern crate cbor; +extern crate serde_cbor; extern crate secp256k1; #[cfg(feature = "global-context")] @@ -77,15 +76,12 @@ fn bincode_x_only_public_key() { assert_eq!(ser, XONLY_PK_BYTES); } -// cbor adds an additional byte of metadata to certain byte values (byte_value < 24). #[test] -#[cfg(target_arch = "x86_64")] fn cbor() { let sk = secret_key(); - - let mut e = cbor::Encoder::from_memory(); - e.encode(sk.as_ref()).unwrap(); - - // 52 because there are 22 bytes in the key for which cbor adds metadata. - assert_eq!(e.as_bytes().len(), 52); + let e = serde_cbor::to_vec(&sk).unwrap(); + // Secret key is 32 bytes. CBOR adds a byte of metadata for 20 of these bytes, + // (Apparently, any byte whose value is <24 gets an extra byte.) + // It also adds a 1-byte length prefix and a byte of metadata for the whole vector. + assert_eq!(e.len(), 54); }