Skip to content

Commit

Permalink
Merge latest changes from master and fix conflicts
Browse files Browse the repository at this point in the history
Signed-off-by: Thane Thomson <connect@thanethomson.com>
  • Loading branch information
thanethomson committed Nov 26, 2021
2 parents b583aa0 + 9cd12b0 commit 07a8efe
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- `[tendermint]` Deprecated `signature::ED25519_SIGNATURE_SIZE`
in favor of `Ed25519Signature::BYTE_SIZE`
([#1023](https://github.com/informalsystems/tendermint-rs/issues/1023))
2 changes: 1 addition & 1 deletion tendermint/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ crate-type = ["cdylib", "rlib"]
async-trait = { version = "0.1", default-features = false }
bytes = { version = "1.0", default-features = false, features = ["serde"] }
chrono = { version = "0.4.19", default-features = false, features = ["serde"] }
ed25519 = { version = "1", default-features = false }
ed25519 = { version = "1.3", default-features = false }
ed25519-dalek = { version = "1", default-features = false, features = ["u64_backend"] }
futures = { version = "0.3", default-features = false }
num-traits = { version = "0.2", default-features = false }
Expand Down
16 changes: 5 additions & 11 deletions tendermint/src/proposal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ mod tests {
use crate::hash::{Algorithm, Hash};
use crate::prelude::*;
use crate::proposal::SignProposalRequest;
use crate::signature::Ed25519Signature;
use crate::{proposal::Type, Proposal, Signature};
use crate::test::dummy_signature;
use crate::{proposal::Type, Proposal};
use chrono::{DateTime, Utc};
use core::str::FromStr;
use tendermint_proto::Protobuf;
Expand Down Expand Up @@ -152,9 +152,7 @@ mod tests {
.unwrap(),
}),
timestamp: Some(dt.into()),
signature: Some(Signature::from(
Ed25519Signature::from_bytes(&[0; Ed25519Signature::BYTE_SIZE]).unwrap(),
)),
signature: Some(dummy_signature()),
};

let mut got = vec![];
Expand Down Expand Up @@ -236,9 +234,7 @@ mod tests {
.unwrap(),
}),
timestamp: Some(dt.into()),
signature: Some(Signature::from(
Ed25519Signature::from_bytes(&[0; Ed25519Signature::BYTE_SIZE]).unwrap(),
)),
signature: Some(dummy_signature()),
};

let mut got = vec![];
Expand Down Expand Up @@ -322,9 +318,7 @@ mod tests {
)
.unwrap(),
}),
signature: Some(Signature::from(
Ed25519Signature::from_bytes(&[0; Ed25519Signature::BYTE_SIZE]).unwrap(),
)),
signature: Some(dummy_signature()),
};
let want = SignProposalRequest {
proposal,
Expand Down
3 changes: 3 additions & 0 deletions tendermint/src/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ use tendermint_proto::Protobuf;

use crate::error::Error;

#[deprecated(since = "0.23.2", note = "use Ed25519Signature::BYTE_SIZE instead")]
pub const ED25519_SIGNATURE_SIZE: usize = Ed25519Signature::BYTE_SIZE;

/// The expected length of all currently supported signatures, in bytes.
pub const SIGNATURE_LENGTH: usize = 64;

Expand Down
7 changes: 7 additions & 0 deletions tendermint/src/test.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use core::fmt::Debug;
use serde::{de::DeserializeOwned, Serialize};

use crate::signature::{Ed25519Signature, Signature};

/// Test that a struct `T` can be:
///
/// - parsed out of the provided JSON data
Expand All @@ -25,3 +27,8 @@ where

assert_eq!(parsed0, parsed1);
}

/// Produces a dummy signature value for use as a placeholder in tests.
pub fn dummy_signature() -> Signature {
Signature::from(Ed25519Signature::from_bytes(&[0; Ed25519Signature::BYTE_SIZE]).unwrap())
}
6 changes: 4 additions & 2 deletions tendermint/src/vote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use core::fmt;
use core::str::FromStr;

use bytes::BufMut;
use ed25519::Signature as Ed25519Signature;
use serde::{Deserialize, Serialize};

use tendermint_proto::types::Vote as RawVote;
Expand All @@ -26,6 +25,7 @@ use crate::consensus::State;
use crate::error::Error;
use crate::hash;
use crate::prelude::*;
use crate::signature::Ed25519Signature;
use crate::{account, block, Signature, Time};

/// Votes are signed messages from validators for a particular block which
Expand Down Expand Up @@ -158,6 +158,7 @@ impl Vote {
}

/// Default trait. Used in tests.
// FIXME: Does it need to be in public crate API? If not, replace with a helper fn in crate::test?
impl Default for Vote {
fn default() -> Self {
Vote {
Expand All @@ -168,7 +169,8 @@ impl Default for Vote {
timestamp: Some(Time::unix_epoch()),
validator_address: account::Id::new([0; account::LENGTH]),
validator_index: ValidatorIndex::try_from(0_i32).unwrap(),
// Unwrap is safe since this is only used in tests.
// Could have reused crate::test::dummy_signature, except that
// this Default impl is defined outside of #[cfg(test)].
signature: Some(Signature::from(
Ed25519Signature::from_bytes(&[0; Ed25519Signature::BYTE_SIZE]).unwrap(),
)),
Expand Down

0 comments on commit 07a8efe

Please sign in to comment.