From 8e7cf729d56ce5a72e940529997955211079e695 Mon Sep 17 00:00:00 2001 From: mohammad-starkware <130282237+MohammadNassar1@users.noreply.github.com> Date: Wed, 29 May 2024 17:07:18 +0300 Subject: [PATCH 1/4] feat(transaction): implement rpc transaction (#236) --- src/external_transaction.rs | 131 +++++++++++++++++-------------- src/external_transaction_test.rs | 23 +++--- 2 files changed, 86 insertions(+), 68 deletions(-) diff --git a/src/external_transaction.rs b/src/external_transaction.rs index 23012092..6bf44844 100644 --- a/src/external_transaction.rs +++ b/src/external_transaction.rs @@ -2,30 +2,28 @@ #[path = "external_transaction_test.rs"] mod external_transaction_test; -use std::collections::HashMap; - use serde::{Deserialize, Serialize}; use crate::core::{ClassHash, CompiledClassHash, ContractAddress, Nonce}; use crate::data_availability::DataAvailabilityMode; -use crate::state::{EntryPoint, EntryPointType}; +use crate::hash::StarkFelt; +use crate::state::EntryPoint; use crate::transaction::{ - AccountDeploymentData, Calldata, ContractAddressSalt, PaymasterData, ResourceBoundsMapping, - Tip, TransactionSignature, + AccountDeploymentData, Calldata, ContractAddressSalt, PaymasterData, ResourceBounds, Tip, + TransactionSignature, }; -/// An external transaction. +/// Transactions that are ready to be broadcasted to the network through RPC and are not included in +/// a block. #[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] #[serde(tag = "type")] +#[serde(deny_unknown_fields)] pub enum ExternalTransaction { - /// A declare transaction. #[serde(rename = "DECLARE")] Declare(ExternalDeclareTransaction), - /// A deploy account transaction. #[serde(rename = "DEPLOY_ACCOUNT")] DeployAccount(ExternalDeployAccountTransaction), - /// An invoke transaction. - #[serde(rename = "INVOKE_FUNCTION")] + #[serde(rename = "INVOKE")] Invoke(ExternalInvokeTransaction), } @@ -54,9 +52,13 @@ impl ExternalTransaction { ); } -/// A declare transaction that can be added to Starknet through the Starknet gateway. -/// It has a serialization format that the Starknet gateway accepts in the `add_transaction` -/// HTTP method. +/// A RPC declare transaction. +/// +/// This transaction is equivalent to the component DECLARE_TXN in the +/// [`Starknet specs`] with a contract class (DECLARE_TXN allows having +/// either a contract class or a class hash). +/// +/// [`Starknet specs`]: https://github.com/starkware-libs/starknet-specs/blob/master/api/starknet_api_openrpc.json #[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] #[serde(tag = "version")] pub enum ExternalDeclareTransaction { @@ -64,20 +66,26 @@ pub enum ExternalDeclareTransaction { V3(ExternalDeclareTransactionV3), } -/// A deploy account transaction that can be added to Starknet through the Starknet gateway. -/// It has a serialization format that the Starknet gateway accepts in the `add_transaction` -/// HTTP method. -#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] +/// A RPC deploy account transaction. +/// +/// This transaction is equivalent to the component DEPLOY_ACCOUNT_TXN in the +/// [`Starknet specs`]. +/// +/// [`Starknet specs`]: https://github.com/starkware-libs/starknet-specs/blob/master/api/starknet_api_openrpc.json +#[derive(Clone, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)] #[serde(tag = "version")] pub enum ExternalDeployAccountTransaction { #[serde(rename = "0x3")] V3(ExternalDeployAccountTransactionV3), } -/// An invoke transaction that can be added to Starknet through the Starknet gateway. -/// It has a serialization format that the Starknet gateway accepts in the `add_transaction` -/// HTTP method. -#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] +/// A RPC invoke transaction. +/// +/// This transaction is equivalent to the component INVOKE_TXN in the +/// [`Starknet specs`]. +/// +/// [`Starknet specs`]: https://github.com/starkware-libs/starknet-specs/blob/master/api/starknet_api_openrpc.json +#[derive(Clone, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)] #[serde(tag = "version")] pub enum ExternalInvokeTransaction { #[serde(rename = "0x3")] @@ -85,67 +93,76 @@ pub enum ExternalInvokeTransaction { } /// A declare transaction of a Cairo-v1 contract class that can be added to Starknet through the -/// Starknet gateway. -/// It has a serialization format that the Starknet gateway accepts in the `add_transaction` -/// HTTP method. +/// RPC. #[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] -#[serde(deny_unknown_fields)] pub struct ExternalDeclareTransactionV3 { + // TODO: Check with Shahak why we need to keep the DeclareType. + // pub r#type: DeclareType, + pub sender_address: ContractAddress, + pub compiled_class_hash: CompiledClassHash, + pub signature: TransactionSignature, + pub nonce: Nonce, pub contract_class: ContractClass, pub resource_bounds: ResourceBoundsMapping, pub tip: Tip, - pub signature: TransactionSignature, - pub nonce: Nonce, - pub compiled_class_hash: CompiledClassHash, - pub sender_address: ContractAddress, - pub nonce_data_availability_mode: DataAvailabilityMode, - pub fee_data_availability_mode: DataAvailabilityMode, pub paymaster_data: PaymasterData, pub account_deployment_data: AccountDeploymentData, + pub nonce_data_availability_mode: DataAvailabilityMode, + pub fee_data_availability_mode: DataAvailabilityMode, } -/// A deploy account transaction that can be added to Starknet through the Starknet gateway. -/// It has a serialization format that the Starknet gateway accepts in the `add_transaction` -/// HTTP method. -#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] -#[serde(deny_unknown_fields)] +/// A deploy account transaction that can be added to Starknet through the RPC. +#[derive(Clone, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)] pub struct ExternalDeployAccountTransactionV3 { - pub resource_bounds: ResourceBoundsMapping, - pub tip: Tip, - pub contract_address_salt: ContractAddressSalt, + pub signature: TransactionSignature, + pub nonce: Nonce, pub class_hash: ClassHash, + pub contract_address_salt: ContractAddressSalt, pub constructor_calldata: Calldata, - pub nonce: Nonce, - pub signature: TransactionSignature, + pub resource_bounds: ResourceBoundsMapping, + pub tip: Tip, + pub paymaster_data: PaymasterData, pub nonce_data_availability_mode: DataAvailabilityMode, pub fee_data_availability_mode: DataAvailabilityMode, - pub paymaster_data: PaymasterData, } -/// An invoke account transaction that can be added to Starknet through the Starknet gateway. -/// The invoke is a V3 transaction. -/// It has a serialization format that the Starknet gateway accepts in the `add_transaction` -/// HTTP method. -#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] -#[serde(deny_unknown_fields)] +/// An invoke account transaction that can be added to Starknet through the RPC. +#[derive(Clone, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)] pub struct ExternalInvokeTransactionV3 { - pub resource_bounds: ResourceBoundsMapping, - pub tip: Tip, - pub calldata: Calldata, pub sender_address: ContractAddress, - pub nonce: Nonce, + pub calldata: Calldata, pub signature: TransactionSignature, - pub nonce_data_availability_mode: DataAvailabilityMode, - pub fee_data_availability_mode: DataAvailabilityMode, + pub nonce: Nonce, + pub resource_bounds: ResourceBoundsMapping, + pub tip: Tip, pub paymaster_data: PaymasterData, pub account_deployment_data: AccountDeploymentData, + pub nonce_data_availability_mode: DataAvailabilityMode, + pub fee_data_availability_mode: DataAvailabilityMode, } +// The contract class in SN_API state doesn't have `contract_class_version`, not following the spec. #[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)] pub struct ContractClass { - #[serde(rename = "sierra_program")] - pub compressed_sierra_program: String, + pub sierra_program: Vec, pub contract_class_version: String, - pub entry_points_by_type: HashMap>, + pub entry_points_by_type: EntryPointByType, pub abi: String, } + +#[derive(Debug, Clone, Default, Eq, PartialEq, Deserialize, Serialize)] +pub struct EntryPointByType { + #[serde(rename = "CONSTRUCTOR")] + pub constructor: Vec, + #[serde(rename = "EXTERNAL")] + pub external: Vec, + #[serde(rename = "L1_HANDLER")] + pub l1handler: Vec, +} + +// The serialization of the struct in transaction is in capital letters, not following the spec. +#[derive(Clone, Debug, Default, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)] +pub struct ResourceBoundsMapping { + pub l1_gas: ResourceBounds, + pub l2_gas: ResourceBounds, +} diff --git a/src/external_transaction_test.rs b/src/external_transaction_test.rs index 1b93d17d..99a9f070 100644 --- a/src/external_transaction_test.rs +++ b/src/external_transaction_test.rs @@ -1,4 +1,3 @@ -use std::collections::BTreeMap; use std::sync::Arc; use rstest::rstest; @@ -8,25 +7,26 @@ use crate::external_transaction::{ ContractClass, DataAvailabilityMode, ExternalDeclareTransaction, ExternalDeclareTransactionV3, ExternalDeployAccountTransaction, ExternalDeployAccountTransactionV3, ExternalInvokeTransaction, ExternalInvokeTransactionV3, ExternalTransaction, + ResourceBoundsMapping, }; use crate::hash::{StarkFelt, StarkHash}; use crate::transaction::{ - AccountDeploymentData, Calldata, ContractAddressSalt, PaymasterData, Resource, ResourceBounds, - ResourceBoundsMapping, Tip, TransactionSignature, + AccountDeploymentData, Calldata, ContractAddressSalt, PaymasterData, ResourceBounds, Tip, + TransactionSignature, }; use crate::{contract_address, patricia_key, stark_felt}; -fn create_resource_bounds() -> ResourceBoundsMapping { - let mut map = BTreeMap::new(); - map.insert(Resource::L1Gas, ResourceBounds { max_amount: 100, max_price_per_unit: 12 }); - map.insert(Resource::L2Gas, ResourceBounds { max_amount: 58, max_price_per_unit: 31 }); - ResourceBoundsMapping(map) +fn create_resource_bounds_for_testing() -> ResourceBoundsMapping { + ResourceBoundsMapping { + l1_gas: ResourceBounds { max_amount: 100, max_price_per_unit: 12 }, + l2_gas: ResourceBounds { max_amount: 58, max_price_per_unit: 31 }, + } } fn create_declare_v3() -> ExternalDeclareTransaction { ExternalDeclareTransaction::V3(ExternalDeclareTransactionV3 { contract_class: ContractClass::default(), - resource_bounds: create_resource_bounds(), + resource_bounds: create_resource_bounds_for_testing(), tip: Tip(1), signature: TransactionSignature(vec![StarkFelt::ONE, StarkFelt::TWO]), nonce: Nonce(stark_felt!("0x1")), @@ -41,7 +41,7 @@ fn create_declare_v3() -> ExternalDeclareTransaction { fn create_deploy_account_v3() -> ExternalDeployAccountTransaction { ExternalDeployAccountTransaction::V3(ExternalDeployAccountTransactionV3 { - resource_bounds: create_resource_bounds(), + resource_bounds: create_resource_bounds_for_testing(), tip: Tip::default(), contract_address_salt: ContractAddressSalt(stark_felt!("0x23")), class_hash: ClassHash(stark_felt!("0x2")), @@ -56,7 +56,7 @@ fn create_deploy_account_v3() -> ExternalDeployAccountTransaction { fn create_invoke_v3() -> ExternalInvokeTransaction { ExternalInvokeTransaction::V3(ExternalInvokeTransactionV3 { - resource_bounds: create_resource_bounds(), + resource_bounds: create_resource_bounds_for_testing(), tip: Tip(50), calldata: Calldata(Arc::new(vec![stark_felt!("0x2000"), stark_felt!("0x1000")])), sender_address: contract_address!("0x53"), @@ -69,6 +69,7 @@ fn create_invoke_v3() -> ExternalInvokeTransaction { }) } +// We are testing the `ExternalTransaction` serialization. Passing non-default values. #[rstest] #[case(ExternalTransaction::Declare(create_declare_v3()))] #[case(ExternalTransaction::DeployAccount(create_deploy_account_v3()))] From 859f491205e293c71dd22ca13ae72d92a9aed51b Mon Sep 17 00:00:00 2001 From: mohammad-starkware <130282237+MohammadNassar1@users.noreply.github.com> Date: Mon, 3 Jun 2024 17:32:44 +0300 Subject: [PATCH 2/4] Mohammad/external tx/resource bounds/implement from trait (#264) --- src/external_transaction.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/external_transaction.rs b/src/external_transaction.rs index 6bf44844..62deacd1 100644 --- a/src/external_transaction.rs +++ b/src/external_transaction.rs @@ -2,6 +2,8 @@ #[path = "external_transaction_test.rs"] mod external_transaction_test; +use std::collections::BTreeMap; + use serde::{Deserialize, Serialize}; use crate::core::{ClassHash, CompiledClassHash, ContractAddress, Nonce}; @@ -9,8 +11,8 @@ use crate::data_availability::DataAvailabilityMode; use crate::hash::StarkFelt; use crate::state::EntryPoint; use crate::transaction::{ - AccountDeploymentData, Calldata, ContractAddressSalt, PaymasterData, ResourceBounds, Tip, - TransactionSignature, + AccountDeploymentData, Calldata, ContractAddressSalt, PaymasterData, Resource, ResourceBounds, + Tip, TransactionSignature, }; /// Transactions that are ready to be broadcasted to the network through RPC and are not included in @@ -166,3 +168,11 @@ pub struct ResourceBoundsMapping { pub l1_gas: ResourceBounds, pub l2_gas: ResourceBounds, } + +impl From for crate::transaction::ResourceBoundsMapping { + fn from(mapping: ResourceBoundsMapping) -> crate::transaction::ResourceBoundsMapping { + let map = + BTreeMap::from([(Resource::L1Gas, mapping.l1_gas), (Resource::L2Gas, mapping.l2_gas)]); + crate::transaction::ResourceBoundsMapping(map) + } +} From 8f13188f46f5255536fc0d6993789aa65275ad60 Mon Sep 17 00:00:00 2001 From: mohammad-starkware <130282237+MohammadNassar1@users.noreply.github.com> Date: Thu, 13 Jun 2024 14:21:22 +0300 Subject: [PATCH 3/4] refactor: change external_transaction to rpc_transaction (#277) --- src/lib.rs | 2 +- ...rnal_transaction.rs => rpc_transaction.rs} | 44 +++++++++---------- ...action_test.rs => rpc_transaction_test.rs} | 35 +++++++-------- 3 files changed, 40 insertions(+), 41 deletions(-) rename src/{external_transaction.rs => rpc_transaction.rs} (85%) rename src/{external_transaction_test.rs => rpc_transaction_test.rs} (69%) diff --git a/src/lib.rs b/src/lib.rs index ced1a116..a8084f11 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,9 +7,9 @@ pub mod core; pub mod crypto; pub mod data_availability; pub mod deprecated_contract_class; -pub mod external_transaction; pub mod hash; pub mod internal_transaction; +pub mod rpc_transaction; pub mod serde_utils; pub mod state; pub mod transaction; diff --git a/src/external_transaction.rs b/src/rpc_transaction.rs similarity index 85% rename from src/external_transaction.rs rename to src/rpc_transaction.rs index 62deacd1..f1592953 100644 --- a/src/external_transaction.rs +++ b/src/rpc_transaction.rs @@ -1,6 +1,6 @@ #[cfg(test)] -#[path = "external_transaction_test.rs"] -mod external_transaction_test; +#[path = "rpc_transaction_test.rs"] +mod rpc_transaction_test; use std::collections::BTreeMap; @@ -20,34 +20,34 @@ use crate::transaction::{ #[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] #[serde(tag = "type")] #[serde(deny_unknown_fields)] -pub enum ExternalTransaction { +pub enum RPCTransaction { #[serde(rename = "DECLARE")] - Declare(ExternalDeclareTransaction), + Declare(RPCDeclareTransaction), #[serde(rename = "DEPLOY_ACCOUNT")] - DeployAccount(ExternalDeployAccountTransaction), + DeployAccount(RPCDeployAccountTransaction), #[serde(rename = "INVOKE")] - Invoke(ExternalInvokeTransaction), + Invoke(RPCInvokeTransaction), } macro_rules! implement_ref_getters { ($(($member_name:ident, $member_type:ty)), *) => { $(pub fn $member_name(&self) -> &$member_type { match self { - ExternalTransaction::Declare( - ExternalDeclareTransaction::V3(tx) + RPCTransaction::Declare( + RPCDeclareTransaction::V3(tx) ) => &tx.$member_name, - ExternalTransaction::DeployAccount( - ExternalDeployAccountTransaction::V3(tx) + RPCTransaction::DeployAccount( + RPCDeployAccountTransaction::V3(tx) ) => &tx.$member_name, - ExternalTransaction::Invoke( - ExternalInvokeTransaction::V3(tx) + RPCTransaction::Invoke( + RPCInvokeTransaction::V3(tx) ) => &tx.$member_name } })* }; } -impl ExternalTransaction { +impl RPCTransaction { implement_ref_getters!( (resource_bounds, ResourceBoundsMapping), (signature, TransactionSignature) @@ -63,9 +63,9 @@ impl ExternalTransaction { /// [`Starknet specs`]: https://github.com/starkware-libs/starknet-specs/blob/master/api/starknet_api_openrpc.json #[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] #[serde(tag = "version")] -pub enum ExternalDeclareTransaction { +pub enum RPCDeclareTransaction { #[serde(rename = "0x3")] - V3(ExternalDeclareTransactionV3), + V3(RPCDeclareTransactionV3), } /// A RPC deploy account transaction. @@ -76,9 +76,9 @@ pub enum ExternalDeclareTransaction { /// [`Starknet specs`]: https://github.com/starkware-libs/starknet-specs/blob/master/api/starknet_api_openrpc.json #[derive(Clone, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)] #[serde(tag = "version")] -pub enum ExternalDeployAccountTransaction { +pub enum RPCDeployAccountTransaction { #[serde(rename = "0x3")] - V3(ExternalDeployAccountTransactionV3), + V3(RPCDeployAccountTransactionV3), } /// A RPC invoke transaction. @@ -89,15 +89,15 @@ pub enum ExternalDeployAccountTransaction { /// [`Starknet specs`]: https://github.com/starkware-libs/starknet-specs/blob/master/api/starknet_api_openrpc.json #[derive(Clone, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)] #[serde(tag = "version")] -pub enum ExternalInvokeTransaction { +pub enum RPCInvokeTransaction { #[serde(rename = "0x3")] - V3(ExternalInvokeTransactionV3), + V3(RPCInvokeTransactionV3), } /// A declare transaction of a Cairo-v1 contract class that can be added to Starknet through the /// RPC. #[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] -pub struct ExternalDeclareTransactionV3 { +pub struct RPCDeclareTransactionV3 { // TODO: Check with Shahak why we need to keep the DeclareType. // pub r#type: DeclareType, pub sender_address: ContractAddress, @@ -115,7 +115,7 @@ pub struct ExternalDeclareTransactionV3 { /// A deploy account transaction that can be added to Starknet through the RPC. #[derive(Clone, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)] -pub struct ExternalDeployAccountTransactionV3 { +pub struct RPCDeployAccountTransactionV3 { pub signature: TransactionSignature, pub nonce: Nonce, pub class_hash: ClassHash, @@ -130,7 +130,7 @@ pub struct ExternalDeployAccountTransactionV3 { /// An invoke account transaction that can be added to Starknet through the RPC. #[derive(Clone, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)] -pub struct ExternalInvokeTransactionV3 { +pub struct RPCInvokeTransactionV3 { pub sender_address: ContractAddress, pub calldata: Calldata, pub signature: TransactionSignature, diff --git a/src/external_transaction_test.rs b/src/rpc_transaction_test.rs similarity index 69% rename from src/external_transaction_test.rs rename to src/rpc_transaction_test.rs index 99a9f070..3d14ffb4 100644 --- a/src/external_transaction_test.rs +++ b/src/rpc_transaction_test.rs @@ -3,13 +3,12 @@ use std::sync::Arc; use rstest::rstest; use crate::core::{ClassHash, CompiledClassHash, ContractAddress, Nonce, PatriciaKey}; -use crate::external_transaction::{ - ContractClass, DataAvailabilityMode, ExternalDeclareTransaction, ExternalDeclareTransactionV3, - ExternalDeployAccountTransaction, ExternalDeployAccountTransactionV3, - ExternalInvokeTransaction, ExternalInvokeTransactionV3, ExternalTransaction, - ResourceBoundsMapping, -}; use crate::hash::{StarkFelt, StarkHash}; +use crate::rpc_transaction::{ + ContractClass, DataAvailabilityMode, RPCDeclareTransaction, RPCDeclareTransactionV3, + RPCDeployAccountTransaction, RPCDeployAccountTransactionV3, RPCInvokeTransaction, + RPCInvokeTransactionV3, RPCTransaction, ResourceBoundsMapping, +}; use crate::transaction::{ AccountDeploymentData, Calldata, ContractAddressSalt, PaymasterData, ResourceBounds, Tip, TransactionSignature, @@ -23,8 +22,8 @@ fn create_resource_bounds_for_testing() -> ResourceBoundsMapping { } } -fn create_declare_v3() -> ExternalDeclareTransaction { - ExternalDeclareTransaction::V3(ExternalDeclareTransactionV3 { +fn create_declare_v3() -> RPCDeclareTransaction { + RPCDeclareTransaction::V3(RPCDeclareTransactionV3 { contract_class: ContractClass::default(), resource_bounds: create_resource_bounds_for_testing(), tip: Tip(1), @@ -39,8 +38,8 @@ fn create_declare_v3() -> ExternalDeclareTransaction { }) } -fn create_deploy_account_v3() -> ExternalDeployAccountTransaction { - ExternalDeployAccountTransaction::V3(ExternalDeployAccountTransactionV3 { +fn create_deploy_account_v3() -> RPCDeployAccountTransaction { + RPCDeployAccountTransaction::V3(RPCDeployAccountTransactionV3 { resource_bounds: create_resource_bounds_for_testing(), tip: Tip::default(), contract_address_salt: ContractAddressSalt(stark_felt!("0x23")), @@ -54,8 +53,8 @@ fn create_deploy_account_v3() -> ExternalDeployAccountTransaction { }) } -fn create_invoke_v3() -> ExternalInvokeTransaction { - ExternalInvokeTransaction::V3(ExternalInvokeTransactionV3 { +fn create_invoke_v3() -> RPCInvokeTransaction { + RPCInvokeTransaction::V3(RPCInvokeTransactionV3 { resource_bounds: create_resource_bounds_for_testing(), tip: Tip(50), calldata: Calldata(Arc::new(vec![stark_felt!("0x2000"), stark_felt!("0x1000")])), @@ -69,13 +68,13 @@ fn create_invoke_v3() -> ExternalInvokeTransaction { }) } -// We are testing the `ExternalTransaction` serialization. Passing non-default values. +// We are testing the `RPCTransaction` serialization. Passing non-default values. #[rstest] -#[case(ExternalTransaction::Declare(create_declare_v3()))] -#[case(ExternalTransaction::DeployAccount(create_deploy_account_v3()))] -#[case(ExternalTransaction::Invoke(create_invoke_v3()))] -fn test_external_transactions(#[case] tx: ExternalTransaction) { +#[case(RPCTransaction::Declare(create_declare_v3()))] +#[case(RPCTransaction::DeployAccount(create_deploy_account_v3()))] +#[case(RPCTransaction::Invoke(create_invoke_v3()))] +fn test_rpc_transactions(#[case] tx: RPCTransaction) { let serialized = serde_json::to_string(&tx).unwrap(); - let deserialized: ExternalTransaction = serde_json::from_str(&serialized).unwrap(); + let deserialized: RPCTransaction = serde_json::from_str(&serialized).unwrap(); assert_eq!(tx, deserialized); } From eb5697bb1d815f87a6e7c66e4916b8573df15dcd Mon Sep 17 00:00:00 2001 From: Elin Tulchinsky Date: Thu, 27 Jun 2024 17:29:51 +0300 Subject: [PATCH 4/4] Merge `main-mempool` into `main` (conflict resolution). --- src/rpc_transaction.rs | 8 +++++--- src/rpc_transaction_test.rs | 16 ---------------- 2 files changed, 5 insertions(+), 19 deletions(-) diff --git a/src/rpc_transaction.rs b/src/rpc_transaction.rs index f1592953..3555613d 100644 --- a/src/rpc_transaction.rs +++ b/src/rpc_transaction.rs @@ -5,10 +5,10 @@ mod rpc_transaction_test; use std::collections::BTreeMap; use serde::{Deserialize, Serialize}; +use starknet_types_core::felt::Felt; use crate::core::{ClassHash, CompiledClassHash, ContractAddress, Nonce}; use crate::data_availability::DataAvailabilityMode; -use crate::hash::StarkFelt; use crate::state::EntryPoint; use crate::transaction::{ AccountDeploymentData, Calldata, ContractAddressSalt, PaymasterData, Resource, ResourceBounds, @@ -49,8 +49,10 @@ macro_rules! implement_ref_getters { impl RPCTransaction { implement_ref_getters!( + (nonce, Nonce), (resource_bounds, ResourceBoundsMapping), - (signature, TransactionSignature) + (signature, TransactionSignature), + (tip, Tip) ); } @@ -146,7 +148,7 @@ pub struct RPCInvokeTransactionV3 { // The contract class in SN_API state doesn't have `contract_class_version`, not following the spec. #[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)] pub struct ContractClass { - pub sierra_program: Vec, + pub sierra_program: Vec, pub contract_class_version: String, pub entry_points_by_type: EntryPointByType, pub abi: String, diff --git a/src/rpc_transaction_test.rs b/src/rpc_transaction_test.rs index 0f9deb6c..1eac74e3 100644 --- a/src/rpc_transaction_test.rs +++ b/src/rpc_transaction_test.rs @@ -4,27 +4,11 @@ use rstest::rstest; use starknet_types_core::felt::Felt; use crate::core::{ClassHash, CompiledClassHash, ContractAddress, Nonce, PatriciaKey}; -<<<<<<< HEAD:src/external_transaction_test.rs -use crate::external_transaction::{ - ContractClass, DataAvailabilityMode, ExternalDeclareTransaction, ExternalDeclareTransactionV3, - ExternalDeployAccountTransaction, ExternalDeployAccountTransactionV3, - ExternalInvokeTransaction, ExternalInvokeTransactionV3, ExternalTransaction, -}; -||||||| 0f49f20:src/external_transaction_test.rs -use crate::external_transaction::{ - ContractClass, DataAvailabilityMode, ExternalDeclareTransaction, ExternalDeclareTransactionV3, - ExternalDeployAccountTransaction, ExternalDeployAccountTransactionV3, - ExternalInvokeTransaction, ExternalInvokeTransactionV3, ExternalTransaction, -}; -use crate::hash::{StarkFelt, StarkHash}; -======= -use crate::hash::{StarkFelt, StarkHash}; use crate::rpc_transaction::{ ContractClass, DataAvailabilityMode, RPCDeclareTransaction, RPCDeclareTransactionV3, RPCDeployAccountTransaction, RPCDeployAccountTransactionV3, RPCInvokeTransaction, RPCInvokeTransactionV3, RPCTransaction, ResourceBoundsMapping, }; ->>>>>>> origin/main-mempool:src/rpc_transaction_test.rs use crate::transaction::{ AccountDeploymentData, Calldata, ContractAddressSalt, PaymasterData, ResourceBounds, Tip, TransactionSignature,