Skip to content

Commit

Permalink
feat: add arbitrary to some types
Browse files Browse the repository at this point in the history
  • Loading branch information
benluelo authored and KaiserKarel committed May 2, 2024
1 parent 3b4027f commit 871fb3b
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tendermint/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,15 @@ 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"]
std = ["flex-error/std", "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"] }
Expand Down
1 change: 1 addition & 0 deletions tendermint/src/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,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<Vec<u8>> for Id {}
Expand Down
1 change: 1 addition & 0 deletions tendermint/src/crypto/ed25519/verification_key.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
1 change: 1 addition & 0 deletions tendermint/src/public_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,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(
Expand Down
2 changes: 2 additions & 0 deletions tendermint/src/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<i64> for ProposerPriority {
Expand Down
1 change: 1 addition & 0 deletions tendermint/src/vote/power.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,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 {
Expand Down

0 comments on commit 871fb3b

Please sign in to comment.