diff --git a/CHANGELOG.md b/CHANGELOG.md index 33eabbe4e7..a43af7f018 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Next release +- dev: Implement tests for new rpc method starknet_getTransactionStatus - feat: actual estimate_fee added, brought back l1 messages and refactored simulate tx - dev: impl get_state_updates using get_transaction_re_execution_state_diff diff --git a/starknet-rpc-test/Cargo.toml b/starknet-rpc-test/Cargo.toml index 520cdf0c05..492e33a0b3 100644 --- a/starknet-rpc-test/Cargo.toml +++ b/starknet-rpc-test/Cargo.toml @@ -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" diff --git a/starknet-rpc-test/get_transaction_status.rs b/starknet-rpc-test/get_transaction_status.rs new file mode 100644 index 0000000000..ac3f34b3a0 --- /dev/null +++ b/starknet-rpc-test/get_transaction_status.rs @@ -0,0 +1,61 @@ +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 account = build_single_owner_account(&rpc, SIGNER_PRIVATE, ARGENT_CONTRACT_ADDRESS, true); + + let txs = { + let mut madara_write_lock = madara.write().await; + 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[0] { + Ok(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; + matches!(result, Ok(TransactionStatus::AcceptedOnL2(TransactionExecutionStatus::Succeeded))) + }, + 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(()) +} diff --git a/starknet-rpc-test/src/constants.rs b/starknet-rpc-test/src/constants.rs index 59d53259ab..31abe2b337 100644 --- a/starknet-rpc-test/src/constants.rs +++ b/starknet-rpc-test/src/constants.rs @@ -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"; @@ -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";