diff --git a/test/basic-e2e.bats b/test/basic-e2e.bats index 2829b396..0428e3ac 100644 --- a/test/basic-e2e.bats +++ b/test/basic-e2e.bats @@ -11,7 +11,7 @@ setup() { } @test "Send EOA transaction" { - local initial_nonce=$(rpcQuery "nonce" "$senderAddr") || return 1 + local initial_nonce=$(cast nonce "$senderAddr" --rpc-url "$rpc_url") || return 1 local value="10ether" # case 1: Transaction successfull sernder has suffecient balance @@ -21,14 +21,14 @@ setup() { # case 2: Transaction rejected sender attempts to transfer more than they have in their wallet # Trx will fail pre validation check on the node and will be dropped subsequently from the pool - # without recording it on the chain and hence nonce will not change - local sender_balance=$(rpcQuery "balance" "--ether" "$senderAddr") || return 1 + # without recording it on the chain and hence nonce will not change + local sender_balance=$(cast balance "$senderAddr" --ether --rpc-url "$rpc_url") || return 1 local excessive_value="$(echo "$sender_balance + 1" | bc)ether" run sendTx "$private_key" "$receiver" "$excessive_value" assert_failure # check wheather nonce of sender was updated correctly or not - local final_nonce=$(rpcQuery "nonce" "$senderAddr") || return 1 + local final_nonce=$(cast nonce "$senderAddr" --rpc-url "$rpc_url") || return 1 assert_equal "$final_nonce" "$(echo "$initial_nonce + 1" | bc)" } diff --git a/test/helpers/common.bash b/test/helpers/common.bash index 85aa37e3..9a7cec47 100644 --- a/test/helpers/common.bash +++ b/test/helpers/common.bash @@ -94,9 +94,9 @@ function sendTx() { return 1 fi - # Check initial ether balance of sender and receiver - local sender_initial_balance=$(rpcQuery "balance" "$senderAddr" "--block latest") || return 1 - local receiver_initial_balance=$(rpcQuery "balance" "$account_addr" "--block latest") || return 1 + # Check initial ether balance of sender and receiver + local sender_initial_balance=$(cast balance "$senderAddr" --ether --rpc-url "$rpc_url") || return 1 + local receiver_initial_balance=$(cast balance "$account_addr" --ether --rpc-url "$rpc_url") || return 1 # Check if the first remaining argument is a numeric value (Ether to be transferred) @@ -149,12 +149,13 @@ function sendTx() { return 1 fi - sleep 7 - - checkTransactionSuccess "$senderAddr" "$receiver" "$value_or_function_sig" "$tx_hash" "$sender_initial_balance" "$receiver_initial_balance" - if [[ $? -ne 0 ]]; then - echo "Error: Balance not updated correctly." - return 1 + if [[ "$value_or_function_sig" =~ ^[0-9]+(ether)?$ ]]; then + sleep 7 + checkTransactionSuccess "$senderAddr" "$receiver" "$value_or_function_sig" "$tx_hash" "$sender_initial_balance" "$receiver_initial_balance" + if [[ $? -ne 0 ]]; then + echo "Error: Balance not updated correctly." + return 1 + fi fi echo "Transaction successful (transaction hash: '$tx_hash')" @@ -212,7 +213,7 @@ function rpcQuery() { # Use cast to perform a generic RPC call local response - response=$(cast --rpc-url "$rpc_url" "$method" "${params[@]}" 2>&1) + response=$(cast rpc "$method" "${params[@]}" --rpc-url "$rpc_url" 2>&1) # Check if the cast rpc command was successful if [[ $? -ne 0 ]]; then @@ -233,24 +234,23 @@ function checkTransactionSuccess() { local sender_initial_balance="$5" local receiver_initial_balance="$6" - local sender_final_balance=$(rpcQuery "balance" "$senderAddr" "--block latest") || return 1 + local sender_final_balance=$(cast balance "$senderAddr" --ether --rpc-url "$rpc_url") || return 1 local gas_used=$(cast tx "$tx_hash" --rpc-url "$rpc_url" | grep '^gas ' | awk '{print $2}') local gas_price=$(cast tx "$tx_hash" --rpc-url "$rpc_url" | grep '^gasPrice' | awk '{print $2}') local gas_fee=$(echo "$gas_used * $gas_price" | bc) - local sender_balance_change=$(echo "$sender_initial_balance - $sender_final_balance" | bc) + local gas_fee_in_ether=$(cast --from-unit wei --to-unit ether "$gas_fee") + local sender_balance_change=$(echo "$sender_initial_balance - $sender_final_balance" | bc) echo "Sender balance changed by: '$sender_balance_change' wei" echo "Gas fee paid: '$gas_fee' wei" - if [[ "$value_or_function_sig" =~ ^[0-9]+(ether)?$ ]]; then - local receiver_final_balance=$(rpcQuery "balance" "$receiver" "--block latest") || return 1 - local receiver_balance_change=$(echo "$receiver_final_balance - $receiver_initial_balance" | bc) - echo "Receiver balance changed by: `$receiver_balance_change` wei" - - value_in_wei=$(cast --to-unit wei "$value_or_function_sig") - assert_equal "$receiver_balance_chang" "$value_in_wei" "Error receiver balance updated incorrectly" - fi + local receiver_final_balance=$(cast balance "$receiver" --ether --rpc-url "$rpc_url") || return 1 + local receiver_balance_change=$(echo "$receiver_final_balance - $receiver_initial_balance" | bc) + echo "Receiver balance changed by: `$receiver_balance_change` wei" + # Trim 'ether' suffix from value_or_function_sig to get the numeric part + local value_in_ether=$(echo "$value_or_function_sig" | sed 's/ether$//') + assert_equal "$receiver_balance_chang" "$value_in_ether" "Error receiver balance updated incorrectly" # Asserts sender's balance change is equal to the value transferred plus the gas fee - assert_equal "$sender_balance_change" "$(echo "$value_in_wei + $gas_fee" | bc)" "Error sender balance updated incorrectly" + assert_equal "$sender_balance_change" "$(echo "$value_in_ether + $gas_fee" | bc)" "Error sender balance updated incorrectly" }