Skip to content

Commit

Permalink
Problem: no integration tests for ibc bridge with main chain (wip cry…
Browse files Browse the repository at this point in the history
…pto-org-chain#2)

Update integration_tests/network.py

thanks~

Co-authored-by: yihuang <huang@crypto.com>

use binary directly

runing together

enable ibc

tidy up

tidy up

hermes working

run cronos, chainmain

hermes working

hermes working

ibc working

ibc test working

tidy up

genesis tested

Problem: no integration tests for ibc bridge with main chain (wip crypto-org-chain#2)

Update integration_tests/network.py

thanks~

Co-authored-by: yihuang <huang@crypto.com>

use binary directly

runing together

enable ibc

tidy up

tidy up

hermes working

run cronos, chainmain

hermes working

hermes working

ibc working

ibc test working

tidy up

metamask working

evm works

tidy up

fix rebase

use hermes 0.7.1

Update integration_tests/network.py

thanks

Co-authored-by: yihuang <huang@crypto.com>

change chainmain version to current

use chain-main v2.1.2

update hermes to 0.7.3

remove ibc setup in genesis
  • Loading branch information
leejw51crypto committed Oct 10, 2021
1 parent 39849e4 commit 00bccb8
Show file tree
Hide file tree
Showing 14 changed files with 424 additions and 3 deletions.
2 changes: 1 addition & 1 deletion integration_tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from .network import setup_cronos, setup_geth
from .network import setup_cronos2, setup_cronos, setup_geth, setup_chainmain, setup_hermes


def pytest_configure(config):
Expand Down
90 changes: 89 additions & 1 deletion integration_tests/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
import os
import signal
import subprocess

import tomlkit
import time
import web3
from pystarport import ports
from web3.middleware import geth_poa_middleware
Expand Down Expand Up @@ -35,13 +36,67 @@ def node_rpc(self, i):
def cosmos_cli(self, i=0):
return CosmosCLI(self.base_dir / f"node{i}", self.node_rpc(i), "cronosd")

class Chainmain:
def __init__(self, base_dir):
self.base_dir = base_dir
self.config = json.load(open(base_dir / "config.json"))

def base_port(self, i):
return self.config["validators"][i]["base_port"]

def node_rpc(self, i):
return "tcp://127.0.0.1:%d" % ports.rpc_port(self.base_port(i))

def cosmos_cli(self, i=0):
return CosmosCLI(self.base_dir / f"node{i}", self.node_rpc(i), "chain-maind")


class Hermes:
def __init__(self, base_dir):
self.base_dir = base_dir
print(f'hermes init base_dir {base_dir}')
configpath= base_dir / "config.toml"
with open(configpath) as f:
a=f.read()
b=tomlkit.loads(a)
self.config = b
self.configpath = configpath
print(f'hermes config path={self.configpath}')
print(json.dumps(self.config, indent=4))


def base_port(self, i):
return self.config["validators"][i]["base_port"]

def node_rpc(self, i):
return "tcp://127.0.0.1:%d" % ports.rpc_port(self.base_port(i))

def cosmos_cli(self, i=0):
return CosmosCLI(self.base_dir / f"node{i}", self.node_rpc(i), "cronosd")


class Geth:
def __init__(self, w3):
self.w3 = w3


def setup_cronos2(path, base_port):
cmd = ["start-cronos", path, "--base_port", str(base_port)]
print(*cmd)
proc = subprocess.Popen(
cmd,
preexec_fn=os.setsid,
)
try:
wait_for_port(ports.evmrpc_port(base_port))
yield Cronos(path / "cronos_777-1")
finally:
os.killpg(os.getpgid(proc.pid), signal.SIGTERM)
# proc.terminate()
proc.wait()

def setup_cronos(path, base_port):
print(f"setup cronos path= {path}")
cmd = ["start-cronos", path, "--base_port", str(base_port)]
print(*cmd)
proc = subprocess.Popen(
Expand All @@ -57,6 +112,39 @@ def setup_cronos(path, base_port):
proc.wait()


def setup_chainmain(path, base_port):
print(f"setup chainmain path= {path}")
cmd = ["start-chainmain", path, "--base_port", str(base_port)]
print(*cmd)
proc = subprocess.Popen(
cmd,
preexec_fn=os.setsid,
)
try:
wait_for_port(base_port)
yield Chainmain(path / "chainmain-1")
finally:
os.killpg(os.getpgid(proc.pid), signal.SIGTERM)
# proc.terminate()
proc.wait()

def setup_hermes(path, base_port):
print(f"setup hermes path= {path}")
cmd = ["start-hermes", path, "--base_port", str(base_port)]
print(*cmd)
proc = subprocess.Popen(
cmd,
preexec_fn=os.setsid,
)
try:
#wait_for_port(base_port)
time.sleep(4)
yield Hermes(path)
finally:
os.killpg(os.getpgid(proc.pid), signal.SIGTERM)
# proc.terminate()
proc.wait()

def setup_geth(path, base_port):
with (path / "geth.log").open("w") as logfile:
cmd = [
Expand Down
3 changes: 3 additions & 0 deletions integration_tests/shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,8 @@ pkgs.mkShell {
pkgs.solc-static-versions.solc_0_6_11
pkgs.test-env
pkgs.nixpkgs-fmt
(import ../nix/testenv.nix { inherit pkgs; })
(import ../nix/chainmain.nix { inherit pkgs; })
(import ../nix/hermes.nix { inherit pkgs; })
];
}
56 changes: 56 additions & 0 deletions integration_tests/test_ibc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import pytest
import time
import os
import json
from .conftest import setup_cronos2, setup_chainmain, setup_hermes
from web3 import Web3
import json
import sys


@pytest.fixture(scope="module")
def cronos(tmp_path_factory):
print(f'cronos tmp folder= {tmp_path_factory}')
yield from setup_cronos2(tmp_path_factory.mktemp("cronos"), 26700)


@pytest.fixture(scope="module")
def chainmain(tmp_path_factory):
print(f'chainmain tmp folder= {tmp_path_factory}')
# "start-cronos"
yield from setup_chainmain(tmp_path_factory.mktemp("chainmain"), 26800)


@pytest.fixture(scope="module")
def hermes(tmp_path_factory):
print("hermes waiting for chains booting up")
time.sleep(20)
print(f'hermes tmp folder= {tmp_path_factory}')
yield from setup_hermes(tmp_path_factory.mktemp("hermes"), 26900)


def getBalance(chain, addr, denom):
output = chain.cosmos_cli(0).raw(
"query",
"bank",
"balances",
addr,
node=chain.node_rpc(0),
output="json",
)
c = json.loads(output.decode())
d = json.dumps(c, indent=4)
print(d)
coins = c["balances"]
for coin in coins:
if coin["denom"] == denom:
value = int(coin["amount"])
return value
return 0


def test_ibc(cronos, chainmain):
print("test ibc")
time.sleep(2000000000)
assert True
pass
8 changes: 8 additions & 0 deletions nix/chainmain.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{pkgs ? import ./default.nix {} }:
let
released = (import (builtins.fetchTarball "https://github.com/crypto-org-chain/chain-main/archive/v2.1.2.tar.gz") { }).chain-maind;
in
pkgs.symlinkJoin {
name = "chainmain";
paths = [ released ];
}
3 changes: 3 additions & 0 deletions nix/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ import sources.nixpkgs {
import ./scripts.nix {
inherit pkgs;
config = {
chainmain-config = ../scripts/chainmain-devnet.yaml;
cronos-config = ../scripts/cronos-devnet.yaml;
cronos2-config = ../scripts/cronos2-devnet.yaml;
hermes-config = ../scripts/hermes.toml;
geth-genesis = ../scripts/geth-genesis.json;
};
}
Expand Down
20 changes: 20 additions & 0 deletions nix/hermes.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{pkgs ? import ./default.nix {} }:
pkgs.stdenv.mkDerivation {
name="hermes";
version="v0.7.3";
src= pkgs.fetchurl {
url="https://github.com/informalsystems/ibc-rs/releases/download/v0.7.3/hermes-v0.7.3-x86_64-unknown-linux-gnu.tar.gz";
sha256 = "sha256:17k9017y41zbjqywrgni0i7s1qn6v0pjc5af7xqaqa9qcsi3l9jr";
};
sourceRoot = ".";
installPhase = ''
echo "hermes"
echo $out
install -m755 -D hermes $out/bin/hermes
'';

meta = with pkgs.lib; {
platforms = platforms.linux;
};

}
18 changes: 17 additions & 1 deletion nix/scripts.nix
Original file line number Diff line number Diff line change
@@ -1,18 +1,34 @@
{ pkgs
, config
, cronos ? (import ../. { inherit pkgs; })
, chainmain ? (import ../nix/chainmain.nix { inherit pkgs; })
, hermes ? (import ../nix/hermes.nix { inherit pkgs; })

}:
rec {
start-chainmain = pkgs.writeShellScriptBin "start-chainmain" ''
export PATH=${pkgs.pystarport}/bin:${chainmain}/bin:$PATH
${../scripts/start-chainmain} ${config.chainmain-config} $@
'';
start-cronos = pkgs.writeShellScriptBin "start-cronos" ''
# rely on environment to provide cronosd
export PATH=${pkgs.pystarport}/bin:$PATH
${../scripts/start-cronos} ${config.cronos-config} $@
'';
start-cronos2 = pkgs.writeShellScriptBin "start-cronos" ''
export PATH=${pkgs.pystarport}/bin:${cronos}/bin:$PATH
${../scripts/start-cronos} ${config.cronos2-config} $@
'';
start-geth = pkgs.writeShellScriptBin "start-geth" ''
export PATH=${pkgs.go-ethereum}/bin:$PATH
${../scripts/start-geth} ${config.geth-genesis} $@
'';
start-hermes = pkgs.writeShellScriptBin "start-hermes" ''
export PATH=${hermes}/bin:$PATH
${../scripts/start-hermes} ${config.hermes-config} $@
'';
start-scripts = pkgs.symlinkJoin {
name = "start-scripts";
paths = [ start-cronos start-geth ];
paths = [ start-cronos2 start-cronos start-geth start-chainmain start-hermes];
};
}
55 changes: 55 additions & 0 deletions scripts/chainmain-devnet.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
chainmain-1:
cmd: chain-maind
start-flags: "--trace"
validators:
- coins: 2234240000000000000cro
staked: 10000000000000cro
mnemonic: visit craft resemble online window solution west chuckle music diesel vital settle comic tribe project blame bulb armed flower region sausage mercy arrive release
- coins: 987870000000000000cro
staked: 20000000000000cro
mnemonic: direct travel shrug hand twice agent sail sell jump phone velvet pilot mango charge usual multiply orient garment bleak virtual action mention panda vast
# min_self_delegation: 10000000 # 0.1cro
accounts:
- name: community
coins: 10000000000000cro
mnemonic: notable error gospel wave pair ugly measure elite toddler cost various fly make eye ketchup despair slab throw tribe swarm word fruit into inmate
- name: signer1
coins: 10000000000000cro
mnemonic: shed crumble dismiss loyal latin million oblige gesture shrug still oxygen custom remove ribbon disorder palace addict again blanket sad flock consider obey popular
- name: signer2
coins: 20000000000000cro
mnemonic: night renew tonight dinner shaft scheme domain oppose echo summer broccoli agent face guitar surface belt veteran siren poem alcohol menu custom crunch index
genesis:
app_state:
staking:
params:
unbonding_time: "1814400s"
gov:
voting_params:
voting_period: "1814400s"
deposit_params:
max_deposit_period: "1814400s"
min_deposit:
- denom: "basecro"
amount: "10000000"
transfer:
params:
receive_enabled: true
send_enabled: true
capability:
index: '3'
owners:
- index: '1'
index_owners:
owners:
- module: ibc
name: ports/transfer
- module: transfer
name: ports/transfer
- index: '2'
index_owners:
owners:
- module: ibc
name: capabilities/ports/transfer/channels/channel-0
- module: transfer
name: capabilities/ports/transfer/channels/channel-0
7 changes: 7 additions & 0 deletions scripts/cronos-devnet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ cronos_777-1:
- name: community
coins: 10000000000000000000000basetcro
mnemonic: "notable error gospel wave pair ugly measure elite toddler cost various fly make eye ketchup despair slab throw tribe swarm word fruit into inmate"
- name: signer1
coins: 20000000000000000000000basetcro
mnemonic: shed crumble dismiss loyal latin million oblige gesture shrug still oxygen custom remove ribbon disorder palace addict again blanket sad flock consider obey popular
- name: signer2
coins: 30000000000000000000000basetcro
mnemonic: night renew tonight dinner shaft scheme domain oppose echo summer broccoli agent face guitar surface belt veteran siren poem alcohol menu custom crunch index

genesis:
app_state:
evm:
Expand Down
Loading

0 comments on commit 00bccb8

Please sign in to comment.