Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(tests): fix a bunch of tests after the wit/2 integation
Browse files Browse the repository at this point in the history
drcpu-github committed Jun 1, 2024
1 parent bd7a300 commit 720f959
Showing 6 changed files with 45 additions and 11 deletions.
14 changes: 8 additions & 6 deletions bridges/centralized-ethereum/src/actors/dr_sender/tests.rs
Original file line number Diff line number Diff line change
@@ -4,14 +4,14 @@ use witnet_data_structures::chain::{RADAggregate, RADRequest, RADRetrieve, RADTa
#[test]
fn deserialize_empty_dr() {
// An empty data request is invalid with error 0xE0: BridgeMalformedRequest
let err = deserialize_and_validate_dr_bytes(&[], 1).unwrap_err();
let err = deserialize_and_validate_dr_bytes(&[], 0, 1).unwrap_err();
assert_eq!(err.encode_cbor(), vec![216, 39, 129, 24, 224]);
}

#[test]
fn deserialize_dr_not_protobuf() {
// A malformed data request is invalid with error 0xE0: BridgeMalformedRequest
let err = deserialize_and_validate_dr_bytes(&[1, 2, 3, 4], 1).unwrap_err();
let err = deserialize_and_validate_dr_bytes(&[1, 2, 3, 4], 0, 1).unwrap_err();
assert_eq!(err.encode_cbor(), vec![216, 39, 129, 24, 224]);
}

@@ -55,7 +55,8 @@ fn deserialize_dr_high_value() {
let dro_bytes = dro.to_pb_bytes().unwrap();
// Setting the maximum allowed value to 1 nanowit below that will result in an error 0xE1:
// BridgePoorIncentives
let err = deserialize_and_validate_dr_bytes(&dro_bytes, total_value - 1).unwrap_err();
let err =
deserialize_and_validate_dr_bytes(&dro_bytes, 1_000_000_000, total_value - 1).unwrap_err();
assert_eq!(err.encode_cbor(), vec![216, 39, 129, 24, 225]);
}

@@ -78,7 +79,7 @@ fn deserialize_dr_collateral_one_nanowit() {
assert_eq!(total_value, 20_000_000);

let dro_bytes = dro.to_pb_bytes().unwrap();
let err = deserialize_and_validate_dr_bytes(&dro_bytes, total_value).unwrap_err();
let err = deserialize_and_validate_dr_bytes(&dro_bytes, 1, total_value).unwrap_err();
assert_eq!(err.encode_cbor(), vec![216, 39, 129, 24, 224]);
}

@@ -95,7 +96,7 @@ fn deserialize_dr_value_overflow() {
};

let dro_bytes = dro.to_pb_bytes().unwrap();
let err = deserialize_and_validate_dr_bytes(&dro_bytes, 1).unwrap_err();
let err = deserialize_and_validate_dr_bytes(&dro_bytes, 0, 1).unwrap_err();
assert_eq!(err.encode_cbor(), vec![216, 39, 129, 24, 224]);
}

@@ -115,6 +116,7 @@ fn deserialize_and_validate_dr_bytes_wip_0022() {
let dro_bytes = dro.to_pb_bytes().unwrap();
let witnet_dr_max_value_nanowits = 100_000_000_000;
let err =
deserialize_and_validate_dr_bytes(&dro_bytes, witnet_dr_max_value_nanowits).unwrap_err();
deserialize_and_validate_dr_bytes(&dro_bytes, 1_000_000_000, witnet_dr_max_value_nanowits)
.unwrap_err();
assert_eq!(err.encode_cbor(), vec![216, 39, 129, 24, 224]);
}
2 changes: 2 additions & 0 deletions node/src/actors/chain_manager/mining.rs
Original file line number Diff line number Diff line change
@@ -1190,6 +1190,7 @@ mod tests {
// Set `max_vt_weight` and `max_dr_weight` to zero (no transaction should be included)
let max_vt_weight = 0;
let max_dr_weight = 0;
let max_st_weight = 0;

// Fields required to mine a block
let block_beacon = CheckpointBeacon::default();
@@ -1219,6 +1220,7 @@ mod tests {
(&mut transaction_pool, &unspent_outputs_pool, &dr_pool),
max_vt_weight,
max_dr_weight,
max_st_weight,
block_beacon,
block_proof,
&[],
1 change: 1 addition & 0 deletions node/src/actors/chain_manager/mod.rs
Original file line number Diff line number Diff line change
@@ -4042,6 +4042,7 @@ mod tests {
vrf_hash_2,
false,
&VrfSlots::new(vec![Hash::default()]),
ProtocolVersion::V1_7,
),
Ordering::Greater
);
6 changes: 2 additions & 4 deletions validations/benches/reppoe.rs
Original file line number Diff line number Diff line change
@@ -7,8 +7,6 @@ use witnet_data_structures::chain::{
Alpha, Environment, PublicKeyHash, Reputation, ReputationEngine,
};

// To benchmark the old algorithm, comment out this import:
use witnet_validations::validations;
// To benchmark the old algorithm, comment out the line that says cfg any:
#[cfg(any())]
mod validations {
@@ -87,7 +85,7 @@ fn be<I>(
}
// Initialize cache
rep_eng.total_active_reputation();
validations::calculate_reppoe_threshold(
witnet_validations::eligibility::legacy::calculate_reppoe_threshold(
&rep_eng,
&my_pkh,
num_witnesses,
@@ -101,7 +99,7 @@ fn be<I>(
if invalidate_threshold_cache {
rep_eng.clear_threshold_cache();
}
validations::calculate_reppoe_threshold(
witnet_validations::eligibility::legacy::calculate_reppoe_threshold(
&rep_eng,
&my_pkh,
num_witnesses,
18 changes: 17 additions & 1 deletion validations/src/tests/compare_block_candidates.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use witnet_data_structures::chain::{tapi::current_active_wips, Hash, Reputation};
use witnet_data_structures::{
chain::{tapi::current_active_wips, Hash, Reputation},
proto::versioning::ProtocolVersion,
};

use std::cmp::Ordering;

@@ -33,6 +36,7 @@ fn test_compare_candidate_same_section() {
vrf_j,
act_j,
&vrf_sections,
ProtocolVersion::V1_7,
),
Ordering::Less
);
@@ -47,6 +51,7 @@ fn test_compare_candidate_same_section() {
vrf_j,
act_j,
&vrf_sections,
ProtocolVersion::V1_7,
),
Ordering::Greater
);
@@ -73,6 +78,7 @@ fn test_compare_candidate_same_section() {
vrf_j,
false,
&vrf_sections,
ProtocolVersion::V1_7,
),
Ordering::Greater
);
@@ -87,6 +93,7 @@ fn test_compare_candidate_same_section() {
vrf_j,
true,
&vrf_sections,
ProtocolVersion::V1_7,
),
Ordering::Less
);
@@ -109,6 +116,7 @@ fn test_compare_candidate_same_section() {
vrf_2,
true,
&vrf_sections,
ProtocolVersion::V1_7,
),
Ordering::Greater
);
@@ -123,6 +131,7 @@ fn test_compare_candidate_same_section() {
vrf_1,
true,
&vrf_sections,
ProtocolVersion::V1_7,
),
Ordering::Less
);
@@ -141,6 +150,7 @@ fn test_compare_candidate_same_section() {
vrf_1,
true,
&vrf_sections,
ProtocolVersion::V1_7,
),
Ordering::Greater
);
@@ -155,6 +165,7 @@ fn test_compare_candidate_same_section() {
vrf_1,
true,
&vrf_sections,
ProtocolVersion::V1_7,
),
Ordering::Less
);
@@ -171,6 +182,7 @@ fn test_compare_candidate_same_section() {
vrf_1,
true,
&vrf_sections,
ProtocolVersion::V1_7,
),
Ordering::Equal
);
@@ -207,6 +219,7 @@ fn test_compare_candidate_different_section() {
vrf_2,
act_j,
&vrf_sections,
ProtocolVersion::V1_7,
),
Ordering::Greater
);
@@ -221,6 +234,7 @@ fn test_compare_candidate_different_section() {
vrf_1,
act_j,
&vrf_sections,
ProtocolVersion::V1_7,
),
Ordering::Less
);
@@ -255,6 +269,7 @@ fn test_compare_candidate_different_reputation_bigger_than_zero() {
vrf_2,
true,
&vrf_sections,
ProtocolVersion::V1_7,
),
Ordering::Greater
);
@@ -270,6 +285,7 @@ fn test_compare_candidate_different_reputation_bigger_than_zero() {
vrf_1,
true,
&vrf_sections,
ProtocolVersion::V1_7,
),
Ordering::Less
);
15 changes: 15 additions & 0 deletions validations/src/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -23,12 +23,15 @@ use witnet_data_structures::{
calculate_tally_change, calculate_witness_reward, create_tally, DataRequestPool,
},
error::{BlockError, DataRequestError, Secp256k1ConversionError, TransactionError},
proto::versioning::ProtocolVersion,
radon_error::RadonError,
radon_report::{RadonReport, ReportContext, TypeLike},
staking::prelude::Stakes,
transaction::*,
transaction_factory::transaction_outputs_sum,
utxo_pool::{UnspentOutputsPool, UtxoDiff},
vrf::{BlockEligibilityClaim, DataRequestEligibilityClaim, VrfCtx},
wit::Wit,
};
use witnet_protected::Protected;
use witnet_rad::{
@@ -8808,6 +8811,8 @@ fn test_block_with_drpool_and_utxo_set<F: FnMut(&mut Block) -> bool>(
&rep_eng,
&consensus_constants,
&active_wips,
ProtocolVersion::V1_7,
&Stakes::<PublicKeyHash, Wit, u32, u64>::default(),
)?;
verify_signatures_test(signatures_to_verify)?;
let mut signatures_to_verify = vec![];
@@ -9083,6 +9088,8 @@ fn block_difficult_proof() {
&rep_eng,
&consensus_constants,
&current_active_wips(),
ProtocolVersion::V1_7,
&Stakes::<PublicKeyHash, Wit, u32, u64>::default(),
)?;
verify_signatures_test(signatures_to_verify)?;
let mut signatures_to_verify = vec![];
@@ -9790,6 +9797,8 @@ fn test_blocks_with_limits(
&rep_eng,
&consensus_constants,
&current_active_wips(),
ProtocolVersion::V1_7,
&Stakes::<PublicKeyHash, Wit, u32, u64>::default(),
)?;
verify_signatures_test(signatures_to_verify)?;
let mut signatures_to_verify = vec![];
@@ -10300,6 +10309,8 @@ fn genesis_block_after_not_bootstrap_hash() {
&rep_eng,
&consensus_constants,
&current_active_wips(),
ProtocolVersion::V1_7,
&Stakes::<PublicKeyHash, Wit, u32, u64>::default(),
);
assert_eq!(signatures_to_verify, vec![]);

@@ -10380,6 +10391,8 @@ fn genesis_block_value_overflow() {
&rep_eng,
&consensus_constants,
&current_active_wips(),
ProtocolVersion::V1_7,
&Stakes::<PublicKeyHash, Wit, u32, u64>::default(),
)
.unwrap();
assert_eq!(signatures_to_verify, vec![]);
@@ -10465,6 +10478,8 @@ fn genesis_block_full_validate() {
&rep_eng,
&consensus_constants,
&current_active_wips(),
ProtocolVersion::V1_7,
&Stakes::<PublicKeyHash, Wit, u32, u64>::default(),
)
.unwrap();
assert_eq!(signatures_to_verify, vec![]);

0 comments on commit 720f959

Please sign in to comment.