Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(block_production): Add tests to block_production_task method #478

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

GMKrieger
Copy link

Pull Request type

Please add the labels corresponding to the type of changes your PR introduces:

  • Testing

What is the current behavior?

Resolves: #NA

The block production tests currently only test block sealing when starting a new service.

What is the new behavior?

This PR aims to add tests on the block_production_task method and related methods to thoroughly test the code.

Does this introduce a breaking change?

No.

Other information

The testing format is based on #468. All feedback is welcome!

@GMKrieger GMKrieger added the testing Related to tests and test infrastructure label Jan 24, 2025
@GMKrieger GMKrieger self-assigned this Jan 24, 2025
@GMKrieger GMKrieger force-pushed the test/block-production-tests branch 2 times, most recently from e400da9 to 6b9d8ec Compare January 29, 2025 21:13
@GMKrieger GMKrieger force-pushed the test/block-production-tests branch from 6b9d8ec to da627d1 Compare January 30, 2025 20:48
@GMKrieger GMKrieger marked this pull request as ready for review January 30, 2025 20:48
Comment on lines +726 to +728
let _ = importer
.add_block(block, BlockValidationContext::new(chain_config.chain_id.clone()).trust_class_hashes(true))
.await;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably should expect this here no?

Comment on lines +884 to +926
#[rstest::fixture]
fn pending_block_state_diff() -> StateDiff {
StateDiff {
storage_diffs: vec![
ContractStorageDiffItem {
address: Felt::ONE,
storage_entries: vec![
StorageEntry { key: Felt::ZERO, value: Felt::ZERO },
StorageEntry { key: Felt::ONE, value: Felt::ONE },
StorageEntry { key: Felt::TWO, value: Felt::TWO },
],
},
ContractStorageDiffItem {
address: Felt::TWO,
storage_entries: vec![
StorageEntry { key: Felt::ZERO, value: Felt::ZERO },
StorageEntry { key: Felt::ONE, value: Felt::ONE },
StorageEntry { key: Felt::TWO, value: Felt::TWO },
],
},
ContractStorageDiffItem {
address: Felt::THREE,
storage_entries: vec![
StorageEntry { key: Felt::ZERO, value: Felt::ZERO },
StorageEntry { key: Felt::ONE, value: Felt::ONE },
StorageEntry { key: Felt::TWO, value: Felt::TWO },
],
},
],
deprecated_declared_classes: vec![Felt::ZERO],
declared_classes: vec![
DeclaredClassItem { class_hash: Felt::ONE, compiled_class_hash: Felt::ONE },
DeclaredClassItem { class_hash: Felt::TWO, compiled_class_hash: Felt::TWO },
],
deployed_contracts: vec![DeployedContractItem { address: Felt::THREE, class_hash: Felt::THREE }],
replaced_classes: vec![ReplacedClassItem { contract_address: Felt::TWO, class_hash: Felt::TWO }],
nonces: vec![
NonceUpdate { contract_address: Felt::ONE, nonce: Felt::ONE },
NonceUpdate { contract_address: Felt::TWO, nonce: Felt::TWO },
NonceUpdate { contract_address: Felt::THREE, nonce: Felt::THREE },
],
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure its a good idea to have a fixture for the pending block state diff as this is very subject to change depending on the test we are running. Imo this is too specific and we should probably be defining this on a per-test basis. Wdyt?

};
*tx_signature = vec![signature.r, signature.s];

let _ = mempool.tx_accept_invoke(invoke_txn);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably expect this too.

};
*tx_signature = vec![signature.r, signature.s];

let _ = mempool.tx_accept_declare(declare_txn);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expect

#[rstest::rstest]
#[tokio::test]
#[allow(clippy::too_many_arguments)]
async fn test_block_prod_on_pending_block_tick_block_still_pending(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add a doc comment with an overview of what this does?

#[rstest::rstest]
#[tokio::test]
#[allow(clippy::too_many_arguments)]
async fn test_block_prod_start_block_production_task_normal_setup(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto

#[rstest::rstest]
#[tokio::test]
#[allow(clippy::too_many_arguments)]
async fn test_block_prod_start_block_production_task_pending_tick_too_small(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto

let result =
block_production_task.block_production_task(mp_utils::service::ServiceContext::new_for_testing()).await;

assert!(result.is_err(), "Expected an error due to very small pending block time");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to check the exact type of the error here?

#[rstest::rstest]
#[tokio::test]
#[allow(clippy::too_many_arguments)]
async fn test_block_prod_start_block_production_task_closes_block_right_after_pending(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto

#[rstest::rstest]
#[tokio::test]
#[allow(clippy::too_many_arguments)]
async fn test_block_prod_start_block_production_task_ungracious_shutdown_and_restart(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
testing Related to tests and test infrastructure
Projects
Status: In review
Development

Successfully merging this pull request may close these issues.

2 participants