tests for block serialization
This commit is contained in:
parent
a0451a3cb5
commit
41e64bff4e
@ -21,7 +21,7 @@ use v1::types::{Bytes, Transaction};
|
|||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum BlockTransactions {
|
pub enum BlockTransactions {
|
||||||
Hashes(Vec<U256>),
|
Hashes(Vec<H256>),
|
||||||
Full(Vec<Transaction>)
|
Full(Vec<Transaction>)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,3 +67,50 @@ pub struct Block {
|
|||||||
pub uncles: Vec<U256>,
|
pub uncles: Vec<U256>,
|
||||||
pub transactions: BlockTransactions
|
pub transactions: BlockTransactions
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use serde_json;
|
||||||
|
use util::hash::*;
|
||||||
|
use util::uint::*;
|
||||||
|
use v1::types::{Transaction, Bytes};
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_serialize_block_transactions() {
|
||||||
|
let t = BlockTransactions::Full(vec![Transaction::default()]);
|
||||||
|
let serialized = serde_json::to_string(&t).unwrap();
|
||||||
|
assert_eq!(serialized, r#"[{"hash":"0x0000000000000000000000000000000000000000000000000000000000000000","nonce":"0x00","blockHash":"0x0000000000000000000000000000000000000000000000000000000000000000","blockNumber":"0x00","transactionIndex":"0x00","from":"0x0000000000000000000000000000000000000000","to":"0x0000000000000000000000000000000000000000","value":"0x00","gasPrice":"0x00","gas":"0x00","input":"0x00"}]"#);
|
||||||
|
|
||||||
|
let t = BlockTransactions::Hashes(vec![H256::default()]);
|
||||||
|
let serialized = serde_json::to_string(&t).unwrap();
|
||||||
|
assert_eq!(serialized, r#"["0x0000000000000000000000000000000000000000000000000000000000000000"]"#);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_serialize_block() {
|
||||||
|
let block = Block {
|
||||||
|
hash: H256::default(),
|
||||||
|
parent_hash: H256::default(),
|
||||||
|
uncles_hash: H256::default(),
|
||||||
|
author: Address::default(),
|
||||||
|
miner: Address::default(),
|
||||||
|
state_root: H256::default(),
|
||||||
|
transactions_root: H256::default(),
|
||||||
|
receipts_root: H256::default(),
|
||||||
|
number: U256::default(),
|
||||||
|
gas_used: U256::default(),
|
||||||
|
gas_limit: U256::default(),
|
||||||
|
extra_data: Bytes::default(),
|
||||||
|
logs_bloom: H2048::default(),
|
||||||
|
timestamp: U256::default(),
|
||||||
|
difficulty: U256::default(),
|
||||||
|
total_difficulty: U256::default(),
|
||||||
|
uncles: vec![],
|
||||||
|
transactions: BlockTransactions::Hashes(vec![])
|
||||||
|
};
|
||||||
|
|
||||||
|
let serialized = serde_json::to_string(&block).unwrap();
|
||||||
|
assert_eq!(serialized, r#"{"hash":"0x0000000000000000000000000000000000000000000000000000000000000000","parentHash":"0x0000000000000000000000000000000000000000000000000000000000000000","sha3Uncles":"0x0000000000000000000000000000000000000000000000000000000000000000","author":"0x0000000000000000000000000000000000000000","miner":"0x0000000000000000000000000000000000000000","stateRoot":"0x0000000000000000000000000000000000000000000000000000000000000000","transactionsRoot":"0x0000000000000000000000000000000000000000000000000000000000000000","receiptsRoot":"0x0000000000000000000000000000000000000000000000000000000000000000","number":"0x00","gasUsed":"0x00","gasLimit":"0x00","extraData":"0x00","logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","timestamp":"0x00","difficulty":"0x00","totalDifficulty":"0x00","uncles":[],"transactions":[]}"#);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user