1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-22 23:48:12 +00:00

core/tests: Fix unit tests to work with BasicApprover in sign_tx.

This commit is contained in:
Andrew Kozlik 2020-07-17 17:39:43 +02:00 committed by Andrew Kozlik
parent d6ee542deb
commit 472e853f0a
10 changed files with 56 additions and 33 deletions

View File

@ -1,6 +1,7 @@
from common import *
from apps.bitcoin.scripts import output_derive_script
from apps.bitcoin.sign_tx.approvers import BasicApprover
from apps.bitcoin.sign_tx.bitcoin import Bitcoin
from apps.bitcoin.writers import get_tx_hash
from apps.common import coins
@ -47,7 +48,7 @@ class TestSegwitBip143NativeP2WPKH(unittest.TestCase):
def test_prevouts(self):
coin = coins.by_name(self.tx.coin_name)
bip143 = Bitcoin(self.tx, None, coin)
bip143 = Bitcoin(self.tx, None, coin, BasicApprover(self.tx, coin))
bip143.hash143_add_input(self.inp1)
bip143.hash143_add_input(self.inp2)
prevouts_hash = get_tx_hash(bip143.h_prevouts, double=coin.sign_hash_double)
@ -55,7 +56,7 @@ class TestSegwitBip143NativeP2WPKH(unittest.TestCase):
def test_sequence(self):
coin = coins.by_name(self.tx.coin_name)
bip143 = Bitcoin(self.tx, None, coin)
bip143 = Bitcoin(self.tx, None, coin, BasicApprover(self.tx, coin))
bip143.hash143_add_input(self.inp1)
bip143.hash143_add_input(self.inp2)
sequence_hash = get_tx_hash(bip143.h_sequence, double=coin.sign_hash_double)
@ -65,7 +66,7 @@ class TestSegwitBip143NativeP2WPKH(unittest.TestCase):
seed = bip39.seed('alcohol woman abuse must during monitor noble actual mixed trade anger aisle', '')
coin = coins.by_name(self.tx.coin_name)
bip143 = Bitcoin(self.tx, None, coin)
bip143 = Bitcoin(self.tx, None, coin, BasicApprover(self.tx, coin))
for txo in [self.out1, self.out2]:
txo_bin = TxOutputBinType()
@ -80,7 +81,7 @@ class TestSegwitBip143NativeP2WPKH(unittest.TestCase):
seed = bip39.seed('alcohol woman abuse must during monitor noble actual mixed trade anger aisle', '')
coin = coins.by_name(self.tx.coin_name)
bip143 = Bitcoin(self.tx, None, coin)
bip143 = Bitcoin(self.tx, None, coin, BasicApprover(self.tx, coin))
bip143.hash143_add_input(self.inp1)
bip143.hash143_add_input(self.inp2)

View File

@ -1,6 +1,7 @@
from common import *
from apps.bitcoin.scripts import output_derive_script
from apps.bitcoin.sign_tx.approvers import BasicApprover
from apps.bitcoin.sign_tx.bitcoin import Bitcoin
from apps.bitcoin.writers import get_tx_hash
from apps.common import coins
@ -39,14 +40,14 @@ class TestSegwitBip143(unittest.TestCase):
def test_bip143_prevouts(self):
coin = coins.by_name(self.tx.coin_name)
bip143 = Bitcoin(self.tx, None, coin)
bip143 = Bitcoin(self.tx, None, coin, BasicApprover(self.tx, coin))
bip143.hash143_add_input(self.inp1)
prevouts_hash = get_tx_hash(bip143.h_prevouts, double=coin.sign_hash_double)
self.assertEqual(hexlify(prevouts_hash), b'b0287b4a252ac05af83d2dcef00ba313af78a3e9c329afa216eb3aa2a7b4613a')
def test_bip143_sequence(self):
coin = coins.by_name(self.tx.coin_name)
bip143 = Bitcoin(self.tx, None, coin)
bip143 = Bitcoin(self.tx, None, coin, BasicApprover(self.tx, coin))
bip143.hash143_add_input(self.inp1)
sequence_hash = get_tx_hash(bip143.h_sequence, double=coin.sign_hash_double)
self.assertEqual(hexlify(sequence_hash), b'18606b350cd8bf565266bc352f0caddcf01e8fa789dd8a15386327cf8cabe198')
@ -54,7 +55,7 @@ class TestSegwitBip143(unittest.TestCase):
def test_bip143_outputs(self):
seed = bip39.seed('alcohol woman abuse must during monitor noble actual mixed trade anger aisle', '')
coin = coins.by_name(self.tx.coin_name)
bip143 = Bitcoin(self.tx, None, coin)
bip143 = Bitcoin(self.tx, None, coin, BasicApprover(self.tx, coin))
for txo in [self.out1, self.out2]:
txo_bin = TxOutputBinType()
@ -68,7 +69,7 @@ class TestSegwitBip143(unittest.TestCase):
def test_bip143_preimage_testdata(self):
seed = bip39.seed('alcohol woman abuse must during monitor noble actual mixed trade anger aisle', '')
coin = coins.by_name(self.tx.coin_name)
bip143 = Bitcoin(self.tx, None, coin)
bip143 = Bitcoin(self.tx, None, coin, BasicApprover(self.tx, coin))
bip143.hash143_add_input(self.inp1)
for txo in [self.out1, self.out2]:
txo_bin = TxOutputBinType()

View File

@ -20,6 +20,7 @@ from apps.common import coins
from apps.common.keychain import Keychain
from apps.bitcoin.keychain import get_namespaces_for_coin
from apps.bitcoin.sign_tx import helpers, bitcoin
from apps.bitcoin.sign_tx.approvers import BasicApprover
EMPTY_SERIALIZED = TxRequestSerializedType(serialized_tx=bytearray())
@ -77,9 +78,6 @@ class TestSignSegwitTxNativeP2WPKH(unittest.TestCase):
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(inputs=[inp1])),
helpers.UiConfirmForeignAddress(address_n=inp1.address_n),
True,
TxRequest(request_type=TXMETA, details=TxRequestDetailsType(request_index=None, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED),
TxAck(tx=ptx1),
@ -92,6 +90,9 @@ class TestSignSegwitTxNativeP2WPKH(unittest.TestCase):
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(bin_outputs=[pout2])),
helpers.UiConfirmForeignAddress(address_n=inp1.address_n),
True,
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(outputs=[out1])),
@ -146,7 +147,8 @@ class TestSignSegwitTxNativeP2WPKH(unittest.TestCase):
ns = get_namespaces_for_coin(coin)
keychain = Keychain(seed, coin.curve_name, ns)
signer = bitcoin.Bitcoin(tx, keychain, coin).signer()
approver = BasicApprover(tx, coin)
signer = bitcoin.Bitcoin(tx, keychain, coin, approver).signer()
for request, response in chunks(messages, 2):
res = signer.send(request)
self.assertEqual(res, response)
@ -202,9 +204,6 @@ class TestSignSegwitTxNativeP2WPKH(unittest.TestCase):
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(inputs=[inp1])),
helpers.UiConfirmForeignAddress(address_n=inp1.address_n),
True,
TxRequest(request_type=TXMETA, details=TxRequestDetailsType(request_index=None, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED),
TxAck(tx=ptx1),
@ -217,6 +216,9 @@ class TestSignSegwitTxNativeP2WPKH(unittest.TestCase):
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(bin_outputs=[pout2])),
helpers.UiConfirmForeignAddress(address_n=inp1.address_n),
True,
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(outputs=[out1])),
@ -269,7 +271,8 @@ class TestSignSegwitTxNativeP2WPKH(unittest.TestCase):
ns = get_namespaces_for_coin(coin)
keychain = Keychain(seed, coin.curve_name, ns)
signer = bitcoin.Bitcoin(tx, keychain, coin).signer()
approver = BasicApprover(tx, coin)
signer = bitcoin.Bitcoin(tx, keychain, coin, approver).signer()
for request, response in chunks(messages, 2):
self.assertEqual(signer.send(request), response)
with self.assertRaises(StopIteration):
@ -317,9 +320,6 @@ class TestSignSegwitTxNativeP2WPKH(unittest.TestCase):
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(inputs=[inp1])),
helpers.UiConfirmForeignAddress(address_n=inp1.address_n),
True,
TxRequest(request_type=TXMETA, details=TxRequestDetailsType(request_index=None, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED),
TxAck(tx=ptx1),
@ -332,6 +332,9 @@ class TestSignSegwitTxNativeP2WPKH(unittest.TestCase):
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(bin_outputs=[pout2])),
helpers.UiConfirmForeignAddress(address_n=inp1.address_n),
True,
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(outputs=[out1])),
None
@ -339,7 +342,8 @@ class TestSignSegwitTxNativeP2WPKH(unittest.TestCase):
ns = get_namespaces_for_coin(coin)
keychain = Keychain(seed, coin.curve_name, ns)
signer = bitcoin.Bitcoin(tx, keychain, coin).signer()
approver = BasicApprover(tx, coin)
signer = bitcoin.Bitcoin(tx, keychain, coin, approver).signer()
for request, response in chunks(messages, 2):
if response is None:
with self.assertRaises(wire.DataError):

View File

@ -19,6 +19,7 @@ from apps.common import coins
from apps.common.keychain import Keychain
from apps.bitcoin.keychain import get_namespaces_for_coin
from apps.bitcoin.sign_tx import bitcoinlike, helpers
from apps.bitcoin.sign_tx.approvers import BasicApprover
EMPTY_SERIALIZED = TxRequestSerializedType(serialized_tx=bytearray())
@ -147,7 +148,8 @@ class TestSignSegwitTxNativeP2WPKH_GRS(unittest.TestCase):
ns = get_namespaces_for_coin(coin)
keychain = Keychain(seed, coin.curve_name, ns)
signer = bitcoinlike.Bitcoinlike(tx, keychain, coin).signer()
approver = BasicApprover(tx, coin)
signer = bitcoinlike.Bitcoinlike(tx, keychain, coin, approver).signer()
for request, response in chunks(messages, 2):
self.assertEqual(signer.send(request), response)
with self.assertRaises(StopIteration):
@ -269,7 +271,8 @@ class TestSignSegwitTxNativeP2WPKH_GRS(unittest.TestCase):
ns = get_namespaces_for_coin(coin)
keychain = Keychain(seed, coin.curve_name, ns)
signer = bitcoinlike.Bitcoinlike(tx, keychain, coin).signer()
approver = BasicApprover(tx, coin)
signer = bitcoinlike.Bitcoinlike(tx, keychain, coin, approver).signer()
for request, response in chunks(messages, 2):
self.assertEqual(signer.send(request), response)
with self.assertRaises(StopIteration):

View File

@ -20,6 +20,7 @@ from apps.common import coins
from apps.common.keychain import Keychain
from apps.bitcoin.keychain import get_namespaces_for_coin
from apps.bitcoin.sign_tx import bitcoin, helpers
from apps.bitcoin.sign_tx.approvers import BasicApprover
EMPTY_SERIALIZED = TxRequestSerializedType(serialized_tx=bytearray())
@ -143,7 +144,8 @@ class TestSignSegwitTxP2WPKHInP2SH(unittest.TestCase):
ns = get_namespaces_for_coin(coin)
keychain = Keychain(seed, coin.curve_name, ns)
signer = bitcoin.Bitcoin(tx, keychain, coin).signer()
approver = BasicApprover(tx, coin)
signer = bitcoin.Bitcoin(tx, keychain, coin, approver).signer()
for request, response in chunks(messages, 2):
self.assertEqual(signer.send(request), response)
with self.assertRaises(StopIteration):
@ -273,7 +275,8 @@ class TestSignSegwitTxP2WPKHInP2SH(unittest.TestCase):
ns = get_namespaces_for_coin(coin)
keychain = Keychain(seed, coin.curve_name, ns)
signer = bitcoin.Bitcoin(tx, keychain, coin).signer()
approver = BasicApprover(tx, coin)
signer = bitcoin.Bitcoin(tx, keychain, coin, approver).signer()
for request, response in chunks(messages, 2):
self.assertEqual(signer.send(request), response)
with self.assertRaises(StopIteration):
@ -355,7 +358,8 @@ class TestSignSegwitTxP2WPKHInP2SH(unittest.TestCase):
ns = get_namespaces_for_coin(coin)
keychain = Keychain(seed, coin.curve_name, ns)
signer = bitcoin.Bitcoin(tx, keychain, coin).signer()
approver = BasicApprover(tx, coin)
signer = bitcoin.Bitcoin(tx, keychain, coin, approver).signer()
i = 0
messages_count = int(len(messages) / 2)
for request, response in chunks(messages, 2):

View File

@ -19,6 +19,7 @@ from apps.common import coins
from apps.common.keychain import Keychain
from apps.bitcoin.keychain import get_namespaces_for_coin
from apps.bitcoin.sign_tx import bitcoinlike, helpers
from apps.bitcoin.sign_tx.approvers import BasicApprover
EMPTY_SERIALIZED = TxRequestSerializedType(serialized_tx=bytearray())
@ -147,7 +148,8 @@ class TestSignSegwitTxP2WPKHInP2SH_GRS(unittest.TestCase):
ns = get_namespaces_for_coin(coin)
keychain = Keychain(seed, coin.curve_name, ns)
signer = bitcoinlike.Bitcoinlike(tx, keychain, coin).signer()
approver = BasicApprover(tx, coin)
signer = bitcoinlike.Bitcoinlike(tx, keychain, coin, approver).signer()
for request, response in chunks(messages, 2):
self.assertEqual(signer.send(request), response)
with self.assertRaises(StopIteration):
@ -277,7 +279,8 @@ class TestSignSegwitTxP2WPKHInP2SH_GRS(unittest.TestCase):
ns = get_namespaces_for_coin(coin)
keychain = Keychain(seed, coin.curve_name, ns)
signer = bitcoinlike.Bitcoinlike(tx, keychain, coin).signer()
approver = BasicApprover(tx, coin)
signer = bitcoinlike.Bitcoinlike(tx, keychain, coin, approver).signer()
for request, response in chunks(messages, 2):
self.assertEqual(signer.send(request), response)
with self.assertRaises(StopIteration):

View File

@ -17,6 +17,7 @@ from trezor.messages import OutputScriptType
from apps.common import coins
from apps.common.keychain import Keychain
from apps.bitcoin.sign_tx import bitcoin, helpers
from apps.bitcoin.sign_tx.approvers import BasicApprover
EMPTY_SERIALIZED = TxRequestSerializedType(serialized_tx=bytearray())
@ -140,8 +141,6 @@ class TestSignTxFeeThreshold(unittest.TestCase):
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(inputs=[inp1])),
helpers.UiConfirmForeignAddress(address_n=inp1.address_n),
True,
TxRequest(request_type=TXMETA, details=TxRequestDetailsType(request_index=None, tx_hash=unhexlify('d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882')), serialized=EMPTY_SERIALIZED),
TxAck(tx=ptx1),
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=unhexlify('d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882')), serialized=EMPTY_SERIALIZED),
@ -150,6 +149,8 @@ class TestSignTxFeeThreshold(unittest.TestCase):
TxAck(tx=TransactionType(inputs=[pinp2])),
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=unhexlify('d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882')), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(bin_outputs=[pout1])),
helpers.UiConfirmForeignAddress(address_n=inp1.address_n),
True,
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(outputs=[out1])),
helpers.UiConfirmOutput(out1, coin_bitcoin),
@ -162,7 +163,8 @@ class TestSignTxFeeThreshold(unittest.TestCase):
seed = bip39.seed('alcohol woman abuse must during monitor noble actual mixed trade anger aisle', '')
keychain = Keychain(seed, coin_bitcoin.curve_name, [[]])
signer = bitcoin.Bitcoin(tx, keychain, coin_bitcoin).signer()
approver = BasicApprover(tx, coin_bitcoin)
signer = bitcoin.Bitcoin(tx, keychain, coin_bitcoin, approver).signer()
for request, response in chunks(messages, 2):
res = signer.send(request)
self.assertEqual(res, response)

View File

@ -18,6 +18,7 @@ from apps.common import coins
from apps.common.keychain import Keychain
from apps.bitcoin.keychain import get_namespaces_for_coin
from apps.bitcoin.sign_tx import bitcoin, helpers
from apps.bitcoin.sign_tx.approvers import BasicApprover
EMPTY_SERIALIZED = TxRequestSerializedType(serialized_tx=bytearray())
@ -100,7 +101,8 @@ class TestSignTx(unittest.TestCase):
seed = bip39.seed('alcohol woman abuse must during monitor noble actual mixed trade anger aisle', '')
ns = get_namespaces_for_coin(coin_bitcoin)
keychain = Keychain(seed, coin_bitcoin.curve_name, ns)
signer = bitcoin.Bitcoin(tx, keychain, coin_bitcoin).signer()
approver = BasicApprover(tx, coin_bitcoin)
signer = bitcoin.Bitcoin(tx, keychain, coin_bitcoin, approver).signer()
for request, response in chunks(messages, 2):
res = signer.send(request)

View File

@ -18,6 +18,7 @@ from apps.common import coins
from apps.common.keychain import Keychain
from apps.bitcoin.keychain import get_namespaces_for_coin
from apps.bitcoin.sign_tx import bitcoinlike, helpers
from apps.bitcoin.sign_tx.approvers import BasicApprover
EMPTY_SERIALIZED = TxRequestSerializedType(serialized_tx=bytearray())
@ -96,7 +97,8 @@ class TestSignTx_GRS(unittest.TestCase):
seed = bip39.seed(' '.join(['all'] * 12), '')
ns = get_namespaces_for_coin(coin)
keychain = Keychain(seed, coin.curve_name, ns)
signer = bitcoinlike.Bitcoinlike(tx, keychain, coin).signer()
approver = BasicApprover(tx, coin)
signer = bitcoinlike.Bitcoinlike(tx, keychain, coin, approver).signer()
for request, response in chunks(messages, 2):
self.assertEqual(signer.send(request), response)
with self.assertRaises(StopIteration):

View File

@ -6,6 +6,7 @@ from trezor.messages.TxOutputBinType import TxOutputBinType
from apps.common import coins
from apps.bitcoin.writers import get_tx_hash
from apps.bitcoin.sign_tx.approvers import BasicApprover
if not utils.BITCOIN_ONLY:
from apps.bitcoin.sign_tx.zcash import Zcashlike
@ -190,7 +191,7 @@ class TestZcashZip243(unittest.TestCase):
branch_id=v["branch_id"],
)
zip243 = Zcashlike(tx, None, coin)
zip243 = Zcashlike(tx, None, coin, BasicApprover(tx, coin))
for i in v["inputs"]:
txi = TxInputType()