|
| 1 | +# mypy: disable-error-code=misc |
| 2 | +import pytest |
| 3 | +from msgspec.json import Decoder |
| 4 | +from pytest_codspeed import BenchmarkFixture |
| 5 | + |
| 6 | +from benchmarks.batch import batch |
| 7 | +from benchmarks.data import ( |
| 8 | + RAW_EIP1559_TX, |
| 9 | + RAW_LEGACY_TX, |
| 10 | + RAW_LOG, |
| 11 | + RAW_RECEIPT, |
| 12 | + RAW_TX_LIST, |
| 13 | +) |
| 14 | +from evmspec.data import _decode_hook |
| 15 | +from evmspec.structs.log import Log |
| 16 | +from evmspec.structs.receipt import TransactionReceipt |
| 17 | +from evmspec.structs.transaction import Transaction, Transaction1559, TransactionLegacy |
| 18 | + |
| 19 | +_decode_legacy_tx = Decoder(type=TransactionLegacy, dec_hook=_decode_hook).decode |
| 20 | +_decode_1559_tx = Decoder(type=Transaction1559, dec_hook=_decode_hook).decode |
| 21 | +_decode_transactions = Decoder(type=tuple[Transaction, ...], dec_hook=_decode_hook).decode |
| 22 | +_decode_receipt = Decoder(type=TransactionReceipt, dec_hook=_decode_hook).decode |
| 23 | +_decode_log = Decoder(type=Log, dec_hook=_decode_hook).decode |
| 24 | + |
| 25 | + |
| 26 | +def _decode_1559_access_list(raw: bytes) -> None: |
| 27 | + tx = _decode_1559_tx(raw) |
| 28 | + tx.accessList |
| 29 | + |
| 30 | + |
| 31 | +def _decode_receipt_logs(raw: bytes) -> None: |
| 32 | + receipt = _decode_receipt(raw) |
| 33 | + receipt.logs |
| 34 | + |
| 35 | + |
| 36 | +@pytest.mark.benchmark(group="decode_tx_legacy") |
| 37 | +def test_decode_tx_legacy(benchmark: BenchmarkFixture) -> None: |
| 38 | + benchmark(batch, 100, _decode_legacy_tx, RAW_LEGACY_TX) |
| 39 | + |
| 40 | + |
| 41 | +@pytest.mark.benchmark(group="decode_tx_1559") |
| 42 | +def test_decode_tx_1559(benchmark: BenchmarkFixture) -> None: |
| 43 | + benchmark(batch, 100, _decode_1559_tx, RAW_EIP1559_TX) |
| 44 | + |
| 45 | + |
| 46 | +@pytest.mark.benchmark(group="decode_tx_list") |
| 47 | +def test_decode_tx_list(benchmark: BenchmarkFixture) -> None: |
| 48 | + benchmark(batch, 50, _decode_transactions, RAW_TX_LIST) |
| 49 | + |
| 50 | + |
| 51 | +@pytest.mark.benchmark(group="decode_tx_access_list") |
| 52 | +def test_decode_tx_access_list(benchmark: BenchmarkFixture) -> None: |
| 53 | + benchmark(batch, 50, _decode_1559_access_list, RAW_EIP1559_TX) |
| 54 | + |
| 55 | + |
| 56 | +@pytest.mark.benchmark(group="decode_log") |
| 57 | +def test_decode_log(benchmark: BenchmarkFixture) -> None: |
| 58 | + benchmark(batch, 200, _decode_log, RAW_LOG) |
| 59 | + |
| 60 | + |
| 61 | +@pytest.mark.benchmark(group="decode_receipt_logs") |
| 62 | +def test_decode_receipt_logs(benchmark: BenchmarkFixture) -> None: |
| 63 | + benchmark(batch, 50, _decode_receipt_logs, RAW_RECEIPT) |
0 commit comments