Skip to content

Add set_balance cheatcode #2929

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 16 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 17 additions & 23 deletions crates/cheatnet/src/constants.rs
Original file line number Diff line number Diff line change
@@ -5,15 +5,14 @@ use blockifier::execution::contract_class::ContractClassV1;

use blockifier::execution::contract_class::ContractClass;

use crate::data::contract_class_no_entrypoints::NO_ENTRYPOINTS_CASM;
use blockifier::execution::entry_point::{CallEntryPoint, CallType};
use conversions::IntoConv;
use indoc::indoc;
use starknet::core::utils::get_selector_from_name;
use starknet_api::deprecated_contract_class::EntryPointType;

use conversions::string::TryFromHexStr;
use conversions::IntoConv;
use runtime::starknet::context::ERC20_CONTRACT_ADDRESS;
use runtime::starknet::state::DictStateReader;
use starknet::core::utils::get_selector_from_name;
use starknet_api::deprecated_contract_class::EntryPointType;
use starknet_api::{core::ContractAddress, transaction::Calldata};

pub const MAX_FEE: u128 = 1_000_000 * 100_000_000_000; // 1000000 * min_gas_price.
@@ -32,22 +31,15 @@ pub const TEST_ENTRY_POINT_SELECTOR: &str = "TEST_CONTRACT_SELECTOR";
// snforge_std/src/cheatcodes.cairo::test_address
pub const TEST_ADDRESS: &str = "0x01724987234973219347210837402";

fn contract_class_no_entrypoints() -> ContractClass {
let raw_contract_class = indoc!(
r#"{
"prime": "0x800000000000011000000000000000000000000000000000000000000000001",
"compiler_version": "2.4.0",
"bytecode": [],
"hints": [],
"entry_points_by_type": {
"EXTERNAL": [],
"L1_HANDLER": [],
"CONSTRUCTOR": []
}
}"#,
);
pub const STRK_CONTRACT_ADDRESS: &str =
"0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d";
pub const STRK_CLASS_HASH: &str =
"0x04ad3c1dc8413453db314497945b6903e1c766495a1e60492d44da9c2a986e4b";

#[must_use]
pub fn get_contract_class(class: &str) -> ContractClass {
ContractClass::V1(
ContractClassV1::try_from_json_string(raw_contract_class)
ContractClassV1::try_from_json_string(class)
.expect("Could not create dummy contract from raw"),
)
}
@@ -61,11 +53,13 @@ pub fn build_testing_state() -> DictStateReader {
TryFromHexStr::try_from_hex_str(TEST_ERC20_CONTRACT_CLASS_HASH).unwrap();
let test_contract_class_hash =
TryFromHexStr::try_from_hex_str(TEST_CONTRACT_CLASS_HASH).unwrap();

let class_hash_to_class = HashMap::from([
// This is dummy put here only to satisfy blockifier
// This dummy test contract class hash and class is put here only to satisfy blockifier
// this class is not used and the test contract cannot be called
(test_contract_class_hash, contract_class_no_entrypoints()),
(
test_contract_class_hash,
get_contract_class(NO_ENTRYPOINTS_CASM),
),
]);

let test_erc20_address = TryFromHexStr::try_from_hex_str(ERC20_CONTRACT_ADDRESS).unwrap();
15 changes: 15 additions & 0 deletions crates/cheatnet/src/data/contract_class_no_entrypoints.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use indoc::indoc;

pub const NO_ENTRYPOINTS_CASM: &str = indoc!(
r#"{
"prime": "0x800000000000011000000000000000000000000000000000000000000000001",
"compiler_version": "2.4.0",
"bytecode": [],
"hints": [],
"entry_points_by_type": {
"EXTERNAL": [],
"L1_HANDLER": [],
"CONSTRUCTOR": []
}
}"#
);
2 changes: 2 additions & 0 deletions crates/cheatnet/src/data/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod contract_class_no_entrypoints;
pub mod strk_erc20_lockable;
Loading