Skip to content

Commit

Permalink
Problem: The unlucky transactions are not shown in json rpc
Browse files Browse the repository at this point in the history
Closes: crypto-org-chain#455
- add patch-tx-result command
- test in integration test
  • Loading branch information
yihuang committed May 6, 2022
1 parent d6ab7c1 commit 41c1330
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
11 changes: 11 additions & 0 deletions integration_tests/cosmoscli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import hashlib
import json
import tempfile
from collections import namedtuple

import bech32
from dateutil.parser import isoparse
Expand Down Expand Up @@ -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")]
34 changes: 33 additions & 1 deletion integration_tests/test_replay_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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
Expand Down Expand Up @@ -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]
6 changes: 6 additions & 0 deletions scripts/devnet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down

0 comments on commit 41c1330

Please sign in to comment.