Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit 010ea97

Browse files
authored
add simnet tests (#3381)
1 parent 68074a7 commit 010ea97

File tree

5 files changed

+201
-0
lines changed

5 files changed

+201
-0
lines changed

Diff for: simnet_tests/README.md

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Simulation tests, or high level integration tests.
2+
3+
4+
_The content of this directory is meant to be used by Parity's private CI/CD
5+
infrastructure with private tools. At the moment those tools are still early
6+
stage of development and we don't know if / when they will available for
7+
public use._
8+
9+
10+
## Content of this dir.
11+
12+
`configs` dir contains config files in toml format that describe how to
13+
configure the simulation network that you want to launch.
14+
15+
`tests` dir contains [cucumber](https://cucumber.io/) files. Those are
16+
Behavior-Driven Development test files that describe tests in plain English.
17+
Under the hood there are assertions that specific metrics should have specific
18+
values.
19+
20+
At the moment we have only one test for parachains: `/parachains.features`
21+
This test uses a JS script that we added to simnet image and it's launched
22+
by this step in the cucumber file:
23+
` Then launch 'node' with parameters '--unhandled-rejections=strict /usr/local/bin/simnet_scripts test_parachain ./configs/adder.json ws://localhost:11222 100 10'`
24+
25+
`run_test.sh` is an entry point for running all tests in the folder.
26+
Any setup required for tests (but cannot be done in configs) is performed
27+
here. The main script's responsibility is to run [gurke](https://github.com/paritytech/gurke)
28+
with passed parameters.
29+
In order to use this script locally, you need to install
30+
[gurke](https://github.com/paritytech/gurke)
31+
Once you have access to a kubernetes cluster (meaning you can do `kubectl get pods`)
32+
you can run this script with no arguments, like `./run_test.sh` and tests should run.
33+
Kubernetes cluster can be local, spawned with
34+
[kind](https://kind.sigs.k8s.io/docs/user/quick-start/#installation)
35+
or an instance living in the
36+
[cloud](https://github.com/paritytech/gurke/blob/main/docs/How-to-setup-access-to-gke-k8s-cluster.md)
37+
38+
### [Here is link to barcamp presenation of simnet](https://www.crowdcast.io/e/ph49xu01)
39+
### [Here is link to the simnet repo, hosted on private gitlab](https://gitlab.parity.io/parity/simnet/-/tree/master)

Diff for: simnet_tests/configs/adder.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"Header":{
3+
"number":"u64",
4+
"parent_hash":"Hash",
5+
"post_state":"Hash"
6+
}
7+
}

Diff for: simnet_tests/configs/simple_rococo_testnet.toml

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
[settings.setup]
2+
timeout = 300
3+
4+
[settings.defaults]
5+
command = "/usr/local/bin/polkadot"
6+
chain-spec = "rococo-local.json"
7+
timeout = 300
8+
9+
[init_nodes.chainspec]
10+
image = "{{get_env(name="SYNTHIMAGE") | safe }}"
11+
command = "/usr/local/bin/polkadot build-spec --chain rococo-local --disable-default-bootnode --raw > /cfg/rococo-local.json"
12+
fetch-files = [ "/cfg/rococo-local.json" ]
13+
timeout = 300
14+
15+
[init_nodes.parachain-specs]
16+
image = "{{get_env(name="COLIMAGE") | safe }}"
17+
command = """
18+
/usr/local/bin/adder-collator export-genesis-state > /cfg/genesis-state &&
19+
/usr/local/bin/adder-collator export-genesis-wasm > /cfg/genesis-wasm
20+
"""
21+
fetch-files = [ "/cfg/genesis-wasm", "/cfg/genesis-state" ]
22+
timeout = 300
23+
24+
[nodes.alice]
25+
validator = true
26+
extra-args = ["--alice"]
27+
28+
[nodes.bob]
29+
validator = true
30+
extra-args = ["--bob"]
31+
32+
[nodes.collator01]
33+
image = "{{get_env(name="COLIMAGE") | safe }}"
34+
command-with-args = "/usr/local/bin/adder-collator --chain /cfg/rococo-local.json --port 30333 --no-mdns --bootnodes /dns/bootnode/tcp/30333/p2p/12D3KooWEyoppNCUx8Yx66oV9fJnriXwCcXwDDUA2kj6vnc6iDEp"
35+
36+
[nodes.nodejs]
37+
image = "{{get_env(name="SCRIPTSIMAGE") | safe }}"
38+
command-with-args = """
39+
cd simnet_scripts;
40+
npm run build;
41+
node /usr/local/bin/simnet_scripts register_parachain /cfg/genesis-wasm /cfg/genesis-state 100 true ws://bootnode:9944;
42+
tail -f /dev/null
43+
"""
44+
copy-files = [
45+
"genesis-state",
46+
"genesis-wasm",
47+
]

Diff for: simnet_tests/run_tests.sh

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
#!/bin/bash
2+
3+
### ARGS FOR THIS SCRIPT ###
4+
# ./${SCRIPT_NAME} NAMESPACE IMAGE LOG_PATH
5+
# All args have default values, specify args to override
6+
# e.g: ./${SCRIPT_NAME} radu-test parity/substrate:some_feature /var/log/gurke
7+
8+
set -eou pipefail
9+
SCRIPT_NAME="$0"
10+
SCRIPT_PATH=$(dirname "${SCRIPT_NAME}") # relative
11+
SCRIPT_PATH=$(cd "${SCRIPT_PATH}" && pwd) # absolutized and normalized
12+
13+
function random_string {
14+
head -1 <(fold -w 30 <(tr -dc 'a-z0-9' < /dev/urandom))
15+
}
16+
17+
NAMESPACE=${1:-gurke-"$(random_string)"-runtest}
18+
IMAGE=${2:-"docker.io/paritypr/synth-wave:master"}
19+
LOG_PATH=${3:-"${SCRIPT_PATH}/logs"}
20+
COLIMAGE=${4:-"docker.io/paritypr/colander:master"}
21+
SCRIPTSIMAGE=${5:-"docker.io/paritytech/simnet:latest"}
22+
23+
mkdir -p "${SCRIPT_PATH}"/logs
24+
25+
echo "Running tests in namespace: ${NAMESPACE}"
26+
echo "Testing image: ${IMAGE}"
27+
echo "Storing scripts logs to: ${LOG_PATH}"
28+
echo "Colator image is ${COLIMAGE}"
29+
echo "SCRIPTSIMAGE image is ${SCRIPTSIMAGE}"
30+
31+
32+
function forward_port {
33+
34+
# RUN_IN_CONTAINER is env var that is set in the dockerfile
35+
# use the -v operator to explicitly test if a variable is set
36+
if [[ ! -v RUN_IN_CONTAINER ]] ; then
37+
if is_port_forward_running ; then
38+
kill_previous_job
39+
fi
40+
fi
41+
start_forwading_job
42+
}
43+
44+
FORWARD_GREP_FILTER='kubectl.*[p]ort-forward.*svc/rpc.*11222'
45+
46+
function is_port_forward_running {
47+
# shellcheck disable=SC2009
48+
ps aux | grep -qE "${FORWARD_GREP_FILTER}"
49+
}
50+
51+
function kill_previous_job {
52+
# shellcheck disable=SC2009
53+
job_pid=$(ps aux | grep -E "${FORWARD_GREP_FILTER}" | awk '{ print $2 }')
54+
echo "INFO Killed forwading port 9944 into bootnode"
55+
kill "${job_pid}"
56+
}
57+
58+
function start_forwading_job {
59+
kubectl -n "${NAMESPACE}" \
60+
expose pod bootnode \
61+
--name=rpc \
62+
--type=NodePort \
63+
--target-port=9944 \
64+
--port=9944
65+
kubectl -n "${NAMESPACE}" \
66+
port-forward svc/rpc 11222:9944 &> "${LOG_PATH}/forward-${NAMESPACE}.log" &
67+
sleep 2
68+
echo "INFO Started forwading port 9944 into bootnode"
69+
}
70+
71+
function update_api {
72+
pwd
73+
cd "${SCRIPT_PATH}"/../../simnet_scripts/
74+
npm run build
75+
cd -
76+
pwd
77+
}
78+
79+
echo "INFO: Checking if namespace has no pods"
80+
kubectl -n "${NAMESPACE}" get pods
81+
82+
export NAMESPACE="${NAMESPACE}"
83+
export COLIMAGE="${COLIMAGE}"
84+
export SYNTHIMAGE="${IMAGE}"
85+
export SCRIPTSIMAGE="${SCRIPTSIMAGE}"
86+
87+
cd "${SCRIPT_PATH}"
88+
89+
set -x # echo the commands to stdout
90+
gurke spawn --config "${SCRIPT_PATH}"/configs/simple_rococo_testnet.toml \
91+
-n "${NAMESPACE}" \
92+
--image "${IMAGE}"
93+
94+
echo "INFO: Checking if pods launched correctly"
95+
kubectl -n "${NAMESPACE}" get pods -o wide
96+
echo "INFO: Updating Polkadot JS API"
97+
update_api
98+
forward_port
99+
100+
# Run tests
101+
gurke test "${NAMESPACE}" "${SCRIPT_PATH}"/tests --log-path "${LOG_PATH}"
102+

Diff for: simnet_tests/tests/parachains.feature

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Feature: ParaTesting
2+
3+
Scenario: spawn parachains network and check parachains
4+
Given a test network
5+
Then sleep 200 seconds
6+
Then launch 'node' with parameters '--unhandled-rejections=strict /usr/local/bin/simnet_scripts test_parachain ./configs/adder.json ws://localhost:11222 100 10'

0 commit comments

Comments
 (0)