Skip to content

Commit

Permalink
fix(tests): fix some tests that rely on block hashes
Browse files Browse the repository at this point in the history
  • Loading branch information
aesedepece committed Nov 21, 2023
1 parent 14e733e commit 3870231
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
24 changes: 16 additions & 8 deletions data_structures/src/chain/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
/// Keeps track of priority being used by transactions included in recent blocks, and provides
/// methods for estimating sensible priority values for future transactions.
pub mod priority;
/// Contains all TAPI related structures and business logic
pub mod tapi;

use std::{
cell::{Cell, RefCell},
cmp::Ordering,
Expand All @@ -20,8 +14,9 @@ use bls_signatures_rs::{bn256, bn256::Bn256, MultiSignature};
use failure::Fail;
use futures::future::BoxFuture;
use ordered_float::OrderedFloat;
use partial_struct::PartialStruct;
use serde::{Deserialize, Serialize};

use partial_struct::PartialStruct;
use witnet_crypto::{
hash::{calculate_sha256, Sha256},
key::ExtendedSK,
Expand All @@ -42,7 +37,10 @@ use crate::{
TransactionError,
},
get_environment,
proto::{schema::witnet, ProtobufConvert},
proto::{
versioning::{ProtocolVersion, VersionedHashable},
ProtobufConvert,
},
superblock::SuperBlockState,
transaction::{
CommitTransaction, DRTransaction, DRTransactionBody, Memoized, MintTransaction,
Expand All @@ -56,6 +54,12 @@ use crate::{
vrf::{BlockEligibilityClaim, DataRequestEligibilityClaim},
};

/// Keeps track of priority being used by transactions included in recent blocks, and provides
/// methods for estimating sensible priority values for future transactions.
pub mod priority;
/// Contains all TAPI related structures and business logic
pub mod tapi;

/// Define how the different structures should be hashed.
pub trait Hashable {
/// Calculate the hash of `self`
Expand Down Expand Up @@ -530,6 +534,10 @@ impl Block {
pub fn weight(&self) -> u32 {
self.dr_weight() + self.vt_weight() + self.st_weight() + self.ut_weight()
}

pub fn is_genesis(&self, genesis: &Hash) -> bool {
self.versioned_hash(ProtocolVersion::Legacy).eq(genesis)
}
}

impl BlockTransactions {
Expand Down
2 changes: 1 addition & 1 deletion node/src/actors/json_rpc/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2081,7 +2081,7 @@ mod tests {
let block = block_example();
let inv_elem = InventoryItem::Block(block);
let s = serde_json::to_string(&inv_elem).unwrap();
let expected = r#"{"block":{"block_header":{"signals":0,"beacon":{"checkpoint":0,"hashPrevBlock":"0000000000000000000000000000000000000000000000000000000000000000"},"merkle_roots":{"mint_hash":"0000000000000000000000000000000000000000000000000000000000000000","vt_hash_merkle_root":"0000000000000000000000000000000000000000000000000000000000000000","dr_hash_merkle_root":"0000000000000000000000000000000000000000000000000000000000000000","commit_hash_merkle_root":"0000000000000000000000000000000000000000000000000000000000000000","reveal_hash_merkle_root":"0000000000000000000000000000000000000000000000000000000000000000","tally_hash_merkle_root":"0000000000000000000000000000000000000000000000000000000000000000"},"proof":{"proof":{"proof":[],"public_key":{"compressed":0,"bytes":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}}},"bn256_public_key":null},"block_sig":{"signature":{"Secp256k1":{"der":[]}},"public_key":{"compressed":0,"bytes":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}},"txns":{"mint":{"epoch":0,"outputs":[]},"value_transfer_txns":[],"data_request_txns":[{"body":{"inputs":[{"output_pointer":"0000000000000000000000000000000000000000000000000000000000000000:0"}],"outputs":[{"pkh":"wit1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqwrt3a4","value":0,"time_lock":0}],"dr_output":{"data_request":{"time_lock":0,"retrieve":[{"kind":"HTTP-GET","url":"https://openweathermap.org/data/2.5/weather?id=2950159&appid=b6907d289e10d714a6e88b30761fae22"},{"kind":"HTTP-GET","url":"https://openweathermap.org/data/2.5/weather?id=2950159&appid=b6907d289e10d714a6e88b30761fae22"}],"aggregate":{"filters":[],"reducer":0},"tally":{"filters":[],"reducer":0}},"witness_reward":0,"witnesses":0,"commit_and_reveal_fee":0,"min_consensus_percentage":0,"collateral":0}},"signatures":[{"signature":{"Secp256k1":{"der":[]}},"public_key":{"compressed":0,"bytes":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}}]}],"commit_txns":[],"reveal_txns":[],"tally_txns":[]}}}"#;
let expected = r#"{"block":{"block_header":{"signals":0,"beacon":{"checkpoint":0,"hashPrevBlock":"0000000000000000000000000000000000000000000000000000000000000000"},"merkle_roots":{"mint_hash":"0000000000000000000000000000000000000000000000000000000000000000","vt_hash_merkle_root":"0000000000000000000000000000000000000000000000000000000000000000","dr_hash_merkle_root":"0000000000000000000000000000000000000000000000000000000000000000","commit_hash_merkle_root":"0000000000000000000000000000000000000000000000000000000000000000","reveal_hash_merkle_root":"0000000000000000000000000000000000000000000000000000000000000000","tally_hash_merkle_root":"0000000000000000000000000000000000000000000000000000000000000000","stake_hash_merkle_root":"0000000000000000000000000000000000000000000000000000000000000000","unstake_hash_merkle_root":"0000000000000000000000000000000000000000000000000000000000000000"},"proof":{"proof":{"proof":[],"public_key":{"compressed":0,"bytes":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}}},"bn256_public_key":null},"block_sig":{"signature":{"Secp256k1":{"der":[]}},"public_key":{"compressed":0,"bytes":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}},"txns":{"mint":{"epoch":0,"outputs":[]},"value_transfer_txns":[],"data_request_txns":[{"body":{"inputs":[{"output_pointer":"0000000000000000000000000000000000000000000000000000000000000000:0"}],"outputs":[{"pkh":"wit1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqwrt3a4","value":0,"time_lock":0}],"dr_output":{"data_request":{"time_lock":0,"retrieve":[{"kind":"HTTP-GET","url":"https://openweathermap.org/data/2.5/weather?id=2950159&appid=b6907d289e10d714a6e88b30761fae22"},{"kind":"HTTP-GET","url":"https://openweathermap.org/data/2.5/weather?id=2950159&appid=b6907d289e10d714a6e88b30761fae22"}],"aggregate":{"filters":[],"reducer":0},"tally":{"filters":[],"reducer":0}},"witness_reward":0,"witnesses":0,"commit_and_reveal_fee":0,"min_consensus_percentage":0,"collateral":0}},"signatures":[{"signature":{"Secp256k1":{"der":[]}},"public_key":{"compressed":0,"bytes":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}}]}],"commit_txns":[],"reveal_txns":[],"tally_txns":[],"stake_txns":[],"unstake_txns":[]}}}"#;
assert_eq!(s, expected, "\n{}\n", s);
}

Expand Down
4 changes: 3 additions & 1 deletion validations/src/validations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::{
};

use itertools::Itertools;

use witnet_config::defaults::{
PSEUDO_CONSENSUS_CONSTANTS_WIP0022_REWARD_COLLATERAL_RATIO,
PSEUDO_CONSENSUS_CONSTANTS_WIP0027_COLLATERAL_AGE,
Expand All @@ -28,6 +29,7 @@ use witnet_data_structures::{
calculate_witness_reward_before_second_hard_fork, create_tally, DataRequestPool,
},
error::{BlockError, DataRequestError, TransactionError},
proto::versioning::VersionedHashable,
radon_report::{RadonReport, ReportContext},
transaction::{
CommitTransaction, DRTransaction, MintTransaction, RevealTransaction, StakeTransaction,
Expand Down Expand Up @@ -1555,7 +1557,7 @@ pub fn validate_block_transactions(
mut visitor: Option<&mut dyn Visitor<Visitable = (Transaction, u64, u32)>>,
) -> Result<Diff, failure::Error> {
let epoch = block.block_header.beacon.checkpoint;
let is_genesis = block.hash() == consensus_constants.genesis_hash;
let is_genesis = block.is_genesis(consensus_constants.genesis_hash);
let mut utxo_diff = UtxoDiff::new(utxo_set, block_number);

// Init total fee
Expand Down

0 comments on commit 3870231

Please sign in to comment.