Skip to content

Commit

Permalink
Problem: there are duplicated hard coded informations in integration …
Browse files Browse the repository at this point in the history
…tests (#233)

* Add .env

* Load dotenv and expand it in all related files

1. Scritps
2. yaml
3. Python files

* Update to read full path of config files

* Test: Replace with test pystarport at first

After crypto-com/pystarport#37, would change
back to crypto-com/pystarport.

* Test expansion

Test the expansion feature

* Update the test pystarport

* Update test pystarport

* Update test_expansion

* Move the test_expansion to pystarport

* Back to crypto-com/pystarport@main

and remove deepdiff dependency.

* Use Path to get path

It is more general and work with full path as well

* Use full path of .env

* Use pystarport v0.2.3

* Override dotenv in start-cronos/start-chainmain

This makes these two script-bins defined in `scripts.nix` always use the
same yaml and dotenv file, for metting the "re-producibility"
requirement during one/same `nix-shell` environment.

These script-bins are wrappers of pystarport with fixed yaml and dotenv.

If you want to create the cronos/chainmain instance with different
configurations, you should avoid using the script-bins. Please run the
scripts directly, or use `pystarport` step by step.

Besides, if you change the yaml or dotenv, you need to exit and
re-enter the nix-shell. So that the modified yaml or dotenv are copied
to nix store, and their paths can be rewritten into these two
script-bins.
  • Loading branch information
damoncro authored Dec 6, 2021
1 parent c3a4283 commit af16f2a
Show file tree
Hide file tree
Showing 17 changed files with 123 additions and 75 deletions.
7 changes: 4 additions & 3 deletions integration_tests/configs/disable_auto_deployment.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
dotenv: ../../scripts/.env
cronos_777-1:
cmd: cronosd
start-flags: "--trace --unsafe-experimental"
Expand All @@ -8,14 +9,14 @@ cronos_777-1:
validators:
- coins: 1000000000000000000stake,10000000000000000000000basetcro
staked: 1000000000000000000stake
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
mnemonic: ${VALIDATOR1_MNEMONIC}
- coins: 1000000000000000000stake,10000000000000000000000basetcro
staked: 1000000000000000000stake
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
mnemonic: ${VALIDATOR2_MNEMONIC}
accounts:
- 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"
mnemonic: ${COMMUNITY_MNEMONIC}
genesis:
app_state:
evm:
Expand Down
7 changes: 4 additions & 3 deletions integration_tests/configs/genesis_token_mapping.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
dotenv: ../../scripts/.env
cronos_777-1:
cmd: cronosd
start-flags: "--trace --unsafe-experimental"
Expand All @@ -8,14 +9,14 @@ cronos_777-1:
validators:
- coins: 1000000000000000000stake,10000000000000000000000basetcro
staked: 1000000000000000000stake
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
mnemonic: ${VALIDATOR1_MNEMONIC}
- coins: 1000000000000000000stake,10000000000000000000000basetcro
staked: 1000000000000000000stake
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
mnemonic: ${VALIDATOR2_MNEMONIC}
accounts:
- 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"
mnemonic: ${COMMUNITY_MNEMONIC}
genesis:
app_state:
cronos:
Expand Down
61 changes: 36 additions & 25 deletions integration_tests/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion integration_tests/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ protobuf = "^3.13.0"
grpcio = "^1.33.2"
PyYAML = "^5.3.1"
python-dateutil = "^2.8.1"
pystarport = { git = "https://github.com/crypto-com/pystarport.git", branch = "main" }
web3 = "^5.20.1"
eth-bloom = "^1.0.4"
python-dotenv = "^0.19.2"
pystarport = "^0.2.3"

[tool.poetry.dev-dependencies]

Expand Down
9 changes: 3 additions & 6 deletions integration_tests/test_ibc.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
from pathlib import Path

import pytest
from eth_account import Account

from .network import setup_chainmain, setup_cronos, setup_hermes
from .utils import wait_for_port
from .utils import KEYS, wait_for_port


@pytest.fixture(scope="module")
Expand Down Expand Up @@ -105,12 +106,8 @@ def test_ibc_reverse(cronos, chainmain, hermes):
def test_contract(cronos, chainmain, hermes):
cronos_chainid = 777
cronos_gas = 10000000
cronos_mnemonics = "night renew tonight dinner shaft scheme \
domain oppose echo summer broccoli agent face guitar surface \
belt veteran siren poem alcohol menu custom crunch index"
web3api = cronos.w3
web3api.eth.account.enable_unaudited_hdwallet_features()
account = web3api.eth.account.from_mnemonic(cronos_mnemonics)
account = Account.from_key(KEYS["validator"])
contract_creator_address = account.address
web3api.eth.get_balance(contract_creator_address)

Expand Down
6 changes: 4 additions & 2 deletions integration_tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,17 @@
import toml
import yaml
from dateutil.parser import isoparse
from dotenv import load_dotenv
from eth_account import Account
from hexbytes import HexBytes
from pystarport import cluster, ledger
from pystarport.ports import rpc_port
from web3._utils.transactions import fill_nonce, fill_transaction_defaults

load_dotenv(Path(__file__).parent.parent / "scripts/.env")
KEYS = {
"validator": "826E479F5385C8C32CD96B0C0ACCDB8CC4FA5CACCC1BE54C1E3AA4D676A6EFF5",
"community": "5D665FBD2FB40CB8E9849263B04457BA46D5F948972D0FE4C1F19B6B0F243574",
"validator": os.getenv("VALIDATOR_KEY"),
"community": os.getenv("COMMUNITY_KEY"),
}
ADDRS = {name: Account.from_key(key).address for name, key in KEYS.items()}
CRONOS_ADDRESS_PREFIX = "crc"
Expand Down
1 change: 1 addition & 0 deletions nix/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import sources.nixpkgs {
cronos-config = ../scripts/cronos-devnet.yaml;
hermes-config = ../scripts/hermes.toml;
geth-genesis = ../scripts/geth-genesis.json;
dotenv = builtins.path { name = "dotenv"; path = ../scripts/.env; };
};
})
(_: pkgs: {
Expand Down
6 changes: 4 additions & 2 deletions nix/scripts.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,21 @@
}: rec {
start-chainmain = pkgs.writeShellScriptBin "start-chainmain" ''
export PATH=${pkgs.pystarport}/bin:${chainmain}/bin:$PATH
${../scripts/start-chainmain} ${config.chainmain-config} $@
${../scripts/start-chainmain} ${config.chainmain-config} ${config.dotenv} $@
'';
start-cronos = pkgs.writeShellScriptBin "start-cronos" ''
# rely on environment to provide cronosd
export PATH=${pkgs.pystarport}/bin:$PATH
${../scripts/start-cronos} ${config.cronos-config} $@
${../scripts/start-cronos} ${config.cronos-config} ${config.dotenv} $@
'';
start-geth = pkgs.writeShellScriptBin "start-geth" ''
export PATH=${pkgs.go-ethereum}/bin:$PATH
source ${config.dotenv}
${../scripts/start-geth} ${config.geth-genesis} $@
'';
start-hermes = pkgs.writeShellScriptBin "start-hermes" ''
export PATH=${hermes}/bin:$PATH
source ${config.dotenv}
${../scripts/start-hermes} ${config.hermes-config} $@
'';
start-scripts = pkgs.symlinkJoin {
Expand Down
9 changes: 5 additions & 4 deletions nix/sources.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,11 @@
"homepage": null,
"owner": "crypto-com",
"repo": "pystarport",
"rev": "a127111b2c23ce167155f7c4f6751e6af894306b",
"sha256": "0y4a7v81p4m1fz374b48vzn0jm8j3z287s7gn64w2x53px58c5r4",
"rev": "e08c02d64b19140e1473dfe47cdc759001eff505",
"sha256": "1h39ckb56br1cgznbr8xw054pg6vixdxhz2vbr4ypgvwh372sd4h",
"type": "tarball",
"url": "https://github.com/crypto-com/pystarport/archive/a127111b2c23ce167155f7c4f6751e6af894306b.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
"url": "https://github.com/crypto-com/pystarport/archive/refs/tags/v0.2.3.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz",
"version": "v0.2.3"
}
}
10 changes: 10 additions & 0 deletions scripts/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export VALIDATOR_KEY='826E479F5385C8C32CD96B0C0ACCDB8CC4FA5CACCC1BE54C1E3AA4D676A6EFF5'
export COMMUNITY_KEY='5D665FBD2FB40CB8E9849263B04457BA46D5F948972D0FE4C1F19B6B0F243574'
export PASSWORD='123456'
export VALIDATOR1_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"
export VALIDATOR2_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"
export COMMUNITY_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"
export SIGNER1_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"
export SIGNER2_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"
export CRONOS_ADMIN="crc12luku6uxehhak02py4rcz65zu0swh7wjsrw0pp"
export IBC_CRO_DENOM="ibc/6411AE2ADA1E73DB59DB151A8988F9B7D5E7E233D8414DB6817F8F1A01611F86"
13 changes: 7 additions & 6 deletions scripts/chainmain-devnet.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
dotenv: .env
chainmain-1:
cmd: chain-maind
start-flags: "--trace"
Expand All @@ -6,21 +7,21 @@ chainmain-1:
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
mnemonic: ${VALIDATOR1_MNEMONIC}
- 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
mnemonic: ${VALIDATOR2_MNEMONIC}
# 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
mnemonic: ${COMMUNITY_MNEMONIC}
- 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
mnemonic: ${SIGNER1_MNEMONIC}
- name: signer2
coins: 10000000000000cro
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
mnemonic: ${SIGNER2_MNEMONIC}
genesis:
app_state:
staking:
Expand All @@ -37,4 +38,4 @@ chainmain-1:
transfer:
params:
receive_enabled: true
send_enabled: true
send_enabled: true
17 changes: 9 additions & 8 deletions scripts/cronos-devnet.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
dotenv: .env
cronos_777-1:
cmd: cronosd
start-flags: "--trace"
Expand All @@ -9,21 +10,21 @@ cronos_777-1:
validators:
- coins: 1000000000000000000stake,10000000000000000000000basetcro
staked: 1000000000000000000stake
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
mnemonic: ${VALIDATOR1_MNEMONIC}
- coins: 1000000000000000000stake,10000000000000000000000basetcro
staked: 1000000000000000000stake
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
mnemonic: ${VALIDATOR2_MNEMONIC}
accounts:
- 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"
mnemonic: ${COMMUNITY_MNEMONIC}
- 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
mnemonic: ${SIGNER1_MNEMONIC}
- 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
mnemonic: ${SIGNER2_MNEMONIC}

genesis:
consensus_params:
block:
Expand All @@ -35,9 +36,9 @@ cronos_777-1:
evm_denom: basetcro
cronos:
params:
cronos_admin: crc12luku6uxehhak02py4rcz65zu0swh7wjsrw0pp
cronos_admin: ${CRONOS_ADMIN}
enable_auto_deployment: true
ibc_cro_denom: ibc/6411AE2ADA1E73DB59DB151A8988F9B7D5E7E233D8414DB6817F8F1A01611F86
ibc_cro_denom: ${IBC_CRO_DENOM}
gov:
voting_params:
voting_period: "10s"
Expand Down
7 changes: 4 additions & 3 deletions scripts/devnet.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
dotenv: .env
cronos_777-1:
cmd: ./build/cronosd
start-flags: "--trace --unsafe-experimental"
Expand All @@ -8,14 +9,14 @@ cronos_777-1:
validators:
- coins: 1000000000000000000stake,1000000000000000000basetcro
staked: 1000000000000000000stake
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
mnemonic: ${VALIDATOR1_MNEMONIC}
- coins: 1000000000000000000stake,1000000000000000000basetcro
staked: 1000000000000000000stake
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
mnemonic: ${VALIDATOR2_MNEMONIC}
accounts:
- 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"
mnemonic: ${COMMUNITY_MNEMONIC}
genesis:
app_state:
evm:
Expand Down
Loading

0 comments on commit af16f2a

Please sign in to comment.