From 4c521b1c11cd4c678d9c86525475b0f5e773faf7 Mon Sep 17 00:00:00 2001 From: Justin Starry Date: Thu, 13 Feb 2025 03:07:45 +0000 Subject: [PATCH] implement Arbitrary for dcou feature --- vote-interface/Cargo.toml | 8 ++++++-- vote-interface/src/authorized_voters.rs | 4 ++-- vote-interface/src/state/mod.rs | 17 ++++++++--------- vote-interface/src/state/vote_state_1_14_11.rs | 4 ++-- 4 files changed, 18 insertions(+), 15 deletions(-) diff --git a/vote-interface/Cargo.toml b/vote-interface/Cargo.toml index a45eb92ef..6e95b547b 100644 --- a/vote-interface/Cargo.toml +++ b/vote-interface/Cargo.toml @@ -10,6 +10,7 @@ license = { workspace = true } edition = { workspace = true } [dependencies] +arbitrary = { workspace = true, features = ["derive"], optional = true } bincode = { workspace = true, optional = true } num-derive = { workspace = true } num-traits = { workspace = true } @@ -37,7 +38,6 @@ solana-system-interface = { workspace = true, features = ["bincode"], optional = solana-serialize-utils = { workspace = true } [dev-dependencies] -arbitrary = { workspace = true, features = ["derive"] } itertools = { workspace = true } rand = { workspace = true } solana-epoch-schedule = { workspace = true } @@ -52,7 +52,11 @@ bincode = [ "dep:solana-system-interface", "serde" ] -dev-context-only-utils = ["bincode"] +dev-context-only-utils = [ + "bincode", + "dep:arbitrary", + "solana-pubkey/dev-context-only-utils", +] frozen-abi = [ "dep:solana-frozen-abi", "dep:solana-frozen-abi-macro", diff --git a/vote-interface/src/authorized_voters.rs b/vote-interface/src/authorized_voters.rs index 4a367bc1e..f36c1300c 100644 --- a/vote-interface/src/authorized_voters.rs +++ b/vote-interface/src/authorized_voters.rs @@ -1,4 +1,4 @@ -#[cfg(test)] +#[cfg(feature = "dev-context-only-utils")] use arbitrary::Arbitrary; #[cfg(feature = "serde")] use serde_derive::{Deserialize, Serialize}; @@ -7,7 +7,7 @@ use {solana_clock::Epoch, solana_pubkey::Pubkey, std::collections::BTreeMap}; #[cfg_attr(feature = "frozen-abi", derive(solana_frozen_abi_macro::AbiExample))] #[cfg_attr(feature = "serde", derive(Deserialize, Serialize))] #[derive(Debug, Default, PartialEq, Eq, Clone)] -#[cfg_attr(test, derive(Arbitrary))] +#[cfg_attr(feature = "dev-context-only-utils", derive(Arbitrary))] pub struct AuthorizedVoters { authorized_voters: BTreeMap, } diff --git a/vote-interface/src/state/mod.rs b/vote-interface/src/state/mod.rs index 14859c990..4cb46cb97 100644 --- a/vote-interface/src/state/mod.rs +++ b/vote-interface/src/state/mod.rs @@ -1,5 +1,7 @@ //! Vote state +#[cfg(feature = "dev-context-only-utils")] +use arbitrary::Arbitrary; #[cfg(all(not(target_os = "solana"), feature = "bincode"))] use bincode::deserialize; #[cfg(feature = "bincode")] @@ -18,10 +20,7 @@ use { std::{collections::VecDeque, fmt::Debug}, }; #[cfg(test)] -use { - arbitrary::{Arbitrary, Unstructured}, - solana_epoch_schedule::MAX_LEADER_SCHEDULE_EPOCH_OFFSET, -}; +use {arbitrary::Unstructured, solana_epoch_schedule::MAX_LEADER_SCHEDULE_EPOCH_OFFSET}; mod vote_state_0_23_5; pub mod vote_state_1_14_11; @@ -82,7 +81,7 @@ impl Vote { #[cfg_attr(feature = "frozen-abi", derive(AbiExample))] #[cfg_attr(feature = "serde", derive(Deserialize, Serialize))] #[derive(Default, Debug, PartialEq, Eq, Copy, Clone)] -#[cfg_attr(test, derive(Arbitrary))] +#[cfg_attr(feature = "dev-context-only-utils", derive(Arbitrary))] pub struct Lockout { slot: Slot, confirmation_count: u32, @@ -132,7 +131,7 @@ impl Lockout { #[cfg_attr(feature = "frozen-abi", derive(AbiExample))] #[cfg_attr(feature = "serde", derive(Deserialize, Serialize))] #[derive(Default, Debug, PartialEq, Eq, Copy, Clone)] -#[cfg_attr(test, derive(Arbitrary))] +#[cfg_attr(feature = "dev-context-only-utils", derive(Arbitrary))] pub struct LandedVote { // Latency is the difference in slot number between the slot that was voted on (lockout.slot) and the slot in // which the vote that added this Lockout landed. For votes which were cast before versions of the validator @@ -354,7 +353,7 @@ pub struct VoteAuthorizeCheckedWithSeedArgs { #[cfg_attr(feature = "frozen-abi", derive(AbiExample))] #[cfg_attr(feature = "serde", derive(Deserialize, Serialize))] #[derive(Debug, Default, PartialEq, Eq, Clone)] -#[cfg_attr(test, derive(Arbitrary))] +#[cfg_attr(feature = "dev-context-only-utils", derive(Arbitrary))] pub struct BlockTimestamp { pub slot: Slot, pub timestamp: UnixTimestamp, @@ -366,7 +365,7 @@ const MAX_ITEMS: usize = 32; #[cfg_attr(feature = "serde", derive(Deserialize, Serialize))] #[cfg_attr(feature = "frozen-abi", derive(AbiExample))] #[derive(Debug, PartialEq, Eq, Clone)] -#[cfg_attr(test, derive(Arbitrary))] +#[cfg_attr(feature = "dev-context-only-utils", derive(Arbitrary))] pub struct CircBuf { buf: [I; MAX_ITEMS], /// next pointer @@ -419,7 +418,7 @@ impl CircBuf { )] #[cfg_attr(feature = "serde", derive(Deserialize, Serialize))] #[derive(Debug, Default, PartialEq, Eq, Clone)] -#[cfg_attr(test, derive(Arbitrary))] +#[cfg_attr(feature = "dev-context-only-utils", derive(Arbitrary))] pub struct VoteState { /// the node that votes in this account pub node_pubkey: Pubkey, diff --git a/vote-interface/src/state/vote_state_1_14_11.rs b/vote-interface/src/state/vote_state_1_14_11.rs index 6a010d475..4f8784e13 100644 --- a/vote-interface/src/state/vote_state_1_14_11.rs +++ b/vote-interface/src/state/vote_state_1_14_11.rs @@ -1,5 +1,5 @@ use super::*; -#[cfg(test)] +#[cfg(feature = "dev-context-only-utils")] use arbitrary::Arbitrary; // Offset used for VoteState version 1_14_11 @@ -12,7 +12,7 @@ const DEFAULT_PRIOR_VOTERS_OFFSET: usize = 82; )] #[cfg_attr(feature = "serde", derive(Deserialize, Serialize))] #[derive(Debug, Default, PartialEq, Eq, Clone)] -#[cfg_attr(test, derive(Arbitrary))] +#[cfg_attr(feature = "dev-context-only-utils", derive(Arbitrary))] pub struct VoteState1_14_11 { /// the node that votes in this account pub node_pubkey: Pubkey,