Skip to content

Commit

Permalink
(experimental) development scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
pro-wh committed Jul 28, 2020
1 parent 01ee3ea commit 84fca7a
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ test: build tests/oasis-net-runner tests/oasis-node tests/rosetta-cli
@printf "$(CYAN)*** Running tests...$(OFF)\n"
@$(ROOT)/tests/test.sh

ti: tests/oasis-net-runner tests/oasis-node tests/rosetta-cli
@printf "$(CYAN)*** Running tests...$(OFF)\n"
@$(ROOT)/tests/test-interactive.sh

fmt:
@printf "$(CYAN)*** Formatting code...$(OFF)\n"
@$(GO) fmt ./...
Expand Down
3 changes: 3 additions & 0 deletions tests/build-run-gateway.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# source this
make -C .. build || return
../oasis-core-rosetta-gateway &
130 changes: 130 additions & 0 deletions tests/test-interactive.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
#!/usr/bin/env bash
set -o nounset -o pipefail -o errexit
trap "exit 1" INT

# Get the root directory of the tests dir inside the repository.
ROOT="$(cd $(dirname $0); pwd -P)"
cd "${ROOT}"

# ANSI escape codes to brighten up the output.
GRN=$'\e[32;1m'
OFF=$'\e[0m'

# Paths to various binaries and config files that we need.
OASIS_ROSETTA_GW="${ROOT}/../oasis-core-rosetta-gateway"
OASIS_NET_RUNNER="${ROOT}/oasis-net-runner"
OASIS_NODE="${ROOT}/oasis-node"
FIXTURE_FILE="${ROOT}/test-fixture-config.json"

# Destination address for test transfers.
DST="oasis1qpkant39yhx59sagnzpc8v0sg8aerwa3jyqde3ge"

# Kill all dangling processes on exit.
cleanup() {
printf "${OFF}"
pkill -P $$ || true
wait || true
}
trap "cleanup" EXIT

# The base directory for all the node and test env cruft.
TEST_BASE_DIR=$(mktemp -d -t oasis-rosetta-XXXXXXXXXX)

# The oasis-node binary must be in the path for the oasis-net-runner to find it.
export PATH="${PATH}:${ROOT}"

printf "${GRN}### Starting the test network...${OFF}\n"
${OASIS_NET_RUNNER} \
--fixture.file ${FIXTURE_FILE} \
--basedir.no_temp_dir \
--basedir ${TEST_BASE_DIR} &

export OASIS_NODE_GRPC_ADDR="unix:${TEST_BASE_DIR}/net-runner/network/client-0/internal.sock"

# How many nodes to wait for each epoch.
NUM_NODES=1

# Current nonce for transactions (incremented after every submit_tx).
NONCE=0

# Helper function for advancing the current epoch to the given parameter.
advance_epoch() {
local epoch=$1
printf "${GRN}### Advancing epoch ($epoch)...${OFF}\n"
${OASIS_NODE} debug control set-epoch \
--address ${OASIS_NODE_GRPC_ADDR} \
--epoch $epoch
}

# Helper function that waits for all nodes to register.
wait_for_nodes() {
printf "${GRN}### Waiting for all nodes to register...${OFF}\n"
${OASIS_NODE} debug control wait-nodes \
--address ${OASIS_NODE_GRPC_ADDR} \
--nodes ${NUM_NODES} \
--wait
}

# Helper function that submits the given transaction JSON file.
submit_tx() {
local tx=$1
# Submit transaction.
${OASIS_NODE} consensus submit_tx \
--transaction.file "$tx" \
--address ${OASIS_NODE_GRPC_ADDR} \
--debug.allow_test_keys
# Increase nonce.
NONCE=$((NONCE+1))
}

# Helper function that generates a transfer transaction.
gen_transfer() {
local tx=$1
local amount=$2
local dst=$3
${OASIS_NODE} stake account gen_transfer \
--stake.amount $amount \
--stake.transfer.destination "$dst" \
--transaction.file "$tx" \
--transaction.nonce ${NONCE} \
--transaction.fee.amount 0 \
--transaction.fee.gas 10000 \
--debug.dont_blame_oasis \
--debug.test_entity \
--debug.allow_test_keys \
--genesis.file "${TEST_BASE_DIR}/net-runner/network/genesis.json"
}

# Helper function that generates a burn transaction.
gen_burn() {
local tx=$1
local amount=$2
${OASIS_NODE} stake account gen_burn \
--stake.amount $amount \
--transaction.file "$tx" \
--transaction.nonce ${NONCE} \
--transaction.fee.amount 1 \
--transaction.fee.gas 10000 \
--debug.dont_blame_oasis \
--debug.test_entity \
--debug.allow_test_keys \
--genesis.file "${TEST_BASE_DIR}/net-runner/network/genesis.json"
}

printf "${GRN}### Waiting for the validator to register...${OFF}\n"
${OASIS_NODE} debug control wait-nodes \
--address ${OASIS_NODE_GRPC_ADDR} \
--nodes 1 \
--wait

sleep 3

printf "${GRN}### Entering interactive...${OFF}\n"
bash

rm -rf "${ROOT}/validator-data" /tmp/rosetta-cli*

# Clean up after a successful run.
rm -rf "${TEST_BASE_DIR}"

printf "${GRN}### Tests finished.${OFF}\n"

0 comments on commit 84fca7a

Please sign in to comment.