Use Magic::BITCOIN in unit tests

We are currently calling `From` to create the magic bytes, this is
unnecessary since `Magic` provides consts.

Refactor only, no logic changes.
This commit is contained in:
Tobin C. Harding 2024-01-25 14:29:28 +11:00
parent 48b42c10fb
commit 6ddb5cce37
No known key found for this signature in database
GPG Key ID: 40BF9E4C269D6607
1 changed files with 7 additions and 8 deletions

View File

@ -551,7 +551,6 @@ mod test {
use crate::blockdata::script::ScriptBuf;
use crate::blockdata::transaction::Transaction;
use crate::consensus::encode::{deserialize, deserialize_partial, serialize};
use crate::network::Network;
use crate::p2p::address::{AddrV2, AddrV2Message, Address};
use crate::p2p::message_blockdata::{GetBlocksMessage, GetHeadersMessage, Inventory};
use crate::p2p::message_bloom::{BloomFlags, FilterAdd, FilterLoad};
@ -705,7 +704,7 @@ mod test {
#[test]
#[rustfmt::skip]
fn serialize_verack_test() {
assert_eq!(serialize(&RawNetworkMessage::new(Magic::from(Network::Bitcoin), NetworkMessage::Verack)),
assert_eq!(serialize(&RawNetworkMessage::new(Magic::BITCOIN, NetworkMessage::Verack)),
vec![0xf9, 0xbe, 0xb4, 0xd9, 0x76, 0x65, 0x72, 0x61,
0x63, 0x6B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x5d, 0xf6, 0xe0, 0xe2]);
@ -714,7 +713,7 @@ mod test {
#[test]
#[rustfmt::skip]
fn serialize_ping_test() {
assert_eq!(serialize(&RawNetworkMessage::new(Magic::from(Network::Bitcoin), NetworkMessage::Ping(100))),
assert_eq!(serialize(&RawNetworkMessage::new(Magic::BITCOIN, NetworkMessage::Ping(100))),
vec![0xf9, 0xbe, 0xb4, 0xd9, 0x70, 0x69, 0x6e, 0x67,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x08, 0x00, 0x00, 0x00, 0x24, 0x67, 0xf1, 0x1d,
@ -724,7 +723,7 @@ mod test {
#[test]
#[rustfmt::skip]
fn serialize_mempool_test() {
assert_eq!(serialize(&RawNetworkMessage::new(Magic::from(Network::Bitcoin), NetworkMessage::MemPool)),
assert_eq!(serialize(&RawNetworkMessage::new(Magic::BITCOIN, NetworkMessage::MemPool)),
vec![0xf9, 0xbe, 0xb4, 0xd9, 0x6d, 0x65, 0x6d, 0x70,
0x6f, 0x6f, 0x6c, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x5d, 0xf6, 0xe0, 0xe2]);
@ -733,7 +732,7 @@ mod test {
#[test]
#[rustfmt::skip]
fn serialize_getaddr_test() {
assert_eq!(serialize(&RawNetworkMessage::new(Magic::from(Network::Bitcoin), NetworkMessage::GetAddr)),
assert_eq!(serialize(&RawNetworkMessage::new(Magic::BITCOIN, NetworkMessage::GetAddr)),
vec![0xf9, 0xbe, 0xb4, 0xd9, 0x67, 0x65, 0x74, 0x61,
0x64, 0x64, 0x72, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x5d, 0xf6, 0xe0, 0xe2]);
@ -748,7 +747,7 @@ mod test {
0x00, 0x00, 0x00, 0x00, 0x5d, 0xf6, 0xe0, 0xe2
]);
let preimage =
RawNetworkMessage::new(Magic::from(Network::Bitcoin), NetworkMessage::GetAddr);
RawNetworkMessage::new(Magic::BITCOIN, NetworkMessage::GetAddr);
assert!(msg.is_ok());
let msg: RawNetworkMessage = msg.unwrap();
assert_eq!(preimage.magic, msg.magic);
@ -779,7 +778,7 @@ mod test {
assert!(msg.is_ok());
let msg = msg.unwrap();
assert_eq!(msg.magic, Magic::from(Network::Bitcoin));
assert_eq!(msg.magic, Magic::BITCOIN);
if let NetworkMessage::Version(version_msg) = msg.payload {
assert_eq!(version_msg.version, 70015);
assert_eq!(
@ -825,7 +824,7 @@ mod test {
let (msg, consumed) = msg.unwrap();
assert_eq!(consumed, data.to_vec().len() - 2);
assert_eq!(msg.magic, Magic::from(Network::Bitcoin));
assert_eq!(msg.magic, Magic::BITCOIN);
if let NetworkMessage::Version(version_msg) = msg.payload {
assert_eq!(version_msg.version, 70015);
assert_eq!(