From f1cfc3a33a2253f673e4d69f7880967e8eebfdbb Mon Sep 17 00:00:00 2001 From: Jongwhan Lee <51560997+leejw51crypto@users.noreply.github.com> Date: Thu, 2 Sep 2021 09:54:26 +0900 Subject: [PATCH] Problem: key import,export not working correctly (fix #26) (#27) add scripts pear makefile add my.nix working works OK works work chainmain works tidy up 1 node --- Makefile | 2 + chainmain.nix2 | 16 ++++ go.sh | 2 +- integration_tests/conftest.py | 5 +- integration_tests/network.py | 31 +++++++ integration_tests/shell.nix | 6 +- integration_tests/test_ibc.py | 158 +++------------------------------- my/apple/addkey.sh | 4 + my/apple/i1.sh | 2 + my/apple/init.sh | 61 +++++++++++++ my/apple/run.sh | 2 + my/apple/s1.sh | 2 + my/apple/s2.sh | 2 + my/apple/send.sh | 8 ++ my/apple/send0.sh | 8 ++ my/apple/setup.sh | 43 +++++++++ my/pear/addkey.sh | 4 + my/pear/init.sh | 61 +++++++++++++ my/pear/run.sh | 2 + my/pear/s1.sh | 2 + my/pear/s2.sh | 2 + my/pear/send.sh | 8 ++ my/pear/send0.sh | 8 ++ my/pear/setup.sh | 43 +++++++++ myold.nix | 16 ++++ nix/chainmain.nix | 25 ++++++ nix/default.nix | 1 + nix/scripts.nix | 12 ++- scripts/chainmain-devnet.yaml | 38 ++++++++ scripts/start-chainmain | 23 +++++ scripts/start-cronos | 16 +--- 31 files changed, 441 insertions(+), 172 deletions(-) create mode 100644 chainmain.nix2 create mode 100755 my/apple/addkey.sh create mode 100755 my/apple/i1.sh create mode 100755 my/apple/init.sh create mode 100755 my/apple/run.sh create mode 100755 my/apple/s1.sh create mode 100755 my/apple/s2.sh create mode 100755 my/apple/send.sh create mode 100755 my/apple/send0.sh create mode 100755 my/apple/setup.sh create mode 100755 my/pear/addkey.sh create mode 100755 my/pear/init.sh create mode 100755 my/pear/run.sh create mode 100755 my/pear/s1.sh create mode 100755 my/pear/s2.sh create mode 100755 my/pear/send.sh create mode 100755 my/pear/send0.sh create mode 100755 my/pear/setup.sh create mode 100644 myold.nix create mode 100644 nix/chainmain.nix create mode 100644 scripts/chainmain-devnet.yaml create mode 100755 scripts/start-chainmain diff --git a/Makefile b/Makefile index b03389d7a6..1e1bf2d050 100644 --- a/Makefile +++ b/Makefile @@ -219,6 +219,8 @@ test-sim-profile: ### Integration Test ### ############################################################################### +get_chainmain: + git clone git@github.com:crypto-org-chain/chain-main.git ./integration_tests/chain-main run-integration-tests: @make gen-bindings-contracts @nix-shell ./integration_tests/shell.nix --run ./scripts/run-integration-tests diff --git a/chainmain.nix2 b/chainmain.nix2 new file mode 100644 index 0000000000..0cb9675d5b --- /dev/null +++ b/chainmain.nix2 @@ -0,0 +1,16 @@ +{ system ? builtins.currentSystem, pkgs ? import ./nix { inherit system; } }: +pkgs.buildGoApplication rec { + pname = "chainmain"; + version = "0.5.2"; + src = ./integration_tests/chain-main; + modules = ./integration_tests/chain-main/gomod2nix.toml; + pwd = src; # needed to support replace + subPackages = [ "./integration_tests/chain-main/cmd/chain-maind" ]; + CGO_ENABLED = "1"; + buildFlagsArray = '' + -ldflags= + -X github.com/cosmos/cosmos-sdk/version.Name=chainmain + -X github.com/cosmos/cosmos-sdk/version.AppName=${pname} + -X github.com/cosmos/cosmos-sdk/version.Version=${version} + ''; +} diff --git a/go.sh b/go.sh index b2340339fc..c58b9be7b4 100755 --- a/go.sh +++ b/go.sh @@ -1 +1 @@ -NETWORK=testnet COSMOS_BUILD_OPTIONS=rocksdb make build +nix-shell ./my.nix diff --git a/integration_tests/conftest.py b/integration_tests/conftest.py index 980d4a9627..f5ca8d60e4 100644 --- a/integration_tests/conftest.py +++ b/integration_tests/conftest.py @@ -4,10 +4,7 @@ import pytest -from .network import setup_cronos, setup_custom_cronos, setup_geth - -dir = os.path.dirname(os.path.realpath(__file__)) -sys.path.append(dir + "/protobuf") +from .network import setup_cronos, setup_geth, setup_chainmain def pytest_configure(config): diff --git a/integration_tests/network.py b/integration_tests/network.py index 893321d72f..12f2c25df3 100644 --- a/integration_tests/network.py +++ b/integration_tests/network.py @@ -88,6 +88,20 @@ def __init__(self, config: Path): self.config = tomlkit.loads(config.read_text()) self.port = 3000 +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), "cronosd") + class Geth: def __init__(self, w3): @@ -103,6 +117,23 @@ def setup_cronos(path, base_port, enable_auto_deployment=True): yield from setup_custom_cronos(path, base_port, cfg) +def setup_chainmain(path, base_port): + print(f'setup_chainmain path {path} base_port {base_port}') + 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_geth(path, base_port): with (path / "geth.log").open("w") as logfile: cmd = [ diff --git a/integration_tests/shell.nix b/integration_tests/shell.nix index 25eb185fe3..de5c871a38 100644 --- a/integration_tests/shell.nix +++ b/integration_tests/shell.nix @@ -20,10 +20,8 @@ pkgs.mkShell { (renameExe pkgs.solc-static-versions.solc_0_8_21 "solc-0.8.21" "solc08") pkgs.test-env pkgs.nixpkgs-fmt - pkgs.rocksdb - pkgs.chain-maind - pkgs.hermes - pkgs.rly + (import ../nix/testenv.nix { inherit pkgs; }) + (import ../nix/chainmain.nix { inherit pkgs; }) ]; shellHook = '' mkdir ./coverage diff --git a/integration_tests/test_ibc.py b/integration_tests/test_ibc.py index bd22947c39..1082c98e62 100644 --- a/integration_tests/test_ibc.py +++ b/integration_tests/test_ibc.py @@ -1,154 +1,18 @@ -import pytest - -from .ibc_utils import ( - RATIO, - assert_ready, - cronos_transfer_source_tokens, - cronos_transfer_source_tokens_with_proxy, - get_balance, - ibc_incentivized_transfer, - ibc_transfer_with_hermes, - prepare_network, -) -from .utils import ADDRS, CONTRACTS, deploy_contract, send_transaction, wait_for_fn - - -@pytest.fixture(scope="module", params=[True, False]) -def ibc(request, tmp_path_factory): - "prepare-network" - incentivized = request.param - name = "ibc" - path = tmp_path_factory.mktemp(name) - network = prepare_network(path, name, incentivized=incentivized) - yield from network - - -def test_ibc_transfer_with_hermes(ibc): - """ - test ibc transfer tokens with hermes cli - """ - ibc_transfer_with_hermes(ibc) - - -def test_ibc_incentivized_transfer(ibc): - if not ibc.incentivized: - # this test case only works for incentivized channel. - return - ibc_incentivized_transfer(ibc) - - -def test_cronos_transfer_tokens(ibc): - """ - test sending basetcro from cronos to crypto-org-chain using cli transfer_tokens. - depends on `test_ibc` to send the original coins. - """ - assert_ready(ibc) - dst_addr = ibc.chainmain.cosmos_cli().address("signer2") - dst_amount = 2 - dst_denom = "basecro" - cli = ibc.cronos.cosmos_cli() - src_amount = dst_amount * RATIO # the decimal places difference - src_addr = cli.address("signer2") - src_denom = "basetcro" - - # case 1: use cronos cli - old_src_balance = get_balance(ibc.cronos, src_addr, src_denom) - old_dst_balance = get_balance(ibc.chainmain, dst_addr, dst_denom) - rsp = cli.transfer_tokens( - src_addr, - dst_addr, - f"{src_amount}{src_denom}", - ) - assert rsp["code"] == 0, rsp["raw_log"] - - new_dst_balance = 0 - def check_balance_change(): - nonlocal new_dst_balance - new_dst_balance = get_balance(ibc.chainmain, dst_addr, dst_denom) - return old_dst_balance != new_dst_balance - wait_for_fn("balance change", check_balance_change) - assert old_dst_balance + dst_amount == new_dst_balance - new_src_balance = get_balance(ibc.cronos, src_addr, src_denom) - assert old_src_balance - src_amount == new_src_balance +import pytest +from .conftest import setup_cronos, setup_chainmain -def test_cronos_transfer_tokens_acknowledgement_error(ibc): - """ - test sending basetcro from cronos to crypto-org-chain using cli transfer_tokens - with invalid receiver for acknowledgement error. - depends on `test_ibc` to send the original coins. - """ - assert_ready(ibc) - dst_addr = "invalid_address" - dst_amount = 2 - cli = ibc.cronos.cosmos_cli() - src_amount = dst_amount * RATIO # the decimal places difference - src_addr = cli.address("signer2") - src_denom = "basetcro" - - old_src_balance = get_balance(ibc.cronos, src_addr, src_denom) - rsp = cli.transfer_tokens( - src_addr, - dst_addr, - f"{src_amount}{src_denom}", - ) - assert rsp["code"] == 0, rsp["raw_log"] - - new_src_balance = 0 - - def check_balance_change(): - nonlocal new_src_balance - new_src_balance = get_balance(ibc.cronos, src_addr, src_denom) - return old_src_balance == new_src_balance - - wait_for_fn("balance no change", check_balance_change) - new_src_balance = get_balance(ibc.cronos, src_addr, src_denom) - - -def test_cro_bridge_contract(ibc): - """ - test sending basetcro from cronos to crypto-org-chain using CroBridge contract. - depends on `test_ibc` to send the original coins. - """ - dst_addr = ibc.chainmain.cosmos_cli().address("signer2") - dst_amount = 2 - dst_denom = "basecro" - src_amount = dst_amount * RATIO # the decimal places difference - old_dst_balance = get_balance(ibc.chainmain, dst_addr, dst_denom) - - # case 2: use CroBridge contract - w3 = ibc.cronos.w3 - contract = deploy_contract(w3, CONTRACTS["CroBridge"]) - tx = contract.functions.send_cro_to_crypto_org(dst_addr).build_transaction( - {"from": ADDRS["signer2"], "value": src_amount} - ) - receipt = send_transaction(w3, tx) - assert receipt.status == 1 - - new_dst_balance = 0 - - def check_balance_change(): - nonlocal new_dst_balance - new_dst_balance = get_balance(ibc.chainmain, dst_addr, dst_denom) - return old_dst_balance != new_dst_balance - - wait_for_fn("check balance change", check_balance_change) - assert old_dst_balance + dst_amount == new_dst_balance - +@pytest.fixture(scope="module") +def cronos(tmp_path_factory): + print("########################################") + print(f'tmp folder= {tmp_path_factory}') + # "start-cronos" + yield from setup_chainmain(tmp_path_factory.mktemp("chainmain"), 26700) -def test_cronos_transfer_source_tokens(ibc): - """ - test sending crc20 tokens originated from cronos to crypto-org-chain - """ - assert_ready(ibc) - cronos_transfer_source_tokens(ibc) -def test_cronos_transfer_source_tokens_with_proxy(ibc): - """ - test sending crc20 tokens originated from cronos to crypto-org-chain - """ - assert_ready(ibc) - cronos_transfer_source_tokens_with_proxy(ibc) +def test_ibc(cronos) : + assert True + pass diff --git a/my/apple/addkey.sh b/my/apple/addkey.sh new file mode 100755 index 0000000000..e984757466 --- /dev/null +++ b/my/apple/addkey.sh @@ -0,0 +1,4 @@ +. ./setup.sh + + + diff --git a/my/apple/i1.sh b/my/apple/i1.sh new file mode 100755 index 0000000000..d8e92ab999 --- /dev/null +++ b/my/apple/i1.sh @@ -0,0 +1,2 @@ +. ./setup.sh +$CLI query bank balances ethm1fzep9fc7hweq9a706x4vacardl0zl0z3zquzd4 --node $NODE diff --git a/my/apple/init.sh b/my/apple/init.sh new file mode 100755 index 0000000000..63cc4645eb --- /dev/null +++ b/my/apple/init.sh @@ -0,0 +1,61 @@ +. ./setup.sh + +# validate dependencies are installed +command -v jq > /dev/null 2>&1 || { echo >&2 "jq not installed. More info: https://stedolan.github.io/jq/download/"; exit 1; } + +# remove existing daemon and client +rm -rf $CHAINHOME + + +$CLI config keyring-backend $KEYRING --home $CHAINHOME +$CLI config chain-id $CHAINID --home $CHAINHOME + +# if $KEY exists it should be deleted +echo $MYMNEMONICS | $CLI keys add "$KEY" --keyring-backend $KEYRING --algo "eth_secp256k1" --recover --index 5 --home $CHAINHOME +echo $MYMNEMONICS | $CLI keys add "$KEY"1 --keyring-backend $KEYRING --algo "eth_secp256k1" --recover --index 0 --home $CHAINHOME +echo $MYMNEMONICS | $CLI keys add "$KEY"2 --keyring-backend $KEYRING --algo "eth_secp256k1" --recover --index 1 --home $CHAINHOME +echo $MYMNEMONICS | $CLI keys add "$KEY"3 --keyring-backend $KEYRING --algo "eth_secp256k1" --recover --index 2 --home $CHAINHOME + +# Set moniker and chain-id for Ethermint (Moniker can be anything, chain-id must be an integer) +$CLI init $MONIKER --chain-id $CHAINID --home $CHAINHOME + +# Change parameter token denominations to $DENOM +cat $GENESIS | jq '.app_state["staking"]["params"]["bond_denom"]="'$DENOM'"' > $TMPGENESIS && mv $TMPGENESIS $GENESIS +cat $GENESIS | jq '.app_state["crisis"]["constant_fee"]["denom"]="'$DENOM'"' > $TMPGENESIS && mv $TMPGENESIS $GENESIS +cat $GENESIS | jq '.app_state["gov"]["deposit_params"]["min_deposit"][0]["denom"]="'$DENOM'"' > $TMPGENESIS && mv $TMPGENESIS $GENESIS +cat $GENESIS | jq '.app_state["mint"]["params"]["mint_denom"]="'$DENOM'"' > $TMPGENESIS && mv $TMPGENESIS $GENESIS + +# increase block time (?) +cat $GENESIS | jq '.consensus_params["block"]["time_iota_ms"]="1000"' > $TMPGENESIS && mv $TMPGENESIS $GENESIS + +# Set gas limit in genesis +cat $GENESIS | jq '.consensus_params["block"]["max_gas"]="10000000"' > $TMPGENESIS && mv $TMPGENESIS $GENESIS + +# change port +sed -i "s/create_empty_blocks = true/create_empty_blocks = false/g" $ETHCONFIG +sed -i "s/26657/$COSMOSPORT1/g" $CLIENTCONFIG +sed -i "s/26657/$COSMOSPORT1/g" $ETHCONFIG +sed -i "s/26656/$COSMOSPORT0/g" $ETHCONFIG +sed -i "s/9090/$GRPCPORT0/g" $APPCONFIG +sed -i "s/9091/$GRPCPORT1/g" $APPCONFIG +sed -i "s/8545/$ETHPORT0/g" $APPCONFIG +sed -i "s/8546/$ETHPORT1/g" $APPCONFIG +sed -i "s/aphoton/$DENOM/g" $APPCONFIG +sed -i "s/aphoton/$DENOM/g" $GENESIS + + + +# Allocate genesis accounts (cosmos formatted addresses) +$CLI add-genesis-account $KEY $TOTALAMOUNT --keyring-backend $KEYRING --home $CHAINHOME +$CLI add-genesis-account "$KEY"1 $MYAMOUNT --keyring-backend $KEYRING --home $CHAINHOME +$CLI add-genesis-account "$KEY"2 $MYAMOUNT --keyring-backend $KEYRING --home $CHAINHOME +$CLI add-genesis-account "$KEY"3 $MYAMOUNT --keyring-backend $KEYRING --home $CHAINHOME + +$CLI gentx $KEY $MYAMOUNT --keyring-backend $KEYRING --chain-id $CHAINID --home $CHAINHOME + +$CLI collect-gentxs --home $CHAINHOME + +$CLI validate-genesis --home $CHAINHOME + + +. ./run.sh diff --git a/my/apple/run.sh b/my/apple/run.sh new file mode 100755 index 0000000000..e572200c0a --- /dev/null +++ b/my/apple/run.sh @@ -0,0 +1,2 @@ +. ./setup.sh +$CLI start --pruning=nothing $TRACE --log_level $LOGLEVEL --minimum-gas-prices=0.0001$DENOM --json-rpc.api eth,txpool,personal,net,debug,web3,miner --home $CHAINHOME diff --git a/my/apple/s1.sh b/my/apple/s1.sh new file mode 100755 index 0000000000..7705c50ba8 --- /dev/null +++ b/my/apple/s1.sh @@ -0,0 +1,2 @@ +. ./setup.sh +$CLI query bank balances $S1 --node $NODE diff --git a/my/apple/s2.sh b/my/apple/s2.sh new file mode 100755 index 0000000000..4468eb16ae --- /dev/null +++ b/my/apple/s2.sh @@ -0,0 +1,2 @@ +. ./setup.sh +$CLI query bank balances $S2 --node $NODE diff --git a/my/apple/send.sh b/my/apple/send.sh new file mode 100755 index 0000000000..528514e129 --- /dev/null +++ b/my/apple/send.sh @@ -0,0 +1,8 @@ +. ./setup.sh +export FROM=$S1 +export TO=$S2 + + +export AMOUNT=2100000000000000001$DENOM +echo "send amount $AMOUNT" +$CLI tx bank send $FROM $TO $AMOUNT --chain-id $CHAINID --keyring-backend $KEYRING --fees 20$DENOM --home $CHAINHOME diff --git a/my/apple/send0.sh b/my/apple/send0.sh new file mode 100755 index 0000000000..f2d2997e40 --- /dev/null +++ b/my/apple/send0.sh @@ -0,0 +1,8 @@ +. ./setup.sh +export FROM=$K1 +export TO=$S1 + + +export AMOUNT=1001000000000000000000$DENOM +echo "send amount $AMOUNT" +$CLI tx bank send $FROM $TO $AMOUNT --chain-id $CHAINID --keyring-backend $KEYRING --fees 20$DENOM --home $CHAINHOME diff --git a/my/apple/setup.sh b/my/apple/setup.sh new file mode 100755 index 0000000000..d6f29fd770 --- /dev/null +++ b/my/apple/setup.sh @@ -0,0 +1,43 @@ + +export KEY="mykey" +export CHAINID="applemint_9000-2" +export MONIKER="localtestnet" +export KEYRING="test" +export KEYALGO="eth_secp256k1" +export LOGLEVEL="info" +# to trace evm +export TRACE="--trace" +#export TRACE="" +export CHAINHOME=$HOME/.$CHAINID + +export ETHCONFIG=$CHAINHOME/config/config.toml +export GENESIS=$CHAINHOME/config/genesis.json +export TMPGENESIS=$CHAINHOME/config/tmp_genesis.json +export APPCONFIG=$CHAINHOME/config/app.toml +export CLIENTCONFIG=$CHAINHOME/config/client.toml +export DENOM=aapple +#echo $GENESIS +#echo $TMPGENESIS +#echo $ETHCONFIG +#echo $APPCONFIG +#echo 'DENOM='$DENOM + + +export GRPCPORT0=9090 +export GRPCPORT1=9091 +export ETHPORT0=8545 +export ETHPORT1=8546 +export COSMOSPORT0=26656 +export COSMOSPORT1=26657 +export CLI=cronosd +export NODE=tcp://127.0.0.1:26657 +$CLI keys list --keyring-backend $KEYRING --home $CHAINHOME +#echo 'HOME='$CHAINHOME + +export TOTALAMOUNT=100000000000000000000000000000000$DENOM +export MYAMOUNT=1000100000000000000001$DENOM + +export K1=$($CLI keys list --keyring-backend $KEYRING --home $CHAINHOME | yq eval -o json | jq '.[0].address' | tr -d '"') +export S1=$($CLI keys list --keyring-backend $KEYRING --home $CHAINHOME | yq eval -o json | jq '.[1].address' | tr -d '"') +export S2=$($CLI keys list --keyring-backend $KEYRING --home $CHAINHOME | yq eval -o json | jq '.[2].address' | tr -d '"') + diff --git a/my/pear/addkey.sh b/my/pear/addkey.sh new file mode 100755 index 0000000000..e984757466 --- /dev/null +++ b/my/pear/addkey.sh @@ -0,0 +1,4 @@ +. ./setup.sh + + + diff --git a/my/pear/init.sh b/my/pear/init.sh new file mode 100755 index 0000000000..63cc4645eb --- /dev/null +++ b/my/pear/init.sh @@ -0,0 +1,61 @@ +. ./setup.sh + +# validate dependencies are installed +command -v jq > /dev/null 2>&1 || { echo >&2 "jq not installed. More info: https://stedolan.github.io/jq/download/"; exit 1; } + +# remove existing daemon and client +rm -rf $CHAINHOME + + +$CLI config keyring-backend $KEYRING --home $CHAINHOME +$CLI config chain-id $CHAINID --home $CHAINHOME + +# if $KEY exists it should be deleted +echo $MYMNEMONICS | $CLI keys add "$KEY" --keyring-backend $KEYRING --algo "eth_secp256k1" --recover --index 5 --home $CHAINHOME +echo $MYMNEMONICS | $CLI keys add "$KEY"1 --keyring-backend $KEYRING --algo "eth_secp256k1" --recover --index 0 --home $CHAINHOME +echo $MYMNEMONICS | $CLI keys add "$KEY"2 --keyring-backend $KEYRING --algo "eth_secp256k1" --recover --index 1 --home $CHAINHOME +echo $MYMNEMONICS | $CLI keys add "$KEY"3 --keyring-backend $KEYRING --algo "eth_secp256k1" --recover --index 2 --home $CHAINHOME + +# Set moniker and chain-id for Ethermint (Moniker can be anything, chain-id must be an integer) +$CLI init $MONIKER --chain-id $CHAINID --home $CHAINHOME + +# Change parameter token denominations to $DENOM +cat $GENESIS | jq '.app_state["staking"]["params"]["bond_denom"]="'$DENOM'"' > $TMPGENESIS && mv $TMPGENESIS $GENESIS +cat $GENESIS | jq '.app_state["crisis"]["constant_fee"]["denom"]="'$DENOM'"' > $TMPGENESIS && mv $TMPGENESIS $GENESIS +cat $GENESIS | jq '.app_state["gov"]["deposit_params"]["min_deposit"][0]["denom"]="'$DENOM'"' > $TMPGENESIS && mv $TMPGENESIS $GENESIS +cat $GENESIS | jq '.app_state["mint"]["params"]["mint_denom"]="'$DENOM'"' > $TMPGENESIS && mv $TMPGENESIS $GENESIS + +# increase block time (?) +cat $GENESIS | jq '.consensus_params["block"]["time_iota_ms"]="1000"' > $TMPGENESIS && mv $TMPGENESIS $GENESIS + +# Set gas limit in genesis +cat $GENESIS | jq '.consensus_params["block"]["max_gas"]="10000000"' > $TMPGENESIS && mv $TMPGENESIS $GENESIS + +# change port +sed -i "s/create_empty_blocks = true/create_empty_blocks = false/g" $ETHCONFIG +sed -i "s/26657/$COSMOSPORT1/g" $CLIENTCONFIG +sed -i "s/26657/$COSMOSPORT1/g" $ETHCONFIG +sed -i "s/26656/$COSMOSPORT0/g" $ETHCONFIG +sed -i "s/9090/$GRPCPORT0/g" $APPCONFIG +sed -i "s/9091/$GRPCPORT1/g" $APPCONFIG +sed -i "s/8545/$ETHPORT0/g" $APPCONFIG +sed -i "s/8546/$ETHPORT1/g" $APPCONFIG +sed -i "s/aphoton/$DENOM/g" $APPCONFIG +sed -i "s/aphoton/$DENOM/g" $GENESIS + + + +# Allocate genesis accounts (cosmos formatted addresses) +$CLI add-genesis-account $KEY $TOTALAMOUNT --keyring-backend $KEYRING --home $CHAINHOME +$CLI add-genesis-account "$KEY"1 $MYAMOUNT --keyring-backend $KEYRING --home $CHAINHOME +$CLI add-genesis-account "$KEY"2 $MYAMOUNT --keyring-backend $KEYRING --home $CHAINHOME +$CLI add-genesis-account "$KEY"3 $MYAMOUNT --keyring-backend $KEYRING --home $CHAINHOME + +$CLI gentx $KEY $MYAMOUNT --keyring-backend $KEYRING --chain-id $CHAINID --home $CHAINHOME + +$CLI collect-gentxs --home $CHAINHOME + +$CLI validate-genesis --home $CHAINHOME + + +. ./run.sh diff --git a/my/pear/run.sh b/my/pear/run.sh new file mode 100755 index 0000000000..8e89a844a3 --- /dev/null +++ b/my/pear/run.sh @@ -0,0 +1,2 @@ +. ./setup.sh +$CLI start --pruning=nothing $TRACE --log_level $LOGLEVEL --minimum-gas-prices=0.0001$DENOM --json-rpc.api eth,txpool,personal,net,debug,web3,miner --home $CHAINHOME \ No newline at end of file diff --git a/my/pear/s1.sh b/my/pear/s1.sh new file mode 100755 index 0000000000..7705c50ba8 --- /dev/null +++ b/my/pear/s1.sh @@ -0,0 +1,2 @@ +. ./setup.sh +$CLI query bank balances $S1 --node $NODE diff --git a/my/pear/s2.sh b/my/pear/s2.sh new file mode 100755 index 0000000000..4468eb16ae --- /dev/null +++ b/my/pear/s2.sh @@ -0,0 +1,2 @@ +. ./setup.sh +$CLI query bank balances $S2 --node $NODE diff --git a/my/pear/send.sh b/my/pear/send.sh new file mode 100755 index 0000000000..528514e129 --- /dev/null +++ b/my/pear/send.sh @@ -0,0 +1,8 @@ +. ./setup.sh +export FROM=$S1 +export TO=$S2 + + +export AMOUNT=2100000000000000001$DENOM +echo "send amount $AMOUNT" +$CLI tx bank send $FROM $TO $AMOUNT --chain-id $CHAINID --keyring-backend $KEYRING --fees 20$DENOM --home $CHAINHOME diff --git a/my/pear/send0.sh b/my/pear/send0.sh new file mode 100755 index 0000000000..f2d2997e40 --- /dev/null +++ b/my/pear/send0.sh @@ -0,0 +1,8 @@ +. ./setup.sh +export FROM=$K1 +export TO=$S1 + + +export AMOUNT=1001000000000000000000$DENOM +echo "send amount $AMOUNT" +$CLI tx bank send $FROM $TO $AMOUNT --chain-id $CHAINID --keyring-backend $KEYRING --fees 20$DENOM --home $CHAINHOME diff --git a/my/pear/setup.sh b/my/pear/setup.sh new file mode 100755 index 0000000000..7c5b75e046 --- /dev/null +++ b/my/pear/setup.sh @@ -0,0 +1,43 @@ + +export KEY="mykey" +export CHAINID="pearmint_9000-6" +export MONIKER="localtestnet" +export KEYRING="test" +export KEYALGO="eth_secp256k1" +export LOGLEVEL="info" +# to trace evm +export TRACE="--trace" +#export TRACE="" +export CHAINHOME=$HOME/.$CHAINID + +export ETHCONFIG=$CHAINHOME/config/config.toml +export GENESIS=$CHAINHOME/config/genesis.json +export TMPGENESIS=$CHAINHOME/config/tmp_genesis.json +export APPCONFIG=$CHAINHOME/config/app.toml +export CLIENTCONFIG=$CHAINHOME/config/client.toml +export DENOM=apear +#echo $GENESIS +#echo $TMPGENESIS +#echo $ETHCONFIG +#echo $APPCONFIG +#echo 'DENOM='$DENOM + + +export GRPCPORT0=9080 +export GRPCPORT1=9081 +export ETHPORT0=8535 +export ETHPORT1=8536 +export COSMOSPORT0=26646 +export COSMOSPORT1=26647 +export CLI=cronosd +export NODE=tcp://127.0.0.1:26647 +$CLI keys list --keyring-backend $KEYRING --home $CHAINHOME +#echo 'HOME='$CHAINHOME + +export TOTALAMOUNT=100000000000000000000000000000000$DENOM +export MYAMOUNT=1000100000000000000001$DENOM + +export K1=$($CLI keys list --keyring-backend $KEYRING --home $CHAINHOME | yq eval -o json | jq '.[0].address' | tr -d '"') +export S1=$($CLI keys list --keyring-backend $KEYRING --home $CHAINHOME | yq eval -o json | jq '.[1].address' | tr -d '"') +export S2=$($CLI keys list --keyring-backend $KEYRING --home $CHAINHOME | yq eval -o json | jq '.[2].address' | tr -d '"') + diff --git a/myold.nix b/myold.nix new file mode 100644 index 0000000000..5fa276fdb6 --- /dev/null +++ b/myold.nix @@ -0,0 +1,16 @@ +{ system ? builtins.currentSystem, pkgs ? import ./nix { inherit system; } }: +pkgs.buildGoApplication rec { + pname = "chainmain"; + version = "0.1"; + src = ../chain-main; + subPackages = [ "../chain-main/cmd/chain-maind" ]; + CGO_ENABLED = "1"; + modules = ../chain-main/gomod2nix.toml; + buildFlagsArray = '' + -ldflags= + -X github.com/cosmos/cosmos-sdk/version.Name=cronos + -X github.com/cosmos/cosmos-sdk/version.AppName=${pname} + -X github.com/cosmos/cosmos-sdk/version.Version=${version} + ''; +} + diff --git a/nix/chainmain.nix b/nix/chainmain.nix new file mode 100644 index 0000000000..c1b678b048 --- /dev/null +++ b/nix/chainmain.nix @@ -0,0 +1,25 @@ +{ system ? builtins.currentSystem, pkgs ? import ./nix { inherit system; } }: +pkgs.buildGoModule rec { + pname = "chainmain"; + version = "0.1"; + src = pkgs.fetchFromGitHub { + owner = "crypto-org-chain"; + repo = "chain-main"; + rev = "v3.1.1"; + sha256 ="113vhzmpsnghf8ip1jj9m9i9x9lgwbyxhkr73kvqddin52fd8nsz"; + }; + + runVend = true; + vendorSha256 = "sha256:0m3w1aq54p46ckxkczh9yjw211lzsj70nygwmx372q2q2xrl2fhg"; + + subPackages = [ "cmd/chain-maind" ]; + CGO_ENABLED = "1"; + + buildFlagsArray = '' + -ldflags= + -X github.com/cosmos/cosmos-sdk/version.Name=chainmain + -X github.com/cosmos/cosmos-sdk/version.AppName=${pname} + -X github.com/cosmos/cosmos-sdk/version.Version=${version} + ''; +} + diff --git a/nix/default.nix b/nix/default.nix index 9893bbe5df..73f3310a46 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -18,6 +18,7 @@ import sources.nixpkgs { import ./scripts.nix { inherit pkgs; config = { + chainmain-config = ../scripts/chainmain-devnet.yaml; cronos-config = ../scripts/cronos-devnet.yaml; geth-genesis = ../scripts/geth-genesis.json; dotenv = builtins.path { name = "dotenv"; path = ../scripts/.env; }; diff --git a/nix/scripts.nix b/nix/scripts.nix index 45aa631b3e..a3ec8e582e 100644 --- a/nix/scripts.nix +++ b/nix/scripts.nix @@ -1,7 +1,11 @@ -{ pkgs -, config -, cronos ? (import ../. { inherit pkgs; }) +{ pkgs, config, cronos ? (import ../. { inherit pkgs; }) +, chainmain ? (import ../nix/chainmain.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.test-env}/bin:$PATH @@ -14,6 +18,6 @@ ''; start-scripts = pkgs.symlinkJoin { name = "start-scripts"; - paths = [ start-cronos start-geth ]; + paths = [ start-cronos start-geth start-chainmain ]; }; } diff --git a/scripts/chainmain-devnet.yaml b/scripts/chainmain-devnet.yaml new file mode 100644 index 0000000000..cec37c0912 --- /dev/null +++ b/scripts/chainmain-devnet.yaml @@ -0,0 +1,38 @@ +chainmain-1: + cmd: chain-maind + start-flags: "--trace" + validators: + - coins: 10cro + staked: 10cro +# min_self_delegation: 10000000 # 0.1cro + accounts: + - name: community + coins: 100cro + - name: ecosystem + coins: 200cro + - name: reserve + coins: 200cro + vesting: "60s" + - name: launch + coins: 100cro + - name: signer1 + coins: 10000cro + - name: signer2 + coins: 2000cro + - name: msigner1 + coins: 2000cro + - name: msigner2 + coins: 2000cro + genesis: + app_state: + staking: + params: + unbonding_time: "10s" + gov: + voting_params: + voting_period: "10s" + deposit_params: + max_deposit_period: "10s" + min_deposit: + - denom: "basecro" + amount: "10000000" diff --git a/scripts/start-chainmain b/scripts/start-chainmain new file mode 100755 index 0000000000..2157af3ba0 --- /dev/null +++ b/scripts/start-chainmain @@ -0,0 +1,23 @@ +#!/bin/sh +set -e + +CONFIG=$1 +if [ -z "$CONFIG" ]; then + echo "No config file supplied" + exit 1 +fi +shift + + +DATA=$1 +if [ -z "$DATA" ]; then + echo "No data directory supplied" + exit 1 +fi +shift + +# `pystarport serve` don't work for integration test for some weird reason +echo 'config'$CONFIG +echo 'data'$DATA +pystarport init --config $CONFIG --data $DATA $@ +supervisord -c $DATA/tasks.ini diff --git a/scripts/start-cronos b/scripts/start-cronos index f0772a05c8..2157af3ba0 100755 --- a/scripts/start-cronos +++ b/scripts/start-cronos @@ -8,12 +8,6 @@ if [ -z "$CONFIG" ]; then fi shift -DOTENV=$1 -if [ -z "$DOTENV" ]; then - echo "No dotenv file supplied" - exit 1 -fi -shift DATA=$1 if [ -z "$DATA" ]; then @@ -22,10 +16,8 @@ if [ -z "$DATA" ]; then fi shift -echo 'pystarport:' -echo ' config: '$CONFIG -echo ' dotenv: '$DOTENV -echo ' data: '$DATA - -pystarport init --config $CONFIG --dotenv $DOTENV --data $DATA $@ +# `pystarport serve` don't work for integration test for some weird reason +echo 'config'$CONFIG +echo 'data'$DATA +pystarport init --config $CONFIG --data $DATA $@ supervisord -c $DATA/tasks.ini