From 8ccac97109ff9ddc2d5690c6e425cfba562f3d8a Mon Sep 17 00:00:00 2001 From: Pankaj Patil Date: Sun, 25 Aug 2019 21:22:31 +0530 Subject: [PATCH] Implement snake case methods for Geth whisper methods --- docs/web3.geth.rst | 163 +++++++-- newsfragments/1433.feature.rst | 1 + tests/core/shh-module/test_shh_filter.py | 162 ++++++++- tests/core/shh-module/test_shh_key_pair.py | 99 +++-- tests/core/shh-module/test_shh_post.py | 21 +- tests/core/shh-module/test_shh_properties.py | 21 +- tests/integration/go_ethereum/common.py | 10 + .../go_ethereum/test_goethereum_ws.py | 4 + web3/__init__.py | 36 +- web3/_utils/module_testing/__init__.py | 14 +- web3/_utils/module_testing/shh_module.py | 342 ++++++++++++++---- web3/_utils/shh.py | 72 +++- web3/geth.py | 54 ++- web3/middleware/__init__.py | 32 +- web3/parity.py | 34 +- web3/providers/__init__.py | 17 +- web3/providers/eth_tester/defaults.py | 46 ++- web3/tools/__init__.py | 5 +- 18 files changed, 879 insertions(+), 254 deletions(-) create mode 100644 newsfragments/1433.feature.rst diff --git a/docs/web3.geth.rst b/docs/web3.geth.rst index 2a89cc0b57..b2a17b2325 100644 --- a/docs/web3.geth.rst +++ b/docs/web3.geth.rst @@ -525,7 +525,12 @@ Full documentation for Geth-supported endpoints can be found `here >>web3.geth.shh.post({'payload': web3.toHex(text="test_payload"), 'pubKey': recipient_public, 'topic': '0x12340000', 'powTarget': 2.5, 'powTime': 2}) True -.. py:method:: Shh.newMessageFilter(self, criteria) +.. py:method:: Shh.newMessageFilter() + + .. warning:: Deprecated: This method is deprecated in favor of + :meth:`~web3.geth.shh.new_message_filter()` + +.. py:method:: Shh.new_message_filter(self, criteria) * Create a new filter id. This filter id can be used with ``ShhFilter`` to poll for new messages that match the set of criteria. @@ -540,10 +545,16 @@ Full documentation for Geth-supported endpoints can be found `here >>web3.geth.shh.newMessageFilter({'topic': '0x12340000', 'privateKeyID': recipient_private}) + >>>web3.geth.shh.new_message_filter({'topic': '0x12340000', 'privateKeyID': recipient_private}) 'b37c3106cfb683e8f01b5019342399e0d1d74e9160f69b27625faba7a6738554' -.. py:method:: Shh.deleteMessageFilter(self, filter_id) +.. py:method:: Shh.deleteMessageFilter() + + .. warning:: Deprecated: This method is deprecated in favor of + :meth:`~web3.geth.shh.delete_message_filter()` + + +.. py:method:: Shh.delete_message_filter(self, filter_id) * Deletes a message filter in the node. @@ -551,10 +562,15 @@ Full documentation for Geth-supported endpoints can be found `here >>web3.geth.shh.deleteMessageFilter('b37c3106cfb683e8f01b5019342399e0d1d74e9160f69b27625faba7a6738554') + >>>web3.geth.shh.delete_message_filter('b37c3106cfb683e8f01b5019342399e0d1d74e9160f69b27625faba7a6738554') True -.. py:method:: Shh.getMessages(self, filter_id) +.. py:method:: Shh.getMessages() + + .. warning:: Deprecated: This method is deprecated in favor of + :meth:`~web3.geth.shh.get_filter_messages()` + +.. py:method:: Shh.get_filter_messages(self, filter_id) * Retrieve messages that match the filter criteria and are received between the last time this function was called and now. @@ -562,7 +578,7 @@ Full documentation for Geth-supported endpoints can be found `here >>web3.geth.shh.getMessages('b37c3106cfb683e8f01b5019342399e0d1d74e9160f69b27625faba7a6738554') + >>>web3.geth.shh.get_filter_messages('b37c3106cfb683e8f01b5019342399e0d1d74e9160f69b27625faba7a6738554') [{ 'ttl': 50, 'timestamp': 1524497850, @@ -574,7 +590,12 @@ Full documentation for Geth-supported endpoints can be found `here >>web3.geth.shh.setMaxMessageSize(1024) + >>>web3.geth.shh.set_max_message_size(1024) True -.. py:method:: Shh.setMinPoW(self, min_pow) +.. py:method:: Shh.setMinPoW() + + .. warning:: Deprecated: This method is deprecated in favor of + :meth:`~web3.geth.shh.set_min_pow()` + +.. py:method:: Shh.set_min_pow(self, min_pow) * Sets the minimal PoW required by this node. @@ -593,10 +619,15 @@ Full documentation for Geth-supported endpoints can be found `here >>web3.geth.shh.setMinPoW(0.4) + >>>web3.geth.shh.set_min_pow(0.4) True -.. py:method:: Shh.markTrustedPeer(self, enode) +.. py:method:: Shh.markTrustedPeer() + + .. warning:: Deprecated: This method is deprecated in favor of + :meth:`~web3.geth.shh.mark_trusted_peer()` + +.. py:method:: Shh.mark_trusted_peer(self, enode) * Marks specific peer trusted, which will allow it to send historic (expired) messages. @@ -604,14 +635,19 @@ Full documentation for Geth-supported endpoints can be found `here >>web3.geth.shh.markTrustedPeer('enode://d25474361659861e9e651bc728a17e807a3359ca0d344afd544ed0f11a31faecaf4d74b55db53c6670fd624f08d5c79adfc8da5dd4a11b9213db49a3b750845e@52.178.209.125:30379') + >>>web3.geth.shh.mark_trusted_peer('enode://d25474361659861e9e651bc728a17e807a3359ca0d344afd544ed0f11a31faecaf4d74b55db53c6670fd624f08d5c79adfc8da5dd4a11b9213db49a3b750845e@52.178.209.125:30379') True --------------- Asymmetric Keys --------------- -.. py:method:: Shh.newKeyPair(self) +.. py:method:: Shh.newKeyPair() + + .. warning:: Deprecated: This method is deprecated in favor of + :meth:`~web3.geth.shh.new_key_pair()` + +.. py:method:: Shh.new_key_pair(self) * Generates a new cryptographic identity for the client, and injects it into the known identities for message decryption @@ -619,10 +655,15 @@ Asymmetric Keys .. code-block:: python - >>>web3.geth.shh.newKeyPair() + >>>web3.geth.shh.new_key_pair() '86e658cbc6da63120b79b5eec0c67d5dcfb6865a8f983eff08932477282b77bb' -.. py:method:: Shh.addPrivateKey(self, key) +.. py:method:: Shh.addPrivateKey() + + .. warning:: Deprecated: This method is deprecated in favor of + :meth:`~web3.geth.shh.add_private_key()` + +.. py:method:: Shh.add_private_key(self, key) * Stores a key pair derived from a private key, and returns its ID. @@ -630,10 +671,15 @@ Asymmetric Keys .. code-block:: python - >>>web3.geth.shh.addPrivateKey('0x7b8190d96cd061a102e551ee36d08d4f3ca1f56fb0008ef5d70c56271d8c46d0') + >>>web3.geth.shh.add_private_key('0x7b8190d96cd061a102e551ee36d08d4f3ca1f56fb0008ef5d70c56271d8c46d0') '86e658cbc6da63120b79b5eec0c67d5dcfb6865a8f983eff08932477282b77bb' -.. py:method:: Shh.deleteKeyPair(self, id) +.. py:method:: Shh.deleteKeyPair() + + .. warning:: Deprecated: This method is deprecated in favor of + :meth:`~web3.geth.shh.delete_key_pair()` + +.. py:method:: Shh.delete_key_pair(self, id) * Deletes the specified key if it exists. @@ -641,10 +687,15 @@ Asymmetric Keys .. code-block:: python - >>>web3.geth.shh.deleteKeyPair('86e658cbc6da63120b79b5eec0c67d5dcfb6865a8f983eff08932477282b77bb') + >>>web3.geth.shh.delete_key_pair('86e658cbc6da63120b79b5eec0c67d5dcfb6865a8f983eff08932477282b77bb') True -.. py:method:: Shh.hasKeyPair(self, id) +.. py:method:: Shh.hasKeyPair() + + .. warning:: Deprecated: This method is deprecated in favor of + :meth:`~web3.geth.shh.has_key_pair()` + +.. py:method:: Shh.has_key_pair(self, id) * Checks if the whisper node has a private key of a key pair matching the given ID. @@ -652,32 +703,47 @@ Asymmetric Keys .. code-block:: python - >>>web3.geth.shh.hasKeyPair('86e658cbc6da63120b79b5eec0c67d5dcfb6865a8f983eff08932477282b77bb') + >>>web3.geth.shh.has_key_pair('86e658cbc6da63120b79b5eec0c67d5dcfb6865a8f983eff08932477282b77bb') False -.. py:method:: Shh.getPublicKey(self, id) +.. py:method:: Shh.getPublicKey() + + .. warning:: Deprecated: This method is deprecated in favor of + :meth:`~web3.geth.shh.get_public_key()` + +.. py:method:: Shh.get_public_key(self, id) * Returns the public key associated with the key pair. .. code-block:: python - >>>web3.geth.shh.getPublicKey('86e658cbc6da63120b79b5eec0c67d5dcfb6865a8f983eff08932477282b77bb') + >>>web3.geth.shh.get_public_key('86e658cbc6da63120b79b5eec0c67d5dcfb6865a8f983eff08932477282b77bb') '0x041b0777ceb8cf8748fe0bba5e55039d650a03eb0239a909f9ee345bbbad249f2aa236a4b8f41f51bd0a97d87c08e69e67c51f154d634ba51a224195212fc31e4e' -.. py:method:: Shh.getPrivateKey(self, id) +.. py:method:: Shh.getPrivateKey() + + .. warning:: Deprecated: This method is deprecated in favor of + :meth:`~web3.geth.shh.get_private_key()` + +.. py:method:: Shh.get_private_key(self, id) * Returns the private key associated with the key pair. .. code-block:: python - >>>web3.geth.shh.getPrivateKey('86e658cbc6da63120b79b5eec0c67d5dcfb6865a8f983eff08932477282b77bb') + >>>web3.geth.shh.get_private_key('86e658cbc6da63120b79b5eec0c67d5dcfb6865a8f983eff08932477282b77bb') '0x7b8190d96cd061a102e551ee36d08d4f3ca1f56fb0008ef5d70c56271d8c46d0' --------------- Symmetric Keys --------------- -.. py:method:: Shh.newSymKey(self) +.. py:method:: Shh.newSymKey() + + .. warning:: Deprecated: This method is deprecated in favor of + :meth:`~web3.geth.shh.new_sym_key()` + +.. py:method:: Shh.new_sym_key(self) * Generates a random symmetric key and stores it under id, which is then returned. Will be used in the future for session key exchange @@ -685,10 +751,15 @@ Symmetric Keys .. code-block:: python - >>>web3.geth.shh.newSymKey() + >>>web3.geth.shh.new_sym_key() '6c388d63003deb378700c9dad87f67df0247e660647d6ba1d04321bbc2f6ce0c' -.. py:method:: Shh.addSymKey(self, key) +.. py:method:: Shh.addSymKey() + + .. warning:: Deprecated: This method is deprecated in favor of + :meth:`~web3.geth.shh.add_sym_key()` + +.. py:method:: Shh.add_sym_key(self, key) * Stores the key, and returns its ID. @@ -696,10 +767,15 @@ Symmetric Keys .. code-block:: python - >>>web3.geth.shh.addSymKey('0x58f6556e56a0d41b464a083161377c8a9c2e95156921f954f99ef97d41cebaa2') + >>>web3.geth.shh.add_sym_key('0x58f6556e56a0d41b464a083161377c8a9c2e95156921f954f99ef97d41cebaa2') '6c388d63003deb378700c9dad87f67df0247e660647d6ba1d04321bbc2f6ce0c' -.. py:method:: Shh.generateSymKeyFromPassword(self) +.. py:method:: Shh.generateSymKeyFromPassword() + + .. warning:: Deprecated: This method is deprecated in favor of + :meth:`~web3.geth.shh.generate_sym_key_from_password()` + +.. py:method:: Shh.generate_sym_key_from_password(self) * Generates the key from password, stores it, and returns its ID. @@ -707,10 +783,15 @@ Symmetric Keys .. code-block:: python - >>>web3.geth.shh.generateSymKeyFromPassword('shh secret pwd') + >>>web3.geth.shh.generate_sym_key_from_password('shh secret pwd') '6c388d63003deb378700c9dad87f67df0247e660647d6ba1d04321bbc2f6ce0c' -.. py:method:: Shh.hasSymKey(self, id) +.. py:method:: Shh.hasSymKey() + + .. warning:: Deprecated: This method is deprecated in favor of + :meth:`~web3.geth.shh.has_sym_key()` + +.. py:method:: Shh.has_sym_key(self, id) * Checks if there is a symmetric key stored with the given ID. @@ -718,10 +799,15 @@ Symmetric Keys .. code-block:: python - >>>web3.geth.shh.hasSymKey('6c388d63003deb378700c9dad87f67df0247e660647d6ba1d04321bbc2f6ce0c') + >>>web3.geth.shh.has_sym_key('6c388d63003deb378700c9dad87f67df0247e660647d6ba1d04321bbc2f6ce0c') False -.. py:method:: Shh.getSymKey(self, id) +.. py:method:: Shh.getSymKey() + + .. warning:: Deprecated: This method is deprecated in favor of + :meth:`~web3.geth.shh.get_sym_key()` + +.. py:method:: Shh.get_sym_key(self, id) * Returns the symmetric key associated with the given ID. @@ -729,10 +815,15 @@ Symmetric Keys .. code-block:: python - >>>web3.geth.shh.getSymKey('6c388d63003deb378700c9dad87f67df0247e660647d6ba1d04321bbc2f6ce0c') + >>>web3.geth.shh.get_sym_key('6c388d63003deb378700c9dad87f67df0247e660647d6ba1d04321bbc2f6ce0c') '0x58f6556e56a0d41b464a083161377c8a9c2e95156921f954f99ef97d41cebaa2' -.. py:method:: Shh.deleteSymKey(self, id) +.. py:method:: Shh.deleteSymKey() + + .. warning:: Deprecated: This method is deprecated in favor of + :meth:`~web3.geth.shh.delete_sym_key()` + +.. py:method:: Shh.delete_sym_key(self, id) * Deletes the symmetric key associated with the given ID. @@ -740,5 +831,5 @@ Symmetric Keys .. code-block:: python - >>>web3.geth.shh.deleteSymKey('6c388d63003deb378700c9dad87f67df0247e660647d6ba1d04321bbc2f6ce0c') + >>>web3.geth.shh.delete_sym_key('6c388d63003deb378700c9dad87f67df0247e660647d6ba1d04321bbc2f6ce0c') True diff --git a/newsfragments/1433.feature.rst b/newsfragments/1433.feature.rst new file mode 100644 index 0000000000..df9bca1001 --- /dev/null +++ b/newsfragments/1433.feature.rst @@ -0,0 +1 @@ +Move Geth Whisper methods to snake case and deprecate camel case methods diff --git a/tests/core/shh-module/test_shh_filter.py b/tests/core/shh-module/test_shh_filter.py index c44a576d2b..0071e2ff1f 100644 --- a/tests/core/shh-module/test_shh_filter.py +++ b/tests/core/shh-module/test_shh_filter.py @@ -1,3 +1,4 @@ +import pytest import time from hexbytes import ( @@ -5,19 +6,66 @@ ) +def test_shh_sync_filter_deprecated(web3, skip_if_testrpc): + skip_if_testrpc(web3) + + with pytest.warns(DeprecationWarning): + sender = web3.shh.newKeyPair() + sender_pub = web3.shh.getPublicKey(sender) + + receiver = web3.shh.newKeyPair() + receiver_pub = web3.shh.getPublicKey(receiver) + + topic = '0x13370000' + payloads = [web3.toHex(text="test message :)"), web3.toHex(text="2nd test message")] + + shh_filter = web3.shh.newMessageFilter({ + 'privateKeyID': receiver, + 'sig': sender_pub, + 'topics': [topic] + }) + + web3.shh.post({ + 'sig': sender, + 'powTarget': 2.5, + 'powTime': 2, + 'payload': payloads[0], + 'pubKey': receiver_pub + }) + time.sleep(1) + + web3.shh.post({ + 'sig': sender, + 'powTarget': 2.5, + 'powTime': 2, + 'payload': payloads[1], + 'topic': topic, + 'pubKey': receiver_pub + }) + time.sleep(1) + + received_messages = shh_filter.get_new_entries() + assert len(received_messages) == 1 + + message = received_messages[0] + + assert message["payload"] == HexBytes(payloads[1]) + assert message["topic"] == HexBytes(topic) + + def test_shh_sync_filter(web3, skip_if_testrpc): skip_if_testrpc(web3) - sender = web3.shh.newKeyPair() - sender_pub = web3.shh.getPublicKey(sender) + sender = web3.shh.new_key_pair() + sender_pub = web3.shh.get_public_key(sender) - receiver = web3.shh.newKeyPair() - receiver_pub = web3.shh.getPublicKey(receiver) + receiver = web3.shh.new_key_pair() + receiver_pub = web3.shh.get_public_key(receiver) topic = '0x13370000' payloads = [web3.toHex(text="test message :)"), web3.toHex(text="2nd test message")] - shh_filter = web3.shh.newMessageFilter({ + shh_filter = web3.shh.new_message_filter({ 'privateKeyID': receiver, 'sig': sender_pub, 'topics': [topic] @@ -51,20 +99,73 @@ def test_shh_sync_filter(web3, skip_if_testrpc): assert message["topic"] == HexBytes(topic) +def test_shh_async_filter_deprecated(web3, skip_if_testrpc): + skip_if_testrpc(web3) + received_messages = [] + + with pytest.warns(DeprecationWarning) as warnings: + sender = web3.shh.newKeyPair() + sender_pub = web3.shh.getPublicKey(sender) + + receiver = web3.shh.newKeyPair() + receiver_pub = web3.shh.getPublicKey(receiver) + + topic = '0x13370000' + payloads = [web3.toHex(text="test message :)"), web3.toHex(text="2nd test message")] + + shh_filter = web3.shh.newMessageFilter({ + 'privateKeyID': receiver, + 'sig': sender_pub, + 'topics': [topic] + }, poll_interval=0.5) + watcher = shh_filter.watch(received_messages.extend) + + web3.shh.post({ + 'sig': sender, + 'powTarget': 2.5, + 'powTime': 2, + 'payload': payloads[0], + 'topic': topic, + 'pubKey': receiver_pub + }) + time.sleep(1) + + web3.shh.post({ + 'sig': sender, + 'powTarget': 2.5, + 'powTime': 2, + 'payload': payloads[1], + 'pubKey': receiver_pub + }) + time.sleep(1) + + assert len(received_messages) == 1 + + message = received_messages[0] + + assert message["payload"] == HexBytes(payloads[0]) + assert message["topic"] == HexBytes(topic) + + assert len(warnings) == 5 + + watcher.stop() + + def test_shh_async_filter(web3, skip_if_testrpc): skip_if_testrpc(web3) + received_messages = [] - sender = web3.shh.newKeyPair() - sender_pub = web3.shh.getPublicKey(sender) + sender = web3.shh.new_key_pair() + sender_pub = web3.shh.get_public_key(sender) - receiver = web3.shh.newKeyPair() - receiver_pub = web3.shh.getPublicKey(receiver) + receiver = web3.shh.new_key_pair() + receiver_pub = web3.shh.get_public_key(receiver) topic = '0x13370000' payloads = [web3.toHex(text="test message :)"), web3.toHex(text="2nd test message")] - shh_filter = web3.shh.newMessageFilter({ + shh_filter = web3.shh.new_message_filter({ 'privateKeyID': receiver, 'sig': sender_pub, 'topics': [topic] @@ -100,14 +201,45 @@ def test_shh_async_filter(web3, skip_if_testrpc): watcher.stop() +def test_shh_remove_filter_deprecated(web3, skip_if_testrpc): + skip_if_testrpc(web3) + + with pytest.warns(DeprecationWarning): + + receiver = web3.shh.newKeyPair() + receiver_pub = web3.shh.getPublicKey(receiver) + + payload = web3.toHex(text="test message :)") + shh_filter = web3.shh.newMessageFilter({'privateKeyID': receiver}) + + web3.shh.post({ + 'powTarget': 2.5, + 'powTime': 2, + 'payload': payload, + 'pubKey': receiver_pub + }) + time.sleep(1) + + message = shh_filter.get_new_entries()[0] + assert message["payload"] == HexBytes(payload) + + assert web3.shh.deleteMessageFilter(shh_filter.filter_id) + + try: + web3.shh.getMessages(shh_filter.filter_id) + assert False + except: + assert True + + def test_shh_remove_filter(web3, skip_if_testrpc): skip_if_testrpc(web3) - receiver = web3.shh.newKeyPair() - receiver_pub = web3.shh.getPublicKey(receiver) + receiver = web3.shh.new_key_pair() + receiver_pub = web3.shh.get_public_key(receiver) payload = web3.toHex(text="test message :)") - shh_filter = web3.shh.newMessageFilter({'privateKeyID': receiver}) + shh_filter = web3.shh.new_message_filter({'privateKeyID': receiver}) web3.shh.post({ 'powTarget': 2.5, @@ -120,10 +252,10 @@ def test_shh_remove_filter(web3, skip_if_testrpc): message = shh_filter.get_new_entries()[0] assert message["payload"] == HexBytes(payload) - assert web3.shh.deleteMessageFilter(shh_filter.filter_id) + assert web3.shh.delete_message_filter(shh_filter.filter_id) try: - web3.shh.getMessages(shh_filter.filter_id) + web3.shh.get_messages(shh_filter.filter_id) assert False except: assert True diff --git a/tests/core/shh-module/test_shh_key_pair.py b/tests/core/shh-module/test_shh_key_pair.py index f82b1519f0..d201e4d5fd 100644 --- a/tests/core/shh-module/test_shh_key_pair.py +++ b/tests/core/shh-module/test_shh_key_pair.py @@ -1,45 +1,102 @@ +import pytest + + +def test_shh_asymmetric_key_pair_deprecated(web3, skip_if_testrpc): + skip_if_testrpc(web3) + + # Test generating key + with pytest.warns(DeprecationWarning) as warnings: + key_id = web3.shh.newKeyPair() + assert web3.shh.haskeyPair(key_id) + assert len(web3.shh.getPublicKey(key_id)) == 132 + private_key = web3.shh.getPrivateKey(key_id) + assert len(private_key) == 66 + assert web3.shh.deleteKeyPair(key_id) + + # Test adding a key + assert not web3.shh.hasKeyPair(key_id) + + key_id = web3.shh.addPrivateKey(private_key) + assert web3.shh.hasKeyPair(key_id) + assert web3.shh.deleteKeyPair(key_id) + + assert len(warnings) == 9 + + def test_shh_asymmetric_key_pair(web3, skip_if_testrpc): skip_if_testrpc(web3) # Test generating key - key_id = web3.shh.newKeyPair() - assert web3.shh.hasKeyPair(key_id) - assert len(web3.shh.getPublicKey(key_id)) == 132 - private_key = web3.shh.getPrivateKey(key_id) + key_id = web3.shh.new_key_pair() + assert web3.shh.has_key_pair(key_id) + assert len(web3.shh.get_public_key(key_id)) == 132 + private_key = web3.shh.get_private_key(key_id) assert len(private_key) == 66 - assert web3.shh.deleteKeyPair(key_id) + assert web3.shh.delete_key_pair(key_id) # Test adding a key - assert not web3.shh.hasKeyPair(key_id) - key_id = web3.shh.addPrivateKey(private_key) - assert web3.shh.hasKeyPair(key_id) - assert web3.shh.deleteKeyPair(key_id) + assert not web3.shh.has_key_pair(key_id) + + key_id = web3.shh.add_private_key(private_key) + assert web3.shh.has_key_pair(key_id) + assert web3.shh.delete_key_pair(key_id) + + +def test_shh_symmetric_key_pair_deprecated(web3, skip_if_testrpc): + skip_if_testrpc(web3) + + # Test generating key + with pytest.warns(DeprecationWarning) as warnings: + key_id = web3.shh.newSymKey() + assert web3.shh.hasSymKey(key_id) + key = web3.shh.getSymKey(key_id) + assert len(key) == 66 + assert web3.shh.deleteSymKey(key_id) + + # Test adding a key + assert not web3.shh.hasSymKey(key_id) + key_id = web3.shh.addSymKey(key) + assert web3.shh.hasSymKey(key_id) + assert web3.shh.deleteSymKey(key_id) + + assert len(warnings) == 8 def test_shh_symmetric_key_pair(web3, skip_if_testrpc): skip_if_testrpc(web3) # Test generating key - key_id = web3.shh.newSymKey() - assert web3.shh.hasSymKey(key_id) - key = web3.shh.getSymKey(key_id) + key_id = web3.shh.new_sym_key() + assert web3.shh.has_sym_key(key_id) + key = web3.shh.get_sym_key(key_id) assert len(key) == 66 - assert web3.shh.deleteSymKey(key_id) + assert web3.shh.delete_sym_key(key_id) # Test adding a key - assert not web3.shh.hasSymKey(key_id) - key_id = web3.shh.addSymKey(key) - assert web3.shh.hasSymKey(key_id) - assert web3.shh.deleteSymKey(key_id) + assert not web3.shh.has_sym_key(key_id) + key_id = web3.shh.add_sym_key(key) + assert web3.shh.has_sym_key(key_id) + assert web3.shh.delete_sym_key(key_id) + + +def test_shh_symmetric_key_pair_from_password_deprecated(web3, skip_if_testrpc): + skip_if_testrpc(web3) + + with pytest.warns(DeprecationWarning): + key_id = web3.shh.generate_sym_key_from_password('shh be quiet') + + assert web3.shh.hasSymKey(key_id) + assert len(web3.shh.getSymKey(key_id)) == 66 + assert web3.shh.deleteSymKey(key_id) def test_shh_symmetric_key_pair_from_password(web3, skip_if_testrpc): skip_if_testrpc(web3) - key_id = web3.shh.generateSymKeyFromPassword('shh be quiet') + key_id = web3.shh.generate_sym_key_from_password('shh be quiet') - assert web3.shh.hasSymKey(key_id) - assert len(web3.shh.getSymKey(key_id)) == 66 - assert web3.shh.deleteSymKey(key_id) + assert web3.shh.has_sym_key(key_id) + assert len(web3.shh.get_sym_key(key_id)) == 66 + assert web3.shh.delete_sym_key(key_id) diff --git a/tests/core/shh-module/test_shh_post.py b/tests/core/shh-module/test_shh_post.py index ff69eb0c63..be334f7d6d 100644 --- a/tests/core/shh-module/test_shh_post.py +++ b/tests/core/shh-module/test_shh_post.py @@ -1,6 +1,25 @@ +import pytest + + +def test_shh_post_deprecated(web3, skip_if_testrpc): + skip_if_testrpc(web3) + + with pytest.warns(DeprecationWarning) as warnings: + receiver_pub = web3.shh.getPublicKey(web3.shh.newKeyPair()) + assert web3.shh.post({ + "topic": "0x12345678", + "powTarget": 2.5, + "powTime": 2, + "payload": web3.toHex(text="testing shh on web3.py"), + "pubKey": receiver_pub, + }) + assert len(warnings) == 1 + + def test_shh_post(web3, skip_if_testrpc): skip_if_testrpc(web3) - receiver_pub = web3.shh.getPublicKey(web3.shh.newKeyPair()) + + receiver_pub = web3.shh.get_public_key(web3.shh.new_key_pair()) assert web3.shh.post({ "topic": "0x12345678", "powTarget": 2.5, diff --git a/tests/core/shh-module/test_shh_properties.py b/tests/core/shh-module/test_shh_properties.py index e95af46e9f..0df26b79ae 100644 --- a/tests/core/shh-module/test_shh_properties.py +++ b/tests/core/shh-module/test_shh_properties.py @@ -1,13 +1,30 @@ +import pytest + + def test_shh_version(web3, skip_if_testrpc): skip_if_testrpc(web3) assert web3.shh.version == '6.0' +def test_shh_info_deprecated(web3, skip_if_testrpc): + skip_if_testrpc(web3) + with pytest.warns(DeprecationWarning) as warnings: + web3.shh.setMaxMessageSize(1024) + web3.shh.setMinPoW(0.5) + + info = web3.shh.info + + assert len(warnings) == 2 + assert len(info) == 4 + assert info["maxMessageSize"] == 1024 + assert info["minPow"] == 0.5 + + def test_shh_info(web3, skip_if_testrpc): skip_if_testrpc(web3) - web3.shh.setMaxMessageSize(1024) - web3.shh.setMinPoW(0.5) + web3.shh.set_max_message_size(1024) + web3.shh.set_min_pow(0.5) info = web3.shh.info diff --git a/tests/integration/go_ethereum/common.py b/tests/integration/go_ethereum/common.py index a91507025c..08bdafb57c 100644 --- a/tests/integration/go_ethereum/common.py +++ b/tests/integration/go_ethereum/common.py @@ -101,11 +101,21 @@ def test_shh_sync_filter(self, web3): pytest.xfail('Whisper version 6 not supported in geth 1.7.2') super().test_shh_sync_filter(web3) + def test_shh_sync_filter_deprecated(self, web3): + if 'v1.7.2' in web3.clientVersion: + pytest.xfail('Whisper version 6 not supported in geth 1.7.2') + super().test_shh_sync_filter_deprecated(web3) + def test_shh_async_filter(self, web3): if 'v1.7.2' in web3.clientVersion: pytest.xfail('Whisper version 6 not supported in geth 1.7.2') super().test_shh_async_filter(web3) + def test_shh_async_filter_deprecated(self, web3): + if 'v1.7.2' in web3.clientVersion: + pytest.xfail('Whisper version 6 not supported in geth 1.7.2') + super().test_shh_async_filter_deprecated(web3) + def test_shh_post(self, web3): if 'v1.7.2' in web3.clientVersion: pytest.xfail('Whisper version 6 not supported in geth 1.7.2') diff --git a/tests/integration/go_ethereum/test_goethereum_ws.py b/tests/integration/go_ethereum/test_goethereum_ws.py index 8eaee8360d..1081879177 100644 --- a/tests/integration/go_ethereum/test_goethereum_ws.py +++ b/tests/integration/go_ethereum/test_goethereum_ws.py @@ -99,3 +99,7 @@ class TestGoEthereumShhModuleTest(CommonGoEthereumShhModuleTest): def test_shh_async_filter(self, web3): pytest.xfail("async filter bug in geth ws version") super().test_shh_async_filter(web3) + + def test_shh_async_filter_deprecated(self, web3): + pytest.xfail("async filter bug in geth ws version") + super().test_shh_async_filter(web3) diff --git a/web3/__init__.py b/web3/__init__.py index 2dafeba539..c0e0e71e4e 100644 --- a/web3/__init__.py +++ b/web3/__init__.py @@ -1,22 +1,13 @@ -import pkg_resources import sys import warnings -if (3, 5) <= sys.version_info < (3, 6): - warnings.warn( - "Support for Python 3.5 will be removed in web3.py v5", - category=DeprecationWarning, - stacklevel=2) - -if sys.version_info < (3, 5): - raise EnvironmentError( - "Python 3.5 or above is required. " - "Note that support for Python 3.5 will be removed in web3.py v5") +import pkg_resources -from eth_account import Account # noqa: E402 -from web3.main import Web3 # noqa: E402 -from web3.providers.rpc import ( # noqa: E402 - HTTPProvider, +from eth_account import ( + Account # noqa: E402, +) +from web3.main import ( + Web3 # noqa: E402, ) from web3.providers.eth_tester import ( # noqa: E402 EthereumTesterProvider, @@ -24,10 +15,25 @@ from web3.providers.ipc import ( # noqa: E402 IPCProvider, ) +from web3.providers.rpc import ( # noqa: E402 + HTTPProvider, +) from web3.providers.websocket import ( # noqa: E402 WebsocketProvider, ) +if (3, 5) <= sys.version_info < (3, 6): + warnings.warn( + "Support for Python 3.5 will be removed in web3.py v5", + category=DeprecationWarning, + stacklevel=2) + +if sys.version_info < (3, 5): + raise EnvironmentError( + "Python 3.5 or above is required. " + "Note that support for Python 3.5 will be removed in web3.py v5") + + __version__ = pkg_resources.get_distribution("web3").version __all__ = [ diff --git a/web3/_utils/module_testing/__init__.py b/web3/_utils/module_testing/__init__.py index 2425deac08..5b763e69ce 100644 --- a/web3/_utils/module_testing/__init__.py +++ b/web3/_utils/module_testing/__init__.py @@ -1,6 +1,3 @@ -from .web3_module import ( # noqa: F401 - Web3ModuleTest, -) from .eth_module import ( # noqa: F401 EthModuleTest, ) @@ -10,6 +7,11 @@ from .net_module import ( # noqa: F401 NetModuleTest, ) +from .parity_module import ( # noqa: F401 + ParityModuleTest, + ParitySetModuleTest, + ParityTraceModuleTest, +) from .personal_module import ( # noqa: F401 GoEthereumPersonalModuleTest, ParityPersonalModuleTest, @@ -21,8 +23,6 @@ from .version_module import ( # noqa: F401 VersionModuleTest, ) -from .parity_module import ( # noqa: F401 - ParitySetModuleTest, - ParityTraceModuleTest, - ParityModuleTest, +from .web3_module import ( # noqa: F401 + Web3ModuleTest, ) diff --git a/web3/_utils/module_testing/shh_module.py b/web3/_utils/module_testing/shh_module.py index a41d2b4aee..1a86cf2551 100644 --- a/web3/_utils/module_testing/shh_module.py +++ b/web3/_utils/module_testing/shh_module.py @@ -18,20 +18,21 @@ class GoEthereumShhModuleTest(): # shh_filter # def test_shh_sync_filter(self, web3): - sender = web3.geth.shh.newKeyPair() - sender_pub = web3.geth.shh.getPublicKey(sender) + sender = web3.geth.shh.new_key_pair() + sender_pub = web3.geth.shh.get_public_key(sender) - receiver = web3.geth.shh.newKeyPair() - receiver_pub = web3.geth.shh.getPublicKey(receiver) + receiver = web3.geth.shh.new_key_pair() + receiver_pub = web3.geth.shh.get_public_key(receiver) topic = '0x13370000' payloads = [web3.toHex(text="test message :)"), web3.toHex(text="2nd test message")] - shh_filter_id = web3.geth.shh.newMessageFilter({ + shh_filter_id = web3.geth.shh.new_message_filter({ 'privateKeyID': receiver, 'sig': sender_pub, 'topics': [topic] }) + shh_filter = ShhFilter(web3, shh_filter_id) web3.geth.shh.post({ @@ -61,23 +62,68 @@ def test_shh_sync_filter(self, web3): assert message["payload"] == HexBytes(payloads[1]) assert message["topic"] == HexBytes(topic) + def test_shh_sync_filter_deprecated(self, web3): + with pytest.warns(DeprecationWarning): + sender = web3.geth.shh.newKeyPair() + sender_pub = web3.geth.shh.getPublicKey(sender) + receiver = web3.geth.shh.newKeyPair() + receiver_pub = web3.geth.shh.getPublicKey(receiver) + + topic = '0x13370000' + payloads = [web3.toHex(text="test message :)"), web3.toHex(text="2nd test message")] + + shh_filter_id = web3.geth.shh.newMessageFilter({ + 'privateKeyID': receiver, + 'sig': sender_pub, + 'topics': [topic] + }) + + shh_filter = ShhFilter(web3, shh_filter_id) + + web3.geth.shh.post({ + 'sig': sender, + 'powTarget': 2.5, + 'powTime': 2, + 'payload': payloads[0], + 'pubKey': receiver_pub + }) + time.sleep(1) + + web3.geth.shh.post({ + 'sig': sender, + 'powTarget': 2.5, + 'powTime': 2, + 'payload': payloads[1], + 'topic': topic, + 'pubKey': receiver_pub + }) + time.sleep(1) + + received_messages = shh_filter.get_new_entries() + assert len(received_messages) == 1 + + message = received_messages[0] + + assert message["payload"] == HexBytes(payloads[1]) + assert message["topic"] == HexBytes(topic) + def test_shh_async_filter(self, web3): received_messages = [] - sender = web3.geth.shh.newKeyPair() - sender_pub = web3.geth.shh.getPublicKey(sender) - - receiver = web3.geth.shh.newKeyPair() - receiver_pub = web3.geth.shh.getPublicKey(receiver) + sender = web3.geth.shh.new_key_pair() + sender_pub = web3.geth.shh.get_public_key(sender) + receiver = web3.geth.shh.new_key_pair() + receiver_pub = web3.geth.shh.get_public_key(receiver) topic = '0x13370000' payloads = [web3.toHex(text="test message :)"), web3.toHex(text="2nd test message")] - shh_filter_id = web3.geth.shh.newMessageFilter({ + shh_filter_id = web3.geth.shh.new_message_filter({ 'privateKeyID': receiver, 'sig': sender_pub, 'topics': [topic] }) + shh_filter = ShhFilter(web3, shh_filter_id, poll_interval=0.5) watcher = shh_filter.watch(received_messages.extend) @@ -109,12 +155,90 @@ def test_shh_async_filter(self, web3): watcher.stop() + def test_shh_async_filter_deprecated(self, web3): + received_messages = [] + + with pytest.warns(DeprecationWarning) as warnings: + sender = web3.geth.shh.newKeyPair() + sender_pub = web3.geth.shh.getPublicKey(sender) + + receiver = web3.geth.shh.newKeyPair() + receiver_pub = web3.geth.shh.getPublicKey(receiver) + + topic = '0x13370000' + payloads = [web3.toHex(text="test message :)"), web3.toHex(text="2nd test message")] + + shh_filter_id = web3.geth.shh.newMessageFilter({ + 'privateKeyID': receiver, + 'sig': sender_pub, + 'topics': [topic] + }) + + shh_filter = ShhFilter(web3, shh_filter_id, poll_interval=0.5) + watcher = shh_filter.watch(received_messages.extend) + + web3.geth.shh.post({ + 'sig': sender, + 'powTarget': 2.5, + 'powTime': 2, + 'payload': payloads[0], + 'topic': topic, + 'pubKey': receiver_pub + }) + time.sleep(1) + + web3.geth.shh.post({ + 'sig': sender, + 'powTarget': 2.5, + 'powTime': 2, + 'payload': payloads[1], + 'pubKey': receiver_pub + }) + time.sleep(1) + + assert len(received_messages) == 1 + assert len(warnings) == 5 + + message = received_messages[0] + + assert message["payload"] == HexBytes(payloads[0]) + assert message["topic"] == HexBytes(topic) + + watcher.stop() + + def test_shh_remove_filter_deprecated(self, web3): + with pytest.warns(DeprecationWarning): + receiver = web3.geth.shh.newKeyPair() + receiver_pub = web3.geth.shh.getPublicKey(receiver) + payload = web3.toHex(text="test message :)") + shh_filter_id = web3.geth.shh.newMessageFilter({'privateKeyID': receiver}) + shh_filter = ShhFilter(web3, shh_filter_id) + + web3.geth.shh.post({ + 'powTarget': 2.5, + 'powTime': 2, + 'payload': payload, + 'pubKey': receiver_pub + }) + time.sleep(1) + + message = shh_filter.get_new_entries()[0] + assert message["payload"] == HexBytes(payload) + + assert web3.geth.shh.deleteMessageFilter(shh_filter.filter_id) + + try: + web3.geth.shh.getMessages(shh_filter.filter_id) + assert False + except BaseException: + assert True + def test_shh_remove_filter(self, web3): - receiver = web3.geth.shh.newKeyPair() - receiver_pub = web3.geth.shh.getPublicKey(receiver) + receiver = web3.geth.shh.new_key_pair() + receiver_pub = web3.geth.shh.get_public_key(receiver) payload = web3.toHex(text="test message :)") - shh_filter_id = web3.geth.shh.newMessageFilter({'privateKeyID': receiver}) + shh_filter_id = web3.geth.shh.new_message_filter({'privateKeyID': receiver}) shh_filter = ShhFilter(web3, shh_filter_id) web3.geth.shh.post({ @@ -128,12 +252,12 @@ def test_shh_remove_filter(self, web3): message = shh_filter.get_new_entries()[0] assert message["payload"] == HexBytes(payload) - assert web3.geth.shh.deleteMessageFilter(shh_filter.filter_id) + assert web3.geth.shh.delete_message_filter(shh_filter.filter_id) try: - web3.geth.shh.getMessages(shh_filter.filter_id) + web3.geth.shh.get_filter_messages(shh_filter.filter_id) assert False - except: + except BaseException: assert True # @@ -141,47 +265,88 @@ def test_shh_remove_filter(self, web3): # def test_shh_asymmetric_key_pair(self, web3): # Test generating key - key_id = web3.geth.shh.newKeyPair() - assert web3.geth.shh.hasKeyPair(key_id) - assert len(web3.geth.shh.getPublicKey(key_id)) == 132 - private_key = web3.geth.shh.getPrivateKey(key_id) + key_id = web3.geth.shh.new_key_pair() + assert web3.geth.shh.has_key_pair(key_id) + assert len(web3.geth.shh.get_public_key(key_id)) == 132 + private_key = web3.geth.shh.get_private_key(key_id) assert len(private_key) == 66 - assert web3.geth.shh.deleteKeyPair(key_id) + assert web3.geth.shh.delete_key_pair(key_id) + + # Test adding a key + assert not web3.geth.shh.has_key_pair(key_id) + key_id = web3.geth.shh.add_private_key(private_key) + assert web3.geth.shh.has_key_pair(key_id) + assert web3.geth.shh.delete_key_pair(key_id) + + def test_shh_asymmetric_key_pair_deprecated(self, web3): + # Test generating key + with pytest.warns(DeprecationWarning): + key_id = web3.geth.shh.newKeyPair() + assert web3.geth.shh.hasKeyPair(key_id) + assert len(web3.geth.shh.getPublicKey(key_id)) == 132 + private_key = web3.geth.shh.getPrivateKey(key_id) + assert len(private_key) == 66 + assert web3.geth.shh.deleteKeyPair(key_id) # Test adding a key - assert not web3.geth.shh.hasKeyPair(key_id) - key_id = web3.geth.shh.addPrivateKey(private_key) - assert web3.geth.shh.hasKeyPair(key_id) - assert web3.geth.shh.deleteKeyPair(key_id) + assert not web3.geth.shh.hasKeyPair(key_id) + key_id = web3.geth.shh.addPrivateKey(private_key) + assert web3.geth.shh.hasKeyPair(key_id) + assert web3.geth.shh.deleteKeyPair(key_id) def test_shh_symmetric_key_pair(self, web3): # Test generating key - key_id = web3.geth.shh.newSymKey() - assert web3.geth.shh.hasSymKey(key_id) + key_id = web3.geth.shh.new_sym_key() + assert web3.geth.shh.has_sym_key(key_id) - key = web3.geth.shh.getSymKey(key_id) + key = web3.geth.shh.get_sym_key(key_id) assert len(key) == 66 - assert web3.geth.shh.deleteSymKey(key_id) + assert web3.geth.shh.delete_sym_key(key_id) + + # Test adding a key + assert not web3.geth.shh.has_sym_key(key_id) + key_id = web3.geth.shh.add_sym_key(key) + assert web3.geth.shh.has_sym_key(key_id) + assert web3.geth.shh.delete_sym_key(key_id) + + def test_shh_symmetric_key_pair_deprecated(self, web3): + with pytest.warns(DeprecationWarning): + # Test generating key + key_id = web3.geth.shh.newSymKey() + assert web3.geth.shh.hasSymKey(key_id) + + key = web3.geth.shh.getSymKey(key_id) + assert len(key) == 66 + assert web3.geth.shh.deleteSymKey(key_id) # Test adding a key - assert not web3.geth.shh.hasSymKey(key_id) - key_id = web3.geth.shh.addSymKey(key) - assert web3.geth.shh.hasSymKey(key_id) - assert web3.geth.shh.deleteSymKey(key_id) + assert not web3.geth.shh.hasSymKey(key_id) + key_id = web3.geth.shh.addSymKey(key) + assert web3.geth.shh.hasSymKey(key_id) + assert web3.geth.shh.deleteSymKey(key_id) + + def test_shh_symmetric_key_pair_from_password_deprecated(self, web3): + with pytest.warns(DeprecationWarning): + key_id = web3.geth.shh.generateSymKeyFromPassword('shh be quiet') + + assert web3.geth.shh.hasSymKey(key_id) + assert len(web3.geth.shh.getSymKey(key_id)) == 66 + assert web3.geth.shh.deleteSymKey(key_id) def test_shh_symmetric_key_pair_from_password(self, web3): - key_id = web3.geth.shh.generateSymKeyFromPassword('shh be quiet') - assert web3.geth.shh.hasSymKey(key_id) - assert len(web3.geth.shh.getSymKey(key_id)) == 66 - assert web3.geth.shh.deleteSymKey(key_id) + key_id = web3.geth.shh.generate_sym_key_from_password('shh be quiet') + + assert web3.geth.shh.has_sym_key(key_id) + assert len(web3.geth.shh.get_sym_key(key_id)) == 66 + assert web3.geth.shh.delete_sym_key(key_id) # # shh_post # def test_shh_post(self, web3): - receiver_pub = web3.geth.shh.getPublicKey(web3.geth.shh.newKeyPair()) + receiver_pub = web3.geth.shh.get_public_key(web3.geth.shh.new_key_pair()) assert web3.geth.shh.post({ "topic": "0x12345678", "powTarget": 2.5, @@ -190,6 +355,17 @@ def test_shh_post(self, web3): "pubKey": receiver_pub, }) + def test_shh_post_deprecated(self, web3): + with pytest.warns(DeprecationWarning): + receiver_pub = web3.geth.shh.getPublicKey(web3.geth.shh.newKeyPair()) + assert web3.geth.shh.post({ + "topic": "0x12345678", + "powTarget": 2.5, + "powTime": 2, + "payload": web3.toHex(text="testing shh on web3.py"), + "pubKey": receiver_pub, + }) + # # shh_properties # @@ -205,8 +381,8 @@ def test_shh_info(self, web3): assert pre_info["maxMessageSize"] is not 1024 assert pre_info["minPow"] is not 0.5 - web3.geth.shh.setMaxMessageSize(1024) - web3.geth.shh.setMinPoW(0.5) + web3.geth.shh.set_max_message_size(1024) + web3.geth.shh.set_min_pow(0.5) info = web3.geth.shh.info() @@ -214,22 +390,37 @@ def test_shh_info(self, web3): assert info["maxMessageSize"] == 1024 assert info["minPow"] == 0.5 + def test_shh_info_deprecated(self, web3): + with pytest.warns(DeprecationWarning): + pre_info = web3.geth.shh.info() + assert pre_info["maxMessageSize"] is not 1024 + assert pre_info["minPow"] is not 0.5 + + web3.geth.shh.setMaxMessageSize(1024) + web3.geth.shh.setMinPoW(0.5) + + info = web3.geth.shh.info() + + assert len(info) == 4 + assert info["maxMessageSize"] == 1024 + assert info["minPow"] == 0.5 + class ParityShhModuleTest(): # # shh_filter # def test_shh_sync_filter(self, web3): - sender = web3.parity.shh.newKeyPair() - sender_pub = web3.parity.shh.getPublicKey(sender) + sender = web3.parity.shh.new_key_pair() + sender_pub = web3.parity.shh.get_public_key(sender) - receiver = web3.parity.shh.newKeyPair() - receiver_pub = web3.parity.shh.getPublicKey(receiver) + receiver = web3.parity.shh.new_key_pair() + receiver_pub = web3.parity.shh.get_public_key(receiver) topic = '0x13370000' payloads = [web3.toHex(text="test message :)"), web3.toHex(text="2nd test message")] - shh_filter_id = web3.parity.shh.newMessageFilter({ + shh_filter_id = web3.parity.shh.new_mssage_filter({ 'decryptWith': receiver, 'from': sender_pub, 'topics': [topic], @@ -267,16 +458,16 @@ def test_shh_sync_filter(self, web3): def test_shh_async_filter(self, web3): received_messages = [] - sender = web3.parity.shh.newKeyPair() - sender_pub = web3.parity.shh.getPublicKey(sender) + sender = web3.parity.shh.new_key_pair() + sender_pub = web3.parity.shh.get_public_key(sender) - receiver = web3.parity.shh.newKeyPair() - receiver_pub = web3.parity.shh.getPublicKey(receiver) + receiver = web3.parity.shh.new_key_pair() + receiver_pub = web3.parity.shh.get_public_key(receiver) topic = '0x13370000' payloads = [web3.toHex(text="test message :)"), web3.toHex(text="2nd test message")] - shh_filter_id = web3.parity.shh.newMessageFilter({ + shh_filter_id = web3.parity.shh.new_message_filter({ 'decryptWith': receiver, 'from': sender_pub, 'topics': [topic] @@ -313,17 +504,13 @@ def test_shh_async_filter(self, web3): watcher.stop() - # Sometimes the post fails because PoW is too low. - # We don't care if an error or a True response comes back, - # we only care that we're interfacing correctly with Parity - @pytest.mark.xfail(strict=False, raises=ValueError) def test_shh_remove_filter(self, web3): - receiver = web3.parity.shh.newKeyPair() - receiver_pub = web3.parity.shh.getPublicKey(receiver) + receiver = web3.parity.shh.new_key_pair() + receiver_pub = web3.parity.shh.get_public_key(receiver) payload = web3.toHex(text="test message :)") topic = '0x13370000' - shh_filter = web3.parity.shh.newMessageFilter({'decryptWith': None, 'topics': [topic]}) + shh_filter = web3.parity.shh.new_message_filter({'decryptWith': None, 'topics': [topic]}) assert web3.parity.shh.post({ 'payload': payload, @@ -339,12 +526,12 @@ def test_shh_remove_filter(self, web3): # message = ShhFilter(web3, shh_filter).get_new_entries() # assert message["payload"] == HexBytes(payload) - assert web3.parity.shh.deleteMessageFilter(shh_filter) + assert web3.parity.shh.delete_message_filter(shh_filter) try: - web3.parity.shh.getFilterMessages(shh_filter) + web3.parity.shh.get_filter_messages(shh_filter) assert False - except: + except BaseException: assert True # @@ -352,41 +539,36 @@ def test_shh_remove_filter(self, web3): # def test_shh_asymmetric_key_pair(self, web3): # Test generating key - key_id = web3.parity.shh.newKeyPair() - assert len(web3.parity.shh.getPublicKey(key_id)) == 130 + key_id = web3.parity.shh.new_key_pair() + assert len(web3.parity.shh.get_public_key(key_id)) == 130 - private_key = web3.parity.shh.getPrivateKey(key_id) + private_key = web3.parity.shh.get_private_key(key_id) assert len(private_key) == 66 - assert web3.parity.shh.deleteKey(key_id) + assert web3.parity.shh.delete_key(key_id) # Test adding a key - assert not web3.parity.shh.deleteKey(key_id) - key_id = web3.parity.shh.addPrivateKey(private_key) - assert web3.parity.shh.deleteKey(key_id) + assert not web3.parity.shh.delete_key(key_id) + key_id = web3.parity.shh.add_private_key(private_key) + assert web3.parity.shh.delete_key(key_id) def test_shh_symmetric_key_pair(self, web3): # Test generating key - key_id = web3.parity.shh.newSymKey() + key_id = web3.parity.shh.new_sym_key() - key = web3.parity.shh.getSymKey(key_id) + key = web3.parity.shh.get_sym_key(key_id) assert len(key) == 66 - assert web3.parity.shh.deleteKey(key_id) + assert web3.parity.shh.delete_key(key_id) # Test adding a key - assert not web3.parity.shh.deleteKey(key_id) - key_id = web3.parity.shh.addSymKey(key) - assert web3.parity.shh.deleteKey(key_id) + assert not web3.parity.shh.delete_key(key_id) + key_id = web3.parity.shh.add_sym_key(key) + assert web3.parity.shh.delete_key(key_id) # # shh_post # - - # Sometimes the post fails because PoW is too low. - # We don't care if an error or a True response comes back, - # we only care that we're interfacing correctly with Parity - @pytest.mark.xfail(strict=False, raises=ValueError) def test_shh_post(self, web3): - sender = web3.parity.shh.newKeyPair() + sender = web3.parity.shh.new_key_pair() assert web3.parity.shh.post({ "topics": ["0x12345678"], "payload": web3.toHex(text="testing shh on web3.py"), diff --git a/web3/_utils/shh.py b/web3/_utils/shh.py index 50df71891c..f0358bcdee 100644 --- a/web3/_utils/shh.py +++ b/web3/_utils/shh.py @@ -1,4 +1,5 @@ from web3.method import ( + DeprecatedMethod, Method, default_root_munger, ) @@ -15,97 +16,97 @@ ) -setMaxMessageSize = Method( +set_max_message_size = Method( "shh_setMaxMessageSize", mungers=[default_root_munger], ) -setMinPoW = Method( +set_min_pow = Method( "shh_setMinPoW", mungers=[default_root_munger], ) -markTrustedPeer = Method( +mark_trusted_peer = Method( "shh_markTrustedPeer", mungers=[default_root_munger], ) -newKeyPair = Method( +new_key_pair = Method( "shh_newKeyPair", mungers=None, ) -addPrivateKey = Method( +add_private_key = Method( "shh_addPrivateKey", mungers=[default_root_munger], ) -deleteKeyPair = Method( +delete_key_pair = Method( "shh_deleteKeyPair", mungers=[default_root_munger], ) -deleteKey = Method( +delete_key = Method( "shh_deleteKey", mungers=[default_root_munger], ) -hasKeyPair = Method( +has_key_pair = Method( "shh_hasKeyPair", mungers=[default_root_munger], ) -getPublicKey = Method( +get_public_key = Method( "shh_getPublicKey", mungers=[default_root_munger], ) -getPrivateKey = Method( +get_private_key = Method( "shh_getPrivateKey", mungers=[default_root_munger], ) -newSymKey = Method( +new_sym_key = Method( "shh_newSymKey", mungers=None, ) -addSymKey = Method( +add_sym_key = Method( "shh_addSymKey", mungers=[default_root_munger], ) -generateSymKeyFromPassword = Method( +generate_sym_key_from_password = Method( "shh_generateSymKeyFromPassword", mungers=[default_root_munger], ) -hasSymKey = Method( +has_sym_key = Method( "shh_hasSymKey", mungers=[default_root_munger], ) -getSymKey = Method( +get_sym_key = Method( "shh_getSymKey", mungers=[default_root_munger], ) -deleteSymKey = Method( +delete_sym_key = Method( "shh_deleteSymKey", mungers=[default_root_munger], ) @@ -124,19 +125,19 @@ def post_munger(module, message): ) -newMessageFilter = Method( +new_message_filter = Method( "shh_newMessageFilter", mungers=[default_root_munger], ) -deleteMessageFilter = Method( +delete_message_filter = Method( "shh_deleteMessageFilter", mungers=[default_root_munger], ) -getFilterMessages = Method( +get_filter_messages = Method( "shh_getFilterMessages", mungers=[default_root_munger], ) @@ -152,3 +153,36 @@ def post_munger(module, message): "shh_unsubscribe", mungers=[default_root_munger], ) + +# DeprecatedMethods +setMaxMessageSize = DeprecatedMethod( + set_max_message_size, + 'setMaxMessageSize', + 'set_max_message_size') +setMinPoW = DeprecatedMethod(set_min_pow, 'setMinPoW', 'set_min_pow') +markTrustedPeer = DeprecatedMethod(mark_trusted_peer, 'markTrustedPeer', 'mark_trusted_peer') +newKeyPair = DeprecatedMethod(new_key_pair, 'newKeyPair', new_key_pair) +addPrivateKey = DeprecatedMethod(add_private_key, 'addPrivateKey', 'add_private_key') +deleteKeyPair = DeprecatedMethod(delete_key_pair, 'deleteKeyPair', 'delete_key_pair') +deleteKey = DeprecatedMethod(delete_key, 'deleteKey', 'delete_key') +hasKeyPair = DeprecatedMethod(has_key_pair, 'hasKeyPair', 'has_key_pair') +getPublicKey = DeprecatedMethod(get_public_key, 'getPublicKey', 'get_public_key') +getPrivateKey = DeprecatedMethod(get_private_key, 'getPrivateKey', 'get_private_key') +newSymKey = DeprecatedMethod(new_sym_key, 'newSymKey', 'new_sym_key') +addSymKey = DeprecatedMethod(add_sym_key, 'addSymKey', 'add_sym_key') +generateSymKeyFromPassword = DeprecatedMethod( + generate_sym_key_from_password, + 'generateSymKeyFromPassword', + 'generate_sym_key_from_password') +hasSymKey = DeprecatedMethod(has_sym_key, 'hasSymKey', 'has_sym_key') +getSymKey = DeprecatedMethod(get_sym_key, 'getSymKey', 'get_sym_key') +deleteSymKey = DeprecatedMethod(delete_sym_key, 'deleteSymKey', 'delete_sym_key') +newMessageFilter = DeprecatedMethod(new_message_filter, 'newMessageFilter', 'new_message_filter') +deleteMessageFilter = DeprecatedMethod( + delete_message_filter, + 'deleteMessageFilter', + 'delete_message_filter') +getFilterMessages = DeprecatedMethod( + get_filter_messages, + 'getFilterMessages', + 'get_filter_messages') diff --git a/web3/geth.py b/web3/geth.py index 280d273a72..1e6cd24b44 100644 --- a/web3/geth.py +++ b/web3/geth.py @@ -116,26 +116,46 @@ class GethShh(ModuleV2): """ https://github.com/ethereum/go-ethereum/wiki/Whisper-v6-RPC-API """ - version = shh.version + add_private_key = shh.add_private_key + add_sym_key = shh.add_sym_key + delete_key = shh.delete_key + delete_key_pair = shh.delete_key_pair + delete_message_filter = shh.delete_message_filter + delete_sym_key = shh.delete_sym_key + generate_sym_key_from_password = shh.generate_sym_key_from_password + get_filter_messages = shh.get_filter_messages + get_private_key = shh.get_private_key + get_public_key = shh.get_public_key + get_sym_key = shh.get_sym_key + has_key_pair = shh.has_key_pair + has_sym_key = shh.has_sym_key info = shh.info - setMaxMessageSize = shh.setMaxMessageSize - setMinPoW = shh.setMinPoW - markTrustedPeer = shh.markTrustedPeer - newKeyPair = shh.newKeyPair + mark_trusted_peer = shh.mark_trusted_peer + new_key_pair = shh.new_key_pair + new_message_filter = shh.new_message_filter + new_sym_key = shh.new_sym_key + post = shh.post + set_max_message_size = shh.set_max_message_size + set_min_pow = shh.set_min_pow + subscribe = shh.subscribe + unsubscribe = shh.unsubscribe + version = shh.version + # Deprecated addPrivateKey = shh.addPrivateKey - deleteKeyPair = shh.deleteKeyPair - hasKeyPair = shh.hasKeyPair - getPublicKey = shh.getPublicKey - getPrivateKey = shh.getPrivateKey - newSymKey = shh.newSymKey addSymKey = shh.addSymKey + deleteKeyPair = shh.deleteKeyPair + deleteMessageFilter = shh.deleteMessageFilter + deleteSymKey = shh.deleteSymKey generateSymKeyFromPassword = shh.generateSymKeyFromPassword - hasSymKey = shh.hasSymKey + getMessages = shh.getFilterMessages + getPrivateKey = shh.getPrivateKey + getPublicKey = shh.getPublicKey getSymKey = shh.getSymKey - deleteSymKey = shh.deleteSymKey - post = shh.post + hasKeyPair = shh.hasKeyPair + hasSymKey = shh.hasSymKey + markTrustedPeer = shh.markTrustedPeer + newKeyPair = shh.newKeyPair newMessageFilter = shh.newMessageFilter - deleteMessageFilter = shh.deleteMessageFilter - getMessages = shh.getFilterMessages - subscribe = shh.subscribe - unsubscribe = shh.unsubscribe + newSymKey = shh.newSymKey + setMaxMessageSize = shh.setMaxMessageSize + setMinPoW = shh.setMinPoW diff --git a/web3/middleware/__init__.py b/web3/middleware/__init__.py index 30ffeab501..d4b93a0e35 100644 --- a/web3/middleware/__init__.py +++ b/web3/middleware/__init__.py @@ -7,23 +7,26 @@ attrdict_middleware, ) from .cache import ( # noqa: F401 - construct_simple_cache_middleware, - construct_time_based_cache_middleware, - construct_latest_block_based_cache_middleware, + _latest_block_based_cache_middleware as latest_block_based_cache_middleware, _simple_cache_middleware as simple_cache_middleware, _time_based_cache_middleware as time_based_cache_middleware, - _latest_block_based_cache_middleware as latest_block_based_cache_middleware, + construct_latest_block_based_cache_middleware, + construct_simple_cache_middleware, + construct_time_based_cache_middleware, ) from .exception_handling import ( # noqa: F401 construct_exception_handler_middleware, ) +from .exception_retry_request import ( # noqa: F401 + http_retry_request_middleware, +) from .filter import ( # noqa: F401 local_filter_middleware, ) from .fixture import ( # noqa: F401 + construct_error_generator_middleware, construct_fixture_middleware, construct_result_generator_middleware, - construct_error_generator_middleware, ) from .formatting import ( # noqa: F401 construct_formatting_middleware, @@ -31,6 +34,9 @@ from .gas_price_strategy import ( # noqa: F401 gas_price_strategy_middleware, ) +from .geth_poa import ( # noqa: F401 + geth_poa_middleware, +) from .names import ( # noqa: F401 name_to_address_middleware, ) @@ -43,26 +49,16 @@ from .pythonic import ( # noqa: F401 pythonic_middleware, ) +from .signing import ( # noqa: F401 + construct_sign_and_send_raw_middleware, +) from .stalecheck import ( # noqa: F401 make_stalecheck_middleware, ) - -from .exception_retry_request import ( # noqa: F401 - http_retry_request_middleware -) - -from .geth_poa import ( # noqa: F401 - geth_poa_middleware, -) - from .validation import ( # noqa: F401 validation_middleware, ) -from .signing import ( # noqa: F401 - construct_sign_and_send_raw_middleware, -) - def combine_middlewares(middlewares, web3, provider_request_fn): """ diff --git a/web3/parity.py b/web3/parity.py index 4e49c3769f..78acdca7c5 100644 --- a/web3/parity.py +++ b/web3/parity.py @@ -29,20 +29,32 @@ class ParityShh(ModuleV2): https://wiki.parity.io/JSONRPC-shh-module """ info = shh.info - newKeyPair = shh.newKeyPair - addPrivateKey = shh.addPrivateKey - newSymKey = shh.newSymKey - addSymKey = shh.addSymKey - getPublicKey = shh.getPublicKey - getPrivateKey = shh.getPrivateKey - getSymKey = shh.getSymKey + new_key_pair = shh.new_key_pair + add_private_key = shh.add_private_key + new_sym_key = shh.new_sym_key + add_sym_key = shh.add_sym_key + get_public_key = shh.get_public_key + get_private_key = shh.get_private_key + get_sym_key = shh.get_sym_key post = shh.post - newMessageFilter = shh.newMessageFilter - deleteMessageFilter = shh.deleteMessageFilter - getFilterMessages = shh.getFilterMessages - deleteKey = shh.deleteKey + new_message_filter = shh.new_message_filter + delete_message_filter = shh.delete_message_filter + get_filter_messages = shh.get_filter_messages + delete_key = shh.delete_key subscribe = shh.subscribe unsubscribe = shh.unsubscribe + # Deprecated + newKeyPair = shh.new_key_pair + addPrivateKey = shh.add_private_key + newSymKey = shh.new_sym_key + addSymKey = shh.add_sym_key + getPublicKey = shh.get_public_key + getPrivateKey = shh.get_private_key + getSymKey = shh.get_sym_key + newMessageFilter = shh.new_message_filter + deleteMessageFilter = shh.delete_message_filter + getFilterMessages = shh.get_filter_messages + deleteKey = shh.delete_key class ParityPersonal(ModuleV2): diff --git a/web3/providers/__init__.py b/web3/providers/__init__.py index 5d244169a0..701c59b5c3 100644 --- a/web3/providers/__init__.py +++ b/web3/providers/__init__.py @@ -2,8 +2,15 @@ BaseProvider, JSONBaseProvider, ) - -from .rpc import HTTPProvider # noqa: F401 -from .ipc import IPCProvider # noqa: F401 -from .websocket import WebsocketProvider # noqa: F401 -from .auto import AutoProvider # noqa: F401 +from .ipc import ( # noqa: F401, + IPCProvider, +) +from .rpc import ( # noqa: F401, + HTTPProvider, +) +from .websocket import ( # noqa: F401, + WebsocketProvider, +) +from .auto import ( # noqa: F401, + AutoProvider, +) diff --git a/web3/providers/eth_tester/defaults.py b/web3/providers/eth_tester/defaults.py index e8f026bef9..3ee90cfb4f 100644 --- a/web3/providers/eth_tester/defaults.py +++ b/web3/providers/eth_tester/defaults.py @@ -253,16 +253,50 @@ def personal_send_transaction(eth_tester, params): 'getHex': not_implemented, }, 'shh': { - 'post': not_implemented, - 'version': not_implemented, - 'newIdentity': not_implemented, + 'add_private_key': not_implemented, + 'add_sym_key': not_implemented, + 'delete_key_pair': not_implemented, + 'delete_message_filter': not_implemented, + 'delete_sym_key': not_implemented, + 'generate_sym_key_from_password': not_implemented, + 'get_filter_messages': not_implemented, + 'get_private_key': not_implemented, + 'get_public_key': not_implemented, + 'get_sym_key': not_implemented, 'hasIdentity': not_implemented, - 'newGroup': not_implemented, - 'addToGroup': not_implemented, + 'has_key_pair': not_implemented, + 'has_sym_key': not_implemented, + 'mark_trusted_peer': not_implemented, 'newFilter': not_implemented, + 'newGroup': not_implemented, + 'newIdentity': not_implemented, + 'new_key_pair': not_implemented, + 'new_message_filter': not_implemented, + 'new_sym_key': not_implemented, + 'post': not_implemented, + 'set_max_message_size': not_implemented, + 'set_min_pow': not_implemented, 'uninstallFilter': not_implemented, - 'getFilterChanges': not_implemented, + 'version': not_implemented, + # Deprecated + 'addPrivateKey': not_implemented, + 'addSymKey': not_implemented, + 'deleteKeyPair': not_implemented, + 'deleteMessageFilter': not_implemented, + 'deleteSymKey': not_implemented, + 'generateSymKeyFromPassword': not_implemented, 'getMessages': not_implemented, + 'getPrivateKey': not_implemented, + 'getPublicKey': not_implemented, + 'getSymKey': not_implemented, + 'hasKeyPair': not_implemented, + 'hasSymKey': not_implemented, + 'markTrustedPeer': not_implemented, + 'newKeyPair': not_implemented, + 'newMessageFilter': not_implemented, + 'newSymKey': not_implemented, + 'setMaxMessageSize': not_implemented, + 'setMinPoW': not_implemented, }, 'admin': { 'add_peer': not_implemented, diff --git a/web3/tools/__init__.py b/web3/tools/__init__.py index c68cbbc7d8..01cd73a94f 100644 --- a/web3/tools/__init__.py +++ b/web3/tools/__init__.py @@ -1 +1,4 @@ -from .pytest_ethereum import deployer, linker # noqa: F401 +from .pytest_ethereum import ( # noqa: F401 + deployer, + linker, +)