Add manual test scripts

This commit is contained in:
Alex Peters 2020-10-27 15:00:56 +01:00
parent e54fbb9eb8
commit dff38d2e5b
No known key found for this signature in database
GPG Key ID: 4E18CD9F98929E11
5 changed files with 137 additions and 0 deletions

17
contrib/local/01-accounts.sh Executable file
View File

@ -0,0 +1,17 @@
#!/bin/sh
set -o errexit -o nounset -o pipefail
BASE_ACCOUNT=$(wasmcli keys show validator -a)
wasmcli q account "$BASE_ACCOUNT" -o json | jq
echo "## Add new account"
wasmcli keys add fred
echo "## Check balance"
NEW_ACCOUNT=$(wasmcli keys show fred -a)
wasmcli q bank balances "$NEW_ACCOUNT" -o json || true
echo "## Transfer tokens"
wasmcli tx send "$BASE_ACCOUNT" "$NEW_ACCOUNT" 1ustake --gas 1000000 -y --chain-id=testing --node=http://localhost:26657 -b block | jq
echo "## Check balance again"
wasmcli q bank balances "$NEW_ACCOUNT" -o json | jq

84
contrib/local/02-contracts.sh Executable file
View File

@ -0,0 +1,84 @@
#!/bin/sh
set -o errexit -o nounset -o pipefail
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
echo "-----------------------"
echo "## Add new CosmWasm contract"
RESP=$(wasmcli tx wasm store "$DIR/../../x/wasm/internal/keeper/testdata/hackatom.wasm" \
--from validator --gas 1000000 -y --chain-id=testing --node=http://localhost:26657 -b block)
CODE_ID=$(echo "$RESP" | jq -r '.logs[0].events[0].attributes[-1].value')
echo "* Code id: $CODE_ID"
echo "* Download code"
TMPDIR=$(mktemp -t wasmcli)
wasmcli q wasm code "$CODE_ID" "$TMPDIR"
rm -f "$TMPDIR"
echo "-----------------------"
echo "## List code"
wasmcli query wasm list-code --node=http://localhost:26657 --chain-id=testing | jq
echo "-----------------------"
echo "## Create new contract instance"
INIT="{\"verifier\":\"$(wasmcli keys show validator -a)\", \"beneficiary\":\"$(wasmcli keys show fred -a)\"}"
wasmcli tx wasm instantiate "$CODE_ID" "$INIT" --admin=$(wasmcli keys show validator -a) \
--from validator --amount="100ustake" --label "local0.1.0" \
--gas 1000000 -y --chain-id=testing -b block | jq
CONTRACT=$(wasmcli query wasm list-contract-by-code "$CODE_ID" -o json | jq -r '.[0].address')
echo "* Contract address: $CONTRACT"
echo "### Query all"
RESP=$(wasmcli query wasm contract-state all "$CONTRACT" -o json)
echo "$RESP"
echo "### Query smart"
wasmcli query wasm contract-state smart "$CONTRACT" '{"verifier":{}}' -o json | jq
echo "### Query raw"
KEY=$(echo "$RESP" | jq -r ".[0].Key")
wasmcli query wasm contract-state raw "$CONTRACT" "$KEY" -o json
echo "-----------------------"
echo "## Execute contract $CONTRACT"
MSG='{"release":{}}'
wasmcli tx wasm execute "$CONTRACT" "$MSG" \
--from validator \
--gas 1000000 -y --chain-id=testing -b block | jq
echo "-----------------------"
echo "## Set new admin"
echo "### Query old admin: $(wasmcli q wasm contract $CONTRACT -o json | jq -r '.admin')"
echo "### Update contract"
wasmcli tx wasm set-contract-admin "$CONTRACT" $(wasmcli keys show fred -a) \
--from validator -y --chain-id=testing -b block | jq
echo "### Query new admin: $(wasmcli q wasm contract $CONTRACT -o json | jq -r '.admin')"
echo "-----------------------"
echo "## Migrate contract"
echo "### Upload new code"
RESP=$(wasmcli tx wasm store "$DIR/../../x/wasm/internal/keeper/testdata/burner.wasm" \
--from validator --gas 1000000 -y --chain-id=testing --node=http://localhost:26657 -b block)
BURNER_CODE_ID=$(echo "$RESP" | jq -r '.logs[0].events[0].attributes[-1].value')
echo "### Migrate to code id: $BURNER_CODE_ID"
DEST_ACCOUNT=$(wasmcli keys show fred -a)
wasmcli tx wasm migrate "$CONTRACT" "$BURNER_CODE_ID" "{\"payout\": \"$DEST_ACCOUNT\"}" --from fred \
--chain-id=testing -b block -y | jq
echo "### Query destination account: $BURNER_CODE_ID"
wasmcli q bank balances "$DEST_ACCOUNT" -o json | jq
echo "### Query contract meta data: $CONTRACT"
wasmcli q wasm contract "$CONTRACT" -o json | jq
echo "### Query contract meta history: $CONTRACT"
wasmcli q wasm contract-history "$CONTRACT" -o json | jq
echo "-----------------------"
echo "## Clear contract admin"
echo "### Query old admin: $(wasmcli q wasm contract $CONTRACT -o json | jq -r '.admin')"
echo "### Update contract"
wasmcli tx wasm clear-contract-admin "$CONTRACT" \
--from fred -y --chain-id=testing -b block | jq
echo "### Query new admin: $(wasmcli q wasm contract $CONTRACT -o json | jq -r '.admin')"

6
contrib/local/README.md Normal file
View File

@ -0,0 +1,6 @@
# Dev scripts
For manual testing. Works on my box(*) ...
*) OSX

26
contrib/local/setup_wasmd.sh Executable file
View File

@ -0,0 +1,26 @@
#!/bin/sh
set -o errexit -o nounset -o pipefail
PASSWORD=${PASSWORD:-1234567890}
STAKE=${STAKE_TOKEN:-ustake}
FEE=${FEE_TOKEN:-ucosm}
CHAIN_ID=${CHAIN_ID:-testing}
MONIKER=${MONIKER:-node001}
wasmd init --chain-id "$CHAIN_ID" "$MONIKER"
# staking/governance token is hardcoded in config, change this
## OSX requires: -i.
sed -i. "s/\"stake\"/\"$STAKE\"/" "$HOME"/.wasmd/config/genesis.json
if ! wasmcli keys show validator; then
(echo "$PASSWORD"; echo "$PASSWORD") | wasmcli keys add validator
fi
# hardcode the validator account for this instance
echo "$PASSWORD" | wasmd add-genesis-account validator "1000000000$STAKE,1000000000$FEE"
# (optionally) add a few more genesis accounts
for addr in "$@"; do
echo $addr
wasmd add-genesis-account "$addr" "1000000000$STAKE,1000000000$FEE"
done
# submit a genesis validator tx
(echo "$PASSWORD"; echo "$PASSWORD"; echo "$PASSWORD") | wasmd gentx validator --chain-id=testing --amount "250000000$STAKE"
wasmd collect-gentxs

4
contrib/local/start_node.sh Executable file
View File

@ -0,0 +1,4 @@
#!/bin/bash
set -eu
wasmd start --rpc.laddr tcp://0.0.0.0:26657 --trace # does not work anymore: --log_level="main:info,state:debug,*:error"