mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-28 09:08:07 +00:00
445f56d387
- core/bitcoin: move common files to the app's root - core/bitcoin: use require_confirm instead of confirm - core: move bitcoin unrelated functions from 'bitcoin' to a new 'misc' app - core/bitcoin: use relative imports inside the app - core: rename wallet app to bitcoin - core/wallet: replace SigningErrors and the other exception classes with wire.Errors
53 lines
1.6 KiB
Python
53 lines
1.6 KiB
Python
from common import *
|
|
|
|
from trezor.messages.TxInputType import TxInputType
|
|
from trezor.messages import InputScriptType
|
|
|
|
from apps.bitcoin import writers
|
|
|
|
|
|
class TestWriters(unittest.TestCase):
|
|
def test_tx_input(self):
|
|
inp = TxInputType(
|
|
address_n=[0],
|
|
amount=390000,
|
|
prev_hash=unhexlify(
|
|
"d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882"
|
|
),
|
|
prev_index=0,
|
|
sequence=0xffffffff,
|
|
script_sig=b"0123456789",
|
|
)
|
|
|
|
b = bytearray()
|
|
writers.write_tx_input(b, inp, inp.script_sig)
|
|
self.assertEqual(len(b), 32 + 4 + 1 + 10 + 4)
|
|
|
|
for bad_prevhash in (b"", b"x", b"hello", b"x" * 33):
|
|
inp.prev_hash = bad_prevhash
|
|
self.assertRaises(AssertionError, writers.write_tx_input, b, inp, inp.script_sig)
|
|
|
|
def test_tx_input_check(self):
|
|
inp = TxInputType(
|
|
address_n=[0],
|
|
amount=390000,
|
|
prev_hash=unhexlify(
|
|
"d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882"
|
|
),
|
|
prev_index=0,
|
|
script_type=InputScriptType.SPENDWITNESS,
|
|
sequence=0xffffffff,
|
|
script_sig=b"0123456789",
|
|
)
|
|
|
|
b = bytearray()
|
|
writers.write_tx_input_check(b, inp)
|
|
self.assertEqual(len(b), 32 + 4 + 4 + 4 + 4 + 4 + 8)
|
|
|
|
for bad_prevhash in (b"", b"x", b"hello", b"x" * 33):
|
|
inp.prev_hash = bad_prevhash
|
|
self.assertRaises(AssertionError, writers.write_tx_input_check, b, inp)
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|