From bbe5ed1306803930daa6619d9c613cb6201ab9fe Mon Sep 17 00:00:00 2001 From: Rachit Sonthalia Date: Thu, 19 Sep 2024 15:00:28 +0530 Subject: [PATCH 01/15] feat: sc tests --- test/basic-e2e.bats | 88 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 77 insertions(+), 11 deletions(-) diff --git a/test/basic-e2e.bats b/test/basic-e2e.bats index 7124dcc2..678f9130 100644 --- a/test/basic-e2e.bats +++ b/test/basic-e2e.bats @@ -7,7 +7,8 @@ setup() { readonly node=${KURTOSIS_NODE:-cdk-erigon-node-001} readonly rpc_url=${RPC_URL:-$(kurtosis port print "$enclave" "$node" http-rpc)} readonly private_key=${SENDER_PRIVATE_KEY:-"12d7de8621a77640c9241b2595ba78ce443d05e94090365ab3bb5e19df82c625"} - readonly receiver=${RECEIVER:-"0x85dA99c8a7C2C95964c8EfD687E95E632Fc533D6"} + readonly receiver_private_key=${RECEIVER_PRIVATE_KEY:-"14b34448b61f2b1599a37aaf3eecbc4e6f4955b19396f99c9ac00374966e84b9"} + readonly receiver=${RECEIVER:-"0x5C053Dd37650d8BEdf3f44232B1d1A3adc2b14B8"} } @test "Send EOA transaction" { @@ -35,8 +36,12 @@ setup() { @test "Deploy ERC20Mock contract" { local contract_artifact="./contracts/erc20mock/ERC20Mock.json" + wallet_A_output=$(cast wallet new) + address_A=$(echo "$wallet_A_output" | grep "Address" | awk '{print $2}') + address_A_private_key=$(echo "$wallet_A_output" | grep "Private key" | awk '{print $3}') + address_B=$(cast wallet new | grep "Address" | awk '{print $2}') - # Deploy ERC20Mock + ## Case 1: An address deploy ERC20Mock contract => Transaction successful run deployContract "$private_key" "$contract_artifact" assert_success contract_addr=$(echo "$output" | tail -n 1) @@ -45,20 +50,81 @@ setup() { local mintFnSig="function mint(address receiver, uint256 amount)" local amount="5" - run sendTx "$private_key" "$contract_addr" "$mintFnSig" "$receiver" "$amount" + run sendTx "$private_key" "$contract_addr" "$mintFnSig" "$address_A" "$amount" assert_success assert_output --regexp "Transaction successful \(transaction hash: 0x[a-fA-F0-9]{64}\)" - # Assert that balance is correct + ## Case 2: Insufficient gas scenario => Transactions fails + # Get bytecode from the contract artifact + local bytecode=$(jq -r .bytecode "$contract_artifact") + if [[ -z "$bytecode" || "$bytecode" == "null" ]]; then + echo "Error: Failed to read bytecode from $contract_artifact" + return 1 + fi + + # Estimate gas,gas price and gas cost + local gas_units=$(cast estimate --create "$bytecode") + local gas_price=$(cast gas-price) + local value=$(echo "$gas_units * $gas_price - 20000" | bc) + local value_ether=$(cast to-unit "$value" ether)"ether" + + # Transfer insufficient funds + cast_output=$(cast send --rpc-url "$rpc_url" --private-key "$private_key" "$address_A" --value "$value_ether" --legacy 2>&1) + if [[ $? -ne 0 ]]; then + echo "Error: Failed to send transaction. Output:" + echo "$cast_output" + return 1 + fi + + # Fetch initial nonce for address_A + local address_A_initial_nonce=$(cast nonce "$address_A" --rpc-url "$rpc_url") || return 1 + # Attempt to deploy contract with insufficient gas + run deployContract "$address_A_private_key" "$contract_artifact" + assert_failure + + ## Case 3: Transaction should fail as address_A tries to transfer more tokens than it has + # Transfer funds for gas fees to address_A + value_ether="4ether" + cast_output=$(cast send --rpc-url "$rpc_url" --private-key "$private_key" "$address_A" --value "$value_ether" --legacy 2>&1) + if [[ $? -ne 0 ]]; then + echo "Error: Failed to send transaction. Output:" + echo "$cast_output" + return 1 + fi + + # Fetch balance of address_A to simulate excessive transfer local balanceOfFnSig="function balanceOf(address) (uint256)" - run queryContract "$contract_addr" "$balanceOfFnSig" "$receiver" + run queryContract "$contract_addr" "$balanceOfFnSig" "$address_A" + assert_success + local address_A_Balance=$(echo "$output" | tail -n 1) + address_A_Balance=$(echo "$address_A_Balance" | xargs) + + # Set excessive amount for transfer + local excessive_amount=$(echo "$address_A_Balance + 1" | bc) + + # Attempt transfer of excessive amount from address_A to address_B + local tranferFnSig="function transfer(address receiver, uint256 amount)" + run sendTx "$address_A_private_key" "$contract_addr" "$tranferFnSig" "$address_B" "$excessive_amount" + assert_failure + + # Verify balance of address_A after failed transaction + run queryContract "$contract_addr" "$balanceOfFnSig" "$address_A" + assert_success + address_A_BalanceAfterFailedTx=$(echo "$output" | tail -n 1) + address_A_BalanceAfterFailedTx=$(echo "$address_A_BalanceAfterFailedTx" | xargs) + + # Ensure balance is unchanged + assert_equal "$address_A_BalanceAfterFailedTx" "$address_A_Balance" + + # Verify balance of address_B is still zero + run queryContract "$contract_addr" "$balanceOfFnSig" "$address_B" assert_success - receiverBalance=$(echo "$output" | tail -n 1) + local address_B_Balance=$(echo "$output" | tail -n 1) + address_B_Balance=$(echo "$address_B_Balance" | xargs) - # Convert balance and amount to a standard format for comparison (e.g., remove any leading/trailing whitespace) - receiverBalance=$(echo "$receiverBalance" | xargs) - amount=$(echo "$amount" | xargs) + assert_equal "$address_B_Balance" "0" - # Check if the balance is equal to the amount - assert_equal "$receiverBalance" "$amount" + # Check if nonce increased by 2 + local address_A_final_nonce=$(cast nonce "$address_A" --rpc-url "$rpc_url") || return 1 + assert_equal "$address_A_final_nonce" "$(echo "$address_A_initial_nonce + 2" | bc)" } From 337bd91b87758d40693a89dd5fb9072c30852532 Mon Sep 17 00:00:00 2001 From: Rachit Sonthalia Date: Fri, 20 Sep 2024 19:33:28 +0530 Subject: [PATCH 02/15] fix: tests --- test/basic-e2e.bats | 39 ++++++++++++++++++++------------------- test/helpers/common.bash | 23 ++++++++--------------- 2 files changed, 28 insertions(+), 34 deletions(-) diff --git a/test/basic-e2e.bats b/test/basic-e2e.bats index 678f9130..c104f2c5 100644 --- a/test/basic-e2e.bats +++ b/test/basic-e2e.bats @@ -6,18 +6,18 @@ setup() { 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)} - readonly private_key=${SENDER_PRIVATE_KEY:-"12d7de8621a77640c9241b2595ba78ce443d05e94090365ab3bb5e19df82c625"} + readonly sender_private_key=${SENDER_PRIVATE_KEY:-"12d7de8621a77640c9241b2595ba78ce443d05e94090365ab3bb5e19df82c625"} readonly receiver_private_key=${RECEIVER_PRIVATE_KEY:-"14b34448b61f2b1599a37aaf3eecbc4e6f4955b19396f99c9ac00374966e84b9"} readonly receiver=${RECEIVER:-"0x5C053Dd37650d8BEdf3f44232B1d1A3adc2b14B8"} } @test "Send EOA transaction" { - local sender_addr=$(cast wallet address --private-key "$private_key") + local sender_addr=$(cast wallet address --private-key "$sender_private_key") local initial_nonce=$(cast nonce "$sender_addr" --rpc-url "$rpc_url") || return 1 local value="10ether" # case 1: Transaction successful sender has sufficient balance - run sendTx "$private_key" "$receiver" "$value" + run sendTx "$sender_private_key" "$receiver" "$value" assert_success assert_output --regexp "Transaction successful \(transaction hash: 0x[a-fA-F0-9]{64}\)" @@ -26,7 +26,7 @@ setup() { # without recording it on the chain and hence nonce will not change local sender_balance=$(cast balance "$sender_addr" --ether --rpc-url "$rpc_url") || return 1 local excessive_value=$(echo "$sender_balance + 1" | bc)"ether" - run sendTx "$private_key" "$receiver" "$excessive_value" + run sendTx "$sender_private_key" "$receiver" "$excessive_value" assert_failure # Check whether the sender's nonce was updated correctly @@ -34,7 +34,7 @@ setup() { assert_equal "$final_nonce" "$(echo "$initial_nonce + 1" | bc)" } -@test "Deploy ERC20Mock contract" { +@test "Test ERC20Mock contract" { local contract_artifact="./contracts/erc20mock/ERC20Mock.json" wallet_A_output=$(cast wallet new) address_A=$(echo "$wallet_A_output" | grep "Address" | awk '{print $2}') @@ -42,15 +42,15 @@ setup() { address_B=$(cast wallet new | grep "Address" | awk '{print $2}') ## Case 1: An address deploy ERC20Mock contract => Transaction successful - run deployContract "$private_key" "$contract_artifact" + run deployContract "$sender_private_key" "$contract_artifact" assert_success contract_addr=$(echo "$output" | tail -n 1) # Mint ERC20 tokens - local mintFnSig="function mint(address receiver, uint256 amount)" + local mintFnSig="mint(address,uint256)" local amount="5" - run sendTx "$private_key" "$contract_addr" "$mintFnSig" "$address_A" "$amount" + run sendTx "$sender_private_key" "$contract_addr" "$mintFnSig" "$address_A" "$amount" assert_success assert_output --regexp "Transaction successful \(transaction hash: 0x[a-fA-F0-9]{64}\)" @@ -62,14 +62,15 @@ setup() { return 1 fi - # Estimate gas,gas price and gas cost - local gas_units=$(cast estimate --create "$bytecode") - local gas_price=$(cast gas-price) - local value=$(echo "$gas_units * $gas_price - 20000" | bc) + # Estimate gas, gas price and gas cost + local gas_units=$(cast estimate --rpc-url "$rpc_url" --create "$bytecode") + gas_units=$(echo "scale=0; $gas_units / 2" | bc) + local gas_price=$(cast gas-price --rpc-url "$rpc_url") + local value=$(echo "$gas_units * $gas_price" | bc) local value_ether=$(cast to-unit "$value" ether)"ether" # Transfer insufficient funds - cast_output=$(cast send --rpc-url "$rpc_url" --private-key "$private_key" "$address_A" --value "$value_ether" --legacy 2>&1) + cast_output=$(cast send --rpc-url "$rpc_url" --private-key "$sender_private_key" "$address_A" --value "$value_ether" --legacy 2>&1) if [[ $? -ne 0 ]]; then echo "Error: Failed to send transaction. Output:" echo "$cast_output" @@ -85,7 +86,7 @@ setup() { ## Case 3: Transaction should fail as address_A tries to transfer more tokens than it has # Transfer funds for gas fees to address_A value_ether="4ether" - cast_output=$(cast send --rpc-url "$rpc_url" --private-key "$private_key" "$address_A" --value "$value_ether" --legacy 2>&1) + cast_output=$(cast send --rpc-url "$rpc_url" --private-key "$sender_private_key" "$address_A" --value "$value_ether" --legacy 2>&1) if [[ $? -ne 0 ]]; then echo "Error: Failed to send transaction. Output:" echo "$cast_output" @@ -93,7 +94,7 @@ setup() { fi # Fetch balance of address_A to simulate excessive transfer - local balanceOfFnSig="function balanceOf(address) (uint256)" + local balanceOfFnSig="balanceOf(address) (uint256)" run queryContract "$contract_addr" "$balanceOfFnSig" "$address_A" assert_success local address_A_Balance=$(echo "$output" | tail -n 1) @@ -103,9 +104,9 @@ setup() { local excessive_amount=$(echo "$address_A_Balance + 1" | bc) # Attempt transfer of excessive amount from address_A to address_B - local tranferFnSig="function transfer(address receiver, uint256 amount)" + local tranferFnSig="transfer(address,uint256)" run sendTx "$address_A_private_key" "$contract_addr" "$tranferFnSig" "$address_B" "$excessive_amount" - assert_failure + #assert_failure # Verify balance of address_A after failed transaction run queryContract "$contract_addr" "$balanceOfFnSig" "$address_A" @@ -124,7 +125,7 @@ setup() { assert_equal "$address_B_Balance" "0" - # Check if nonce increased by 2 + # Check if nonce increased by 1 local address_A_final_nonce=$(cast nonce "$address_A" --rpc-url "$rpc_url") || return 1 - assert_equal "$address_A_final_nonce" "$(echo "$address_A_initial_nonce + 2" | bc)" + assert_equal "$address_A_final_nonce" "$(echo "$address_A_initial_nonce + 1" | bc)" } diff --git a/test/helpers/common.bash b/test/helpers/common.bash index aabae0b6..10edfb21 100644 --- a/test/helpers/common.bash +++ b/test/helpers/common.bash @@ -96,18 +96,18 @@ function sendTx() { return 1 } - # Get initial ether balances of sender and receiver - local sender_initial_balance receiver_initial_balance - sender_initial_balance=$(cast balance "$sender_addr" --ether --rpc-url "$rpc_url") || return 1 - receiver_initial_balance=$(cast balance "$receiver_addr" --ether --rpc-url "$rpc_url") || return 1 - # Check if the value_or_function_sig is a numeric value (Ether to be transferred) if [[ "$value_or_function_sig" =~ ^[0-9]+(\.[0-9]+)?(ether)?$ ]]; then # Case: Ether transfer (EOA transaction) + # Get initial ether balances of sender and receiver + local sender_initial_balance receiver_initial_balance + sender_initial_balance=$(cast balance "$sender_addr" --ether --rpc-url "$rpc_url") || return 1 + receiver_initial_balance=$(cast balance "$receiver_addr" --ether --rpc-url "$rpc_url") || return 1 + send_eoa_transaction "$private_key" "$receiver_addr" "$value_or_function_sig" "$sender_addr" "$sender_initial_balance" "$receiver_initial_balance" else # Case: Smart contract interaction (contract interaction with function signature and parameters) - send_smart_contract_transaction "$private_key" "$receiver_addr" "$value_or_function_sig" "$sender_addr" "${params[@]}" + send_smart_contract_transaction "$private_key" "$receiver_addr" "$value_or_function_sig" "${params[@]}" fi } @@ -149,21 +149,14 @@ function send_smart_contract_transaction() { local private_key="$1" local receiver_addr="$2" local function_sig="$3" - local sender_addr="$4" - shift 4 + shift 3 local params=("$@") - # Verify if the function signature starts with "function" - if [[ ! "$function_sig" =~ ^function\ .+\(.+\)$ ]]; then - echo "Error: Invalid function signature format '$function_sig'." - return 1 - fi - echo "Sending smart contract transaction to $receiver_addr with function signature: '$function_sig' and params: ${params[*]}" >&3 # Send the smart contract interaction using cast local cast_output tx_hash - cast_output=$(cast send --rpc-url "$rpc_url" --private-key "$private_key" "$receiver_addr" "$function_sig" "${params[@]}" --legacy 2>&1) + cast_output=$(cast send "$receiver_addr" --rpc-url "$rpc_url" --private-key "$private_key" --legacy "$function_sig" "${params[@]}" 2>&1) if [[ $? -ne 0 ]]; then echo "Error: Failed to send transaction. Output:" echo "$cast_output" From 38d79db0d08a745c032a8b3481fd674b2ff7539e Mon Sep 17 00:00:00 2001 From: Rachit Sonthalia Date: Fri, 20 Sep 2024 21:25:53 +0530 Subject: [PATCH 03/15] fix: test --- test/basic-e2e.bats | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/basic-e2e.bats b/test/basic-e2e.bats index c104f2c5..9f374436 100644 --- a/test/basic-e2e.bats +++ b/test/basic-e2e.bats @@ -55,6 +55,7 @@ setup() { assert_output --regexp "Transaction successful \(transaction hash: 0x[a-fA-F0-9]{64}\)" ## Case 2: Insufficient gas scenario => Transactions fails + # nonce would not increase since transaction fails at the node's pre-validation check # Get bytecode from the contract artifact local bytecode=$(jq -r .bytecode "$contract_artifact") if [[ -z "$bytecode" || "$bytecode" == "null" ]]; then @@ -84,6 +85,7 @@ setup() { assert_failure ## Case 3: Transaction should fail as address_A tries to transfer more tokens than it has + # nonce would not increase # Transfer funds for gas fees to address_A value_ether="4ether" cast_output=$(cast send --rpc-url "$rpc_url" --private-key "$sender_private_key" "$address_A" --value "$value_ether" --legacy 2>&1) @@ -125,7 +127,7 @@ setup() { assert_equal "$address_B_Balance" "0" - # Check if nonce increased by 1 + # Nonce should not increase local address_A_final_nonce=$(cast nonce "$address_A" --rpc-url "$rpc_url") || return 1 - assert_equal "$address_A_final_nonce" "$(echo "$address_A_initial_nonce + 1" | bc)" + assert_equal "$address_A_final_nonce" "$address_A_initial_nonce" } From 76e5afcc6cfcd889791b91c2d12d1f18a10948f8 Mon Sep 17 00:00:00 2001 From: Rachit Sonthalia Date: Fri, 20 Sep 2024 23:34:26 +0530 Subject: [PATCH 04/15] feat: more tests --- .github/workflows/test-e2e.yml | 6 +++++ test/basic-e2e.bats | 44 +++++++++++++++++++++++++++++++++- 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test-e2e.yml b/.github/workflows/test-e2e.yml index b20bb982..e26807b3 100644 --- a/.github/workflows/test-e2e.yml +++ b/.github/workflows/test-e2e.yml @@ -48,6 +48,12 @@ jobs: pip3 install yq yq --version + - name: Install polycli + run: | + tmp_dir=$(mktemp -d) && curl -L https://github.com/0xPolygon/polygon-cli/releases/download/v0.1.48/polycli_v0.1.48_linux_amd64.tar.gz | tar -xz -C "$tmp_dir" && mv "$tmp_dir"/* /usr/local/bin/polycli && rm -rf "$tmp_dir" + sudo chmod +x /usr/local/bin/polycli + /usr/local/bin/polycli version + - name: Install foundry uses: foundry-rs/foundry-toolchain@v1 diff --git a/test/basic-e2e.bats b/test/basic-e2e.bats index 9f374436..e16dd95d 100644 --- a/test/basic-e2e.bats +++ b/test/basic-e2e.bats @@ -108,7 +108,7 @@ setup() { # Attempt transfer of excessive amount from address_A to address_B local tranferFnSig="transfer(address,uint256)" run sendTx "$address_A_private_key" "$contract_addr" "$tranferFnSig" "$address_B" "$excessive_amount" - #assert_failure + assert_failure # Verify balance of address_A after failed transaction run queryContract "$contract_addr" "$balanceOfFnSig" "$address_A" @@ -131,3 +131,45 @@ setup() { local address_A_final_nonce=$(cast nonce "$address_A" --rpc-url "$rpc_url") || return 1 assert_equal "$address_A_final_nonce" "$address_A_initial_nonce" } + + +@test "Deploy and test UniswapV3 contract" { + run polycli loadtest uniswapv3 --legacy --rpc-url $rpc_url --private-key $sender_private_key + + assert_success + + # Check if the WETH9 contract were deployed + assert_output --regexp "Contract deployed address=0x[a-fA-F0-9]{40} name=WETH9" + assert_output --regexp "Contract deployed address=0x[a-fA-F0-9]{40} name=UniswapV3Factory" + assert_output --regexp "Contract deployed address=0x[a-fA-F0-9]{40} name=UniswapInterfaceMulticall" + assert_output --regexp "Contract deployed address=0x[a-fA-F0-9]{40} name=ProxyAdmin" + assert_output --regexp "Contract deployed address=0x[a-fA-F0-9]{40} name=TickLens" + assert_output --regexp "Contract deployed address=0x[a-fA-F0-9]{40} name=NFTDescriptor" + assert_output --regexp "Contract deployed address=0x[a-fA-F0-9]{40} name=NonfungibleTokenPositionDescriptor" + assert_output --regexp "Contract deployed address=0x[a-fA-F0-9]{40} name=TransparentUpgradeableProxy" + assert_output --regexp "Contract deployed address=0x[a-fA-F0-9]{40} name=NonfungiblePositionManager" + assert_output --regexp "Contract deployed address=0x[a-fA-F0-9]{40} name=V3Migrator" + assert_output --regexp "Contract deployed address=0x[a-fA-F0-9]{40} name=UniswapV3Staker" + assert_output --regexp "Contract deployed address=0x[a-fA-F0-9]{40} name=QuoterV2" + assert_output --regexp "Contract deployed address=0x[a-fA-F0-9]{40} name=SwapRouter02" + + assert_output --regexp "UniswapV3 deployed addresses={\"FactoryV3\":\"0x[a-fA-F0-9]{40}\".*}" + + # Check if ERC20 tokens were minted + assert_output --regexp "Minted tokens amount=[0-9]+ recipient=0x[a-fA-F0-9]{40} token=SwapperA" + assert_output --regexp "Minted tokens amount=[0-9]+ recipient=0x[a-fA-F0-9]{40} token=SwapperB" + + # Check if liquidity pool was created and initialized + assert_output --regexp "Pool created and initialized fees=[0-9]+" + + # Check if liquidity was provided to the pool + assert_output --regexp "Liquidity provided to the pool liquidity=[0-9]+" + + # Check if transaction got executed successfully + assert_output --regexp "Starting main load test loop currentNonce=[0-9]+" + assert_output --regexp "Finished main load test loop lastNonce=[0-9]+ startNonce=[0-9]+" + assert_output --regexp "Got final block number currentNonce=[0-9]+ final block number=[0-9]+" + assert_output --regexp "Num errors numErrors=0" + assert_output --regexp "Finished" +} + From c2a62e69b4bf2f1c6cca32fbac76032a5a4ea863 Mon Sep 17 00:00:00 2001 From: Rachit Sonthalia Date: Sat, 21 Sep 2024 00:17:11 +0530 Subject: [PATCH 05/15] fix: tests --- test/basic-e2e.bats | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/basic-e2e.bats b/test/basic-e2e.bats index e16dd95d..dd288bc1 100644 --- a/test/basic-e2e.bats +++ b/test/basic-e2e.bats @@ -134,10 +134,13 @@ setup() { @test "Deploy and test UniswapV3 contract" { - run polycli loadtest uniswapv3 --legacy --rpc-url $rpc_url --private-key $sender_private_key + run polycli loadtest uniswapv3 --legacy -v 600 --rpc-url $rpc_url --private-key $sender_private_key assert_success + # Remove ANSI escape codes from the output + output=$(echo "$output" | sed -r "s/\x1B\[[0-9;]*[mGKH]//g") + # Check if the WETH9 contract were deployed assert_output --regexp "Contract deployed address=0x[a-fA-F0-9]{40} name=WETH9" assert_output --regexp "Contract deployed address=0x[a-fA-F0-9]{40} name=UniswapV3Factory" From 2b19636722a6d512563c1e3be0e341c484a74f18 Mon Sep 17 00:00:00 2001 From: Rachit Sonthalia Date: Sat, 21 Sep 2024 00:46:38 +0530 Subject: [PATCH 06/15] fix: tests --- test/basic-e2e.bats | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/basic-e2e.bats b/test/basic-e2e.bats index dd288bc1..f3ed1656 100644 --- a/test/basic-e2e.bats +++ b/test/basic-e2e.bats @@ -156,8 +156,6 @@ setup() { assert_output --regexp "Contract deployed address=0x[a-fA-F0-9]{40} name=QuoterV2" assert_output --regexp "Contract deployed address=0x[a-fA-F0-9]{40} name=SwapRouter02" - assert_output --regexp "UniswapV3 deployed addresses={\"FactoryV3\":\"0x[a-fA-F0-9]{40}\".*}" - # Check if ERC20 tokens were minted assert_output --regexp "Minted tokens amount=[0-9]+ recipient=0x[a-fA-F0-9]{40} token=SwapperA" assert_output --regexp "Minted tokens amount=[0-9]+ recipient=0x[a-fA-F0-9]{40} token=SwapperB" From 9da549fc70fd620630a8d409b7b7f369658d2d2d Mon Sep 17 00:00:00 2001 From: Rachit Sonthalia Date: Sat, 21 Sep 2024 02:32:01 +0530 Subject: [PATCH 07/15] fix: seprate keys for contracts deployement --- test/basic-e2e.bats | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/test/basic-e2e.bats b/test/basic-e2e.bats index 6b4f2bb6..2860a9da 100644 --- a/test/basic-e2e.bats +++ b/test/basic-e2e.bats @@ -130,8 +130,21 @@ setup() { @test "Deploy and test UniswapV3 contract" { - run polycli loadtest uniswapv3 --legacy -v 600 --rpc-url $l2_rpc_url --private-key $sender_private_key + # Generate new key pair + wallet_A_output=$(cast wallet new) + address_A=$(echo "$wallet_A_output" | grep "Address" | awk '{print $2}') + address_A_private_key=$(echo "$wallet_A_output" | grep "Private key" | awk '{print $3}') + + # Transfer funds for gas + local value_ether="50ether" + cast_output=$(cast send --rpc-url "$l2_rpc_url" --private-key "$sender_private_key" "$address_A" --value "$value_ether" --legacy 2>&1) + if [[ $? -ne 0 ]]; then + echo "Error: Failed to send transaction. Output:" + echo "$cast_output" + return 1 + fi + run polycli loadtest uniswapv3 --legacy -v 600 --rpc-url $l2_rpc_url --private-key $address_A_private_key assert_success # Remove ANSI escape codes from the output From f220f216fc86cfbe74342053a1b56ff4172b973e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Negovanovi=C4=87?= Date: Mon, 23 Sep 2024 08:04:05 +0200 Subject: [PATCH 08/15] fix: rename sender private key env var --- test/access-list-e2e.bats | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/access-list-e2e.bats b/test/access-list-e2e.bats index cdcccc6a..814354f7 100644 --- a/test/access-list-e2e.bats +++ b/test/access-list-e2e.bats @@ -5,7 +5,7 @@ setup() { readonly erigon_sequencer_node=${KURTOSIS_ERIGON_SEQUENCER:-cdk-erigon-sequencer-001} readonly kurtosis_sequencer_wrapper=${KURTOSIS_SEQUENCER_WRAPPER:-"kurtosis service exec $enclave $erigon_sequencer_node"} - readonly key=${SENDER_key:-"12d7de8621a77640c9241b2595ba78ce443d05e94090365ab3bb5e19df82c625"} + readonly key=${SENDER_PRIVATE_KEY:-"12d7de8621a77640c9241b2595ba78ce443d05e94090365ab3bb5e19df82c625"} readonly receiver=${RECEIVER:-"0x85dA99c8a7C2C95964c8EfD687E95E632Fc533D6"} readonly data_dir=${ACL_DATA_DIR:-"/home/erigon/data/dynamic-kurtosis-sequencer/txpool/acls"} } From e528574bb406af1f81c24d172f6aaa3265714543 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Negovanovi=C4=87?= Date: Mon, 23 Sep 2024 08:15:31 +0200 Subject: [PATCH 09/15] fix: failing e2e tests --- test/helpers/common.bash | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/helpers/common.bash b/test/helpers/common.bash index a394f73d..2834fe2d 100644 --- a/test/helpers/common.bash +++ b/test/helpers/common.bash @@ -102,6 +102,7 @@ function sendTx() { if [[ "$value_or_function_sig" =~ ^[0-9]+(\.[0-9]+)?(ether)?$ ]]; then # Case: Ether transfer (EOA transaction) # Get initial ether balances of sender and receiver + local sender_addr=$(cast wallet address --private-key "$private_key") local sender_initial_balance receiver_initial_balance sender_initial_balance=$(cast balance "$sender_addr" --ether --rpc-url "$rpc_url") || return 1 receiver_initial_balance=$(cast balance "$receiver_addr" --ether --rpc-url "$rpc_url") || return 1 @@ -121,7 +122,7 @@ function send_eoa_transaction() { local sender_initial_balance="$5" local receiver_initial_balance="$6" - echo "Sending EOA transaction to: $receiver_addr with value: $value" >&3 + echo "Sending EOA transaction (from: $sender, rpc url: $rpc_url) to: $receiver_addr with value: $value" >&3 # Send transaction via cast local cast_output tx_hash From cf8f434da18a492576d9c11ddf3693875965dae9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Negovanovi=C4=87?= Date: Mon, 23 Sep 2024 08:18:03 +0200 Subject: [PATCH 10/15] chore: rename functions ( bash style) --- test/access-list-e2e.bats | 20 ++++++++++---------- test/basic-e2e.bats | 18 +++++++++--------- test/bridge-e2e.bats | 6 +++--- test/helpers/common.bash | 12 ++++++------ 4 files changed, 28 insertions(+), 28 deletions(-) diff --git a/test/access-list-e2e.bats b/test/access-list-e2e.bats index 814354f7..33e881e8 100644 --- a/test/access-list-e2e.bats +++ b/test/access-list-e2e.bats @@ -33,7 +33,7 @@ set_acl_mode() { @test "Test Block List - Sending regular transaction when address not in block list" { local value="10ether" run set_acl_mode "blocklist" - run sendTx $l2_rpc_url $key $receiver $value + run send_tx $l2_rpc_url $key $receiver $value assert_success assert_output --regexp "Transaction successful \(transaction hash: 0x[a-fA-F0-9]{64}\)" @@ -42,7 +42,7 @@ set_acl_mode() { @test "Test Block List - Sending contracts deploy transaction when address not in block list" { local contract_artifact="./contracts/erc20mock/ERC20Mock.json" run set_acl_mode "blocklist" - run deployContract $l2_rpc_url $key $contract_artifact + run deploy_contract $l2_rpc_url $key $contract_artifact assert_success @@ -54,9 +54,9 @@ set_acl_mode() { local value="10ether" run set_acl_mode "blocklist" - run add_to_access_list "blocklist" "sendTx" + run add_to_access_list "blocklist" "send_tx" - run sendTx $l2_rpc_url $key $receiver $value + run send_tx $l2_rpc_url $key $receiver $value assert_failure assert_output --partial "sender disallowed to send tx by ACL policy" @@ -67,7 +67,7 @@ set_acl_mode() { run set_acl_mode "blocklist" run add_to_access_list "blocklist" "deploy" - run deployContract $l2_rpc_url $key $contract_artifact + run deploy_contract $l2_rpc_url $key $contract_artifact assert_failure assert_output --partial "sender disallowed to deploy contract by ACL policy" @@ -77,7 +77,7 @@ set_acl_mode() { local value="10ether" run set_acl_mode "allowlist" - run sendTx $l2_rpc_url $key $receiver $value + run send_tx $l2_rpc_url $key $receiver $value assert_failure assert_output --partial "sender disallowed to send tx by ACL policy" @@ -87,7 +87,7 @@ set_acl_mode() { local contract_artifact="./contracts/erc20mock/ERC20Mock.json" run set_acl_mode "allowlist" - run deployContract $l2_rpc_url $key $contract_artifact + run deploy_contract $l2_rpc_url $key $contract_artifact assert_failure assert_output --partial "sender disallowed to deploy contract by ACL policy" @@ -97,8 +97,8 @@ set_acl_mode() { local value="10ether" run set_acl_mode "allowlist" - run add_to_access_list "allowlist" "sendTx" - run sendTx $l2_rpc_url $key $receiver $value + run add_to_access_list "allowlist" "send_tx" + run send_tx $l2_rpc_url $key $receiver $value assert_success assert_output --regexp "Transaction successful \(transaction hash: 0x[a-fA-F0-9]{64}\)" @@ -109,7 +109,7 @@ set_acl_mode() { run set_acl_mode "allowlist" run add_to_access_list "allowlist" "deploy" - run deployContract $l2_rpc_url $key $contract_artifact + run deploy_contract $l2_rpc_url $key $contract_artifact assert_success diff --git a/test/basic-e2e.bats b/test/basic-e2e.bats index 2860a9da..ed7ba6a5 100644 --- a/test/basic-e2e.bats +++ b/test/basic-e2e.bats @@ -13,7 +13,7 @@ setup() { local value="10ether" # case 1: Transaction successful sender has sufficient balance - run sendTx "$l2_rpc_url" "$sender_private_key" "$receiver" "$value" + run send_tx "$l2_rpc_url" "$sender_private_key" "$receiver" "$value" assert_success assert_output --regexp "Transaction successful \(transaction hash: 0x[a-fA-F0-9]{64}\)" @@ -22,7 +22,7 @@ setup() { # without recording it on the chain and hence nonce will not change local sender_balance=$(cast balance "$sender_addr" --ether --rpc-url "$l2_rpc_url") || return 1 local excessive_value=$(echo "$sender_balance + 1" | bc)"ether" - run sendTx "$l2_rpc_url" "$sender_private_key" "$receiver" "$excessive_value" + run send_tx "$l2_rpc_url" "$sender_private_key" "$receiver" "$excessive_value" assert_failure # Check whether the sender's nonce was updated correctly @@ -38,7 +38,7 @@ setup() { address_B=$(cast wallet new | grep "Address" | awk '{print $2}') # Deploy ERC20Mock - run deployContract "$l2_rpc_url" "$sender_private_key" "$contract_artifact" + run deploy_contract "$l2_rpc_url" "$sender_private_key" "$contract_artifact" assert_success contract_addr=$(echo "$output" | tail -n 1) @@ -46,7 +46,7 @@ setup() { local mintFnSig="mint(address,uint256)" local amount="5" - run sendTx "$l2_rpc_url" "$sender_private_key" "$contract_addr" "$mintFnSig" "$address_A" "$amount" + run send_tx "$l2_rpc_url" "$sender_private_key" "$contract_addr" "$mintFnSig" "$address_A" "$amount" assert_success assert_output --regexp "Transaction successful \(transaction hash: 0x[a-fA-F0-9]{64}\)" @@ -77,7 +77,7 @@ setup() { # Fetch initial nonce for address_A local address_A_initial_nonce=$(cast nonce "$address_A" --rpc-url "$l2_rpc_url") || return 1 # Attempt to deploy contract with insufficient gas - run deployContract "$l2_rpc_url" "$address_A_private_key" "$contract_artifact" + run deploy_contract "$l2_rpc_url" "$address_A_private_key" "$contract_artifact" assert_failure ## Case 3: Transaction should fail as address_A tries to transfer more tokens than it has @@ -93,7 +93,7 @@ setup() { # Fetch balance of address_A to simulate excessive transfer local balanceOfFnSig="balanceOf(address) (uint256)" - run queryContract "$l2_rpc_url" "$contract_addr" "$balanceOfFnSig" "$address_A" + run query_contract "$l2_rpc_url" "$contract_addr" "$balanceOfFnSig" "$address_A" assert_success local address_A_Balance=$(echo "$output" | tail -n 1) address_A_Balance=$(echo "$address_A_Balance" | xargs) @@ -103,11 +103,11 @@ setup() { # Attempt transfer of excessive amount from address_A to address_B local tranferFnSig="transfer(address,uint256)" - run sendTx "$l2_rpc_url" "$address_A_private_key" "$contract_addr" "$tranferFnSig" "$address_B" "$excessive_amount" + run send_tx "$l2_rpc_url" "$address_A_private_key" "$contract_addr" "$tranferFnSig" "$address_B" "$excessive_amount" assert_failure # Verify balance of address_A after failed transaction - run queryContract "$l2_rpc_url" "$contract_addr" "$balanceOfFnSig" "$address_A" + run query_contract "$l2_rpc_url" "$contract_addr" "$balanceOfFnSig" "$address_A" assert_success address_A_BalanceAfterFailedTx=$(echo "$output" | tail -n 1) address_A_BalanceAfterFailedTx=$(echo "$address_A_BalanceAfterFailedTx" | xargs) @@ -116,7 +116,7 @@ setup() { assert_equal "$address_A_BalanceAfterFailedTx" "$address_A_Balance" # Verify balance of address_B is still zero - run queryContract "$l2_rpc_url" "$contract_addr" "$balanceOfFnSig" "$address_B" + run query_contract "$l2_rpc_url" "$contract_addr" "$balanceOfFnSig" "$address_B" assert_success local address_B_Balance=$(echo "$output" | tail -n 1) address_B_Balance=$(echo "$address_B_Balance" | xargs) diff --git a/test/bridge-e2e.bats b/test/bridge-e2e.bats index c392e647..842d87e9 100644 --- a/test/bridge-e2e.bats +++ b/test/bridge-e2e.bats @@ -77,7 +77,7 @@ setup() { echo "Initial receiver balance of native token on L2 $initial_receiver_balance" >&3 # Query for initial sender balance - run queryContract "$l1_rpc_url" "$gas_token_addr" "$balance_of_fn_sig" "$sender_addr" + run query_contract "$l1_rpc_url" "$gas_token_addr" "$balance_of_fn_sig" "$sender_addr" assert_success local gas_token_init_sender_balance=$(echo "$output" | tail -n 1 | awk '{print $1}') echo "Initial sender balance $gas_token_init_sender_balance" of gas token on L1 >&3 @@ -90,7 +90,7 @@ setup() { assert_success # Assert that balance of gas token (on the L1) is correct - run queryContract "$l1_rpc_url" "$gas_token_addr" "$balance_of_fn_sig" "$sender_addr" + run query_contract "$l1_rpc_url" "$gas_token_addr" "$balance_of_fn_sig" "$sender_addr" assert_success local gas_token_final_sender_balance=$(echo "$output" | tail -n 1 | @@ -104,7 +104,7 @@ setup() { # Send approve transaction to the gas token on L1 deposit_ether_value="0.1ether" - run sendTx "$l1_rpc_url" "$sender_private_key" "$gas_token_addr" "$approve_fn_sig" "$bridge_addr" "$deposit_ether_value" + run send_tx "$l1_rpc_url" "$sender_private_key" "$gas_token_addr" "$approve_fn_sig" "$bridge_addr" "$deposit_ether_value" assert_success assert_output --regexp "Transaction successful \(transaction hash: 0x[a-fA-F0-9]{64}\)" diff --git a/test/helpers/common.bash b/test/helpers/common.bash index 2834fe2d..821a1f59 100644 --- a/test/helpers/common.bash +++ b/test/helpers/common.bash @@ -1,6 +1,6 @@ #!/usr/bin/env bash -function deployContract() { +function deploy_contract() { local rpc_url="$1" local private_key="$2" local contract_artifact="$3" @@ -70,10 +70,10 @@ function deployContract() { return 0 } -function sendTx() { +function send_tx() { # Check if at least 4 arguments are provided if [[ $# -lt 4 ]]; then - echo "Usage: sendTx [ ...]" + echo "Usage: send_tx [ ...]" return 1 fi @@ -180,7 +180,7 @@ function extract_tx_hash() { echo "$cast_output" | grep 'transactionHash' | awk '{print $2}' | tail -n 1 } -function queryContract() { +function query_contract() { local rpc_url="$1" # RPC URL local addr="$2" # Contract address local funcSignature="$3" # Function signature @@ -310,7 +310,7 @@ function mint_erc20_tokens() { local tokens_amount="$5" # The amount of tokens to transfer (e.g., "0.1ether") # Query the erc20 token balance of the sender - run queryContract "$rpc_url" "$erc20_token_addr" "$balance_of_fn_sig" "$sender_addr" + run query_contract "$rpc_url" "$erc20_token_addr" "$balance_of_fn_sig" "$sender_addr" assert_success local erc20_token_balance=$(echo "$output" | tail -n 1) @@ -321,6 +321,6 @@ function mint_erc20_tokens() { local wei_amount=$(cast --to-unit "$tokens_amount" wei) # Mint the required tokens by sending a transaction - run sendTx "$rpc_url" "$minter_private_key" "$erc20_token_addr" "$mint_fn_sig" "$receiver" "$tokens_amount" + run send_tx "$rpc_url" "$minter_private_key" "$erc20_token_addr" "$mint_fn_sig" "$receiver" "$tokens_amount" assert_success } From 03ac2ed3c0264b1b1852d93fe3cca4c5f93b7c14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Negovanovi=C4=87?= Date: Mon, 23 Sep 2024 08:48:20 +0200 Subject: [PATCH 11/15] fix: access lists e2e tests --- test/access-list-e2e.bats | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/access-list-e2e.bats b/test/access-list-e2e.bats index 33e881e8..83947c03 100644 --- a/test/access-list-e2e.bats +++ b/test/access-list-e2e.bats @@ -54,7 +54,7 @@ set_acl_mode() { local value="10ether" run set_acl_mode "blocklist" - run add_to_access_list "blocklist" "send_tx" + run add_to_access_list "blocklist" "sendTx" run send_tx $l2_rpc_url $key $receiver $value @@ -97,7 +97,7 @@ set_acl_mode() { local value="10ether" run set_acl_mode "allowlist" - run add_to_access_list "allowlist" "send_tx" + run add_to_access_list "allowlist" "sendTx" run send_tx $l2_rpc_url $key $receiver $value assert_success From 42b882a67bdd97bc2ea93c50b638b1583207360d Mon Sep 17 00:00:00 2001 From: Rachit Sonthalia Date: Tue, 24 Sep 2024 00:14:59 +0530 Subject: [PATCH 12/15] refactor: apply feedback --- .github/workflows/test-e2e.yml | 6 +++++- test/basic-e2e.bats | 10 ++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test-e2e.yml b/.github/workflows/test-e2e.yml index e26807b3..f5062244 100644 --- a/.github/workflows/test-e2e.yml +++ b/.github/workflows/test-e2e.yml @@ -50,7 +50,11 @@ jobs: - name: Install polycli run: | - tmp_dir=$(mktemp -d) && curl -L https://github.com/0xPolygon/polygon-cli/releases/download/v0.1.48/polycli_v0.1.48_linux_amd64.tar.gz | tar -xz -C "$tmp_dir" && mv "$tmp_dir"/* /usr/local/bin/polycli && rm -rf "$tmp_dir" + POLYCLI_VERSION="${{ env.POLYCLI_VERSION }}" + tmp_dir=$(mktemp -d) + curl -L "https://github.com/0xPolygon/polygon-cli/releases/download/${POLYCLI_VERSION}/polycli_${POLYCLI_VERSION}_linux_amd64.tar.gz" | tar -xz -C "$tmp_dir" + mv "$tmp_dir"/* /usr/local/bin/polycli + rm -rf "$tmp_dir" sudo chmod +x /usr/local/bin/polycli /usr/local/bin/polycli version diff --git a/test/basic-e2e.bats b/test/basic-e2e.bats index ed7ba6a5..c0f00093 100644 --- a/test/basic-e2e.bats +++ b/test/basic-e2e.bats @@ -43,10 +43,9 @@ setup() { contract_addr=$(echo "$output" | tail -n 1) # Mint ERC20 tokens - local mintFnSig="mint(address,uint256)" local amount="5" - run send_tx "$l2_rpc_url" "$sender_private_key" "$contract_addr" "$mintFnSig" "$address_A" "$amount" + run send_tx "$l2_rpc_url" "$sender_private_key" "$contract_addr" "$mint_fn_sig" "$address_A" "$amount" assert_success assert_output --regexp "Transaction successful \(transaction hash: 0x[a-fA-F0-9]{64}\)" @@ -92,8 +91,7 @@ setup() { fi # Fetch balance of address_A to simulate excessive transfer - local balanceOfFnSig="balanceOf(address) (uint256)" - run query_contract "$l2_rpc_url" "$contract_addr" "$balanceOfFnSig" "$address_A" + run query_contract "$l2_rpc_url" "$contract_addr" "$balance_of_fn_sig" "$address_A" assert_success local address_A_Balance=$(echo "$output" | tail -n 1) address_A_Balance=$(echo "$address_A_Balance" | xargs) @@ -107,7 +105,7 @@ setup() { assert_failure # Verify balance of address_A after failed transaction - run query_contract "$l2_rpc_url" "$contract_addr" "$balanceOfFnSig" "$address_A" + run query_contract "$l2_rpc_url" "$contract_addr" "$balance_of_fn_sig" "$address_A" assert_success address_A_BalanceAfterFailedTx=$(echo "$output" | tail -n 1) address_A_BalanceAfterFailedTx=$(echo "$address_A_BalanceAfterFailedTx" | xargs) @@ -116,7 +114,7 @@ setup() { assert_equal "$address_A_BalanceAfterFailedTx" "$address_A_Balance" # Verify balance of address_B is still zero - run query_contract "$l2_rpc_url" "$contract_addr" "$balanceOfFnSig" "$address_B" + run query_contract "$l2_rpc_url" "$contract_addr" "$balance_of_fn_sig" "$address_B" assert_success local address_B_Balance=$(echo "$output" | tail -n 1) address_B_Balance=$(echo "$address_B_Balance" | xargs) From 0c743336adb8a4d2a0fcbbdff8359044a5cc126b Mon Sep 17 00:00:00 2001 From: Rachit Sonthalia Date: Tue, 24 Sep 2024 01:06:17 +0530 Subject: [PATCH 13/15] fix: polycli version --- .github/workflows/test-e2e.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-e2e.yml b/.github/workflows/test-e2e.yml index f5062244..7fb9a919 100644 --- a/.github/workflows/test-e2e.yml +++ b/.github/workflows/test-e2e.yml @@ -50,7 +50,7 @@ jobs: - name: Install polycli run: | - POLYCLI_VERSION="${{ env.POLYCLI_VERSION }}" + POLYCLI_VERSION="v0.1.57" tmp_dir=$(mktemp -d) curl -L "https://github.com/0xPolygon/polygon-cli/releases/download/${POLYCLI_VERSION}/polycli_${POLYCLI_VERSION}_linux_amd64.tar.gz" | tar -xz -C "$tmp_dir" mv "$tmp_dir"/* /usr/local/bin/polycli From 4890634ee370a8757119d2aa1361d063b65f7038 Mon Sep 17 00:00:00 2001 From: Rachit Sonthalia Date: Tue, 24 Sep 2024 08:28:36 +0530 Subject: [PATCH 14/15] fix: polycli workflow --- .github/workflows/test-e2e.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-e2e.yml b/.github/workflows/test-e2e.yml index 7fb9a919..af54879b 100644 --- a/.github/workflows/test-e2e.yml +++ b/.github/workflows/test-e2e.yml @@ -50,7 +50,7 @@ jobs: - name: Install polycli run: | - POLYCLI_VERSION="v0.1.57" + POLYCLI_VERSION="${{ vars.POLYCLI_VERSION }}" tmp_dir=$(mktemp -d) curl -L "https://github.com/0xPolygon/polygon-cli/releases/download/${POLYCLI_VERSION}/polycli_${POLYCLI_VERSION}_linux_amd64.tar.gz" | tar -xz -C "$tmp_dir" mv "$tmp_dir"/* /usr/local/bin/polycli From 962eab432b89faf929ead5e15928ba471239be64 Mon Sep 17 00:00:00 2001 From: Rachit Sonthalia Date: Tue, 24 Sep 2024 14:14:59 +0530 Subject: [PATCH 15/15] refactor: apply feedback --- test/basic-e2e.bats | 24 ++++++++++++++++++------ test/helpers/common-setup.bash | 2 +- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/test/basic-e2e.bats b/test/basic-e2e.bats index c0f00093..1024ac4a 100644 --- a/test/basic-e2e.bats +++ b/test/basic-e2e.bats @@ -9,7 +9,10 @@ setup() { @test "Send EOA transaction" { local sender_addr=$(cast wallet address --private-key "$sender_private_key") - local initial_nonce=$(cast nonce "$sender_addr" --rpc-url "$l2_rpc_url") || return 1 + local initial_nonce=$(cast nonce "$sender_addr" --rpc-url "$l2_rpc_url") || { + echo "Failed to retrieve nonce for sender: $sender_addr using RPC URL: $l2_rpc_url" + return 1 + } local value="10ether" # case 1: Transaction successful sender has sufficient balance @@ -20,13 +23,19 @@ setup() { # case 2: Transaction rejected as sender attempts to transfer more than it has in its wallet. # Transaction 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=$(cast balance "$sender_addr" --ether --rpc-url "$l2_rpc_url") || return 1 + local sender_balance=$(cast balance "$sender_addr" --ether --rpc-url "$l2_rpc_url") || { + echo "Failed to retrieve balance for sender: $sender_addr using RPC URL: $l2_rpc_url" + return 1 + } local excessive_value=$(echo "$sender_balance + 1" | bc)"ether" run send_tx "$l2_rpc_url" "$sender_private_key" "$receiver" "$excessive_value" assert_failure # Check whether the sender's nonce was updated correctly - local final_nonce=$(cast nonce "$sender_addr" --rpc-url "$l2_rpc_url") || return 1 + local final_nonce=$(cast nonce "$sender_addr" --rpc-url "$l2_rpc_url") || { + echo "Failed to retrieve nonce for sender: $sender_addr using RPC URL: $l2_rpc_url" + return 1 + } assert_equal "$final_nonce" "$(echo "$initial_nonce + 1" | bc)" } @@ -65,7 +74,7 @@ setup() { local value=$(echo "$gas_units * $gas_price" | bc) local value_ether=$(cast to-unit "$value" ether)"ether" - # Transfer insufficient funds + # Transfer only half amount of tokens needed for contract deployment fees cast_output=$(cast send --rpc-url "$l2_rpc_url" --private-key "$sender_private_key" "$address_A" --value "$value_ether" --legacy 2>&1) if [[ $? -ne 0 ]]; then echo "Error: Failed to send transaction. Output:" @@ -122,7 +131,10 @@ setup() { assert_equal "$address_B_Balance" "0" # Nonce should not increase - local address_A_final_nonce=$(cast nonce "$address_A" --rpc-url "$l2_rpc_url") || return 1 + local address_A_final_nonce=$(cast nonce "$address_A" --rpc-url "$l2_rpc_url") || { + echo "Failed to retrieve nonce for sender: $address_A using RPC URL: $l2_rpc_url" + return 1 + } assert_equal "$address_A_final_nonce" "$address_A_initial_nonce" } @@ -148,7 +160,7 @@ setup() { # Remove ANSI escape codes from the output output=$(echo "$output" | sed -r "s/\x1B\[[0-9;]*[mGKH]//g") - # Check if the WETH9 contract were deployed + # Check if all required Uniswap contracts were deployed assert_output --regexp "Contract deployed address=0x[a-fA-F0-9]{40} name=WETH9" assert_output --regexp "Contract deployed address=0x[a-fA-F0-9]{40} name=UniswapV3Factory" assert_output --regexp "Contract deployed address=0x[a-fA-F0-9]{40} name=UniswapInterfaceMulticall" diff --git a/test/helpers/common-setup.bash b/test/helpers/common-setup.bash index 7cb4dec7..415f211d 100644 --- a/test/helpers/common-setup.bash +++ b/test/helpers/common-setup.bash @@ -23,4 +23,4 @@ _common_setup() { readonly contracts_service_wrapper=${KURTOSIS_CONTRACTS_WRAPPER:-"kurtosis service exec $enclave $contracts_container"} readonly erigon_rpc_node=${KURTOSIS_ERIGON_RPC:-cdk-erigon-node-001} readonly l2_rpc_url=${L2_ETH_RPC_URL:-"$(kurtosis port print $enclave $erigon_rpc_node http-rpc)"} -} +} \ No newline at end of file