From 2a874af56d4650945b9c72358738be3c4833c4a0 Mon Sep 17 00:00:00 2001 From: benluelo Date: Sun, 28 Jan 2024 23:01:05 -0500 Subject: [PATCH] feat: add arbitrary to some types --- tendermint/Cargo.toml | 2 ++ tendermint/src/account.rs | 1 + tendermint/src/crypto/ed25519/verification_key.rs | 1 + tendermint/src/public_key.rs | 1 + tendermint/src/validator.rs | 2 ++ tendermint/src/vote/power.rs | 1 + 6 files changed, 8 insertions(+) diff --git a/tendermint/Cargo.toml b/tendermint/Cargo.toml index 489a56cb4..7192ca682 100644 --- a/tendermint/Cargo.toml +++ b/tendermint/Cargo.toml @@ -52,6 +52,7 @@ ed25519-consensus = { version = "2", optional = true, default-features = false } sha2 = { version = "0.10", optional = true, default-features = false } k256 = { version = "0.13", optional = true, default-features = false, features = ["alloc", "ecdsa"] } ripemd = { version = "0.1.3", optional = true, default-features = false } +arbitrary = { version = "1.3.2", features = ["derive"], optional = true } [features] default = ["std", "rust-crypto"] @@ -59,6 +60,7 @@ std = ["flex-error/std", "flex-error/eyre_tracer", "clock"] clock = ["time/std"] secp256k1 = ["k256", "ripemd"] rust-crypto = ["sha2", "ed25519-consensus"] +arbitrary = ["dep:arbitrary"] [dev-dependencies] k256 = { version = "0.13", default-features = false, features = ["ecdsa"] } diff --git a/tendermint/src/account.rs b/tendermint/src/account.rs index 76ce41324..0ec6fcc5c 100644 --- a/tendermint/src/account.rs +++ b/tendermint/src/account.rs @@ -20,6 +20,7 @@ pub const LENGTH: usize = 20; /// Account IDs #[derive(Copy, Clone, Eq, Hash, PartialEq, PartialOrd, Ord)] +#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] pub struct Id([u8; LENGTH]); // JSON custom serialization for priv_validator_key.json impl Protobuf> for Id {} diff --git a/tendermint/src/crypto/ed25519/verification_key.rs b/tendermint/src/crypto/ed25519/verification_key.rs index 305614f07..4d2b67417 100644 --- a/tendermint/src/crypto/ed25519/verification_key.rs +++ b/tendermint/src/crypto/ed25519/verification_key.rs @@ -1,6 +1,7 @@ use crate::Error; #[derive(Copy, Clone, Eq, PartialEq)] +#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] pub struct VerificationKey([u8; 32]); impl core::fmt::Display for VerificationKey { diff --git a/tendermint/src/public_key.rs b/tendermint/src/public_key.rs index c899088b7..b19864891 100644 --- a/tendermint/src/public_key.rs +++ b/tendermint/src/public_key.rs @@ -32,6 +32,7 @@ use crate::{error::Error, prelude::*}; #[derive(Copy, Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] #[non_exhaustive] #[serde(tag = "type", content = "value")] // JSON custom serialization for priv_validator_key.json +#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] pub enum PublicKey { /// Ed25519 keys #[serde( diff --git a/tendermint/src/validator.rs b/tendermint/src/validator.rs index 7db1a7cef..4147a0c8c 100644 --- a/tendermint/src/validator.rs +++ b/tendermint/src/validator.rs @@ -145,6 +145,7 @@ impl Set { /// Validator information // Todo: Remove address and make it into a function that generates it on the fly from pub_key. #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] +#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] pub struct Info { /// Validator account address pub address: account::Id, @@ -228,6 +229,7 @@ impl Info { // Todo: Is there more knowledge/restrictions about proposerPriority? /// Proposer priority #[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Default)] +#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] pub struct ProposerPriority(i64); impl From for ProposerPriority { diff --git a/tendermint/src/vote/power.rs b/tendermint/src/vote/power.rs index 61a21a4ac..fcc7e0bc4 100644 --- a/tendermint/src/vote/power.rs +++ b/tendermint/src/vote/power.rs @@ -11,6 +11,7 @@ use crate::{error::Error, prelude::*}; /// Voting power #[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Default)] +#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] pub struct Power(u64); impl fmt::Display for Power {