This repository has been archived by the owner on Aug 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(execution)!: pre_process_block refactor for full_nodes simul…
…ate transaction (#1387)
- Loading branch information
1 parent
38e81df
commit 344d0ba
Showing
8 changed files
with
168 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,68 @@ | ||
use starknet_api::block::BlockNumber; | ||
use starknet_api::core::ContractAddress; | ||
use starknet_api::hash::StarkFelt; | ||
use starknet_api::state::StorageKey; | ||
|
||
use crate::abi::constants; | ||
use crate::block::{pre_process_block, BlockNumberHashPair}; | ||
use crate::block::{pre_process_block, BlockInfo, BlockNumberHashPair}; | ||
use crate::context::ChainInfo; | ||
use crate::state::state_api::StateReader; | ||
use crate::test_utils::cached_state::create_test_state; | ||
use crate::versioned_constants::VersionedConstants; | ||
|
||
#[test] | ||
fn test_pre_process_block() { | ||
let mut state = create_test_state(); | ||
|
||
let block_number: u64 = 10; | ||
// Test the positive flow of pre_process_block inside the allowed block number interval | ||
let block_number = constants::STORED_BLOCK_HASH_BUFFER; | ||
let block_hash = StarkFelt::from(20_u8); | ||
pre_process_block(&mut state, Some(BlockNumberHashPair::new(block_number, block_hash))) | ||
.unwrap(); | ||
let mut block_info = BlockInfo::create_for_testing(); | ||
block_info.block_number = BlockNumber(block_number); | ||
pre_process_block( | ||
&mut state, | ||
Some(BlockNumberHashPair::new(block_number, block_hash)), | ||
block_info, | ||
ChainInfo::default(), | ||
VersionedConstants::default(), | ||
) | ||
.unwrap(); | ||
|
||
let written_hash = state.get_storage_at( | ||
ContractAddress::try_from(StarkFelt::from(constants::BLOCK_HASH_CONTRACT_ADDRESS)).unwrap(), | ||
StorageKey::try_from(StarkFelt::from(block_number)).unwrap(), | ||
ContractAddress::from(constants::BLOCK_HASH_CONTRACT_ADDRESS), | ||
StorageKey::from(block_number), | ||
); | ||
assert_eq!(written_hash.unwrap(), block_hash); | ||
|
||
// Test that block pre-process with block hash None is successful only within the allowed | ||
// block number interval. | ||
let mut block_info = BlockInfo::create_for_testing(); | ||
block_info.block_number = BlockNumber(constants::STORED_BLOCK_HASH_BUFFER - 1); | ||
assert!( | ||
pre_process_block( | ||
&mut state, | ||
None, | ||
block_info, | ||
ChainInfo::default(), | ||
VersionedConstants::default() | ||
) | ||
.is_ok() | ||
); | ||
|
||
let mut block_info = BlockInfo::create_for_testing(); | ||
block_info.block_number = BlockNumber(constants::STORED_BLOCK_HASH_BUFFER); | ||
let error = pre_process_block( | ||
&mut state, | ||
None, | ||
block_info, | ||
ChainInfo::default(), | ||
VersionedConstants::default(), | ||
); | ||
assert_eq!( | ||
format!( | ||
"A block hash must be provided for block number > {}.", | ||
constants::STORED_BLOCK_HASH_BUFFER | ||
), | ||
format!("{}", error.unwrap_err()) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.