Skip to content

Commit

Permalink
test: fix integration test - remove tx priority test
Browse files Browse the repository at this point in the history
  • Loading branch information
dudong2 committed Jan 2, 2024
1 parent 6d26495 commit d0facf3
Show file tree
Hide file tree
Showing 2 changed files with 166 additions and 168 deletions.
6 changes: 0 additions & 6 deletions tests/integration_tests/configs/default.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@
'ethermint_9000-1': {
cmd: 'ethermintd',
'start-flags': '--trace',
config: {
mempool: {
// use v1 mempool to enable tx prioritization
version: 'v1',
},
},
'app-config': {
'minimum-gas-prices': '0aphoton',
'index-events': ['ethereum_tx.ethereumTxHash'],
Expand Down
328 changes: 166 additions & 162 deletions tests/integration_tests/test_priority.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,168 +34,172 @@ def tx_priority(tx, base_fee):
# legacy tx
return (tx["gasPrice"] - base_fee) // PRIORITY_REDUCTION


def test_priority(ethermint):
"""
test priorities of different tx types
use a relatively large priority number to counter
the effect of base fee change during the testing.
"""
w3 = ethermint.w3
amount = 10000
base_fee = w3.eth.get_block("latest").baseFeePerGas

# [ ( sender, tx ), ... ]
# use different senders to avoid nonce conflicts
test_cases = [
(
"validator",
{
"to": "0x0000000000000000000000000000000000000000",
"value": amount,
"gas": 21000,
"maxFeePerGas": base_fee + PRIORITY_REDUCTION * 600000,
"maxPriorityFeePerGas": 0,
},
),
(
"community",
{
"to": "0x0000000000000000000000000000000000000000",
"value": amount,
"gas": 21000,
"gasPrice": base_fee + PRIORITY_REDUCTION * 200000,
},
),
(
"signer2",
{
"to": "0x0000000000000000000000000000000000000000",
"value": amount,
"gasPrice": base_fee + PRIORITY_REDUCTION * 400000,
"accessList": [
{
"address": "0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae",
"storageKeys": (
"0x00000000000000000000000000000000000000000000000000000000"
"00000003",
"0x00000000000000000000000000000000000000000000000000000000"
"00000007",
),
}
],
},
),
(
"signer1",
{
"to": "0x0000000000000000000000000000000000000000",
"value": amount,
"gas": 21000,
"maxFeePerGas": base_fee + PRIORITY_REDUCTION * 600000,
"maxPriorityFeePerGas": PRIORITY_REDUCTION * 600000,
},
),
]

# test cases are ordered by priority
expect_priorities = [tx_priority(tx, base_fee) for _, tx in test_cases]
assert expect_priorities == [0, 200000, 400000, 600000]

signed = [sign_transaction(w3, tx, key=KEYS[sender]) for sender, tx in test_cases]
# send the txs from low priority to high,
# but the later sent txs should be included earlier.
txhashes = [w3.eth.send_raw_transaction(tx.rawTransaction) for tx in signed]

receipts = [w3.eth.wait_for_transaction_receipt(txhash) for txhash in txhashes]
print(receipts)
assert all(receipt.status == 1 for receipt in receipts), "expect all txs success"

# the later txs should be included earlier because of higher priority
# FIXME there's some non-deterministics due to mempool logic
tx_indexes = [(r.blockNumber, r.transactionIndex) for r in receipts]
print(tx_indexes)
# the first sent tx are included later, because of lower priority
assert all(i1 > i2 for i1, i2 in zip(tx_indexes, tx_indexes[1:]))


def test_native_tx_priority(ethermint):
cli = ethermint.cosmos_cli()
base_fee = cli.query_base_fee()
print("base_fee", base_fee)
test_cases = [
{
"from": eth_to_bech32(ADDRS["community"]),
"to": eth_to_bech32(ADDRS["validator"]),
"amount": "1000aphoton",
"gas_prices": f"{base_fee + PRIORITY_REDUCTION * 600000}aphoton",
"max_priority_price": 0,
},
{
"from": eth_to_bech32(ADDRS["signer1"]),
"to": eth_to_bech32(ADDRS["signer2"]),
"amount": "1000aphoton",
"gas_prices": f"{base_fee + PRIORITY_REDUCTION * 600000}aphoton",
"max_priority_price": PRIORITY_REDUCTION * 200000,
},
{
"from": eth_to_bech32(ADDRS["signer2"]),
"to": eth_to_bech32(ADDRS["signer1"]),
"amount": "1000aphoton",
"gas_prices": f"{base_fee + PRIORITY_REDUCTION * 400000}aphoton",
"max_priority_price": PRIORITY_REDUCTION * 400000,
},
{
"from": eth_to_bech32(ADDRS["validator"]),
"to": eth_to_bech32(ADDRS["community"]),
"amount": "1000aphoton",
"gas_prices": f"{base_fee + PRIORITY_REDUCTION * 600000}aphoton",
"max_priority_price": None, # no extension, maximum tipFeeCap
},
]
txs = []
expect_priorities = []
for tc in test_cases:
tx = cli.transfer(
tc["from"],
tc["to"],
tc["amount"],
gas_prices=tc["gas_prices"],
generate_only=True,
)
txs.append(
cli.sign_tx_json(
tx, tc["from"], max_priority_price=tc.get("max_priority_price")
)
)
gas_price = int(tc["gas_prices"].removesuffix("aphoton"))
expect_priorities.append(
min(
get_max_priority_price(tc.get("max_priority_price")),
gas_price - base_fee,
)
// PRIORITY_REDUCTION
)
assert expect_priorities == [0, 200000, 400000, 600000]

txhashes = []
for tx in txs:
rsp = cli.broadcast_tx_json(tx, broadcast_mode="sync")
assert rsp["code"] == 0, rsp["raw_log"]
txhashes.append(rsp["txhash"])

print("wait for two new blocks, so the sent txs are all included")
wait_for_new_blocks(cli, 2)

tx_results = [cli.tx_search_rpc(f"tx.hash='{txhash}'")[0] for txhash in txhashes]
tx_indexes = [(int(r["height"]), r["index"]) for r in tx_results]
print(tx_indexes)
# the first sent tx are included later, because of lower priority
# ensure desc within continuous block
assert all((
b1 < b2 or (b1 == b2 and i1 > i2)
) for (b1, i1), (b2, i2) in zip(tx_indexes, tx_indexes[1:]))
# The priority mempool feature has been removed from comet bft.

Check failure on line 37 in tests/integration_tests/test_priority.py

View workflow job for this annotation

GitHub Actions / Run flake8 on python integration tests

./tests/integration_tests/test_priority.py:37:64: W291 trailing whitespace
# Tx priority features can be implemented using ABCI++'s app-side mempool.

Check failure on line 38 in tests/integration_tests/test_priority.py

View workflow job for this annotation

GitHub Actions / Run flake8 on python integration tests

./tests/integration_tests/test_priority.py:38:75: W291 trailing whitespace
# Therefore, we are removing the related tests. If tx priority features

Check failure on line 39 in tests/integration_tests/test_priority.py

View workflow job for this annotation

GitHub Actions / Run flake8 on python integration tests

./tests/integration_tests/test_priority.py:39:72: W291 trailing whitespace
# are implemented on the app-side in the future, the tests will need to be restored.

Check failure on line 41 in tests/integration_tests/test_priority.py

View workflow job for this annotation

GitHub Actions / Run flake8 on python integration tests

./tests/integration_tests/test_priority.py:41:1: W293 blank line contains whitespace
# def test_priority(ethermint):
# """
# test priorities of different tx types

# use a relatively large priority number to counter
# the effect of base fee change during the testing.
# """
# w3 = ethermint.w3
# amount = 10000
# base_fee = w3.eth.get_block("latest").baseFeePerGas

# # [ ( sender, tx ), ... ]
# # use different senders to avoid nonce conflicts
# test_cases = [
# (
# "validator",
# {
# "to": "0x0000000000000000000000000000000000000000",
# "value": amount,
# "gas": 21000,
# "maxFeePerGas": base_fee + PRIORITY_REDUCTION * 600000,
# "maxPriorityFeePerGas": 0,
# },
# ),
# (
# "community",
# {
# "to": "0x0000000000000000000000000000000000000000",
# "value": amount,
# "gas": 21000,
# "gasPrice": base_fee + PRIORITY_REDUCTION * 200000,
# },
# ),
# (
# "signer2",
# {
# "to": "0x0000000000000000000000000000000000000000",
# "value": amount,
# "gasPrice": base_fee + PRIORITY_REDUCTION * 400000,
# "accessList": [
# {
# "address": "0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae",
# "storageKeys": (
# "0x00000000000000000000000000000000000000000000000000000000"
# "00000003",
# "0x00000000000000000000000000000000000000000000000000000000"
# "00000007",
# ),
# }
# ],
# },
# ),
# (
# "signer1",
# {
# "to": "0x0000000000000000000000000000000000000000",
# "value": amount,
# "gas": 21000,
# "maxFeePerGas": base_fee + PRIORITY_REDUCTION * 600000,
# "maxPriorityFeePerGas": PRIORITY_REDUCTION * 600000,
# },
# ),
# ]

# # test cases are ordered by priority
# expect_priorities = [tx_priority(tx, base_fee) for _, tx in test_cases]
# assert expect_priorities == [0, 200000, 400000, 600000]

# signed = [sign_transaction(w3, tx, key=KEYS[sender]) for sender, tx in test_cases]
# # send the txs from low priority to high,
# # but the later sent txs should be included earlier.
# txhashes = [w3.eth.send_raw_transaction(tx.rawTransaction) for tx in signed]

# receipts = [w3.eth.wait_for_transaction_receipt(txhash) for txhash in txhashes]
# print(receipts)
# assert all(receipt.status == 1 for receipt in receipts), "expect all txs success"

# # the later txs should be included earlier because of higher priority
# # FIXME there's some non-deterministics due to mempool logic
# tx_indexes = [(r.blockNumber, r.transactionIndex) for r in receipts]
# print(tx_indexes)
# # the first sent tx are included later, because of lower priority
# assert all(i1 > i2 for i1, i2 in zip(tx_indexes, tx_indexes[1:]))


# def test_native_tx_priority(ethermint):
# cli = ethermint.cosmos_cli()
# base_fee = cli.query_base_fee()
# print("base_fee", base_fee)
# test_cases = [
# {
# "from": eth_to_bech32(ADDRS["community"]),
# "to": eth_to_bech32(ADDRS["validator"]),
# "amount": "1000aphoton",
# "gas_prices": f"{base_fee + PRIORITY_REDUCTION * 600000}aphoton",
# "max_priority_price": 0,
# },
# {
# "from": eth_to_bech32(ADDRS["signer1"]),
# "to": eth_to_bech32(ADDRS["signer2"]),
# "amount": "1000aphoton",
# "gas_prices": f"{base_fee + PRIORITY_REDUCTION * 600000}aphoton",
# "max_priority_price": PRIORITY_REDUCTION * 200000,
# },
# {
# "from": eth_to_bech32(ADDRS["signer2"]),
# "to": eth_to_bech32(ADDRS["signer1"]),
# "amount": "1000aphoton",
# "gas_prices": f"{base_fee + PRIORITY_REDUCTION * 400000}aphoton",
# "max_priority_price": PRIORITY_REDUCTION * 400000,
# },
# {
# "from": eth_to_bech32(ADDRS["validator"]),
# "to": eth_to_bech32(ADDRS["community"]),
# "amount": "1000aphoton",
# "gas_prices": f"{base_fee + PRIORITY_REDUCTION * 600000}aphoton",
# "max_priority_price": None, # no extension, maximum tipFeeCap
# },
# ]
# txs = []
# expect_priorities = []
# for tc in test_cases:
# tx = cli.transfer(
# tc["from"],
# tc["to"],
# tc["amount"],
# gas_prices=tc["gas_prices"],
# generate_only=True,
# )
# txs.append(
# cli.sign_tx_json(
# tx, tc["from"], max_priority_price=tc.get("max_priority_price")
# )
# )
# gas_price = int(tc["gas_prices"].removesuffix("aphoton"))
# expect_priorities.append(
# min(
# get_max_priority_price(tc.get("max_priority_price")),
# gas_price - base_fee,
# )
# // PRIORITY_REDUCTION
# )
# assert expect_priorities == [0, 200000, 400000, 600000]

# txhashes = []
# for tx in txs:
# rsp = cli.broadcast_tx_json(tx, broadcast_mode="sync")
# assert rsp["code"] == 0, rsp["raw_log"]
# txhashes.append(rsp["txhash"])

# print("wait for two new blocks, so the sent txs are all included")
# wait_for_new_blocks(cli, 2)

# tx_results = [cli.tx_search_rpc(f"tx.hash='{txhash}'")[0] for txhash in txhashes]
# tx_indexes = [(int(r["height"]), r["index"]) for r in tx_results]
# print(tx_indexes)
# # the first sent tx are included later, because of lower priority
# # ensure desc within continuous block
# assert all((
# b1 < b2 or (b1 == b2 and i1 > i2)
# ) for (b1, i1), (b2, i2) in zip(tx_indexes, tx_indexes[1:]))


def get_max_priority_price(max_priority_price):
Expand Down

0 comments on commit d0facf3

Please sign in to comment.