Skip to content

Commit

Permalink
refactor(starknet_api): use general invoke rpc transaction test util
Browse files Browse the repository at this point in the history
  • Loading branch information
ayeletstarkware committed Nov 13, 2024
1 parent e777b13 commit f87a869
Showing 1 changed file with 11 additions and 18 deletions.
29 changes: 11 additions & 18 deletions crates/starknet_api/src/rpc_transaction_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ use crate::rpc_transaction::{
RpcDeclareTransactionV3,
RpcDeployAccountTransaction,
RpcDeployAccountTransactionV3,
RpcInvokeTransaction,
RpcInvokeTransactionV3,
RpcTransaction,
};
use crate::test_utils::invoke::{rpc_invoke_tx, InvokeTxArgs};
use crate::transaction::fields::{
AccountDeploymentData,
AllResourceBounds,
Expand All @@ -26,6 +25,7 @@ use crate::transaction::fields::{
ResourceBounds,
Tip,
TransactionSignature,
ValidResourceBounds,
};
use crate::{class_hash, contract_address, felt, nonce};

Expand Down Expand Up @@ -68,26 +68,19 @@ fn create_deploy_account_v3() -> RpcDeployAccountTransaction {
})
}

fn create_invoke_v3() -> RpcInvokeTransaction {
RpcInvokeTransaction::V3(RpcInvokeTransactionV3 {
resource_bounds: create_resource_bounds_for_testing(),
tip: Tip(50),
calldata: Calldata(Arc::new(vec![felt!("0x2000"), felt!("0x1000")])),
sender_address: contract_address!("0x53"),
nonce: nonce!(32),
signature: TransactionSignature::default(),
nonce_data_availability_mode: DataAvailabilityMode::L1,
fee_data_availability_mode: DataAvailabilityMode::L1,
paymaster_data: PaymasterData(vec![Felt::TWO, Felt::ZERO]),
account_deployment_data: AccountDeploymentData(vec![felt!("0x87")]),
})
}

// We are testing the `RpcTransaction` serialization. Passing non-default values.
#[rstest]
#[case(RpcTransaction::Declare(create_declare_v3()))]
#[case(RpcTransaction::DeployAccount(create_deploy_account_v3()))]
#[case(RpcTransaction::Invoke(create_invoke_v3()))]
#[case(rpc_invoke_tx(InvokeTxArgs {
resource_bounds: ValidResourceBounds::AllResources(create_resource_bounds_for_testing()),
tip: Tip(50),
calldata: Calldata(Arc::new(vec![felt!("0x2000"), felt!("0x1000")])),
sender_address: contract_address!("0x53"),
nonce: nonce!(32),
paymaster_data: PaymasterData(vec![Felt::TWO, Felt::ZERO]),
account_deployment_data: AccountDeploymentData(vec![felt!("0x87")]),
..Default::default()}))]
fn test_rpc_transactions(#[case] tx: RpcTransaction) {
let serialized = serde_json::to_string(&tx).unwrap();
let deserialized: RpcTransaction = serde_json::from_str(&serialized).unwrap();
Expand Down

0 comments on commit f87a869

Please sign in to comment.