Skip to content

Commit

Permalink
Start stubbing out Signatures and other types required by RET, which …
Browse files Browse the repository at this point in the history
…requires more fixed size BagOfBytes, introducing: Hex64Bytes, Hex65Bytes, Hex33Bytes, generated with macro.
  • Loading branch information
Sajjon committed Feb 19, 2024
1 parent 7592b04 commit 9437497
Show file tree
Hide file tree
Showing 22 changed files with 1,165 additions and 127 deletions.
4 changes: 2 additions & 2 deletions src/core/error/common_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ pub enum CommonError {
#[error("String not hex {bad_value}")]
StringNotHex { bad_value: String } = 10011,

#[error("Invalid byte count, expected 32, found: {bad_value}")]
InvalidByteCountExpected32 { bad_value: u64 } = 10012,
#[error("Invalid byte count, expected {expected}, found: {found}")]
InvalidByteCount { expected: u64, found: u64 } = 10012,

#[error("Invalid BIP32 path '{bad_value}'.")]
InvalidBIP32Path { bad_value: String } = 10013,
Expand Down
7 changes: 7 additions & 0 deletions src/core/secure_random_bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ pub fn generate_32_bytes() -> Vec<u8> {
generate_bytes::<32>()
}

/// Generates `64` random bytes using a cryptographically
/// secure random generator and returns these bytes as
/// a Vec<u8>.
pub fn generate_64_bytes() -> Vec<u8> {
generate_bytes::<64>()
}

#[cfg(test)]
mod tests {
use std::collections::HashSet;
Expand Down
62 changes: 62 additions & 0 deletions src/core/types/epoch.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
pub use crate::prelude::*;

// use radix_engine_common::types::Epoch as ScryptoEpoch;

// Generate the FfiConverter needed by UniFFI for newtype `Epoch`.
uniffi::custom_newtype!(Epoch, u64);

Check warning on line 6 in src/core/types/epoch.rs

View check run for this annotation

Codecov / codecov/patch

src/core/types/epoch.rs#L6

Added line #L6 was not covered by tests

/// A type-safe consensus epoch number.
#[derive(
Clone,
Copy,
PartialEq,
Eq,
Hash,
Ord,
PartialOrd,
derive_more::Display,
derive_more::Debug,
)]
pub struct Epoch(pub u64);

impl From<u64> for Epoch {
fn from(value: u64) -> Self {
Self(value)
}
}

impl From<Epoch> for u64 {
fn from(value: Epoch) -> Self {
value.0
}
}

#[cfg(test)]
mod tests {
use crate::prelude::*;

#[test]
fn from_u64() {
let test =
|u: u64| assert_eq!(Into::<u64>::into(Into::<Epoch>::into(u)), u);
test(0);
test(1);
test(2);
test(1337);
}

#[test]
fn to_u64() {
let test = |u: u64| {
assert_eq!(
Into::<Epoch>::into(Into::<u64>::into(Into::<Epoch>::into(u)))
.0,
u
)
};
test(0);
test(1);
test(2);
test(1337);
}
}
Loading

0 comments on commit 9437497

Please sign in to comment.