# Path: keepkeylib/client.py
# class CallException(Exception):
#     def __init__(self, code, message):
#         super(CallException, self).__init__()
#         self.args = [code, message]


import unittest
import common
import binascii
import base64
from keepkeylib.client import CallException
from keepkeylib import messages_pb2 as proto
    def test_message_testnet(self):
        self.setup_mnemonic_nopin_nopassphrase()
        sig = base64.b64decode('IFP/nvQalDo9lWCI7kScOzRkz/fiiScdkw7tFAKPoGbl6S8AY3wEws43s2gR57AfwZP8/8y7+F+wvGK9phQghN4=')
        ret = self.client.verify_message(
            'Testnet',
            'moRDikgmxcpouFtqnKnVVzLYgkDD2gQ3sk',
            sig,
            'Ahoj')
        self.assertTrue(ret)

    def test_message_grs(self):
        self.setup_mnemonic_allallall()
        sig = base64.b64decode('INOYaa/jj8Yxz3mD5k+bZfUmjkjB9VzoV4dNG7+RsBUyK30xL7I9yMgWWVvsL46C5yQtxtZY0cRRk7q9N6b+YTM=')
        ret = self.client.verify_message(
            'Groestlcoin',
            'Fj62rBJi8LvbmWu2jzkaUX1NFXLEqDLoZM',
            sig,
            'test')
        self.assertTrue(ret)

    def test_vuln1972(self):
        self.setup_mnemonic_allallall()

        signature = base64.b64decode('IFP/nvQalDo9lWCI7kScOzRkz/fiiScdkw7tFAKPoGbl6S8AY3wEws43s2gR57AfwZP8/8y7+F+wvGK9phQghN4=')
        address = 'moRDikgmxcpouFtqnKnVVzLYgkDD2gQ3sk'
        message = b'Ahoj'

        # Null pointer dereference caused the emulator to crash at this point.
        # After the fix, this shoud raise a CallException to signify that the
        # sig isn't valid for this coin's signing curve.

# Path: keepkeylib/client.py
# class CallException(Exception):
#     def __init__(self, code, message):
#         super(CallException, self).__init__()
#         self.args = [code, message]


# Path: tests/test_msg_verifymessage.py
import unittest
import common
import binascii
import base64
from keepkeylib.client import CallException
from keepkeylib import messages_pb2 as proto

    def test_message_testnet(self):
        self.setup_mnemonic_nopin_nopassphrase()
        sig = base64.b64decode('IFP/nvQalDo9lWCI7kScOzRkz/fiiScdkw7tFAKPoGbl6S8AY3wEws43s2gR57AfwZP8/8y7+F+wvGK9phQghN4=')
        ret = self.client.verify_message(
            'Testnet',
            'moRDikgmxcpouFtqnKnVVzLYgkDD2gQ3sk',
            sig,
            'Ahoj')
        self.assertTrue(ret)

    def test_message_grs(self):
        self.setup_mnemonic_allallall()
        sig = base64.b64decode('INOYaa/jj8Yxz3mD5k+bZfUmjkjB9VzoV4dNG7+RsBUyK30xL7I9yMgWWVvsL46C5yQtxtZY0cRRk7q9N6b+YTM=')
        ret = self.client.verify_message(
            'Groestlcoin',
            'Fj62rBJi8LvbmWu2jzkaUX1NFXLEqDLoZM',
            sig,
            'test')
        self.assertTrue(ret)

    def test_vuln1972(self):
        self.setup_mnemonic_allallall()

        signature = base64.b64decode('IFP/nvQalDo9lWCI7kScOzRkz/fiiScdkw7tFAKPoGbl6S8AY3wEws43s2gR57AfwZP8/8y7+F+wvGK9phQghN4=')
        address = 'moRDikgmxcpouFtqnKnVVzLYgkDD2gQ3sk'
        message = b'Ahoj'

        # Null pointer dereference caused the emulator to crash at this point.
        # After the fix, this shoud raise a CallException to signify that the
        # sig isn't valid for this coin's signing curve.

        self.assertRaises(CallException, self.client.call, proto.VerifyMessage(address=address, signature=signature, message=message, coin_name="Nano"))