Skip to content

Commit b03602b

Browse files
committed
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.
1 parent d738998 commit b03602b

File tree

2 files changed

+7
-15
lines changed

2 files changed

+7
-15
lines changed

Cargo.toml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,10 @@ rand = { version = "0.8", default-features = false, optional = true }
4747

4848
[dev-dependencies]
4949
rand_core = "0.6"
50+
serde_cbor = "0.10.0"
5051
serde_test = "1.0"
5152
bincode = "1.3.3"
5253

53-
# cbor does not build on WASM, we use it in a single trivial test (an example of when
54-
# fixed-width-serde breaks down). Just run the test when on an x86_64 machine.
55-
[target.'cfg(target_arch = "x86_64")'.dev-dependencies]
56-
cbor = "0.4.1"
57-
5854
[target.wasm32-unknown-unknown.dev-dependencies]
5955
wasm-bindgen-test = "0.3"
6056
getrandom = { version = "0.2", features = ["js"] }

tests/serde.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
#![cfg(feature = "serde")]
22

33
extern crate bincode;
4-
#[cfg(target_arch = "x86_64")]
5-
extern crate cbor;
4+
extern crate serde_cbor;
65
extern crate secp256k1;
76

87
#[cfg(feature = "global-context")]
@@ -77,15 +76,12 @@ fn bincode_x_only_public_key() {
7776
assert_eq!(ser, XONLY_PK_BYTES);
7877
}
7978

80-
// cbor adds an additional byte of metadata to certain byte values (byte_value < 24).
8179
#[test]
82-
#[cfg(target_arch = "x86_64")]
8380
fn cbor() {
8481
let sk = secret_key();
85-
86-
let mut e = cbor::Encoder::from_memory();
87-
e.encode(sk.as_ref()).unwrap();
88-
89-
// 52 because there are 22 bytes in the key for which cbor adds metadata.
90-
assert_eq!(e.as_bytes().len(), 52);
82+
let e = serde_cbor::to_vec(&sk).unwrap();
83+
// Secret key is 32 bytes. CBOR adds a byte of metadata for 20 of these bytes,
84+
// (Apparently, any byte whose value is <24 gets an extra byte.)
85+
// It also adds a 1-byte length prefix and a byte of metadata for the whole vector.
86+
assert_eq!(e.len(), 54);
9187
}

0 commit comments

Comments
 (0)