Skip to content

Commit

Permalink
Upgrade starknet-rs to 0.12.0 (#604)
Browse files Browse the repository at this point in the history
  • Loading branch information
FabijanC authored Sep 18, 2024
1 parent b219656 commit cccfc72
Show file tree
Hide file tree
Showing 17 changed files with 800 additions and 770 deletions.
1,353 changes: 713 additions & 640 deletions Cargo.lock

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ enum-helper-macros = "0.0.1"
starknet-types-core = "0.1.5"
starknet_api = { version = "0.13.0-rc.0", features = ["testing"] }
blockifier = { version = "0.8.0-rc.3" }
starknet-rs-signers = { version = "0.9.0", package = "starknet-signers" }
starknet-rs-core = { version = "0.11.0", package = "starknet-core" }
starknet-rs-providers = { version = "0.11.0", package = "starknet-providers" }
starknet-rs-accounts = { version = "0.10.0", package = "starknet-accounts" }
starknet-rs-contract = { version = "0.10.0", package = "starknet-contract" }
starknet-rs-crypto = { version = "0.7.0", package = "starknet-crypto" }
starknet-rs-signers = { version = "0.10.0", package = "starknet-signers" }
starknet-rs-core = { version = "0.12.0", package = "starknet-core" }
starknet-rs-providers = { version = "0.12.0", package = "starknet-providers" }
starknet-rs-accounts = { version = "0.11.0", package = "starknet-accounts" }
starknet-rs-contract = { version = "0.11.0", package = "starknet-contract" }
starknet-rs-crypto = { version = "0.7.2", package = "starknet-crypto" }
cairo-vm = "=1.0.1"

# Cairo-lang dependencies
Expand Down
1 change: 0 additions & 1 deletion crates/starknet-devnet-core/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ pub const DEVNET_DEFAULT_CHAIN_ID: ChainId = ChainId::Testnet;
pub const DEVNET_DEFAULT_STARTING_BLOCK_NUMBER: u64 = 0;
pub const DEVNET_DEFAULT_REQUEST_BODY_SIZE_LIMIT: usize = 2_000_000;

pub const SUPPORTED_TX_VERSION: u32 = 1;
pub const USE_KZG_DA: bool = true;

// chargeable account
Expand Down
18 changes: 5 additions & 13 deletions crates/starknet-devnet-core/src/raw_execution.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
/// Copied from https://github.com/xJonathanLEI/starknet-rs/
use starknet_rs_core::{crypto::pedersen_hash, types::Felt};
use starknet_rs_core::crypto::pedersen_hash;
use starknet_rs_core::types::{Call, Felt};
use starknet_types::constants::PREFIX_INVOKE;

use crate::constants::SUPPORTED_TX_VERSION;

#[derive(Debug, Clone)]
pub struct Call {
pub to: Felt,
pub selector: Felt,
pub calldata: Vec<Felt>,
}

#[derive(Debug)]
pub struct RawExecution {
pub struct RawExecutionV1 {
pub calls: Vec<Call>,
pub nonce: Felt,
pub max_fee: Felt,
Expand All @@ -29,7 +21,7 @@ pub fn compute_hash_on_elements(data: &[Felt]) -> Felt {
pedersen_hash(&current_hash, &data_len)
}

impl RawExecution {
impl RawExecutionV1 {
pub fn raw_calldata(&self) -> Vec<Felt> {
let mut concated_calldata: Vec<Felt> = vec![];
let mut execute_calldata: Vec<Felt> = vec![self.calls.len().into()];
Expand All @@ -54,7 +46,7 @@ impl RawExecution {
pub fn transaction_hash(&self, chain_id: Felt, address: Felt) -> Felt {
compute_hash_on_elements(&[
PREFIX_INVOKE,
Felt::from(SUPPORTED_TX_VERSION), // version
Felt::ONE, // version
address,
Felt::ZERO, // entry_point_selector
compute_hash_on_elements(&self.raw_calldata()),
Expand Down
6 changes: 3 additions & 3 deletions crates/starknet-devnet-core/src/starknet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use starknet_api::felt;
use starknet_api::transaction::Fee;
use starknet_config::BlockGenerationOn;
use starknet_rs_core::types::{
BlockId, BlockTag, ExecutionResult, Felt, MsgFromL1, TransactionExecutionStatus,
BlockId, BlockTag, Call, ExecutionResult, Felt, MsgFromL1, TransactionExecutionStatus,
TransactionFinalityStatus,
};
use starknet_rs_core::utils::get_selector_from_name;
Expand Down Expand Up @@ -70,7 +70,7 @@ use crate::contract_class_choice::AccountContractClassChoice;
use crate::error::{DevnetResult, Error, TransactionValidationError};
use crate::messaging::MessagingBroker;
use crate::predeployed_accounts::PredeployedAccounts;
use crate::raw_execution::{Call, RawExecution};
use crate::raw_execution::RawExecutionV1;
use crate::state::state_diff::StateDiff;
use crate::state::{CommittedClassStorage, CustomState, CustomStateReader, StarknetState};
use crate::traits::{AccountGenerator, Deployed, HashIdentified, HashIdentifiedMut};
Expand Down Expand Up @@ -772,7 +772,7 @@ impl Starknet {
let (high, low) = split_biguint(amount);
let calldata = vec![Felt::from(address), low, high];

let raw_execution = RawExecution {
let raw_execution = RawExecutionV1 {
calls: vec![Call {
to: erc20_address.into(),
selector: get_selector_from_name("transfer")
Expand Down
5 changes: 2 additions & 3 deletions crates/starknet-devnet/tests/get_transaction_by_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ mod get_transaction_by_hash_integration_tests {

use starknet_core::constants::{CAIRO_0_ACCOUNT_CONTRACT_HASH, ETH_ERC20_CONTRACT_ADDRESS};
use starknet_rs_accounts::{
Account, AccountFactory, Call, ExecutionEncoding, OpenZeppelinAccountFactory,
SingleOwnerAccount,
Account, AccountFactory, ExecutionEncoding, OpenZeppelinAccountFactory, SingleOwnerAccount,
};
use starknet_rs_core::types::contract::legacy::LegacyContractClass;
use starknet_rs_core::types::{BlockId, BlockTag, Felt, StarknetError};
use starknet_rs_core::types::{BlockId, BlockTag, Call, Felt, StarknetError};
use starknet_rs_core::utils::get_selector_from_name;
use starknet_rs_providers::{Provider, ProviderError};
use starknet_types::felt::{felt_from_prefixed_hex, try_felt_to_num};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ mod get_transaction_receipt_by_hash_integration_tests {
use server::test_utils::declare_v1_str;
use starknet_core::constants::{CAIRO_0_ACCOUNT_CONTRACT_HASH, ETH_ERC20_CONTRACT_ADDRESS};
use starknet_rs_accounts::{
Account, AccountFactory, Call, ExecutionEncoding, OpenZeppelinAccountFactory,
SingleOwnerAccount,
Account, AccountFactory, ExecutionEncoding, OpenZeppelinAccountFactory, SingleOwnerAccount,
};
use starknet_rs_contract::ContractFactory;
use starknet_rs_core::types::{
BroadcastedDeclareTransactionV1, ExecutionResult, Felt, StarknetError, TransactionReceipt,
BroadcastedDeclareTransactionV1, Call, ExecutionResult, Felt, StarknetError,
TransactionReceipt,
};
use starknet_rs_core::utils::{get_selector_from_name, get_udc_deployed_address};
use starknet_rs_providers::{Provider, ProviderError};
Expand Down
4 changes: 2 additions & 2 deletions crates/starknet-devnet/tests/test_account_impersonation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ mod impersonated_account_tests {

use server::test_utils::assert_contains;
use starknet_core::constants::STRK_ERC20_CONTRACT_ADDRESS;
use starknet_rs_accounts::{Account, Call, ExecutionEncoding, SingleOwnerAccount};
use starknet_rs_core::types::{BlockId, BlockTag, ExecutionResult, Felt};
use starknet_rs_accounts::{Account, ExecutionEncoding, SingleOwnerAccount};
use starknet_rs_core::types::{BlockId, BlockTag, Call, ExecutionResult, Felt};
use starknet_rs_core::utils::get_selector_from_name;
use starknet_rs_providers::jsonrpc::HttpTransport;
use starknet_rs_providers::{JsonRpcClient, Provider};
Expand Down
4 changes: 2 additions & 2 deletions crates/starknet-devnet/tests/test_account_selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ mod test_account_selection {
CAIRO_1_ACCOUNT_CONTRACT_SIERRA_HASH, CAIRO_1_ACCOUNT_CONTRACT_SIERRA_PATH,
};
use starknet_core::utils::exported_test_utils::dummy_cairo_0_contract_class;
use starknet_rs_accounts::{Account, Call, ExecutionEncoding, SingleOwnerAccount};
use starknet_rs_accounts::{Account, ExecutionEncoding, SingleOwnerAccount};
use starknet_rs_contract::ContractFactory;
use starknet_rs_core::types::contract::legacy::LegacyContractClass;
use starknet_rs_core::types::{BlockId, BlockTag, Felt, FunctionCall};
use starknet_rs_core::types::{BlockId, BlockTag, Call, Felt, FunctionCall};
use starknet_rs_core::utils::{
get_selector_from_name, get_udc_deployed_address, UdcUniqueness,
};
Expand Down
4 changes: 2 additions & 2 deletions crates/starknet-devnet/tests/test_blocks_generation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ mod blocks_generation_tests {

use serde_json::json;
use starknet_core::constants::CAIRO_1_ACCOUNT_CONTRACT_SIERRA_HASH;
use starknet_rs_accounts::{Account, Call, ExecutionEncoding, SingleOwnerAccount};
use starknet_rs_accounts::{Account, ExecutionEncoding, SingleOwnerAccount};
use starknet_rs_contract::ContractFactory;
use starknet_rs_core::types::{
BlockId, BlockStatus, BlockTag, DeclaredClassItem, Felt, FunctionCall,
BlockId, BlockStatus, BlockTag, Call, DeclaredClassItem, Felt, FunctionCall,
MaybePendingStateUpdate, NonceUpdate, StateUpdate, TransactionTrace,
};
use starknet_rs_core::utils::{
Expand Down
32 changes: 13 additions & 19 deletions crates/starknet-devnet/tests/test_estimate_fee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ pub mod common;
mod estimate_fee_tests {
use std::sync::Arc;

use serde_json::json;
use server::test_utils::assert_contains;
use starknet_core::constants::{CAIRO_0_ACCOUNT_CONTRACT_HASH, UDC_CONTRACT_ADDRESS};
use starknet_core::utils::exported_test_utils::dummy_cairo_0_contract_class;
use starknet_rs_accounts::{
Account, AccountError, AccountFactory, AccountFactoryError, Call, ConnectedAccount,
Account, AccountError, AccountFactory, AccountFactoryError, ConnectedAccount,
ExecutionEncoding, OpenZeppelinAccountFactory, SingleOwnerAccount,
};
use starknet_rs_contract::ContractFactory;
use starknet_rs_core::types::contract::legacy::LegacyContractClass;
use starknet_rs_core::types::{
BlockId, BlockTag, BroadcastedDeclareTransactionV1, BroadcastedInvokeTransaction,
BroadcastedInvokeTransactionV1, BroadcastedTransaction, FeeEstimate, Felt, FunctionCall,
StarknetError,
BroadcastedInvokeTransactionV1, BroadcastedTransaction, Call, ContractErrorData,
FeeEstimate, Felt, FunctionCall, StarknetError,
};
use starknet_rs_core::utils::{
cairo_short_string_to_felt, get_selector_from_name, get_udc_deployed_address, UdcUniqueness,
Expand Down Expand Up @@ -415,26 +415,20 @@ mod estimate_fee_tests {
calldata: vec![cairo_short_string_to_felt(panic_reason).unwrap()],
}];

let prepared = account
let invoke_err = account
.execute_v1(calls.clone())
.nonce(account.get_nonce().await.unwrap())
.max_fee(Felt::ZERO)
.prepared()
.unwrap()
.get_invoke_request(true)
.estimate_fee()
.await
.unwrap();
.unwrap_err();

let params = json!({
"block_id": "latest",
"simulation_flags": [],
"request": [
serde_json::to_value(prepared).unwrap()
]
});

let rpc_error = devnet.send_custom_rpc("starknet_estimateFee", params).await.unwrap_err();
assert!(rpc_error.data.unwrap()["revert_error"].as_str().unwrap().contains(panic_reason));
match invoke_err {
AccountError::Provider(ProviderError::StarknetError(StarknetError::ContractError(
ContractErrorData { revert_error },
))) => assert_contains(&revert_error, panic_reason),
other => panic!("Invalid err: {other:?}"),
};
}

#[tokio::test]
Expand Down
4 changes: 2 additions & 2 deletions crates/starknet-devnet/tests/test_fork.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ mod fork_tests {
use server::test_utils::assert_contains;
use starknet_core::constants::CAIRO_1_ERC20_CONTRACT_CLASS_HASH;
use starknet_rs_accounts::{
Account, AccountFactory, AccountFactoryError, Call, ExecutionEncoding,
Account, AccountFactory, AccountFactoryError, ExecutionEncoding,
OpenZeppelinAccountFactory, SingleOwnerAccount,
};
use starknet_rs_contract::ContractFactory;
use starknet_rs_core::types::contract::legacy::LegacyContractClass;
use starknet_rs_core::types::{
BlockId, BlockTag, ContractClass, Felt, FunctionCall, MaybePendingBlockWithTxHashes,
BlockId, BlockTag, Call, ContractClass, Felt, FunctionCall, MaybePendingBlockWithTxHashes,
StarknetError,
};
use starknet_rs_core::utils::{
Expand Down
15 changes: 6 additions & 9 deletions crates/starknet-devnet/tests/test_gas_modification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ mod gas_modification_tests {
use starknet_rs_accounts::{Account, AccountError, ExecutionEncoding, SingleOwnerAccount};
use starknet_rs_core::types::{Felt, ResourcePrice, StarknetError};
use starknet_rs_providers::ProviderError;
use starknet_rs_signers::Signer;
use starknet_types::chain_id::ChainId;
use starknet_types::felt::felt_from_prefixed_hex;

Expand All @@ -30,7 +31,7 @@ mod gas_modification_tests {
let (signer, account_address) = devnet.get_first_predeployed_account().await;
let account = SingleOwnerAccount::new(
devnet.clone_provider(),
signer,
signer.clone(),
account_address,
felt_from_prefixed_hex(expected_chain_id).unwrap(),
ExecutionEncoding::New,
Expand All @@ -43,18 +44,14 @@ mod gas_modification_tests {
let max_fee = Felt::ZERO;
let nonce = Felt::ZERO;

let signature = account
let declaration = account
.declare_v2(Arc::new(flattened_contract_artifact.clone()), casm_hash)
.max_fee(max_fee)
.nonce(nonce)
.prepared()
.unwrap()
.get_declare_request(false)
.await
.unwrap()
.signature;
.unwrap();
let signature = signer.sign_hash(&declaration.transaction_hash(false)).await.unwrap();

let signature_hex: Vec<String> = iter_to_hex_felt(&signature);
let sender_address_hex = to_hex_felt(&account_address);
let get_params = |simulation_flags: &[&str]| -> serde_json::Value {
json!({
Expand All @@ -67,7 +64,7 @@ mod gas_modification_tests {
"compiled_class_hash": to_hex_felt(&casm_hash),
"max_fee": to_hex_felt(&max_fee),
"version": "0x2",
"signature": signature_hex,
"signature": iter_to_hex_felt(&[signature.r, signature.s]),
"nonce": to_num_as_hex(&nonce),
"contract_class": flattened_contract_artifact,
}
Expand Down
6 changes: 2 additions & 4 deletions crates/starknet-devnet/tests/test_get_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ pub mod common;
mod get_events_integration_tests {
use std::sync::Arc;

use starknet_rs_accounts::{
Account, Call, ConnectedAccount, ExecutionEncoding, SingleOwnerAccount,
};
use starknet_rs_accounts::{Account, ConnectedAccount, ExecutionEncoding, SingleOwnerAccount};
use starknet_rs_contract::ContractFactory;
use starknet_rs_core::types::{BlockId, BlockTag, EventFilter, Felt, StarknetError};
use starknet_rs_core::types::{BlockId, BlockTag, Call, EventFilter, Felt, StarknetError};
use starknet_rs_core::utils::{get_selector_from_name, get_udc_deployed_address};
use starknet_rs_providers::{Provider, ProviderError};

Expand Down
6 changes: 3 additions & 3 deletions crates/starknet-devnet/tests/test_messaging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ mod test_messaging {
use ethers::prelude::*;
use serde_json::{json, Value};
use starknet_rs_accounts::{
Account, AccountError, Call, ConnectedAccount, ExecutionEncoding, SingleOwnerAccount,
Account, AccountError, ConnectedAccount, ExecutionEncoding, SingleOwnerAccount,
};
use starknet_rs_contract::ContractFactory;
use starknet_rs_core::types::{
BlockId, BlockTag, Felt, FunctionCall, InvokeTransactionResult, TransactionExecutionStatus,
TransactionReceipt, TransactionReceiptWithBlockInfo,
BlockId, BlockTag, Call, Felt, FunctionCall, InvokeTransactionResult,
TransactionExecutionStatus, TransactionReceipt, TransactionReceiptWithBlockInfo,
};
use starknet_rs_core::utils::{
get_selector_from_name, get_udc_deployed_address, UdcUniqueness,
Expand Down
Loading

0 comments on commit cccfc72

Please sign in to comment.