Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sdbondi committed Aug 4, 2022
1 parent cd37449 commit 20661f6
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 20 deletions.
6 changes: 4 additions & 2 deletions base_layer/core/src/base_node/sync/rpc/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,10 @@ mod sync_utxos {
let (_, chain) = create_main_chain(&db, block_specs!(["A->GB"], ["B->A"]));

let block = chain.get("B").unwrap();
let total_outputs = block.block().header.output_mmr_size;
let start = total_outputs - 2;
let msg = SyncUtxosRequest {
start: 3500,
start,
end_header_hash: block.hash().clone(),
include_pruned_utxos: true,
include_deleted_bitmaps: false,
Expand All @@ -170,6 +172,6 @@ mod sync_utxos {
.collect::<Vec<_>>()
.await;

assert!(utxo_indexes.iter().all(|index| (3500..=4002).contains(index)));
assert!(utxo_indexes.iter().all(|index| (start..=start + 2).contains(index)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -526,11 +526,12 @@ mod fetch_total_size_stats {
#[test]
fn it_measures_the_number_of_entries() {
let db = setup();
let genesis_output_count = db.fetch_header(0).unwrap().unwrap().output_mmr_size;
let _block_and_outputs = add_many_chained_blocks(2, &db);
let stats = db.fetch_total_size_stats().unwrap();
assert_eq!(
stats.sizes().iter().find(|s| s.name == "utxos_db").unwrap().num_entries,
4003
genesis_output_count + 2
);
}
}
Expand Down Expand Up @@ -580,7 +581,7 @@ mod fetch_header_containing_utxo_mmr {
fn it_returns_genesis() {
let db = setup();
let genesis = db.fetch_block(0).unwrap();
assert_eq!(genesis.block().body.outputs().len(), 4001);
assert!(!genesis.block().body.outputs().is_empty());
let mut mmr_position = 0;
genesis.block().body.outputs().iter().for_each(|_| {
let header = db.fetch_header_containing_utxo_mmr(mmr_position).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion base_layer/core/src/consensus/consensus_constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ impl ConsensusConstants {
vec![ConsensusConstants {
effective_from_height: 0,
coinbase_lock_height: 2,
blockchain_version: 1,
blockchain_version: 2,
valid_blockchain_version_range: 0..=3,
future_time_limit: 540,
difficulty_block_window,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ impl TransactionOutput {
encrypted_value: &EncryptedValue,
minimum_value_promise: MicroTari,
) -> [u8; 32] {
let common = DomainSeparatedConsensusHasher::<TransactionHashDomain>::new("metadata_signature_challenge")
let common = DomainSeparatedConsensusHasher::<TransactionHashDomain>::new("metadata_signature")
.chain(public_commitment_nonce)
.chain(script)
.chain(features)
Expand Down
3 changes: 1 addition & 2 deletions base_layer/core/tests/node_comms_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,7 @@ async fn inbound_fetch_blocks() {
#[allow(clippy::too_many_lines)]
async fn inbound_fetch_blocks_before_horizon_height() {
let factories = CryptoFactories::default();
let network = Network::LocalNet;
let consensus_manager = ConsensusManager::builder(network).build();
let consensus_manager = ConsensusManager::builder(Network::Dibbler).build();
let block0 = consensus_manager.get_genesis_block();
let validators = Validators::new(
MockValidator::new(true),
Expand Down
4 changes: 2 additions & 2 deletions base_layer/tari_mining_helper_ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,8 @@ mod tests {

#[test]
fn detect_change_in_consensus_encoding() {
const NONCE: u64 = 7157305302409646947;
const DIFFICULTY: Difficulty = Difficulty::from_u64(6126);
const NONCE: u64 = 8624065455907397555;
const DIFFICULTY: Difficulty = Difficulty::from_u64(11786);
// Use this to generate new NONCE and DIFFICULTY
// Use ONLY if you know encoding has changed
// let (difficulty, nonce) = generate_nonce_with_min_difficulty(MIN_DIFFICULTY).unwrap();
Expand Down
10 changes: 5 additions & 5 deletions comms/core/src/utils/multiaddr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,15 @@ mod test {

#[test]
fn multiaddr_to_socketaddr_ok() {
fn expect_success(addr: &str, expected_ip: &str) {
fn expect_success(addr: &str, expected_ips: &[&str]) {
let addr = Multiaddr::from_str(addr).unwrap();
let sock_addr = super::multiaddr_to_socketaddr(&addr).unwrap();
assert_eq!(sock_addr.ip().to_string(), expected_ip);
assert!(expected_ips.iter().any(|ip| *ip == sock_addr.ip().to_string()));
}

expect_success("/ip4/254.0.1.2/tcp/1234", "254.0.1.2");
expect_success("/ip6/::1/tcp/1234", "::1");
expect_success("/dns4/taridns.dyn-ip.me/tcp/1234", "127.0.0.1");
expect_success("/ip4/254.0.1.2/tcp/1234", &["254.0.1.2"]);
expect_success("/ip6/::1/tcp/1234", &["::1"]);
expect_success("/dns4/localhost/tcp/1234", &["::1", "127.0.0.1"]);
}

#[test]
Expand Down
9 changes: 4 additions & 5 deletions integration_tests/helpers/transactionBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,17 @@ class TransactionBuilder {
covenant,
encryptedValue
) {
const buf_nonce = Buffer.from(publicNonce, "hex");
const script_offset_public_key = Buffer.from(scriptOffsetPublicKey, "hex");
const publicCommitmentNonce = Buffer.from(publicNonce, "hex");
const sender_offset_public_key = Buffer.from(scriptOffsetPublicKey, "hex");
const features_buffer = this.featuresToConsensusBytes(features);

// base_layer/core/src/transactions/transaction/transaction_output.rs
let hash = new DomainHasher(
"com.tari.base_layer.core.transactions.v0.metadata_signature"
)
.chain(buf_nonce)
.chain(publicCommitmentNonce)
.chain(this.toLengthEncoded(script))
.chain(features_buffer)
.chain(script_offset_public_key)
.chain(sender_offset_public_key)
.chain(commitment)
.chain(this.toLengthEncoded(covenant))
.chain(encryptedValue)
Expand Down

0 comments on commit 20661f6

Please sign in to comment.