|
14 | 14 | EXPECTED_STRUCT_TRACER, |
15 | 15 | ) |
16 | 16 | from .utils import ( |
| 17 | + ACCOUNTS, |
17 | 18 | ADDRS, |
18 | 19 | CONTRACTS, |
19 | 20 | create_contract_transaction, |
@@ -754,3 +755,100 @@ def process(w3): |
754 | 755 | assert isinstance(res[0], exceptions.ContractLogicError) |
755 | 756 | assert isinstance(res[-1], exceptions.ContractLogicError) |
756 | 757 | assert str(res[0]) == str(res[-1]) == "('execution reverted', '0x')" |
| 758 | + |
| 759 | + |
| 760 | +def test_4byte_tracer_intrinsic_gas_too_low(ethermint, geth): |
| 761 | + method = "debug_traceCall" |
| 762 | + tracer = {"tracer": "4byteTracer"} |
| 763 | + acc = derive_new_account(6) |
| 764 | + |
| 765 | + tx = { |
| 766 | + "from": ACCOUNTS["community"].address, |
| 767 | + "to": acc.address, |
| 768 | + "gas": "0x4e29", |
| 769 | + } |
| 770 | + |
| 771 | + def process(w3): |
| 772 | + tx_res = w3.provider.make_request(method, [tx, "latest", tracer]) |
| 773 | + return json.dumps(tx_res["error"], sort_keys=True) |
| 774 | + |
| 775 | + providers = [ethermint.w3, geth.w3] |
| 776 | + with ThreadPoolExecutor(len(providers)) as exec: |
| 777 | + tasks = [exec.submit(process, w3) for w3 in providers] |
| 778 | + res = [future.result() for future in as_completed(tasks)] |
| 779 | + assert len(res) == len(providers) |
| 780 | + res = [json.loads(r) for r in res] |
| 781 | + assert res[0]["code"] == res[-1]["code"] == -32000 |
| 782 | + assert "intrinsic gas too low" in res[0]["message"] |
| 783 | + assert "intrinsic gas too low" in res[-1]["message"] |
| 784 | + |
| 785 | + |
| 786 | +def test_4byte_tracer_success(ethermint, geth): |
| 787 | + method = "debug_traceCall" |
| 788 | + tracer = {"tracer": "4byteTracer"} |
| 789 | + acc = derive_new_account(6) |
| 790 | + |
| 791 | + tx = { |
| 792 | + "from": ACCOUNTS["community"].address, |
| 793 | + "to": acc.address, |
| 794 | + "gas": hex(21000), |
| 795 | + } |
| 796 | + |
| 797 | + def process(w3): |
| 798 | + tx_res = w3.provider.make_request(method, [tx, "latest", tracer]) |
| 799 | + return json.dumps(tx_res["result"], sort_keys=True) |
| 800 | + |
| 801 | + providers = [ethermint.w3, geth.w3] |
| 802 | + with ThreadPoolExecutor(len(providers)) as exec: |
| 803 | + tasks = [exec.submit(process, w3) for w3 in providers] |
| 804 | + res = [future.result() for future in as_completed(tasks)] |
| 805 | + assert len(res) == len(providers) |
| 806 | + assert res[0] == res[-1] |
| 807 | + |
| 808 | + |
| 809 | +def test_prestate_tracer_block_miner_address(ethermint, geth): |
| 810 | + """ |
| 811 | + prestateTracer on a tx will include the block miner address |
| 812 | + """ |
| 813 | + acc = ACCOUNTS["community"] |
| 814 | + receiver = derive_new_account(12) |
| 815 | + |
| 816 | + def process(w3): |
| 817 | + assert ( |
| 818 | + w3.eth.get_balance(receiver.address) == 0 |
| 819 | + ), "receiver balance need to be 0" |
| 820 | + tx = { |
| 821 | + "from": acc.address, |
| 822 | + "to": receiver.address, |
| 823 | + "value": 1, |
| 824 | + } |
| 825 | + receipt = send_transaction(w3, tx, key=acc.key) |
| 826 | + tx_hash = Web3.to_hex(receipt["transactionHash"]) |
| 827 | + tracer = {"tracer": "prestateTracer"} |
| 828 | + tx_res = w3.provider.make_request("debug_traceTransaction", [tx_hash, tracer]) |
| 829 | + latest_block = w3.eth.get_block(receipt.blockNumber) |
| 830 | + block_miner = latest_block.miner |
| 831 | + return [json.dumps(tx_res["result"], sort_keys=True), block_miner] |
| 832 | + |
| 833 | + providers = [ethermint.w3, geth.w3] |
| 834 | + with ThreadPoolExecutor(len(providers)) as exec: |
| 835 | + tasks = [exec.submit(process, w3) for w3 in providers] |
| 836 | + res = [future.result() for future in as_completed(tasks)] |
| 837 | + miner_lhs = res[0][1].lower() |
| 838 | + miner_rhs = res[1][1].lower() |
| 839 | + assert len(res) == len(providers) |
| 840 | + |
| 841 | + from_addr = acc.address.lower() |
| 842 | + to_addr = receiver.address.lower() |
| 843 | + |
| 844 | + lhs = json.loads(res[0][0]) |
| 845 | + rhs = json.loads(res[1][0]) |
| 846 | + |
| 847 | + assert len(lhs) == len(rhs) == 3, (lhs, rhs) |
| 848 | + |
| 849 | + assert lhs[from_addr] is not None |
| 850 | + assert lhs[to_addr] is not None |
| 851 | + assert rhs[from_addr] is not None |
| 852 | + assert rhs[to_addr] is not None |
| 853 | + assert lhs[miner_lhs] is not None |
| 854 | + assert rhs[miner_rhs] is not None |
0 commit comments