From a648abf3f82d5857668bfeba56724369cb06279b Mon Sep 17 00:00:00 2001 From: brianp Date: Mon, 27 Nov 2023 16:55:23 +0100 Subject: [PATCH] Update more tests --- .../tests/blockchain_database.rs | 4 +--- .../core/src/consensus/consensus_constants.rs | 5 ++--- .../consensus/consensus_encoding/hashing.rs | 7 +++++-- .../core/src/proof_of_work/sha3x_pow.rs | 2 +- .../transaction_components/test.rs | 4 ++-- .../core/tests/tests/node_comms_interface.rs | 19 +++++++++---------- 6 files changed, 20 insertions(+), 21 deletions(-) diff --git a/base_layer/core/src/chain_storage/tests/blockchain_database.rs b/base_layer/core/src/chain_storage/tests/blockchain_database.rs index ac891be066c..9d212c04a51 100644 --- a/base_layer/core/src/chain_storage/tests/blockchain_database.rs +++ b/base_layer/core/src/chain_storage/tests/blockchain_database.rs @@ -481,7 +481,7 @@ mod fetch_header_containing_kernel_mmr { fn it_returns_genesis() { let db = setup(); let genesis = db.fetch_block(0, true).unwrap(); - assert_eq!(genesis.block().body.kernels().len(), 1); + assert_eq!(genesis.block().body.kernels().len(), 0); let mut mmr_position = 0; genesis.block().body.kernels().iter().for_each(|_| { let header = db.fetch_header_containing_kernel_mmr(mmr_position).unwrap(); @@ -519,8 +519,6 @@ mod fetch_header_containing_kernel_mmr { db.add_block(block).unwrap(); let _block_and_outputs = add_many_chained_blocks(3, &db, &key_manager).await; - let header = db.fetch_header_containing_kernel_mmr(num_genesis_kernels - 1).unwrap(); - assert_eq!(header.height(), 0); let header = db.fetch_header_containing_kernel_mmr(num_genesis_kernels).unwrap(); assert_eq!(header.height(), 1); diff --git a/base_layer/core/src/consensus/consensus_constants.rs b/base_layer/core/src/consensus/consensus_constants.rs index 95cadcacb9c..de66e9fad59 100644 --- a/base_layer/core/src/consensus/consensus_constants.rs +++ b/base_layer/core/src/consensus/consensus_constants.rs @@ -149,7 +149,7 @@ pub struct PowAlgorithmConstants { pub target_time: u64, } -// const ESMERALDA_FAUCET_VALUE: u64 = 3_798_999_293_855_109; +const ESMERALDA_FAUCET_VALUE: u64 = 3_798_999_293_855_109; // The target time used by the difficulty adjustment algorithms, their target time is the target block interval * PoW // algorithm count @@ -372,8 +372,7 @@ impl ConsensusConstants { emission_tail: 800 * T, max_randomx_seed_height: u64::MAX, proof_of_work: algos, - faucet_value: 0.into(), /* ESMERALDA_FAUCET_VALUE.into(), // The esmeralda genesis block is re-used for - * localnet */ + faucet_value: ESMERALDA_FAUCET_VALUE.into(), // The esmeralda genesis block is re-used for localnet transaction_weight: TransactionWeight::latest(), max_script_byte_size: 2048, input_version_range, diff --git a/base_layer/core/src/consensus/consensus_encoding/hashing.rs b/base_layer/core/src/consensus/consensus_encoding/hashing.rs index 581bbebed14..9889ac9665a 100644 --- a/base_layer/core/src/consensus/consensus_encoding/hashing.rs +++ b/base_layer/core/src/consensus/consensus_encoding/hashing.rs @@ -149,8 +149,10 @@ mod tests { #[test] fn it_hashes_using_the_domain_hasher() { + let network = *CURRENT_NETWORK.lock().unwrap(); + // Script is chosen because the consensus encoding impl for TariScript has 2 writes let mut hasher = Blake2b::::default(); - TestHashDomain::add_domain_separation_tag(&mut hasher, "foo"); + TestHashDomain::add_domain_separation_tag(&mut hasher, &format!("{}.n{}", "foo", network.as_byte())); let expected_hash = hasher.chain_update(b"\xff\x00\x00\x00\x00\x00\x00\x00").finalize(); let hash = DomainSeparatedConsensusHasher::>::new("foo") @@ -162,10 +164,11 @@ mod tests { #[test] fn it_adds_to_hash_challenge_in_complete_chunks() { + let network = *CURRENT_NETWORK.lock().unwrap(); // Script is chosen because the consensus encoding impl for TariScript has 2 writes let test_subject = script!(Nop); let mut hasher = Blake2b::::default(); - TestHashDomain::add_domain_separation_tag(&mut hasher, "foo"); + TestHashDomain::add_domain_separation_tag(&mut hasher, &format!("{}.n{}", "foo", network.as_byte())); let expected_hash = hasher.chain_update(b"\x01\x73").finalize(); let hash = DomainSeparatedConsensusHasher::>::new("foo") diff --git a/base_layer/core/src/proof_of_work/sha3x_pow.rs b/base_layer/core/src/proof_of_work/sha3x_pow.rs index 0b433ea0c68..783e642c414 100644 --- a/base_layer/core/src/proof_of_work/sha3x_pow.rs +++ b/base_layer/core/src/proof_of_work/sha3x_pow.rs @@ -100,6 +100,6 @@ pub mod test { let mut header = get_header(); header.nonce = 631; println!("{:?}", header); - assert_eq!(sha3x_difficulty(&header).unwrap(), Difficulty::from_u64(3347).unwrap()); + assert_eq!(sha3x_difficulty(&header).unwrap(), Difficulty::from_u64(28).unwrap()); } } diff --git a/base_layer/core/src/transactions/transaction_components/test.rs b/base_layer/core/src/transactions/transaction_components/test.rs index 3265bfe9e8c..896ffecba23 100644 --- a/base_layer/core/src/transactions/transaction_components/test.rs +++ b/base_layer/core/src/transactions/transaction_components/test.rs @@ -293,7 +293,7 @@ fn kernel_hash() { .unwrap(); assert_eq!( &k.hash().to_hex(), - "d99f6c45b0c1051987eb5ce8f4434fbd88ae44c2d0f3a066ebc7f64114d33df8" + "38b03d013f941e86c027969fbbc190ca2a28fa2d7ac075d50dbfb6232deee646" ); } @@ -312,7 +312,7 @@ fn kernel_metadata() { .unwrap(); assert_eq!( &k.hash().to_hex(), - "ee7ff5ebcdc66757411afb2dced7d1bd7c09373f1717a7b6eb618fbda849ab4d" + "ebc852fbac798c25ce497b416f69ec11a97e186aacaa10e2bb4ca5f5a0f197f2" ) } diff --git a/base_layer/core/tests/tests/node_comms_interface.rs b/base_layer/core/tests/tests/node_comms_interface.rs index f8edda06c91..5f025723561 100644 --- a/base_layer/core/tests/tests/node_comms_interface.rs +++ b/base_layer/core/tests/tests/node_comms_interface.rs @@ -65,7 +65,7 @@ use tari_script::{inputs, script, ExecutionStack}; use tari_service_framework::reply_channel; use tokio::sync::{broadcast, mpsc}; -use crate::helpers::block_builders::append_block; +use crate::helpers::{block_builders::append_block, sample_blockchains::create_new_blockchain}; fn new_mempool() -> Mempool { let rules = create_consensus_rules(); @@ -110,11 +110,10 @@ async fn inbound_get_metadata() { #[tokio::test] async fn inbound_fetch_kernel_by_excess_sig() { - let store = create_test_blockchain_db(); + let network = Network::LocalNet; + let (store, blocks, _outputs, consensus_manager, _key_manager) = create_new_blockchain(network).await; let mempool = new_mempool(); - let network = Network::LocalNet; - let consensus_manager = ConsensusManager::builder(network).build().unwrap(); let (block_event_sender, _) = broadcast::channel(50); let (request_sender, _) = reply_channel::unbounded(); let (block_sender, _) = mpsc::unbounded_channel(); @@ -130,7 +129,7 @@ async fn inbound_fetch_kernel_by_excess_sig() { connectivity, randomx_factory, ); - let block = store.fetch_block(0, true).unwrap().block().clone(); + let block = blocks[0].block().clone(); let sig = block.body.kernels()[0].excess_sig.clone(); if let Ok(NodeCommsResponse::TransactionKernels(received_kernels)) = inbound_nch @@ -179,10 +178,9 @@ async fn inbound_fetch_headers() { #[tokio::test] async fn inbound_fetch_utxos() { - let store = create_test_blockchain_db(); - let mempool = new_mempool(); let network = Network::LocalNet; - let consensus_manager = ConsensusManager::builder(network).build().unwrap(); + let (store, blocks, _outputs, consensus_manager, _key_manager) = create_new_blockchain(network).await; + let mempool = new_mempool(); let (block_event_sender, _) = broadcast::channel(50); let (request_sender, _) = reply_channel::unbounded(); let (block_sender, _) = mpsc::unbounded_channel(); @@ -198,8 +196,9 @@ async fn inbound_fetch_utxos() { connectivity, randomx_factory, ); - let block = store.fetch_block(0, true).unwrap().block().clone(); - let utxo_1 = block.body.outputs()[0].clone(); + + let block0 = blocks[0].block().clone(); + let utxo_1 = block0.body.outputs()[0].clone(); let hash_1 = utxo_1.hash(); let key_manager = create_memory_db_key_manager();