parent
d4987849ce
commit
8b252bff80
@ -1,42 +1,43 @@
|
||||
from common import *
|
||||
from ubinascii import unhexlify
|
||||
|
||||
from common import *
|
||||
from trezor.messages import TezosContractType
|
||||
from trezor.messages.TezosContractID import TezosContractID
|
||||
|
||||
from apps.tezos.sign_tx import _get_address_from_contract
|
||||
|
||||
|
||||
class TestTezosAddress(unittest.TestCase):
|
||||
|
||||
def test_get_address_from_contract(self):
|
||||
contracts = [
|
||||
TezosContractID(
|
||||
tag=TezosContractType.Implicit,
|
||||
hash=unhexlify("0090ec585b4d5fa39b20213e46b232cc57a4cfab4b")
|
||||
hash=unhexlify("0090ec585b4d5fa39b20213e46b232cc57a4cfab4b"),
|
||||
),
|
||||
TezosContractID(
|
||||
tag=TezosContractType.Implicit,
|
||||
hash=unhexlify("017dfb3fef44082eca8cd3eccebd77db44633ffc9e")
|
||||
hash=unhexlify("017dfb3fef44082eca8cd3eccebd77db44633ffc9e"),
|
||||
),
|
||||
TezosContractID(
|
||||
tag=TezosContractType.Implicit,
|
||||
hash=unhexlify("02c1fc1b7e503825068ff4fe2f8916f98af981eab1")
|
||||
hash=unhexlify("02c1fc1b7e503825068ff4fe2f8916f98af981eab1"),
|
||||
),
|
||||
TezosContractID(
|
||||
tag=TezosContractType.Originated,
|
||||
hash=unhexlify("65671dedc69669f066f45d586a2ecdeddacc95af00")
|
||||
)
|
||||
hash=unhexlify("65671dedc69669f066f45d586a2ecdeddacc95af00"),
|
||||
),
|
||||
]
|
||||
|
||||
outputs = [
|
||||
"tz1YrK8Hqt6GAPYRHAaeJmhETYyPSQCHTrkj",
|
||||
"tz2KoN7TFjhp96V2XikqYSGyDmVVUHXvkzko",
|
||||
"tz3e1k3QzCwEbRZrfHCwT3Npvw1rezmMQArY",
|
||||
"KT1HpwLq2AjZgEQspiSnYmdtaHy4NgXw6BDC"
|
||||
"KT1HpwLq2AjZgEQspiSnYmdtaHy4NgXw6BDC",
|
||||
]
|
||||
|
||||
for i, contract in enumerate(contracts):
|
||||
self.assertEqual(_get_address_from_contract(contract), outputs[i])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
@ -1,79 +1,100 @@
|
||||
from common import *
|
||||
from ubinascii import unhexlify
|
||||
|
||||
from common import *
|
||||
from trezor.messages import TezosContractType
|
||||
from trezor.messages.TezosContractID import TezosContractID
|
||||
|
||||
from apps.tezos.helpers import b58cencode, b58cdecode
|
||||
from apps.tezos.helpers import base58_decode_check, base58_encode_check
|
||||
from apps.tezos.sign_tx import (
|
||||
_encode_zarith,
|
||||
_encode_data_with_bool_prefix,
|
||||
_encode_bool,
|
||||
_encode_contract_id
|
||||
_encode_contract_id,
|
||||
_encode_data_with_bool_prefix,
|
||||
_encode_zarith,
|
||||
)
|
||||
|
||||
|
||||
class TestTezosEncoding(unittest.TestCase):
|
||||
|
||||
def test_tezos_encode_zarith(self):
|
||||
inputs = [2000000, 159066, 200, 60000, 157000000, 0]
|
||||
outputs = ["80897a", "dada09", "c801", "e0d403", "c0c2ee4a", "00"]
|
||||
|
||||
for i, o in zip(inputs, outputs):
|
||||
self.assertEqual(_encode_zarith(i), unhexlify(o))
|
||||
w = bytearray()
|
||||
_encode_zarith(w, i)
|
||||
self.assertEqual(bytes(w), unhexlify(o))
|
||||
|
||||
def test_tezos_encode_data_with_bool_prefix(self):
|
||||
self.assertEqual(_encode_data_with_bool_prefix(None), bytes([0]))
|
||||
w = bytearray()
|
||||
_encode_data_with_bool_prefix(w, None)
|
||||
self.assertEqual(bytes(w), bytes([0]))
|
||||
|
||||
data = "afffeb1dc3c0"
|
||||
self.assertEqual(_encode_data_with_bool_prefix(unhexlify(data)),
|
||||
unhexlify("ff" + data))
|
||||
w = bytearray()
|
||||
_encode_data_with_bool_prefix(w, unhexlify(data))
|
||||
self.assertEqual(bytes(w), unhexlify("ff" + data))
|
||||
|
||||
def test_tezos_encode_bool(self):
|
||||
self.assertEqual(_encode_bool(True), bytes([255]))
|
||||
self.assertEqual(_encode_bool(False), bytes([0]))
|
||||
w = bytearray()
|
||||
_encode_bool(w, True)
|
||||
self.assertEqual(bytes(w), bytes([255]))
|
||||
|
||||
w = bytearray()
|
||||
_encode_bool(w, False)
|
||||
self.assertEqual(bytes(w), bytes([0]))
|
||||
|
||||
def test_tezos_encode_contract_id(self):
|
||||
implicit = TezosContractID(
|
||||
tag=TezosContractType.Implicit,
|
||||
hash=unhexlify("00101368afffeb1dc3c089facbbe23f5c30b787ce9")
|
||||
hash=unhexlify("00101368afffeb1dc3c089facbbe23f5c30b787ce9"),
|
||||
)
|
||||
w = bytearray()
|
||||
_encode_contract_id(w, implicit)
|
||||
self.assertEqual(
|
||||
bytes(w), unhexlify("0000101368afffeb1dc3c089facbbe23f5c30b787ce9")
|
||||
)
|
||||
self.assertEqual(_encode_contract_id(implicit),
|
||||
unhexlify("0000101368afffeb1dc3c089facbbe23f5c30b787ce9"))
|
||||
|
||||
originated = TezosContractID(
|
||||
tag=TezosContractType.Originated,
|
||||
hash=unhexlify("65671dedc69669f066f45d586a2ecdeddacc95af00")
|
||||
hash=unhexlify("65671dedc69669f066f45d586a2ecdeddacc95af00"),
|
||||
)
|
||||
w = bytearray()
|
||||
_encode_contract_id(w, originated)
|
||||
self.assertEqual(
|
||||
bytes(w), unhexlify("0165671dedc69669f066f45d586a2ecdeddacc95af00")
|
||||
)
|
||||
self.assertEqual(_encode_contract_id(originated),
|
||||
unhexlify("0165671dedc69669f066f45d586a2ecdeddacc95af00"))
|
||||
|
||||
def test_tezos_b58cencode(self):
|
||||
def test_tezos_base58_encode_check(self):
|
||||
pkh = unhexlify("101368afffeb1dc3c089facbbe23f5c30b787ce9")
|
||||
|
||||
self.assertEqual(b58cencode(pkh, prefix="tz1"),
|
||||
"tz1M72kkAJrntPtayM4yU4CCwQPLSdpEgRrn")
|
||||
self.assertEqual(b58cencode(pkh, prefix="tz2"),
|
||||
"tz29nEixktH9p9XTFX7p8hATUyeLxXEz96KR")
|
||||
self.assertEqual(b58cencode(pkh, prefix="tz3"),
|
||||
"tz3Mo3gHekQhCmykfnC58ecqJLXrjMKzkF2Q")
|
||||
self.assertEqual(b58cencode(pkh), "2U14dJ6ED97bBHDZTQWA6umVL8SAVefXj")
|
||||
self.assertEqual(
|
||||
base58_encode_check(pkh, prefix="tz1"),
|
||||
"tz1M72kkAJrntPtayM4yU4CCwQPLSdpEgRrn",
|
||||
)
|
||||
self.assertEqual(
|
||||
base58_encode_check(pkh, prefix="tz2"),
|
||||
"tz29nEixktH9p9XTFX7p8hATUyeLxXEz96KR",
|
||||
)
|
||||
self.assertEqual(
|
||||
base58_encode_check(pkh, prefix="tz3"),
|
||||
"tz3Mo3gHekQhCmykfnC58ecqJLXrjMKzkF2Q",
|
||||
)
|
||||
self.assertEqual(base58_encode_check(pkh), "2U14dJ6ED97bBHDZTQWA6umVL8SAVefXj")
|
||||
|
||||
def test_tezos_b58cdecode(self):
|
||||
def test_tezos_base58_decode_check(self):
|
||||
pkh = unhexlify("101368afffeb1dc3c089facbbe23f5c30b787ce9")
|
||||
|
||||
address = "tz1M72kkAJrntPtayM4yU4CCwQPLSdpEgRrn"
|
||||
self.assertEqual(b58cdecode(address, prefix="tz1"), pkh)
|
||||
self.assertEqual(base58_decode_check(address, prefix="tz1"), pkh)
|
||||
|
||||
address = "tz29nEixktH9p9XTFX7p8hATUyeLxXEz96KR"
|
||||
self.assertEqual(b58cdecode(address, prefix="tz2"), pkh)
|
||||
self.assertEqual(base58_decode_check(address, prefix="tz2"), pkh)
|
||||
|
||||
address = "tz3Mo3gHekQhCmykfnC58ecqJLXrjMKzkF2Q"
|
||||
self.assertEqual(b58cdecode(address, prefix="tz3"), pkh)
|
||||
self.assertEqual(base58_decode_check(address, prefix="tz3"), pkh)
|
||||
|
||||
address = "2U14dJ6ED97bBHDZTQWA6umVL8SAVefXj"
|
||||
self.assertEqual(b58cdecode(address), pkh)
|
||||
self.assertEqual(base58_decode_check(address), pkh)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
Loading…
Reference in new issue