Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Commit

Permalink
Merge branch 'main' into fix-fee-transfer-failure
Browse files Browse the repository at this point in the history
  • Loading branch information
MegaRedHand committed Jul 6, 2023
2 parents 04985fa + 996bb68 commit 96d88fa
Show file tree
Hide file tree
Showing 38 changed files with 217 additions and 315 deletions.
7 changes: 3 additions & 4 deletions bench/internals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@ use starknet_in_rust::{
transaction::{declare::Declare, Deploy, DeployAccount, InvokeFunction},
utils::Address,
};
use std::{fs::File, hint::black_box, io::BufReader};
use std::hint::black_box;

lazy_static! {
// include_str! doesn't seem to work in CI
static ref CONTRACT_CLASS: ContractClass = ContractClass::try_from(BufReader::new(File::open(
static ref CONTRACT_CLASS: ContractClass = ContractClass::from_path(
"starknet_programs/account_without_validation.json",
).unwrap()))
.unwrap();
).unwrap();
static ref CLASS_HASH: Felt252 = compute_deprecated_class_hash(&CONTRACT_CLASS).unwrap();
static ref CLASS_HASH_BYTES: [u8; 32] = CLASS_HASH.clone().to_be_bytes();
static ref SALT: Felt252 = felt_str!(
Expand Down
2 changes: 1 addition & 1 deletion cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ fn declare_parser(
args: &DeclareArgs,
) -> Result<(Felt252, Felt252), ParserError> {
let contract_class =
ContractClass::try_from(&args.contract).map_err(ContractAddressError::Program)?;
ContractClass::from_path(&args.contract).map_err(ContractAddressError::Program)?;
let class_hash = compute_deprecated_class_hash(&contract_class)?;
cached_state.set_contract_class(&felt_to_hash(&class_hash), &contract_class)?;

Expand Down
4 changes: 2 additions & 2 deletions examples/contract_execution/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ fn test_contract(
//* --------------------------------------------
//* Read contract from file
//* --------------------------------------------
let contract_class = ContractClass::try_from(contract_path.as_ref().to_path_buf())
.expect("Could not load contract from JSON");
let contract_class =
ContractClass::from_path(contract_path).expect("Could not load contract from JSON");

//* --------------------------------------------
//* Declare new contract class
Expand Down
2 changes: 1 addition & 1 deletion fuzzer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ fn main() {
// ---------------------------------------------------------

let path = PathBuf::from(&json_file_name);
let contract_class = ContractClass::try_from(path).unwrap();
let contract_class = ContractClass::from_path(path).unwrap();

let storage_entrypoint_selector = contract_class
.entry_points_by_type()
Expand Down
6 changes: 2 additions & 4 deletions src/bin/deploy.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::path::PathBuf;

use lazy_static::lazy_static;
use starknet_in_rust::{
services::api::contract_classes::deprecated_contract_class::ContractClass,
Expand All @@ -15,9 +13,9 @@ static ALLOC: MiMalloc = MiMalloc;

lazy_static! {
// include_str! doesn't seem to work in CI
static ref CONTRACT_CLASS: ContractClass = ContractClass::try_from(PathBuf::from(
static ref CONTRACT_CLASS: ContractClass = ContractClass::from_path(
"starknet_programs/first_contract.json",
)).unwrap();
).unwrap();
}

fn main() {
Expand Down
4 changes: 2 additions & 2 deletions src/bin/deploy_invoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ static ALLOC: MiMalloc = MiMalloc;

lazy_static! {
// include_str! doesn't seem to work in CI
static ref CONTRACT_CLASS: ContractClass = ContractClass::try_from(PathBuf::from(
static ref CONTRACT_CLASS: ContractClass = ContractClass::from_path(
"starknet_programs/first_contract.json",
)).unwrap();
).unwrap();

static ref CONTRACT_PATH: PathBuf = PathBuf::from("starknet_programs/first_contract.json");

Expand Down
4 changes: 2 additions & 2 deletions src/bin/fibonacci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ static ALLOC: MiMalloc = MiMalloc;

lazy_static! {
// include_str! doesn't seem to work in CI
static ref CONTRACT_CLASS: ContractClass = ContractClass::try_from(PathBuf::from(
static ref CONTRACT_CLASS: ContractClass = ContractClass::from_path(
"starknet_programs/fibonacci.json",
)).unwrap();
).unwrap();

static ref CONTRACT_PATH: PathBuf = PathBuf::from("starknet_programs/fibonacci.json");

Expand Down
4 changes: 2 additions & 2 deletions src/bin/invoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ static ALLOC: MiMalloc = MiMalloc;

lazy_static! {
// include_str! doesn't seem to work in CI
static ref CONTRACT_CLASS: ContractClass = ContractClass::try_from(PathBuf::from(
static ref CONTRACT_CLASS: ContractClass = ContractClass::from_path(
"starknet_programs/first_contract.json",
)).unwrap();
).unwrap();

static ref CONTRACT_PATH: PathBuf = PathBuf::from("starknet_programs/first_contract.json");

Expand Down
4 changes: 2 additions & 2 deletions src/bin/invoke_with_cachedstate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ static ALLOC: MiMalloc = MiMalloc;

lazy_static! {
// include_str! doesn't seem to work in CI
static ref CONTRACT_CLASS: ContractClass = ContractClass::try_from(PathBuf::from(
static ref CONTRACT_CLASS: ContractClass = ContractClass::from_path(
"starknet_programs/first_contract.json",
)).unwrap();
).unwrap();

static ref CONTRACT_PATH: PathBuf = PathBuf::from("starknet_programs/first_contract.json");

Expand Down
22 changes: 10 additions & 12 deletions src/core/contract_address/deprecated_contract_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,13 @@ fn get_contract_entry_points(
contract_class: &ContractClass,
entry_point_type: &EntryPointType,
) -> Result<Vec<ContractEntryPoint>, ContractAddressError> {
let program_length = contract_class.program().iter_data().count();

let entry_points = contract_class
.entry_points_by_type()
.get(entry_point_type)
.ok_or(ContractAddressError::NoneExistingEntryPointType)?;

let program_len = program_length;
let program_len = contract_class.program().iter_data().count();

for entry_point in entry_points {
if entry_point.offset() > program_len {
return Err(ContractAddressError::InvalidOffset(entry_point.offset()));
Expand Down Expand Up @@ -358,10 +357,9 @@ mod tests {

#[test]
fn test_compute_hinted_class_hash_with_abi() {
let contract_class = ContractClass::new_from_path(
"starknet_programs/raw_contract_classes/class_with_abi.json",
)
.unwrap();
let contract_class =
ContractClass::from_path("starknet_programs/raw_contract_classes/class_with_abi.json")
.unwrap();

assert_eq!(
contract_class.hinted_class_hash(),
Expand All @@ -375,7 +373,7 @@ mod tests {

#[test]
fn test_compute_class_hash_1354433237b0039baa138bf95b98fe4a8ae3df7ac4fd4d4845f0b41cd11bec4() {
let contract_class = ContractClass::new_from_path("starknet_programs/raw_contract_classes/0x1354433237b0039baa138bf95b98fe4a8ae3df7ac4fd4d4845f0b41cd11bec4.json").unwrap();
let contract_class = ContractClass::from_path("starknet_programs/raw_contract_classes/0x1354433237b0039baa138bf95b98fe4a8ae3df7ac4fd4d4845f0b41cd11bec4.json").unwrap();

assert_eq!(
compute_deprecated_class_hash(&contract_class).unwrap(),
Expand All @@ -390,7 +388,7 @@ mod tests {
#[test]
fn test_compute_class_hash_0x03131fa018d520a037686ce3efddeab8f28895662f019ca3ca18a626650f7d1e()
{
let contract_class = ContractClass::new_from_path("starknet_programs/raw_contract_classes/0x03131fa018d520a037686ce3efddeab8f28895662f019ca3ca18a626650f7d1e.json").unwrap();
let contract_class = ContractClass::from_path("starknet_programs/raw_contract_classes/0x03131fa018d520a037686ce3efddeab8f28895662f019ca3ca18a626650f7d1e.json").unwrap();

assert_eq!(
compute_deprecated_class_hash(&contract_class).unwrap(),
Expand All @@ -405,7 +403,7 @@ mod tests {
#[test]
fn test_compute_class_hash_0x025ec026985a3bf9d0cc1fe17326b245dfdc3ff89b8fde106542a3ea56c5a918()
{
let contract_class = ContractClass::new_from_path("starknet_programs/raw_contract_classes/0x025ec026985a3bf9d0cc1fe17326b245dfdc3ff89b8fde106542a3ea56c5a918.json").unwrap();
let contract_class = ContractClass::from_path("starknet_programs/raw_contract_classes/0x025ec026985a3bf9d0cc1fe17326b245dfdc3ff89b8fde106542a3ea56c5a918.json").unwrap();

assert_eq!(
compute_deprecated_class_hash(&contract_class).unwrap(),
Expand All @@ -420,7 +418,7 @@ mod tests {
#[test]
fn test_compute_class_hash_0x02c3348ad109f7f3967df6494b3c48741d61675d9a7915b265aa7101a631dc33()
{
let contract_class = ContractClass::new_from_path("starknet_programs/raw_contract_classes/0x02c3348ad109f7f3967df6494b3c48741d61675d9a7915b265aa7101a631dc33.json").unwrap();
let contract_class = ContractClass::from_path("starknet_programs/raw_contract_classes/0x02c3348ad109f7f3967df6494b3c48741d61675d9a7915b265aa7101a631dc33.json").unwrap();

assert_eq!(
compute_deprecated_class_hash(&contract_class).unwrap(),
Expand All @@ -437,7 +435,7 @@ mod tests {
#[test]
fn test_compute_class_hash_0x00801ad5dc7c995addf7fbce1c4c74413586acb44f9ff44ba903a08a6153fa80()
{
let contract_class = ContractClass::new_from_path("starknet_programs/raw_contract_classes/0x00801ad5dc7c995addf7fbce1c4c74413586acb44f9ff44ba903a08a6153fa80.json").unwrap();
let contract_class = ContractClass::from_path("starknet_programs/raw_contract_classes/0x00801ad5dc7c995addf7fbce1c4c74413586acb44f9ff44ba903a08a6153fa80.json").unwrap();

assert_eq!(
compute_deprecated_class_hash(&contract_class).unwrap(),
Expand Down
22 changes: 9 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use crate::{
transaction::{error::TransactionError, Transaction},
};

use cairo_vm::felt::Felt252;
use definitions::block_context::BlockContext;
use state::cached_state::CachedState;
use transaction::L1Handler;
Expand All @@ -31,7 +32,7 @@ pub use crate::services::api::contract_classes::deprecated_contract_class::{
pub use cairo_lang_starknet::casm_contract_class::CasmContractClass;
pub use cairo_lang_starknet::contract_class::ContractClass;
pub use cairo_lang_starknet::contract_class::ContractClass as SierraContractClass;
pub use cairo_vm::felt::Felt252;
pub use cairo_vm::felt;

pub mod core;
pub mod definitions;
Expand Down Expand Up @@ -190,8 +191,6 @@ pub fn execute_transaction<T: State + StateReader>(
#[cfg(test)]
mod test {
use std::collections::HashMap;
use std::fs::File;
use std::io::BufReader;
use std::path::PathBuf;

use crate::core::contract_address::compute_deprecated_class_hash;
Expand Down Expand Up @@ -237,9 +236,9 @@ mod test {

lazy_static! {
// include_str! doesn't seem to work in CI
static ref CONTRACT_CLASS: ContractClass = ContractClass::try_from(BufReader::new(File::open(
static ref CONTRACT_CLASS: ContractClass = ContractClass::from_path(
"starknet_programs/account_without_validation.json",
).unwrap()))
)
.unwrap();
static ref CLASS_HASH: Felt252 = compute_deprecated_class_hash(&CONTRACT_CLASS).unwrap();
static ref CLASS_HASH_BYTES: [u8; 32] = CLASS_HASH.clone().to_be_bytes();
Expand All @@ -256,8 +255,7 @@ mod test {

#[test]
fn estimate_fee_test() {
let contract_class: ContractClass =
ContractClass::try_from(PathBuf::from(TEST_CONTRACT_PATH)).unwrap();
let contract_class: ContractClass = ContractClass::from_path(TEST_CONTRACT_PATH).unwrap();

let entrypoints = contract_class.entry_points_by_type;
let entrypoint_selector = entrypoints.get(&EntryPointType::External).unwrap()[0].selector();
Expand Down Expand Up @@ -350,8 +348,7 @@ mod test {
let mut state_reader = InMemoryStateReader::default();
// Set contract_class
let class_hash = [1; 32];
let contract_class =
ContractClass::try_from(PathBuf::from("starknet_programs/l1l2.json")).unwrap();
let contract_class = ContractClass::from_path("starknet_programs/l1l2.json").unwrap();
// Set contact_state
let contract_address = Address(0.into());
let nonce = Felt252::zero();
Expand Down Expand Up @@ -442,7 +439,7 @@ mod test {
#[test]
fn test_skip_execute_flag() {
let path = PathBuf::from("starknet_programs/account_without_validation.json");
let contract_class = ContractClass::try_from(path).unwrap();
let contract_class = ContractClass::from_path(path).unwrap();

// ------------ contract data --------------------
// hack store account contract
Expand Down Expand Up @@ -570,7 +567,7 @@ mod test {
#[test]
fn test_skip_execute_and_validate_flags() {
let path = PathBuf::from("starknet_programs/account_without_validation.json");
let contract_class = ContractClass::try_from(path).unwrap();
let contract_class = ContractClass::from_path(path).unwrap();

// ------------ contract data --------------------
// hack store account contract
Expand Down Expand Up @@ -901,8 +898,7 @@ mod test {
let mut state_reader = InMemoryStateReader::default();
// Set contract_class
let class_hash = [1; 32];
let contract_class =
ContractClass::try_from(PathBuf::from("starknet_programs/l1l2.json")).unwrap();
let contract_class = ContractClass::from_path("starknet_programs/l1l2.json").unwrap();
// Set contact_state
let contract_address = Address(0.into());
let nonce = Felt252::zero();
Expand Down
Loading

0 comments on commit 96d88fa

Please sign in to comment.