Skip to content

Commit

Permalink
Snakecase solidityKeccak (#2702)
Browse files Browse the repository at this point in the history
* snakecase solidityKeccak

* Add entry to release notes
  • Loading branch information
linda-le1 authored Nov 2, 2022
1 parent ef178cc commit 191a072
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 16 deletions.
2 changes: 1 addition & 1 deletion docs/overview.rst
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ Cryptographic Hashing
---------------------

- :meth:`Web3.keccak() <web3.Web3.keccak>`
- :meth:`Web3.solidityKeccak() <web3.Web3.solidityKeccak>`
- :meth:`Web3.solidity_keccak() <web3.Web3.solidity_keccak>`


web3.eth API
Expand Down
12 changes: 6 additions & 6 deletions docs/web3.main.rst
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ Cryptographic Hashing
>>> Web3.keccak(text='txt')
HexBytes('0xd7278090a36507640ea6b7a0034b69b0d240766fa3f98e3722be93c613b29d2e')
.. py:classmethod:: Web3.solidityKeccak(abi_types, value)
.. py:classmethod:: Web3.solidity_keccak(abi_types, value)
Returns the Keccak-256 as it would be computed by the solidity ``keccak``
function on a *packed* ABI encoding of the ``value`` list contents. The ``abi_types``
Expand All @@ -278,19 +278,19 @@ Cryptographic Hashing

.. code-block:: python
>>> Web3.solidityKeccak(['bool'], [True])
>>> Web3.solidity_keccak(['bool'], [True])
HexBytes("0x5fe7f977e71dba2ea1a68e21057beebb9be2ac30c6410aa38d4f3fbe41dcffd2")
>>> Web3.solidityKeccak(['uint8', 'uint8', 'uint8'], [97, 98, 99])
>>> Web3.solidity_keccak(['uint8', 'uint8', 'uint8'], [97, 98, 99])
HexBytes("0x4e03657aea45a94fc7d47ba826c8d667c0d1e6e33a64a036ec44f58fa12d6c45")
>>> Web3.solidityKeccak(['uint8[]'], [[97, 98, 99]])
>>> Web3.solidity_keccak(['uint8[]'], [[97, 98, 99]])
HexBytes("0x233002c671295529bcc50b76a2ef2b0de2dac2d93945fca745255de1a9e4017e")
>>> Web3.solidityKeccak(['address'], ["0x49EdDD3769c0712032808D86597B84ac5c2F5614"])
>>> Web3.solidity_keccak(['address'], ["0x49EdDD3769c0712032808D86597B84ac5c2F5614"])
HexBytes("0x2ff37b5607484cd4eecf6d13292e22bd6e5401eaffcc07e279583bc742c68882")
>>> Web3.solidityKeccak(['address'], ["ethereumfoundation.eth"])
>>> Web3.solidity_keccak(['address'], ["ethereumfoundation.eth"])
HexBytes("0x913c99ea930c78868f1535d34cd705ab85929b2eaaf70fcd09677ecd6e5d75e9")
Expand Down
1 change: 1 addition & 0 deletions newsfragments/2702.breaking.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Snakecase the solidityKeccak method
16 changes: 8 additions & 8 deletions web3/_utils/module_testing/web3_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def _check_web3_client_version(self, client_version: str) -> NoReturn:
),
),
)
def test_solidityKeccak(
def test_solidity_keccak(
self,
w3: "Web3",
types: Sequence[TypeStr],
Expand All @@ -228,10 +228,10 @@ def test_solidityKeccak(
) -> None:
if isinstance(expected, type) and issubclass(expected, Exception):
with pytest.raises(expected): # type: ignore
w3.solidityKeccak(types, values)
w3.solidity_keccak(types, values)
return

actual = w3.solidityKeccak(types, values)
actual = w3.solidity_keccak(types, values)
assert actual == expected

@pytest.mark.parametrize(
Expand All @@ -253,7 +253,7 @@ def test_solidityKeccak(
),
),
)
def test_solidityKeccak_ens(
def test_solidity_keccak_ens(
self,
w3: "Web3",
types: Sequence[TypeStr],
Expand All @@ -273,10 +273,10 @@ def test_solidityKeccak_ens(
):
# when called as class method, any name lookup attempt will fail
with pytest.raises(InvalidAddress):
Web3.solidityKeccak(types, values)
Web3.solidity_keccak(types, values)

# when called as instance method, ens lookups can succeed
actual = w3.solidityKeccak(types, values)
actual = w3.solidity_keccak(types, values)
assert actual == expected

@pytest.mark.parametrize(
Expand All @@ -287,11 +287,11 @@ def test_solidityKeccak_ens(
([], ["0xA6b759bBbf4B59D24acf7E06e79f3a5D104fdCE5"]),
),
)
def test_solidityKeccak_same_number_of_types_and_values(
def test_solidity_keccak_same_number_of_types_and_values(
self, w3: "Web3", types: Sequence[TypeStr], values: Sequence[Any]
) -> None:
with pytest.raises(ValueError):
w3.solidityKeccak(types, values)
w3.solidity_keccak(types, values)

def test_is_connected(self, w3: "Web3") -> None:
assert w3.is_connected()
2 changes: 1 addition & 1 deletion web3/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ def keccak(
)

@combomethod
def solidityKeccak(cls, abi_types: List[TypeStr], values: List[Any]) -> bytes:
def solidity_keccak(cls, abi_types: List[TypeStr], values: List[Any]) -> bytes:
"""
Executes keccak256 exactly as Solidity does.
Takes list of abi_types as inputs -- `[uint24, int8[], bool]`
Expand Down

0 comments on commit 191a072

Please sign in to comment.