Skip to content

Commit

Permalink
Problem: key import,export not working correctly (fix crypto-org-chai…
Browse files Browse the repository at this point in the history
…n#26) (crypto-org-chain#27)

add scripts

pear

makefile

add my.nix

working

works

OK

works

work

chainmain works

tidy up

1 node
  • Loading branch information
leejw51crypto committed Sep 8, 2021
1 parent 552d88a commit 16696ff
Show file tree
Hide file tree
Showing 32 changed files with 449 additions and 3 deletions.
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ BINDIR ?= ~/go/bin
build: go.sum
@go build -mod=readonly $(BUILD_FLAGS) $(BUILD_TAGS) -o $(BUILDDIR)/cronosd ./cmd/cronosd

install: go.sum
@go install -mod=readonly $(BUILD_FLAGS) $(BUILD_TAGS) ./cmd/cronosd

test:
@go test -v -mod=readonly $(PACKAGES) -coverprofile=$(COVERAGE) -covermode=atomic

Expand Down Expand Up @@ -143,6 +146,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:
@nix-shell ./integration_tests/shell.nix --run ./scripts/run-integration-tests

Expand Down
16 changes: 16 additions & 0 deletions chainmain.nix2
Original file line number Diff line number Diff line change
@@ -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}
'';
}
2 changes: 1 addition & 1 deletion cmd/cronosd/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func NewRootCmd() (*cobra.Command, params.EncodingConfig) {
initRootCmd(rootCmd, encodingConfig)
overwriteFlagDefaults(rootCmd, map[string]string{
flags.FlagChainID: ChainID,
flags.FlagKeyringBackend: "test",
flags.FlagKeyringBackend: "os",
})

return rootCmd, encodingConfig
Expand Down
1 change: 1 addition & 0 deletions go.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nix-shell ./my.nix
2 changes: 1 addition & 1 deletion integration_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import pytest

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


def pytest_configure(config):
Expand Down
31 changes: 31 additions & 0 deletions integration_tests/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,20 @@ 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), "cronosd")


class Geth:
def __init__(self, w3):
Expand All @@ -57,6 +71,23 @@ def setup_cronos(path, base_port):
proc.wait()


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 = [
Expand Down
1 change: 1 addition & 0 deletions integration_tests/shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ pkgs.mkShell {
pkgs.nodejs
pkgs.git
(import ../nix/testenv.nix { inherit pkgs; })
(import ../nix/chainmain.nix { inherit pkgs; })
];
}
18 changes: 18 additions & 0 deletions integration_tests/test_ibc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@



import pytest
from .conftest import setup_cronos, setup_chainmain

@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_ibc(cronos) :
assert True
pass
4 changes: 4 additions & 0 deletions my/apple/addkey.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
. ./setup.sh



2 changes: 2 additions & 0 deletions my/apple/i1.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
. ./setup.sh
$CLI query bank balances ethm1fzep9fc7hweq9a706x4vacardl0zl0z3zquzd4 --node $NODE
61 changes: 61 additions & 0 deletions my/apple/init.sh
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions my/apple/run.sh
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions my/apple/s1.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
. ./setup.sh
$CLI query bank balances $S1 --node $NODE
2 changes: 2 additions & 0 deletions my/apple/s2.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
. ./setup.sh
$CLI query bank balances $S2 --node $NODE
8 changes: 8 additions & 0 deletions my/apple/send.sh
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions my/apple/send0.sh
Original file line number Diff line number Diff line change
@@ -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
43 changes: 43 additions & 0 deletions my/apple/setup.sh
Original file line number Diff line number Diff line change
@@ -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 '"')

4 changes: 4 additions & 0 deletions my/pear/addkey.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
. ./setup.sh



61 changes: 61 additions & 0 deletions my/pear/init.sh
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions my/pear/run.sh
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions my/pear/s1.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
. ./setup.sh
$CLI query bank balances $S1 --node $NODE
2 changes: 2 additions & 0 deletions my/pear/s2.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
. ./setup.sh
$CLI query bank balances $S2 --node $NODE
8 changes: 8 additions & 0 deletions my/pear/send.sh
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions my/pear/send0.sh
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit 16696ff

Please sign in to comment.