Skip to content
Merged
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
1 change: 1 addition & 0 deletions newsfragments/3247.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add support for ``eth_getRawTransactionByHash`` RPC method
36 changes: 20 additions & 16 deletions tests/integration/test_ethereum_tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,26 @@ class TestEthereumTesterEthModule(EthModuleTest):
EthModuleTest.test_eth_call_with_override_code,
TypeError,
)
test_eth_getBlockReceipts_hash = not_implemented(
EthModuleTest.test_eth_getBlockReceipts_hash,
MethodUnavailable,
)
test_eth_getBlockReceipts_not_found = not_implemented(
EthModuleTest.test_eth_getBlockReceipts_not_found,
MethodUnavailable,
)
test_eth_getBlockReceipts_with_integer = not_implemented(
EthModuleTest.test_eth_getBlockReceipts_with_integer,
MethodUnavailable,
)
test_eth_getBlockReceipts_safe = not_implemented(
EthModuleTest.test_eth_getBlockReceipts_safe,
MethodUnavailable,
)
test_eth_getBlockReceipts_finalized = not_implemented(
EthModuleTest.test_eth_getBlockReceipts_finalized,
MethodUnavailable,
)

def test_eth_getBlockByHash_pending(self, w3: "Web3") -> None:
block = w3.eth.get_block("pending")
Expand Down Expand Up @@ -632,27 +652,11 @@ def test_eth_send_transaction_no_gas(self, eth_tester, w3, unlocked_account):
def test_eth_send_transaction_no_max_fee(self, eth_tester, w3, unlocked_account):
super().test_eth_send_transaction_no_max_fee(w3, unlocked_account)

def test_eth_getBlockByNumber_safe(
self, w3: "Web3", empty_block: BlockData
) -> None:
super().test_eth_getBlockByNumber_safe(w3, empty_block)

def test_eth_getBlockByNumber_finalized(
self, w3: "Web3", empty_block: BlockData
) -> None:
super().test_eth_getBlockByNumber_finalized(w3, empty_block)

def test_eth_fee_history(self, w3: "Web3") -> None:
super().test_eth_fee_history(w3)

def test_eth_fee_history_with_integer(
self, w3: "Web3", empty_block: BlockData
) -> None:
super().test_eth_fee_history_with_integer(w3, empty_block)

def test_eth_fee_history_with_no_reward_percentiles(self, w3: "Web3") -> None:
super().test_eth_fee_history_no_reward_percentiles(w3)

def test_eth_get_balance_with_block_identifier(self, w3: "Web3") -> None:
w3.testing.mine()
miner_address = w3.eth.get_block(1)["miner"]
Expand Down
3 changes: 3 additions & 0 deletions web3/_utils/method_formatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,7 @@ def apply_list_to_array_formatter(formatter: Any) -> Callable[..., Any]:
),
RPC.eth_getBalance: apply_formatter_at_index(to_hex_if_integer, 1),
RPC.eth_getBlockByNumber: apply_formatter_at_index(to_hex_if_integer, 0),
RPC.eth_getBlockReceipts: apply_formatter_at_index(to_hex_if_integer, 0),
RPC.eth_getBlockTransactionCountByNumber: apply_formatter_at_index(
to_hex_if_integer,
0,
Expand Down Expand Up @@ -723,6 +724,7 @@ def subscription_formatter(value: Any) -> Union[HexBytes, HexStr, Dict[str, Any]
RPC.eth_getBalance: to_integer_if_hex,
RPC.eth_getBlockByHash: apply_formatter_if(is_not_null, block_formatter),
RPC.eth_getBlockByNumber: apply_formatter_if(is_not_null, block_formatter),
RPC.eth_getBlockReceipts: apply_formatter_to_array(receipt_formatter),
RPC.eth_getBlockTransactionCountByHash: to_integer_if_hex,
RPC.eth_getBlockTransactionCountByNumber: to_integer_if_hex,
RPC.eth_getCode: HexBytes,
Expand Down Expand Up @@ -900,6 +902,7 @@ def raise_transaction_not_found_with_index(
NULL_RESULT_FORMATTERS: Dict[RPCEndpoint, Callable[..., Any]] = {
RPC.eth_getBlockByHash: raise_block_not_found,
RPC.eth_getBlockByNumber: raise_block_not_found,
RPC.eth_getBlockReceipts: raise_block_not_found,
RPC.eth_getBlockTransactionCountByHash: raise_block_not_found,
RPC.eth_getBlockTransactionCountByNumber: raise_block_not_found,
RPC.eth_getUncleCountByBlockHash: raise_block_not_found,
Expand Down
61 changes: 61 additions & 0 deletions web3/_utils/module_testing/eth_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -977,6 +977,39 @@ async def test_eth_getBlockByNumber_finalized(
assert block is not None
assert isinstance(block["number"], int)

@pytest.mark.asyncio
async def test_eth_getBlockReceipts_hash(
self, async_w3: "AsyncWeb3", async_empty_block: BlockData
) -> None:
receipts = await async_w3.eth.get_block_receipts(async_empty_block["hash"])
assert isinstance(receipts, list)

@pytest.mark.asyncio
async def test_eth_getBlockReceipts_not_found(self, async_w3: "AsyncWeb3") -> None:
with pytest.raises(BlockNotFound):
await async_w3.eth.get_block_receipts(UNKNOWN_HASH)

@pytest.mark.asyncio
async def test_eth_getBlockReceipts_with_integer(
self, async_w3: "AsyncWeb3", async_empty_block: BlockData
) -> None:
receipts = await async_w3.eth.get_block_receipts(async_empty_block["number"])
assert isinstance(receipts, list)

@pytest.mark.asyncio
async def test_eth_getBlockReceipts_safe(
self, async_w3: "AsyncWeb3", async_empty_block: BlockData
) -> None:
receipts = await async_w3.eth.get_block_receipts("safe")
assert isinstance(receipts, list)

@pytest.mark.asyncio
async def test_eth_getBlockReceipts_finalized(
self, async_w3: "AsyncWeb3", async_empty_block: BlockData
) -> None:
receipts = await async_w3.eth.get_block_receipts("finalized")
assert isinstance(receipts, list)

@pytest.mark.asyncio
async def test_eth_get_block_by_number_full_transactions(
self, async_w3: "AsyncWeb3", async_block_with_txn: BlockData
Expand Down Expand Up @@ -4224,6 +4257,34 @@ def test_eth_getBlockByNumber_full_transactions(
transaction = block["transactions"][0]
assert transaction["hash"] == block_with_txn["transactions"][0] # type: ignore

def test_eth_getBlockReceipts_hash(
self, w3: "Web3", empty_block: BlockData
) -> None:
receipts = w3.eth.get_block_receipts(empty_block["hash"])
assert isinstance(receipts, list)

def test_eth_getBlockReceipts_not_found(self, w3: "Web3") -> None:
with pytest.raises(BlockNotFound):
w3.eth.get_block_receipts(UNKNOWN_HASH)

def test_eth_getBlockReceipts_with_integer(
self, w3: "Web3", empty_block: BlockData
) -> None:
receipts = w3.eth.get_block_receipts(empty_block["number"])
assert isinstance(receipts, list)

def test_eth_getBlockReceipts_safe(
self, w3: "Web3", empty_block: BlockData
) -> None:
receipts = w3.eth.get_block_receipts("safe")
assert isinstance(receipts, list)

def test_eth_getBlockReceipts_finalized(
self, w3: "Web3", empty_block: BlockData
) -> None:
receipts = w3.eth.get_block_receipts("finalized")
assert isinstance(receipts, list)

def test_eth_getTransactionByHash(self, w3: "Web3", mined_txn_hash: HexStr) -> None:
transaction = w3.eth.get_transaction(mined_txn_hash)
assert is_dict(transaction)
Expand Down
1 change: 1 addition & 0 deletions web3/_utils/rpc_abi.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class RPC:
eth_getBalance = RPCEndpoint("eth_getBalance")
eth_getBlockByHash = RPCEndpoint("eth_getBlockByHash")
eth_getBlockByNumber = RPCEndpoint("eth_getBlockByNumber")
eth_getBlockReceipts = RPCEndpoint("eth_getBlockReceipts")
eth_getBlockTransactionCountByHash = RPCEndpoint(
"eth_getBlockTransactionCountByHash"
)
Expand Down
15 changes: 15 additions & 0 deletions web3/eth/async_eth.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
BlockData,
BlockIdentifier,
BlockParams,
BlockReceipts,
CreateAccessListResponse,
FeeHistory,
FilterParams,
Expand Down Expand Up @@ -440,6 +441,20 @@ async def get_block(
) -> BlockData:
return await self._get_block(block_identifier, full_transactions)

# eth_getBlockReceipts

_get_block_receipts: Method[
Callable[[BlockIdentifier], Awaitable[BlockReceipts]]
] = Method(
RPC.eth_getBlockReceipts,
mungers=[default_root_munger],
)

async def get_block_receipts(
self, block_identifier: BlockIdentifier
) -> BlockReceipts:
return await self._get_block_receipts(block_identifier)

# eth_getBalance

_get_balance: Method[
Expand Down
11 changes: 11 additions & 0 deletions web3/eth/eth.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
BlockData,
BlockIdentifier,
BlockParams,
BlockReceipts,
CreateAccessListResponse,
FeeHistory,
FilterParams,
Expand Down Expand Up @@ -411,6 +412,16 @@ def get_block(
) -> BlockData:
return self._get_block(block_identifier, full_transactions)

# eth_getBlockReceipts

_get_block_receipts: Method[Callable[[BlockIdentifier], BlockReceipts]] = Method(
RPC.eth_getBlockReceipts,
mungers=[default_root_munger],
)

def get_block_receipts(self, block_identifier: BlockIdentifier) -> BlockReceipts:
return self._get_block_receipts(block_identifier)

# eth_getBalance

_get_balance: Method[
Expand Down
2 changes: 2 additions & 0 deletions web3/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,8 @@ class FeeHistory(TypedDict):
},
)

BlockReceipts = List[TxReceipt]


class SignedTx(TypedDict, total=False):
raw: bytes
Expand Down