refactor: remove #[reth_codec] and #[derive_arbitrary] macros (#10263)

This commit is contained in:
Arsenii Kulikov
2024-08-12 22:23:50 +08:00
committed by GitHub
parent 6eae55e516
commit 330f73b7ec
45 changed files with 240 additions and 206 deletions

View File

@ -1,6 +1,6 @@
use crate::{Capability, EthVersion, ProtocolVersion};
use alloy_rlp::{RlpDecodable, RlpEncodable};
use reth_codecs::derive_arbitrary;
use reth_codecs::add_arbitrary_tests;
use reth_network_peers::PeerId;
use reth_primitives::constants::RETH_CLIENT_VERSION;
@ -103,9 +103,10 @@ impl HelloMessageWithProtocols {
/// supported RLPx protocol version and capabilities.
///
/// See also <https://github.com/ethereum/devp2p/blob/master/rlpx.md#hello-0x00>
#[derive_arbitrary(rlp)]
#[derive(Clone, Debug, PartialEq, Eq, RlpEncodable, RlpDecodable)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))]
#[add_arbitrary_tests(rlp)]
pub struct HelloMessage {
/// The version of the `p2p` protocol.
pub protocol_version: ProtocolVersion,

View File

@ -8,7 +8,7 @@ use crate::{
use alloy_rlp::{Decodable, Encodable, Error as RlpError, EMPTY_LIST_CODE};
use futures::{Sink, SinkExt, StreamExt};
use pin_project::pin_project;
use reth_codecs::derive_arbitrary;
use reth_codecs::add_arbitrary_tests;
use reth_metrics::metrics::counter;
use reth_primitives::{
bytes::{Buf, BufMut, Bytes, BytesMut},
@ -642,9 +642,10 @@ where
}
/// This represents only the reserved `p2p` subprotocol messages.
#[derive_arbitrary(rlp)]
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))]
#[add_arbitrary_tests(rlp)]
pub enum P2PMessage {
/// The first packet sent over the connection, and sent once by both sides.
Hello(HelloMessage),

View File

@ -49,7 +49,7 @@ macro_rules! fuzz_type_and_name {
pub mod fuzz_rlp {
use crate::roundtrip_encoding;
use alloy_rlp::{RlpDecodableWrapper, RlpEncodableWrapper};
use reth_codecs::derive_arbitrary;
use reth_codecs::add_arbitrary_tests;
use reth_eth_wire::{
BlockBodies, BlockHeaders, DisconnectReason, GetBlockBodies, GetBlockHeaders, GetNodeData,
GetPooledTransactions, GetReceipts, HelloMessage, NewBlock, NewBlockHashes,
@ -78,7 +78,6 @@ pub mod fuzz_rlp {
// see message below for why wrapper types are necessary for fuzzing types that do not have a
// Default impl
#[derive_arbitrary(rlp)]
#[derive(
Clone,
Debug,
@ -89,6 +88,8 @@ pub mod fuzz_rlp {
RlpEncodableWrapper,
RlpDecodableWrapper,
)]
#[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))]
#[add_arbitrary_tests(rlp)]
struct HelloMessageWrapper(HelloMessage);
impl Default for HelloMessageWrapper {
@ -120,7 +121,6 @@ pub mod fuzz_rlp {
//
// We just provide a default value here so test-fuzz can auto-generate a corpus file for the
// type.
#[derive_arbitrary(rlp)]
#[derive(
Clone,
Debug,
@ -131,6 +131,8 @@ pub mod fuzz_rlp {
RlpEncodableWrapper,
RlpDecodableWrapper,
)]
#[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))]
#[add_arbitrary_tests(rlp)]
struct GetBlockHeadersWrapper(GetBlockHeaders);
impl Default for GetBlockHeadersWrapper {