Skip to content

Commit

Permalink
Merge pull request #11 from zenodeapp/genesis-v1.0.0
Browse files Browse the repository at this point in the history
Fixed some merge issues
  • Loading branch information
zenodeapp authored Jan 7, 2024
2 parents 2417cd6 + cac81bf commit 6763bd7
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 162 deletions.
2 changes: 1 addition & 1 deletion configs/default_app.toml
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ gas-to-suggest = 200000

# DenomToSuggest defines the defult denom for fee suggestion.
# Price must be in minimum-gas-prices.
denom-to-suggest = "uatom"
denom-to-suggest = "el1"

###############################################################################
### gRPC Configuration ###
Expand Down
4 changes: 2 additions & 2 deletions configs/default_config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,10 @@ laddr = "tcp://0.0.0.0:26656"
external_address = ""

# Comma separated list of seed nodes to connect to
seeds = "[email protected]:26656"
seeds = ""

# Comma separated list of nodes to keep persistent connections to
persistent_peers = "[email protected]:26656,[email protected]:26656,[email protected]:26656"
persistent_peers = "[email protected]:21496,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:61356,[email protected]:26656,[email protected]:26656"

# UPNP port forwarding
upnp = false
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -827,8 +827,6 @@ github.com/alitto/pond v1.8.2/go.mod h1:CmvIIGd5jKLasGI3D87qDkQxjzChdKMmnXMg3fG6
github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156/go.mod h1:Cb/ax3seSYIx7SuZdm2G2xzfwmv3TPSk2ucNfQESPXM=
github.com/allegro/bigcache v1.2.1 h1:hg1sY1raCwic3Vnsvje6TT7/pnZba83LeFck5NrFKSc=
github.com/allegro/bigcache v1.2.1/go.mod h1:Cb/ax3seSYIx7SuZdm2G2xzfwmv3TPSk2ucNfQESPXM=
github.com/alpha-omega-labs/cometbft-db v0.0.0-20230722202700-39607195539a h1:iwQVHwLiYzaJGzxy3SID255kp/Hm8Y2cu+zSXtjkkDE=
github.com/alpha-omega-labs/cometbft-db v0.0.0-20230722202700-39607195539a/go.mod h1:hF5aclS++7WrW8USOA3zPeKI0CuzwUD2TPYug25ANlQ=
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8=
github.com/andybalholm/brotli v1.0.2/go.mod h1:loMXtMfwqflxFJPmdbJO0a3KNoPuLBgiu3qAvBg8x/Y=
github.com/andybalholm/brotli v1.0.3/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
Expand Down
61 changes: 33 additions & 28 deletions integration_tests/test_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from pathlib import Path

import pytest
from dateutil.parser import isoparse
from pystarport import ports
from pystarport.cluster import SUPERVISOR_CONFIG_FILE

Expand Down Expand Up @@ -108,8 +109,13 @@ def test_cosmovisor_upgrade(custom_cronos: Cronos, tmp_path_factory):
)
print("old values", old_height, old_balance, old_base_fee)

plan_name = "v2.0.0-testnet3"
rsp = cli.gov_propose_legacy(
# estimateGas for an erc20 transfer tx
old_gas = contract.functions.transfer(ADDRS["community"], 100).build_transaction(
{"from": ADDRS["validator"]}
)["gas"]

plan_name = "v1.0.0"
rsp = cli.gov_propose_v0_7(
"community",
"software-upgrade",
{
Expand All @@ -121,7 +127,21 @@ def test_cosmovisor_upgrade(custom_cronos: Cronos, tmp_path_factory):
},
)
assert rsp["code"] == 0, rsp["raw_log"]
approve_proposal(custom_cronos, rsp)

# get proposal_id
ev = parse_events(rsp["logs"])["submit_proposal"]
assert ev["proposal_type"] == "SoftwareUpgrade", rsp
proposal_id = ev["proposal_id"]

rsp = cli.gov_vote("validator", proposal_id, "yes")
assert rsp["code"] == 0, rsp["raw_log"]
rsp = custom_cronos.cosmos_cli(1).gov_vote("validator", proposal_id, "yes")
assert rsp["code"] == 0, rsp["raw_log"]

proposal = cli.query_proposal(proposal_id)
wait_for_block_time(cli, isoparse(proposal["voting_end_time"]))
proposal = cli.query_proposal(proposal_id)
assert proposal["status"] == "PROPOSAL_STATUS_PASSED", proposal

# update cli chain binary
custom_cronos.chain_binary = (
Expand Down Expand Up @@ -161,30 +181,15 @@ def test_cosmovisor_upgrade(custom_cronos: Cronos, tmp_path_factory):
ADDRS["validator"]
)

# check gravity params
assert cli.query_gravity_params() == {
"params": {
"gravity_id": "cronos_gravity_testnet",
"contract_source_hash": "",
"bridge_ethereum_address": "0x0000000000000000000000000000000000000000",
"bridge_chain_id": "0",
"signed_signer_set_txs_window": "10000",
"signed_batches_window": "10000",
"ethereum_signatures_window": "10000",
"target_eth_tx_timeout": "43200000",
"average_block_time": "5000",
"average_ethereum_block_time": "15000",
"slash_fraction_signer_set_tx": "0.001000000000000000",
"slash_fraction_batch": "0.001000000000000000",
"slash_fraction_ethereum_signature": "0.001000000000000000",
"slash_fraction_conflicting_ethereum_signature": "0.001000000000000000",
"unbond_slashing_signer_set_txs_window": "10000",
"bridge_active": False,
"batch_creation_period": "10",
"batch_max_element": "100",
"observe_ethereum_height_period": "50",
}
}
assert not cli.evm_params()["params"]["extra_eips"]

# check the gas cost is lower after upgrade
assert (
old_gas - 3700
== contract.functions.transfer(ADDRS["community"], 100).build_transaction(
{"from": ADDRS["validator"]}
)["gas"]
)

# migrate to sdk v0.46
custom_cronos.supervisorctl("stop", "all")
Expand Down Expand Up @@ -213,4 +218,4 @@ def test_cosmovisor_upgrade(custom_cronos: Cronos, tmp_path_factory):
file.write_text(json.dumps(genesis))
custom_cronos.supervisorctl("start", "cronos_777-1-node0", "cronos_777-1-node1")
wait_for_new_blocks(custom_cronos.cosmos_cli(), 1)
custom_cronos.supervisorctl("stop", "all")
custom_cronos.supervisorctl("stop", "all")

Check failure on line 221 in integration_tests/test_upgrade.py

View workflow job for this annotation

GitHub Actions / Lint python

./integration_tests/test_upgrade.py:221:47: W292 no newline at end of file
135 changes: 6 additions & 129 deletions integration_tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

import bech32
import eth_utils
import pytest
import rlp
import toml
from dateutil.parser import isoparse
Expand Down Expand Up @@ -48,10 +47,6 @@
"TestBlackListERC20": "TestBlackListERC20.sol",
"CroBridge": "CroBridge.sol",
"CronosGravityCancellation": "CronosGravityCancellation.sol",
"TestCRC20": "TestCRC20.sol",
"TestCRC20Proxy": "TestCRC20Proxy.sol",
"TestMaliciousSupply": "TestMaliciousSupply.sol",
"CosmosERC20": "CosmosToken.sol",
}


Expand All @@ -69,8 +64,6 @@ def contract_path(name, filename):
/ "x/cronos/types/contracts/ModuleCRC20.json",
"ModuleCRC21": Path(__file__).parent.parent
/ "x/cronos/types/contracts/ModuleCRC21.json",
"ModuleCRC20Proxy": Path(__file__).parent.parent
/ "x/cronos/types/contracts/ModuleCRC20Proxy.json",
**{
name: contract_path(name, filename) for name, filename in TEST_CONTRACTS.items()
},
Expand Down Expand Up @@ -122,27 +115,6 @@ def wait_for_block_time(cli, t):
time.sleep(0.5)


def approve_proposal(n, rsp, event_query_tx=False):
cli = n.cosmos_cli()
if event_query_tx:
rsp = cli.event_query_tx_for(rsp["txhash"])
# get proposal_id
ev = parse_events(rsp["logs"])["submit_proposal"]
proposal_id = ev["proposal_id"]
for i in range(len(n.config["validators"])):
rsp = n.cosmos_cli(i).gov_vote("validator", proposal_id, "yes")
assert rsp["code"] == 0, rsp["raw_log"]
wait_for_new_blocks(cli, 1)
assert (
int(cli.query_tally(proposal_id)["yes_count"]) == cli.staking_pool()
), "all validators should have voted yes"
print("wait for proposal to be activated")
proposal = cli.query_proposal(proposal_id)
wait_for_block_time(cli, isoparse(proposal["voting_end_time"]))
proposal = cli.query_proposal(proposal_id)
assert proposal["status"] == "PROPOSAL_STATUS_PASSED", proposal


def wait_for_port(port, host="127.0.0.1", timeout=40.0):
start_time = time.perf_counter()
while True:
Expand Down Expand Up @@ -322,12 +294,7 @@ def deploy_contract(w3, jsonfile, args=(), key=KEYS["validator"]):
"""
acct = Account.from_key(key)
info = json.loads(jsonfile.read_text())
bytecode = ""
if "bytecode" in info:
bytecode = info["bytecode"]
if "byte" in info:
bytecode = info["byte"]
contract = w3.eth.contract(abi=info["abi"], bytecode=bytecode)
contract = w3.eth.contract(abi=info["abi"], bytecode=info["bytecode"])
tx = contract.constructor(*args).build_transaction({"from": acct.address})
txreceipt = send_transaction(w3, tx, key)
assert txreceipt.status == 1
Expand Down Expand Up @@ -364,13 +331,13 @@ def cronos_address_from_mnemonics(mnemonics, prefix=CRONOS_ADDRESS_PREFIX):
return eth_to_bech32(acct.address, prefix)


def send_to_cosmos(gravity_contract, token_contract, w3, recipient, amount, key=None):
def send_to_cosmos(gravity_contract, token_contract, recipient, amount, key=None):
"""
do approve and sendToCronos on ethereum side
"""
acct = Account.from_key(key)
txreceipt = send_transaction(
w3,
token_contract.web3,
token_contract.functions.approve(
gravity_contract.address, amount
).build_transaction({"from": acct.address}),
Expand All @@ -379,19 +346,19 @@ def send_to_cosmos(gravity_contract, token_contract, w3, recipient, amount, key=
assert txreceipt.status == 1, "approve failed"

return send_transaction(
w3,
gravity_contract.web3,
gravity_contract.functions.sendToCronos(
token_contract.address, HexBytes(recipient), amount
).build_transaction({"from": acct.address}),
key,
)


def deploy_erc20(gravity_contract, w3, denom, name, symbol, decimal, key=None):
def deploy_erc20(gravity_contract, denom, name, symbol, decimal, key=None):
acct = Account.from_key(key)

return send_transaction(
w3,
gravity_contract.web3,
gravity_contract.functions.deployERC20(
denom, name, symbol, decimal
).build_transaction({"from": acct.address}),
Expand Down Expand Up @@ -557,93 +524,3 @@ def send_txs(w3, cli, to, keys, params):
sended_hash_set = send_raw_transactions(w3, raw_transactions)

return block_num_0, sended_hash_set


def multiple_send_to_cosmos(gcontract, tcontract, w3, recipient, amount, keys):
# use different sender accounts to be able be send concurrently
raw_transactions = []
for key_from in keys:
acct = Account.from_key(key_from)
acct_address = HexBytes(acct.address)
# approve first
approve = tcontract.functions.approve(gcontract.address, amount)
txreceipt = send_transaction(
w3,
approve.build_transaction({"from": acct.address}),
key_from,
)
assert txreceipt.status == 1, "approve failed"

# generate the tx
tx = gcontract.functions.sendToCronos(
tcontract.address, HexBytes(recipient), amount
).build_transaction({"from": acct_address})
signed = sign_transaction(w3, tx, key_from)
raw_transactions.append(signed.rawTransaction)

# wait for new block
w3_wait_for_new_blocks(w3, 1)
return send_raw_transactions(w3, raw_transactions)


def setup_token_mapping(cronos, name, symbol):
# deploy contract
w3 = cronos.w3
contract = deploy_contract(w3, CONTRACTS[name])

# setup the contract mapping
cronos_cli = cronos.cosmos_cli()

print("contract", contract.address)
denom = f"cronos{contract.address}"
balance = contract.caller.balanceOf(ADDRS["validator"])
assert balance == 100000000000000000000000000

print("check the contract mapping not exists yet")
with pytest.raises(AssertionError):
cronos_cli.query_contract_by_denom(denom)

rsp = cronos_cli.update_token_mapping(
denom, contract.address, symbol, 6, from_="validator"
)
assert rsp["code"] == 0, rsp["raw_log"]
wait_for_new_blocks(cronos_cli, 1)

print("check the contract mapping exists now")
rsp = cronos_cli.query_denom_by_contract(contract.address)
assert rsp["denom"] == denom
return contract, denom


def submit_any_proposal(cronos, tmp_path, event_query_tx=False):
# governance module account as granter
cli = cronos.cosmos_cli()
granter_addr = "crc10d07y265gmmuvt4z0w9aw880jnsr700jdufnyd"
grantee_addr = cli.address("signer1")

# this json can be obtained with `--generate-only` flag for respective cli calls
proposal_json = {
"messages": [
{
"@type": "/cosmos.feegrant.v1beta1.MsgGrantAllowance",
"granter": granter_addr,
"grantee": grantee_addr,
"allowance": {
"@type": "/cosmos.feegrant.v1beta1.BasicAllowance",
"spend_limit": [],
"expiration": None,
},
}
],
"deposit": "1basetcro",
}
proposal_file = tmp_path / "proposal.json"
proposal_file.write_text(json.dumps(proposal_json))
rsp = cli.submit_gov_proposal(proposal_file, from_="community")
assert rsp["code"] == 0, rsp["raw_log"]

approve_proposal(cronos, rsp, event_query_tx)

grant_detail = cli.query_grant(granter_addr, grantee_addr)
assert grant_detail["granter"] == granter_addr
assert grant_detail["grantee"] == grantee_addr

0 comments on commit 6763bd7

Please sign in to comment.