Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mpapierski committed Dec 13, 2024
1 parent 2c65e9d commit ccf7cf7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 25 deletions.
41 changes: 23 additions & 18 deletions node/src/components/block_validator/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,10 @@ impl BlockValidationState {
.transaction_v1_config
.get_max_transaction_count(supported_lane);
if lane_count_limit < transactions as u64 {
warn!("too many transactions in lane: {lane_count_limit}");
warn!(
supported_lane,
lane_count_limit, transactions, "too many transactions in lane"
);
return Err(());
}
}
Expand Down Expand Up @@ -674,11 +677,12 @@ mod tests {
}

// Please note: values in the following test cases must match the production chainspec.
const MAX_LARGE_COUNT: u64 = 3;
const MAX_LARGE_COUNT: u64 = 1;
const MAX_AUCTION_COUNT: u64 = 145;
const MAX_INSTALL_UPGRADE_COUNT: u64 = 1;
const MAX_MINT_COUNT: u64 = 650;

#[derive(Debug)]
struct TestCase {
mint_count: u64,
auction_count: u64,
Expand Down Expand Up @@ -760,13 +764,13 @@ mod tests {
},
};

const LESS_THAN_MAX_STANDARD: TestCase = TestCase {
standard_count: FULL_STANDARD.standard_count - 1,
state_validator: |(state, responder)| {
responder.is_none() && matches!(state, BlockValidationState::InProgress { .. })
},
..FULL_STANDARD
};
// const LESS_THAN_MAX_STANDARD: TestCase = TestCase {
// standard_count: FULL_STANDARD.standard_count - 1,
// state_validator: |(state, responder)| {
// responder.is_none() && matches!(state, BlockValidationState::InProgress { .. })
// },
// ..FULL_STANDARD
// };

const TOO_MANY_STANDARD: TestCase = TestCase {
standard_count: FULL_STANDARD.standard_count + 1,
Expand Down Expand Up @@ -850,7 +854,8 @@ mod tests {
let mut rng = TestRng::new();
run_test_case(TOO_MANY_STANDARD, &mut rng);
run_test_case(FULL_STANDARD, &mut rng);
run_test_case(LESS_THAN_MAX_STANDARD, &mut rng);
// NOTE: current prod chainspec has a limit of 1 large transaction, so one less is 0 which
// makes the test invalid run_test_case(LESS_THAN_MAX_STANDARD, &mut rng);
}

#[test]
Expand Down Expand Up @@ -943,7 +948,7 @@ mod tests {
fn should_add_responder_if_in_progress() {
let mut rng = TestRng::new();
let mut fixture = Fixture::new(&mut rng);
let (mut state, _maybe_responder) = fixture.new_state(2, 2, 1, 2);
let (mut state, _maybe_responder) = fixture.new_state(2, 2, 1, 1);
assert!(matches!(state, BlockValidationState::InProgress { .. }));
assert_eq!(state.responder_count(), 1);

Expand Down Expand Up @@ -984,7 +989,7 @@ mod tests {
fn should_add_new_holder_if_in_progress() {
let mut rng = TestRng::new();
let mut fixture = Fixture::new(&mut rng);
let (mut state, _maybe_responder) = fixture.new_state(2, 2, 1, 2);
let (mut state, _maybe_responder) = fixture.new_state(2, 2, 1, 1);
assert!(matches!(state, BlockValidationState::InProgress { .. }));
assert_eq!(state.holders_mut().unwrap().len(), 1);

Expand All @@ -1001,7 +1006,7 @@ mod tests {
fn should_not_change_holder_state() {
let mut rng = TestRng::new();
let mut fixture = Fixture::new(&mut rng);
let (mut state, _maybe_responder) = fixture.new_state(2, 2, 1, 2);
let (mut state, _maybe_responder) = fixture.new_state(2, 2, 1, 1);
assert!(matches!(state, BlockValidationState::InProgress { .. }));
let (holder, holder_state) = state
.holders_mut()
Expand All @@ -1024,7 +1029,7 @@ mod tests {
fn should_start_fetching() {
let mut rng = TestRng::new();
let mut fixture = Fixture::new(&mut rng);
let (mut state, _maybe_responder) = fixture.new_state(2, 2, 1, 2);
let (mut state, _maybe_responder) = fixture.new_state(2, 2, 1, 1);
assert!(matches!(state, BlockValidationState::InProgress { .. }));
let (holder, holder_state) = state
.holders_mut()
Expand Down Expand Up @@ -1052,7 +1057,7 @@ mod tests {
..
} => {
assert_eq!(holder, original_holder);
assert_eq!(missing_transactions.len(), 7);
assert_eq!(missing_transactions.len(), 6);
}
_ => panic!("unexpected return value"),
}
Expand All @@ -1066,7 +1071,7 @@ mod tests {
fn start_fetching_should_return_ongoing_if_any_holder_in_asked_state() {
let mut rng = TestRng::new();
let mut fixture = Fixture::new(&mut rng);
let (mut state, _maybe_responder) = fixture.new_state(2, 2, 1, 2);
let (mut state, _maybe_responder) = fixture.new_state(2, 2, 1, 1);
assert!(matches!(state, BlockValidationState::InProgress { .. }));

// Change the current (only) holder's state to `Asked`.
Expand Down Expand Up @@ -1111,7 +1116,7 @@ mod tests {
fn start_fetching_should_return_unable_if_all_holders_in_failed_state() {
let mut rng = TestRng::new();
let mut fixture = Fixture::new(&mut rng);
let (mut state, _maybe_responder) = fixture.new_state(2, 2, 1, 2);
let (mut state, _maybe_responder) = fixture.new_state(2, 2, 1, 1);
assert!(matches!(state, BlockValidationState::InProgress { .. }));

// Set the original holder's state to `Failed` and add some more failed.
Expand Down Expand Up @@ -1192,7 +1197,7 @@ mod tests {
fn unrelated_transaction_added_should_not_change_state() {
let mut rng = TestRng::new();
let mut fixture = Fixture::new(&mut rng);
let (mut state, _maybe_responder) = fixture.new_state(2, 2, 1, 2);
let (mut state, _maybe_responder) = fixture.new_state(2, 2, 1, 1);
let (appendable_block_before, missing_transactions_before, holders_before) = match &state {
BlockValidationState::InProgress {
appendable_block,
Expand Down
11 changes: 4 additions & 7 deletions node/src/components/block_validator/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,7 @@ async fn transfer_transaction_mixup_and_replay() {
let transfer_v1 = new_v1_transfer(&mut rng, timestamp, ttl);

// First we make sure that our transfers and transactions would normally be valid.
let transactions = vec![deploy.clone(), transaction_v1.clone()];
let transactions = vec![transaction_v1.clone()];
let transfers = vec![transfer_orig.clone(), transfer_v1.clone()];
let mut context = ValidationContext::new()
.with_num_validators(&mut rng, 1)
Expand Down Expand Up @@ -1146,15 +1146,14 @@ async fn should_validate_block_with_signatures() {
let mut rng = TestRng::new();
let ttl = TimeDiff::from_millis(200);
let timestamp = Timestamp::from(1000);
let deploy = new_deploy(&mut rng, timestamp, ttl);
let transaction_v1 = new_v1_standard(&mut rng, timestamp, ttl);
let transfer = new_transfer(&mut rng, timestamp, ttl);
let transfer_v1 = new_v1_transfer(&mut rng, timestamp, ttl);

let context = ValidationContext::new()
.with_num_validators(&mut rng, 3)
.with_past_blocks(&mut rng, 0, 5, 0.into())
.with_transactions(vec![deploy, transaction_v1])
.with_transactions(vec![transaction_v1])
.with_transfers(vec![transfer, transfer_v1])
.include_all_transactions()
.include_all_transfers();
Expand All @@ -1173,15 +1172,14 @@ async fn should_fetch_missing_signature() {
let mut rng = TestRng::new();
let ttl = TimeDiff::from_millis(200);
let timestamp = Timestamp::from(1000);
let deploy = new_deploy(&mut rng, timestamp, ttl);
let transaction_v1 = new_v1_standard(&mut rng, timestamp, ttl);
let transfer = new_transfer(&mut rng, timestamp, ttl);
let transfer_v1 = new_v1_transfer(&mut rng, timestamp, ttl);

let context = ValidationContext::new()
.with_num_validators(&mut rng, 3)
.with_past_blocks(&mut rng, 0, 5, 0.into())
.with_transactions(vec![deploy, transaction_v1])
.with_transactions(vec![transaction_v1])
.with_transfers(vec![transfer, transfer_v1])
.include_all_transactions()
.include_all_transfers();
Expand Down Expand Up @@ -1253,7 +1251,6 @@ async fn should_validate_with_delayed_block() {
let mut rng = TestRng::new();
let ttl = TimeDiff::from_millis(200);
let timestamp = Timestamp::from(1000);
let deploy = new_deploy(&mut rng, timestamp, ttl);
let transaction_v1 = new_v1_standard(&mut rng, timestamp, ttl);
let transfer = new_transfer(&mut rng, timestamp, ttl);
let transfer_v1 = new_v1_transfer(&mut rng, timestamp, ttl);
Expand All @@ -1262,7 +1259,7 @@ async fn should_validate_with_delayed_block() {
.with_num_validators(&mut rng, 3)
.with_past_blocks(&mut rng, 0, 4, 0.into())
.with_delayed_blocks(&mut rng, 5, 5, 0.into())
.with_transactions(vec![deploy, transaction_v1])
.with_transactions(vec![transaction_v1])
.with_transfers(vec![transfer, transfer_v1])
.include_all_transactions()
.include_all_transfers();
Expand Down

0 comments on commit ccf7cf7

Please sign in to comment.