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.
This commit is contained in:
Andrew Poelstra 2023-03-18 16:00:56 +00:00
parent d738998486
commit b03602bfaa
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
2 changed files with 7 additions and 15 deletions

View File

@ -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"] }

View File

@ -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);
}