Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rpc test starknet_getTransactionStatus #1610

Merged
merged 4 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
- 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
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
61 changes: 61 additions & 0 deletions starknet-rpc-test/get_transaction_status.rs
Original file line number Diff line number Diff line change
@@ -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(())
}
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
Loading