-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #272 from neotheprogramist/v8-get-storage-proof
V8 get storage proof tests
- Loading branch information
Showing
18 changed files
with
1,117 additions
and
6 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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#[starknet::interface] | ||
pub trait IHelloStarknet<TContractState> { | ||
fn increase_balance(ref self: TContractState, amount: felt252); | ||
fn get_balance(self: @TContractState) -> felt252; | ||
} | ||
|
||
#[starknet::contract] | ||
mod HelloStarknet { | ||
use starknet::storage::Map; | ||
|
||
#[storage] | ||
struct Storage { | ||
balance: felt252, | ||
balances: Map<felt252, felt252>, | ||
another_arg11: felt252, | ||
} | ||
|
||
#[event] | ||
#[derive(Drop, starknet::Event)] | ||
enum Event { | ||
DepositFromL1: DepositFromL1, | ||
} | ||
|
||
#[derive(Drop, starknet::Event)] | ||
struct DepositFromL1 { | ||
#[key] | ||
user: felt252, | ||
#[key] | ||
amount: felt252, | ||
} | ||
|
||
#[l1_handler] | ||
fn deposit(ref self: ContractState, from_address: felt252, user: felt252, amount: felt252) { | ||
let balance = self.balances.read(user); | ||
self.balances.write(user, balance + amount); | ||
self.emit(DepositFromL1 { user, amount }); | ||
} | ||
|
||
#[abi(embed_v0)] | ||
impl HelloStarknetImpl of super::IHelloStarknet<ContractState> { | ||
fn increase_balance(ref self: ContractState, amount: felt252) { | ||
self.balance.write(self.balance.read() + amount); | ||
} | ||
|
||
fn get_balance(self: @ContractState) -> felt252 { | ||
self.balance.read() | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#[starknet::interface] | ||
pub trait IHelloStarknet<TContractState> { | ||
fn increase_balance(ref self: TContractState, amount: felt252); | ||
fn get_balance(self: @TContractState) -> felt252; | ||
} | ||
|
||
#[starknet::contract] | ||
mod HelloStarknet { | ||
use starknet::storage::Map; | ||
|
||
#[storage] | ||
struct Storage { | ||
balance: felt252, | ||
balances: Map<felt252, felt252>, | ||
another_arg12: felt252, | ||
} | ||
|
||
#[event] | ||
#[derive(Drop, starknet::Event)] | ||
enum Event { | ||
DepositFromL1: DepositFromL1, | ||
} | ||
|
||
#[derive(Drop, starknet::Event)] | ||
struct DepositFromL1 { | ||
#[key] | ||
user: felt252, | ||
#[key] | ||
amount: felt252, | ||
} | ||
|
||
#[l1_handler] | ||
fn deposit(ref self: ContractState, from_address: felt252, user: felt252, amount: felt252) { | ||
let balance = self.balances.read(user); | ||
self.balances.write(user, balance + amount); | ||
self.emit(DepositFromL1 { user, amount }); | ||
} | ||
|
||
#[abi(embed_v0)] | ||
impl HelloStarknetImpl of super::IHelloStarknet<ContractState> { | ||
fn increase_balance(ref self: ContractState, amount: felt252) { | ||
self.balance.write(self.balance.read() + amount); | ||
} | ||
|
||
fn get_balance(self: @ContractState) -> felt252 { | ||
self.balance.read() | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#[starknet::interface] | ||
pub trait IHelloStarknet<TContractState> { | ||
fn increase_balance(ref self: TContractState, amount: felt252); | ||
fn get_balance(self: @TContractState) -> felt252; | ||
} | ||
|
||
#[starknet::contract] | ||
mod HelloStarknet { | ||
use starknet::storage::Map; | ||
|
||
#[storage] | ||
struct Storage { | ||
balance: felt252, | ||
balances: Map<felt252, felt252>, | ||
another_arg13: felt252, | ||
} | ||
|
||
#[event] | ||
#[derive(Drop, starknet::Event)] | ||
enum Event { | ||
DepositFromL1: DepositFromL1, | ||
} | ||
|
||
#[derive(Drop, starknet::Event)] | ||
struct DepositFromL1 { | ||
#[key] | ||
user: felt252, | ||
#[key] | ||
amount: felt252, | ||
} | ||
|
||
#[l1_handler] | ||
fn deposit(ref self: ContractState, from_address: felt252, user: felt252, amount: felt252) { | ||
let balance = self.balances.read(user); | ||
self.balances.write(user, balance + amount); | ||
self.emit(DepositFromL1 { user, amount }); | ||
} | ||
|
||
#[abi(embed_v0)] | ||
impl HelloStarknetImpl of super::IHelloStarknet<ContractState> { | ||
fn increase_balance(ref self: ContractState, amount: felt252) { | ||
self.balance.write(self.balance.read() + amount); | ||
} | ||
|
||
fn get_balance(self: @ContractState) -> felt252 { | ||
self.balance.read() | ||
} | ||
} | ||
} |
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
74 changes: 74 additions & 0 deletions
74
openrpc-testgen/src/suite_openrpc/test_get_storage_class_proof.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 |
---|---|---|
@@ -0,0 +1,74 @@ | ||
use std::{path::PathBuf, str::FromStr}; | ||
|
||
use crate::{ | ||
assert_result, | ||
utils::{ | ||
v7::{ | ||
accounts::account::{Account, ConnectedAccount}, | ||
endpoints::{ | ||
declare_contract::get_compiled_contract, errors::OpenRpcTestGenError, | ||
utils::wait_for_sent_transaction, | ||
}, | ||
providers::provider::Provider, | ||
}, | ||
v8::types::MerkleTree, | ||
}, | ||
RandomizableAccountsTrait, RunnableTrait, | ||
}; | ||
use starknet_types_core::hash::{Poseidon, StarkHash}; | ||
use starknet_types_rpc::{BlockId, BlockTag}; | ||
|
||
#[derive(Clone, Debug)] | ||
pub struct TestCase {} | ||
|
||
impl RunnableTrait for TestCase { | ||
type Input = super::TestSuiteOpenRpc; | ||
|
||
async fn run(test_input: &Self::Input) -> Result<Self, OpenRpcTestGenError> { | ||
let (flattened_sierra_class, compiled_class_hash) = get_compiled_contract( | ||
PathBuf::from_str( | ||
"target/dev/contracts_contracts_smpl20_HelloStarknet.contract_class.json", | ||
)?, | ||
PathBuf::from_str( | ||
"target/dev/contracts_contracts_smpl20_HelloStarknet.compiled_contract_class.json", | ||
)?, | ||
) | ||
.await?; | ||
|
||
let sender = test_input.random_paymaster_account.random_accounts()?; | ||
|
||
let declare_result = sender | ||
.declare_v3(flattened_sierra_class, compiled_class_hash) | ||
.send() | ||
.await?; | ||
|
||
wait_for_sent_transaction( | ||
declare_result.transaction_hash, | ||
&test_input.random_paymaster_account.random_accounts()?, | ||
) | ||
.await?; | ||
|
||
let storage_proof = test_input | ||
.random_paymaster_account | ||
.provider() | ||
.get_storage_proof( | ||
BlockId::Tag(BlockTag::Latest), | ||
Some(vec![declare_result.class_hash]), | ||
None, | ||
None, | ||
) | ||
.await?; | ||
|
||
let merkle_tree = MerkleTree::from_proof( | ||
storage_proof.classes_proof, | ||
Some(storage_proof.global_roots.classes_tree_root), | ||
); | ||
|
||
let expected_child = | ||
merkle_tree.compute_expected_child_for_class_proof(&compiled_class_hash); | ||
let valid_proof = merkle_tree.verify_proof(&expected_child, Poseidon::hash)?; | ||
assert_result!(valid_proof, "Class proof verification failed"); | ||
|
||
Ok(Self {}) | ||
} | ||
} |
Oops, something went wrong.