fn powers_of_two_round_trip_successfully() {
for i in 0..128 {
let n = 1 << i;
let encoded = encode(n);
let (decoded, length) = decode(&encoded).unwrap();
assert_eq!(decoded, n);
assert_eq!(length, encoded.len());
}
}
#[test]
fn alternating_bit_strings_round_trip_successfully() {
let mut n = 0;
for i in 0..129 {
n = n << 1 | (i % 2);
let encoded = encode(n);
let (decoded, length) = decode(&encoded).unwrap();
assert_eq!(decoded, n);
assert_eq!(length, encoded.len());
}
}
#[test]
fn decoding_integer_over_max_is_an_error() {
assert_eq!(
decode(&[
130, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 255,
0,
]),
Err(Error::Varint)
);
}
#[test]
fn taproot_annex_format_bip_test_vectors_round_trip_successfully() {
const TEST_VECTORS: &[(u128, &[u8])] = &[
(0, &[0x00]),
(1, &[0x01]),
(127, &[0x7F]),
(128, &[0x80, 0x00]),