1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-22 14:28:07 +00:00

SignTx test

This commit is contained in:
slush 2013-04-05 17:13:57 +02:00
parent a6f0657de7
commit 4b9a6675c7
2 changed files with 156 additions and 16 deletions

View File

@ -2,9 +2,17 @@ import sys
sys.path = ['../',] + sys.path
from bitkeylib.transport_pipe import PipeTransport
from bitkeylib.transport_hid import HidTransport
from bitkeylib.transport_socket import SocketTransportClient
TRANSPORT = PipeTransport
TRANSPORT_ARGS = ('../../bitkey-python/pipe', False)
#TRANSPORT = PipeTransport
#TRANSPORT_ARGS = ('../../bitkey-python/pipe', False)
TRANSPORT = HidTransport
TRANSPORT_ARGS = ('0x10c4:0xea80:000868D3', False)
#TRANSPORT = SocketTransportClient
#TRANSPORT_ARGS = ('trezor.dyn:3000', False)
DEBUG_TRANSPORT = PipeTransport
DEBUG_TRANSPORT_ARGS = ('../../bitkey-python/pipe.debug', False)
#DEBUG_TRANSPORT = PipeTransport
#DEBUG_TRANSPORT_ARGS = ('../../bitkey-python/pipe.debug', False)
DEBUG_TRANSPORT = SocketTransportClient
DEBUG_TRANSPORT_ARGS = ('trezor.dyn:2000', False)

View File

@ -1,16 +1,64 @@
import unittest
import common
import binascii
import bitkeylib.bitkey_pb2 as proto
'''
./electrum -w ~/.electrum-bitkey mktx 1FQVPnjrbkPWeA8poUoEnX9U3n9DyhAVtv 0.001
--fromaddr 13jqMdrZAzMYkaFqHGv5GbJavdZpoKDkSL --changeaddr 17GpAFnkHRjWKePkX4kxHaHy49V8EHTr7i --fee 0.0005
01000000012de70f7d6ffed0db70f8882f3fca90db9bb09f0e99bce27468c23d3c994fcd56
010000008b4830450221009b985e14d53cfeed3496846db6ddaa77a0206138d0df4c2ccd3b
759e91bae3e1022004c76e10f99ccac8ced761719181a96bae25a74829eab3ecb8f29eb07f
e18f7e01410436ae8595f03a7324d1d1482ede8560a4508c767fbc662559482d5759b32209
a62964699995f6e018cfbeb7a71a66d4c64fa38875d79ead0a9ac66f59c1c8b3a3ffffffff
0250c30000000000001976a91444ce5c6789b0bb0e8a9ab9a4769fe181cb274c4688aca086
0100000000001976a9149e03078026388661b197129a43f0f64f88379ce688ac00000000
'''
class TestSignTx(common.BitkeyTest):
def test_signtx(self):
expected_tx = '01000000012de70f7d6ffed0db70f8882f3fca90db9bb09f0e99bce27468c23d3c994fcd56' \
'010000008b4830450221009b985e14d53cfeed3496846db6ddaa77a0206138d0df4c2ccd3b' \
'759e91bae3e1022004c76e10f99ccac8ced761719181a96bae25a74829eab3ecb8f29eb07f' \
'e18f7e01410436ae8595f03a7324d1d1482ede8560a4508c767fbc662559482d5759b32209' \
'a62964699995f6e018cfbeb7a71a66d4c64fa38875d79ead0a9ac66f59c1c8b3a3ffffffff' \
'0250c30000000000001976a91444ce5c6789b0bb0e8a9ab9a4769fe181cb274c4688aca086' \
'0100000000001976a9149e03078026388661b197129a43f0f64f88379ce688ac00000000'
inp1 = proto.TxInput(index=0,
address_n=[1,0],
amount=200000, # 0.002 BTC
prev_hash=binascii.unhexlify('56cd4f993c3dc26874e2bc990e9fb09bdb90ca3f2f88f870dbd0fe6f7d0fe72d'),
prev_index=1,
#script_sig=
)
out1 = proto.TxOutput(index=0,
address='17GpAFnkHRjWKePkX4kxHaHy49V8EHTr7i',
address_n=[0, 1],
amount=50000, # 0.0005 BTC
script_type=proto.PAYTOADDRESS,
#script_args=
)
out2 = proto.TxOutput(index=1,
address='1FQVPnjrbkPWeA8poUoEnX9U3n9DyhAVtv',
#address_n=[],
amount=100000, # 0.001 BTC
script_type=proto.PAYTOADDRESS,
#script_args=
)
print binascii.hexlify(self.bitkey.sign_tx([inp1], [out1, out2])[1])
'''
def test_workflow(self):
inp1 = proto.TxInput(index=0,
address_n=[1,0],
amount=100000000,
prev_hash='prevhash1234354346543456543654',
prev_index=11,
#script_sig=
)
inp2 = proto.TxInput(index=1,
@ -18,15 +66,12 @@ class TestSignTx(common.BitkeyTest):
amount=100000000,
prev_hash='prevhash2222254346543456543654',
prev_index=11,
#script_sig=
)
out1 = proto.TxOutput(index=0,
address='1BitkeyP2nDd5oa647AjvBbbwST54W5Zmx',
#address_n=[],
amount=100000000,
script_type=proto.PAYTOADDRESS,
#script_args=
)
out2 = proto.TxOutput(index=1,
@ -37,14 +82,101 @@ class TestSignTx(common.BitkeyTest):
#script_args=
)
out3 = proto.TxOutput(index=2,
address='1MVgq4XaMX7PmohkYzFEisH1D7uxTiPbFK',
address_n=[2, 1],
amount=100000000,
script_type=proto.PAYTOADDRESS,
#script_args=
)
print self.bitkey.sign_tx([inp1, inp2], [out1, out2, out3])
serialized = ''
# Prepare and send initial message
tx = proto.SignTx()
tx.algo = proto.ELECTRUM
tx.random = self.bitkey._get_local_entropy()
tx.inputs_count = 2
tx.outputs_count = 2
res = self.bitkey.call(tx)
self.assertIsInstance(res, proto.TxRequest)
self.assertEqual(res.request_type, proto.TXINPUT)
self.assertEqual(res.request_index, 0)
self.assertEqual(res.signature, '')
self.assertEqual(res.serialized_tx, '')
# FIRST SIGNATURE
res = self.bitkey.call(inp1)
self.assertIsInstance(res, proto.TxRequest)
self.assertEqual(res.request_type, proto.TXINPUT)
self.assertEqual(res.request_index, 1)
self.assertEqual(res.signature, '')
self.assertEqual(res.serialized_tx, '')
res = self.bitkey.call(inp2)
self.assertIsInstance(res, proto.TxRequest)
self.assertEqual(res.request_type, proto.TXOUTPUT)
self.assertEqual(res.request_index, 0)
self.assertEqual(res.signature, '')
self.assertEqual(res.serialized_tx, '')
res = self.bitkey.call(out1)
self.assertIsInstance(res, proto.TxRequest)
self.assertEqual(res.request_type, proto.TXOUTPUT)
self.assertEqual(res.request_index, 1)
self.assertEqual(res.signature, '')
self.assertEqual(res.serialized_tx, '')
res = self.bitkey.call(out2)
self.assertIsInstance(res, proto.TxRequest)
self.assertEqual(res.request_type, proto.TXINPUT)
self.assertEqual(res.request_index, 0)
self.assertNotEqual(res.signature, '')
self.assertNotEqual(res.serialized_tx, '')
serialized += res.serialized_tx
# SECOND SIGNATURE
res = self.bitkey.call(inp1)
self.assertIsInstance(res, proto.TxRequest)
self.assertEqual(res.request_type, proto.TXINPUT)
self.assertEqual(res.request_index, 1)
self.assertEqual(res.signature, '')
self.assertEqual(res.serialized_tx, '')
res = self.bitkey.call(inp2)
self.assertIsInstance(res, proto.TxRequest)
self.assertEqual(res.request_type, proto.TXOUTPUT)
self.assertEqual(res.request_index, 0)
self.assertEqual(res.signature, '')
self.assertEqual(res.serialized_tx, '')
res = self.bitkey.call(out1)
self.assertIsInstance(res, proto.TxRequest)
self.assertEqual(res.request_type, proto.TXOUTPUT)
self.assertEqual(res.request_index, 1)
self.assertEqual(res.signature, '')
self.assertEqual(res.serialized_tx, '')
res = self.bitkey.call(out2)
self.assertIsInstance(res, proto.TxRequest)
self.assertEqual(res.request_type, proto.TXOUTPUT)
self.assertEqual(res.request_index, 0)
self.assertNotEqual(res.signature, '')
self.assertNotEqual(res.serialized_tx, '')
serialized += res.serialized_tx
# FINALIZING OUTPUTS
res = self.bitkey.call(out1)
self.assertIsInstance(res, proto.TxRequest)
self.assertEqual(res.request_type, proto.TXOUTPUT)
self.assertEqual(res.request_index, 1)
self.assertEqual(res.signature, '')
self.assertNotEqual(res.serialized_tx, '')
serialized += res.serialized_tx
res = self.bitkey.call(out2)
self.assertIsInstance(res, proto.TxRequest)
self.assertEqual(res.request_type, proto.TXOUTPUT)
self.assertEqual(res.request_index, -1)
self.assertEqual(res.signature, '')
self.assertNotEqual(res.serialized_tx, '')
serialized += res.serialized_tx
print binascii.hexlify(serialized)
'''
if __name__ == '__main__':
unittest.main()