Skip to content

Commit

Permalink
chore(JSON-RPC): merge rpc v0_5 into v0_6 (#1545)
Browse files Browse the repository at this point in the history
* chore(JSON-RPC): merge rpc v0_5 into v0_6

* chore(JSON-RPC): support only query
  • Loading branch information
ShahakShama authored Dec 24, 2023
1 parent ec822e5 commit d335ee5
Show file tree
Hide file tree
Showing 7 changed files with 173 additions and 72 deletions.
6 changes: 3 additions & 3 deletions crates/papyrus_rpc/resources/V0_6/starknet_write_api.json
Original file line number Diff line number Diff line change
Expand Up @@ -223,13 +223,13 @@
"$ref": "./starknet_api_openrpc.json#/components/schemas/TXN_HASH"
},
"BROADCASTED_INVOKE_TXN": {
"$ref": "./api/starknet_api_openrpc.json#/components/schemas/BROADCASTED_INVOKE_TXN"
"$ref": "./starknet_api_openrpc.json#/components/schemas/BROADCASTED_INVOKE_TXN"
},
"BROADCASTED_DECLARE_TXN": {
"$ref": "./api/starknet_api_openrpc.json#/components/schemas/BROADCASTED_DECLARE_TXN"
"$ref": "./starknet_api_openrpc.json#/components/schemas/BROADCASTED_DECLARE_TXN"
},
"BROADCASTED_DEPLOY_ACCOUNT_TXN": {
"$ref": "./api/starknet_api_openrpc.json#/components/schemas/BROADCASTED_DEPLOY_ACCOUNT_TXN"
"$ref": "./starknet_api_openrpc.json#/components/schemas/BROADCASTED_DEPLOY_ACCOUNT_TXN"
},
"FUNCTION_CALL": {
"$ref": "./starknet_api_openrpc.json#/components/schemas/FUNCTION_CALL"
Expand Down
8 changes: 4 additions & 4 deletions crates/papyrus_rpc/src/v0_6/api/api_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,8 @@ use super::super::state::{AcceptedStateUpdate, PendingStateUpdate, StateUpdate};
use super::super::transaction::{
get_block_tx_hashes_by_number,
get_block_txs_by_number,
DeployAccountTransaction,
Event,
GeneralTransactionReceipt,
InvokeTransaction,
L1HandlerMsgHash,
MessageFromL1,
PendingTransactionFinalityStatus,
Expand All @@ -90,6 +88,8 @@ use super::super::transaction::{
TransactionStatus,
TransactionWithHash,
Transactions,
TypedDeployAccountTransaction,
TypedInvokeTransaction,
};
use super::super::write_api_error::{
starknet_error_to_declare_error,
Expand Down Expand Up @@ -924,7 +924,7 @@ impl JsonRpcServer for JsonRpcServerV0_6Impl {
#[instrument(skip(self), level = "debug", err, ret)]
async fn add_invoke_transaction(
&self,
invoke_transaction: InvokeTransaction,
invoke_transaction: TypedInvokeTransaction,
) -> RpcResult<AddInvokeOkResult> {
let result = self.writer_client.add_invoke_transaction(&invoke_transaction.into()).await;
match result {
Expand All @@ -939,7 +939,7 @@ impl JsonRpcServer for JsonRpcServerV0_6Impl {
#[instrument(skip(self), level = "debug", err, ret)]
async fn add_deploy_account_transaction(
&self,
deploy_account_transaction: DeployAccountTransaction,
deploy_account_transaction: TypedDeployAccountTransaction,
) -> RpcResult<AddDeployAccountOkResult> {
let result = self
.writer_client
Expand Down
6 changes: 4 additions & 2 deletions crates/papyrus_rpc/src/v0_6/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ use super::transaction::{
MessageFromL1,
TransactionStatus,
TransactionWithHash,
TypedDeployAccountTransaction,
TypedInvokeTransaction,
};
use super::write_api_result::{AddDeclareOkResult, AddDeployAccountOkResult, AddInvokeOkResult};
use crate::api::{BlockId, CallRequest};
Expand Down Expand Up @@ -185,14 +187,14 @@ pub trait JsonRpc {
#[method(name = "addInvokeTransaction")]
async fn add_invoke_transaction(
&self,
invoke_transaction: InvokeTransaction,
invoke_transaction: TypedInvokeTransaction,
) -> RpcResult<AddInvokeOkResult>;

/// Submits a new deploy account transaction to be added to the chain.
#[method(name = "addDeployAccountTransaction")]
async fn add_deploy_account_transaction(
&self,
deploy_account_transaction: DeployAccountTransaction,
deploy_account_transaction: TypedDeployAccountTransaction,
) -> RpcResult<AddDeployAccountOkResult>;

/// Submits a new declare transaction to be added to the chain.
Expand Down
29 changes: 23 additions & 6 deletions crates/papyrus_rpc/src/v0_6/api/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ use starknet_client::writer::{MockStarknetWriter, WriterClientError, WriterClien
use starknet_client::ClientError;
use test_utils::{
auto_impl_get_test_instance,
get_number_of_variants,
get_rng,
get_test_block,
get_test_body,
Expand Down Expand Up @@ -143,6 +144,8 @@ use super::super::transaction::{
TransactionStatus,
TransactionWithHash,
Transactions,
TypedDeployAccountTransaction,
TypedInvokeTransaction,
};
use super::super::write_api_result::{
AddDeclareOkResult,
Expand Down Expand Up @@ -3320,14 +3323,15 @@ where
// https://github.com/rust-lang/rfcs/blob/master/text/2289-associated-type-bounds.md
<<Self as AddTransactionTest>::ClientTransaction as TryFrom<Self::Transaction>>::Error: Debug,
{
type Transaction: GetTestInstance + Serialize + Clone + Send + Debug;
type Transaction: GetTestInstance + Serialize + Clone + Send + Sync + 'static + Debug;
type ClientTransaction: TryFrom<Self::Transaction> + Send + Debug;
type Response: From<Self::ClientResponse>
+ for<'de> Deserialize<'de>
+ Eq
+ Debug
+ Clone
+ Send;
+ Send
+ Sync;
type ClientResponse: GetTestInstance + Clone + Send;

const METHOD_NAME: &'static str;
Expand Down Expand Up @@ -3358,8 +3362,15 @@ where
None,
None,
);
let resp = module.call::<_, Self::Response>(Self::METHOD_NAME, [tx]).await.unwrap();
assert_eq!(resp, expected_resp);
call_api_then_assert_and_validate_schema_for_result(
&module,
Self::METHOD_NAME,
vec![Box::new(tx)],
&VERSION,
SpecFile::WriteApi,
&expected_resp,
)
.await;
}

async fn test_internal_error() {
Expand Down Expand Up @@ -3460,7 +3471,7 @@ where

struct AddInvokeTest {}
impl AddTransactionTest for AddInvokeTest {
type Transaction = InvokeTransaction;
type Transaction = TypedInvokeTransaction;
type ClientTransaction = ClientInvokeTransaction;
type Response = AddInvokeOkResult;
type ClientResponse = InvokeResponse;
Expand All @@ -3482,7 +3493,7 @@ impl AddTransactionTest for AddInvokeTest {

struct AddDeployAccountTest {}
impl AddTransactionTest for AddDeployAccountTest {
type Transaction = DeployAccountTransaction;
type Transaction = TypedDeployAccountTransaction;
type ClientTransaction = ClientDeployAccountTransaction;
type Response = AddDeployAccountOkResult;
type ClientResponse = DeployAccountResponse;
Expand Down Expand Up @@ -3646,4 +3657,10 @@ auto_impl_get_test_instance! {
pub price_in_wei: GasPrice,
pub price_in_fri: GasPrice,
}
pub enum TypedInvokeTransaction {
Invoke(InvokeTransaction) = 0,
}
pub enum TypedDeployAccountTransaction {
DeployAccount(DeployAccountTransaction) = 0,
}
}
13 changes: 7 additions & 6 deletions crates/papyrus_rpc/src/v0_6/execution_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ use super::transaction::{
InvokeTransaction,
InvokeTransactionV1,
MessageFromL1,
TransactionVersion1,
};
use crate::api::{BlockHashOrNumber, BlockId, CallRequest, Tag};
use crate::test_utils::{
Expand Down Expand Up @@ -317,7 +318,7 @@ async fn call_estimate_fee() {

let invoke = BroadcastedTransaction::Invoke(InvokeTransaction::Version1(InvokeTransactionV1 {
max_fee: Fee(1000000 * GAS_PRICE.0),
version: TransactionVersion::ONE,
version: TransactionVersion1::Version1,
sender_address: account_address,
calldata: calldata![
*DEPRECATED_CONTRACT_ADDRESS.0.key(), // Contract address.
Expand Down Expand Up @@ -376,7 +377,7 @@ async fn call_estimate_fee() {
let non_existent_entry_point =
BroadcastedTransaction::Invoke(InvokeTransaction::Version1(InvokeTransactionV1 {
max_fee: Fee(1000000 * GAS_PRICE.0),
version: TransactionVersion::ONE,
version: TransactionVersion1::Version1,
sender_address: account_address,
calldata: calldata![
*DEPRECATED_CONTRACT_ADDRESS.0.key(), // Contract address.
Expand Down Expand Up @@ -428,7 +429,7 @@ async fn pending_call_estimate_fee() {

let invoke = BroadcastedTransaction::Invoke(InvokeTransaction::Version1(InvokeTransactionV1 {
max_fee: Fee(1000000 * GAS_PRICE.0),
version: TransactionVersion::ONE,
version: TransactionVersion1::Version1,
sender_address: account_address,
calldata: calldata![
*DEPRECATED_CONTRACT_ADDRESS.0.key(), // Contract address.
Expand Down Expand Up @@ -491,7 +492,7 @@ async fn test_call_simulate(
) {
let mut invoke_v1 = InvokeTransactionV1 {
max_fee: Fee(1000000 * GAS_PRICE.0),
version: TransactionVersion::ONE,
version: TransactionVersion1::Version1,
sender_address: *ACCOUNT_ADDRESS,
calldata: calldata![
*DEPRECATED_CONTRACT_ADDRESS.0.key(), // Contract address.
Expand Down Expand Up @@ -572,7 +573,7 @@ async fn call_simulate_skip_validate() {

let invoke = BroadcastedTransaction::Invoke(InvokeTransaction::Version1(InvokeTransactionV1 {
max_fee: Fee(1000000 * GAS_PRICE.0),
version: TransactionVersion::ONE,
version: TransactionVersion1::Version1,
sender_address: *ACCOUNT_ADDRESS,
calldata: calldata![
*DEPRECATED_CONTRACT_ADDRESS.0.key(), // Contract address.
Expand Down Expand Up @@ -620,7 +621,7 @@ async fn call_simulate_skip_fee_charge() {

let invoke = BroadcastedTransaction::Invoke(InvokeTransaction::Version1(InvokeTransactionV1 {
max_fee: Fee(1000000 * GAS_PRICE.0),
version: TransactionVersion::ONE,
version: TransactionVersion1::Version1,
sender_address: *ACCOUNT_ADDRESS,
calldata: calldata![
*DEPRECATED_CONTRACT_ADDRESS.0.key(), // Contract address.
Expand Down
Loading

0 comments on commit d335ee5

Please sign in to comment.