Skip to content

Commit

Permalink
Adds/updates tests
Browse files Browse the repository at this point in the history
  • Loading branch information
arya2 committed May 14, 2024
1 parent b476485 commit 29166cf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions zebra-chain/src/parameters/network/magic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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! {
Expand Down
20 changes: 20 additions & 0 deletions zebra-network/src/protocol/external/codec/tests/vectors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

0 comments on commit 29166cf

Please sign in to comment.