Skip to content

Commit

Permalink
Problem: update evm param is not tested
Browse files Browse the repository at this point in the history
  • Loading branch information
mmsqe committed Mar 28, 2024
1 parent 96642b2 commit 6b4c2b5
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
8 changes: 8 additions & 0 deletions integration_tests/contracts/contracts/Random.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.15;

contract Random {
function randomTokenId() public returns (uint256) {
return uint256(keccak256(abi.encodePacked(block.prevrandao)));
}
}
46 changes: 45 additions & 1 deletion integration_tests/test_gov_update_params.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,56 @@
import hashlib
import json

import pytest

from .utils import approve_proposal
from .utils import CONTRACTS, approve_proposal, deploy_contract, eth_to_bech32

pytestmark = pytest.mark.gov


def test_evm_update_param(cronos, tmp_path):
contract = deploy_contract(
cronos.w3,
CONTRACTS["Random"],
)
with pytest.raises(ValueError) as e_info:
contract.caller.randomTokenId()
assert "invalid memory address or nil pointer dereference" in str(e_info.value)
deploy_contract(cronos.w3, CONTRACTS["Greeter"])
cli = cronos.cosmos_cli()
p = cli.query_params("evm")["params"]
del p["chain_config"]["shanghai_time"]
proposal = tmp_path / "proposal.json"
# governance module account as signer
data = hashlib.sha256("gov".encode()).digest()[:20]
signer = eth_to_bech32(data)
proposal_src = {
"messages": [
{
"@type": "/ethermint.evm.v1.MsgUpdateParams",
"authority": signer,
"params": p,
}
],
"deposit": "1basetcro",
"title": "title",
"summary": "summary",
}
proposal.write_text(json.dumps(proposal_src))
rsp = cli.submit_gov_proposal(proposal, from_="community")
assert rsp["code"] == 0, rsp["raw_log"]
approve_proposal(cronos, rsp)
print("check params have been updated now")
p = cli.query_params("evm")["params"]
invalid_msg = "invalid opcode: PUSH0"
with pytest.raises(ValueError) as e_info:
contract.caller.randomTokenId()
assert invalid_msg in str(e_info.value)
with pytest.raises(ValueError) as e_info:
deploy_contract(cronos.w3, CONTRACTS["Greeter"])
assert invalid_msg in str(e_info.value)


def test_gov_update_params(cronos, tmp_path):
cli = cronos.cosmos_cli()

Expand Down
1 change: 1 addition & 0 deletions integration_tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"CosmosERC20": "CosmosToken.sol",
"TestBank": "TestBank.sol",
"TestICA": "TestICA.sol",
"Random": "Random.sol",
}


Expand Down

0 comments on commit 6b4c2b5

Please sign in to comment.