mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-08 12:19:24 +00:00
Define all coordinator transaction types
This commit is contained in:
@@ -10,9 +10,17 @@ edition = "2021"
|
||||
[dependencies]
|
||||
thiserror = "1"
|
||||
|
||||
rand_core = { version = "0.6", optional = true }
|
||||
|
||||
blake2 = "0.10"
|
||||
|
||||
ciphersuite = { package = "ciphersuite", path = "../../crypto/ciphersuite", features = ["ristretto"] }
|
||||
schnorr = { package = "schnorr-signatures", path = "../../crypto/schnorr" }
|
||||
|
||||
tendermint = { package = "tendermint-machine", path = "./tendermint" }
|
||||
|
||||
[dev-dependencies]
|
||||
rand_core = "0.6"
|
||||
|
||||
[features]
|
||||
tests = ["rand_core"]
|
||||
|
||||
@@ -9,6 +9,9 @@ pub use transaction::*;
|
||||
mod block;
|
||||
pub use block::*;
|
||||
|
||||
#[cfg(any(test, feature = "tests"))]
|
||||
pub mod tests;
|
||||
|
||||
/// An item which can be read and written.
|
||||
pub trait ReadWrite: Sized {
|
||||
fn read<R: io::Read>(reader: &mut R) -> io::Result<Self>;
|
||||
|
||||
2
coordinator/tributary/src/tests/mod.rs
Normal file
2
coordinator/tributary/src/tests/mod.rs
Normal file
@@ -0,0 +1,2 @@
|
||||
mod transaction;
|
||||
pub use transaction::*;
|
||||
27
coordinator/tributary/src/tests/transaction.rs
Normal file
27
coordinator/tributary/src/tests/transaction.rs
Normal file
@@ -0,0 +1,27 @@
|
||||
use rand_core::RngCore;
|
||||
|
||||
use ciphersuite::{
|
||||
group::{ff::Field, Group},
|
||||
Ciphersuite, Ristretto,
|
||||
};
|
||||
use schnorr::SchnorrSignature;
|
||||
|
||||
use crate::Signed;
|
||||
|
||||
pub fn random_signed<R: RngCore>(rng: &mut R) -> Signed {
|
||||
Signed {
|
||||
signer: <Ristretto as Ciphersuite>::G::random(&mut *rng),
|
||||
nonce: u32::try_from(rng.next_u64() >> 32).unwrap(),
|
||||
signature: SchnorrSignature::<Ristretto> {
|
||||
R: <Ristretto as Ciphersuite>::G::random(&mut *rng),
|
||||
s: <Ristretto as Ciphersuite>::F::random(rng),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn serialize_signed() {
|
||||
use crate::ReadWrite;
|
||||
let signed = signed(&mut rand_core::OsRng);
|
||||
assert_eq!(Signed::read::<&[u8]>(&mut signed.serialize().as_ref()).unwrap(), signed);
|
||||
}
|
||||
Reference in New Issue
Block a user