Esempio n. 1
0
    def test_shh_remove_filter(self, web3: "Web3") -> None:

        info = web3.geth.shh.info()
        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.new_message_filter({'privateKeyID': receiver})
        shh_filter = ShhFilter(web3, shh_filter_id)

        web3.geth.shh.post({
            'powTarget': info['minPow'],
            '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.delete_message_filter(shh_filter.filter_id)

        try:
            web3.geth.shh.get_filter_messages(shh_filter.filter_id)
            assert False
        except BaseException:
            assert True
Esempio n. 2
0
    def test_shh_remove_filter_deprecated(self, web3: "Web3") -> None:
        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
Esempio n. 3
0
    def test_shh_async_filter(self, web3: "Web3") -> None:
        received_messages: List[ShhMessage] = []

        sender = web3.parity.shh.new_key_pair()
        sender_pub = web3.parity.shh.get_public_key(sender)

        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.new_message_filter({
            'decryptWith': receiver,
            'from': sender_pub,
            'topics': [topic]
        })
        shh_filter = ShhFilter(web3, shh_filter_id, poll_interval=0.5)
        watcher = shh_filter.watch(received_messages.extend)

        web3.parity.shh.post({
            'from': sender,
            'payload': payloads[0],
            'topics': [topic],
            'to': {
                'public': receiver_pub
            },
            'priority': 1000,
            'ttl': 100,
        })
        time.sleep(1)

        web3.parity.shh.post({
            'from': sender,
            'payload': payloads[1],
            'topics': [topic],
            'to': {
                'identity': receiver
            },
            'priority': 1000,
            'ttl': 100,
        })
        time.sleep(1)

        assert len(received_messages) == 1

        message = received_messages[0]

        assert message["payload"] == HexBytes(payloads[0])
        assert message["topic"] == HexBytes(topic)

        watcher.stop()
Esempio n. 4
0
    def test_shh_async_filter_deprecated(self, web3: "Web3") -> None:
        received_messages: List[ShhMessage] = []

        with pytest.warns(DeprecationWarning) as warnings:
            info = web3.geth.shh.info()
            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 = HexStr('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': info['minPow'],
                'powTime': 2,
                'payload': payloads[0],
                'topic': topic,
                'pubKey': receiver_pub
            })
            time.sleep(1)

            web3.geth.shh.post({
                'sig': sender,
                'powTarget': info['minPow'],
                '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()
Esempio n. 5
0
    def test_shh_async_filter(self, web3: "Web3") -> None:
        received_messages: List[ShhMessage] = []

        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.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)

        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

        message = received_messages[0]

        assert message["payload"] == HexBytes(payloads[0])
        assert message["topic"] == HexBytes(topic)

        watcher.stop()
Esempio n. 6
0
    def test_shh_sync_filter(self, web3: "Web3") -> None:
        sender = web3.parity.shh.new_key_pair()
        sender_pub = web3.parity.shh.get_public_key(sender)

        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.new_message_filter({
            'decryptWith': receiver,
            'from': sender_pub,
            'topics': [topic],
        })

        shh_filter = ShhFilter(web3, shh_filter_id)
        time.sleep(1)

        assert web3.parity.shh.post({
            'from': sender,
            'payload': payloads[0],
            'to': {
                'public': receiver_pub
            },
            'topics': [topic],
            'priority': 1000,
            'ttl': 100,
        })
        time.sleep(1)

        assert web3.parity.shh.post({
            'from': receiver,
            'payload': payloads[1],
            'topics': [topic],
            'priority': 1000,
            'ttl': 100,
        })
        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)
Esempio n. 7
0
    def test_shh_sync_filter(self, web3: "Web3") -> None:

        info = web3.geth.shh.info()
        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 = HexStr('0x13370000')
        payloads = [
            web3.toHex(text="test message :)"),
            web3.toHex(text="2nd test message")
        ]

        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({
            'sig': sender,
            'powTarget': info['minPow'],
            'powTime': 2,
            'payload': payloads[0],
            'pubKey': receiver_pub
        })
        time.sleep(1)

        web3.geth.shh.post({
            'sig': sender,
            'powTarget': info['minPow'],
            '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)
Esempio n. 8
0
    def test_shh_sync_filter_deprecated(self, web3: "Web3") -> None:
        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)
Esempio n. 9
0
 def newMessageFilter(self, criteria, poll_interval=None):
     filter_id = self.web3.manager.request_blocking("shh_newMessageFilter",
                                                    [criteria])
     return ShhFilter(self.web3, filter_id, poll_interval=poll_interval)