|
| 1 | +use std::{path::PathBuf, str::FromStr}; |
| 2 | + |
| 3 | +use crate::{ |
| 4 | + assert_result, |
| 5 | + utils::{ |
| 6 | + v7::{ |
| 7 | + accounts::account::{Account, ConnectedAccount}, |
| 8 | + endpoints::{ |
| 9 | + declare_contract::get_compiled_contract, errors::OpenRpcTestGenError, |
| 10 | + utils::wait_for_sent_transaction, |
| 11 | + }, |
| 12 | + providers::provider::Provider, |
| 13 | + }, |
| 14 | + v8::types::MerkleTree, |
| 15 | + }, |
| 16 | + RandomizableAccountsTrait, RunnableTrait, |
| 17 | +}; |
| 18 | +use starknet_types_core::hash::{Poseidon, StarkHash}; |
| 19 | +use starknet_types_rpc::{BlockId, BlockTag}; |
| 20 | + |
| 21 | +#[derive(Clone, Debug)] |
| 22 | +pub struct TestCase {} |
| 23 | + |
| 24 | +impl RunnableTrait for TestCase { |
| 25 | + type Input = super::TestSuiteOpenRpc; |
| 26 | + |
| 27 | + async fn run(test_input: &Self::Input) -> Result<Self, OpenRpcTestGenError> { |
| 28 | + let (flattened_sierra_class, compiled_class_hash) = get_compiled_contract( |
| 29 | + PathBuf::from_str( |
| 30 | + "target/dev/contracts_contracts_smpl20_HelloStarknet.contract_class.json", |
| 31 | + )?, |
| 32 | + PathBuf::from_str( |
| 33 | + "target/dev/contracts_contracts_smpl20_HelloStarknet.compiled_contract_class.json", |
| 34 | + )?, |
| 35 | + ) |
| 36 | + .await?; |
| 37 | + |
| 38 | + let sender = test_input.random_paymaster_account.random_accounts()?; |
| 39 | + |
| 40 | + let declare_result = sender |
| 41 | + .declare_v3(flattened_sierra_class, compiled_class_hash) |
| 42 | + .send() |
| 43 | + .await?; |
| 44 | + |
| 45 | + wait_for_sent_transaction( |
| 46 | + declare_result.transaction_hash, |
| 47 | + &test_input.random_paymaster_account.random_accounts()?, |
| 48 | + ) |
| 49 | + .await?; |
| 50 | + |
| 51 | + let storage_proof = test_input |
| 52 | + .random_paymaster_account |
| 53 | + .provider() |
| 54 | + .get_storage_proof( |
| 55 | + BlockId::Tag(BlockTag::Latest), |
| 56 | + Some(vec![declare_result.class_hash]), |
| 57 | + None, |
| 58 | + None, |
| 59 | + ) |
| 60 | + .await?; |
| 61 | + |
| 62 | + let merkle_tree = MerkleTree::from_proof( |
| 63 | + storage_proof.classes_proof, |
| 64 | + Some(storage_proof.global_roots.classes_tree_root), |
| 65 | + ); |
| 66 | + |
| 67 | + let expected_child = |
| 68 | + merkle_tree.compute_expected_child_for_class_proof(&compiled_class_hash); |
| 69 | + let valid_proof = merkle_tree.verify_proof(&expected_child, Poseidon::hash)?; |
| 70 | + assert_result!(valid_proof, "Class proof verification failed"); |
| 71 | + |
| 72 | + Ok(Self {}) |
| 73 | + } |
| 74 | +} |
0 commit comments