mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-22 14:28:07 +00:00
add msg_signtx_zcash unittest
This commit is contained in:
parent
883ebf0e03
commit
22faa4cafa
@ -18,6 +18,7 @@ class TrezorTest(unittest.TestCase):
|
||||
self.mnemonic12 = 'alcohol woman abuse must during monitor noble actual mixed trade anger aisle'
|
||||
self.mnemonic18 = 'owner little vague addict embark decide pink prosper true fork panda embody mixture exchange choose canoe electric jewel'
|
||||
self.mnemonic24 = 'dignity pass list indicate nasty swamp pool script soccer toe leaf photo multiply desk host tomato cradle drill spread actor shine dismiss champion exotic'
|
||||
self.mnemonic_all = ' '.join(['all'] * 12)
|
||||
|
||||
self.pin4 = '1234'
|
||||
self.pin6 = '789456'
|
||||
@ -28,6 +29,9 @@ class TrezorTest(unittest.TestCase):
|
||||
print("Setup finished")
|
||||
print("--------------")
|
||||
|
||||
def setup_mnemonic_allallall(self):
|
||||
self.client.load_device_by_mnemonic(mnemonic=self.mnemonic_all, pin='', passphrase_protection=False, label='test', language='english')
|
||||
|
||||
def setup_mnemonic_nopin_nopassphrase(self):
|
||||
self.client.load_device_by_mnemonic(mnemonic=self.mnemonic12, pin='', passphrase_protection=False, label='test', language='english')
|
||||
|
||||
|
55
tests/test_msg_signtx_zcash.py
Normal file
55
tests/test_msg_signtx_zcash.py
Normal file
@ -0,0 +1,55 @@
|
||||
import unittest
|
||||
import common
|
||||
import binascii
|
||||
|
||||
import trezorlib.messages_pb2 as proto
|
||||
import trezorlib.types_pb2 as proto_types
|
||||
from trezorlib.client import CallException
|
||||
from trezorlib.tx_api import TXAPIZcashTestnet
|
||||
|
||||
class TestMsgSigntx(common.TrezorTest):
|
||||
|
||||
def test_one_one_fee(self):
|
||||
self.setup_mnemonic_allallall()
|
||||
|
||||
# tx: 83fc9d26e90ed70f161cbd4b6af6c4cf5d27525dedd5477d054b9a4935cf01d9
|
||||
# input 0: 2.1 TAZ
|
||||
|
||||
inp1 = proto_types.TxInputType(address_n=[2147483692, 2147483649, 2147483648, 0, 0], # tmQoJ3PTXgQLaRRZZYT6xk8XtjRbr2kCqwu
|
||||
# amount=210000000,
|
||||
prev_hash=binascii.unhexlify(b'83fc9d26e90ed70f161cbd4b6af6c4cf5d27525dedd5477d054b9a4935cf01d9'),
|
||||
prev_index=0,
|
||||
)
|
||||
|
||||
out1 = proto_types.TxOutputType(address='tmJ1xYxP8XNTtCoDgvdmQPSrxh5qZJgy65Z',
|
||||
amount=210000000 - 1940,
|
||||
script_type=proto_types.PAYTOADDRESS,
|
||||
)
|
||||
|
||||
with self.client:
|
||||
self.client.set_tx_api(TXAPIZcashTestnet())
|
||||
self.client.set_expected_responses([
|
||||
proto.TxRequest(request_type=proto_types.TXINPUT, details=proto_types.TxRequestDetailsType(request_index=0)),
|
||||
proto.TxRequest(request_type=proto_types.TXMETA, details=proto_types.TxRequestDetailsType(tx_hash=binascii.unhexlify(b"83fc9d26e90ed70f161cbd4b6af6c4cf5d27525dedd5477d054b9a4935cf01d9"))),
|
||||
proto.TxRequest(request_type=proto_types.TXOUTPUT, details=proto_types.TxRequestDetailsType(request_index=0, tx_hash=binascii.unhexlify(b"83fc9d26e90ed70f161cbd4b6af6c4cf5d27525dedd5477d054b9a4935cf01d9"))),
|
||||
proto.TxRequest(request_type=proto_types.TXEXTRADATA, details=proto_types.TxRequestDetailsType(tx_hash=binascii.unhexlify(b"83fc9d26e90ed70f161cbd4b6af6c4cf5d27525dedd5477d054b9a4935cf01d9"),extra_data_offset=0, extra_data_len=1024)),
|
||||
proto.TxRequest(request_type=proto_types.TXEXTRADATA, details=proto_types.TxRequestDetailsType(tx_hash=binascii.unhexlify(b"83fc9d26e90ed70f161cbd4b6af6c4cf5d27525dedd5477d054b9a4935cf01d9"),extra_data_offset=1024, extra_data_len=875)),
|
||||
proto.TxRequest(request_type=proto_types.TXOUTPUT, details=proto_types.TxRequestDetailsType(request_index=0)),
|
||||
proto.ButtonRequest(code=proto_types.ButtonRequest_ConfirmOutput),
|
||||
proto.ButtonRequest(code=proto_types.ButtonRequest_SignTx),
|
||||
proto.TxRequest(request_type=proto_types.TXINPUT, details=proto_types.TxRequestDetailsType(request_index=0)),
|
||||
proto.TxRequest(request_type=proto_types.TXOUTPUT, details=proto_types.TxRequestDetailsType(request_index=0)),
|
||||
proto.TxRequest(request_type=proto_types.TXOUTPUT, details=proto_types.TxRequestDetailsType(request_index=0)),
|
||||
proto.TxRequest(request_type=proto_types.TXFINISHED),
|
||||
])
|
||||
|
||||
(signatures, serialized_tx) = self.client.sign_tx('Zcash Testnet', [inp1, ], [out1, ])
|
||||
|
||||
self.assertEqual(len(signatures), 1)
|
||||
self.assertEqual(binascii.hexlify(signatures[0]), b'3045022100adb008fb056919eeeb61285689048333a0e782208a04d84d1b7bd5eb42f231d6022064a0c903723025d52ee664354b048127d076a68c77d459d1b822168b6db241e6')
|
||||
|
||||
# Accepted by network: tx 1c2a9faa81403643b8d17de905db64bb9c6e50a49ac9cc5688588d676efd5687
|
||||
self.assertEqual(binascii.hexlify(serialized_tx), b'0100000001d901cf35499a4b057d47d5ed5d52275dcfc4f66a4bbd1c160fd70ee9269dfc83000000006b483045022100adb008fb056919eeeb61285689048333a0e782208a04d84d1b7bd5eb42f231d6022064a0c903723025d52ee664354b048127d076a68c77d459d1b822168b6db241e60121030e669acac1f280d1ddf441cd2ba5e97417bf2689e4bbec86df4f831bf9f7ffd0ffffffff01ec50840c000000001976a9145b157a678a10021243307e4bb58f36375aa80e1088ac00000000')
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
@ -681,6 +681,7 @@ class ProtocolMixin(object):
|
||||
msg.outputs_cnt = len(current_tx.bin_outputs)
|
||||
else:
|
||||
msg.outputs_cnt = len(current_tx.outputs)
|
||||
msg.extra_data_len = len(current_tx.extra_data)
|
||||
res = self.call(proto.TxAck(tx=msg))
|
||||
continue
|
||||
|
||||
@ -706,6 +707,13 @@ class ProtocolMixin(object):
|
||||
res = self.call(proto.TxAck(tx=msg))
|
||||
continue
|
||||
|
||||
elif res.request_type == types.TXEXTRADATA:
|
||||
o, l = res.details.extra_data_offset, res.details.extra_data_len
|
||||
msg = types.TransactionType()
|
||||
msg.extra_data = current_tx.extra_data[o:o + l]
|
||||
res = self.call(proto.TxAck(tx=msg))
|
||||
continue
|
||||
|
||||
if None in signatures:
|
||||
raise Exception("Some signatures are missing!")
|
||||
|
||||
|
@ -11,7 +11,7 @@ def fetch_json(url):
|
||||
except:
|
||||
raise Exception('URL error: %s' % url)
|
||||
|
||||
def insight_tx(url, rawdata=False):
|
||||
def insight_tx(url, rawdata=False, zcash=False):
|
||||
if not rawdata:
|
||||
data = fetch_json(url)
|
||||
else:
|
||||
@ -40,6 +40,17 @@ def insight_tx(url, rawdata=False):
|
||||
o.amount = int(Decimal(str(vout['value'])) * 100000000)
|
||||
o.script_pubkey = binascii.unhexlify(vout['scriptPubKey']['hex'])
|
||||
|
||||
if zcash:
|
||||
if t.version == 2:
|
||||
joinsplit_cnt = len(data['vjoinsplit'])
|
||||
if joinsplit_cnt == 0:
|
||||
t.extra_data =b'\x00'
|
||||
else:
|
||||
extra_data_len = 1 + joinsplit_cnt * 1802 + 32 + 64 # we assume cnt < 253, so we can treat varIntLen(cnt) as 1
|
||||
raw = fetch_json(url.replace('/tx/', '/rawtx/'))
|
||||
raw = binascii.unhexlify(raw['rawtx'])
|
||||
t.extra_data = raw[-extra_data_len:]
|
||||
|
||||
return t
|
||||
|
||||
def smartbit_tx(url, rawdata=False):
|
||||
@ -96,3 +107,10 @@ class TXAPISegnet(object):
|
||||
def get_tx(self, txhash):
|
||||
url = 'https://segnet-api.smartbit.com.au/v1/blockchain/tx/%s' % txhash.decode('ascii')
|
||||
return smartbit_tx(url)
|
||||
|
||||
class TXAPIZcashTestnet(object):
|
||||
|
||||
# @filecache(DAY)
|
||||
def get_tx(self, txhash):
|
||||
url = 'https://explorer.testnet.z.cash/api/tx/%s' % txhash.decode('ascii')
|
||||
return insight_tx(url, zcash=True)
|
||||
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user