2020-07-23 13:54:49 +00:00
|
|
|
from common import *
|
|
|
|
|
|
|
|
if not utils.BITCOIN_ONLY:
|
2021-03-02 18:08:14 +00:00
|
|
|
from apps.cardano.helpers.utils import variable_length_encode, format_asset_fingerprint
|
2020-07-23 13:54:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
@unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin")
|
|
|
|
class TestCardanoUtils(unittest.TestCase):
|
|
|
|
def test_variable_length_encode(self):
|
|
|
|
test_vectors = [
|
2020-11-11 13:43:09 +00:00
|
|
|
(0, bytes([0x00])),
|
|
|
|
(42, bytes([0x2A])),
|
|
|
|
(127, bytes([0x7F])),
|
2020-07-23 13:54:49 +00:00
|
|
|
(128, bytes([0x81, 0x00])),
|
|
|
|
(129, bytes([0x81, 0x01])),
|
|
|
|
(255, bytes([0x81, 0x7F])),
|
|
|
|
(256, bytes([0x82, 0x00])),
|
|
|
|
(16383, bytes([0xFF, 0x7F])),
|
|
|
|
(16384, bytes([0x81, 0x80, 0x00])),
|
|
|
|
]
|
|
|
|
|
|
|
|
for number, expected in test_vectors:
|
|
|
|
actual = variable_length_encode(number)
|
|
|
|
self.assertEqual(actual, expected)
|
|
|
|
|
|
|
|
|
|
|
|
def test_variable_length_encode_negative_number(self):
|
|
|
|
with self.assertRaises(ValueError):
|
|
|
|
variable_length_encode(-1)
|
|
|
|
|
2021-03-02 18:08:14 +00:00
|
|
|
def test_format_asset_fingerprint(self):
|
|
|
|
# source: https://github.com/cardano-foundation/CIPs/pull/64
|
|
|
|
test_vectors = [
|
|
|
|
(("7eae28af2208be856f7a119668ae52a49b73725e326dc16579dcc373", ""), "asset1rjklcrnsdzqp65wjgrg55sy9723kw09mlgvlc3"),
|
|
|
|
(("7eae28af2208be856f7a119668ae52a49b73725e326dc16579dcc373", "504154415445"), "asset13n25uv0yaf5kus35fm2k86cqy60z58d9xmde92"),
|
|
|
|
(("1e349c9bdea19fd6c147626a5260bc44b71635f398b67c59881df209", "7eae28af2208be856f7a119668ae52a49b73725e326dc16579dcc373"), "asset1aqrdypg669jgazruv5ah07nuyqe0wxjhe2el6f"),
|
|
|
|
]
|
|
|
|
|
|
|
|
for params, expected in test_vectors:
|
|
|
|
actual = format_asset_fingerprint(policy_id=unhexlify(params[0]), asset_name_bytes=unhexlify(params[1]))
|
|
|
|
self.assertEqual(actual, expected)
|
|
|
|
|
2020-07-23 13:54:49 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|