mirror of
https://github.com/mimblewimble/grin.git
synced 2025-01-21 11:31:08 +03:00
7b12746a1f
* initial pass at indexing block header hashes by commitments * check block height matches currently indexed block height when getting block header for an output commit * add some test coverage * document get_block_header_by_output_commit
56 lines
1.7 KiB
Rust
56 lines
1.7 KiB
Rust
// Copyright 2017 The Grin Developers
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
extern crate env_logger;
|
|
extern crate grin_chain as chain;
|
|
extern crate grin_core as core;
|
|
extern crate rand;
|
|
extern crate secp256k1zkp as secp;
|
|
|
|
use std::fs;
|
|
|
|
use chain::ChainStore;
|
|
use core::core::hash::Hashed;
|
|
use core::core::{Block, BlockHeader};
|
|
use secp::key;
|
|
|
|
fn clean_output_dir(dir_name: &str) {
|
|
let _ = fs::remove_dir_all(dir_name);
|
|
}
|
|
|
|
#[test]
|
|
fn test_various_store_indices() {
|
|
let _ = env_logger::init();
|
|
clean_output_dir(".grin");
|
|
|
|
let chain_store = &chain::store::ChainKVStore::new(".grin".to_string()).unwrap() as &ChainStore;
|
|
|
|
let block = Block::new(&BlockHeader::default(), vec![], key::ONE_KEY).unwrap();
|
|
let commit = block.outputs[0].commitment();
|
|
let block_hash = block.hash();
|
|
|
|
chain_store.save_block(&block).unwrap();
|
|
chain_store.setup_height(&block.header).unwrap();
|
|
|
|
let block_header = chain_store.get_block_header(&block_hash).unwrap();
|
|
assert_eq!(block_header.hash(), block_hash);
|
|
|
|
let block_header = chain_store.get_header_by_height(1).unwrap();
|
|
assert_eq!(block_header.hash(), block_hash);
|
|
|
|
let block_header = chain_store
|
|
.get_block_header_by_output_commit(&commit)
|
|
.unwrap();
|
|
assert_eq!(block_header.hash(), block_hash);
|
|
}
|