Skip to content

Commit

Permalink
feat(coonsensus): add cetral deploy account transaction written object
Browse files Browse the repository at this point in the history
  • Loading branch information
Yael-Starkware committed Dec 22, 2024
1 parent c414502 commit aa9acdb
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,17 @@ use starknet_api::block::{
};
use starknet_api::core::{ClassHash, CompiledClassHash, ContractAddress, Nonce};
use starknet_api::data_availability::DataAvailabilityMode;
use starknet_api::executable_transaction::{AccountTransaction, InvokeTransaction, Transaction};
use starknet_api::executable_transaction::{
AccountTransaction,
DeployAccountTransaction,
InvokeTransaction,
Transaction,
};
use starknet_api::state::StorageKey;
use starknet_api::transaction::fields::{
AccountDeploymentData,
Calldata,
ContractAddressSalt,
PaymasterData,
Tip,
TransactionSignature,
Expand Down Expand Up @@ -165,11 +171,55 @@ pub enum CentralInvokeTransaction {
V3(CentralInvokeTransactionV3),
}

#[derive(Debug, PartialEq, Deserialize, Serialize)]
pub struct CentralDeployAccountTransactionV3 {
pub resource_bounds: ValidResourceBounds,
pub tip: Tip,
pub signature: TransactionSignature,
pub nonce: Nonce,
pub class_hash: ClassHash,
pub contract_address_salt: ContractAddressSalt,
pub constructor_calldata: Calldata,
pub nonce_data_availability_mode: CentralDataAvailabilityMode,
pub fee_data_availability_mode: CentralDataAvailabilityMode,
pub paymaster_data: PaymasterData,
pub hash_value: TransactionHash,
pub sender_address: ContractAddress,
}

impl From<DeployAccountTransaction> for CentralDeployAccountTransactionV3 {
fn from(tx: DeployAccountTransaction) -> CentralDeployAccountTransactionV3 {
CentralDeployAccountTransactionV3 {
resource_bounds: tx.resource_bounds(),
tip: tx.tip(),
signature: tx.signature(),
nonce: tx.nonce(),
class_hash: tx.class_hash(),
contract_address_salt: tx.contract_address_salt(),
constructor_calldata: tx.constructor_calldata(),
nonce_data_availability_mode: tx.nonce_data_availability_mode().into(),
fee_data_availability_mode: tx.fee_data_availability_mode().into(),
paymaster_data: tx.paymaster_data(),
hash_value: tx.tx_hash(),
sender_address: tx.contract_address,
}
}
}

#[derive(Debug, PartialEq, Deserialize, Serialize)]
#[serde(tag = "version")]
pub enum CentralDeployAccountTransaction {
#[serde(rename = "0x3")]
V3(CentralDeployAccountTransactionV3),
}

#[derive(Debug, PartialEq, Deserialize, Serialize)]
#[serde(tag = "type")]
pub enum CentralTransaction {
#[serde(rename = "INVOKE_FUNCTION")]
Invoke(CentralInvokeTransaction),
#[serde(rename = "DEPLOY_ACCOUNT")]
DeployAccount(CentralDeployAccountTransaction),
}

impl From<Transaction> for CentralTransaction {
Expand All @@ -180,6 +230,11 @@ impl From<Transaction> for CentralTransaction {
CentralInvokeTransactionV3::from(invoke_tx),
))
}
Transaction::Account(AccountTransaction::DeployAccount(deploy_tx)) => {
CentralTransaction::DeployAccount(CentralDeployAccountTransaction::V3(
deploy_tx.into(),
))
}
Transaction::Account(_) => unimplemented!(),
Transaction::L1Handler(_) => unimplemented!(),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,17 @@ use starknet_api::execution_resources::GasAmount;
use starknet_api::transaction::fields::{
AllResourceBounds,
Calldata,
ContractAddressSalt,
ResourceBounds,
ValidResourceBounds,
};
use starknet_api::transaction::TransactionHash;
use starknet_api::{contract_address, felt, storage_key};

use crate::cende::central_objects::{
use super::{
CentralBlockInfo,
CentralDeployAccountTransaction,
CentralDeployAccountTransactionV3,
CentralInvokeTransaction,
CentralInvokeTransactionV3,
CentralResourcePrice,
Expand All @@ -44,6 +47,8 @@ pub const CENTRAL_STATE_DIFF_JSON_PATH: &str =
concat!(test_resources_dir!(), "/central_state_diff.json");
pub const CENTRAL_INVOKE_TX_JSON_PATH: &str =
concat!(test_resources_dir!(), "/central_invoke_tx.json");
pub const CENTRAL_DEPLOY_ACCOUNT_TX_JSON_PATH: &str =
concat!(test_resources_dir!(), "/central_deploy_account_tx.json");

fn central_state_diff() -> CentralStateDiff {
CentralStateDiff {
Expand Down Expand Up @@ -112,9 +117,46 @@ fn invoke_transaction() -> CentralTransactionWritten {
}
}

fn deploy_account_transaction() -> CentralTransactionWritten {
CentralTransactionWritten {
tx: CentralTransaction::DeployAccount(CentralDeployAccountTransaction::V3(
CentralDeployAccountTransactionV3 {
resource_bounds: ValidResourceBounds::AllResources(AllResourceBounds {
l1_gas: ResourceBounds {
max_amount: GasAmount(1),
max_price_per_unit: GasPrice(1),
},
l2_gas: ResourceBounds::default(),
l1_data_gas: ResourceBounds::default(),
}),
sender_address: contract_address!(
"0x4c2e031b0ddaa38e06fd9b1bf32bff739965f9d64833006204c67cbc879a57c"
),
signature: Default::default(),
nonce: Default::default(),
tip: Default::default(),
paymaster_data: Default::default(),
nonce_data_availability_mode: Default::default(),
fee_data_availability_mode: Default::default(),

class_hash: ClassHash(felt!(
"0x1b5a0b09f23b091d5d1fa2f660ddfad6bcfce607deba23806cd7328ccfb8ee9"
)),
contract_address_salt: ContractAddressSalt(felt!(2_u8)),
constructor_calldata: Default::default(),
hash_value: TransactionHash(felt!(
"0x429cb4dc45610a80a96800ab350a11ff50e2d69e25c7723c002934e66b5a282"
)),
},
)),
time_created: CentralTransactionTimestamp(1734601616),
}
}

#[rstest]
#[case::state_diff(serde_json::to_value(central_state_diff()).unwrap(), CENTRAL_STATE_DIFF_JSON_PATH)]
#[case::invoke_tx(serde_json::to_value(invoke_transaction()).unwrap(), CENTRAL_INVOKE_TX_JSON_PATH)]
#[case::deploy_account_tx(serde_json::to_value(deploy_account_transaction()).unwrap(), CENTRAL_DEPLOY_ACCOUNT_TX_JSON_PATH)]
fn serialize_central_objects(#[case] rust_json: Value, #[case] python_json_path: &str) {
let file = File::open(resolve_project_relative_path(python_json_path).unwrap()).unwrap();
let python_json: Value = serde_json::from_reader(file).unwrap();
Expand Down

0 comments on commit aa9acdb

Please sign in to comment.