From 02c6cdb462208dad89019b699df3cc7d0a995809 Mon Sep 17 00:00:00 2001 From: jbcaron Date: Thu, 11 Jan 2024 16:10:24 +0100 Subject: [PATCH 1/2] test: :test_tube: add tests for getTransactionReceipt --- .../tests/test_get_transaction_receipt.rs | 132 ++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100644 unit_tests/tests/test_get_transaction_receipt.rs diff --git a/unit_tests/tests/test_get_transaction_receipt.rs b/unit_tests/tests/test_get_transaction_receipt.rs new file mode 100644 index 0000000..50496ae --- /dev/null +++ b/unit_tests/tests/test_get_transaction_receipt.rs @@ -0,0 +1,132 @@ +#![feature(assert_matches)] + +mod common; +use common::*; + +use std::{assert_matches::assert_matches, collections::HashMap}; + +use starknet_core::types::{FieldElement, StarknetError}; +use starknet_providers::{ + jsonrpc::{HttpTransport, JsonRpcClient}, + MaybeUnknownErrorCode, Provider, ProviderError, StarknetErrorWithMessage, +}; + +// invalid transaction_hash +#[rstest] +#[tokio::test] +async fn fail_invalid_transaction_hash(clients: HashMap>) { + let deoxys = &clients[DEOXYS]; + + let response_deoxys = deoxys + .get_transaction_receipt(FieldElement::ZERO) + .await + .err(); + + assert_matches!( + response_deoxys, + Some(ProviderError::StarknetError(StarknetErrorWithMessage { + message: _, + code: MaybeUnknownErrorCode::Known(StarknetError::TransactionHashNotFound) + })) + ); +} + +/// reverted transaction on block 200000 +#[rstest] +#[tokio::test] +async fn work_with_rejected_transaction(clients: HashMap>) { + let deoxys = &clients[DEOXYS]; + let pathfinder = &clients[PATHFINDER]; + + let transaction_hash = FieldElement::from_hex_be( + "0x410e4d74a2322b78d2e342ac376ea555c89b1a0fe73bb36067eb149da123dd1", + ) + .expect("Error parsing transaction hash"); + + let response_deoxys = deoxys + .get_transaction_receipt(transaction_hash) + .await + .expect("Error waiting for response from Deoxys node"); + + let response_pathfinder = pathfinder + .get_transaction_receipt(transaction_hash) + .await + .expect("Error waiting for response from Pathfinder node"); + + assert_eq!(response_deoxys, response_pathfinder); +} + +/// first transaction on block 0 +#[rstest] +#[tokio::test] +async fn work_with_first_transaction(clients: HashMap>) { + let deoxys = &clients[DEOXYS]; + let pathfinder = &clients[PATHFINDER]; + + let transaction_hash = FieldElement::from_hex_be( + "0xe0a2e45a80bb827967e096bcf58874f6c01c191e0a0530624cba66a508ae75", + ) + .expect("Error parsing transaction hash"); + + let response_deoxys = deoxys + .get_transaction_receipt(transaction_hash) + .await + .expect("Error waiting for response from Deoxys node"); + + let response_pathfinder = pathfinder + .get_transaction_receipt(transaction_hash) + .await + .expect("Error waiting for response from Pathfinder node"); + + assert_eq!(response_deoxys, response_pathfinder); +} + +/// deploy transaction +#[rstest] +#[tokio::test] +async fn work_with_deploy(clients: HashMap>) { + let deoxys = &clients[DEOXYS]; + let pathfinder = &clients[PATHFINDER]; + + let transaction_hash = FieldElement::from_hex_be( + "0x12c96ae3c050771689eb261c9bf78fac2580708c7f1f3d69a9647d8be59f1e1", + ) + .expect("Error parsing transaction hash"); + + let response_deoxys = deoxys + .get_transaction_receipt(transaction_hash) + .await + .expect("Error waiting for response from Deoxys node"); + + let response_pathfinder = pathfinder + .get_transaction_receipt(transaction_hash) + .await + .expect("Error waiting for response from Pathfinder node"); + + assert_eq!(response_deoxys, response_pathfinder); +} + +///invoke transaction +#[rstest] +#[tokio::test] +async fn work_with_invoke(clients: HashMap>) { + let deoxys = &clients[DEOXYS]; + let pathfinder = &clients[PATHFINDER]; + + let transaction_hash = FieldElement::from_hex_be( + "0xce54bbc5647e1c1ea4276c01a708523f740db0ff5474c77734f73beec2624", + ) + .expect("Error parsing transaction hash"); + + let response_deoxys = deoxys + .get_transaction_receipt(transaction_hash) + .await + .expect("Error waiting for response from Deoxys node"); + + let response_pathfinder = pathfinder + .get_transaction_receipt(transaction_hash) + .await + .expect("Error waiting for response from Pathfinder node"); + + assert_eq!(response_deoxys, response_pathfinder); +} \ No newline at end of file From 3fe0ab5a2f6a70f728f1fc6342af5ef3661d75aa Mon Sep 17 00:00:00 2001 From: jbcaron Date: Thu, 11 Jan 2024 17:40:44 +0100 Subject: [PATCH 2/2] style: :lipstick: add new line at the end of file --- unit_tests/tests/test_get_transaction_receipt.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unit_tests/tests/test_get_transaction_receipt.rs b/unit_tests/tests/test_get_transaction_receipt.rs index 50496ae..9909698 100644 --- a/unit_tests/tests/test_get_transaction_receipt.rs +++ b/unit_tests/tests/test_get_transaction_receipt.rs @@ -129,4 +129,4 @@ async fn work_with_invoke(clients: HashMap> .expect("Error waiting for response from Pathfinder node"); assert_eq!(response_deoxys, response_pathfinder); -} \ No newline at end of file +}