Skip to content

Commit

Permalink
fix: make test_validate_chunk_extra work with stateless validation (#…
Browse files Browse the repository at this point in the history
…10603)

This test didn't work with stateless validation.
It manually creates a chunk and blocks containing this chunk, but it
didn't set the `chunk_endorsements` field in the blocks, because of
which the blocks couldn't be accepted.
Let's fix it by generating the correct chunk endoresment and setting the
field in the generated blocks.

Refs: #10506
  • Loading branch information
jancionear authored Feb 13, 2024
1 parent 61cec49 commit 9274cd6
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions integration-tests/src/tests/client/process_blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ use near_primitives::shard_layout::{get_block_shard_uid, ShardUId};
use near_primitives::sharding::{ShardChunkHeader, ShardChunkHeaderInner, ShardChunkHeaderV3};
use near_primitives::state_part::PartId;
use near_primitives::state_sync::StatePartKey;
use near_primitives::stateless_validation::ChunkEndorsement;
use near_primitives::test_utils::create_test_signer;
use near_primitives::test_utils::TestBlockBuilder;
use near_primitives::transaction::{
Expand All @@ -60,7 +61,6 @@ use near_primitives::version::PROTOCOL_VERSION;
use near_primitives::views::{
BlockHeaderView, FinalExecutionStatus, QueryRequest, QueryResponseKind,
};
use near_primitives_core::checked_feature;
use near_primitives_core::num_rational::{Ratio, Rational32};
use near_primitives_core::types::ShardId;
use near_store::cold_storage::{update_cold_db, update_cold_head};
Expand Down Expand Up @@ -2158,11 +2158,6 @@ fn test_block_height_processed_orphan() {

#[test]
fn test_validate_chunk_extra() {
// TODO(#10506): Fix test to handle stateless validation
if checked_feature!("stable", StatelessValidationV0, PROTOCOL_VERSION) {
return;
}

let mut capture = near_o11y::testonly::TracingCapture::enable();

let epoch_length = 5;
Expand Down Expand Up @@ -2237,7 +2232,7 @@ fn test_validate_chunk_extra() {
for (i, block) in vec![&mut block1, &mut block2].into_iter().enumerate() {
let mut chunk_header = encoded_chunk.cloned_header();
*chunk_header.height_included_mut() = i as BlockHeight + next_height;
let chunk_headers = vec![chunk_header];
let chunk_headers = vec![chunk_header.clone()];
block.set_chunks(chunk_headers.clone());
block.mut_header().get_mut().inner_rest.chunk_headers_root =
Block::compute_chunk_headers_root(&chunk_headers).0;
Expand All @@ -2250,6 +2245,8 @@ fn test_validate_chunk_extra() {
block.mut_header().get_mut().inner_rest.chunk_mask = vec![true];
block.mut_header().get_mut().inner_lite.prev_outcome_root =
Block::compute_outcome_root(block.chunks().iter());
let endorsement = ChunkEndorsement::new(chunk_header.chunk_hash(), &validator_signer);
block.set_chunk_endorsements(vec![vec![Some(Box::new(endorsement.signature))]]);
block.mut_header().get_mut().inner_rest.block_body_hash =
block.compute_block_body_hash().unwrap();
block.mut_header().resign(&validator_signer);
Expand Down

0 comments on commit 9274cd6

Please sign in to comment.