Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ for CONTRACT in "$CONTRACT_DIR"/*.wasm; do

tx_hash=$($BINARY tx wasm store "$CONTRACT" \
--from "$WALLET" \
--instantiate-anyof-addresses "$WALLET" \
--instantiate-anyof-addresses "$($BINARY keys show $WALLET -a)" \

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Consider including all intended admins and avoid repeated key lookups

If the intent was to allow both wallets to instantiate, pass both addresses as a comma-separated list. Also, avoid repeated keys show calls by caching resolved addresses.

Apply within this line:

-        --instantiate-anyof-addresses "$($BINARY keys show $WALLET -a)" \
+        --instantiate-anyof-addresses "$WALLET_ADDR,$WALLET2_ADDR" \

Define once after parsing flags (and validate):

# after getopts and required args check
WALLET_ADDR="$($BINARY keys show "$WALLET" -a)"
WALLET2_ADDR="$($BINARY keys show "$WALLET2" -a)"
if [ -z "$WALLET_ADDR" ] || [ -z "$WALLET2_ADDR" ]; then
  echo "Failed to resolve wallet addresses"; exit 1
fi

If only one admin was intended, still prefer using $WALLET_ADDR and quote the inner var in command substitution if you keep it:

-        --instantiate-anyof-addresses "$($BINARY keys show $WALLET -a)" \
+        --instantiate-anyof-addresses "$WALLET_ADDR" \

🏁 Script executed:

#!/bin/bash
set -e

echo "1. Locate 'instantiate-anyof-addresses' usage:"
rg "instantiate-anyof-addresses" -n scripts/test.sh || echo "No matches found"

echo
echo "2. Locate all '$BINARY keys show' invocations:"
rg "\$BINARY keys show" -n scripts/test.sh || echo "No matches found"

echo
echo "3. Check for WALLET2 references:"
rg "WALLET2" -n scripts/test.sh || echo "No matches found"

echo
echo "4. Inspect flag parsing to see how many wallets are accepted:"
rg "getopts" -n scripts/test.sh || echo "No getopts usage found"

echo
echo "5. Show lines 120–160 for ShellCheck SC2145 context:"
sed -n '120,160p' scripts/test.sh || echo "Unable to display lines"

echo
echo "6. Check for hardcoded 'uom' denom usage:"
rg "uom" -n scripts/test.sh || echo "No hardcoded denom found"

Length of output: 4370


scripts/test.sh: cache wallet addresses, include both admins, parameterize denom, and fix array echo

  • After parsing flags (around line 55), cache and validate both wallet addresses:
    WALLET_ADDR="$($BINARY keys show "$WALLET" -a)"
    WALLET2_ADDR="$($BINARY keys show "$WALLET2" -a)"
    if [ -z "$WALLET_ADDR" ] || [ -z "$WALLET2_ADDR" ]; then
      echo "Failed to resolve wallet addresses"; exit 1
    fi
  • Line 86: pass both admins to instantiate-anyof-addresses:
    -        --instantiate-anyof-addresses "$($BINARY keys show $WALLET -a)" \
    +        --instantiate-anyof-addresses "$WALLET_ADDR,$WALLET2_ADDR" \
  • Replace all other in-place "$($BINARY keys show …)" invocations with $WALLET_ADDR or $WALLET2_ADDR, e.g. bank sends at lines 241–243:
    -$BINARY tx bank send "$($BINARY keys show $WALLET -a)" "$($BINARY keys show $WALLET2 -a)" 100uom … --from $WALLET
    +$BINARY tx bank send "$WALLET_ADDR" "$WALLET2_ADDR" 100${DENOM} … --from "$WALLET"
    
    -$BINARY tx bank send "$($BINARY keys show $WALLET2 -a)" "$($BINARY keys show $WALLET -a)" 80uom … --from $WALLET2
    +$BINARY tx bank send "$WALLET2_ADDR" "$WALLET_ADDR" 80${DENOM} … --from "$WALLET2"
  • Parameterize all hardcoded “uom” amounts inside execute_tx (lines 162, 168, 171) to use $DENOM.
  • Fix ShellCheck SC2145 on array echo (around “Instantiated contracts at :”):
    -echo -e "\nInstantiated contracts at : ${contract_addresses[@]}"
    +echo -e "\nInstantiated contracts at : ${contract_addresses[*]}"
🤖 Prompt for AI Agents
In scripts/test.sh around line 55, cache wallet addresses by assigning
WALLET_ADDR and WALLET2_ADDR using the keys show command and validate they are
not empty, exiting with an error if they are. At line 86, update the
instantiate-anyof-addresses command to pass both $WALLET_ADDR and $WALLET2_ADDR
as admins. Replace all other direct calls to keys show with the cached variables
$WALLET_ADDR or $WALLET2_ADDR, including the bank sends at lines 241-243.
Parameterize all hardcoded "uom" amounts in execute_tx calls at lines 162, 168,
and 171 to use a $DENOM variable instead. Finally, fix the ShellCheck SC2145
warning by properly quoting or expanding arrays in the echo statement near the
"Instantiated contracts at :" message.

--chain-id "$CHAIN_ID" \
--node "$RPC" \
--gas-prices "0.5$DENOM" \
Expand Down Expand Up @@ -125,23 +125,23 @@ fi
if [ ${#code_ids[@]} -eq 1 ]; then
echo "Instantiating contract with code_id ${code_ids[0]}"
for i in {1..2}; do
res=$($BINARY tx wasm instantiate ${code_ids[0]} '{}' --label test --admin $WALLET $TXFLAG --from $WALLET | jq -r '.txhash')
res=$($BINARY tx wasm instantiate ${code_ids[0]} '{}' --label test --admin "$($BINARY keys show $WALLET -a)" $TXFLAG --from $WALLET | jq -r '.txhash')

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Use cached address and quote --from

Avoid repeated key lookups and ensure --from is quoted.

-res=$($BINARY tx wasm instantiate ${code_ids[0]} '{}' --label test --admin "$($BINARY keys show $WALLET -a)" $TXFLAG --from $WALLET | jq -r '.txhash')
+res=$($BINARY tx wasm instantiate ${code_ids[0]} '{}' --label test --admin "$WALLET_ADDR" $TXFLAG --from "$WALLET" | jq -r '.txhash')
🤖 Prompt for AI Agents
In scripts/test.sh at line 128, the command repeatedly looks up the wallet
address and does not quote the --from argument. To fix this, store the wallet
address in a variable before this line and use that cached variable in the
command. Also, ensure the --from argument is enclosed in quotes to handle any
special characters or spaces properly.

sleep 10
contract_address=$($BINARY q tx $res --node $RPC -o json | jq -r '.events[] | select(.type == "instantiate").attributes[] | select(.key == "_contract_address").value')
contract_addresses+=("$contract_address")
done
else
echo "Instantiating contracts with code_ids ${code_ids[@]}"
for code_id in "${code_ids[@]}"; do
res=$($BINARY tx wasm instantiate $code_id '{}' --label test --admin $WALLET $TXFLAG --from $WALLET | jq -r '.txhash')
res=$($BINARY tx wasm instantiate $code_id '{}' --label test --admin "$($BINARY keys show $WALLET -a)" $TXFLAG --from $WALLET | jq -r '.txhash')

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

DRY: reuse cached admin address and quote --from

Same refactor as above to reduce command invocations and harden quoting.

-res=$($BINARY tx wasm instantiate $code_id '{}' --label test --admin "$($BINARY keys show $WALLET -a)" $TXFLAG --from $WALLET | jq -r '.txhash')
+res=$($BINARY tx wasm instantiate $code_id '{}' --label test --admin "$WALLET_ADDR" $TXFLAG --from "$WALLET" | jq -r '.txhash')
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
res=$($BINARY tx wasm instantiate $code_id '{}' --label test --admin "$($BINARY keys show $WALLET -a)" $TXFLAG --from $WALLET | jq -r '.txhash')
res=$($BINARY tx wasm instantiate $code_id '{}' --label test --admin "$WALLET_ADDR" $TXFLAG --from "$WALLET" | jq -r '.txhash')
🤖 Prompt for AI Agents
In scripts/test.sh at line 136, the admin address is retrieved inline multiple
times which is inefficient and the --from argument is not quoted. To fix this,
cache the admin address in a variable before this line and reuse it in both the
--admin and --from flags. Also, ensure the --from argument is properly quoted to
handle any special characters or spaces.

sleep 10
contract_address=$($BINARY q tx $res --node $RPC -o json | jq -r '.events[] | select(.type == "instantiate").attributes[] | select(.key == "_contract_address").value')
contract_addresses+=("$contract_address")
done
fi

echo -e "\nTrying to instantiate a contract with $WALLET2 should fail..."
$BINARY tx wasm instantiate ${code_ids[0]} '{}' --label test_fail --admin $WALLET2 $TXFLAG --from $WALLET2
$BINARY tx wasm instantiate ${code_ids[0]} '{}' --label test_fail --admin "$($BINARY keys show $WALLET2 -a)" $TXFLAG --from $WALLET2

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Use cached address for negative test and optionally assert failure

Reusing the cached address avoids extra lookups. Consider asserting that this instantiate indeed fails to make the test deterministic.

Minimal change:

-$BINARY tx wasm instantiate ${code_ids[0]} '{}' --label test_fail --admin "$($BINARY keys show $WALLET2 -a)" $TXFLAG --from $WALLET2
+$BINARY tx wasm instantiate ${code_ids[0]} '{}' --label test_fail --admin "$WALLET2_ADDR" $TXFLAG --from "$WALLET2"

Optional stronger check:

if $BINARY tx wasm instantiate "${code_ids[0]}" '{}' --label test_fail --admin "$WALLET2_ADDR" $TXFLAG --from "$WALLET2"; then
  echo "Unexpected success: instantiate should have failed"; exit 1
else
  echo "Expected failure confirmed"
fi

🏁 Script executed:

#!/bin/bash
# Check if WALLET2_ADDR is defined/cached in the test script
rg -n 'WALLET2_ADDR' -C3 scripts/test.sh

Length of output: 40


🏁 Script executed:

#!/bin/bash
# Search for any assignment to WALLET2_ADDR or usage of keys show for WALLET2
rg -n 'WALLET2_ADDR' -C3 scripts/test.sh
rg -n 'keys show.*\$WALLET2' -C3 scripts/test.sh

Length of output: 777


🏁 Script executed:

#!/bin/bash
# Search for where WALLET_ADDR is defined to locate address caching block
rg -n 'WALLET_ADDR=' -C5 scripts/test.sh

Length of output: 40


Define and cache WALLET2_ADDR before reuse, then assert instantiate failure

The variable WALLET2_ADDR isn’t defined in scripts/test.sh, so swapping out the inline lookup will break the script. To both avoid extra keys show calls and make the negative test deterministic:

• Add a cache assignment before line 144 in scripts/test.sh:

WALLET2_ADDR=$($BINARY keys show $WALLET2 -a)

• Update the instantiate call to use the cached address:

-$BINARY tx wasm instantiate ${code_ids[0]} '{}' --label test_fail \
-  --admin "$($BINARY keys show $WALLET2 -a)" $TXFLAG --from $WALLET2
+$BINARY tx wasm instantiate ${code_ids[0]} '{}' --label test_fail \
+  --admin "$WALLET2_ADDR" $TXFLAG --from "$WALLET2"

• (Optional) Wrap in an if to assert failure for determinism:

if $BINARY tx wasm instantiate "${code_ids[0]}" '{}' \
     --label test_fail --admin "$WALLET2_ADDR" $TXFLAG --from "$WALLET2"; then
  echo "Unexpected success: instantiate should have failed"
  exit 1
else
  echo "Expected failure confirmed"
fi
🤖 Prompt for AI Agents
In scripts/test.sh at line 144, define and cache the variable WALLET2_ADDR
before its reuse by assigning it the output of the command '$BINARY keys show
$WALLET2 -a'. Then update the instantiate command to use this cached
WALLET2_ADDR instead of calling the command inline. Additionally, wrap the
instantiate command in an if statement to assert that it fails as expected,
printing a message and exiting with an error if it unexpectedly succeeds, or
confirming the expected failure otherwise.


echo -e "\nInstantiated contracts at : ${contract_addresses[@]}"

Expand Down Expand Up @@ -238,7 +238,7 @@ echo -e "\n--- All contract interactions complete ---"
echo -e "\n--- Interop with Native Cosmos Modules ---"

echo -e "\nSending native tokens..."
$BINARY tx bank send $WALLET $WALLET2 100uom $TXFLAG --from $WALLET
$BINARY tx bank send "$($BINARY keys show $WALLET -a)" "$($BINARY keys show $WALLET2 -a)" 100uom $TXFLAG --from $WALLET

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Reuse cached addresses, quote --from, and use $DENOM

Keep denom configurable and avoid repeated key lookups.

-$BINARY tx bank send "$($BINARY keys show $WALLET -a)" "$($BINARY keys show $WALLET2 -a)" 100uom $TXFLAG --from $WALLET
+$BINARY tx bank send "$WALLET_ADDR" "$WALLET2_ADDR" "100$DENOM" $TXFLAG --from "$WALLET"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
$BINARY tx bank send "$($BINARY keys show $WALLET -a)" "$($BINARY keys show $WALLET2 -a)" 100uom $TXFLAG --from $WALLET
$BINARY tx bank send "$WALLET_ADDR" "$WALLET2_ADDR" "100$DENOM" $TXFLAG --from "$WALLET"
🤖 Prompt for AI Agents
In scripts/test.sh at line 241, the command repeatedly looks up wallet addresses
and hardcodes the denom. Refactor to store the addresses in variables before
this line to reuse cached values, replace the hardcoded denom 'uom' with the
variable $DENOM for configurability, and ensure the --from argument is quoted to
handle any special characters or spaces safely.

sleep 8
$BINARY tx bank send $WALLET2 $WALLET 80uom $TXFLAG --from $WALLET2
$BINARY tx bank send "$($BINARY keys show $WALLET2 -a)" "$($BINARY keys show $WALLET -a)" 80uom $TXFLAG --from $WALLET2

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Same as above: cached addresses, quoting, and configurable denom

-$BINARY tx bank send "$($BINARY keys show $WALLET2 -a)" "$($BINARY keys show $WALLET -a)" 80uom $TXFLAG --from $WALLET2
+$BINARY tx bank send "$WALLET2_ADDR" "$WALLET_ADDR" "80$DENOM" $TXFLAG --from "$WALLET2"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
$BINARY tx bank send "$($BINARY keys show $WALLET2 -a)" "$($BINARY keys show $WALLET -a)" 80uom $TXFLAG --from $WALLET2
-$BINARY tx bank send "$($BINARY keys show $WALLET2 -a)" "$($BINARY keys show $WALLET -a)" 80uom $TXFLAG --from $WALLET2
+$BINARY tx bank send "$WALLET2_ADDR" "$WALLET_ADDR" "80$DENOM" $TXFLAG --from "$WALLET2"
🤖 Prompt for AI Agents
In scripts/test.sh at line 243, the command uses direct calls to fetch addresses
without caching, lacks proper quoting, and hardcodes the denomination. Modify
the script to cache the addresses in variables before this line, ensure all
variables are properly quoted to handle spaces or special characters, and
replace the hardcoded denomination "uom" with a configurable variable to improve
flexibility and reliability.

sleep 8