Skip to content

Commit

Permalink
test(blockifier): add from file trait
Browse files Browse the repository at this point in the history
  • Loading branch information
aner-starkware authored and noaov1 committed Oct 31, 2024
1 parent c82604f commit 34599b9
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 11 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions crates/blockifier/src/test_utils/struct_impls.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use std::sync::Arc;

use cairo_lang_starknet_classes::casm_contract_class::CasmContractClass;
use cairo_vm::vm::runners::cairo_runner::ExecutionResources;
use serde_json::Value;
use starknet_api::block::{BlockNumber, BlockTimestamp, NonzeroGasPrice};
use starknet_api::core::{ChainId, ClassHash, ContractAddress, Nonce, PatriciaKey};
use starknet_api::deprecated_contract_class::ContractClass as DeprecatedContractClass;
use starknet_api::transaction::{Fee, TransactionHash, TransactionVersion};
use starknet_api::{calldata, contract_address, patricia_key};
use starknet_types_core::felt::Felt;
Expand Down Expand Up @@ -210,6 +212,24 @@ impl CallExecution {

// Contract loaders.

pub trait LoadFile {
fn from_file(contract_path: &str) -> Self;
}

impl LoadFile for DeprecatedContractClass {
fn from_file(contract_path: &str) -> Self {
let raw_contract_class = get_raw_contract_class(contract_path);
serde_json::from_str(&raw_contract_class).unwrap()
}
}

impl LoadFile for CasmContractClass {
fn from_file(contract_path: &str) -> Self {
let raw_contract_class = get_raw_contract_class(contract_path);
serde_json::from_str(&raw_contract_class).unwrap()
}
}

impl ContractClassV0 {
pub fn from_file(contract_path: &str) -> Self {
let raw_contract_class = get_raw_contract_class(contract_path);
Expand Down
38 changes: 28 additions & 10 deletions crates/blockifier_reexecution/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,35 @@ pub struct BlockifierReexecutionCliArgs {
command: Command,
}

#[derive(Args, Debug)]
struct SharedArgs {
/// Node url.
/// Default: https://free-rpc.nethermind.io/mainnet-juno/. Won't work for big tests.
#[clap(long, short = 'n', default_value = "https://free-rpc.nethermind.io/mainnet-juno/")]
node_url: String,

/// Block number.
#[clap(long, short = 'b')]
block_number: u64,
}

#[derive(Debug, Subcommand)]
enum Command {
/// Runs the RPC test.
RpcTest {
/// Node url.
/// Default: https://free-rpc.nethermind.io/mainnet-juno/. Won't work for big tests.
#[clap(long, short = 'n', default_value = "https://free-rpc.nethermind.io/mainnet-juno/")]
node_url: String,

/// Block number.
#[clap(long, short = 'b')]
block_number: u64,
#[clap(flatten)]
url_and_block_number: SharedArgs,
},

/// Writes the RPC queries to json files.
WriteRpcRepliesToJson {
#[clap(flatten)]
url_and_block_number: SharedArgs,

/// Directory path to json files.
/// Default: "./crates/blockifier_reexecution/resources/block_{block_number}".
#[clap(long, default_value = None)]
directory_path: Option<String>,
},
}

Expand All @@ -43,8 +60,8 @@ fn main() {
let args = BlockifierReexecutionCliArgs::parse();

match args.command {
Command::RpcTest { node_url, block_number } => {
println!("Running RPC test for block number {block_number} using node url {node_url}.");
Command::RpcTest { url_and_block_number: SharedArgs { node_url, block_number } } => {
println!("Running RPC test for block number {block_number} using node url {node_url}.",);

let config = RpcStateReaderConfig {
url: node_url,
Expand Down Expand Up @@ -73,5 +90,6 @@ fn main() {

println!("RPC test passed successfully.");
}
Command::WriteRpcRepliesToJson { .. } => todo!(),
}
}

0 comments on commit 34599b9

Please sign in to comment.