From 29166cfe05bd78d33b5c214854ef8a9ec1d751f2 Mon Sep 17 00:00:00 2001 From: Arya Date: Mon, 13 May 2024 20:54:45 -0400 Subject: [PATCH] Adds/updates tests --- zebra-chain/src/parameters/network/magic.rs | 1 + .../protocol/external/codec/tests/vectors.rs | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/zebra-chain/src/parameters/network/magic.rs b/zebra-chain/src/parameters/network/magic.rs index e04e3614a0b..692a1b8d1ab 100644 --- a/zebra-chain/src/parameters/network/magic.rs +++ b/zebra-chain/src/parameters/network/magic.rs @@ -41,6 +41,7 @@ mod proptest { assert_eq!(format!("{:?}", magics::MAINNET), "Magic(\"24e92764\")"); assert_eq!(format!("{:?}", magics::TESTNET), "Magic(\"fa1af9bf\")"); + assert_eq!(format!("{:?}", magics::REGTEST), "Magic(\"aae83f5f\")"); } proptest! { diff --git a/zebra-network/src/protocol/external/codec/tests/vectors.rs b/zebra-network/src/protocol/external/codec/tests/vectors.rs index 74f46ec7f52..da6b3ce5830 100644 --- a/zebra-network/src/protocol/external/codec/tests/vectors.rs +++ b/zebra-network/src/protocol/external/codec/tests/vectors.rs @@ -587,3 +587,23 @@ fn reject_command_and_reason_size_limits() { }; } } + +/// Check that the version test vector deserialization fails when there's a network magic mismatch. +#[test] +fn message_with_wrong_network_magic_returns_error() { + let _init_guard = zebra_test::init(); + let mut codec = Codec::builder().finish(); + let mut bytes = BytesMut::new(); + + codec + .encode(VERSION_TEST_VECTOR.clone(), &mut bytes) + .expect("encoding should succeed"); + + let mut codec = Codec::builder() + .for_network(&Network::new_default_testnet()) + .finish(); + + codec + .decode(&mut bytes) + .expect_err("decoding message with mismatching network magic should return an error"); +}