Skip to content

Commit

Permalink
Merge pull request #1915 from tmckenzie51/tiffany/signTypedData-to-sn…
Browse files Browse the repository at this point in the history
…akecase

deprecate signTypedData in favor of sign_typed_data
  • Loading branch information
tmckenzie51 authored Apr 1, 2021
2 parents 5d6c278 + db5bfcf commit 836996f
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 34 deletions.
2 changes: 1 addition & 1 deletion docs/overview.rst
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ API
- :meth:`web3.eth.waitForTransactionReceipt() <web3.eth.Eth.waitForTransactionReceipt>`
- :meth:`web3.eth.get_transaction_receipt() <web3.eth.Eth.get_transaction_receipt>`
- :meth:`web3.eth.sign() <web3.eth.Eth.sign>`
- :meth:`web3.eth.signTypedData() <web3.eth.Eth.signTypedData>`
- :meth:`web3.eth.sign_typed_data() <web3.eth.Eth.sign_typed_data>`
- :meth:`web3.eth.estimateGas() <web3.eth.Eth.estimateGas>`
- :meth:`web3.eth.generateGasPrice() <web3.eth.Eth.generateGasPrice>`
- :meth:`web3.eth.setGasPriceStrategy() <web3.eth.Eth.setGasPriceStrategy>`
Expand Down
6 changes: 5 additions & 1 deletion docs/web3.eth.rst
Original file line number Diff line number Diff line change
Expand Up @@ -902,7 +902,7 @@ The following methods are available on the ``web3.eth`` namespace.
'0x1a8bbe6eab8c72a219385681efefe565afd3accee35f516f8edf5ae82208fbd45a58f9f9116d8d88ba40fcd29076d6eada7027a3b412a9db55a0164547810cc401'
.. py:method:: Eth.signTypedData(account, jsonMessage)
.. py:method:: Eth.sign_typed_data(account, jsonMessage)
* Delegates to ``eth_signTypedData`` RPC Method

Expand All @@ -914,6 +914,10 @@ The following methods are available on the ``web3.eth`` namespace.

``account`` may be a checksum address or an ENS name

.. py:method:: Eth.signTypedData(account, jsonMessage)
.. warning:: Deprecated: This property is deprecated in favor of
:meth:`~web3.eth.Eth.sign_typed_data()`

.. py:method:: Eth.call(transaction, block_identifier=web3.eth.default_block)
Expand Down
1 change: 1 addition & 0 deletions newsfragments/1915.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add ``w3.eth.sign_typed_data`` deprecate ``w3.eth.signTypedData``
20 changes: 8 additions & 12 deletions tests/integration/go_ethereum/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,16 @@ def test_eth_replace_transaction_already_mined(self, web3, unlocked_account_dual
web3.geth.miner.stop()

@pytest.mark.xfail(reason='eth_signTypedData has not been released in geth')
def test_eth_signTypedData(self,
web3,
unlocked_account_dual_type):
super().test_eth_signTypedData(
web3, unlocked_account_dual_type
)
def test_eth_sign_typed_data(self, web3, unlocked_account_dual_type):
super().test_eth_sign_typed_data(web3, unlocked_account_dual_type)

@pytest.mark.xfail(reason='eth_signTypedData has not been released in geth')
def test_invalid_eth_signTypedData(self,
web3,
unlocked_account_dual_type):
super().test_invalid_eth_signTypedData(
web3, unlocked_account_dual_type
)
def test_eth_signTypedData_deprecated(self, web3, unlocked_account_dual_type):
super().test_eth_signTypedData_deprecated(web3, unlocked_account_dual_type)

@pytest.mark.xfail(reason='eth_signTypedData has not been released in geth')
def test_invalid_eth_sign_typed_data(self, web3, unlocked_account_dual_type):
super().test_invalid_eth_sign_typed_data(web3, unlocked_account_dual_type)

@pytest.mark.xfail(reason='eth_protocolVersion was removed in Geth 1.10.0')
def test_eth_protocol_version(self, web3):
Expand Down
16 changes: 4 additions & 12 deletions tests/integration/parity/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,20 +151,12 @@ def test_eth_get_logs_without_logs(self, web3, block_with_txn_with_log):
assert len(result) == 0

@pytest.mark.xfail(reason='eth_signTypedData has not been released in Parity')
def test_eth_signTypedData(self,
web3,
unlocked_account_dual_type):
super().test_eth_signTypedData(
web3, unlocked_account_dual_type
)
def test_eth_sign_typed_data(self, web3, unlocked_account_dual_type):
super().test_eth_sign_typed_data(web3, unlocked_account_dual_type)

@pytest.mark.xfail(reason='eth_signTypedData has not been released in Parity')
def test_invalid_eth_signTypedData(self,
web3,
unlocked_account_dual_type):
super().test_invalid_eth_signTypedData(
web3, unlocked_account_dual_type
)
def test_invalid_eth_sign_typed_data(self, web3, unlocked_account_dual_type):
super().test_invalid_eth_sign_typed_data(web3, unlocked_account_dual_type)


class ParityTraceModuleTest(ParityTraceModuleTest):
Expand Down
9 changes: 8 additions & 1 deletion tests/integration/test_ethereum_tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,14 @@ class TestEthereumTesterEthModule(EthModuleTest):
test_eth_sign_ens_names = not_implemented(
EthModuleTest.test_eth_sign_ens_names, ValueError
)
test_eth_signTypedData = not_implemented(EthModuleTest.test_eth_signTypedData, ValueError)
test_eth_signTypedData_deprecated = not_implemented(
EthModuleTest.test_eth_signTypedData_deprecated,
ValueError
)
test_eth_sign_typed_data = not_implemented(
EthModuleTest.test_eth_sign_typed_data,
ValueError
)
test_eth_signTransaction_deprecated = not_implemented(
EthModuleTest.test_eth_signTransaction_deprecated,
ValueError
Expand Down
58 changes: 55 additions & 3 deletions web3/_utils/module_testing/eth_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,59 @@ def test_eth_sign_ens_names(
assert is_bytes(signature)
assert len(signature) == 32 + 32 + 1

def test_eth_signTypedData(
def test_eth_sign_typed_data(
self,
web3: "Web3",
unlocked_account_dual_type: ChecksumAddress,
skip_if_testrpc: Callable[["Web3"], None],
) -> None:
validJSONMessage = '''
{
"types": {
"EIP712Domain": [
{"name": "name", "type": "string"},
{"name": "version", "type": "string"},
{"name": "chainId", "type": "uint256"},
{"name": "verifyingContract", "type": "address"}
],
"Person": [
{"name": "name", "type": "string"},
{"name": "wallet", "type": "address"}
],
"Mail": [
{"name": "from", "type": "Person"},
{"name": "to", "type": "Person"},
{"name": "contents", "type": "string"}
]
},
"primaryType": "Mail",
"domain": {
"name": "Ether Mail",
"version": "1",
"chainId": "0x01",
"verifyingContract": "0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC"
},
"message": {
"from": {
"name": "Cow",
"wallet": "0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826"
},
"to": {
"name": "Bob",
"wallet": "0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB"
},
"contents": "Hello, Bob!"
}
}
'''
skip_if_testrpc(web3)
signature = HexBytes(web3.eth.sign_typed_data(
unlocked_account_dual_type,
json.loads(validJSONMessage)
))
assert len(signature) == 32 + 32 + 1

def test_eth_signTypedData_deprecated(
self,
web3: "Web3",
unlocked_account_dual_type: ChecksumAddress,
Expand Down Expand Up @@ -464,7 +516,7 @@ def test_eth_signTypedData(
))
assert len(signature) == 32 + 32 + 1

def test_invalid_eth_signTypedData(
def test_invalid_eth_sign_typed_data(
self,
web3: "Web3",
unlocked_account_dual_type: ChecksumAddress,
Expand Down Expand Up @@ -512,7 +564,7 @@ def test_invalid_eth_signTypedData(
'''
with pytest.raises(ValueError,
match=r".*Expected 2 items for array type Person\[2\], got 1 items.*"):
web3.eth.signTypedData(
web3.eth.sign_typed_data(
unlocked_account_dual_type,
json.loads(invalid_typed_message)
)
Expand Down
6 changes: 3 additions & 3 deletions web3/_utils/module_testing/personal_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ def test_personal_sign_typed_data_deprecated(
}
}
'''
signature = HexBytes(web3.geth.personal.signTypedData(
signature = HexBytes(web3.geth.personal.sign_typed_data(
json.loads(typed_message),
unlockable_account_dual_type,
unlockable_account_pw
Expand Down Expand Up @@ -639,7 +639,7 @@ def test_personal_sign_typed_data_deprecated(
}
}
'''
signature = HexBytes(web3.parity.personal.signTypedData(
signature = HexBytes(web3.parity.personal.sign_typed_data(
json.loads(typed_message),
unlockable_account_dual_type,
unlockable_account_pw
Expand Down Expand Up @@ -755,7 +755,7 @@ def test_invalid_personal_sign_typed_data_deprecated(
with pytest.raises(ValueError,
match=r".*Expected 2 items for array type Person\[2\], got 1 items.*"
):
web3.parity.personal.signTypedData(
web3.parity.personal.sign_typed_data(
json.loads(invalid_typed_message),
unlockable_account_dual_type,
unlockable_account_pw
Expand Down
3 changes: 2 additions & 1 deletion web3/eth.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ def sign_munger(
mungers=[default_root_munger],
)

signTypedData: Method[Callable[..., HexStr]] = Method(
sign_typed_data: Method[Callable[..., HexStr]] = Method(
RPC.eth_signTypedData,
mungers=[default_root_munger],
)
Expand Down Expand Up @@ -689,6 +689,7 @@ def setGasPriceStrategy(self, gas_price_strategy: GasPriceStrategy) -> None:
getUncleCount = DeprecatedMethod(get_uncle_count, 'getUncleCount', 'get_uncle_count')
sendTransaction = DeprecatedMethod(send_transaction, 'sendTransaction', 'send_transaction')
signTransaction = DeprecatedMethod(sign_transaction, 'signTransaction', 'sign_transaction')
signTypedData = DeprecatedMethod(sign_typed_data, 'signTypedData', 'sign_typed_data')
submitHashrate = DeprecatedMethod(submit_hashrate, 'submitHashrate', 'submit_hashrate')
submitWork = DeprecatedMethod(submit_work, 'submitWork', 'submit_work')
getLogs = DeprecatedMethod(get_logs, 'getLogs', 'get_logs')
Expand Down

0 comments on commit 836996f

Please sign in to comment.