forked from crypto-org-chain/cronos
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Problem: json-rpc failed on pruned nodes (backport crypto-org-chain#550)
Solution: - Make basic json-rpc apis works on pruned nodes - Test with integration tests
- Loading branch information
Showing
6 changed files
with
194 additions
and
28 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
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,64 @@ | ||
dotenv: ../../scripts/.env | ||
cronos_777-1: | ||
cmd: cronosd | ||
start-flags: "--trace" | ||
app-config: | ||
minimum-gas-prices: 0basetcro | ||
index-events: | ||
- ethereum_tx.ethereumTxHash | ||
pruning: "everything" | ||
state-sync: | ||
snapshot-interval: 0 | ||
json-rpc: | ||
address: "0.0.0.0:{EVMRPC_PORT}" | ||
ws-address: "0.0.0.0:{EVMRPC_PORT_WS}" | ||
api: "eth,net,web3,debug,cronos" | ||
validators: | ||
- coins: 1000000000000000000stake,10000000000000000000000basetcro | ||
staked: 1000000000000000000stake | ||
mnemonic: ${VALIDATOR1_MNEMONIC} | ||
- coins: 1000000000000000000stake,10000000000000000000000basetcro | ||
staked: 1000000000000000000stake | ||
mnemonic: ${VALIDATOR2_MNEMONIC} | ||
accounts: | ||
- name: community | ||
coins: 10000000000000000000000basetcro | ||
mnemonic: ${COMMUNITY_MNEMONIC} | ||
- name: signer1 | ||
coins: 20000000000000000000000basetcro | ||
mnemonic: ${SIGNER1_MNEMONIC} | ||
- name: signer2 | ||
coins: 30000000000000000000000basetcro | ||
mnemonic: ${SIGNER2_MNEMONIC} | ||
|
||
|
||
genesis: | ||
consensus_params: | ||
block: | ||
max_bytes: "1048576" | ||
max_gas: "81500000" | ||
app_state: | ||
evm: | ||
params: | ||
evm_denom: basetcro | ||
cronos: | ||
params: | ||
cronos_admin: ${CRONOS_ADMIN} | ||
enable_auto_deployment: true | ||
ibc_cro_denom: ${IBC_CRO_DENOM} | ||
gov: | ||
voting_params: | ||
voting_period: "10s" | ||
deposit_params: | ||
max_deposit_period: "10s" | ||
min_deposit: | ||
- denom: "basetcro" | ||
amount: "1" | ||
transfer: | ||
params: | ||
receive_enabled: true | ||
send_enabled: true | ||
feemarket: | ||
params: | ||
no_base_fee: false | ||
base_fee: "100000000000" |
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,108 @@ | ||
from pathlib import Path | ||
|
||
import pytest | ||
from eth_bloom import BloomFilter | ||
from eth_utils import abi, big_endian_to_int | ||
from hexbytes import HexBytes | ||
from web3.datastructures import AttributeDict | ||
|
||
from .network import setup_custom_cronos | ||
from .utils import ( | ||
ADDRS, | ||
CONTRACTS, | ||
KEYS, | ||
deploy_contract, | ||
sign_transaction, | ||
wait_for_new_blocks, | ||
) | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def cronos(request, tmp_path_factory): | ||
"""start-cronos | ||
params: enable_auto_deployment | ||
""" | ||
yield from setup_custom_cronos( | ||
tmp_path_factory.mktemp("pruned"), | ||
26900, | ||
Path(__file__).parent / "configs/pruned-node.yaml", | ||
) | ||
|
||
|
||
def test_pruned_node(cronos): | ||
""" | ||
test basic json-rpc apis works in pruned node | ||
""" | ||
w3 = cronos.w3 | ||
erc20 = deploy_contract( | ||
w3, | ||
CONTRACTS["TestERC20A"], | ||
key=KEYS["validator"], | ||
) | ||
tx = erc20.functions.transfer(ADDRS["community"], 10).buildTransaction( | ||
{"from": ADDRS["validator"]} | ||
) | ||
signed = sign_transaction(w3, tx, KEYS["validator"]) | ||
txhash = w3.eth.send_raw_transaction(signed.rawTransaction) | ||
|
||
print("wait for prunning happens") | ||
wait_for_new_blocks(cronos.cosmos_cli(0), 10) | ||
|
||
txreceipt = w3.eth.wait_for_transaction_receipt(txhash) | ||
assert len(txreceipt.logs) == 1 | ||
expect_log = { | ||
"address": erc20.address, | ||
"topics": [ | ||
HexBytes( | ||
abi.event_signature_to_log_topic("Transfer(address,address,uint256)") | ||
), | ||
HexBytes(b"\x00" * 12 + HexBytes(ADDRS["validator"])), | ||
HexBytes(b"\x00" * 12 + HexBytes(ADDRS["community"])), | ||
], | ||
"data": "0x000000000000000000000000000000000000000000000000000000000000000a", | ||
"transactionIndex": 0, | ||
"logIndex": 0, | ||
"removed": False, | ||
} | ||
assert expect_log.items() <= txreceipt.logs[0].items() | ||
|
||
# check block bloom | ||
block = w3.eth.get_block(txreceipt.blockNumber) | ||
assert "baseFeePerGas" in block | ||
assert block.miner == "0x0000000000000000000000000000000000000000" | ||
bloom = BloomFilter(big_endian_to_int(block.logsBloom)) | ||
assert HexBytes(erc20.address) in bloom | ||
for topic in expect_log["topics"]: | ||
assert topic in bloom | ||
|
||
tx1 = w3.eth.get_transaction(txhash) | ||
tx2 = w3.eth.get_transaction_by_block( | ||
txreceipt.blockNumber, txreceipt.transactionIndex | ||
) | ||
exp_tx = AttributeDict( | ||
{ | ||
"from": "0x57f96e6B86CdeFdB3d412547816a82E3E0EbF9D2", | ||
"gas": 51503, | ||
"input": ( | ||
"0xa9059cbb000000000000000000000000378c50d9264c63f3f92b806d4ee56e" | ||
"9d86ffb3ec000000000000000000000000000000000000000000000000000000" | ||
"000000000a" | ||
), | ||
"nonce": 2, | ||
"to": erc20.address, | ||
"transactionIndex": 0, | ||
"value": 0, | ||
"type": "0x2", | ||
"accessList": [], | ||
"chainId": "0x309", | ||
} | ||
) | ||
assert tx1 == tx2 | ||
for name in exp_tx.keys(): | ||
assert tx1[name] == tx2[name] == exp_tx[name] | ||
|
||
print( | ||
w3.eth.get_logs( | ||
{"fromBlock": txreceipt.blockNumber, "toBlock": txreceipt.blockNumber} | ||
) | ||
) |
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