diff --git a/cosmwasm/testing/callback-test.sh b/cosmwasm/testing/callback-test.sh index cda68b38b..d1513de66 100755 --- a/cosmwasm/testing/callback-test.sh +++ b/cosmwasm/testing/callback-test.sh @@ -2,9 +2,11 @@ set -euvx -function wait_for_tx () { - until (./secretcli q tx "$1") - do +alias secretcli="./secretcli" +alias secretd="./secretd" + +function wait_for_tx() { + until (secretcli q tx "$1"); do echo "$2" sleep 1 done @@ -15,103 +17,102 @@ rm -rf ./.sgx_secrets mkdir -p ./.sgx_secrets rm -rf ~/.secret* -./secretcli config chain-id enigma-testnet -./secretcli config output json -./secretcli config indent true -./secretcli config trust-node true -./secretcli config keyring-backend test -./secretd init banana --chain-id enigma-testnet +secretcli config chain-id enigma-testnet +secretcli config output json +secretcli config indent true +secretcli config trust-node true +secretcli config keyring-backend test + +secretd init banana --chain-id enigma-testnet perl -i -pe 's/"stake"/"uscrt"/g' ~/.secretd/config/genesis.json echo "cost member exercise evoke isolate gift cattle move bundle assume spell face balance lesson resemble orange bench surge now unhappy potato dress number acid" | - ./secretcli keys add a --recover -./secretd add-genesis-account "$(./secretcli keys show -a a)" 1000000000000uscrt -./secretd gentx --name a --keyring-backend test --amount 1000000uscrt -./secretd collect-gentxs -./secretd validate-genesis + secretcli keys add a --recover +secretd add-genesis-account "$(secretcli keys show -a a)" 1000000000000uscrt +secretd gentx --name a --keyring-backend test --amount 1000000uscrt +secretd collect-gentxs +secretd validate-genesis -./secretd init-bootstrap ./node-master-cert.der ./io-master-cert.der +secretd init-bootstrap ./node-master-cert.der ./io-master-cert.der -./secretd validate-genesis +secretd validate-genesis -RUST_BACKTRACE=1 ./secretd start --bootstrap & +RUST_BACKTRACE=1 secretd start --bootstrap & export secretd_PID=$(echo $!) -until (./secretcli status 2>&1 | jq -e '(.sync_info.latest_block_height | tonumber) > 0' &> /dev/null) -do +until (secretcli status 2>&1 | jq -e '(.sync_info.latest_block_height | tonumber) > 0' &>/dev/null); do echo "Waiting for chain to start..." sleep 1 done -./secretcli rest-server --chain-id enigma-testnet --laddr tcp://0.0.0.0:1337 & +secretcli rest-server --chain-id enigma-testnet --laddr tcp://0.0.0.0:1337 & export LCD_PID=$(echo $!) -function cleanup() -{ +function cleanup() { kill -KILL "$secretd_PID" "$LCD_PID" } trap cleanup EXIT ERR export STORE_TX_HASH=$( yes | - ./secretcli tx compute store ./x/compute/internal/keeper/testdata/test-contract/contract.wasm --from a --gas 10000000 | - jq -r .txhash + secretcli tx compute store ./x/compute/internal/keeper/testdata/test-contract/contract.wasm --from a --gas 10000000 | + jq -r .txhash ) wait_for_tx "$STORE_TX_HASH" "Waiting for store to finish on-chain..." # test storing of wasm code (this doesn't touch sgx yet) -./secretcli q tx "$STORE_TX_HASH" | +secretcli q tx "$STORE_TX_HASH" | jq -e '.logs[].events[].attributes[] | select(.key == "code_id" and .value == "1")' # init the contract (ocall_init + write_db + canonicalize_address) export INIT_TX_HASH=$( yes | - ./secretcli tx compute instantiate 1 '{"nop":{}}' --label baaaaaaa --from a | + secretcli tx compute instantiate 1 '{"nop":{}}' --label baaaaaaa --from a | jq -r .txhash ) wait_for_tx "$INIT_TX_HASH" "Waiting for instantiate to finish on-chain..." -./secretcli q compute tx "$INIT_TX_HASH" +secretcli q compute tx "$INIT_TX_HASH" export CONTRACT_ADDRESS=$( - ./secretcli q tx "$INIT_TX_HASH" | + secretcli q tx "$INIT_TX_HASH" | jq -er '.logs[].events[].attributes[] | select(.key == "contract_address") | .value' | head -1 ) # exec (generate callbacks) export EXEC_TX_HASH=$( yes | - ./secretcli tx compute execute --from a $CONTRACT_ADDRESS "{\"a\":{\"contract_addr\":\"$CONTRACT_ADDRESS\",\"x\":2,\"y\":3}}" | + secretcli tx compute execute --from a $CONTRACT_ADDRESS "{\"a\":{\"contract_addr\":\"$CONTRACT_ADDRESS\",\"x\":2,\"y\":3}}" | jq -r .txhash ) wait_for_tx "$EXEC_TX_HASH" "Waiting for exec to finish on-chain..." -./secretcli q compute tx "$EXEC_TX_HASH" +secretcli q compute tx "$EXEC_TX_HASH" # exec (generate error inside WASM) export EXEC_ERR_TX_HASH=$( yes | - ./secretcli tx compute execute --from a $CONTRACT_ADDRESS "{\"contract_error\":{\"error_type\":\"generic_err\"}}" | + secretcli tx compute execute --from a $CONTRACT_ADDRESS "{\"contract_error\":{\"error_type\":\"generic_err\"}}" | jq -r .txhash ) wait_for_tx "$EXEC_ERR_TX_HASH" "Waiting for exec to finish on-chain..." -./secretcli q compute tx "$EXEC_ERR_TX_HASH" +secretcli q compute tx "$EXEC_ERR_TX_HASH" # exec (generate error inside WASM) export EXEC_ERR_TX_HASH=$( yes | - ./secretcli tx compute execute --from a $CONTRACT_ADDRESS '{"allocate_on_heap":{"bytes":1073741824}}' | + secretcli tx compute execute --from a $CONTRACT_ADDRESS '{"allocate_on_heap":{"bytes":1073741824}}' | jq -r .txhash ) wait_for_tx "$EXEC_ERR_TX_HASH" "Waiting for exec to finish on-chain..." -./secretcli q compute tx "$EXEC_ERR_TX_HASH" +secretcli q compute tx "$EXEC_ERR_TX_HASH" # sleep infinity diff --git a/cosmwasm/testing/sanity-test-d-setup.sh b/cosmwasm/testing/sanity-test-d-setup.sh deleted file mode 100755 index 4b9b28776..000000000 --- a/cosmwasm/testing/sanity-test-d-setup.sh +++ /dev/null @@ -1,48 +0,0 @@ -#!/bin/bash - -#!/bin/bash - -# Use this script to run secretd with debugger -# Put this in .vscode/launch.json: -# { -# "version": "0.2.0", -# "configurations": [ -# { -# "name": "Go", -# "type": "go", -# "request": "launch", -# "mode": "auto", -# "cwd": "${workspaceFolder}", -# "program": "${workspaceFolder}/cmd/secretd", -# "env": { "SGX_MODE": "SW" }, -# "args": ["start", "--bootstrap"] -# } -# ] -# } -# And then: -# 1. Build secretcli and secretd `SGX_MODE=SW make build-linux` -# 2. Init the node: `SGX_MODE=SW cosmwasm/testing/sanity-test-d-setup.sh ` -# 3. Launch vscode in debug mode (you can set breakpoints in secretd go code) -# 4. Run the tests with secretcli: `SGX_MODE=SW cosmwasm/testing/sanity-test-only-cli.sh` - -set -euvx - -# init the node -rm -rf ./.sgx_secrets -mkdir -p ./.sgx_secrets - -rm -rf ~/.enigma* - -./secretd init banana --chain-id enigma-testnet -perl -i -pe 's/"stake"/"uscrt"/g' ~/.secretd/config/genesis.json -./secretcli config keyring-backend test -echo "cost member exercise evoke isolate gift cattle move bundle assume spell face balance lesson resemble orange bench surge now unhappy potato dress number acid" | - ./secretcli keys add a --recover -./secretd add-genesis-account "$(./secretcli keys show -a a)" 1000000000000uscrt -./secretd gentx --name a --keyring-backend test --amount 1000000uscrt -./secretd collect-gentxs -./secretd validate-genesis - -./secretd init-bootstrap ./node-master-cert.der ./io-master-cert.der - -./secretd validate-genesis diff --git a/cosmwasm/testing/sanity-test-only-cli.sh b/cosmwasm/testing/sanity-test-only-cli.sh deleted file mode 100755 index ee3b04463..000000000 --- a/cosmwasm/testing/sanity-test-only-cli.sh +++ /dev/null @@ -1,102 +0,0 @@ -#!/bin/bash - - -# Use this script to run secretd with debugger -# Put this in .vscode/launch.json: -# { -# "version": "0.2.0", -# "configurations": [ -# { -# "name": "Go", -# "type": "go", -# "request": "launch", -# "mode": "auto", -# "cwd": "${workspaceFolder}", -# "program": "${workspaceFolder}/cmd/secretd", -# "env": { "SGX_MODE": "SW" }, -# "args": ["start", "--bootstrap"] -# } -# ] -# } -# And then: -# 1. Build secretcli and secretd `SGX_MODE=SW make build-linux` -# 2. Init the node: `SGX_MODE=SW cosmwasm/testing/sanity-test-d-setup.sh ` -# 3. Launch vscode in debug mode (you can set breakpoints in secretd go code) -# 4. Run the tests with secretcli: `SGX_MODE=SW cosmwasm/testing/sanity-test-only-cli.sh` - - -set -euvx - -function wait_for_tx () { - until (./secretcli q tx "$1") - do - echo "$2" - sleep 1 - done -} - -./secretcli config chain-id enigma-testnet -./secretcli config output json -./secretcli config indent true -./secretcli config trust-node true -./secretcli config keyring-backend test - -until (./secretcli status 2>&1 | jq -e '(.sync_info.latest_block_height | tonumber) > 0' &> /dev/null) -do - echo "Waiting for chain to start..." - sleep 1 -done - -# store wasm code on-chain so we could later instansiate it -wget -O /tmp/contract.wasm https://raw.githubusercontent.com/CosmWasm/cosmwasm-examples/f5ea00a85247abae8f8cbcba301f94ef21c66087/erc20/contract.wasm -export STORE_TX_HASH=$( - yes | - ./secretcli tx compute store /tmp/contract.wasm --from a --gas 10000000 | - jq -r .txhash -) - -wait_for_tx "$STORE_TX_HASH" "Waiting for store to finish on-chain..." - -# test storing of wasm code (this doesn't touch sgx yet) -./secretcli q tx "$STORE_TX_HASH" | - jq -e '.logs[].events[].attributes[] | select(.key == "code_id" and .value == "1")' - -# init the contract (ocall_init + write_db + canonicalize_address) -# a is a tendermint address (will be used in transfer: https://github.com/CosmWasm/cosmwasm-examples/blob/f2f0568ebc90d812bcfaa0ef5eb1da149a951552/erc20/src/contract.rs#L110) -# secret1f395p0gg67mmfd5zcqvpnp9cxnu0hg6rjep44t is just a random address -# balances are set to 108 & 53 at init -export INIT_TX_HASH=$( - yes | - ./secretcli tx compute instantiate 1 "{\"decimals\":10,\"initial_balances\":[{\"address\":\"$(./secretcli keys show a -a)\",\"amount\":\"108\"},{\"address\":\"secret1f395p0gg67mmfd5zcqvpnp9cxnu0hg6rjep44t\",\"amount\":\"53\"}],\"name\":\"ReuvenPersonalRustCoin\",\"symbol\":\"RPRC\"}" --label RPRCCoin --from a | - jq -r .txhash -) - -wait_for_tx "$INIT_TX_HASH" "Waiting for instantiate to finish on-chain..." - -export CONTRACT_ADDRESS=$( - ./secretcli q tx "$INIT_TX_HASH" | - jq -er '.logs[].events[].attributes[] | select(.key == "contract_address") | .value' -) - -# test balances after init (ocall_query + read_db + canonicalize_address) -./secretcli q compute query "$CONTRACT_ADDRESS" "{\"balance\":{\"address\":\"$(./secretcli keys show a -a)\"}}" | - jq -e '.balance == "108"' -./secretcli q compute query "$CONTRACT_ADDRESS" "{\"balance\":{\"address\":\"secret1f395p0gg67mmfd5zcqvpnp9cxnu0hg6rjep44t\"}}" | - jq -e '.balance == "53"' - -# transfer 10 balance (ocall_handle + read_db + write_db + humanize_address + canonicalize_address) -export TRANSFER_TX_HASH=$( - yes | - ./secretcli tx compute execute --from a "$CONTRACT_ADDRESS" '{"transfer":{"amount":"10","recipient":"secret1f395p0gg67mmfd5zcqvpnp9cxnu0hg6rjep44t"}}' | - jq -r .txhash -) - -wait_for_tx "$TRANSFER_TX_HASH" "Waiting for transfer to finish on-chain..." - -# test balances after transfer (ocall_query + read_db) -./secretcli q compute query "$CONTRACT_ADDRESS" "{\"balance\":{\"address\":\"$(./secretcli keys show a -a)\"}}" | - jq -e '.balance == "98"' -./secretcli q compute query "$CONTRACT_ADDRESS" "{\"balance\":{\"address\":\"secret1f395p0gg67mmfd5zcqvpnp9cxnu0hg6rjep44t\"}}" | - jq -e '.balance == "63"' - -echo "All is done. Yay!" diff --git a/cosmwasm/testing/sanity-test.sh b/cosmwasm/testing/sanity-test.sh index ce77c6403..dd3754915 100755 --- a/cosmwasm/testing/sanity-test.sh +++ b/cosmwasm/testing/sanity-test.sh @@ -2,9 +2,11 @@ set -euvx -function wait_for_tx () { - until (./secretcli q tx "$1") - do +alias secretcli="./secretcli" +alias secretd="./secretd" + +function wait_for_tx() { + until (secretcli q tx "$1"); do echo "$2" sleep 1 done @@ -15,39 +17,37 @@ rm -rf ./.sgx_secrets mkdir -p ./.sgx_secrets rm -rf ~/.secret* -./secretcli config chain-id secret-sanity -./secretcli config output json -./secretcli config indent true -./secretcli config trust-node true -./secretcli config keyring-backend test +secretcli config chain-id secret-sanity +secretcli config output json +secretcli config indent true +secretcli config trust-node true +secretcli config keyring-backend test -./secretd init banana --chain-id secret-sanity +secretd init banana --chain-id secret-sanity perl -i -pe 's/"stake"/"uscrt"/g' ~/.secretd/config/genesis.json echo "cost member exercise evoke isolate gift cattle move bundle assume spell face balance lesson resemble orange bench surge now unhappy potato dress number acid" | - ./secretcli keys add a --recover -./secretd add-genesis-account "$(./secretcli keys show -a a)" 1000000000000uscrt -./secretd gentx --name a --keyring-backend test --amount 1000000uscrt -./secretd collect-gentxs -./secretd validate-genesis + secretcli keys add a --recover +secretd add-genesis-account "$(secretcli keys show -a a)" 1000000000000uscrt +secretd gentx --name a --keyring-backend test --amount 1000000uscrt +secretd collect-gentxs +secretd validate-genesis -./secretd init-bootstrap ./node-master-cert.der ./io-master-cert.der +secretd init-bootstrap ./node-master-cert.der ./io-master-cert.der -./secretd validate-genesis +secretd validate-genesis -RUST_BACKTRACE=1 ./secretd start --bootstrap & +RUST_BACKTRACE=1 secretd start --bootstrap & export SECRETD_PID=$(echo $!) -until (./secretcli status 2>&1 | jq -e '(.sync_info.latest_block_height | tonumber) > 0' &> /dev/null) -do +until (secretcli status 2>&1 | jq -e '(.sync_info.latest_block_height | tonumber) > 0' &>/dev/null); do echo "Waiting for chain to start..." sleep 1 done -./secretcli rest-server --chain-id secret-sanity --laddr tcp://0.0.0.0:1337 & +secretcli rest-server --chain-id secret-sanity --laddr tcp://0.0.0.0:1337 & export LCD_PID=$(echo $!) -function cleanup() -{ +function cleanup() { kill -KILL "$SECRETD_PID" "$LCD_PID" } trap cleanup EXIT ERR @@ -55,14 +55,14 @@ trap cleanup EXIT ERR # store wasm code on-chain so we could later instansiate it export STORE_TX_HASH=$( yes | - ./secretcli tx compute store ./x/compute/internal/keeper/testdata/erc20.wasm --from a --gas 10000000 | - jq -r .txhash + secretcli tx compute store ./x/compute/internal/keeper/testdata/erc20.wasm --from a --gas 10000000 | + jq -r .txhash ) wait_for_tx "$STORE_TX_HASH" "Waiting for store to finish on-chain..." # test storing of wasm code (this doesn't touch sgx yet) -./secretcli q tx "$STORE_TX_HASH" | +secretcli q tx "$STORE_TX_HASH" | jq -e '.logs[].events[].attributes[] | select(.key == "code_id" and .value == "1")' # init the contract (ocall_init + write_db + canonicalize_address) @@ -71,38 +71,38 @@ wait_for_tx "$STORE_TX_HASH" "Waiting for store to finish on-chain..." # balances are set to 108 & 53 at init export INIT_TX_HASH=$( yes | - ./secretcli tx compute instantiate 1 "{\"decimals\":10,\"initial_balances\":[{\"address\":\"$(./secretcli keys show a -a)\",\"amount\":\"108\"},{\"address\":\"secret1f395p0gg67mmfd5zcqvpnp9cxnu0hg6rjep44t\",\"amount\":\"53\"}],\"name\":\"ReuvenPersonalRustCoin\",\"symbol\":\"RPRC\"}" --label RPRCCoin --from a | + secretcli tx compute instantiate 1 "{\"decimals\":10,\"initial_balances\":[{\"address\":\"$(secretcli keys show a -a)\",\"amount\":\"108\"},{\"address\":\"secret1f395p0gg67mmfd5zcqvpnp9cxnu0hg6rjep44t\",\"amount\":\"53\"}],\"name\":\"ReuvenPersonalRustCoin\",\"symbol\":\"RPRC\"}" --label RPRCCoin --from a | jq -r .txhash ) wait_for_tx "$INIT_TX_HASH" "Waiting for instantiate to finish on-chain..." -./secretcli q compute tx "$INIT_TX_HASH" +secretcli q compute tx "$INIT_TX_HASH" export CONTRACT_ADDRESS=$( - ./secretcli q tx "$INIT_TX_HASH" | + secretcli q tx "$INIT_TX_HASH" | jq -er '.logs[].events[].attributes[] | select(.key == "contract_address") | .value' ) # test balances after init (ocall_query + read_db + canonicalize_address) -./secretcli q compute query "$CONTRACT_ADDRESS" "{\"balance\":{\"address\":\"$(./secretcli keys show a -a)\"}}" | +secretcli q compute query "$CONTRACT_ADDRESS" "{\"balance\":{\"address\":\"$(secretcli keys show a -a)\"}}" | jq -e '.balance == "108"' -./secretcli q compute query "$CONTRACT_ADDRESS" "{\"balance\":{\"address\":\"secret1f395p0gg67mmfd5zcqvpnp9cxnu0hg6rjep44t\"}}" | +secretcli q compute query "$CONTRACT_ADDRESS" "{\"balance\":{\"address\":\"secret1f395p0gg67mmfd5zcqvpnp9cxnu0hg6rjep44t\"}}" | jq -e '.balance == "53"' # transfer 10 balance (ocall_handle + read_db + write_db + humanize_address + canonicalize_address) yes | - ./secretcli tx compute execute --from a "$CONTRACT_ADDRESS" '{"transfer":{"amount":"10","recipient":"secret1f395p0gg67mmfd5zcqvpnp9cxnu0hg6rjep44t"}}' -b block | + secretcli tx compute execute --from a "$CONTRACT_ADDRESS" '{"transfer":{"amount":"10","recipient":"secret1f395p0gg67mmfd5zcqvpnp9cxnu0hg6rjep44t"}}' -b block | jq -r .txhash | - xargs ./secretcli q compute tx + xargs secretcli q compute tx # test balances after transfer (ocall_query + read_db) -./secretcli q compute query "$CONTRACT_ADDRESS" "{\"balance\":{\"address\":\"$(./secretcli keys show a -a)\"}}" | +secretcli q compute query "$CONTRACT_ADDRESS" "{\"balance\":{\"address\":\"$(secretcli keys show a -a)\"}}" | jq -e '.balance == "98"' -./secretcli q compute query "$CONTRACT_ADDRESS" "{\"balance\":{\"address\":\"secret1f395p0gg67mmfd5zcqvpnp9cxnu0hg6rjep44t\"}}" | +secretcli q compute query "$CONTRACT_ADDRESS" "{\"balance\":{\"address\":\"secret1f395p0gg67mmfd5zcqvpnp9cxnu0hg6rjep44t\"}}" | jq -e '.balance == "63"' -(./secretcli q compute query "$CONTRACT_ADDRESS" "{\"balance\":{\"address\":\"secret1zzzzzzzzzzzzzzzzzz\"}}" || true) 2>&1 | grep -c 'canonicalize_address errored: invalid checksum' +(secretcli q compute query "$CONTRACT_ADDRESS" "{\"balance\":{\"address\":\"secret1zzzzzzzzzzzzzzzzzz\"}}" || true) 2>&1 | grep -c 'canonicalize_address errored: invalid checksum' # sleep infinity