-
Notifications
You must be signed in to change notification settings - Fork 51
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
base: main
Are you sure you want to change the base?
Conversation
e400da9
to
6b9d8ec
Compare
6b9d8ec
to
da627d1
Compare
let _ = importer | ||
.add_block(block, BlockValidationContext::new(chain_config.chain_id.clone()).trust_class_hashes(true)) | ||
.await; |
There was a problem hiding this comment.
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?
#[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 }, | ||
], | ||
} | ||
} |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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"); |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto
Pull Request type
Please add the labels corresponding to the type of changes your PR introduces:
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!