Skip to content

Commit

Permalink
Update more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
brianp committed Nov 27, 2023
1 parent 249c395 commit a648abf
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);

Expand Down
5 changes: 2 additions & 3 deletions base_layer/core/src/consensus/consensus_constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
7 changes: 5 additions & 2 deletions base_layer/core/src/consensus/consensus_encoding/hashing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<U32>::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::<TestHashDomain, Blake2b<U32>>::new("foo")
Expand All @@ -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::<U32>::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::<TestHashDomain, Blake2b<U32>>::new("foo")
Expand Down
2 changes: 1 addition & 1 deletion base_layer/core/src/proof_of_work/sha3x_pow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ fn kernel_hash() {
.unwrap();
assert_eq!(
&k.hash().to_hex(),
"d99f6c45b0c1051987eb5ce8f4434fbd88ae44c2d0f3a066ebc7f64114d33df8"
"38b03d013f941e86c027969fbbc190ca2a28fa2d7ac075d50dbfb6232deee646"
);
}

Expand All @@ -312,7 +312,7 @@ fn kernel_metadata() {
.unwrap();
assert_eq!(
&k.hash().to_hex(),
"ee7ff5ebcdc66757411afb2dced7d1bd7c09373f1717a7b6eb618fbda849ab4d"
"ebc852fbac798c25ce497b416f69ec11a97e186aacaa10e2bb4ca5f5a0f197f2"
)
}

Expand Down
19 changes: 9 additions & 10 deletions base_layer/core/tests/tests/node_comms_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand All @@ -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
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down

0 comments on commit a648abf

Please sign in to comment.