Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Complete dockernet setup #69

Merged
merged 2 commits into from
May 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 116 additions & 1 deletion dockernet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,53 @@ Note: ensure price-feeder repo is cloned under elys repository.

The configuration files and genesis files are generated with the binaries built on local and should ensure that correct versions of `bandd`, `elysd`, `hermes`, `price-feeder`, `rly` daemons are put on `build` directory.

# Starting dockernet
### Version table

```
hermes 1.4.0+daad028
rly v2.3.0
price-feeder `4a977ab` (`feature/binance_price_feeder_working` branch)
bandd `79456dc` (`v2_4_1_customization` branch)
```

# Starting dockernet

```sh
make start-docker

# Logs
canceled
canceled
canceled
docker-compose -f ./dockernet/docker-compose.yml down --remove-orphans
[+] Running 6/6
⠿ Container dockernet-relayer-band-1 Removed 10.2s
⠿ Container dockernet-elys3-1 Removed 0.3s
⠿ Container dockernet-elys1-1 Removed 0.4s
⠿ Container dockernet-elys2-1 Removed 0.3s
⠿ Container dockernet-band1-1 Removed 0.5s
⠿ Network dockernet_default Removed 0.1s
Initializing ELYS chain...
Node #1 ID: d031ff99190a741cb0db26259741e792af40d613@elys1:26656
Node #2 ID: 39bfa155ad11ef25e864ed28fb2f3f4e52dffe96@elys2:26656
Node #3 ID: 4091cebb593b7e72ca89feffca8d8bfb9d7d3ee2@elys3:26656
Initializing BAND chain...
Node #1 ID: b28a089a4c34a651f26e745155f9b195db8a6ff5@band1:26656
Starting ELYS chain
[+] Running 4/4
⠿ Network dockernet_default Created
⠿ Container dockernet-elys1-1 Started
⠿ Container dockernet-elys2-1 Started
⠿ Container dockernet-elys3-1 Started
Starting BAND chain
[+] Running 1/1
⠿ Container dockernet-band1-1 Started
Waiting for ELYS to start...Done
Waiting for BAND to start...Done
ELYS <> BAND - Adding relayer keys...Done restoring relayer keys
ELYS <> BAND - Creating client, connection, and transfer channel...Done.
[+] Running 1/1
⠿ Container dockernet-relayer-band-1 Started
```

# Checking logs from docker
Expand All @@ -29,3 +72,75 @@ make start-docker
# Interacting with dockernet

The commands on `dockernet/tests` could be executed to interact with dockernet.

# Testing dockernet environment automatically

```sh
cd dockernet/tests/
sh check.sh

# Logs
+ source ./assert.sh
++ command -v tput
++ tty -s
+++ tput setaf 1
++ RED=''
+++ tput setaf 2
++ GREEN=''
+++ tput setaf 5
++ MAGENTA=''
+++ tput sgr0
++ NORMAL=''
+++ tput bold
++ BOLD=''
++ elysd query oracle show-price BTC --source=band
+ band_price='price:
asset: BTC
price: "0.000000000000490441"
provider: automation
source: band
timestamp: "1683195717"'
+ assert_contain 'price:
asset: BTC
price: "0.000000000000490441"
provider: automation
source: band
timestamp: "1683195717"' 'asset: BTC' 'band price check failure'
+ local 'haystack=price:
asset: BTC
price: "0.000000000000490441"
provider: automation
source: band
timestamp: "1683195717"'
+ local 'needle=asset: BTC'
+ local 'msg=band price check failure'
+ '[' -z x ']'
+ '[' -z '' ']'
+ return 0
++ elysd query oracle show-price BTC --source=binance
+ elys_price='price:
asset: BTC
price: "29159.631493739183154355"
provider: elys1mxk8wmns33vs6yynsaeud2k97xkl5dqlkjv3j9
source: binance
timestamp: "1683195535"'
+ assert_contain 'price:
asset: BTC
price: "29159.631493739183154355"
provider: elys1mxk8wmns33vs6yynsaeud2k97xkl5dqlkjv3j9
source: binance
timestamp: "1683195535"' 'asset: BTC' 'elys price check failure'
+ local 'haystack=price:
asset: BTC
price: "29159.631493739183154355"
provider: elys1mxk8wmns33vs6yynsaeud2k97xkl5dqlkjv3j9
source: binance
timestamp: "1683195535"'
+ local 'needle=asset: BTC'
+ local 'msg=elys price check failure'
+ '[' -z x ']'
+ '[' -z '' ']'
+ return 0
+ echo 'All passed'
All passed
```
248 changes: 248 additions & 0 deletions dockernet/tests/assert.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,248 @@
#!/usr/bin/env bash

#####################################################################
##
## title: Assert Extension
##
## description:
## Assert extension of shell (bash, ...)
## with the common assert functions
## Function list based on:
## http://junit.sourceforge.net/javadoc/org/junit/Assert.html
## Log methods : inspired by
## - https://natelandau.com/bash-scripting-utilities/
## author: Mark Torok
##
## date: 07. Dec. 2016
##
## license: MIT
##
#####################################################################

if command -v tput &>/dev/null && tty -s; then
RED=$(tput setaf 1)
GREEN=$(tput setaf 2)
MAGENTA=$(tput setaf 5)
NORMAL=$(tput sgr0)
BOLD=$(tput bold)
else
RED=$(echo -en "\e[31m")
GREEN=$(echo -en "\e[32m")
MAGENTA=$(echo -en "\e[35m")
NORMAL=$(echo -en "\e[00m")
BOLD=$(echo -en "\e[01m")
fi

log_header() {
printf "\n${BOLD}${MAGENTA}========== %s ==========${NORMAL}\n" "$@" >&2
}

log_success() {
printf "${GREEN}✔ %s${NORMAL}\n" "$@" >&2
}

log_failure() {
printf "${RED}✖ %s${NORMAL}\n" "$@" >&2
}


assert_eq() {
local expected="$1"
local actual="$2"
local msg="${3-}"

if [ "$expected" == "$actual" ]; then
return 0
else
[ "${#msg}" -gt 0 ] && log_failure "$expected == $actual :: $msg" || true
return 1
fi
}

assert_not_eq() {
local expected="$1"
local actual="$2"
local msg="${3-}"

if [ ! "$expected" == "$actual" ]; then
return 0
else
[ "${#msg}" -gt 0 ] && log_failure "$expected != $actual :: $msg" || true
return 1
fi
}

assert_true() {
local actual="$1"
local msg="${2-}"

assert_eq true "$actual" "$msg"
return "$?"
}

assert_false() {
local actual="$1"
local msg="${2-}"

assert_eq false "$actual" "$msg"
return "$?"
}

assert_array_eq() {

declare -a expected=("${!1-}")
# echo "AAE ${expected[@]}"

declare -a actual=("${!2}")
# echo "AAE ${actual[@]}"

local msg="${3-}"

local return_code=0
if [ ! "${#expected[@]}" == "${#actual[@]}" ]; then
return_code=1
fi

local i
for (( i=1; i < ${#expected[@]} + 1; i+=1 )); do
if [ ! "${expected[$i-1]}" == "${actual[$i-1]}" ]; then
return_code=1
break
fi
done

if [ "$return_code" == 1 ]; then
[ "${#msg}" -gt 0 ] && log_failure "(${expected[*]}) != (${actual[*]}) :: $msg" || true
fi

return "$return_code"
}

assert_array_not_eq() {

declare -a expected=("${!1-}")
declare -a actual=("${!2}")

local msg="${3-}"

local return_code=1
if [ ! "${#expected[@]}" == "${#actual[@]}" ]; then
return_code=0
fi

local i
for (( i=1; i < ${#expected[@]} + 1; i+=1 )); do
if [ ! "${expected[$i-1]}" == "${actual[$i-1]}" ]; then
return_code=0
break
fi
done

if [ "$return_code" == 1 ]; then
[ "${#msg}" -gt 0 ] && log_failure "(${expected[*]}) == (${actual[*]}) :: $msg" || true
fi

return "$return_code"
}

assert_empty() {
local actual=$1
local msg="${2-}"

assert_eq "" "$actual" "$msg"
return "$?"
}

assert_not_empty() {
local actual=$1
local msg="${2-}"

assert_not_eq "" "$actual" "$msg"
return "$?"
}

assert_contain() {
local haystack="$1"
local needle="${2-}"
local msg="${3-}"

if [ -z "${needle:+x}" ]; then
return 0;
fi

if [ -z "${haystack##*$needle*}" ]; then
return 0
else
[ "${#msg}" -gt 0 ] && log_failure "$haystack doesn't contain $needle :: $msg" || true
return 1
fi
}

assert_not_contain() {
local haystack="$1"
local needle="${2-}"
local msg="${3-}"

if [ -z "${needle:+x}" ]; then
return 0;
fi

if [ "${haystack##*$needle*}" ]; then
return 0
else
[ "${#msg}" -gt 0 ] && log_failure "$haystack contains $needle :: $msg" || true
return 1
fi
}

assert_gt() {
local first="$1"
local second="$2"
local msg="${3-}"

if [[ "$first" -gt "$second" ]]; then
return 0
else
[ "${#msg}" -gt 0 ] && log_failure "$first > $second :: $msg" || true
return 1
fi
}

assert_ge() {
local first="$1"
local second="$2"
local msg="${3-}"

if [[ "$first" -ge "$second" ]]; then
return 0
else
[ "${#msg}" -gt 0 ] && log_failure "$first >= $second :: $msg" || true
return 1
fi
}

assert_lt() {
local first="$1"
local second="$2"
local msg="${3-}"

if [[ "$first" -lt "$second" ]]; then
return 0
else
[ "${#msg}" -gt 0 ] && log_failure "$first < $second :: $msg" || true
return 1
fi
}

assert_le() {
local first="$1"
local second="$2"
local msg="${3-}"

if [[ "$first" -le "$second" ]]; then
return 0
else
[ "${#msg}" -gt 0 ] && log_failure "$first <= $second :: $msg" || true
return 1
fi
}
Loading