Skip to content

Commit

Permalink
alias secret{d,cli} in bash tests
Browse files Browse the repository at this point in the history
  • Loading branch information
assafmo committed Sep 17, 2020
1 parent 241aca2 commit 0a0545e
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 219 deletions.
69 changes: 35 additions & 34 deletions cosmwasm/testing/callback-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
48 changes: 0 additions & 48 deletions cosmwasm/testing/sanity-test-d-setup.sh

This file was deleted.

102 changes: 0 additions & 102 deletions cosmwasm/testing/sanity-test-only-cli.sh

This file was deleted.

Loading

0 comments on commit 0a0545e

Please sign in to comment.