add assets for seal.rs
This commit is contained in:
parent
5c7c30cc4b
commit
f96731c82b
@ -70,32 +70,62 @@ pub enum Seal {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use serde_json;
|
||||
use spec::Seal;
|
||||
use hash::*;
|
||||
use bytes::Bytes;
|
||||
use uint::Uint;
|
||||
use util::U256;
|
||||
use util::{H64 as Eth64, H256 as Eth256, H520 as Eth520};
|
||||
use spec::{Ethereum, AuthorityRoundSeal, TendermintSeal, Seal};
|
||||
|
||||
#[test]
|
||||
fn seal_deserialization() {
|
||||
let s = r#"[{
|
||||
"ethereum": {
|
||||
"nonce": "0x0000000000000042",
|
||||
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000"
|
||||
"mixHash": "0x1000000000000000000000000000000000000000000000000000000000000001"
|
||||
}
|
||||
},{
|
||||
"generic": "0xe011bbe8db4e347b4e8c937c1c8370e4b5ed33adb3db69cbdb7a38e1e50b1b82fa"
|
||||
},{
|
||||
"authorityRound": {
|
||||
"step": "0x0",
|
||||
"signature": "0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
|
||||
"signature": "0x2000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002"
|
||||
}
|
||||
},{
|
||||
"tendermint": {
|
||||
"round": "0x0",
|
||||
"proposal": "0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
|
||||
"round": "0x3",
|
||||
"proposal": "0x3000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003",
|
||||
"precommits": [
|
||||
"0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
|
||||
"0x4000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004"
|
||||
]
|
||||
}
|
||||
}]"#;
|
||||
let _deserialized: Vec<Seal> = serde_json::from_str(s).unwrap();
|
||||
// TODO: validate all fields
|
||||
|
||||
let deserialized: Vec<Seal> = serde_json::from_str(s).unwrap();
|
||||
assert_eq!(deserialized.len(), 4);
|
||||
|
||||
// [0]
|
||||
assert_eq!(deserialized[0], Seal::Ethereum(Ethereum {
|
||||
nonce: H64(Eth64::from("0x0000000000000042")),
|
||||
mix_hash: H256(Eth256::from("0x1000000000000000000000000000000000000000000000000000000000000001"))
|
||||
}));
|
||||
|
||||
// [1]
|
||||
assert_eq!(deserialized[1], Seal::Generic(Bytes::new(vec![
|
||||
0xe0, 0x11, 0xbb, 0xe8, 0xdb, 0x4e, 0x34, 0x7b, 0x4e, 0x8c, 0x93, 0x7c, 0x1c, 0x83, 0x70, 0xe4,
|
||||
0xb5, 0xed, 0x33, 0xad, 0xb3, 0xdb, 0x69, 0xcb, 0xdb, 0x7a, 0x38, 0xe1, 0xe5, 0x0b, 0x1b, 0x82, 0xfa])));
|
||||
|
||||
// [2]
|
||||
assert_eq!(deserialized[2], Seal::AuthorityRound(AuthorityRoundSeal {
|
||||
step: Uint(U256::from(0x0)),
|
||||
signature: H520(Eth520::from("0x2000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002"))
|
||||
}));
|
||||
|
||||
// [3]
|
||||
assert_eq!(deserialized[3], Seal::Tendermint(TendermintSeal {
|
||||
round: Uint(U256::from(0x3)),
|
||||
proposal: H520(Eth520::from("0x3000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003")),
|
||||
precommits: vec![H520(Eth520::from("0x4000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004"))]
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user