thread local chain type vs global chain type (#3327)

* Introduce GLOBAL_CHAIN_TYPE and make CHAIN_TYPE thread_local.
This makes testing more explicit and significantly more robust.

* set_local_chain_type() in tests

* cleanup - weird

* get pool tests working with explicit local chain_type config

* core tests working with explicit local chain_type

* p2p tests working with explicit local chain_type

* store tests working

* cleanup, feedback
This commit is contained in:
Antioch Peverell
2020-05-22 12:51:58 +01:00
committed by GitHub
parent 096b6924ce
commit 6faa0e8d75
33 changed files with 192 additions and 114 deletions
+2 -2
View File
@@ -17,12 +17,12 @@
use chrono::prelude::{DateTime, Utc};
use self::core::consensus;
use self::core::core::block;
use self::core::core::committed;
use self::core::core::hash::Hash;
use self::core::core::transaction::{self, Transaction};
use self::core::core::{BlockHeader, BlockSums};
use self::core::{consensus, global};
use failure::Fail;
use grin_core as core;
use grin_keychain as keychain;
@@ -144,7 +144,7 @@ fn default_max_stempool_size() -> usize {
50_000
}
fn default_mineable_max_weight() -> usize {
global::max_block_weight()
consensus::MAX_BLOCK_WEIGHT
}
/// Represents a single entry in the pool.
+2 -1
View File
@@ -17,8 +17,8 @@ pub mod common;
use self::core::core::hash::Hashed;
use self::core::core::verifier_cache::LruVerifierCache;
use self::core::core::{Block, BlockHeader, Transaction};
use self::core::libtx;
use self::core::pow::Difficulty;
use self::core::{global, libtx};
use self::keychain::{ExtKeychain, Keychain};
use self::util::RwLock;
use crate::common::*;
@@ -30,6 +30,7 @@ use std::sync::Arc;
#[test]
fn test_transaction_pool_block_building() {
util::init_test_logger();
global::set_local_chain_type(global::ChainTypes::AutomatedTesting);
let keychain: ExtKeychain = Keychain::from_random_seed(false).unwrap();
let db_root = ".grin_block_building".to_string();
+1 -1
View File
@@ -33,7 +33,7 @@ use std::sync::Arc;
#[test]
fn test_block_building_max_weight() {
util::init_test_logger();
global::set_mining_mode(global::ChainTypes::AutomatedTesting);
global::set_local_chain_type(global::ChainTypes::AutomatedTesting);
let keychain: ExtKeychain = Keychain::from_random_seed(false).unwrap();
+2 -1
View File
@@ -17,8 +17,8 @@ pub mod common;
use self::core::core::hash::Hashed;
use self::core::core::verifier_cache::LruVerifierCache;
use self::core::core::{Block, BlockHeader};
use self::core::libtx;
use self::core::pow::Difficulty;
use self::core::{global, libtx};
use self::keychain::{ExtKeychain, Keychain};
use self::util::RwLock;
use crate::common::ChainAdapter;
@@ -30,6 +30,7 @@ use std::sync::Arc;
#[test]
fn test_transaction_pool_block_reconciliation() {
global::set_local_chain_type(global::ChainTypes::AutomatedTesting);
let keychain: ExtKeychain = Keychain::from_random_seed(false).unwrap();
let db_root = ".grin_block_reconciliation".to_string();
+2
View File
@@ -17,6 +17,7 @@ pub mod common;
use self::core::core::hash::Hash;
use self::core::core::verifier_cache::LruVerifierCache;
use self::core::core::{BlockHeader, BlockSums, Transaction};
use self::core::global;
use self::keychain::{ExtKeychain, Keychain};
use self::pool::types::{BlockChain, PoolError};
use self::util::RwLock;
@@ -67,6 +68,7 @@ impl BlockChain for CoinbaseMaturityErrorChainAdapter {
/// Test we correctly verify coinbase maturity when adding txs to the pool.
#[test]
fn test_coinbase_maturity() {
global::set_local_chain_type(global::ChainTypes::AutomatedTesting);
let keychain: ExtKeychain = Keychain::from_random_seed(false).unwrap();
// Mocking this up with an adapter that will raise an error for coinbase
+3 -1
View File
@@ -16,8 +16,8 @@ pub mod common;
use self::core::core::verifier_cache::LruVerifierCache;
use self::core::core::{transaction, Block, BlockHeader, Weighting};
use self::core::libtx;
use self::core::pow::Difficulty;
use self::core::{global, libtx};
use self::keychain::{ExtKeychain, Keychain};
use self::pool::TxSource;
use self::util::RwLock;
@@ -31,6 +31,8 @@ use std::sync::Arc;
/// Test we can add some txs to the pool (both stempool and txpool).
#[test]
fn test_the_transaction_pool() {
// Use mainnet config to allow for reasonably large block weights.
global::set_local_chain_type(global::ChainTypes::Mainnet);
let keychain: ExtKeychain = Keychain::from_random_seed(false).unwrap();
let db_root = ".grin_transaction_pool".to_string();