forked from crypto-org-chain/cronos
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Problem: key import,export not working correctly (fix crypto-org-chai…
…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
1 parent
72d3c02
commit f1cfc3a
Showing
31 changed files
with
441 additions
and
172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} | ||
''; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
NETWORK=testnet COSMOS_BUILD_OPTIONS=rocksdb make build | ||
nix-shell ./my.nix |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
. ./setup.sh | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
. ./setup.sh | ||
$CLI query bank balances ethm1fzep9fc7hweq9a706x4vacardl0zl0z3zquzd4 --node $NODE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
. ./setup.sh | ||
$CLI query bank balances $S1 --node $NODE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
. ./setup.sh | ||
$CLI query bank balances $S2 --node $NODE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.