more tests
This commit is contained in:
parent
3597c2e8cc
commit
320970aac3
|
@ -6,7 +6,7 @@ use super::Benchmark;
|
|||
|
||||
pub fn fetch(benchmark: &mut Benchmark) {
|
||||
// params
|
||||
const BLOCKS: usize = 10000;
|
||||
const BLOCKS: usize = 1000;
|
||||
|
||||
// test setup
|
||||
let path = RandomTempPath::create_dir();
|
||||
|
@ -98,7 +98,7 @@ pub fn reorg_short(benchmark: &mut Benchmark) {
|
|||
let next_block = test_data::block_builder()
|
||||
.transaction().coinbase().build()
|
||||
.transaction().output().value(5000000000).build().build()
|
||||
.merkled_header().parent(rolling_hash.clone()).nonce(x*4).build()
|
||||
.merkled_header().parent(rolling_hash.clone()).nonce(x as u32 * 4).build()
|
||||
.build();
|
||||
rolling_hash = next_block.hash();
|
||||
blocks.push(next_block);
|
||||
|
@ -106,7 +106,7 @@ pub fn reorg_short(benchmark: &mut Benchmark) {
|
|||
let next_block_side = test_data::block_builder()
|
||||
.transaction().coinbase().build()
|
||||
.transaction().output().value(5000000000).build().build()
|
||||
.merkled_header().parent(base).nonce(x * 4 + 2).build()
|
||||
.merkled_header().parent(base).nonce(x as u32 * 4 + 2).build()
|
||||
.build();
|
||||
let next_base = next_block_side.hash();
|
||||
blocks.push(next_block_side);
|
||||
|
@ -114,14 +114,14 @@ pub fn reorg_short(benchmark: &mut Benchmark) {
|
|||
let next_block_side_continue = test_data::block_builder()
|
||||
.transaction().coinbase().build()
|
||||
.transaction().output().value(5000000000).build().build()
|
||||
.merkled_header().parent(next_base).nonce(x * 4 + 3).build()
|
||||
.merkled_header().parent(next_base).nonce(x as u32 * 4 + 3).build()
|
||||
.build();
|
||||
blocks.push(next_block_side_continue);
|
||||
|
||||
let next_block_continue = test_data::block_builder()
|
||||
.transaction().coinbase().build()
|
||||
.transaction().output().value(5000000000).build().build()
|
||||
.merkled_header().parent(rolling_hash.clone()).nonce(x * 4+1).build()
|
||||
.merkled_header().parent(rolling_hash.clone()).nonce(x as u32 * 4 + 1).build()
|
||||
.build();
|
||||
rolling_hash = next_block_continue.hash();
|
||||
blocks.push(next_block_continue);
|
||||
|
@ -140,6 +140,69 @@ pub fn reorg_short(benchmark: &mut Benchmark) {
|
|||
}
|
||||
benchmark.stop();
|
||||
|
||||
// reorgs occur twice per iteration except last one where there only one, blocks are inserted with rate 4/iteration
|
||||
// so reorgs = total/2 - 1
|
||||
assert_eq!(1000, total);
|
||||
assert_eq!(499, reorgs);
|
||||
}
|
||||
|
||||
// 1. write 12000 blocks
|
||||
// 2. write 100 blocks that has 100 transaction each spending outputs from first 1000 blocks
|
||||
pub fn write_heavy(benchmark: &mut Benchmark) {
|
||||
// params
|
||||
const BLOCKS_INITIAL: usize = 12000;
|
||||
const BLOCKS: usize = 100;
|
||||
const TRANSACTIONS: usize = 100;
|
||||
|
||||
// test setup
|
||||
let path = RandomTempPath::create_dir();
|
||||
let store = Storage::new(path.as_path()).unwrap();
|
||||
|
||||
let genesis = test_data::genesis();
|
||||
store.insert_block(&genesis).unwrap();
|
||||
|
||||
let genesis = test_data::genesis();
|
||||
store.insert_block(&genesis).unwrap();
|
||||
|
||||
let mut rolling_hash = genesis.hash();
|
||||
let mut blocks = Vec::new();
|
||||
let mut hashes = Vec::new();
|
||||
|
||||
for x in 0..BLOCKS_INITIAL {
|
||||
let next_block = test_data::block_builder()
|
||||
.transaction()
|
||||
.coinbase()
|
||||
.output().value(5000000000).build()
|
||||
.build()
|
||||
.merkled_header().parent(rolling_hash.clone()).nonce(x as u32).build()
|
||||
.build();
|
||||
rolling_hash = next_block.hash();
|
||||
blocks.push(next_block);
|
||||
hashes.push(rolling_hash.clone());
|
||||
}
|
||||
|
||||
for b in 0..BLOCKS {
|
||||
let mut builder = test_data::block_builder()
|
||||
.transaction().coinbase().build();
|
||||
|
||||
for t in 0..TRANSACTIONS {
|
||||
builder = builder.transaction()
|
||||
.input().hash(blocks[b*TRANSACTIONS+t].transactions()[0].hash()).build() // default index is 0 which is ok
|
||||
.output().value(1000).build()
|
||||
.build();
|
||||
}
|
||||
|
||||
let next_block = builder.merkled_header().parent(rolling_hash).build().build();
|
||||
|
||||
rolling_hash = next_block.hash();
|
||||
blocks.push(next_block);
|
||||
hashes.push(rolling_hash.clone());
|
||||
}
|
||||
|
||||
for block in blocks[..BLOCKS_INITIAL].iter() { store.insert_block(block).unwrap(); }
|
||||
|
||||
// bench
|
||||
benchmark.start();
|
||||
for block in blocks[BLOCKS_INITIAL+1..].iter() { store.insert_block(block).unwrap(); }
|
||||
benchmark.stop();
|
||||
}
|
||||
|
|
|
@ -57,4 +57,5 @@ fn main() {
|
|||
benchmark!(database::fetch);
|
||||
benchmark!(database::write);
|
||||
benchmark!(database::reorg_short);
|
||||
benchmark!(database::write_heavy);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue