Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rachit77 committed Sep 17, 2024
1 parent 75a4d19 commit bc4a1a4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions test/basic-e2e.bats
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ setup() {
local sender_balance=$(rpcQuery "balance" "--ether" "$senderAddr") || return 1
local excessive_value=$(echo "$sender_balance + 1" | bc)ether
run sendTx "$private_key" "$receiver" "$excessive_value"
assert_failure "Transaction should fail when attempting to transfer more than the sender balance"
assert_failure

# check wheather nonce of sender was updated correctly or not
local final_nonce=$(rpcQuery "nonce" "$senderAddr") || return 1
assert_equal "$final_nonce" "$(echo "$initial_nonce + 1" | bc)" "Error nonce not updated correctly"
assert_equal "$final_nonce" "$(echo "$initial_nonce + 1" | bc)"
}

@test "Deploy ERC20Mock contract" {
Expand Down
16 changes: 8 additions & 8 deletions test/helpers/common.bash
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ function sendTx() {
fi

# Check initial ether balance of sender and receiver
local sender_initial_balance=$(rpcQuery "balance" "$senderAddr" "latest") || return 1
local receiver_initial_balance=$(rpcQuery "balance" "$account_addr" "latest") || return 1
local sender_initial_balance=$(rpcQuery "balance" "$senderAddr" "--block latest") || return 1
local receiver_initial_balance=$(rpcQuery "balance" "$account_addr" "--block latest") || return 1


# Check if the first remaining argument is a numeric value (Ether to be transferred)
Expand Down Expand Up @@ -155,7 +155,7 @@ function sendTx() {
return 1
fi

echo "Transaction successful (transaction hash: $tx_hash)"
echo "Transaction successful (transaction hash: '$tx_hash')"

return 0
}
Expand Down Expand Up @@ -231,19 +231,19 @@ function checkTransactionSuccess() {
local sender_initial_balance="$5"
local receiver_initial_balance="$6"

local sender_final_balance=$(rpcQuery "balance" "$senderAddr" "latest") || return 1
local sender_final_balance=$(rpcQuery "balance" "$senderAddr" "--block latest") || 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)

echo "Sender's balance changed by: $sender_balance_change wei"
echo "Gas fee paid: $gas_fee wei"
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" "latest") || return 1
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's balance changed by: $receiver_balance_change wei"
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."
Expand Down

0 comments on commit bc4a1a4

Please sign in to comment.