Skip to content

Add test to cover error branches of LiveCollector::execute_and_store_block_updates #436

@emhane

Description

@emhane

Describe the feature

Integration test exist for LiveCollector::execute_and_store_block_updates

/// End-to-end test of a single live collector iteration.
/// (1) Creates a chain with some state
/// (2) Stores the genesis state into storage via backfill
/// (3) Executes a block and calculates the state root using the stored state
#[tokio::test]
async fn test_execute_and_store_block_updates() {
let storage = Arc::new(InMemoryProofsStorage::new()).into();
// Create a keypair for signing transactions
let secp = Secp256k1::new();
let key_pair = Keypair::new(&secp, &mut thread_rng());
let sender = public_key_to_address(key_pair.public_key());
// Create chain spec with the sender address funded in genesis
let chain_spec = chain_spec_with_address(sender);
// Create test database and provider factory
let provider_factory = create_test_provider_factory_with_chain_spec(chain_spec.clone());
// Insert genesis state into the database
init_genesis(&provider_factory).unwrap();
// Define the test scenario:
// - No blocks before backfill
// - Backfill to genesis (block 0)
// - Execute one block with a single transaction after backfill
let recipient = Address::repeat_byte(0x42);
let scenario = TestScenario::new(
vec![],
vec![BlockSpec::new(vec![TxSpec::transfer(recipient, U256::from(1))])],
);
run_test_scenario(scenario, provider_factory, chain_spec, key_pair, storage).await.unwrap();
}

Duplicate that test code to add tests to cover the error paths
if parent_block_number > latest {
return Err(OpProofsStorageError::MissingParentBlock {
block_number: block.number(),
parent_block_number,
latest_block_number: latest,
}
.into());
}

and
if state_root != block.state_root() {
return Err(OpProofsStorageError::StateRootMismatch {
block_number: block.number(),
current_state_hash: state_root,
expected_state_hash: block.state_root(),
}
.into());
}

Additional context

No response

Metadata

Metadata

Assignees

Labels

A-trieArea: Merkle Patricia TrieK-testKind: testM-good-first-issueMeta: good issue for first time contributorsW-historical-proofsWorkstream: historical-proofs

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions