Dump chain to JSON file
This commit is contained in:
parent
90ae2298ab
commit
eb77fb75b7
@ -13,7 +13,9 @@ failure = "0.1"
|
||||
failure_derive = "0.1"
|
||||
genesis = { path = "../../eth2/genesis" }
|
||||
hashing = { path = "../../eth2/utils/hashing" }
|
||||
serde = "1.0"
|
||||
serde_derive = "1.0"
|
||||
serde_json = "1.0"
|
||||
slot_clock = { path = "../../eth2/utils/slot_clock" }
|
||||
ssz = { path = "../../eth2/utils/ssz" }
|
||||
types = { path = "../../eth2/types" }
|
||||
|
@ -1,7 +1,8 @@
|
||||
use super::{BeaconChain, ClientDB, DBError, SlotClock};
|
||||
use serde_derive::Serialize;
|
||||
use types::{BeaconBlock, BeaconState, Hash256};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct SlotDump {
|
||||
pub beacon_block: BeaconBlock,
|
||||
pub beacon_block_root: Hash256,
|
||||
|
@ -15,4 +15,6 @@ fn it_can_produce_blocks() {
|
||||
let dump = rig.chain_dump().expect("Chain dump failed.");
|
||||
|
||||
assert_eq!(dump.len(), blocks + 1); // + 1 for genesis block.
|
||||
|
||||
rig.dump_to_file("/tmp/chaindump.json".to_string(), &dump);
|
||||
}
|
||||
|
@ -6,7 +6,10 @@ use db::{
|
||||
stores::{BeaconBlockStore, BeaconStateStore},
|
||||
MemoryDB,
|
||||
};
|
||||
use serde_json::Result as SerdeResult;
|
||||
use slot_clock::TestingSlotClock;
|
||||
use std::fs::File;
|
||||
use std::io::prelude::*;
|
||||
use std::sync::Arc;
|
||||
use types::{ChainSpec, Keypair, Validator};
|
||||
|
||||
@ -87,4 +90,10 @@ impl TestRig {
|
||||
pub fn chain_dump(&self) -> Result<Vec<SlotDump>, DumpError> {
|
||||
self.beacon_chain.chain_dump()
|
||||
}
|
||||
|
||||
pub fn dump_to_file(&self, filename: String, chain_dump: &Vec<SlotDump>) {
|
||||
let json = serde_json::to_string(chain_dump).unwrap();
|
||||
let mut file = File::create(filename).unwrap();
|
||||
file.write_all(json.as_bytes());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user