Skip to content
This repository has been archived by the owner on Aug 2, 2024. It is now read-only.

Commit

Permalink
Add rpc test starknet_getTransactionStatus
Browse files Browse the repository at this point in the history
  • Loading branch information
fishseabowl committed May 24, 2024
1 parent 003a0d6 commit 89f5011
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Next release

- dev: Implement tests for new rpc method starknet_getTransactionStatus
- dev: impl get_state_updates using get_transaction_re_execution_state_diff
- feat: support strk as fee token
- dev: pallet test for estimate_fee that skip validation
Expand Down
4 changes: 4 additions & 0 deletions starknet-rpc-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ path = "get_transaction_by_hash.rs"
name = "starknet_get_transaction_receipt"
path = "get_transaction_receipt.rs"

[[test]]
name = "starknet_get_transaction_status"
path = "get_transaction_status.rs"

[[test]]
name = "starknet_get_events"
path = "get_events.rs"
Expand Down
65 changes: 65 additions & 0 deletions starknet-rpc-test/get_transaction_status.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
use std::panic;

use assert_matches::assert_matches;
use rstest::rstest;
use starknet_core::types::{StarknetError, TransactionExecutionStatus, TransactionStatus};
use starknet_ff::FieldElement;
use starknet_providers::{Provider, ProviderError};
use starknet_rpc_test::constants::{ARGENT_CONTRACT_ADDRESS, SIGNER_PRIVATE};
use starknet_rpc_test::fixtures::{madara, ThreadSafeMadaraClient};
use starknet_rpc_test::utils::{assert_poll, build_single_owner_account, AccountActions};
use starknet_rpc_test::{Transaction, TransactionResult};

#[rstest]
#[tokio::test]
async fn work_with_valid_transaction_hash(madara: &ThreadSafeMadaraClient) -> Result<(), anyhow::Error> {
let rpc = madara.get_starknet_client().await;

let mut madara_write_lock = madara.write().await;
let account = build_single_owner_account(&rpc, SIGNER_PRIVATE, ARGENT_CONTRACT_ADDRESS, true);

let mut txs = madara_write_lock
.create_block_with_txs(vec![Transaction::Execution(account.transfer_tokens(
FieldElement::from_hex_be("0x123").unwrap(),
FieldElement::ONE,
None,
))])
.await?;

assert_eq!(txs.len(), 1);

let rpc_response = match txs.remove(0).unwrap() {
TransactionResult::Execution(rpc_response) => rpc_response,
_ => panic!("expected execution result"),
};

// There is a delay between the transaction being available at the client
// and the sealing of the block, hence sleeping for 1000ms and repeat 20 times
assert_poll(
|| async {
let result = rpc.get_transaction_status(rpc_response.transaction_hash).await;
match result {
Ok(TransactionStatus::AcceptedOnL2(TransactionExecutionStatus::Succeeded)) => true,
_ => false,
}
},
1000,
20,
)
.await;

Ok(())
}

#[rstest]
#[tokio::test]
async fn fail_with_invalid_transaction_hash(madara: &ThreadSafeMadaraClient) -> Result<(), anyhow::Error> {
let rpc = madara.get_starknet_client().await;

assert_matches!(
rpc.get_transaction_status(FieldElement::from_hex_be("0x123").unwrap()).await,
Err(ProviderError::StarknetError(StarknetError::TransactionHashNotFound))
);

Ok(())
}
4 changes: 2 additions & 2 deletions starknet-rpc-test/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub const MIN_AMOUNT: &str = "0x1";
pub const DEPLOY_ACCOUNT_COST: &str = "0xffffffff";
pub const MAX_U256: &str = "0xffffffffffffffffffffffffffffffff";

// Usefull class hashes
// Useful class hashes
pub const TEST_CONTRACT_CLASS_HASH: &str = "0x04c5efa8dc6f0554da51f125d04e379ac41153a8b837391083a8dc3771a33388";
pub const TOKEN_CLASS_HASH: &str = "0x10000";
pub const ACCOUNT_CONTRACT_CLASS_HASH: &str = "0x0279d77db761fba82e0054125a6fdb5f6baa6286fa3fb73450cc44d193c2d37f";
Expand All @@ -19,7 +19,7 @@ pub const ARGENT_ACCOUNT_CLASS_HASH_CAIRO_0: &str =
pub const CAIRO_1_ACCOUNT_CONTRACT_CLASS_HASH: &str =
"0x035ccefcf9d5656da623468e27e682271cd327af196785df99e7fee1436b6276";

// Usefull contract address
// Useful contract address
pub const SEQUENCER_CONTRACT_ADDRESS: &str = "0xdead";
pub const ACCOUNT_CONTRACT_ADDRESS: &str = "0x1";
pub const ARGENT_CONTRACT_ADDRESS: &str = "0x2";
Expand Down

0 comments on commit 89f5011

Please sign in to comment.