mirror of
https://github.com/mimblewimble/grin.git
synced 2025-01-20 19:11:08 +03:00
fix calls to next_diff() in tests to use next height correctly (#3501)
This commit is contained in:
parent
f86102b2a6
commit
6e73e00d6b
3 changed files with 30 additions and 20 deletions
|
@ -86,13 +86,14 @@ where
|
||||||
{
|
{
|
||||||
for n in 1..chain_length {
|
for n in 1..chain_length {
|
||||||
let prev = chain.head_header().unwrap();
|
let prev = chain.head_header().unwrap();
|
||||||
let next_header_info = consensus::next_difficulty(1, chain.difficulty_iter().unwrap());
|
let next_header_info =
|
||||||
|
consensus::next_difficulty(prev.height + 1, chain.difficulty_iter().unwrap());
|
||||||
let pk = ExtKeychainPath::new(1, n as u32, 0, 0, 0).to_identifier();
|
let pk = ExtKeychainPath::new(1, n as u32, 0, 0, 0).to_identifier();
|
||||||
let reward =
|
let reward =
|
||||||
libtx::reward::output(keychain, &libtx::ProofBuilder::new(keychain), &pk, 0, false)
|
libtx::reward::output(keychain, &libtx::ProofBuilder::new(keychain), &pk, 0, false)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let mut b = core::core::Block::new(&prev, &[], next_header_info.clone().difficulty, reward)
|
let mut b =
|
||||||
.unwrap();
|
core::core::Block::new(&prev, &[], next_header_info.difficulty, reward).unwrap();
|
||||||
b.header.timestamp = prev.timestamp + Duration::seconds(60);
|
b.header.timestamp = prev.timestamp + Duration::seconds(60);
|
||||||
b.header.pow.secondary_scaling = next_header_info.secondary_scaling;
|
b.header.pow.secondary_scaling = next_header_info.secondary_scaling;
|
||||||
|
|
||||||
|
|
|
@ -747,7 +747,9 @@ fn spend_in_fork_and_compact() {
|
||||||
/// Test ability to retrieve block headers for a given output
|
/// Test ability to retrieve block headers for a given output
|
||||||
#[test]
|
#[test]
|
||||||
fn output_header_mappings() {
|
fn output_header_mappings() {
|
||||||
|
clean_output_dir(".grin_header_for_output");
|
||||||
global::set_local_chain_type(ChainTypes::AutomatedTesting);
|
global::set_local_chain_type(ChainTypes::AutomatedTesting);
|
||||||
|
util::init_test_logger();
|
||||||
{
|
{
|
||||||
let chain = init_chain(
|
let chain = init_chain(
|
||||||
".grin_header_for_output",
|
".grin_header_for_output",
|
||||||
|
@ -758,7 +760,8 @@ fn output_header_mappings() {
|
||||||
|
|
||||||
for n in 1..15 {
|
for n in 1..15 {
|
||||||
let prev = chain.head_header().unwrap();
|
let prev = chain.head_header().unwrap();
|
||||||
let next_header_info = consensus::next_difficulty(1, chain.difficulty_iter().unwrap());
|
let next_header_info =
|
||||||
|
consensus::next_difficulty(prev.height + 1, chain.difficulty_iter().unwrap());
|
||||||
let pk = ExtKeychainPath::new(1, n as u32, 0, 0, 0).to_identifier();
|
let pk = ExtKeychainPath::new(1, n as u32, 0, 0, 0).to_identifier();
|
||||||
let reward = libtx::reward::output(
|
let reward = libtx::reward::output(
|
||||||
&keychain,
|
&keychain,
|
||||||
|
|
|
@ -18,12 +18,10 @@ use self::core::core::verifier_cache::LruVerifierCache;
|
||||||
use self::core::core::KernelFeatures;
|
use self::core::core::KernelFeatures;
|
||||||
use self::core::global::{self, ChainTypes};
|
use self::core::global::{self, ChainTypes};
|
||||||
use self::core::libtx::{self, build, ProofBuilder};
|
use self::core::libtx::{self, build, ProofBuilder};
|
||||||
use self::core::pow::Difficulty;
|
|
||||||
use self::core::{consensus, pow};
|
use self::core::{consensus, pow};
|
||||||
use self::keychain::{ExtKeychain, ExtKeychainPath, Keychain};
|
use self::keychain::{ExtKeychain, ExtKeychainPath, Keychain};
|
||||||
use self::util::RwLock;
|
use self::util::RwLock;
|
||||||
use chrono::Duration;
|
use chrono::Duration;
|
||||||
use env_logger;
|
|
||||||
use grin_chain as chain;
|
use grin_chain as chain;
|
||||||
use grin_core as core;
|
use grin_core as core;
|
||||||
use grin_keychain as keychain;
|
use grin_keychain as keychain;
|
||||||
|
@ -37,7 +35,7 @@ fn clean_output_dir(dir_name: &str) {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_coinbase_maturity() {
|
fn test_coinbase_maturity() {
|
||||||
let _ = env_logger::init();
|
util::init_test_logger();
|
||||||
let chain_dir = ".grin_coinbase";
|
let chain_dir = ".grin_coinbase";
|
||||||
clean_output_dir(chain_dir);
|
clean_output_dir(chain_dir);
|
||||||
global::set_local_chain_type(ChainTypes::AutomatedTesting);
|
global::set_local_chain_type(ChainTypes::AutomatedTesting);
|
||||||
|
@ -66,9 +64,11 @@ fn test_coinbase_maturity() {
|
||||||
let key_id3 = ExtKeychainPath::new(1, 3, 0, 0, 0).to_identifier();
|
let key_id3 = ExtKeychainPath::new(1, 3, 0, 0, 0).to_identifier();
|
||||||
let key_id4 = ExtKeychainPath::new(1, 4, 0, 0, 0).to_identifier();
|
let key_id4 = ExtKeychainPath::new(1, 4, 0, 0, 0).to_identifier();
|
||||||
|
|
||||||
let next_header_info = consensus::next_difficulty(1, chain.difficulty_iter().unwrap());
|
let next_header_info =
|
||||||
|
consensus::next_difficulty(prev.height + 1, chain.difficulty_iter().unwrap());
|
||||||
let reward = libtx::reward::output(&keychain, &builder, &key_id1, 0, false).unwrap();
|
let reward = libtx::reward::output(&keychain, &builder, &key_id1, 0, false).unwrap();
|
||||||
let mut block = core::core::Block::new(&prev, &[], Difficulty::min_dma(), reward).unwrap();
|
let mut block =
|
||||||
|
core::core::Block::new(&prev, &[], next_header_info.difficulty, reward).unwrap();
|
||||||
block.header.timestamp = prev.timestamp + Duration::seconds(60);
|
block.header.timestamp = prev.timestamp + Duration::seconds(60);
|
||||||
block.header.pow.secondary_scaling = next_header_info.secondary_scaling;
|
block.header.pow.secondary_scaling = next_header_info.secondary_scaling;
|
||||||
|
|
||||||
|
@ -113,8 +113,10 @@ fn test_coinbase_maturity() {
|
||||||
let txs = &[coinbase_txn.clone()];
|
let txs = &[coinbase_txn.clone()];
|
||||||
let fees = txs.iter().map(|tx| tx.fee()).sum();
|
let fees = txs.iter().map(|tx| tx.fee()).sum();
|
||||||
let reward = libtx::reward::output(&keychain, &builder, &key_id3, fees, false).unwrap();
|
let reward = libtx::reward::output(&keychain, &builder, &key_id3, fees, false).unwrap();
|
||||||
let mut block = core::core::Block::new(&prev, txs, Difficulty::min_dma(), reward).unwrap();
|
let next_header_info =
|
||||||
let next_header_info = consensus::next_difficulty(1, chain.difficulty_iter().unwrap());
|
consensus::next_difficulty(prev.height + 1, chain.difficulty_iter().unwrap());
|
||||||
|
let mut block =
|
||||||
|
core::core::Block::new(&prev, txs, next_header_info.difficulty, reward).unwrap();
|
||||||
block.header.timestamp = prev.timestamp + Duration::seconds(60);
|
block.header.timestamp = prev.timestamp + Duration::seconds(60);
|
||||||
block.header.pow.secondary_scaling = next_header_info.secondary_scaling;
|
block.header.pow.secondary_scaling = next_header_info.secondary_scaling;
|
||||||
|
|
||||||
|
@ -147,10 +149,11 @@ fn test_coinbase_maturity() {
|
||||||
let builder = ProofBuilder::new(&keychain);
|
let builder = ProofBuilder::new(&keychain);
|
||||||
let key_id1 = ExtKeychainPath::new(1, 1, 0, 0, 0).to_identifier();
|
let key_id1 = ExtKeychainPath::new(1, 1, 0, 0, 0).to_identifier();
|
||||||
|
|
||||||
let next_header_info = consensus::next_difficulty(1, chain.difficulty_iter().unwrap());
|
let next_header_info =
|
||||||
|
consensus::next_difficulty(prev.height + 1, chain.difficulty_iter().unwrap());
|
||||||
let reward = libtx::reward::output(&keychain, &builder, &key_id1, 0, false).unwrap();
|
let reward = libtx::reward::output(&keychain, &builder, &key_id1, 0, false).unwrap();
|
||||||
let mut block =
|
let mut block =
|
||||||
core::core::Block::new(&prev, &[], Difficulty::min_dma(), reward).unwrap();
|
core::core::Block::new(&prev, &[], next_header_info.difficulty, reward).unwrap();
|
||||||
|
|
||||||
block.header.timestamp = prev.timestamp + Duration::seconds(60);
|
block.header.timestamp = prev.timestamp + Duration::seconds(60);
|
||||||
block.header.pow.secondary_scaling = next_header_info.secondary_scaling;
|
block.header.pow.secondary_scaling = next_header_info.secondary_scaling;
|
||||||
|
@ -196,9 +199,10 @@ fn test_coinbase_maturity() {
|
||||||
let txs = &[coinbase_txn.clone()];
|
let txs = &[coinbase_txn.clone()];
|
||||||
let fees = txs.iter().map(|tx| tx.fee()).sum();
|
let fees = txs.iter().map(|tx| tx.fee()).sum();
|
||||||
let reward = libtx::reward::output(&keychain, &builder, &key_id3, fees, false).unwrap();
|
let reward = libtx::reward::output(&keychain, &builder, &key_id3, fees, false).unwrap();
|
||||||
|
let next_header_info =
|
||||||
|
consensus::next_difficulty(prev.height + 1, chain.difficulty_iter().unwrap());
|
||||||
let mut block =
|
let mut block =
|
||||||
core::core::Block::new(&prev, txs, Difficulty::min_dma(), reward).unwrap();
|
core::core::Block::new(&prev, txs, next_header_info.difficulty, reward).unwrap();
|
||||||
let next_header_info = consensus::next_difficulty(1, chain.difficulty_iter().unwrap());
|
|
||||||
block.header.timestamp = prev.timestamp + Duration::seconds(60);
|
block.header.timestamp = prev.timestamp + Duration::seconds(60);
|
||||||
block.header.pow.secondary_scaling = next_header_info.secondary_scaling;
|
block.header.pow.secondary_scaling = next_header_info.secondary_scaling;
|
||||||
|
|
||||||
|
@ -232,10 +236,11 @@ fn test_coinbase_maturity() {
|
||||||
let pk = ExtKeychainPath::new(1, 1, 0, 0, 0).to_identifier();
|
let pk = ExtKeychainPath::new(1, 1, 0, 0, 0).to_identifier();
|
||||||
|
|
||||||
let reward = libtx::reward::output(&keychain, &builder, &pk, 0, false).unwrap();
|
let reward = libtx::reward::output(&keychain, &builder, &pk, 0, false).unwrap();
|
||||||
let mut block =
|
|
||||||
core::core::Block::new(&prev, &[], Difficulty::min_dma(), reward).unwrap();
|
|
||||||
let next_header_info =
|
let next_header_info =
|
||||||
consensus::next_difficulty(1, chain.difficulty_iter().unwrap());
|
consensus::next_difficulty(prev.height + 1, chain.difficulty_iter().unwrap());
|
||||||
|
let mut block =
|
||||||
|
core::core::Block::new(&prev, &[], next_header_info.difficulty, reward)
|
||||||
|
.unwrap();
|
||||||
block.header.timestamp = prev.timestamp + Duration::seconds(60);
|
block.header.timestamp = prev.timestamp + Duration::seconds(60);
|
||||||
block.header.pow.secondary_scaling = next_header_info.secondary_scaling;
|
block.header.pow.secondary_scaling = next_header_info.secondary_scaling;
|
||||||
|
|
||||||
|
@ -262,10 +267,11 @@ fn test_coinbase_maturity() {
|
||||||
|
|
||||||
let txs = &[coinbase_txn];
|
let txs = &[coinbase_txn];
|
||||||
let fees = txs.iter().map(|tx| tx.fee()).sum();
|
let fees = txs.iter().map(|tx| tx.fee()).sum();
|
||||||
let next_header_info = consensus::next_difficulty(1, chain.difficulty_iter().unwrap());
|
let next_header_info =
|
||||||
|
consensus::next_difficulty(prev.height + 1, chain.difficulty_iter().unwrap());
|
||||||
let reward = libtx::reward::output(&keychain, &builder, &key_id4, fees, false).unwrap();
|
let reward = libtx::reward::output(&keychain, &builder, &key_id4, fees, false).unwrap();
|
||||||
let mut block =
|
let mut block =
|
||||||
core::core::Block::new(&prev, txs, Difficulty::min_dma(), reward).unwrap();
|
core::core::Block::new(&prev, txs, next_header_info.difficulty, reward).unwrap();
|
||||||
|
|
||||||
block.header.timestamp = prev.timestamp + Duration::seconds(60);
|
block.header.timestamp = prev.timestamp + Duration::seconds(60);
|
||||||
block.header.pow.secondary_scaling = next_header_info.secondary_scaling;
|
block.header.pow.secondary_scaling = next_header_info.secondary_scaling;
|
||||||
|
|
Loading…
Reference in a new issue