Skip to content

asyncify get_storage_at #2350

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 23, 2022
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 docs/providers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@ Eth
- :meth:`web3.eth.get_transaction() <web3.eth.Eth.get_transaction>`
- :meth:`web3.eth.get_transaction_count() <web3.eth.Eth.get_transaction_count>`
- :meth:`web3.eth.get_transaction_receipt() <web3.eth.Eth.get_transaction_receipt>`
- :meth:`web3.eth.get_storage_at() <web3.eth.Eth.get_storage_at>`
- :meth:`web3.eth.send_transaction() <web3.eth.Eth.send_transaction>`
- :meth:`web3.eth.send_raw_transaction() <web3.eth.Eth.send_raw_transaction>`
- :meth:`web3.eth.wait_for_transaction_receipt() <web3.eth.Eth.wait_for_transaction_receipt>`
Expand Down
1 change: 1 addition & 0 deletions newsfragments/2350.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
+ Add async `eth.get_storage_at` method
24 changes: 24 additions & 0 deletions web3/_utils/module_testing/eth_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -1096,6 +1096,30 @@ async def test_async_eth_syncing(self, async_w3: "Web3") -> None:
assert is_integer(sync_dict['currentBlock'])
assert is_integer(sync_dict['highestBlock'])

@pytest.mark.asyncio
async def test_async_eth_get_storage_at(
self, async_w3: "Web3", emitter_contract_address: ChecksumAddress
) -> None:
storage = await async_w3.eth.get_storage_at(emitter_contract_address, 0) # type: ignore
assert isinstance(storage, HexBytes)

@pytest.mark.asyncio
@pytest.mark.xfail
async def test_async_eth_get_storage_at_ens_name(
self, async_w3: "Web3", emitter_contract_address: ChecksumAddress
) -> None:
with ens_addresses(async_w3, {'emitter.eth': emitter_contract_address}):
storage = await async_w3.eth.get_storage_at('emitter.eth', 0) # type: ignore
assert isinstance(storage, HexBytes)

@pytest.mark.asyncio
async def test_async_eth_get_storage_at_invalid_address(self, async_w3: "Web3") -> None:
coinbase = await async_w3.eth.coinbase # type: ignore
with pytest.raises(InvalidAddress):
await async_w3.eth.get_storage_at(
ChecksumAddress(HexAddress(HexStr(coinbase.lower()))),
0) # type: ignore

def test_async_provider_default_account(
self,
async_w3: "Web3",
Expand Down
35 changes: 24 additions & 11 deletions web3/eth.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,16 @@ def block_id_munger(
block_identifier = self.default_block
return (account, block_identifier)

def get_storage_at_munger(
self,
account: Union[Address, ChecksumAddress, ENS],
position: int,
block_identifier: Optional[BlockIdentifier] = None
) -> Tuple[Union[Address, ChecksumAddress, ENS], int, BlockIdentifier]:
if block_identifier is None:
block_identifier = self.default_block
return (account, position, block_identifier)

def call_munger(
self,
transaction: TxParams,
Expand Down Expand Up @@ -519,6 +529,19 @@ async def _wait_for_tx_receipt_with_timeout(
f"after {timeout} seconds"
)

_get_storage_at: Method[Callable[..., Awaitable[HexBytes]]] = Method(
RPC.eth_getStorageAt,
mungers=[BaseEth.get_storage_at_munger],
)

async def get_storage_at(
self,
account: Union[Address, ChecksumAddress, ENS],
position: int,
block_identifier: Optional[BlockIdentifier] = None
) -> HexBytes:
return await self._get_storage_at(account, position, block_identifier)

async def call(
self,
transaction: TxParams,
Expand Down Expand Up @@ -636,19 +659,9 @@ def max_priority_fee(self) -> Wei:
)
return fee_history_priority_fee(self)

def get_storage_at_munger(
self,
account: Union[Address, ChecksumAddress, ENS],
position: int,
block_identifier: Optional[BlockIdentifier] = None
) -> Tuple[Union[Address, ChecksumAddress, ENS], int, BlockIdentifier]:
if block_identifier is None:
block_identifier = self.default_block
return (account, position, block_identifier)

get_storage_at: Method[Callable[..., HexBytes]] = Method(
RPC.eth_getStorageAt,
mungers=[get_storage_at_munger],
mungers=[BaseEth.get_storage_at_munger],
)

def get_proof_munger(
Expand Down