Skip to content

Commit

Permalink
test: 🧪 add tests
Browse files Browse the repository at this point in the history
tests on the first blocks, add block_min on others tests
  • Loading branch information
jbcaron committed Jan 29, 2024
1 parent 2384605 commit ea733b2
Showing 1 changed file with 122 additions and 4 deletions.
126 changes: 122 additions & 4 deletions unit_tests/tests/test_get_transaction_by_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ async fn fail_non_existing_transaction(clients: HashMap<String, JsonRpcClient<Ht
/// purpose: call getTransactionHash on INVOKE transaction.
/// success case: retrieve correct INVOKE transaction.
///
#[require(spec_version = "0.5.1")]
#[require(block_min = 50_000, spec_version = "0.5.1")]
#[rstest]
#[tokio::test]
async fn work_transaction_invoke(clients: HashMap<String, JsonRpcClient<HttpTransport>>) {
Expand All @@ -65,7 +65,7 @@ async fn work_transaction_invoke(clients: HashMap<String, JsonRpcClient<HttpTran
/// purpose: call getTransactionHash on L1_HANDLER transaction.
/// success case: retrieve correct INVOKE transaction.
///
#[require(spec_version = "0.5.1")]
#[require(block_min = 50_000, spec_version = "0.5.1")]
#[rstest]
#[tokio::test]
async fn work_transaction_l1_handler(clients: HashMap<String, JsonRpcClient<HttpTransport>>) {
Expand All @@ -92,7 +92,7 @@ async fn work_transaction_l1_handler(clients: HashMap<String, JsonRpcClient<Http
/// purpose: call getTransactionHash on DECLARE transaction.
/// success case: retrieve correct DECLARE transaction.
///
#[require(spec_version = "0.5.1")]
#[require(block_min = 49_990spec_version = "0.5.1")]
#[rstest]
#[tokio::test]
async fn work_transaction_declare(clients: HashMap<String, JsonRpcClient<HttpTransport>>) {
Expand Down Expand Up @@ -121,7 +121,7 @@ async fn work_transaction_declare(clients: HashMap<String, JsonRpcClient<HttpTra
/// purpose: call getTransactionHash on DEPLOY_ACCOUNT transaction.
/// success case: retrieve correct DEPLOY_ACCOUNT transaction.
///
#[require(spec_version = "0.5.1")]
#[require(block_min = 50_000, spec_version = "0.5.1")]
#[rstest]
#[tokio::test]
async fn work_transaction_deploy_account(clients: HashMap<String, JsonRpcClient<HttpTransport>>) {
Expand All @@ -141,3 +141,121 @@ async fn work_transaction_deploy_account(clients: HashMap<String, JsonRpcClient<
assert_matches!(response_deoxys, Transaction::DeployAccount(_));
assert_eq!(response_deoxys, response_pathfinder);
}

/// helper function for testing transaction by hash
async fn work_with_hash(
deoxys: JsonRpcClient<HttpTransport>,
pathfinder: JsonRpcClient<HttpTransport>,
transaction_hash: &str,
) {
let transaction_hash =
FieldElement::from_hex_be(transaction_hash).expect("Error parsing transaction hash");

let response_deoxys = deoxys
.get_transaction_by_hash(transaction_hash)
.await
.expect("Error waiting for response from Deoxys node");

let response_pathfinder = pathfinder
.get_transaction_by_hash(transaction_hash)
.await
.expect("Error waiting for response from Pathfinder node");

assert_eq!(response_deoxys, response_pathfinder);
}

/// first transaction on block 0
#[require(spec_version = "0.5.1")]
#[rstest]
#[tokio::test]
async fn work_with_first_transaction_block_0(
deoxys: JsonRpcClient<HttpTransport>,
pathfinder: JsonRpcClient<HttpTransport>,
) {
work_with_hash(
deoxys,
pathfinder,
"0xe0a2e45a80bb827967e096bcf58874f6c01c191e0a0530624cba66a508ae75",
)
.await;
}

/// deploy transaction on block 0
#[require(spec_version = "0.5.1")]
#[rstest]
#[tokio::test]
async fn work_with_deploy_transaction_block_0(
deoxys: JsonRpcClient<HttpTransport>,
pathfinder: JsonRpcClient<HttpTransport>,
) {
work_with_hash(
deoxys,
pathfinder,
"0x12c96ae3c050771689eb261c9bf78fac2580708c7f1f3d69a9647d8be59f1e1",
)
.await;
}

/// invoke transaction on block 0
#[require(spec_version = "0.5.1")]
#[rstest]
#[tokio::test]
async fn work_with_invoke_transaction_block_0(
deoxys: JsonRpcClient<HttpTransport>,
pathfinder: JsonRpcClient<HttpTransport>,
) {
work_with_hash(
deoxys,
pathfinder,
"0xce54bbc5647e1c1ea4276c01a708523f740db0ff5474c77734f73beec2624",
)
.await;
}

/// deploy transaction on block 1
#[require(block_min = 1, spec_version = "0.5.1")]
#[rstest]
#[tokio::test]
async fn work_with_deploy_transaction_block_1(
deoxys: JsonRpcClient<HttpTransport>,
pathfinder: JsonRpcClient<HttpTransport>,
) {
work_with_hash(
deoxys,
pathfinder,
"0x2f07a65f9f7a6445b2a0b1fb90ef12f5fd3b94128d06a67712efd3b2f163533",
)
.await;
}

/// invoke transaction on block 0
#[require(block_min = 10, spec_version = "0.5.1")]
#[rstest]
#[tokio::test]
async fn work_with_invoke_transaction_block_10(
deoxys: JsonRpcClient<HttpTransport>,
pathfinder: JsonRpcClient<HttpTransport>,
) {
work_with_hash(
deoxys,
pathfinder,
"0x50398c6ec05a07642e5bd52c656e1650f3b057361283ecbb19d4062199e4626",
)
.await;
}

/// deploy transaction on block 10
#[require(block_min = 10, spec_version = "0.5.1")]
#[rstest]
#[tokio::test]
async fn work_with_deploy_transaction_block_10(
deoxys: JsonRpcClient<HttpTransport>,
pathfinder: JsonRpcClient<HttpTransport>,
) {
work_with_hash(
deoxys,
pathfinder,
"0x6eac388fc0a464285ea3c7ca79ddff73217b5466e97ac5415cf6548934dce82",
)
.await;
}

0 comments on commit ea733b2

Please sign in to comment.