mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 07:31:02 +00:00
add simnet tests (#3381)
This commit is contained in:
@@ -0,0 +1,39 @@
|
|||||||
|
# Simulation tests, or high level integration tests.
|
||||||
|
|
||||||
|
|
||||||
|
_The content of this directory is meant to be used by Parity's private CI/CD
|
||||||
|
infrastructure with private tools. At the moment those tools are still early
|
||||||
|
stage of development and we don't know if / when they will available for
|
||||||
|
public use._
|
||||||
|
|
||||||
|
|
||||||
|
## Content of this dir.
|
||||||
|
|
||||||
|
`configs` dir contains config files in toml format that describe how to
|
||||||
|
configure the simulation network that you want to launch.
|
||||||
|
|
||||||
|
`tests` dir contains [cucumber](https://cucumber.io/) files. Those are
|
||||||
|
Behavior-Driven Development test files that describe tests in plain English.
|
||||||
|
Under the hood there are assertions that specific metrics should have specific
|
||||||
|
values.
|
||||||
|
|
||||||
|
At the moment we have only one test for parachains: `/parachains.features`
|
||||||
|
This test uses a JS script that we added to simnet image and it's launched
|
||||||
|
by this step in the cucumber file:
|
||||||
|
` Then launch 'node' with parameters '--unhandled-rejections=strict /usr/local/bin/simnet_scripts test_parachain ./configs/adder.json ws://localhost:11222 100 10'`
|
||||||
|
|
||||||
|
`run_test.sh` is an entry point for running all tests in the folder.
|
||||||
|
Any setup required for tests (but cannot be done in configs) is performed
|
||||||
|
here. The main script's responsibility is to run [gurke](https://github.com/paritytech/gurke)
|
||||||
|
with passed parameters.
|
||||||
|
In order to use this script locally, you need to install
|
||||||
|
[gurke](https://github.com/paritytech/gurke)
|
||||||
|
Once you have access to a kubernetes cluster (meaning you can do `kubectl get pods`)
|
||||||
|
you can run this script with no arguments, like `./run_test.sh` and tests should run.
|
||||||
|
Kubernetes cluster can be local, spawned with
|
||||||
|
[kind](https://kind.sigs.k8s.io/docs/user/quick-start/#installation)
|
||||||
|
or an instance living in the
|
||||||
|
[cloud](https://github.com/paritytech/gurke/blob/main/docs/How-to-setup-access-to-gke-k8s-cluster.md)
|
||||||
|
|
||||||
|
### [Here is link to barcamp presenation of simnet](https://www.crowdcast.io/e/ph49xu01)
|
||||||
|
### [Here is link to the simnet repo, hosted on private gitlab](https://gitlab.parity.io/parity/simnet/-/tree/master)
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"Header":{
|
||||||
|
"number":"u64",
|
||||||
|
"parent_hash":"Hash",
|
||||||
|
"post_state":"Hash"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
[settings.setup]
|
||||||
|
timeout = 300
|
||||||
|
|
||||||
|
[settings.defaults]
|
||||||
|
command = "/usr/local/bin/polkadot"
|
||||||
|
chain-spec = "rococo-local.json"
|
||||||
|
timeout = 300
|
||||||
|
|
||||||
|
[init_nodes.chainspec]
|
||||||
|
image = "{{get_env(name="SYNTHIMAGE") | safe }}"
|
||||||
|
command = "/usr/local/bin/polkadot build-spec --chain rococo-local --disable-default-bootnode --raw > /cfg/rococo-local.json"
|
||||||
|
fetch-files = [ "/cfg/rococo-local.json" ]
|
||||||
|
timeout = 300
|
||||||
|
|
||||||
|
[init_nodes.parachain-specs]
|
||||||
|
image = "{{get_env(name="COLIMAGE") | safe }}"
|
||||||
|
command = """
|
||||||
|
/usr/local/bin/adder-collator export-genesis-state > /cfg/genesis-state &&
|
||||||
|
/usr/local/bin/adder-collator export-genesis-wasm > /cfg/genesis-wasm
|
||||||
|
"""
|
||||||
|
fetch-files = [ "/cfg/genesis-wasm", "/cfg/genesis-state" ]
|
||||||
|
timeout = 300
|
||||||
|
|
||||||
|
[nodes.alice]
|
||||||
|
validator = true
|
||||||
|
extra-args = ["--alice"]
|
||||||
|
|
||||||
|
[nodes.bob]
|
||||||
|
validator = true
|
||||||
|
extra-args = ["--bob"]
|
||||||
|
|
||||||
|
[nodes.collator01]
|
||||||
|
image = "{{get_env(name="COLIMAGE") | safe }}"
|
||||||
|
command-with-args = "/usr/local/bin/adder-collator --chain /cfg/rococo-local.json --port 30333 --no-mdns --bootnodes /dns/bootnode/tcp/30333/p2p/12D3KooWEyoppNCUx8Yx66oV9fJnriXwCcXwDDUA2kj6vnc6iDEp"
|
||||||
|
|
||||||
|
[nodes.nodejs]
|
||||||
|
image = "{{get_env(name="SCRIPTSIMAGE") | safe }}"
|
||||||
|
command-with-args = """
|
||||||
|
cd simnet_scripts;
|
||||||
|
npm run build;
|
||||||
|
node /usr/local/bin/simnet_scripts register_parachain /cfg/genesis-wasm /cfg/genesis-state 100 true ws://bootnode:9944;
|
||||||
|
tail -f /dev/null
|
||||||
|
"""
|
||||||
|
copy-files = [
|
||||||
|
"genesis-state",
|
||||||
|
"genesis-wasm",
|
||||||
|
]
|
||||||
Executable
+102
@@ -0,0 +1,102 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
### ARGS FOR THIS SCRIPT ###
|
||||||
|
# ./${SCRIPT_NAME} NAMESPACE IMAGE LOG_PATH
|
||||||
|
# All args have default values, specify args to override
|
||||||
|
# e.g: ./${SCRIPT_NAME} radu-test parity/substrate:some_feature /var/log/gurke
|
||||||
|
|
||||||
|
set -eou pipefail
|
||||||
|
SCRIPT_NAME="$0"
|
||||||
|
SCRIPT_PATH=$(dirname "${SCRIPT_NAME}") # relative
|
||||||
|
SCRIPT_PATH=$(cd "${SCRIPT_PATH}" && pwd) # absolutized and normalized
|
||||||
|
|
||||||
|
function random_string {
|
||||||
|
head -1 <(fold -w 30 <(tr -dc 'a-z0-9' < /dev/urandom))
|
||||||
|
}
|
||||||
|
|
||||||
|
NAMESPACE=${1:-gurke-"$(random_string)"-runtest}
|
||||||
|
IMAGE=${2:-"docker.io/paritypr/synth-wave:master"}
|
||||||
|
LOG_PATH=${3:-"${SCRIPT_PATH}/logs"}
|
||||||
|
COLIMAGE=${4:-"docker.io/paritypr/colander:master"}
|
||||||
|
SCRIPTSIMAGE=${5:-"docker.io/paritytech/simnet:latest"}
|
||||||
|
|
||||||
|
mkdir -p "${SCRIPT_PATH}"/logs
|
||||||
|
|
||||||
|
echo "Running tests in namespace: ${NAMESPACE}"
|
||||||
|
echo "Testing image: ${IMAGE}"
|
||||||
|
echo "Storing scripts logs to: ${LOG_PATH}"
|
||||||
|
echo "Colator image is ${COLIMAGE}"
|
||||||
|
echo "SCRIPTSIMAGE image is ${SCRIPTSIMAGE}"
|
||||||
|
|
||||||
|
|
||||||
|
function forward_port {
|
||||||
|
|
||||||
|
# RUN_IN_CONTAINER is env var that is set in the dockerfile
|
||||||
|
# use the -v operator to explicitly test if a variable is set
|
||||||
|
if [[ ! -v RUN_IN_CONTAINER ]] ; then
|
||||||
|
if is_port_forward_running ; then
|
||||||
|
kill_previous_job
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
start_forwading_job
|
||||||
|
}
|
||||||
|
|
||||||
|
FORWARD_GREP_FILTER='kubectl.*[p]ort-forward.*svc/rpc.*11222'
|
||||||
|
|
||||||
|
function is_port_forward_running {
|
||||||
|
# shellcheck disable=SC2009
|
||||||
|
ps aux | grep -qE "${FORWARD_GREP_FILTER}"
|
||||||
|
}
|
||||||
|
|
||||||
|
function kill_previous_job {
|
||||||
|
# shellcheck disable=SC2009
|
||||||
|
job_pid=$(ps aux | grep -E "${FORWARD_GREP_FILTER}" | awk '{ print $2 }')
|
||||||
|
echo "INFO Killed forwading port 9944 into bootnode"
|
||||||
|
kill "${job_pid}"
|
||||||
|
}
|
||||||
|
|
||||||
|
function start_forwading_job {
|
||||||
|
kubectl -n "${NAMESPACE}" \
|
||||||
|
expose pod bootnode \
|
||||||
|
--name=rpc \
|
||||||
|
--type=NodePort \
|
||||||
|
--target-port=9944 \
|
||||||
|
--port=9944
|
||||||
|
kubectl -n "${NAMESPACE}" \
|
||||||
|
port-forward svc/rpc 11222:9944 &> "${LOG_PATH}/forward-${NAMESPACE}.log" &
|
||||||
|
sleep 2
|
||||||
|
echo "INFO Started forwading port 9944 into bootnode"
|
||||||
|
}
|
||||||
|
|
||||||
|
function update_api {
|
||||||
|
pwd
|
||||||
|
cd "${SCRIPT_PATH}"/../../simnet_scripts/
|
||||||
|
npm run build
|
||||||
|
cd -
|
||||||
|
pwd
|
||||||
|
}
|
||||||
|
|
||||||
|
echo "INFO: Checking if namespace has no pods"
|
||||||
|
kubectl -n "${NAMESPACE}" get pods
|
||||||
|
|
||||||
|
export NAMESPACE="${NAMESPACE}"
|
||||||
|
export COLIMAGE="${COLIMAGE}"
|
||||||
|
export SYNTHIMAGE="${IMAGE}"
|
||||||
|
export SCRIPTSIMAGE="${SCRIPTSIMAGE}"
|
||||||
|
|
||||||
|
cd "${SCRIPT_PATH}"
|
||||||
|
|
||||||
|
set -x # echo the commands to stdout
|
||||||
|
gurke spawn --config "${SCRIPT_PATH}"/configs/simple_rococo_testnet.toml \
|
||||||
|
-n "${NAMESPACE}" \
|
||||||
|
--image "${IMAGE}"
|
||||||
|
|
||||||
|
echo "INFO: Checking if pods launched correctly"
|
||||||
|
kubectl -n "${NAMESPACE}" get pods -o wide
|
||||||
|
echo "INFO: Updating Polkadot JS API"
|
||||||
|
update_api
|
||||||
|
forward_port
|
||||||
|
|
||||||
|
# Run tests
|
||||||
|
gurke test "${NAMESPACE}" "${SCRIPT_PATH}"/tests --log-path "${LOG_PATH}"
|
||||||
|
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
Feature: ParaTesting
|
||||||
|
|
||||||
|
Scenario: spawn parachains network and check parachains
|
||||||
|
Given a test network
|
||||||
|
Then sleep 200 seconds
|
||||||
|
Then launch 'node' with parameters '--unhandled-rejections=strict /usr/local/bin/simnet_scripts test_parachain ./configs/adder.json ws://localhost:11222 100 10'
|
||||||
Reference in New Issue
Block a user