Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test_tx_inclusion #11

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/api/json-rpc/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ PubSubAPI](https://geth.ethereum.org/docs/rpc/pubsub), Cronos needs to cast the
responses retrieved into the Ethereum types.

You can start a connection with the Ethereum websocket using the `--json-rpc.ws-address` flag when starting
the node (default `"0.0.0.0:8546"`):
the node (default `"127.0.0.1:8546"`):

```bash
cronosd start --json-rpc.address"0.0.0.0:8545" --json-rpc.ws-address="0.0.0.0:8546" --evm.rpc.api="eth,web3,net,txpool,debug" --json-rpc.enable
cronosd start --json-rpc.address"127.0.0.1:8545" --json-rpc.ws-address="127.0.0.1:8546" --evm.rpc.api="eth,web3,net,txpool,debug" --json-rpc.enable
```

Then, start a websocket subscription with [`ws`](https://github.com/hashrocket/ws)
Expand Down
4 changes: 2 additions & 2 deletions integration_tests/configs/cronos-experimental-devnet.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ config {
'app-db-backend':: super['app-db-backend'],
'minimum-gas-prices': '100000000000basetcro',
'json-rpc': {
address: '0.0.0.0:{EVMRPC_PORT}',
'ws-address': '0.0.0.0:{EVMRPC_PORT_WS}',
address: '127.0.0.1:{EVMRPC_PORT}',
'ws-address': '127.0.0.1:{EVMRPC_PORT_WS}',
},
},
genesis+: {
Expand Down
11 changes: 7 additions & 4 deletions integration_tests/configs/default.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@
},
},
'app-config': {
'app-db-backend': 'pebbledb',
'evm': {
'max-tx-gas-wanted': 400000,
},
'app-db-backend': 'rocksdb',
'minimum-gas-prices': '0basetcro',
'index-events': ['ethereum_tx.ethereumTxHash'],
'iavl-lazy-loading': true,
'json-rpc': {
address: '0.0.0.0:{EVMRPC_PORT}',
'ws-address': '0.0.0.0:{EVMRPC_PORT_WS}',
address: '127.0.0.1:{EVMRPC_PORT}',
'ws-address': '127.0.0.1:{EVMRPC_PORT_WS}',
api: 'eth,net,web3,debug,cronos',
'feehistory-cap': 100,
'block-range-cap': 10000,
Expand Down Expand Up @@ -61,7 +64,7 @@
consensus_params: {
block: {
max_bytes: '1048576',
max_gas: '81500000',
max_gas: '40000000',
},
},
app_state: {
Expand Down
58 changes: 19 additions & 39 deletions integration_tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from hexbytes import HexBytes
from pystarport import cluster, ports

from .utils import (

Check failure on line 13 in integration_tests/test_basic.py

View workflow job for this annotation

GitHub Actions / Lint python

./integration_tests/test_basic.py:13:1: F401 '.utils.modify_command_in_supervisor_config' imported but unused

Check failure on line 13 in integration_tests/test_basic.py

View workflow job for this annotation

GitHub Actions / Lint python

./integration_tests/test_basic.py:13:1: F401 '.utils.send_txs' imported but unused
ADDRS,
CONTRACTS,
KEYS,
Expand All @@ -24,6 +24,7 @@
modify_command_in_supervisor_config,
send_transaction,
send_txs,
send_txs2,
wait_for_block,
wait_for_port,
)
Expand Down Expand Up @@ -191,8 +192,8 @@
clustercli.base_port(i),
{
"json-rpc": {
"address": "0.0.0.0:{EVMRPC_PORT}",
"ws-address": "0.0.0.0:{EVMRPC_PORT_WS}",
"address": "127.0.0.1:{EVMRPC_PORT}",
"ws-address": "127.0.0.1:{EVMRPC_PORT_WS}",
}
},
)
Expand Down Expand Up @@ -668,51 +669,30 @@
origin_cmd = None


@pytest.mark.parametrize("max_gas_wanted", [80000000, 40000000, 25000000, 500000])
def test_tx_inclusion(cronos, max_gas_wanted):
def test_tx_inclusion(cronos):
"""
- send multiple heavy transactions at the same time.
- check they are included in consecutively blocks without failure.

test against different max-gas-wanted configuration.
"""

def fn(cmd):
global origin_cmd
if origin_cmd is None:
origin_cmd = cmd
return f"{origin_cmd} --evm.max-tx-gas-wanted {max_gas_wanted}"

modify_command_in_supervisor_config(
cronos.base_dir / "tasks.ini",
lambda cmd: fn(cmd),
)
cronos.supervisorctl("update")
wait_for_port(ports.evmrpc_port(cronos.base_port(0)))

w3 = cronos.w3
cli = cronos.cosmos_cli()
block_gas_limit = 81500000
tx_gas_limit = 80000000
max_tx_in_block = block_gas_limit // min(max_gas_wanted, tx_gas_limit)
print("max_tx_in_block", max_tx_in_block)
to = ADDRS["validator"]
params = {"gas": tx_gas_limit}
_, sended_hash_set = send_txs(w3, cli, to, list(KEYS.values())[0:4], params)
block_nums = [
w3.eth.wait_for_transaction_receipt(h).blockNumber for h in sended_hash_set
]
block_nums.sort()
print(f"all block numbers: {block_nums}")
# the transactions should be included according to max_gas_wanted
if max_tx_in_block == 1:
for block_num, next_block_num in zip(block_nums, block_nums[1:]):
assert next_block_num == block_num + 1
else:
for num in block_nums[1:max_tx_in_block]:
assert num == block_nums[0]
for num in block_nums[max_tx_in_block:]:
assert num == block_nums[0] + 1
tx_gas_limit = 289275000
contract = deploy_contract(
w3,
CONTRACTS["TestMessageCall"],
key=KEYS["community"],
)
iterations = 13000
tx = contract.functions.test(iterations).build_transaction()
print("estimate_gas", w3.eth.estimate_gas(tx))
tx["gas"] = tx_gas_limit
_, sended_hash_set = send_txs2(w3, cli, list(KEYS.values())[0:4], tx)
for h in sended_hash_set:
res = w3.eth.wait_for_transaction_receipt(h)
print("res:", h.hex(), res["blockNumber"], res["cumulativeGasUsed"], res["gasUsed"], res["status"])

Check failure on line 694 in integration_tests/test_basic.py

View workflow job for this annotation

GitHub Actions / Lint python

./integration_tests/test_basic.py:694:15: BLK100 Black would make changes.

Check failure on line 694 in integration_tests/test_basic.py

View workflow job for this annotation

GitHub Actions / Lint python

./integration_tests/test_basic.py:694:89: E501 line too long (107 > 88 characters)
time.sleep(30)


def test_replay_protection(cronos):
Expand Down
23 changes: 20 additions & 3 deletions integration_tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
Account.enable_unaudited_hdwallet_features()
ACCOUNTS = {
"validator": Account.from_mnemonic(os.getenv("VALIDATOR1_MNEMONIC")),
"validator2": Account.from_mnemonic(os.getenv("VALIDATOR2_MNEMONIC")),
# "validator2": Account.from_mnemonic(os.getenv("VALIDATOR2_MNEMONIC")),
"community": Account.from_mnemonic(os.getenv("COMMUNITY_MNEMONIC")),
"signer1": Account.from_mnemonic(os.getenv("SIGNER1_MNEMONIC")),
"signer2": Account.from_mnemonic(os.getenv("SIGNER2_MNEMONIC")),
# "signer1": Account.from_mnemonic(os.getenv("SIGNER1_MNEMONIC")),
# "signer2": Account.from_mnemonic(os.getenv("SIGNER2_MNEMONIC")),
}
KEYS = {name: account.key for name, account in ACCOUNTS.items()}
ADDRS = {name: account.address for name, account in ACCOUNTS.items()}
Expand Down Expand Up @@ -510,3 +510,20 @@ 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 send_txs2(w3, cli, keys, tx):
# use different sender accounts to be able be send concurrently
raw_transactions = []
for key_from in keys:
signed = sign_transaction(w3, tx, key_from)
raw_transactions.append(signed.rawTransaction)

# wait block update
block_num_0 = wait_for_new_blocks(cli, 1, sleep=0.1)
print(f"block number start: {block_num_0}")

# send transactions
sended_hash_set = send_raw_transactions(w3, raw_transactions)

return block_num_0, sended_hash_set
4 changes: 2 additions & 2 deletions scripts/cronos-devnet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ cronos_777-1:
index-events:
- ethereum_tx.ethereumTxHash
json-rpc:
address: "0.0.0.0:{EVMRPC_PORT}"
ws-address: "0.0.0.0:{EVMRPC_PORT_WS}"
address: "127.0.0.1:{EVMRPC_PORT}"
ws-address: "127.0.0.1:{EVMRPC_PORT_WS}"
api: "eth,net,web3,debug,cronos"
validators:
- coins: 1000000000000000000stake,10000000000000000000000basetcro
Expand Down
2 changes: 1 addition & 1 deletion scripts/run-integration-tests
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ cd ../integration_tests/contracts
HUSKY_SKIP_INSTALL=1 npm install
npm run typechain
cd ..
nix-shell --run "pytest -vv -s"
nix-shell --run "pytest -v -s test_basic.py::test_tx_inclusion"
Loading