Merge rust-bitcoin/rust-bitcoin#2399: Use `Magic::BITCOIN` in unit tests
6ddb5cce37
Use Magic::BITCOIN in unit tests (Tobin C. Harding) Pull request description: We are currently calling `From` to create the magic bytes, this is unnecessary since `Magic` provides consts. Refactor only, no logic changes. ACKs for top commit: Kixunil: ACK6ddb5cce37
apoelstra: ACK6ddb5cce37
Tree-SHA512: 20e2e017683f123309e3c0876bba42d86a9411bb225f07c486716184fc79837e04a832338ec8b18874ac76791260f6a4620b932ede92c8b222dac08d468cef8a
This commit is contained in:
commit
2971740fd4
|
@ -548,7 +548,6 @@ mod test {
|
||||||
use crate::blockdata::script::ScriptBuf;
|
use crate::blockdata::script::ScriptBuf;
|
||||||
use crate::blockdata::transaction::Transaction;
|
use crate::blockdata::transaction::Transaction;
|
||||||
use crate::consensus::encode::{deserialize, deserialize_partial, serialize};
|
use crate::consensus::encode::{deserialize, deserialize_partial, serialize};
|
||||||
use crate::network::Network;
|
|
||||||
use crate::p2p::address::{AddrV2, AddrV2Message, Address};
|
use crate::p2p::address::{AddrV2, AddrV2Message, Address};
|
||||||
use crate::p2p::message_blockdata::{GetBlocksMessage, GetHeadersMessage, Inventory};
|
use crate::p2p::message_blockdata::{GetBlocksMessage, GetHeadersMessage, Inventory};
|
||||||
use crate::p2p::message_bloom::{BloomFlags, FilterAdd, FilterLoad};
|
use crate::p2p::message_bloom::{BloomFlags, FilterAdd, FilterLoad};
|
||||||
|
@ -701,7 +700,7 @@ mod test {
|
||||||
#[test]
|
#[test]
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
fn serialize_verack_test() {
|
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,
|
vec![0xf9, 0xbe, 0xb4, 0xd9, 0x76, 0x65, 0x72, 0x61,
|
||||||
0x63, 0x6B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
0x63, 0x6B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
0x00, 0x00, 0x00, 0x00, 0x5d, 0xf6, 0xe0, 0xe2]);
|
0x00, 0x00, 0x00, 0x00, 0x5d, 0xf6, 0xe0, 0xe2]);
|
||||||
|
@ -710,7 +709,7 @@ mod test {
|
||||||
#[test]
|
#[test]
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
fn serialize_ping_test() {
|
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,
|
vec![0xf9, 0xbe, 0xb4, 0xd9, 0x70, 0x69, 0x6e, 0x67,
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
0x08, 0x00, 0x00, 0x00, 0x24, 0x67, 0xf1, 0x1d,
|
0x08, 0x00, 0x00, 0x00, 0x24, 0x67, 0xf1, 0x1d,
|
||||||
|
@ -720,7 +719,7 @@ mod test {
|
||||||
#[test]
|
#[test]
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
fn serialize_mempool_test() {
|
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,
|
vec![0xf9, 0xbe, 0xb4, 0xd9, 0x6d, 0x65, 0x6d, 0x70,
|
||||||
0x6f, 0x6f, 0x6c, 0x00, 0x00, 0x00, 0x00, 0x00,
|
0x6f, 0x6f, 0x6c, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
0x00, 0x00, 0x00, 0x00, 0x5d, 0xf6, 0xe0, 0xe2]);
|
0x00, 0x00, 0x00, 0x00, 0x5d, 0xf6, 0xe0, 0xe2]);
|
||||||
|
@ -729,7 +728,7 @@ mod test {
|
||||||
#[test]
|
#[test]
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
fn serialize_getaddr_test() {
|
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,
|
vec![0xf9, 0xbe, 0xb4, 0xd9, 0x67, 0x65, 0x74, 0x61,
|
||||||
0x64, 0x64, 0x72, 0x00, 0x00, 0x00, 0x00, 0x00,
|
0x64, 0x64, 0x72, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
0x00, 0x00, 0x00, 0x00, 0x5d, 0xf6, 0xe0, 0xe2]);
|
0x00, 0x00, 0x00, 0x00, 0x5d, 0xf6, 0xe0, 0xe2]);
|
||||||
|
@ -744,7 +743,7 @@ mod test {
|
||||||
0x00, 0x00, 0x00, 0x00, 0x5d, 0xf6, 0xe0, 0xe2
|
0x00, 0x00, 0x00, 0x00, 0x5d, 0xf6, 0xe0, 0xe2
|
||||||
]);
|
]);
|
||||||
let preimage =
|
let preimage =
|
||||||
RawNetworkMessage::new(Magic::from(Network::Bitcoin), NetworkMessage::GetAddr);
|
RawNetworkMessage::new(Magic::BITCOIN, NetworkMessage::GetAddr);
|
||||||
assert!(msg.is_ok());
|
assert!(msg.is_ok());
|
||||||
let msg: RawNetworkMessage = msg.unwrap();
|
let msg: RawNetworkMessage = msg.unwrap();
|
||||||
assert_eq!(preimage.magic, msg.magic);
|
assert_eq!(preimage.magic, msg.magic);
|
||||||
|
@ -775,7 +774,7 @@ mod test {
|
||||||
|
|
||||||
assert!(msg.is_ok());
|
assert!(msg.is_ok());
|
||||||
let msg = msg.unwrap();
|
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 {
|
if let NetworkMessage::Version(version_msg) = msg.payload {
|
||||||
assert_eq!(version_msg.version, 70015);
|
assert_eq!(version_msg.version, 70015);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
@ -821,7 +820,7 @@ mod test {
|
||||||
|
|
||||||
let (msg, consumed) = msg.unwrap();
|
let (msg, consumed) = msg.unwrap();
|
||||||
assert_eq!(consumed, data.to_vec().len() - 2);
|
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 {
|
if let NetworkMessage::Version(version_msg) = msg.payload {
|
||||||
assert_eq!(version_msg.version, 70015);
|
assert_eq!(version_msg.version, 70015);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
|
Loading…
Reference in New Issue