Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

Commit

Permalink
test debug_traceBlockByNumber
Browse files Browse the repository at this point in the history
  • Loading branch information
mmsqe committed Feb 28, 2023
1 parent a5cb4b9 commit 523121d
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 13 deletions.
16 changes: 3 additions & 13 deletions tests/integration_tests/test_account.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import os

import pytest
from eth_account import Account
from web3 import Web3

from .network import setup_ethermint
from .utils import ADDRS, w3_wait_for_new_blocks
from .utils import ADDRS, derive_new_account, w3_wait_for_new_blocks


@pytest.fixture(scope="module")
Expand All @@ -32,19 +29,12 @@ def cluster(request, custom_ethermint, geth):
raise NotImplementedError


def derive_new_address(n=1):
# derive a new address
account_path = f"m/44'/60'/0'/0/{n}"
mnemonic = os.getenv("COMMUNITY_MNEMONIC")
return (Account.from_mnemonic(mnemonic, account_path=account_path)).address


def test_get_transaction_count(cluster):
w3: Web3 = cluster.w3
blk = hex(w3.eth.block_number)
sender = ADDRS["validator"]

receiver = derive_new_address()
receiver = derive_new_account().address
n0 = w3.eth.get_transaction_count(receiver, blk)
# ensure transaction send in new block
w3_wait_for_new_blocks(w3, 1, sleep=0.1)
Expand All @@ -64,7 +54,7 @@ def test_get_transaction_count(cluster):

def test_query_future_blk(cluster):
w3: Web3 = cluster.w3
acc = derive_new_address(2)
acc = derive_new_account(2).address
current = w3.eth.block_number
future = current + 1000
with pytest.raises(ValueError) as exc:
Expand Down
53 changes: 53 additions & 0 deletions tests/integration_tests/test_debug_trace.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import requests
from pystarport import ports

from .utils import (
derive_new_account,
send_transaction,
sign_transaction,
wait_for_new_blocks,
)


def test_trace_blk(ethermint):
w3 = ethermint.w3
cli = ethermint.cosmos_cli()
acc = derive_new_account(3)
sender = acc.address
# fund new sender
fund = 3000000000000000000
tx = {"to": sender, "value": fund, "gasPrice": w3.eth.gas_price}
send_transaction(w3, tx)
assert w3.eth.get_balance(sender, "latest") == fund
nonce = w3.eth.get_transaction_count(sender)
blk = wait_for_new_blocks(cli, 1, sleep=0.1)
print(f"block number start: {blk}")
txhashes = []
total = 3
for n in range(total):
tx = {
"to": "0x2956c404227Cc544Ea6c3f4a36702D0FD73d20A2",
"value": fund // total,
"gas": 21000,
"maxFeePerGas": 6556868066901,
"maxPriorityFeePerGas": 1500000000,
"nonce": nonce + n,
}
signed = sign_transaction(w3, tx, acc.key)
txhash = w3.eth.send_raw_transaction(signed.rawTransaction)
print("txhash", txhash.hex())
txhashes.append(txhash)
for txhash in txhashes[0:total - 1]:
res = w3.eth.wait_for_transaction_receipt(txhash)
assert res.status == 1

url = f"http://127.0.0.1:{ports.evmrpc_port(ethermint.base_port(0))}"
params = {
"method": "debug_traceBlockByNumber",
"params": [hex(blk + 1)],
"id": 1,
"jsonrpc": "2.0",
}
rsp = requests.post(url, json=params)
assert rsp.status_code == 200
assert len(rsp.json()["result"]) == 2
7 changes: 7 additions & 0 deletions tests/integration_tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,10 @@ def parse_events(logs):
ev["type"]: {attr["key"]: attr["value"] for attr in ev["attributes"]}
for ev in logs[0]["events"]
}


def derive_new_account(n=1):
# derive a new address
account_path = f"m/44'/60'/0'/0/{n}"
mnemonic = os.getenv("COMMUNITY_MNEMONIC")
return Account.from_mnemonic(mnemonic, account_path=account_path)

0 comments on commit 523121d

Please sign in to comment.