1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-13 19:18:56 +00:00

core/tests: rename trezor.io.sdcard test, don't use assert in tests directly

This commit is contained in:
Pavol Rusnak 2019-06-20 17:22:00 +02:00
parent c8bc21a393
commit 4938fb5461
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
3 changed files with 74 additions and 74 deletions

View File

@ -9,9 +9,9 @@ from apps.ripple.sign_tx import get_network_prefix
class TestRippleSerializer(unittest.TestCase):
def test_amount(self):
# https://github.com/ripple/ripple-binary-codec/blob/4581f1b41e712f545ba08be15e188a557c731ecf/test/fixtures/data-driven-tests.json#L2494
assert serialize_amount(0) == unhexlify("4000000000000000")
assert serialize_amount(1) == unhexlify("4000000000000001")
assert serialize_amount(93493429243) == unhexlify("40000015c4a483fb")
self.assertEqual(serialize_amount(0), unhexlify("4000000000000000"))
self.assertEqual(serialize_amount(1), unhexlify("4000000000000001"))
self.assertEqual(serialize_amount(93493429243), unhexlify("40000015c4a483fb"))
with self.assertRaises(ValueError):
serialize_amount(1000000000000000000) # too large
with self.assertRaises(ValueError):
@ -24,41 +24,41 @@ class TestRippleSerializer(unittest.TestCase):
source_address = "r3P9vH81KBayazSTrQj6S25jW6kDb779Gi"
payment = RipplePayment(200000000, "r3kmLJN5D28dHuH8vZNUZpMC43pEHpaocV")
common = RippleSignTx(None, 10, None, 1, None, payment)
assert serialize(common, source_address) == unhexlify(
self.assertEqual(serialize(common, source_address), unhexlify(
"120000240000000161400000000bebc20068400000000000000a811450f97a072f1c4357f1ad84566a609479d927c9428314550fc62003e785dc231a1058a05e56e3f09cf4e6"
)
))
source_address = "r3kmLJN5D28dHuH8vZNUZpMC43pEHpaocV"
payment = RipplePayment(1, "r3P9vH81KBayazSTrQj6S25jW6kDb779Gi")
common = RippleSignTx(None, 99, None, 99, None, payment)
assert serialize(common, source_address) == unhexlify(
self.assertEqual(serialize(common, source_address), unhexlify(
"12000024000000636140000000000000016840000000000000638114550fc62003e785dc231a1058a05e56e3f09cf4e6831450f97a072f1c4357f1ad84566a609479d927c942"
)
))
# https://github.com/ripple/ripple-binary-codec/blob/4581f1b41e712f545ba08be15e188a557c731ecf/test/fixtures/data-driven-tests.json#L1579
source_address = "r9TeThyi5xiuUUrFjtPKZiHcDxs7K9H6Rb"
payment = RipplePayment(25000000, "r4BPgS7DHebQiU31xWELvZawwSG2fSPJ7C")
common = RippleSignTx(None, 10, 0, 2, None, payment)
assert serialize(common, source_address) == unhexlify(
self.assertEqual(serialize(common, source_address), unhexlify(
"120000220000000024000000026140000000017d784068400000000000000a81145ccb151f6e9d603f394ae778acf10d3bece874f68314e851bbbe79e328e43d68f43445368133df5fba5a"
)
))
# https://github.com/ripple/ripple-binary-codec/blob/4581f1b41e712f545ba08be15e188a557c731ecf/test/fixtures/data-driven-tests.json#L1651
source_address = "rGWTUVmm1fB5QUjMYn8KfnyrFNgDiD9H9e"
payment = RipplePayment(200000, "rw71Qs1UYQrSQ9hSgRohqNNQcyjCCfffkQ")
common = RippleSignTx(None, 15, 0, 144, None, payment)
# 201b005ee9ba removed from the test vector because last ledger sequence is not supported
assert serialize(common, source_address) == unhexlify(
self.assertEqual(serialize(common, source_address), unhexlify(
"12000022000000002400000090614000000000030d4068400000000000000f8114aa1bd19d9e87be8069fdbf6843653c43837c03c6831467fe6ec28e0464dd24fb2d62a492aac697cfad02"
)
))
# https://github.com/ripple/ripple-binary-codec/blob/4581f1b41e712f545ba08be15e188a557c731ecf/test/fixtures/data-driven-tests.json#L1732
source_address = "r4BPgS7DHebQiU31xWELvZawwSG2fSPJ7C"
payment = RipplePayment(25000000, "rBqSFEFg2B6GBMobtxnU1eLA1zbNC9NDGM", 4146942154)
common = RippleSignTx(None, 12, 0, 1, None, payment)
assert serialize(common, source_address) == unhexlify(
self.assertEqual(serialize(common, source_address), unhexlify(
"120000220000000024000000012ef72d50ca6140000000017d784068400000000000000c8114e851bbbe79e328e43d68f43445368133df5fba5a831476dac5e814cd4aa74142c3ab45e69a900e637aa2"
)
))
def test_transactions_for_signing(self):
# https://github.com/ripple/ripple-binary-codec/blob/4581f1b41e712f545ba08be15e188a557c731ecf/test/signing-data-encoding-test.js
@ -75,22 +75,22 @@ class TestRippleSerializer(unittest.TestCase):
)
tx = get_network_prefix() + tx
assert tx[0:4] == unhexlify("53545800") # signing prefix
assert tx[4:7] == unhexlify("120000") # transaction type
assert tx[7:12] == unhexlify("2280000000") # flags
assert tx[12:17] == unhexlify("2400000001") # sequence
assert tx[17:26] == unhexlify("6140000000000003e8") # amount
assert tx[26:35] == unhexlify("68400000000000000a") # fee
assert tx[35:70] == unhexlify(
self.assertEqual(tx[0:4], unhexlify("53545800")) # signing prefix
self.assertEqual(tx[4:7], unhexlify("120000")) # transaction type
self.assertEqual(tx[7:12], unhexlify("2280000000")) # flags
self.assertEqual(tx[12:17], unhexlify("2400000001")) # sequence
self.assertEqual(tx[17:26], unhexlify("6140000000000003e8")) # amount
self.assertEqual(tx[26:35], unhexlify("68400000000000000a")) # fee
self.assertEqual(tx[35:70], unhexlify(
"7321ed5f5ac8b98974a3ca843326d9b88cebd0560177b973ee0b149f782cfaa06dc66a"
) # singing pub key
assert tx[70:92] == unhexlify(
)) # signing pub key
self.assertEqual(tx[70:92], unhexlify(
"81145b812c9d57731e27a2da8b1830195f88ef32a3b6"
) # account
assert tx[92:114] == unhexlify(
)) # account
self.assertEqual(tx[92:114], unhexlify(
"8314b5f762798a53d543a014caf8b297cff8f2f937e8"
) # destination
assert len(tx[114:]) == 0 # that's it
)) # destination
self.assertEqual(len(tx[114:]), 0) # that's it
if __name__ == "__main__":

View File

@ -1,48 +0,0 @@
from common import *
from trezor import io
class TestIo(unittest.TestCase):
def test_sdcard_start(self):
sd = io.SDCard()
assert sd.present() is True
def test_sdcard_power(self):
sd = io.SDCard()
x = bytearray(8 * 512)
assert sd.capacity() == 0
assert sd.read(0, x) is False
sd.power(True)
assert sd.capacity() > 0
assert sd.read(0, x) is True
sd.power(False)
assert sd.capacity() == 0
assert sd.read(0, x) is False
def test_sdcard_read(self):
sd = io.SDCard()
x = bytearray(8 * 512)
sd.power(True)
assert sd.read(0, x) is True
sd.power(False)
assert sd.read(0, x) is False
def test_sdcard_read_write(self):
sd = io.SDCard()
r = bytearray(8 * 512)
w0 = bytearray(b'0' * (8 * 512))
w1 = bytearray(b'1' * (8 * 512))
sd.power(True)
assert sd.write(0, w0) is True
assert sd.read(0, r) is True
assert r == w0
assert sd.write(0, w1) is True
assert sd.read(0, r) is True
assert r == w1
sd.power(False)
if __name__ == '__main__':
unittest.main()

View File

@ -0,0 +1,48 @@
from common import *
from trezor import io
class TestTrezorIoSdcard(unittest.TestCase):
def test_start(self):
sd = io.SDCard()
self.assertTrue(sd.present())
def test_power(self):
sd = io.SDCard()
x = bytearray(8 * 512)
self.assertEqual(sd.capacity(), 0)
self.assertFalse(sd.read(0, x))
sd.power(True)
self.assertTrue(sd.capacity() > 0)
self.assertTrue(sd.read(0, x))
sd.power(False)
self.assertEqual(sd.capacity(), 0)
self.assertFalse(sd.read(0, x))
def test_read(self):
sd = io.SDCard()
x = bytearray(8 * 512)
sd.power(True)
self.assertTrue(sd.read(0, x))
sd.power(False)
self.assertFalse(sd.read(0, x))
def test_read_write(self):
sd = io.SDCard()
r = bytearray(8 * 512)
w0 = bytearray(b'0' * (8 * 512))
w1 = bytearray(b'1' * (8 * 512))
sd.power(True)
self.assertTrue(sd.write(0, w0))
self.assertTrue(sd.read(0, r))
self.assertEqual(r, w0)
self.assertTrue(sd.write(0, w1))
self.assertTrue(sd.read(0, r))
self.assertEqual(r, w1)
sd.power(False)
if __name__ == '__main__':
unittest.main()