From 94f594b3dda1082b173e2daf930a6bdc12f1eceb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Negovanovi=C4=87?= Date: Mon, 9 Sep 2024 14:09:38 +0200 Subject: [PATCH] Send EOA transaction test basic --- test/basic-e2e.bats | 28 ++++++++++++++++++++++++++++ test/helpers/common.bash | 31 ++++++++++++++++++------------- 2 files changed, 46 insertions(+), 13 deletions(-) create mode 100644 test/basic-e2e.bats diff --git a/test/basic-e2e.bats b/test/basic-e2e.bats new file mode 100644 index 000000000..4a9bb278c --- /dev/null +++ b/test/basic-e2e.bats @@ -0,0 +1,28 @@ +setup() { + load '/usr/local/lib/bats/bats-support/load' + load '/usr/local/lib/bats/bats-assert/load' + + # get the containing directory of this file + # use $BATS_TEST_FILENAME instead of ${BASH_SOURCE[0]} or $0, + # as those will point to the bats executable's location or the preprocessed file respectively + DIR="$(cd "$(dirname "$BATS_TEST_FILENAME")" >/dev/null 2>&1 && pwd)" + # make executables in src/ visible to PATH + PATH="$DIR/../src:$PATH" + + readonly enclave=${ENCLAVE:-cdk-v1} + readonly node=${KURTOSIS_NODE:-cdk-erigon-node-001} + readonly rpc_url=${RPC_URL:-$(kurtosis port print "$enclave" "$node" http-rpc)} +} + +@test "Send EOA transaction" { + load 'helpers/common' + + local receiver="0x85dA99c8a7C2C95964c8EfD687E95E632Fc533D6" + local value="10ether" + local private_key="0x12d7de8621a77640c9241b2595ba78ce443d05e94090365ab3bb5e19df82c625" + + run sendTx $private_key $receiver $value + + assert_success + assert_output --partial 'Transaction successful!' +} diff --git a/test/helpers/common.bash b/test/helpers/common.bash index f728f39ed..d6609bd39 100644 --- a/test/helpers/common.bash +++ b/test/helpers/common.bash @@ -1,8 +1,7 @@ #!/usr/bin/env bash function deployContract() { - local rpc_url="$1" - local private_key="$2" - local contract_artifact="$3" + local private_key="$1" + local contract_artifact="$2" if [[ ! -f "$contract_artifact" ]]; then echo "Error: Contract artifact $contract_artifact does not exist." @@ -43,15 +42,14 @@ function deployContract() { function sendTx() { # Check if at least 3 arguments are provided if [[ $# -lt 3 ]]; then - echo "Usage: sendTx [ ...]" + echo "Usage: sendTx ] [ ...]" return 1 fi # Assign variables from function arguments - local rpc_url="$1" - local private_key="$2" - local receiver="$3" - shift 3 # Shift the first 3 arguments (rpc_url, private_key, receiver) + local private_key="$1" + local receiver="$2" + shift 2 # Shift the first 2 arguments (private_key, receiver) local first_remaining_arg="$1" shift # Shift the first remaining argument (value or function signature) @@ -63,26 +61,32 @@ function sendTx() { fi # Check if the first remaining argument is a numeric value (Ether to be transferred) - if [[ "$first_remaining_arg" =~ ^[0-9]+$ ]]; then + if [[ "$first_remaining_arg" =~ ^[0-9]+(ether)?$ ]]; then # Case: EOA transaction (Ether transfer) - echo "Sending Ether transaction to EOA: $receiver with value: $first_remaining_arg Wei" + echo "Sending EOA transaction (RPC URL: $rpc_url) to: $receiver with value: $first_remaining_arg" cast_output=$(cast send --rpc-url "$rpc_url" \ --private-key "$private_key" \ "$receiver" --value "$first_remaining_arg" \ + --legacy \ 2>&1) else # Case: Smart contract transaction (contract interaction with function signature and parameters) local functionSignature="$first_remaining_arg" local params=("$@") # Collect all remaining arguments as function parameters - echo "Sending smart contract transaction to $receiver with function signature: $functionSignature and params: ${params[*]}" + echo "Sending smart contract transaction (RPC URL: $rpc_url) to $receiver with function signature: $functionSignature and params: ${params[*]}" # Prepare the function signature with parameters for cast send cast_output=$(cast send --rpc-url "$rpc_url" \ --private-key "$private_key" \ "$receiver" "$functionSignature" "${params[@]}" \ + --legacy \ 2>&1) fi + # Print the cast output + echo "cast send output:" + echo "$cast_output" + # Check if the transaction was successful if [[ $? -ne 0 ]]; then echo "Error: Failed to send transaction. Output:" @@ -90,8 +94,9 @@ function sendTx() { return 1 fi - # Transaction was successful, extract and display the transaction hash - tx_hash=$(echo "$cast_output" | grep -oP '(?<=Transaction hash: )0x[a-fA-F0-9]+') + # Extract the transaction hash from the output + local tx_hash=$(echo "$cast_output" | grep 'transactionHash' | sed 's/transactionHash\s\+//') + echo "Tx hash: $tx_hash" if [[ -z "$tx_hash" ]]; then echo "Error: Failed to extract transaction hash."