-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
137 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# source this | ||
make -C .. build || return | ||
../oasis-core-rosetta-gateway & |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |