-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(starknet_patricia,starknet_committer): stop using custom Contrac…
…tAddress type
- Loading branch information
1 parent
c654b17
commit c211f84
Showing
18 changed files
with
135 additions
and
81 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
25 changes: 18 additions & 7 deletions
25
crates/starknet_committer/src/block_committer/input_test.rs
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,25 +1,36 @@ | ||
use rstest::rstest; | ||
use starknet_api::core::ContractAddress; | ||
use starknet_patricia::patricia_merkle_tree::types::NodeIndex; | ||
use starknet_types_core::felt::Felt; | ||
|
||
use crate::block_committer::input::ContractAddress; | ||
use crate::block_committer::input::try_from_node_index_for_contract_address; | ||
|
||
#[rstest] | ||
fn test_node_index_to_contract_address_conversion() { | ||
// Positive flow. | ||
assert_eq!(ContractAddress::try_from(&NodeIndex::FIRST_LEAF), Ok(ContractAddress(Felt::ZERO))); | ||
assert_eq!( | ||
ContractAddress::try_from(&(NodeIndex::FIRST_LEAF + NodeIndex(1_u32.into()))), | ||
Ok(ContractAddress(Felt::ONE)) | ||
try_from_node_index_for_contract_address(&NodeIndex::FIRST_LEAF), | ||
Ok(ContractAddress::try_from(Felt::ZERO).unwrap()) | ||
); | ||
assert_eq!( | ||
ContractAddress::try_from(&NodeIndex::MAX), | ||
Ok(ContractAddress(Felt::try_from(NodeIndex::MAX - NodeIndex::FIRST_LEAF).unwrap())) | ||
try_from_node_index_for_contract_address( | ||
&(NodeIndex::FIRST_LEAF + NodeIndex(1_u32.into())) | ||
), | ||
Ok(ContractAddress::try_from(Felt::ONE).unwrap()) | ||
); | ||
assert_eq!( | ||
try_from_node_index_for_contract_address(&NodeIndex::MAX), | ||
Ok(ContractAddress::try_from( | ||
Felt::try_from(NodeIndex::MAX - NodeIndex::FIRST_LEAF).unwrap() | ||
) | ||
.unwrap()) | ||
); | ||
|
||
// Negative flow. | ||
assert_eq!( | ||
ContractAddress::try_from(&(NodeIndex::FIRST_LEAF - NodeIndex(1_u32.into()))), | ||
try_from_node_index_for_contract_address( | ||
&(NodeIndex::FIRST_LEAF - NodeIndex(1_u32.into())) | ||
), | ||
Err("NodeIndex is not a leaf.".to_string()) | ||
); | ||
} |
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.