From 41c13306a438b40e373949d870fb6d222ffdf9ea Mon Sep 17 00:00:00 2001 From: HuangYi Date: Fri, 6 May 2022 09:32:21 +0800 Subject: [PATCH] Problem: The unlucky transactions are not shown in json rpc Closes: #455 - add patch-tx-result command - test in integration test --- integration_tests/cosmoscli.py | 11 +++++++++ integration_tests/test_replay_block.py | 34 +++++++++++++++++++++++++- scripts/devnet.yaml | 6 +++++ 3 files changed, 50 insertions(+), 1 deletion(-) diff --git a/integration_tests/cosmoscli.py b/integration_tests/cosmoscli.py index a68b2b53f1..28146112ec 100644 --- a/integration_tests/cosmoscli.py +++ b/integration_tests/cosmoscli.py @@ -2,6 +2,7 @@ import hashlib import json import tempfile +from collections import namedtuple import bech32 from dateutil.parser import isoparse @@ -1012,3 +1013,13 @@ def update_token_mapping(self, denom, contract, **kwargs): **kwargs, ) ) + + def fix_tx_result(self, begin_block, end_block): + output = self.raw( + "fix-tx-result", + begin_block, + end_block, + home=self.data_dir, + ) + Item = namedtuple("hash height index") + return [Item(*line.split()[1:]) for line in output.split("\n")] diff --git a/integration_tests/test_replay_block.py b/integration_tests/test_replay_block.py index cba0f6587c..7970e44c8b 100644 --- a/integration_tests/test_replay_block.py +++ b/integration_tests/test_replay_block.py @@ -2,11 +2,19 @@ import pytest import web3 +from pystarport import ports from web3._utils.method_formatters import receipt_formatter from web3.datastructures import AttributeDict from .network import setup_custom_cronos -from .utils import ADDRS, KEYS, deploy_contract, sign_transaction +from .utils import ( + ADDRS, + KEYS, + deploy_contract, + sign_transaction, + supervisorctl, + wait_for_port, +) @pytest.fixture(scope="module") @@ -19,6 +27,8 @@ def custom_cronos(tmp_path_factory): def test_replay_block(custom_cronos): w3: web3.Web3 = custom_cronos.w3 + cli = custom_cronos.cosmos_cli() + begin_height = cli.block_height() contract = deploy_contract( w3, Path(__file__).parent @@ -93,3 +103,25 @@ def test_replay_block(custom_cronos): replay_receipts = [AttributeDict(receipt_formatter(item)) for item in rsp["result"]] assert replay_receipts[1].status == 0 assert replay_receipts[1].gasUsed == gas_limit + + # check the preUpgrade mode, should be the same as the receipt after patch. + replay_receipts = w3.provider.make_request( + "cronos_replayBlock", [hex(receipt1.blockNumber), False] + )["result"] + + # patch the unlucky tx with the new cli command + # stop the node0 + end_height = cli.block_height() + supervisorctl(custom_cronos.base_dir / "../tasks.ini", "stop", "cronos_777-1-node0") + results = custom_cronos.cosmos_cli().fix_tx_result(begin_height, end_height) + # the second tx is patched + assert results[0].hash == txhashes[1] + # start the node0 again + supervisorctl( + custom_cronos.base_dir / "../tasks.ini", "start", "cronos_777-1-node0" + ) + # wait for json-rpc port + wait_for_port(ports.evmrpc_port(custom_cronos.base_port(0))) + w3: web3.Web3 = custom_cronos.w3 + receipt = w3.eth.get_transaction_receipt(txhashes[1]) + assert receipt == replay_receipts[1] diff --git a/scripts/devnet.yaml b/scripts/devnet.yaml index dfc5c207a3..bb85366e04 100644 --- a/scripts/devnet.yaml +++ b/scripts/devnet.yaml @@ -5,6 +5,8 @@ cronos_777-1: json-rpc: address: "0.0.0.0:{EVMRPC_PORT}" ws-address: "0.0.0.0:{EVMRPC_PORT_WS}" + evm: + max-tx-gas-wanted: 0 validators: - coins: 1000000000000000000stake,1000000000000000000basetcro staked: 1000000000000000000stake @@ -17,6 +19,10 @@ cronos_777-1: coins: 10000000000000000000000basetcro mnemonic: "notable error gospel wave pair ugly measure elite toddler cost various fly make eye ketchup despair slab throw tribe swarm word fruit into inmate" genesis: + consensus_params: + block: + max_bytes: "1048576" + max_gas: "800000" app_state: evm: params: