mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-23 06:48:16 +00:00
tests: adapt tests to new APIs
This commit is contained in:
parent
9caea6d413
commit
620e48e4d0
@ -16,15 +16,12 @@
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from trezorlib import coins, debuglink, device, tx_api
|
from trezorlib import coins, debuglink, device
|
||||||
from trezorlib.debuglink import TrezorClientDebugLink
|
from trezorlib.debuglink import TrezorClientDebugLink
|
||||||
from trezorlib.messages.PassphraseSourceType import HOST as PASSPHRASE_ON_HOST
|
from trezorlib.messages.PassphraseSourceType import HOST as PASSPHRASE_ON_HOST
|
||||||
|
|
||||||
from . import conftest
|
from . import conftest
|
||||||
|
|
||||||
tests_dir = os.path.dirname(os.path.abspath(__file__))
|
|
||||||
tx_api.cache_dir = os.path.join(tests_dir, "../txcache")
|
|
||||||
|
|
||||||
|
|
||||||
class TrezorTest:
|
class TrezorTest:
|
||||||
# fmt: off
|
# fmt: off
|
||||||
@ -42,7 +39,6 @@ class TrezorTest:
|
|||||||
def setup_method(self, method):
|
def setup_method(self, method):
|
||||||
wirelink = conftest.get_device()
|
wirelink = conftest.get_device()
|
||||||
self.client = TrezorClientDebugLink(wirelink)
|
self.client = TrezorClientDebugLink(wirelink)
|
||||||
self.client.set_tx_api(coins.tx_api["Bitcoin"])
|
|
||||||
# self.client.set_buttonwait(3)
|
# self.client.set_buttonwait(3)
|
||||||
|
|
||||||
device.wipe(self.client)
|
device.wipe(self.client)
|
||||||
|
@ -19,7 +19,7 @@ import os
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from trezorlib import coins, debuglink, log
|
from trezorlib import debuglink, log
|
||||||
from trezorlib.debuglink import TrezorClientDebugLink
|
from trezorlib.debuglink import TrezorClientDebugLink
|
||||||
from trezorlib.device import wipe as wipe_device
|
from trezorlib.device import wipe as wipe_device
|
||||||
from trezorlib.transport import enumerate_devices, get_transport
|
from trezorlib.transport import enumerate_devices, get_transport
|
||||||
@ -54,7 +54,6 @@ def device_version():
|
|||||||
def client():
|
def client():
|
||||||
wirelink = get_device()
|
wirelink = get_device()
|
||||||
client = TrezorClientDebugLink(wirelink)
|
client = TrezorClientDebugLink(wirelink)
|
||||||
client.set_tx_api(coins.tx_api["Bitcoin"])
|
|
||||||
wipe_device(client)
|
wipe_device(client)
|
||||||
client.transport.session_begin()
|
client.transport.session_begin()
|
||||||
|
|
||||||
|
@ -18,10 +18,11 @@ import pytest
|
|||||||
|
|
||||||
from trezorlib import btc, messages as proto
|
from trezorlib import btc, messages as proto
|
||||||
from trezorlib.coins import tx_api
|
from trezorlib.coins import tx_api
|
||||||
from trezorlib.tools import H_, CallException, parse_path
|
from trezorlib.tools import H_, CallException, parse_path, btc_hash
|
||||||
|
|
||||||
from .common import TrezorTest
|
from .common import TrezorTest
|
||||||
from .conftest import TREZOR_VERSION
|
from .conftest import TREZOR_VERSION
|
||||||
|
from ..support.tx_cache import tx_cache
|
||||||
|
|
||||||
TXHASH_157041 = bytes.fromhex(
|
TXHASH_157041 = bytes.fromhex(
|
||||||
"1570416eb4302cf52979afd5e6909e37d8fdd874301f7cc87e547e509cb1caa6"
|
"1570416eb4302cf52979afd5e6909e37d8fdd874301f7cc87e547e509cb1caa6"
|
||||||
@ -68,7 +69,7 @@ def check_sign_tx(client, coin_name, inputs, outputs, fee_too_high=False, failur
|
|||||||
__tracebackhide__ = True
|
__tracebackhide__ = True
|
||||||
expected_responses = []
|
expected_responses = []
|
||||||
|
|
||||||
txes = tx_api[coin_name]
|
txes = tx_cache(coin_name)
|
||||||
|
|
||||||
t = proto.RequestType
|
t = proto.RequestType
|
||||||
b = proto.ButtonRequestType
|
b = proto.ButtonRequestType
|
||||||
@ -95,8 +96,7 @@ def check_sign_tx(client, coin_name, inputs, outputs, fee_too_high=False, failur
|
|||||||
):
|
):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
prev_hash = inp.prev_hash.hex()
|
prev_tx = txes[inp.prev_hash]
|
||||||
prev_tx = txes.get_tx(prev_hash)
|
|
||||||
for pi in range(len(prev_tx.inputs)):
|
for pi in range(len(prev_tx.inputs)):
|
||||||
r = tx_request(t.TXINPUT, request_index=pi, tx_hash=inp.prev_hash)
|
r = tx_request(t.TXINPUT, request_index=pi, tx_hash=inp.prev_hash)
|
||||||
expected_responses.append(r)
|
expected_responses.append(r)
|
||||||
@ -138,7 +138,7 @@ def check_sign_tx(client, coin_name, inputs, outputs, fee_too_high=False, failur
|
|||||||
|
|
||||||
with client:
|
with client:
|
||||||
client.set_expected_responses(expected_responses)
|
client.set_expected_responses(expected_responses)
|
||||||
return btc.sign_tx(client, coin_name, inputs, outputs)
|
return btc.sign_tx(client, coin_name, inputs, outputs, prev_txes=txes)
|
||||||
|
|
||||||
|
|
||||||
class TestMsgSigntx(TrezorTest):
|
class TestMsgSigntx(TrezorTest):
|
||||||
@ -171,7 +171,6 @@ class TestMsgSigntx(TrezorTest):
|
|||||||
|
|
||||||
def test_testnet_one_two_fee(self):
|
def test_testnet_one_two_fee(self):
|
||||||
self.setup_mnemonic_allallall()
|
self.setup_mnemonic_allallall()
|
||||||
self.client.set_tx_api(tx_api["Testnet"])
|
|
||||||
# see 87be0736f202f7c2bff0781b42bad3e0cdcb54761939da69ea793a3735552c56
|
# see 87be0736f202f7c2bff0781b42bad3e0cdcb54761939da69ea793a3735552c56
|
||||||
|
|
||||||
# tx: e5040e1bc1ae7667ffb9e5248e90b2fb93cd9150234151ce90e14ab2f5933bcd
|
# tx: e5040e1bc1ae7667ffb9e5248e90b2fb93cd9150234151ce90e14ab2f5933bcd
|
||||||
@ -204,8 +203,6 @@ class TestMsgSigntx(TrezorTest):
|
|||||||
|
|
||||||
def test_testnet_fee_too_high(self):
|
def test_testnet_fee_too_high(self):
|
||||||
self.setup_mnemonic_nopin_nopassphrase()
|
self.setup_mnemonic_nopin_nopassphrase()
|
||||||
self.client.set_tx_api(tx_api["Testnet"])
|
|
||||||
|
|
||||||
# tx: 6f90f3c7cbec2258b0971056ef3fe34128dbde30daa9c0639a898f9977299d54
|
# tx: 6f90f3c7cbec2258b0971056ef3fe34128dbde30daa9c0639a898f9977299d54
|
||||||
# input 1: 10.00000000 BTC
|
# input 1: 10.00000000 BTC
|
||||||
inp1 = proto.TxInputType(
|
inp1 = proto.TxInputType(
|
||||||
@ -354,29 +351,38 @@ class TestMsgSigntx(TrezorTest):
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Accepted by network: tx c63e24ed820c5851b60c54613fbc4bcb37df6cd49b4c96143e99580a472f79fb
|
# Accepted by network: tx c63e24ed820c5851b60c54613fbc4bcb37df6cd49b4c96143e99580a472f79fb
|
||||||
|
# The transaction was produced before Trezor implemented BIP-66, so the signature
|
||||||
|
# is now different and txhash doesn't match what is on the blockchain.
|
||||||
assert (
|
assert (
|
||||||
serialized_tx.hex()
|
serialized_tx.hex()
|
||||||
== "01000000021c032e5715d1da8115a2fe4f57699e15742fe113b0d2d1ca3b594649d322bec6010000006b483045022100f773c403b2f85a5c1d6c9c4ad69c43de66930fff4b1bc818eb257af98305546a0220443bde4be439f276a6ce793664b463580e210ec6c9255d68354449ac0443c76501210338d78612e990f2eea0c426b5e48a8db70b9d7ed66282b3b26511e0b1c75515a6ffffffff6ea42cd8d9c8e5441c4c5f85bfe50311078730d2881494f11f4d2257777a4958010000006b48304502210090cff1c1911e771605358a8cddd5ae94c7b60cc96e50275908d9bf9d6367c79f02202bfa72e10260a146abd59d0526e1335bacfbb2b4401780e9e3a7441b0480c8da0121038caebd6f753bbbd2bb1f3346a43cd32140648583673a31d62f2dfb56ad0ab9e3ffffffff02a0860100000000001976a9142f4490d5263906e4887ca2996b9e207af3e7824088aca0860100000000001976a914812c13d97f9159e54e326b481b8f88a73df8507a88ac00000000"
|
== "01000000021c032e5715d1da8115a2fe4f57699e15742fe113b0d2d1ca3b594649d322bec6010000006b483045022100f773c403b2f85a5c1d6c9c4ad69c43de66930fff4b1bc818eb257af98305546a0220443bde4be439f276a6ce793664b463580e210ec6c9255d68354449ac0443c76501210338d78612e990f2eea0c426b5e48a8db70b9d7ed66282b3b26511e0b1c75515a6ffffffff6ea42cd8d9c8e5441c4c5f85bfe50311078730d2881494f11f4d2257777a4958010000006b48304502210090cff1c1911e771605358a8cddd5ae94c7b60cc96e50275908d9bf9d6367c79f02202bfa72e10260a146abd59d0526e1335bacfbb2b4401780e9e3a7441b0480c8da0121038caebd6f753bbbd2bb1f3346a43cd32140648583673a31d62f2dfb56ad0ab9e3ffffffff02a0860100000000001976a9142f4490d5263906e4887ca2996b9e207af3e7824088aca0860100000000001976a914812c13d97f9159e54e326b481b8f88a73df8507a88ac00000000"
|
||||||
)
|
)
|
||||||
|
|
||||||
"""
|
|
||||||
def test_lots_of_inputs(self):
|
def test_lots_of_inputs(self):
|
||||||
self.setup_mnemonic_nopin_nopassphrase()
|
self.setup_mnemonic_nopin_nopassphrase()
|
||||||
# Tests if device implements serialization of len(inputs) correctly
|
# Tests if device implements serialization of len(inputs) correctly
|
||||||
# tx 4a7b7e0403ae5607e473949cfa03f09f2cd8b0f404bf99ce10b7303d86280bf7 : 100 UTXO for spending for unit tests
|
# tx 4a7b7e0403ae5607e473949cfa03f09f2cd8b0f404bf99ce10b7303d86280bf7 : 100 UTXO for spending for unit tests
|
||||||
inputs = []
|
inputs = []
|
||||||
for i in range(100):
|
for i in range(100):
|
||||||
inputs.append( proto.TxInputType(address_n=[4], # 1NwN6UduuVkJi6sw3gSiKZaCY5rHgVXC2h
|
inputs.append(
|
||||||
prev_hash=TXHASH_4a7b7e,
|
proto.TxInputType(
|
||||||
prev_index=i) )
|
address_n=[4], # 1NwN6UduuVkJi6sw3gSiKZaCY5rHgVXC2h
|
||||||
out = proto.TxOutputType(address='19dvDdyxxptP9dGvozYe8BP6tgFV9L4jg5',
|
prev_hash=TXHASH_4a7b7e,
|
||||||
amount=100 * 26000 - 15 * 10000,
|
prev_index=i,
|
||||||
script_type=proto.OutputScriptType.PAYTOADDRESS)
|
)
|
||||||
with self.client:
|
)
|
||||||
(signatures, serialized_tx) = self.client.sign_tx('Bitcoin', inputs, [out])
|
out = proto.TxOutputType(
|
||||||
|
address="19dvDdyxxptP9dGvozYe8BP6tgFV9L4jg5",
|
||||||
|
amount=100 * 26000 - 15 * 10000,
|
||||||
|
script_type=proto.OutputScriptType.PAYTOADDRESS,
|
||||||
|
)
|
||||||
|
_, serialized_tx = check_sign_tx(self.client, "Bitcoin", inputs, [out])
|
||||||
# Accepted by network: tx 23d9d8eecf3abf6c0f0f3f8b0976a04792d7f1c9a4ea9b0a8931734949e27c92
|
# Accepted by network: tx 23d9d8eecf3abf6c0f0f3f8b0976a04792d7f1c9a4ea9b0a8931734949e27c92
|
||||||
# too big put in unit test
|
# too big put in unit test, only check hash
|
||||||
"""
|
assert (
|
||||||
|
btc_hash(serialized_tx)[::-1].hex()
|
||||||
|
== "23d9d8eecf3abf6c0f0f3f8b0976a04792d7f1c9a4ea9b0a8931734949e27c92"
|
||||||
|
)
|
||||||
|
|
||||||
def test_lots_of_outputs(self):
|
def test_lots_of_outputs(self):
|
||||||
self.setup_mnemonic_nopin_nopassphrase()
|
self.setup_mnemonic_nopin_nopassphrase()
|
||||||
@ -540,30 +546,9 @@ class TestMsgSigntx(TrezorTest):
|
|||||||
script_type=proto.OutputScriptType.PAYTOADDRESS,
|
script_type=proto.OutputScriptType.PAYTOADDRESS,
|
||||||
)
|
)
|
||||||
|
|
||||||
global run_attack
|
out2.force_confirm = True
|
||||||
run_attack = False
|
|
||||||
|
|
||||||
def attack_processor(req, msg):
|
|
||||||
global run_attack
|
|
||||||
|
|
||||||
if req.details.tx_hash is not None:
|
|
||||||
return msg
|
|
||||||
|
|
||||||
if req.details.request_index != 1:
|
|
||||||
return msg
|
|
||||||
|
|
||||||
if req.request_type != proto.RequestType.TXOUTPUT:
|
|
||||||
return msg
|
|
||||||
|
|
||||||
if not run_attack:
|
|
||||||
run_attack = True
|
|
||||||
return msg
|
|
||||||
|
|
||||||
msg.outputs[0].amount = 9999999 # Sign output with another amount
|
|
||||||
return msg
|
|
||||||
|
|
||||||
# Test if the transaction can be signed normally
|
# Test if the transaction can be signed normally
|
||||||
(_, serialized_tx) = btc.sign_tx(
|
_, serialized_tx = check_sign_tx(
|
||||||
self.client, "Bitcoin", [inp1, inp2], [out1, out2]
|
self.client, "Bitcoin", [inp1, inp2], [out1, out2]
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -573,14 +558,29 @@ class TestMsgSigntx(TrezorTest):
|
|||||||
== "01000000021c032e5715d1da8115a2fe4f57699e15742fe113b0d2d1ca3b594649d322bec6010000006b483045022100f773c403b2f85a5c1d6c9c4ad69c43de66930fff4b1bc818eb257af98305546a0220443bde4be439f276a6ce793664b463580e210ec6c9255d68354449ac0443c76501210338d78612e990f2eea0c426b5e48a8db70b9d7ed66282b3b26511e0b1c75515a6ffffffff6ea42cd8d9c8e5441c4c5f85bfe50311078730d2881494f11f4d2257777a4958010000006b48304502210090cff1c1911e771605358a8cddd5ae94c7b60cc96e50275908d9bf9d6367c79f02202bfa72e10260a146abd59d0526e1335bacfbb2b4401780e9e3a7441b0480c8da0121038caebd6f753bbbd2bb1f3346a43cd32140648583673a31d62f2dfb56ad0ab9e3ffffffff02a0860100000000001976a9142f4490d5263906e4887ca2996b9e207af3e7824088aca0860100000000001976a914812c13d97f9159e54e326b481b8f88a73df8507a88ac00000000"
|
== "01000000021c032e5715d1da8115a2fe4f57699e15742fe113b0d2d1ca3b594649d322bec6010000006b483045022100f773c403b2f85a5c1d6c9c4ad69c43de66930fff4b1bc818eb257af98305546a0220443bde4be439f276a6ce793664b463580e210ec6c9255d68354449ac0443c76501210338d78612e990f2eea0c426b5e48a8db70b9d7ed66282b3b26511e0b1c75515a6ffffffff6ea42cd8d9c8e5441c4c5f85bfe50311078730d2881494f11f4d2257777a4958010000006b48304502210090cff1c1911e771605358a8cddd5ae94c7b60cc96e50275908d9bf9d6367c79f02202bfa72e10260a146abd59d0526e1335bacfbb2b4401780e9e3a7441b0480c8da0121038caebd6f753bbbd2bb1f3346a43cd32140648583673a31d62f2dfb56ad0ab9e3ffffffff02a0860100000000001976a9142f4490d5263906e4887ca2996b9e207af3e7824088aca0860100000000001976a914812c13d97f9159e54e326b481b8f88a73df8507a88ac00000000"
|
||||||
)
|
)
|
||||||
|
|
||||||
# Now run the attack, must trigger the exception
|
run_attack = False
|
||||||
|
|
||||||
|
def attack_processor(msg):
|
||||||
|
nonlocal run_attack
|
||||||
|
if msg.tx.outputs and msg.tx.outputs[0] == out2:
|
||||||
|
if not run_attack:
|
||||||
|
run_attack = True
|
||||||
|
else:
|
||||||
|
# Sign output with another amount
|
||||||
|
msg.tx.outputs[0].amount = 9999999
|
||||||
|
|
||||||
|
return msg
|
||||||
|
|
||||||
|
# Set up attack processors
|
||||||
|
self.client.set_filter(proto.TxAck, attack_processor)
|
||||||
|
|
||||||
with pytest.raises(CallException) as exc:
|
with pytest.raises(CallException) as exc:
|
||||||
btc.sign_tx(
|
btc.sign_tx(
|
||||||
self.client,
|
self.client,
|
||||||
"Bitcoin",
|
"Bitcoin",
|
||||||
[inp1, inp2],
|
[inp1, inp2],
|
||||||
[out1, out2],
|
[out1, out2],
|
||||||
debug_processor=attack_processor,
|
prev_txes=tx_cache("Bitcoin"),
|
||||||
)
|
)
|
||||||
assert exc.value.args[0] in (
|
assert exc.value.args[0] in (
|
||||||
proto.FailureType.ProcessError,
|
proto.FailureType.ProcessError,
|
||||||
@ -591,9 +591,7 @@ class TestMsgSigntx(TrezorTest):
|
|||||||
def test_attack_change_input_address(self):
|
def test_attack_change_input_address(self):
|
||||||
# This unit test attempts to modify input address after the Trezor checked
|
# This unit test attempts to modify input address after the Trezor checked
|
||||||
# that it matches the change output
|
# that it matches the change output
|
||||||
|
|
||||||
self.setup_mnemonic_allallall()
|
self.setup_mnemonic_allallall()
|
||||||
self.client.set_tx_api(tx_api["Testnet"])
|
|
||||||
|
|
||||||
inp1 = proto.TxInputType(
|
inp1 = proto.TxInputType(
|
||||||
address_n=parse_path("44'/1'/4'/0/0"),
|
address_n=parse_path("44'/1'/4'/0/0"),
|
||||||
@ -610,41 +608,32 @@ class TestMsgSigntx(TrezorTest):
|
|||||||
)
|
)
|
||||||
|
|
||||||
out2 = proto.TxOutputType(
|
out2 = proto.TxOutputType(
|
||||||
address_n=parse_path("44'/1'/12345'/1/0"),
|
address_n=parse_path("44'/1'/4'/1/0"),
|
||||||
amount=123400000 - 5000 - 100000,
|
amount=123400000 - 5000 - 100000,
|
||||||
script_type=proto.OutputScriptType.PAYTOADDRESS,
|
script_type=proto.OutputScriptType.PAYTOADDRESS,
|
||||||
)
|
)
|
||||||
|
|
||||||
global run_attack
|
|
||||||
run_attack = True
|
|
||||||
|
|
||||||
def attack_processor(req, msg):
|
|
||||||
global run_attack
|
|
||||||
|
|
||||||
if req.details.tx_hash is not None:
|
|
||||||
return msg
|
|
||||||
|
|
||||||
if req.request_type != proto.RequestType.TXINPUT:
|
|
||||||
return msg
|
|
||||||
|
|
||||||
if req.details.request_index != 0:
|
|
||||||
return msg
|
|
||||||
|
|
||||||
if not run_attack:
|
|
||||||
return msg
|
|
||||||
|
|
||||||
msg.inputs[0].address_n[2] = H_(12345)
|
|
||||||
run_attack = False
|
|
||||||
return msg
|
|
||||||
|
|
||||||
# Test if the transaction can be signed normally
|
# Test if the transaction can be signed normally
|
||||||
(_, serialized_tx) = btc.sign_tx(self.client, "Testnet", [inp1], [out1, out2])
|
_, serialized_tx = check_sign_tx(self.client, "Testnet", [inp1], [out1, out2])
|
||||||
|
|
||||||
assert (
|
assert (
|
||||||
serialized_tx.hex()
|
serialized_tx.hex()
|
||||||
== "0100000001243e15b53cc553d93ec4e27e16984adc3d885ef107c613a7577fea47f5dadcd2010000006a47304402207d517dcb6b823bba4d252da096795a7f914d0c477aee26e554ba61653c45608a02202cba1e805c586c830472f399510be5d42c2fcfd67b8a6b0690cbe8a3e6e475e801210364430c9122948e525e2f1c6d88f00f47679274f0810fd8c63754954f310995c1ffffffff02a0860100000000001976a914b3cc67f3349974d0f1b50e9bb5dfdf226f888fa088ac18555907000000001976a91485a3f5b0d23cdd61f5f8e1eb8c9ca0890dd15a9788ac00000000"
|
== "0100000001243e15b53cc553d93ec4e27e16984adc3d885ef107c613a7577fea47f5dadcd2010000006b483045022100eedaadde3a771967beee39f1daa9e9450f72fccdec63488a96d71eeae4224b4002203a22be3c1677d3451c93a49550b69e8f8fc06328823c7e0f633dde13d67ef96b01210364430c9122948e525e2f1c6d88f00f47679274f0810fd8c63754954f310995c1ffffffff02a0860100000000001976a914b3cc67f3349974d0f1b50e9bb5dfdf226f888fa088ac18555907000000001976a914f80fb232a1e54b1fa732bc120cae72eabd7fcf6888ac00000000"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
run_attack = False
|
||||||
|
|
||||||
|
def attack_processor(msg):
|
||||||
|
nonlocal run_attack
|
||||||
|
if msg.tx.inputs and msg.tx.inputs[0] == inp1:
|
||||||
|
if not run_attack:
|
||||||
|
run_attack = True
|
||||||
|
else:
|
||||||
|
msg.tx.inputs[0].address_n[2] = H_(12345)
|
||||||
|
|
||||||
|
return msg
|
||||||
|
|
||||||
|
self.client.set_filter(proto.TxAck, attack_processor)
|
||||||
# Now run the attack, must trigger the exception
|
# Now run the attack, must trigger the exception
|
||||||
with self.client:
|
with self.client:
|
||||||
self.client.set_expected_responses(
|
self.client.set_expected_responses(
|
||||||
@ -699,7 +688,7 @@ class TestMsgSigntx(TrezorTest):
|
|||||||
"Testnet",
|
"Testnet",
|
||||||
[inp1],
|
[inp1],
|
||||||
[out1, out2],
|
[out1, out2],
|
||||||
debug_processor=attack_processor,
|
prev_txes=tx_cache("Testnet"),
|
||||||
)
|
)
|
||||||
|
|
||||||
assert exc.value.args[0] == proto.FailureType.ProcessError
|
assert exc.value.args[0] == proto.FailureType.ProcessError
|
||||||
@ -716,7 +705,6 @@ class TestMsgSigntx(TrezorTest):
|
|||||||
# input 0: 25.0027823 BTC
|
# input 0: 25.0027823 BTC
|
||||||
|
|
||||||
self.setup_mnemonic_nopin_nopassphrase()
|
self.setup_mnemonic_nopin_nopassphrase()
|
||||||
self.client.set_tx_api(tx_api["Testnet"])
|
|
||||||
|
|
||||||
inp1 = proto.TxInputType(
|
inp1 = proto.TxInputType(
|
||||||
address_n=[1], # mfiGQVPcRcaEvQPYDErR34DcCovtxYvUUV
|
address_n=[1], # mfiGQVPcRcaEvQPYDErR34DcCovtxYvUUV
|
||||||
@ -741,7 +729,6 @@ class TestMsgSigntx(TrezorTest):
|
|||||||
|
|
||||||
def test_two_changes(self):
|
def test_two_changes(self):
|
||||||
self.setup_mnemonic_allallall()
|
self.setup_mnemonic_allallall()
|
||||||
self.client.set_tx_api(tx_api["Testnet"])
|
|
||||||
# see 87be0736f202f7c2bff0781b42bad3e0cdcb54761939da69ea793a3735552c56
|
# see 87be0736f202f7c2bff0781b42bad3e0cdcb54761939da69ea793a3735552c56
|
||||||
|
|
||||||
# tx: e5040e1bc1ae7667ffb9e5248e90b2fb93cd9150234151ce90e14ab2f5933bcd
|
# tx: e5040e1bc1ae7667ffb9e5248e90b2fb93cd9150234151ce90e14ab2f5933bcd
|
||||||
@ -777,7 +764,6 @@ class TestMsgSigntx(TrezorTest):
|
|||||||
|
|
||||||
def test_change_on_main_chain_allowed(self):
|
def test_change_on_main_chain_allowed(self):
|
||||||
self.setup_mnemonic_allallall()
|
self.setup_mnemonic_allallall()
|
||||||
self.client.set_tx_api(tx_api["Testnet"])
|
|
||||||
# see 87be0736f202f7c2bff0781b42bad3e0cdcb54761939da69ea793a3735552c56
|
# see 87be0736f202f7c2bff0781b42bad3e0cdcb54761939da69ea793a3735552c56
|
||||||
|
|
||||||
# tx: e5040e1bc1ae7667ffb9e5248e90b2fb93cd9150234151ce90e14ab2f5933bcd
|
# tx: e5040e1bc1ae7667ffb9e5248e90b2fb93cd9150234151ce90e14ab2f5933bcd
|
||||||
|
@ -20,15 +20,15 @@ from trezorlib import btc, coins, messages as proto
|
|||||||
from trezorlib.tools import H_, CallException, parse_path
|
from trezorlib.tools import H_, CallException, parse_path
|
||||||
|
|
||||||
from ..support.ckd_public import deserialize
|
from ..support.ckd_public import deserialize
|
||||||
|
from ..support.tx_cache import tx_cache
|
||||||
from .common import TrezorTest
|
from .common import TrezorTest
|
||||||
|
|
||||||
TxApiBcash = coins.tx_api["Bcash"]
|
TX_API = tx_cache("Bcash")
|
||||||
|
|
||||||
|
|
||||||
class TestMsgSigntxBch(TrezorTest):
|
class TestMsgSigntxBch(TrezorTest):
|
||||||
def test_send_bch_change(self):
|
def test_send_bch_change(self):
|
||||||
self.setup_mnemonic_allallall()
|
self.setup_mnemonic_allallall()
|
||||||
self.client.set_tx_api(TxApiBcash)
|
|
||||||
inp1 = proto.TxInputType(
|
inp1 = proto.TxInputType(
|
||||||
address_n=parse_path("44'/145'/0'/0/0"),
|
address_n=parse_path("44'/145'/0'/0/0"),
|
||||||
# bitcoincash:qr08q88p9etk89wgv05nwlrkm4l0urz4cyl36hh9sv
|
# bitcoincash:qr08q88p9etk89wgv05nwlrkm4l0urz4cyl36hh9sv
|
||||||
@ -81,8 +81,8 @@ class TestMsgSigntxBch(TrezorTest):
|
|||||||
proto.TxRequest(request_type=proto.RequestType.TXFINISHED),
|
proto.TxRequest(request_type=proto.RequestType.TXFINISHED),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
(signatures, serialized_tx) = btc.sign_tx(
|
_, serialized_tx = btc.sign_tx(
|
||||||
self.client, "Bcash", [inp1], [out1, out2]
|
self.client, "Bcash", [inp1], [out1, out2], prev_txes=TX_API
|
||||||
)
|
)
|
||||||
|
|
||||||
assert (
|
assert (
|
||||||
@ -92,7 +92,6 @@ class TestMsgSigntxBch(TrezorTest):
|
|||||||
|
|
||||||
def test_send_bch_nochange(self):
|
def test_send_bch_nochange(self):
|
||||||
self.setup_mnemonic_allallall()
|
self.setup_mnemonic_allallall()
|
||||||
self.client.set_tx_api(TxApiBcash)
|
|
||||||
inp1 = proto.TxInputType(
|
inp1 = proto.TxInputType(
|
||||||
address_n=parse_path("44'/145'/0'/1/0"),
|
address_n=parse_path("44'/145'/0'/1/0"),
|
||||||
# bitcoincash:qzc5q87w069lzg7g3gzx0c8dz83mn7l02scej5aluw
|
# bitcoincash:qzc5q87w069lzg7g3gzx0c8dz83mn7l02scej5aluw
|
||||||
@ -150,8 +149,8 @@ class TestMsgSigntxBch(TrezorTest):
|
|||||||
proto.TxRequest(request_type=proto.RequestType.TXFINISHED),
|
proto.TxRequest(request_type=proto.RequestType.TXFINISHED),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
(signatures, serialized_tx) = btc.sign_tx(
|
_, serialized_tx = btc.sign_tx(
|
||||||
self.client, "Bcash", [inp1, inp2], [out1]
|
self.client, "Bcash", [inp1, inp2], [out1], prev_txes=TX_API
|
||||||
)
|
)
|
||||||
|
|
||||||
assert (
|
assert (
|
||||||
@ -161,7 +160,6 @@ class TestMsgSigntxBch(TrezorTest):
|
|||||||
|
|
||||||
def test_send_bch_oldaddr(self):
|
def test_send_bch_oldaddr(self):
|
||||||
self.setup_mnemonic_allallall()
|
self.setup_mnemonic_allallall()
|
||||||
self.client.set_tx_api(TxApiBcash)
|
|
||||||
inp1 = proto.TxInputType(
|
inp1 = proto.TxInputType(
|
||||||
address_n=parse_path("44'/145'/0'/1/0"),
|
address_n=parse_path("44'/145'/0'/1/0"),
|
||||||
# bitcoincash:qzc5q87w069lzg7g3gzx0c8dz83mn7l02scej5aluw
|
# bitcoincash:qzc5q87w069lzg7g3gzx0c8dz83mn7l02scej5aluw
|
||||||
@ -219,8 +217,8 @@ class TestMsgSigntxBch(TrezorTest):
|
|||||||
proto.TxRequest(request_type=proto.RequestType.TXFINISHED),
|
proto.TxRequest(request_type=proto.RequestType.TXFINISHED),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
(signatures, serialized_tx) = btc.sign_tx(
|
_, serialized_tx = btc.sign_tx(
|
||||||
self.client, "Bcash", [inp1, inp2], [out1]
|
self.client, "Bcash", [inp1, inp2], [out1], prev_txes=TX_API
|
||||||
)
|
)
|
||||||
|
|
||||||
assert (
|
assert (
|
||||||
@ -230,7 +228,6 @@ class TestMsgSigntxBch(TrezorTest):
|
|||||||
|
|
||||||
def test_attack_amount(self):
|
def test_attack_amount(self):
|
||||||
self.setup_mnemonic_allallall()
|
self.setup_mnemonic_allallall()
|
||||||
self.client.set_tx_api(TxApiBcash)
|
|
||||||
inp1 = proto.TxInputType(
|
inp1 = proto.TxInputType(
|
||||||
address_n=parse_path("44'/145'/0'/1/0"),
|
address_n=parse_path("44'/145'/0'/1/0"),
|
||||||
# bitcoincash:qzc5q87w069lzg7g3gzx0c8dz83mn7l02scej5aluw
|
# bitcoincash:qzc5q87w069lzg7g3gzx0c8dz83mn7l02scej5aluw
|
||||||
@ -257,31 +254,6 @@ class TestMsgSigntxBch(TrezorTest):
|
|||||||
script_type=proto.OutputScriptType.PAYTOADDRESS,
|
script_type=proto.OutputScriptType.PAYTOADDRESS,
|
||||||
)
|
)
|
||||||
|
|
||||||
global run_attack
|
|
||||||
run_attack = True
|
|
||||||
|
|
||||||
def attack_processor(req, msg):
|
|
||||||
global run_attack
|
|
||||||
|
|
||||||
if req.details.tx_hash is not None:
|
|
||||||
return msg
|
|
||||||
|
|
||||||
if req.request_type != proto.RequestType.TXINPUT:
|
|
||||||
return msg
|
|
||||||
|
|
||||||
if req.details.request_index != 0:
|
|
||||||
return msg
|
|
||||||
|
|
||||||
if not run_attack:
|
|
||||||
return msg
|
|
||||||
|
|
||||||
# 300 is lowered to 280 at the first run
|
|
||||||
# the user confirms 280 but the transaction
|
|
||||||
# is spending 300 => larger fee without the user knowing
|
|
||||||
msg.inputs[0].amount = 280
|
|
||||||
run_attack = False
|
|
||||||
return msg
|
|
||||||
|
|
||||||
# test if passes without modifications
|
# test if passes without modifications
|
||||||
with self.client:
|
with self.client:
|
||||||
self.client.set_expected_responses(
|
self.client.set_expected_responses(
|
||||||
@ -315,9 +287,24 @@ class TestMsgSigntxBch(TrezorTest):
|
|||||||
proto.TxRequest(request_type=proto.RequestType.TXFINISHED),
|
proto.TxRequest(request_type=proto.RequestType.TXFINISHED),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
btc.sign_tx(self.client, "Bcash", [inp1, inp2], [out1])
|
btc.sign_tx(self.client, "Bcash", [inp1, inp2], [out1], prev_txes=TX_API)
|
||||||
|
|
||||||
|
run_attack = True
|
||||||
|
|
||||||
|
def attack_processor(msg):
|
||||||
|
nonlocal run_attack
|
||||||
|
|
||||||
|
if run_attack and msg.tx.inputs and msg.tx.inputs[0] == inp1:
|
||||||
|
# 300 is lowered to 280 at the first run
|
||||||
|
# the user confirms 280 but the transaction
|
||||||
|
# is spending 300 => larger fee without the user knowing
|
||||||
|
msg.tx.inputs[0].amount = 280
|
||||||
|
run_attack = False
|
||||||
|
|
||||||
|
return msg
|
||||||
|
|
||||||
# now fails
|
# now fails
|
||||||
|
self.client.set_filter(proto.TxAck, attack_processor)
|
||||||
with self.client:
|
with self.client:
|
||||||
self.client.set_expected_responses(
|
self.client.set_expected_responses(
|
||||||
[
|
[
|
||||||
@ -349,11 +336,7 @@ class TestMsgSigntxBch(TrezorTest):
|
|||||||
|
|
||||||
with pytest.raises(CallException) as exc:
|
with pytest.raises(CallException) as exc:
|
||||||
btc.sign_tx(
|
btc.sign_tx(
|
||||||
self.client,
|
self.client, "Bcash", [inp1, inp2], [out1], prev_txes=TX_API
|
||||||
"Bcash",
|
|
||||||
[inp1, inp2],
|
|
||||||
[out1],
|
|
||||||
debug_processor=attack_processor,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
assert exc.value.args[0] in (
|
assert exc.value.args[0] in (
|
||||||
@ -364,7 +347,6 @@ class TestMsgSigntxBch(TrezorTest):
|
|||||||
|
|
||||||
def test_attack_change_input(self):
|
def test_attack_change_input(self):
|
||||||
self.setup_mnemonic_allallall()
|
self.setup_mnemonic_allallall()
|
||||||
self.client.set_tx_api(TxApiBcash)
|
|
||||||
inp1 = proto.TxInputType(
|
inp1 = proto.TxInputType(
|
||||||
address_n=parse_path("44'/145'/1000'/0/0"),
|
address_n=parse_path("44'/145'/1000'/0/0"),
|
||||||
# bitcoincash:qr08q88p9etk89wgv05nwlrkm4l0urz4cyl36hh9sv
|
# bitcoincash:qr08q88p9etk89wgv05nwlrkm4l0urz4cyl36hh9sv
|
||||||
@ -386,25 +368,21 @@ class TestMsgSigntxBch(TrezorTest):
|
|||||||
script_type=proto.OutputScriptType.PAYTOADDRESS,
|
script_type=proto.OutputScriptType.PAYTOADDRESS,
|
||||||
)
|
)
|
||||||
|
|
||||||
global attack_ctr
|
run_attack = False
|
||||||
attack_ctr = 0
|
|
||||||
|
|
||||||
def attack_processor(req, msg):
|
def attack_processor(msg):
|
||||||
global attack_ctr
|
nonlocal run_attack
|
||||||
|
|
||||||
if req.details.tx_hash is not None:
|
if msg.tx.inputs and msg.tx.inputs[0] == inp1:
|
||||||
return msg
|
if not run_attack:
|
||||||
|
run_attack = True
|
||||||
|
else:
|
||||||
|
msg.tx.inputs[0].address_n[2] = H_(1)
|
||||||
|
|
||||||
if req.request_type != proto.RequestType.TXINPUT:
|
|
||||||
return msg
|
|
||||||
|
|
||||||
attack_ctr += 1
|
|
||||||
if attack_ctr <= 1:
|
|
||||||
return msg
|
|
||||||
|
|
||||||
msg.inputs[0].address_n[2] = H_(1)
|
|
||||||
return msg
|
return msg
|
||||||
|
|
||||||
|
self.client.set_filter(proto.TxAck, attack_processor)
|
||||||
|
|
||||||
with self.client:
|
with self.client:
|
||||||
self.client.set_expected_responses(
|
self.client.set_expected_responses(
|
||||||
[
|
[
|
||||||
@ -431,16 +409,11 @@ class TestMsgSigntxBch(TrezorTest):
|
|||||||
)
|
)
|
||||||
with pytest.raises(CallException):
|
with pytest.raises(CallException):
|
||||||
btc.sign_tx(
|
btc.sign_tx(
|
||||||
self.client,
|
self.client, "Bcash", [inp1], [out1, out2], prev_txes=TX_API
|
||||||
"Bcash",
|
|
||||||
[inp1],
|
|
||||||
[out1, out2],
|
|
||||||
debug_processor=attack_processor,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_send_bch_multisig_wrongchange(self):
|
def test_send_bch_multisig_wrongchange(self):
|
||||||
self.setup_mnemonic_allallall()
|
self.setup_mnemonic_allallall()
|
||||||
self.client.set_tx_api(TxApiBcash)
|
|
||||||
xpubs = []
|
xpubs = []
|
||||||
for n in map(
|
for n in map(
|
||||||
lambda index: btc.get_public_node(
|
lambda index: btc.get_public_node(
|
||||||
@ -528,7 +501,7 @@ class TestMsgSigntxBch(TrezorTest):
|
|||||||
]
|
]
|
||||||
)
|
)
|
||||||
(signatures1, serialized_tx) = btc.sign_tx(
|
(signatures1, serialized_tx) = btc.sign_tx(
|
||||||
self.client, "Bcash", [inp1], [out1]
|
self.client, "Bcash", [inp1], [out1], prev_txes=TX_API
|
||||||
)
|
)
|
||||||
assert (
|
assert (
|
||||||
signatures1[0].hex()
|
signatures1[0].hex()
|
||||||
@ -541,7 +514,6 @@ class TestMsgSigntxBch(TrezorTest):
|
|||||||
|
|
||||||
def test_send_bch_multisig_change(self):
|
def test_send_bch_multisig_change(self):
|
||||||
self.setup_mnemonic_allallall()
|
self.setup_mnemonic_allallall()
|
||||||
self.client.set_tx_api(TxApiBcash)
|
|
||||||
xpubs = []
|
xpubs = []
|
||||||
for n in map(
|
for n in map(
|
||||||
lambda index: btc.get_public_node(
|
lambda index: btc.get_public_node(
|
||||||
@ -620,7 +592,7 @@ class TestMsgSigntxBch(TrezorTest):
|
|||||||
]
|
]
|
||||||
)
|
)
|
||||||
(signatures1, serialized_tx) = btc.sign_tx(
|
(signatures1, serialized_tx) = btc.sign_tx(
|
||||||
self.client, "Bcash", [inp1], [out1, out2]
|
self.client, "Bcash", [inp1], [out1, out2], prev_txes=TX_API
|
||||||
)
|
)
|
||||||
|
|
||||||
assert (
|
assert (
|
||||||
@ -674,7 +646,7 @@ class TestMsgSigntxBch(TrezorTest):
|
|||||||
]
|
]
|
||||||
)
|
)
|
||||||
(signatures1, serialized_tx) = btc.sign_tx(
|
(signatures1, serialized_tx) = btc.sign_tx(
|
||||||
self.client, "Bcash", [inp1], [out1, out2]
|
self.client, "Bcash", [inp1], [out1, out2], prev_txes=TX_API
|
||||||
)
|
)
|
||||||
|
|
||||||
assert (
|
assert (
|
||||||
|
@ -20,16 +20,16 @@ from trezorlib import btc, coins, messages as proto
|
|||||||
from trezorlib.tools import H_, CallException, parse_path
|
from trezorlib.tools import H_, CallException, parse_path
|
||||||
|
|
||||||
from ..support.ckd_public import deserialize
|
from ..support.ckd_public import deserialize
|
||||||
|
from ..support.tx_cache import tx_cache
|
||||||
from .common import TrezorTest
|
from .common import TrezorTest
|
||||||
|
|
||||||
TxApiBitcoinGold = coins.tx_api["Bgold"]
|
TX_API = tx_cache("Bgold")
|
||||||
|
|
||||||
|
|
||||||
# All data taken from T1
|
# All data taken from T1
|
||||||
class TestMsgSigntxBitcoinGold(TrezorTest):
|
class TestMsgSigntxBitcoinGold(TrezorTest):
|
||||||
def test_send_bitcoin_gold_change(self):
|
def test_send_bitcoin_gold_change(self):
|
||||||
self.setup_mnemonic_allallall()
|
self.setup_mnemonic_allallall()
|
||||||
self.client.set_tx_api(TxApiBitcoinGold)
|
|
||||||
inp1 = proto.TxInputType(
|
inp1 = proto.TxInputType(
|
||||||
address_n=parse_path("44'/156'/0'/0/0"),
|
address_n=parse_path("44'/156'/0'/0/0"),
|
||||||
amount=1995344,
|
amount=1995344,
|
||||||
@ -81,8 +81,8 @@ class TestMsgSigntxBitcoinGold(TrezorTest):
|
|||||||
proto.TxRequest(request_type=proto.RequestType.TXFINISHED),
|
proto.TxRequest(request_type=proto.RequestType.TXFINISHED),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
(signatures, serialized_tx) = btc.sign_tx(
|
_, serialized_tx = btc.sign_tx(
|
||||||
self.client, "Bgold", [inp1], [out1, out2]
|
self.client, "Bgold", [inp1], [out1, out2], prev_txes=TX_API
|
||||||
)
|
)
|
||||||
|
|
||||||
assert (
|
assert (
|
||||||
@ -92,7 +92,6 @@ class TestMsgSigntxBitcoinGold(TrezorTest):
|
|||||||
|
|
||||||
def test_send_bitcoin_gold_nochange(self):
|
def test_send_bitcoin_gold_nochange(self):
|
||||||
self.setup_mnemonic_allallall()
|
self.setup_mnemonic_allallall()
|
||||||
self.client.set_tx_api(TxApiBitcoinGold)
|
|
||||||
inp1 = proto.TxInputType(
|
inp1 = proto.TxInputType(
|
||||||
address_n=parse_path("44'/156'/0'/1/0"),
|
address_n=parse_path("44'/156'/0'/1/0"),
|
||||||
amount=1896050,
|
amount=1896050,
|
||||||
@ -149,8 +148,8 @@ class TestMsgSigntxBitcoinGold(TrezorTest):
|
|||||||
proto.TxRequest(request_type=proto.RequestType.TXFINISHED),
|
proto.TxRequest(request_type=proto.RequestType.TXFINISHED),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
(signatures, serialized_tx) = btc.sign_tx(
|
_, serialized_tx = btc.sign_tx(
|
||||||
self.client, "Bgold", [inp1, inp2], [out1]
|
self.client, "Bgold", [inp1, inp2], [out1], prev_txes=TX_API
|
||||||
)
|
)
|
||||||
|
|
||||||
assert (
|
assert (
|
||||||
@ -160,7 +159,6 @@ class TestMsgSigntxBitcoinGold(TrezorTest):
|
|||||||
|
|
||||||
def test_attack_change_input(self):
|
def test_attack_change_input(self):
|
||||||
self.setup_mnemonic_allallall()
|
self.setup_mnemonic_allallall()
|
||||||
self.client.set_tx_api(TxApiBitcoinGold)
|
|
||||||
inp1 = proto.TxInputType(
|
inp1 = proto.TxInputType(
|
||||||
address_n=parse_path("44'/156'/1000'/0/0"),
|
address_n=parse_path("44'/156'/1000'/0/0"),
|
||||||
# 1MH9KKcvdCTY44xVDC2k3fjBbX5Cz29N1q
|
# 1MH9KKcvdCTY44xVDC2k3fjBbX5Cz29N1q
|
||||||
@ -182,25 +180,20 @@ class TestMsgSigntxBitcoinGold(TrezorTest):
|
|||||||
script_type=proto.OutputScriptType.PAYTOADDRESS,
|
script_type=proto.OutputScriptType.PAYTOADDRESS,
|
||||||
)
|
)
|
||||||
|
|
||||||
global attack_ctr
|
run_attack = False
|
||||||
attack_ctr = 0
|
|
||||||
|
|
||||||
def attack_processor(req, msg):
|
def attack_processor(msg):
|
||||||
global attack_ctr
|
nonlocal run_attack
|
||||||
|
|
||||||
if req.details.tx_hash is not None:
|
if msg.tx.inputs and msg.tx.inputs[0] == inp1:
|
||||||
return msg
|
if run_attack:
|
||||||
|
msg.tx.inputs[0].address_n[2] = H_(1)
|
||||||
|
else:
|
||||||
|
run_attack = True
|
||||||
|
|
||||||
if req.request_type != proto.RequestType.TXINPUT:
|
|
||||||
return msg
|
|
||||||
|
|
||||||
attack_ctr += 1
|
|
||||||
if attack_ctr <= 1:
|
|
||||||
return msg
|
|
||||||
|
|
||||||
msg.inputs[0].address_n[2] = H_(1)
|
|
||||||
return msg
|
return msg
|
||||||
|
|
||||||
|
self.client.set_filter(proto.TxAck, attack_processor)
|
||||||
with self.client:
|
with self.client:
|
||||||
self.client.set_expected_responses(
|
self.client.set_expected_responses(
|
||||||
[
|
[
|
||||||
@ -227,16 +220,11 @@ class TestMsgSigntxBitcoinGold(TrezorTest):
|
|||||||
)
|
)
|
||||||
with pytest.raises(CallException):
|
with pytest.raises(CallException):
|
||||||
btc.sign_tx(
|
btc.sign_tx(
|
||||||
self.client,
|
self.client, "Bgold", [inp1], [out1, out2], prev_txes=TX_API
|
||||||
"Bgold",
|
|
||||||
[inp1],
|
|
||||||
[out1, out2],
|
|
||||||
debug_processor=attack_processor,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_send_btg_multisig_change(self):
|
def test_send_btg_multisig_change(self):
|
||||||
self.setup_mnemonic_allallall()
|
self.setup_mnemonic_allallall()
|
||||||
self.client.set_tx_api(TxApiBitcoinGold)
|
|
||||||
xpubs = []
|
xpubs = []
|
||||||
for n in map(
|
for n in map(
|
||||||
lambda index: btc.get_public_node(
|
lambda index: btc.get_public_node(
|
||||||
@ -314,18 +302,18 @@ class TestMsgSigntxBitcoinGold(TrezorTest):
|
|||||||
proto.TxRequest(request_type=proto.RequestType.TXFINISHED),
|
proto.TxRequest(request_type=proto.RequestType.TXFINISHED),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
(signatures1, serialized_tx) = btc.sign_tx(
|
signatures, serialized_tx = btc.sign_tx(
|
||||||
self.client, "Bgold", [inp1], [out1, out2]
|
self.client, "Bgold", [inp1], [out1, out2], prev_txes=TX_API
|
||||||
)
|
)
|
||||||
|
|
||||||
assert (
|
assert (
|
||||||
signatures1[0].hex()
|
signatures[0].hex()
|
||||||
== "3045022100b1594f3b186d0dedbf61e53a1c407b1e0747098b7375941df85af045040f578e022013ba1893eb9e2fd854dd07073a83b261cf4beba76f66b07742e462b4088a7e4a"
|
== "3045022100b1594f3b186d0dedbf61e53a1c407b1e0747098b7375941df85af045040f578e022013ba1893eb9e2fd854dd07073a83b261cf4beba76f66b07742e462b4088a7e4a"
|
||||||
)
|
)
|
||||||
|
|
||||||
inp1 = proto.TxInputType(
|
inp1 = proto.TxInputType(
|
||||||
address_n=parse_path("44'/156'/1'/0/0"),
|
address_n=parse_path("44'/156'/1'/0/0"),
|
||||||
multisig=getmultisig(0, 0, [b"", b"", signatures1[0]]),
|
multisig=getmultisig(0, 0, [b"", b"", signatures[0]]),
|
||||||
# 33Ju286QvonBz5N1V754ZekQv4GLJqcc5R
|
# 33Ju286QvonBz5N1V754ZekQv4GLJqcc5R
|
||||||
amount=48490,
|
amount=48490,
|
||||||
prev_hash=bytes.fromhex(
|
prev_hash=bytes.fromhex(
|
||||||
@ -368,12 +356,12 @@ class TestMsgSigntxBitcoinGold(TrezorTest):
|
|||||||
proto.TxRequest(request_type=proto.RequestType.TXFINISHED),
|
proto.TxRequest(request_type=proto.RequestType.TXFINISHED),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
(signatures1, serialized_tx) = btc.sign_tx(
|
signatures, serialized_tx = btc.sign_tx(
|
||||||
self.client, "Bgold", [inp1], [out1, out2]
|
self.client, "Bgold", [inp1], [out1, out2], prev_txes=TX_API
|
||||||
)
|
)
|
||||||
|
|
||||||
assert (
|
assert (
|
||||||
signatures1[0].hex()
|
signatures[0].hex()
|
||||||
== "3044022006da8dbd14e6656ac8dcb956f4c0498574e88680eaeceb2cbafd8d2b2329d8cc02200972d076d444c5ff8f2ab18e14d8249ab661cb9c53335039bedcde037a40d747"
|
== "3044022006da8dbd14e6656ac8dcb956f4c0498574e88680eaeceb2cbafd8d2b2329d8cc02200972d076d444c5ff8f2ab18e14d8249ab661cb9c53335039bedcde037a40d747"
|
||||||
)
|
)
|
||||||
assert (
|
assert (
|
||||||
@ -383,7 +371,6 @@ class TestMsgSigntxBitcoinGold(TrezorTest):
|
|||||||
|
|
||||||
def test_send_p2sh(self):
|
def test_send_p2sh(self):
|
||||||
self.setup_mnemonic_allallall()
|
self.setup_mnemonic_allallall()
|
||||||
self.client.set_tx_api(TxApiBitcoinGold)
|
|
||||||
inp1 = proto.TxInputType(
|
inp1 = proto.TxInputType(
|
||||||
address_n=parse_path("49'/156'/0'/1/0"),
|
address_n=parse_path("49'/156'/0'/1/0"),
|
||||||
amount=123456789,
|
amount=123456789,
|
||||||
@ -440,8 +427,8 @@ class TestMsgSigntxBitcoinGold(TrezorTest):
|
|||||||
proto.TxRequest(request_type=proto.RequestType.TXFINISHED),
|
proto.TxRequest(request_type=proto.RequestType.TXFINISHED),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
(signatures, serialized_tx) = btc.sign_tx(
|
_, serialized_tx = btc.sign_tx(
|
||||||
self.client, "Bgold", [inp1], [out1, out2]
|
self.client, "Bgold", [inp1], [out1, out2], prev_txes=TX_API
|
||||||
)
|
)
|
||||||
|
|
||||||
assert (
|
assert (
|
||||||
@ -451,7 +438,6 @@ class TestMsgSigntxBitcoinGold(TrezorTest):
|
|||||||
|
|
||||||
def test_send_p2sh_witness_change(self):
|
def test_send_p2sh_witness_change(self):
|
||||||
self.setup_mnemonic_allallall()
|
self.setup_mnemonic_allallall()
|
||||||
self.client.set_tx_api(TxApiBitcoinGold)
|
|
||||||
inp1 = proto.TxInputType(
|
inp1 = proto.TxInputType(
|
||||||
address_n=parse_path("49'/156'/0'/1/0"),
|
address_n=parse_path("49'/156'/0'/1/0"),
|
||||||
amount=123456789,
|
amount=123456789,
|
||||||
@ -507,8 +493,8 @@ class TestMsgSigntxBitcoinGold(TrezorTest):
|
|||||||
proto.TxRequest(request_type=proto.RequestType.TXFINISHED),
|
proto.TxRequest(request_type=proto.RequestType.TXFINISHED),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
(signatures, serialized_tx) = btc.sign_tx(
|
_, serialized_tx = btc.sign_tx(
|
||||||
self.client, "Bgold", [inp1], [out1, out2]
|
self.client, "Bgold", [inp1], [out1, out2], prev_txes=TX_API
|
||||||
)
|
)
|
||||||
|
|
||||||
assert (
|
assert (
|
||||||
@ -518,7 +504,6 @@ class TestMsgSigntxBitcoinGold(TrezorTest):
|
|||||||
|
|
||||||
def test_send_multisig_1(self):
|
def test_send_multisig_1(self):
|
||||||
self.setup_mnemonic_allallall()
|
self.setup_mnemonic_allallall()
|
||||||
self.client.set_tx_api(TxApiBitcoinGold)
|
|
||||||
nodes = map(
|
nodes = map(
|
||||||
lambda index: btc.get_public_node(
|
lambda index: btc.get_public_node(
|
||||||
self.client, parse_path("999'/1'/%d'" % index)
|
self.client, parse_path("999'/1'/%d'" % index)
|
||||||
@ -583,9 +568,11 @@ class TestMsgSigntxBitcoinGold(TrezorTest):
|
|||||||
proto.TxRequest(request_type=proto.RequestType.TXFINISHED),
|
proto.TxRequest(request_type=proto.RequestType.TXFINISHED),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
(signatures1, _) = btc.sign_tx(self.client, "Bgold", [inp1], [out1])
|
signatures, _ = btc.sign_tx(
|
||||||
|
self.client, "Bgold", [inp1], [out1], prev_txes=TX_API
|
||||||
|
)
|
||||||
# store signature
|
# store signature
|
||||||
inp1.multisig.signatures[0] = signatures1[0]
|
inp1.multisig.signatures[0] = signatures[0]
|
||||||
# sign with third key
|
# sign with third key
|
||||||
inp1.address_n[2] = H_(3)
|
inp1.address_n[2] = H_(3)
|
||||||
self.client.set_expected_responses(
|
self.client.set_expected_responses(
|
||||||
@ -615,8 +602,8 @@ class TestMsgSigntxBitcoinGold(TrezorTest):
|
|||||||
proto.TxRequest(request_type=proto.RequestType.TXFINISHED),
|
proto.TxRequest(request_type=proto.RequestType.TXFINISHED),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
(signatures2, serialized_tx) = btc.sign_tx(
|
_, serialized_tx = btc.sign_tx(
|
||||||
self.client, "Bgold", [inp1], [out1]
|
self.client, "Bgold", [inp1], [out1], prev_txes=TX_API
|
||||||
)
|
)
|
||||||
|
|
||||||
assert (
|
assert (
|
||||||
|
@ -16,10 +16,11 @@
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from trezorlib import btc, coins, messages as proto
|
from trezorlib import btc, messages
|
||||||
from trezorlib.tools import parse_path
|
from trezorlib.tools import parse_path
|
||||||
|
|
||||||
from .common import TrezorTest
|
from .conftest import setup_client
|
||||||
|
from ..support.tx_cache import tx_cache
|
||||||
|
|
||||||
TXHASH_3bf506 = bytes.fromhex(
|
TXHASH_3bf506 = bytes.fromhex(
|
||||||
"3bf506c81ce84eda891679ddc797d162c17c60b15d6c0ac23be5e31369e7235f"
|
"3bf506c81ce84eda891679ddc797d162c17c60b15d6c0ac23be5e31369e7235f"
|
||||||
@ -32,44 +33,38 @@ TXHASH_f3a6e6 = bytes.fromhex(
|
|||||||
|
|
||||||
@pytest.mark.xfail
|
@pytest.mark.xfail
|
||||||
@pytest.mark.capricoin
|
@pytest.mark.capricoin
|
||||||
class TestMsgSigntx(TrezorTest):
|
@setup_client()
|
||||||
def test_timestamp_included(self):
|
def test_timestamp_included(client):
|
||||||
self.setup_mnemonic_allallall()
|
# tx: 3bf506c81ce84eda891679ddc797d162c17c60b15d6c0ac23be5e31369e7235f
|
||||||
self.client.set_tx_api(coins.tx_api["Capricoin"])
|
# input 0: 0.01 CPC
|
||||||
|
# tx: f3a6e6411f1b2dffd76d2729bae8e056f8f9ecf8996d3f428e75a6f23f2c5e8c
|
||||||
|
# input 0: 0.02 CPC
|
||||||
|
|
||||||
# tx: 3bf506c81ce84eda891679ddc797d162c17c60b15d6c0ac23be5e31369e7235f
|
inp1 = messages.TxInputType(
|
||||||
# input 0: 0.01 CPC
|
address_n=parse_path("m/44'/289'/0'/0/0"), prev_hash=TXHASH_3bf506, prev_index=0
|
||||||
# tx: f3a6e6411f1b2dffd76d2729bae8e056f8f9ecf8996d3f428e75a6f23f2c5e8c
|
)
|
||||||
# input 0: 0.02 CPC
|
|
||||||
|
|
||||||
inp1 = proto.TxInputType(
|
inp2 = messages.TxInputType(
|
||||||
address_n=parse_path("m/44'/289'/0'/0/0"),
|
address_n=parse_path("m/44'/289'/0'/0/0"), prev_hash=TXHASH_f3a6e6, prev_index=1
|
||||||
prev_hash=TXHASH_3bf506,
|
)
|
||||||
prev_index=0,
|
|
||||||
|
out1 = messages.TxOutputType(
|
||||||
|
address="CUGi8RGPWxbHM6FxF4eMEfqmQ6Bs5VjCdr",
|
||||||
|
amount=3000000 - 20000,
|
||||||
|
script_type=messages.OutputScriptType.PAYTOADDRESS,
|
||||||
|
)
|
||||||
|
|
||||||
|
with client:
|
||||||
|
details = messages.SignTx(version=1, timestamp=0x5BCF5C66)
|
||||||
|
_, timestamp_tx = btc.sign_tx(
|
||||||
|
client,
|
||||||
|
"Capricoin",
|
||||||
|
[inp1, inp2],
|
||||||
|
[out1],
|
||||||
|
details=details,
|
||||||
|
prev_txes=tx_cache("Capricoin"),
|
||||||
)
|
)
|
||||||
|
|
||||||
inp2 = proto.TxInputType(
|
# Accepted by network https://insight.capricoin.org/tx/1bf227e6e24fe1f8ac98849fe06a2c5b77762e906fcf7e82787675f7f3a10bb8
|
||||||
address_n=parse_path("m/44'/289'/0'/0/0"),
|
accepted_txhex = "01000000665ccf5b025f23e76913e3e53bc20a6c5db1607cc162d197c7dd791689da4ee81cc806f53b000000006b483045022100fce7ccbeb9524f36d118ebcfebcb133a05c236c4478e2051cfd5c9632920aee602206921b7be1a81f30cce3d8e7dba4597fc16a2761c42321c49d65eeacdfe3781250121021fcf98aee04939ec7df5762f426dc2d1db8026e3a73c3bbe44749dacfbb61230ffffffff8c5e2c3ff2a6758e423f6d99f8ecf9f856e0e8ba29276dd7ff2d1b1f41e6a6f3010000006a473044022015d967166fe9f89fbed8747328b1c4658aa1d7163e731c5fd5908feafe08e9a6022028af30801098418bd298cc60b143c52c48466f5791256721304b6eba4fdf0b3c0121021fcf98aee04939ec7df5762f426dc2d1db8026e3a73c3bbe44749dacfbb61230ffffffff01a0782d00000000001976a914818437acfd15780debd31f3fd21d4ca678bb36d188ac00000000"
|
||||||
prev_hash=TXHASH_f3a6e6,
|
assert timestamp_tx.hex() == accepted_txhex
|
||||||
prev_index=1,
|
|
||||||
)
|
|
||||||
|
|
||||||
out1 = proto.TxOutputType(
|
|
||||||
address="CUGi8RGPWxbHM6FxF4eMEfqmQ6Bs5VjCdr",
|
|
||||||
amount=3000000 - 20000,
|
|
||||||
script_type=proto.OutputScriptType.PAYTOADDRESS,
|
|
||||||
)
|
|
||||||
|
|
||||||
with self.client:
|
|
||||||
timestamp_signatures, timestamp_tx = btc.sign_tx(
|
|
||||||
self.client,
|
|
||||||
"Capricoin",
|
|
||||||
[inp1, inp2],
|
|
||||||
[out1],
|
|
||||||
version=1,
|
|
||||||
timestamp=0x5BCF5C66,
|
|
||||||
)
|
|
||||||
|
|
||||||
# Accepted by network https://insight.capricoin.org/tx/1bf227e6e24fe1f8ac98849fe06a2c5b77762e906fcf7e82787675f7f3a10bb8
|
|
||||||
accepted_txhex = "01000000665ccf5b025f23e76913e3e53bc20a6c5db1607cc162d197c7dd791689da4ee81cc806f53b000000006b483045022100fce7ccbeb9524f36d118ebcfebcb133a05c236c4478e2051cfd5c9632920aee602206921b7be1a81f30cce3d8e7dba4597fc16a2761c42321c49d65eeacdfe3781250121021fcf98aee04939ec7df5762f426dc2d1db8026e3a73c3bbe44749dacfbb61230ffffffff8c5e2c3ff2a6758e423f6d99f8ecf9f856e0e8ba29276dd7ff2d1b1f41e6a6f3010000006a473044022015d967166fe9f89fbed8747328b1c4658aa1d7163e731c5fd5908feafe08e9a6022028af30801098418bd298cc60b143c52c48466f5791256721304b6eba4fdf0b3c0121021fcf98aee04939ec7df5762f426dc2d1db8026e3a73c3bbe44749dacfbb61230ffffffff01a0782d00000000001976a914818437acfd15780debd31f3fd21d4ca678bb36d188ac00000000"
|
|
||||||
assert timestamp_tx.hex() == accepted_txhex
|
|
||||||
|
@ -16,12 +16,13 @@
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from trezorlib import btc, coins, messages as proto
|
from trezorlib import btc, messages as proto
|
||||||
from trezorlib.tools import parse_path
|
from trezorlib.tools import parse_path
|
||||||
|
|
||||||
from .common import TrezorTest
|
from .common import TrezorTest
|
||||||
|
from ..support.tx_cache import tx_cache
|
||||||
|
|
||||||
TxApiDecredTestnet = coins.tx_api["Decred Testnet"]
|
TX_API = tx_cache("Decred Testnet")
|
||||||
|
|
||||||
|
|
||||||
TXHASH_e16248 = bytes.fromhex(
|
TXHASH_e16248 = bytes.fromhex(
|
||||||
@ -48,7 +49,6 @@ TXHASH_16da18 = bytes.fromhex(
|
|||||||
class TestMsgSigntxDecred(TrezorTest):
|
class TestMsgSigntxDecred(TrezorTest):
|
||||||
def test_send_decred(self):
|
def test_send_decred(self):
|
||||||
self.setup_mnemonic_allallall()
|
self.setup_mnemonic_allallall()
|
||||||
self.client.set_tx_api(TxApiDecredTestnet)
|
|
||||||
|
|
||||||
inp1 = proto.TxInputType(
|
inp1 = proto.TxInputType(
|
||||||
# TscqTv1he8MZrV321SfRghw7LFBCJDKB3oz
|
# TscqTv1he8MZrV321SfRghw7LFBCJDKB3oz
|
||||||
@ -109,8 +109,8 @@ class TestMsgSigntxDecred(TrezorTest):
|
|||||||
proto.TxRequest(request_type=proto.RequestType.TXFINISHED),
|
proto.TxRequest(request_type=proto.RequestType.TXFINISHED),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
(signatures, serialized_tx) = btc.sign_tx(
|
_, serialized_tx = btc.sign_tx(
|
||||||
self.client, "Decred Testnet", [inp1], [out1]
|
self.client, "Decred Testnet", [inp1], [out1], prev_txes=TX_API
|
||||||
)
|
)
|
||||||
|
|
||||||
assert (
|
assert (
|
||||||
@ -120,7 +120,6 @@ class TestMsgSigntxDecred(TrezorTest):
|
|||||||
|
|
||||||
def test_send_decred_change(self):
|
def test_send_decred_change(self):
|
||||||
self.setup_mnemonic_allallall()
|
self.setup_mnemonic_allallall()
|
||||||
self.client.set_tx_api(TxApiDecredTestnet)
|
|
||||||
|
|
||||||
inp1 = proto.TxInputType(
|
inp1 = proto.TxInputType(
|
||||||
# TscqTv1he8MZrV321SfRghw7LFBCJDKB3oz
|
# TscqTv1he8MZrV321SfRghw7LFBCJDKB3oz
|
||||||
@ -264,8 +263,12 @@ class TestMsgSigntxDecred(TrezorTest):
|
|||||||
proto.TxRequest(request_type=proto.RequestType.TXFINISHED),
|
proto.TxRequest(request_type=proto.RequestType.TXFINISHED),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
(signatures, serialized_tx) = btc.sign_tx(
|
_, serialized_tx = btc.sign_tx(
|
||||||
self.client, "Decred Testnet", [inp1, inp2, inp3], [out1, out2]
|
self.client,
|
||||||
|
"Decred Testnet",
|
||||||
|
[inp1, inp2, inp3],
|
||||||
|
[out1, out2],
|
||||||
|
prev_txes=TX_API,
|
||||||
)
|
)
|
||||||
|
|
||||||
assert (
|
assert (
|
||||||
@ -275,7 +278,6 @@ class TestMsgSigntxDecred(TrezorTest):
|
|||||||
|
|
||||||
def test_decred_multisig_change(self):
|
def test_decred_multisig_change(self):
|
||||||
self.setup_mnemonic_allallall()
|
self.setup_mnemonic_allallall()
|
||||||
self.client.set_tx_api(TxApiDecredTestnet)
|
|
||||||
|
|
||||||
paths = [parse_path("m/48'/1'/%d'" % index) for index in range(3)]
|
paths = [parse_path("m/48'/1'/%d'" % index) for index in range(3)]
|
||||||
nodes = [
|
nodes = [
|
||||||
@ -414,8 +416,12 @@ class TestMsgSigntxDecred(TrezorTest):
|
|||||||
proto.TxRequest(request_type=proto.RequestType.TXFINISHED),
|
proto.TxRequest(request_type=proto.RequestType.TXFINISHED),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
(signature, serialized_tx) = btc.sign_tx(
|
signature, serialized_tx = btc.sign_tx(
|
||||||
self.client, "Decred Testnet", [inp1, inp2], [out1, out2]
|
self.client,
|
||||||
|
"Decred Testnet",
|
||||||
|
[inp1, inp2],
|
||||||
|
[out1, out2],
|
||||||
|
prev_txes=TX_API,
|
||||||
)
|
)
|
||||||
|
|
||||||
signatures[0][index] = signature[0]
|
signatures[0][index] = signature[0]
|
||||||
|
@ -18,19 +18,18 @@ import pytest
|
|||||||
|
|
||||||
from trezorlib import btc, messages as proto
|
from trezorlib import btc, messages as proto
|
||||||
from trezorlib.tools import H_, CallException, parse_path
|
from trezorlib.tools import H_, CallException, parse_path
|
||||||
from trezorlib.tx_api import TxApiInsight
|
|
||||||
|
|
||||||
from ..support.ckd_public import deserialize
|
from ..support.ckd_public import deserialize
|
||||||
|
from ..support.tx_cache import tx_cache
|
||||||
from .common import TrezorTest
|
from .common import TrezorTest
|
||||||
from .conftest import TREZOR_VERSION
|
from .conftest import TREZOR_VERSION
|
||||||
|
|
||||||
TxApiTestnet = TxApiInsight("insight_testnet")
|
TX_API = tx_cache("Testnet")
|
||||||
|
|
||||||
|
|
||||||
class TestMsgSigntxSegwit(TrezorTest):
|
class TestMsgSigntxSegwit(TrezorTest):
|
||||||
def test_send_p2sh(self):
|
def test_send_p2sh(self):
|
||||||
self.setup_mnemonic_allallall()
|
self.setup_mnemonic_allallall()
|
||||||
self.client.set_tx_api(TxApiTestnet)
|
|
||||||
inp1 = proto.TxInputType(
|
inp1 = proto.TxInputType(
|
||||||
address_n=parse_path("49'/1'/0'/1/0"),
|
address_n=parse_path("49'/1'/0'/1/0"),
|
||||||
# 2N1LGaGg836mqSQqiuUBLfcyGBhyZbremDX
|
# 2N1LGaGg836mqSQqiuUBLfcyGBhyZbremDX
|
||||||
@ -88,8 +87,8 @@ class TestMsgSigntxSegwit(TrezorTest):
|
|||||||
proto.TxRequest(request_type=proto.RequestType.TXFINISHED),
|
proto.TxRequest(request_type=proto.RequestType.TXFINISHED),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
(signatures, serialized_tx) = btc.sign_tx(
|
_, serialized_tx = btc.sign_tx(
|
||||||
self.client, "Testnet", [inp1], [out1, out2]
|
self.client, "Testnet", [inp1], [out1, out2], prev_txes=TX_API
|
||||||
)
|
)
|
||||||
|
|
||||||
assert (
|
assert (
|
||||||
@ -99,7 +98,6 @@ class TestMsgSigntxSegwit(TrezorTest):
|
|||||||
|
|
||||||
def test_send_p2sh_change(self):
|
def test_send_p2sh_change(self):
|
||||||
self.setup_mnemonic_allallall()
|
self.setup_mnemonic_allallall()
|
||||||
self.client.set_tx_api(TxApiTestnet)
|
|
||||||
inp1 = proto.TxInputType(
|
inp1 = proto.TxInputType(
|
||||||
address_n=parse_path("49'/1'/0'/1/0"),
|
address_n=parse_path("49'/1'/0'/1/0"),
|
||||||
# 2N1LGaGg836mqSQqiuUBLfcyGBhyZbremDX
|
# 2N1LGaGg836mqSQqiuUBLfcyGBhyZbremDX
|
||||||
@ -156,8 +154,8 @@ class TestMsgSigntxSegwit(TrezorTest):
|
|||||||
proto.TxRequest(request_type=proto.RequestType.TXFINISHED),
|
proto.TxRequest(request_type=proto.RequestType.TXFINISHED),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
(signatures, serialized_tx) = btc.sign_tx(
|
_, serialized_tx = btc.sign_tx(
|
||||||
self.client, "Testnet", [inp1], [out1, out2]
|
self.client, "Testnet", [inp1], [out1, out2], prev_txes=TX_API
|
||||||
)
|
)
|
||||||
|
|
||||||
assert (
|
assert (
|
||||||
@ -167,7 +165,6 @@ class TestMsgSigntxSegwit(TrezorTest):
|
|||||||
|
|
||||||
def test_send_multisig_1(self):
|
def test_send_multisig_1(self):
|
||||||
self.setup_mnemonic_allallall()
|
self.setup_mnemonic_allallall()
|
||||||
self.client.set_tx_api(TxApiTestnet)
|
|
||||||
nodes = map(
|
nodes = map(
|
||||||
lambda index: btc.get_public_node(
|
lambda index: btc.get_public_node(
|
||||||
self.client, parse_path("999'/1'/%d'" % index)
|
self.client, parse_path("999'/1'/%d'" % index)
|
||||||
@ -232,9 +229,11 @@ class TestMsgSigntxSegwit(TrezorTest):
|
|||||||
proto.TxRequest(request_type=proto.RequestType.TXFINISHED),
|
proto.TxRequest(request_type=proto.RequestType.TXFINISHED),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
(signatures1, _) = btc.sign_tx(self.client, "Testnet", [inp1], [out1])
|
signatures, _ = btc.sign_tx(
|
||||||
|
self.client, "Testnet", [inp1], [out1], prev_txes=TX_API
|
||||||
|
)
|
||||||
# store signature
|
# store signature
|
||||||
inp1.multisig.signatures[0] = signatures1[0]
|
inp1.multisig.signatures[0] = signatures[0]
|
||||||
# sign with third key
|
# sign with third key
|
||||||
inp1.address_n[2] = H_(3)
|
inp1.address_n[2] = H_(3)
|
||||||
self.client.set_expected_responses(
|
self.client.set_expected_responses(
|
||||||
@ -264,8 +263,8 @@ class TestMsgSigntxSegwit(TrezorTest):
|
|||||||
proto.TxRequest(request_type=proto.RequestType.TXFINISHED),
|
proto.TxRequest(request_type=proto.RequestType.TXFINISHED),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
(signatures2, serialized_tx) = btc.sign_tx(
|
_, serialized_tx = btc.sign_tx(
|
||||||
self.client, "Testnet", [inp1], [out1]
|
self.client, "Testnet", [inp1], [out1], prev_txes=TX_API
|
||||||
)
|
)
|
||||||
|
|
||||||
assert (
|
assert (
|
||||||
@ -278,7 +277,6 @@ class TestMsgSigntxSegwit(TrezorTest):
|
|||||||
# that it matches the change output
|
# that it matches the change output
|
||||||
|
|
||||||
self.setup_mnemonic_allallall()
|
self.setup_mnemonic_allallall()
|
||||||
self.client.set_tx_api(TxApiTestnet)
|
|
||||||
inp1 = proto.TxInputType(
|
inp1 = proto.TxInputType(
|
||||||
address_n=parse_path("49'/1'/0'/1/0"),
|
address_n=parse_path("49'/1'/0'/1/0"),
|
||||||
# 2N1LGaGg836mqSQqiuUBLfcyGBhyZbremDX
|
# 2N1LGaGg836mqSQqiuUBLfcyGBhyZbremDX
|
||||||
@ -300,28 +298,6 @@ class TestMsgSigntxSegwit(TrezorTest):
|
|||||||
amount=123456789 - 11000 - 12300000,
|
amount=123456789 - 11000 - 12300000,
|
||||||
)
|
)
|
||||||
|
|
||||||
global run_attack
|
|
||||||
run_attack = True
|
|
||||||
|
|
||||||
def attack_processor(req, msg):
|
|
||||||
global run_attack
|
|
||||||
|
|
||||||
if req.details.tx_hash is not None:
|
|
||||||
return msg
|
|
||||||
|
|
||||||
if req.request_type != proto.RequestType.TXINPUT:
|
|
||||||
return msg
|
|
||||||
|
|
||||||
if req.details.request_index != 0:
|
|
||||||
return msg
|
|
||||||
|
|
||||||
if not run_attack:
|
|
||||||
return msg
|
|
||||||
|
|
||||||
msg.inputs[0].address_n[2] = H_(12345)
|
|
||||||
run_attack = False
|
|
||||||
return msg
|
|
||||||
|
|
||||||
# Test if the transaction can be signed normally
|
# Test if the transaction can be signed normally
|
||||||
with self.client:
|
with self.client:
|
||||||
self.client.set_expected_responses(
|
self.client.set_expected_responses(
|
||||||
@ -360,8 +336,8 @@ class TestMsgSigntxSegwit(TrezorTest):
|
|||||||
proto.TxRequest(request_type=proto.RequestType.TXFINISHED),
|
proto.TxRequest(request_type=proto.RequestType.TXFINISHED),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
(signatures, serialized_tx) = btc.sign_tx(
|
_, serialized_tx = btc.sign_tx(
|
||||||
self.client, "Testnet", [inp1], [out1, out2]
|
self.client, "Testnet", [inp1], [out1, out2], prev_txes=TX_API
|
||||||
)
|
)
|
||||||
|
|
||||||
assert (
|
assert (
|
||||||
@ -369,7 +345,19 @@ class TestMsgSigntxSegwit(TrezorTest):
|
|||||||
== "0100000000010137c361fb8f2d9056ba8c98c5611930fcb48cacfdd0fe2e0449d83eea982f91200000000017160014d16b8c0680c61fc6ed2e407455715055e41052f5ffffffff02e0aebb00000000001976a91414fdede0ddc3be652a0ce1afbc1b509a55b6b94888ac3df39f060000000017a914dae9e09a7fc3bbe5a716fffec1bbb340b82a4fb9870248304502210099b5c4f8fd4402c9c0136fee5f711137d64fc9f14587e01bfa7798f5428f845d0220253e21c98f5b1b64efae69bc2ea9799c5620a43450baa6762a0c3cf4fdc886e5012103e7bfe10708f715e8538c92d46ca50db6f657bbc455b7494e6a0303ccdb868b7900000000"
|
== "0100000000010137c361fb8f2d9056ba8c98c5611930fcb48cacfdd0fe2e0449d83eea982f91200000000017160014d16b8c0680c61fc6ed2e407455715055e41052f5ffffffff02e0aebb00000000001976a91414fdede0ddc3be652a0ce1afbc1b509a55b6b94888ac3df39f060000000017a914dae9e09a7fc3bbe5a716fffec1bbb340b82a4fb9870248304502210099b5c4f8fd4402c9c0136fee5f711137d64fc9f14587e01bfa7798f5428f845d0220253e21c98f5b1b64efae69bc2ea9799c5620a43450baa6762a0c3cf4fdc886e5012103e7bfe10708f715e8538c92d46ca50db6f657bbc455b7494e6a0303ccdb868b7900000000"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
run_attack = True
|
||||||
|
|
||||||
|
def attack_processor(msg):
|
||||||
|
nonlocal run_attack
|
||||||
|
|
||||||
|
if run_attack and msg.tx.inputs and msg.tx.inputs[0] == inp1:
|
||||||
|
run_attack = False
|
||||||
|
msg.tx.inputs[0].address_n[2] = H_(12345)
|
||||||
|
|
||||||
|
return msg
|
||||||
|
|
||||||
# Now run the attack, must trigger the exception
|
# Now run the attack, must trigger the exception
|
||||||
|
self.client.set_filter(proto.TxAck, attack_processor)
|
||||||
with self.client:
|
with self.client:
|
||||||
self.client.set_expected_responses(
|
self.client.set_expected_responses(
|
||||||
[
|
[
|
||||||
@ -396,11 +384,7 @@ class TestMsgSigntxSegwit(TrezorTest):
|
|||||||
)
|
)
|
||||||
with pytest.raises(CallException) as exc:
|
with pytest.raises(CallException) as exc:
|
||||||
btc.sign_tx(
|
btc.sign_tx(
|
||||||
self.client,
|
self.client, "Testnet", [inp1], [out1, out2], prev_txes=TX_API
|
||||||
"Testnet",
|
|
||||||
[inp1],
|
|
||||||
[out1, out2],
|
|
||||||
debug_processor=attack_processor,
|
|
||||||
)
|
)
|
||||||
assert exc.value.args[0] == proto.FailureType.ProcessError
|
assert exc.value.args[0] == proto.FailureType.ProcessError
|
||||||
if TREZOR_VERSION == 1:
|
if TREZOR_VERSION == 1:
|
||||||
|
@ -16,18 +16,17 @@
|
|||||||
|
|
||||||
from trezorlib import btc, messages as proto
|
from trezorlib import btc, messages as proto
|
||||||
from trezorlib.tools import H_, parse_path
|
from trezorlib.tools import H_, parse_path
|
||||||
from trezorlib.tx_api import TxApiInsight
|
|
||||||
|
|
||||||
from ..support.ckd_public import deserialize
|
from ..support.ckd_public import deserialize
|
||||||
|
from ..support.tx_cache import tx_cache
|
||||||
from .common import TrezorTest
|
from .common import TrezorTest
|
||||||
|
|
||||||
TxApiTestnet = TxApiInsight("insight_testnet")
|
TX_API = tx_cache("Testnet")
|
||||||
|
|
||||||
|
|
||||||
class TestMsgSigntxSegwitNative(TrezorTest):
|
class TestMsgSigntxSegwitNative(TrezorTest):
|
||||||
def test_send_p2sh(self):
|
def test_send_p2sh(self):
|
||||||
self.setup_mnemonic_allallall()
|
self.setup_mnemonic_allallall()
|
||||||
self.client.set_tx_api(TxApiTestnet)
|
|
||||||
inp1 = proto.TxInputType(
|
inp1 = proto.TxInputType(
|
||||||
address_n=parse_path("49'/1'/0'/1/0"),
|
address_n=parse_path("49'/1'/0'/1/0"),
|
||||||
# 2N1LGaGg836mqSQqiuUBLfcyGBhyZbremDX
|
# 2N1LGaGg836mqSQqiuUBLfcyGBhyZbremDX
|
||||||
@ -85,8 +84,8 @@ class TestMsgSigntxSegwitNative(TrezorTest):
|
|||||||
proto.TxRequest(request_type=proto.RequestType.TXFINISHED),
|
proto.TxRequest(request_type=proto.RequestType.TXFINISHED),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
(signatures, serialized_tx) = btc.sign_tx(
|
_, serialized_tx = btc.sign_tx(
|
||||||
self.client, "Testnet", [inp1], [out1, out2]
|
self.client, "Testnet", [inp1], [out1, out2], prev_txes=TX_API
|
||||||
)
|
)
|
||||||
|
|
||||||
assert (
|
assert (
|
||||||
@ -96,7 +95,6 @@ class TestMsgSigntxSegwitNative(TrezorTest):
|
|||||||
|
|
||||||
def test_send_p2sh_change(self):
|
def test_send_p2sh_change(self):
|
||||||
self.setup_mnemonic_allallall()
|
self.setup_mnemonic_allallall()
|
||||||
self.client.set_tx_api(TxApiTestnet)
|
|
||||||
inp1 = proto.TxInputType(
|
inp1 = proto.TxInputType(
|
||||||
address_n=parse_path("49'/1'/0'/1/0"),
|
address_n=parse_path("49'/1'/0'/1/0"),
|
||||||
# 2N1LGaGg836mqSQqiuUBLfcyGBhyZbremDX
|
# 2N1LGaGg836mqSQqiuUBLfcyGBhyZbremDX
|
||||||
@ -153,8 +151,8 @@ class TestMsgSigntxSegwitNative(TrezorTest):
|
|||||||
proto.TxRequest(request_type=proto.RequestType.TXFINISHED),
|
proto.TxRequest(request_type=proto.RequestType.TXFINISHED),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
(signatures, serialized_tx) = btc.sign_tx(
|
_, serialized_tx = btc.sign_tx(
|
||||||
self.client, "Testnet", [inp1], [out1, out2]
|
self.client, "Testnet", [inp1], [out1, out2], prev_txes=TX_API
|
||||||
)
|
)
|
||||||
|
|
||||||
assert (
|
assert (
|
||||||
@ -164,7 +162,6 @@ class TestMsgSigntxSegwitNative(TrezorTest):
|
|||||||
|
|
||||||
def test_send_native(self):
|
def test_send_native(self):
|
||||||
self.setup_mnemonic_allallall()
|
self.setup_mnemonic_allallall()
|
||||||
self.client.set_tx_api(TxApiTestnet)
|
|
||||||
inp1 = proto.TxInputType(
|
inp1 = proto.TxInputType(
|
||||||
address_n=parse_path("49'/1'/0'/0/0"),
|
address_n=parse_path("49'/1'/0'/0/0"),
|
||||||
# tb1qqzv60m9ajw8drqulta4ld4gfx0rdh82un5s65s
|
# tb1qqzv60m9ajw8drqulta4ld4gfx0rdh82un5s65s
|
||||||
@ -222,8 +219,8 @@ class TestMsgSigntxSegwitNative(TrezorTest):
|
|||||||
proto.TxRequest(request_type=proto.RequestType.TXFINISHED),
|
proto.TxRequest(request_type=proto.RequestType.TXFINISHED),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
(signatures, serialized_tx) = btc.sign_tx(
|
_, serialized_tx = btc.sign_tx(
|
||||||
self.client, "Testnet", [inp1], [out1, out2]
|
self.client, "Testnet", [inp1], [out1, out2], prev_txes=TX_API
|
||||||
)
|
)
|
||||||
|
|
||||||
assert (
|
assert (
|
||||||
@ -233,7 +230,6 @@ class TestMsgSigntxSegwitNative(TrezorTest):
|
|||||||
|
|
||||||
def test_send_native_change(self):
|
def test_send_native_change(self):
|
||||||
self.setup_mnemonic_allallall()
|
self.setup_mnemonic_allallall()
|
||||||
self.client.set_tx_api(TxApiTestnet)
|
|
||||||
inp1 = proto.TxInputType(
|
inp1 = proto.TxInputType(
|
||||||
address_n=parse_path("49'/1'/0'/0/0"),
|
address_n=parse_path("49'/1'/0'/0/0"),
|
||||||
# tb1qqzv60m9ajw8drqulta4ld4gfx0rdh82un5s65s
|
# tb1qqzv60m9ajw8drqulta4ld4gfx0rdh82un5s65s
|
||||||
@ -290,8 +286,8 @@ class TestMsgSigntxSegwitNative(TrezorTest):
|
|||||||
proto.TxRequest(request_type=proto.RequestType.TXFINISHED),
|
proto.TxRequest(request_type=proto.RequestType.TXFINISHED),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
(signatures, serialized_tx) = btc.sign_tx(
|
_, serialized_tx = btc.sign_tx(
|
||||||
self.client, "Testnet", [inp1], [out1, out2]
|
self.client, "Testnet", [inp1], [out1, out2], prev_txes=TX_API
|
||||||
)
|
)
|
||||||
|
|
||||||
assert (
|
assert (
|
||||||
@ -301,7 +297,6 @@ class TestMsgSigntxSegwitNative(TrezorTest):
|
|||||||
|
|
||||||
def test_send_both(self):
|
def test_send_both(self):
|
||||||
self.setup_mnemonic_allallall()
|
self.setup_mnemonic_allallall()
|
||||||
self.client.set_tx_api(TxApiTestnet)
|
|
||||||
inp1 = proto.TxInputType(
|
inp1 = proto.TxInputType(
|
||||||
address_n=parse_path("49'/1'/0'/1/0"),
|
address_n=parse_path("49'/1'/0'/1/0"),
|
||||||
# 2N1LGaGg836mqSQqiuUBLfcyGBhyZbremDX
|
# 2N1LGaGg836mqSQqiuUBLfcyGBhyZbremDX
|
||||||
@ -398,8 +393,12 @@ class TestMsgSigntxSegwitNative(TrezorTest):
|
|||||||
proto.TxRequest(request_type=proto.RequestType.TXFINISHED),
|
proto.TxRequest(request_type=proto.RequestType.TXFINISHED),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
(signatures, serialized_tx) = btc.sign_tx(
|
_, serialized_tx = btc.sign_tx(
|
||||||
self.client, "Testnet", [inp1, inp2], [out1, out2, out3]
|
self.client,
|
||||||
|
"Testnet",
|
||||||
|
[inp1, inp2],
|
||||||
|
[out1, out2, out3],
|
||||||
|
prev_txes=TX_API,
|
||||||
)
|
)
|
||||||
|
|
||||||
# 0e480a97c7a545c85e101a2f13c9af0e115d43734e1448f0cac3e55fe8e7399d
|
# 0e480a97c7a545c85e101a2f13c9af0e115d43734e1448f0cac3e55fe8e7399d
|
||||||
@ -410,7 +409,6 @@ class TestMsgSigntxSegwitNative(TrezorTest):
|
|||||||
|
|
||||||
def test_send_multisig_1(self):
|
def test_send_multisig_1(self):
|
||||||
self.setup_mnemonic_allallall()
|
self.setup_mnemonic_allallall()
|
||||||
self.client.set_tx_api(TxApiTestnet)
|
|
||||||
nodes = [
|
nodes = [
|
||||||
btc.get_public_node(self.client, parse_path("999'/1'/%d'" % index))
|
btc.get_public_node(self.client, parse_path("999'/1'/%d'" % index))
|
||||||
for index in range(1, 4)
|
for index in range(1, 4)
|
||||||
@ -473,9 +471,11 @@ class TestMsgSigntxSegwitNative(TrezorTest):
|
|||||||
proto.TxRequest(request_type=proto.RequestType.TXFINISHED),
|
proto.TxRequest(request_type=proto.RequestType.TXFINISHED),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
(signatures1, _) = btc.sign_tx(self.client, "Testnet", [inp1], [out1])
|
signatures, _ = btc.sign_tx(
|
||||||
|
self.client, "Testnet", [inp1], [out1], prev_txes=TX_API
|
||||||
|
)
|
||||||
# store signature
|
# store signature
|
||||||
inp1.multisig.signatures[0] = signatures1[0]
|
inp1.multisig.signatures[0] = signatures[0]
|
||||||
# sign with third key
|
# sign with third key
|
||||||
inp1.address_n[2] = H_(3)
|
inp1.address_n[2] = H_(3)
|
||||||
self.client.set_expected_responses(
|
self.client.set_expected_responses(
|
||||||
@ -505,8 +505,8 @@ class TestMsgSigntxSegwitNative(TrezorTest):
|
|||||||
proto.TxRequest(request_type=proto.RequestType.TXFINISHED),
|
proto.TxRequest(request_type=proto.RequestType.TXFINISHED),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
(signatures2, serialized_tx) = btc.sign_tx(
|
_, serialized_tx = btc.sign_tx(
|
||||||
self.client, "Testnet", [inp1], [out1]
|
self.client, "Testnet", [inp1], [out1], prev_txes=TX_API
|
||||||
)
|
)
|
||||||
|
|
||||||
# f41cbedd8becee05a830f418d13aa665125464547db5c7a6cd28f21639fe1228
|
# f41cbedd8becee05a830f418d13aa665125464547db5c7a6cd28f21639fe1228
|
||||||
@ -517,7 +517,6 @@ class TestMsgSigntxSegwitNative(TrezorTest):
|
|||||||
|
|
||||||
def test_send_multisig_2(self):
|
def test_send_multisig_2(self):
|
||||||
self.setup_mnemonic_allallall()
|
self.setup_mnemonic_allallall()
|
||||||
self.client.set_tx_api(TxApiTestnet)
|
|
||||||
nodes = [
|
nodes = [
|
||||||
btc.get_public_node(self.client, parse_path("999'/1'/%d'" % index))
|
btc.get_public_node(self.client, parse_path("999'/1'/%d'" % index))
|
||||||
for index in range(1, 4)
|
for index in range(1, 4)
|
||||||
@ -580,9 +579,11 @@ class TestMsgSigntxSegwitNative(TrezorTest):
|
|||||||
proto.TxRequest(request_type=proto.RequestType.TXFINISHED),
|
proto.TxRequest(request_type=proto.RequestType.TXFINISHED),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
(signatures1, _) = btc.sign_tx(self.client, "Testnet", [inp1], [out1])
|
signatures, _ = btc.sign_tx(
|
||||||
|
self.client, "Testnet", [inp1], [out1], prev_txes=TX_API
|
||||||
|
)
|
||||||
# store signature
|
# store signature
|
||||||
inp1.multisig.signatures[1] = signatures1[0]
|
inp1.multisig.signatures[1] = signatures[0]
|
||||||
# sign with first key
|
# sign with first key
|
||||||
inp1.address_n[2] = H_(1)
|
inp1.address_n[2] = H_(1)
|
||||||
self.client.set_expected_responses(
|
self.client.set_expected_responses(
|
||||||
@ -612,8 +613,8 @@ class TestMsgSigntxSegwitNative(TrezorTest):
|
|||||||
proto.TxRequest(request_type=proto.RequestType.TXFINISHED),
|
proto.TxRequest(request_type=proto.RequestType.TXFINISHED),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
(signatures2, serialized_tx) = btc.sign_tx(
|
_, serialized_tx = btc.sign_tx(
|
||||||
self.client, "Testnet", [inp1], [out1]
|
self.client, "Testnet", [inp1], [out1], prev_txes=TX_API
|
||||||
)
|
)
|
||||||
|
|
||||||
# c9348040bbc2024e12dcb4a0b4806b0398646b91acf314da028c3f03dd0179fc
|
# c9348040bbc2024e12dcb4a0b4806b0398646b91acf314da028c3f03dd0179fc
|
||||||
@ -624,7 +625,6 @@ class TestMsgSigntxSegwitNative(TrezorTest):
|
|||||||
|
|
||||||
def test_send_multisig_3_change(self):
|
def test_send_multisig_3_change(self):
|
||||||
self.setup_mnemonic_allallall()
|
self.setup_mnemonic_allallall()
|
||||||
self.client.set_tx_api(TxApiTestnet)
|
|
||||||
nodes = [
|
nodes = [
|
||||||
btc.get_public_node(self.client, parse_path("999'/1'/%d'" % index))
|
btc.get_public_node(self.client, parse_path("999'/1'/%d'" % index))
|
||||||
for index in range(1, 4)
|
for index in range(1, 4)
|
||||||
@ -699,9 +699,11 @@ class TestMsgSigntxSegwitNative(TrezorTest):
|
|||||||
proto.TxRequest(request_type=proto.RequestType.TXFINISHED),
|
proto.TxRequest(request_type=proto.RequestType.TXFINISHED),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
(signatures1, _) = btc.sign_tx(self.client, "Testnet", [inp1], [out1])
|
signatures, _ = btc.sign_tx(
|
||||||
|
self.client, "Testnet", [inp1], [out1], prev_txes=TX_API
|
||||||
|
)
|
||||||
# store signature
|
# store signature
|
||||||
inp1.multisig.signatures[0] = signatures1[0]
|
inp1.multisig.signatures[0] = signatures[0]
|
||||||
# sign with third key
|
# sign with third key
|
||||||
inp1.address_n[2] = H_(3)
|
inp1.address_n[2] = H_(3)
|
||||||
out1.address_n[2] = H_(3)
|
out1.address_n[2] = H_(3)
|
||||||
@ -731,8 +733,8 @@ class TestMsgSigntxSegwitNative(TrezorTest):
|
|||||||
proto.TxRequest(request_type=proto.RequestType.TXFINISHED),
|
proto.TxRequest(request_type=proto.RequestType.TXFINISHED),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
(signatures2, serialized_tx) = btc.sign_tx(
|
_, serialized_tx = btc.sign_tx(
|
||||||
self.client, "Testnet", [inp1], [out1]
|
self.client, "Testnet", [inp1], [out1], prev_txes=TX_API
|
||||||
)
|
)
|
||||||
|
|
||||||
# 31bc1c88ce6ae337a6b3057a16d5bad0b561ad1dfc047d0a7fbb8814668f91e5
|
# 31bc1c88ce6ae337a6b3057a16d5bad0b561ad1dfc047d0a7fbb8814668f91e5
|
||||||
@ -743,7 +745,6 @@ class TestMsgSigntxSegwitNative(TrezorTest):
|
|||||||
|
|
||||||
def test_send_multisig_4_change(self):
|
def test_send_multisig_4_change(self):
|
||||||
self.setup_mnemonic_allallall()
|
self.setup_mnemonic_allallall()
|
||||||
self.client.set_tx_api(TxApiTestnet)
|
|
||||||
nodes = [
|
nodes = [
|
||||||
btc.get_public_node(self.client, parse_path("999'/1'/%d'" % index))
|
btc.get_public_node(self.client, parse_path("999'/1'/%d'" % index))
|
||||||
for index in range(1, 4)
|
for index in range(1, 4)
|
||||||
@ -818,9 +819,11 @@ class TestMsgSigntxSegwitNative(TrezorTest):
|
|||||||
proto.TxRequest(request_type=proto.RequestType.TXFINISHED),
|
proto.TxRequest(request_type=proto.RequestType.TXFINISHED),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
(signatures1, _) = btc.sign_tx(self.client, "Testnet", [inp1], [out1])
|
signatures, _ = btc.sign_tx(
|
||||||
|
self.client, "Testnet", [inp1], [out1], prev_txes=TX_API
|
||||||
|
)
|
||||||
# store signature
|
# store signature
|
||||||
inp1.multisig.signatures[0] = signatures1[0]
|
inp1.multisig.signatures[0] = signatures[0]
|
||||||
# sign with third key
|
# sign with third key
|
||||||
inp1.address_n[2] = H_(3)
|
inp1.address_n[2] = H_(3)
|
||||||
out1.address_n[2] = H_(3)
|
out1.address_n[2] = H_(3)
|
||||||
@ -850,8 +853,8 @@ class TestMsgSigntxSegwitNative(TrezorTest):
|
|||||||
proto.TxRequest(request_type=proto.RequestType.TXFINISHED),
|
proto.TxRequest(request_type=proto.RequestType.TXFINISHED),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
(signatures2, serialized_tx) = btc.sign_tx(
|
_, serialized_tx = btc.sign_tx(
|
||||||
self.client, "Testnet", [inp1], [out1]
|
self.client, "Testnet", [inp1], [out1], prev_txes=TX_API
|
||||||
)
|
)
|
||||||
|
|
||||||
# c0bf56060a109624b4635222696d94a7d533cacea1b3f8245417a4348c045829
|
# c0bf56060a109624b4635222696d94a7d533cacea1b3f8245417a4348c045829
|
||||||
|
@ -20,8 +20,9 @@ from trezorlib import btc, coins, messages as proto
|
|||||||
from trezorlib.tools import parse_path
|
from trezorlib.tools import parse_path
|
||||||
|
|
||||||
from .common import TrezorTest
|
from .common import TrezorTest
|
||||||
|
from ..support.tx_cache import tx_cache
|
||||||
|
|
||||||
TxApiZcashTestnet = coins.tx_api["Zcash Testnet"]
|
TX_API = tx_cache("Zcash Testnet")
|
||||||
|
|
||||||
TXHASH_aaf51e = bytes.fromhex(
|
TXHASH_aaf51e = bytes.fromhex(
|
||||||
"aaf51e4606c264e47e5c42c958fe4cf1539c5172684721e38e69f4ef634d75dc"
|
"aaf51e4606c264e47e5c42c958fe4cf1539c5172684721e38e69f4ef634d75dc"
|
||||||
@ -55,7 +56,6 @@ class TestMsgSigntxZcash(TrezorTest):
|
|||||||
)
|
)
|
||||||
|
|
||||||
with self.client:
|
with self.client:
|
||||||
self.client.set_tx_api(TxApiZcashTestnet)
|
|
||||||
self.client.set_expected_responses(
|
self.client.set_expected_responses(
|
||||||
[
|
[
|
||||||
proto.TxRequest(
|
proto.TxRequest(
|
||||||
@ -80,14 +80,16 @@ class TestMsgSigntxZcash(TrezorTest):
|
|||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
(signatures, serialized_tx) = btc.sign_tx(
|
details = proto.SignTx(
|
||||||
|
version=3, overwintered=True, version_group_id=0x3C48270
|
||||||
|
)
|
||||||
|
_, serialized_tx = btc.sign_tx(
|
||||||
self.client,
|
self.client,
|
||||||
"Zcash Testnet",
|
"Zcash Testnet",
|
||||||
[inp1],
|
[inp1],
|
||||||
[out1],
|
[out1],
|
||||||
version=3,
|
details=details,
|
||||||
overwintered=True,
|
prev_txes=TX_API,
|
||||||
version_group_id=0x3C48270,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# Accepted by network: tx eda9b772c47f0c29310759960e0081c98707aa67a0a2738bcc71439fcf360675
|
# Accepted by network: tx eda9b772c47f0c29310759960e0081c98707aa67a0a2738bcc71439fcf360675
|
||||||
@ -118,7 +120,6 @@ class TestMsgSigntxZcash(TrezorTest):
|
|||||||
)
|
)
|
||||||
|
|
||||||
with self.client:
|
with self.client:
|
||||||
self.client.set_tx_api(TxApiZcashTestnet)
|
|
||||||
self.client.set_expected_responses(
|
self.client.set_expected_responses(
|
||||||
[
|
[
|
||||||
proto.TxRequest(
|
proto.TxRequest(
|
||||||
@ -143,14 +144,16 @@ class TestMsgSigntxZcash(TrezorTest):
|
|||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
(signatures, serialized_tx) = btc.sign_tx(
|
details = proto.SignTx(
|
||||||
|
version=4, overwintered=True, version_group_id=0x892F2085
|
||||||
|
)
|
||||||
|
_, serialized_tx = btc.sign_tx(
|
||||||
self.client,
|
self.client,
|
||||||
"Zcash Testnet",
|
"Zcash Testnet",
|
||||||
[inp1],
|
[inp1],
|
||||||
[out1],
|
[out1],
|
||||||
version=4,
|
details=details,
|
||||||
overwintered=True,
|
prev_txes=TX_API,
|
||||||
version_group_id=0x892F2085,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# Accepted by network: tx 0cef132c1d6d67f11cfa48f7fca3209da29cf872ac782354bedb686e61a17a78
|
# Accepted by network: tx 0cef132c1d6d67f11cfa48f7fca3209da29cf872ac782354bedb686e61a17a78
|
||||||
|
@ -20,8 +20,11 @@ from trezorlib import btc, messages as proto
|
|||||||
from trezorlib.tools import CallException
|
from trezorlib.tools import CallException
|
||||||
|
|
||||||
from ..support import ckd_public as bip32
|
from ..support import ckd_public as bip32
|
||||||
|
from ..support.tx_cache import tx_cache
|
||||||
from .common import TrezorTest
|
from .common import TrezorTest
|
||||||
|
|
||||||
|
TX_API = tx_cache("Bitcoin")
|
||||||
|
|
||||||
TXHASH_c6091a = bytes.fromhex(
|
TXHASH_c6091a = bytes.fromhex(
|
||||||
"c6091adf4c0c23982a35899a6e58ae11e703eacd7954f588ed4b9cdefc4dba52"
|
"c6091adf4c0c23982a35899a6e58ae11e703eacd7954f588ed4b9cdefc4dba52"
|
||||||
)
|
)
|
||||||
@ -139,7 +142,9 @@ class TestMultisig(TrezorTest):
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Now we have first signature
|
# Now we have first signature
|
||||||
(signatures1, _) = btc.sign_tx(self.client, "Bitcoin", [inp1], [out1])
|
signatures1, _ = btc.sign_tx(
|
||||||
|
self.client, "Bitcoin", [inp1], [out1], prev_txes=TX_API
|
||||||
|
)
|
||||||
|
|
||||||
assert (
|
assert (
|
||||||
signatures1[0].hex()
|
signatures1[0].hex()
|
||||||
@ -222,8 +227,8 @@ class TestMultisig(TrezorTest):
|
|||||||
proto.TxRequest(request_type=proto.RequestType.TXFINISHED),
|
proto.TxRequest(request_type=proto.RequestType.TXFINISHED),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
(signatures2, serialized_tx) = btc.sign_tx(
|
signatures2, serialized_tx = btc.sign_tx(
|
||||||
self.client, "Bitcoin", [inp3], [out1]
|
self.client, "Bitcoin", [inp3], [out1], prev_txes=TX_API
|
||||||
)
|
)
|
||||||
|
|
||||||
assert (
|
assert (
|
||||||
@ -287,8 +292,8 @@ class TestMultisig(TrezorTest):
|
|||||||
)
|
)
|
||||||
|
|
||||||
with self.client:
|
with self.client:
|
||||||
(sig, serialized_tx) = btc.sign_tx(
|
sig, serialized_tx = btc.sign_tx(
|
||||||
self.client, "Bitcoin", [inp1], [out1]
|
self.client, "Bitcoin", [inp1], [out1], prev_txes=TX_API
|
||||||
)
|
)
|
||||||
signatures[x] = sig[0]
|
signatures[x] = sig[0]
|
||||||
|
|
||||||
@ -345,7 +350,7 @@ class TestMultisig(TrezorTest):
|
|||||||
)
|
)
|
||||||
|
|
||||||
with pytest.raises(CallException) as exc:
|
with pytest.raises(CallException) as exc:
|
||||||
btc.sign_tx(self.client, "Bitcoin", [inp1], [out1])
|
btc.sign_tx(self.client, "Bitcoin", [inp1], [out1], prev_txes=TX_API)
|
||||||
|
|
||||||
assert exc.value.args[0] == proto.FailureType.DataError
|
assert exc.value.args[0] == proto.FailureType.DataError
|
||||||
assert exc.value.args[1].endswith("Pubkey not found in multisig script")
|
assert exc.value.args[1].endswith("Pubkey not found in multisig script")
|
||||||
|
@ -16,19 +16,15 @@
|
|||||||
|
|
||||||
from trezorlib import btc, messages as proto
|
from trezorlib import btc, messages as proto
|
||||||
from trezorlib.tools import H_, parse_path
|
from trezorlib.tools import H_, parse_path
|
||||||
from trezorlib.tx_api import TxApiInsight
|
|
||||||
|
|
||||||
from ..support import ckd_public as bip32
|
from ..support import ckd_public as bip32
|
||||||
|
from ..support.tx_cache import tx_cache
|
||||||
from .common import TrezorTest
|
from .common import TrezorTest
|
||||||
|
|
||||||
TxApiTestnet = TxApiInsight("insight_testnet")
|
TX_API = tx_cache("Testnet")
|
||||||
|
|
||||||
|
|
||||||
class TestMultisigChange(TrezorTest):
|
class TestMultisigChange(TrezorTest):
|
||||||
def setup_method(self, method):
|
|
||||||
super(TestMultisigChange, self).setup_method(method)
|
|
||||||
self.client.set_tx_api(TxApiTestnet)
|
|
||||||
|
|
||||||
node_ext1 = bip32.deserialize(
|
node_ext1 = bip32.deserialize(
|
||||||
"tpubDADHV9u9Y6gkggintTdMjJE3be58zKNLhpxBQyuEM6Pwx3sN9JVLmMCMN4DNVwL9AKec27z5TaWcWuHzMXiGAtcra5DjwWbvppGX4gaEGVN"
|
"tpubDADHV9u9Y6gkggintTdMjJE3be58zKNLhpxBQyuEM6Pwx3sN9JVLmMCMN4DNVwL9AKec27z5TaWcWuHzMXiGAtcra5DjwWbvppGX4gaEGVN"
|
||||||
)
|
)
|
||||||
@ -267,8 +263,12 @@ class TestMultisigChange(TrezorTest):
|
|||||||
|
|
||||||
with self.client:
|
with self.client:
|
||||||
self.client.set_expected_responses(self._responses(self.inp1, self.inp2))
|
self.client.set_expected_responses(self._responses(self.inp1, self.inp2))
|
||||||
(_, serialized_tx) = btc.sign_tx(
|
_, serialized_tx = btc.sign_tx(
|
||||||
self.client, "Testnet", [self.inp1, self.inp2], [out1, out2]
|
self.client,
|
||||||
|
"Testnet",
|
||||||
|
[self.inp1, self.inp2],
|
||||||
|
[out1, out2],
|
||||||
|
prev_txes=TX_API,
|
||||||
)
|
)
|
||||||
|
|
||||||
assert (
|
assert (
|
||||||
@ -296,8 +296,12 @@ class TestMultisigChange(TrezorTest):
|
|||||||
self.client.set_expected_responses(
|
self.client.set_expected_responses(
|
||||||
self._responses(self.inp1, self.inp2, change=2)
|
self._responses(self.inp1, self.inp2, change=2)
|
||||||
)
|
)
|
||||||
(_, serialized_tx) = btc.sign_tx(
|
_, serialized_tx = btc.sign_tx(
|
||||||
self.client, "Testnet", [self.inp1, self.inp2], [out1, out2]
|
self.client,
|
||||||
|
"Testnet",
|
||||||
|
[self.inp1, self.inp2],
|
||||||
|
[out1, out2],
|
||||||
|
prev_txes=TX_API,
|
||||||
)
|
)
|
||||||
|
|
||||||
assert (
|
assert (
|
||||||
@ -325,8 +329,12 @@ class TestMultisigChange(TrezorTest):
|
|||||||
self.client.set_expected_responses(
|
self.client.set_expected_responses(
|
||||||
self._responses(self.inp1, self.inp2, change=1)
|
self._responses(self.inp1, self.inp2, change=1)
|
||||||
)
|
)
|
||||||
(_, serialized_tx) = btc.sign_tx(
|
_, serialized_tx = btc.sign_tx(
|
||||||
self.client, "Testnet", [self.inp1, self.inp2], [out1, out2]
|
self.client,
|
||||||
|
"Testnet",
|
||||||
|
[self.inp1, self.inp2],
|
||||||
|
[out1, out2],
|
||||||
|
prev_txes=TX_API,
|
||||||
)
|
)
|
||||||
|
|
||||||
assert (
|
assert (
|
||||||
@ -352,8 +360,12 @@ class TestMultisigChange(TrezorTest):
|
|||||||
|
|
||||||
with self.client:
|
with self.client:
|
||||||
self.client.set_expected_responses(self._responses(self.inp1, self.inp2))
|
self.client.set_expected_responses(self._responses(self.inp1, self.inp2))
|
||||||
(_, serialized_tx) = btc.sign_tx(
|
_, serialized_tx = btc.sign_tx(
|
||||||
self.client, "Testnet", [self.inp1, self.inp2], [out1, out2]
|
self.client,
|
||||||
|
"Testnet",
|
||||||
|
[self.inp1, self.inp2],
|
||||||
|
[out1, out2],
|
||||||
|
prev_txes=TX_API,
|
||||||
)
|
)
|
||||||
|
|
||||||
assert (
|
assert (
|
||||||
@ -392,8 +404,12 @@ class TestMultisigChange(TrezorTest):
|
|||||||
self.client.set_expected_responses(
|
self.client.set_expected_responses(
|
||||||
self._responses(self.inp1, self.inp2, change=1)
|
self._responses(self.inp1, self.inp2, change=1)
|
||||||
)
|
)
|
||||||
(_, serialized_tx) = btc.sign_tx(
|
_, serialized_tx = btc.sign_tx(
|
||||||
self.client, "Testnet", [self.inp1, self.inp2], [out1, out2]
|
self.client,
|
||||||
|
"Testnet",
|
||||||
|
[self.inp1, self.inp2],
|
||||||
|
[out1, out2],
|
||||||
|
prev_txes=TX_API,
|
||||||
)
|
)
|
||||||
|
|
||||||
assert (
|
assert (
|
||||||
@ -432,8 +448,12 @@ class TestMultisigChange(TrezorTest):
|
|||||||
self.client.set_expected_responses(
|
self.client.set_expected_responses(
|
||||||
self._responses(self.inp1, self.inp2, change=2)
|
self._responses(self.inp1, self.inp2, change=2)
|
||||||
)
|
)
|
||||||
(_, serialized_tx) = btc.sign_tx(
|
_, serialized_tx = btc.sign_tx(
|
||||||
self.client, "Testnet", [self.inp1, self.inp2], [out1, out2]
|
self.client,
|
||||||
|
"Testnet",
|
||||||
|
[self.inp1, self.inp2],
|
||||||
|
[out1, out2],
|
||||||
|
prev_txes=TX_API,
|
||||||
)
|
)
|
||||||
|
|
||||||
assert (
|
assert (
|
||||||
@ -470,8 +490,12 @@ class TestMultisigChange(TrezorTest):
|
|||||||
|
|
||||||
with self.client:
|
with self.client:
|
||||||
self.client.set_expected_responses(self._responses(self.inp1, self.inp2))
|
self.client.set_expected_responses(self._responses(self.inp1, self.inp2))
|
||||||
(_, serialized_tx) = btc.sign_tx(
|
_, serialized_tx = btc.sign_tx(
|
||||||
self.client, "Testnet", [self.inp1, self.inp2], [out1, out2]
|
self.client,
|
||||||
|
"Testnet",
|
||||||
|
[self.inp1, self.inp2],
|
||||||
|
[out1, out2],
|
||||||
|
prev_txes=TX_API,
|
||||||
)
|
)
|
||||||
|
|
||||||
assert (
|
assert (
|
||||||
@ -508,8 +532,12 @@ class TestMultisigChange(TrezorTest):
|
|||||||
|
|
||||||
with self.client:
|
with self.client:
|
||||||
self.client.set_expected_responses(self._responses(self.inp1, self.inp3))
|
self.client.set_expected_responses(self._responses(self.inp1, self.inp3))
|
||||||
(_, serialized_tx) = btc.sign_tx(
|
_, serialized_tx = btc.sign_tx(
|
||||||
self.client, "Testnet", [self.inp1, self.inp3], [out1, out2]
|
self.client,
|
||||||
|
"Testnet",
|
||||||
|
[self.inp1, self.inp3],
|
||||||
|
[out1, out2],
|
||||||
|
prev_txes=TX_API,
|
||||||
)
|
)
|
||||||
|
|
||||||
assert (
|
assert (
|
||||||
|
@ -22,6 +22,10 @@ from trezorlib.tools import CallException
|
|||||||
from .common import TrezorTest
|
from .common import TrezorTest
|
||||||
from .conftest import TREZOR_VERSION
|
from .conftest import TREZOR_VERSION
|
||||||
|
|
||||||
|
from ..support.tx_cache import tx_cache
|
||||||
|
|
||||||
|
TX_API = tx_cache("Bitcoin")
|
||||||
|
|
||||||
TXHASH_d5f65e = bytes.fromhex(
|
TXHASH_d5f65e = bytes.fromhex(
|
||||||
"d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882"
|
"d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882"
|
||||||
)
|
)
|
||||||
@ -116,8 +120,8 @@ class TestOpReturn(TrezorTest):
|
|||||||
proto.TxRequest(request_type=proto.RequestType.TXFINISHED),
|
proto.TxRequest(request_type=proto.RequestType.TXFINISHED),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
(signatures, serialized_tx) = btc.sign_tx(
|
_, serialized_tx = btc.sign_tx(
|
||||||
self.client, "Bitcoin", [inp1], [out1, out2]
|
self.client, "Bitcoin", [inp1], [out1, out2], prev_txes=TX_API
|
||||||
)
|
)
|
||||||
|
|
||||||
assert (
|
assert (
|
||||||
@ -182,7 +186,7 @@ class TestOpReturn(TrezorTest):
|
|||||||
)
|
)
|
||||||
|
|
||||||
with pytest.raises(CallException) as exc:
|
with pytest.raises(CallException) as exc:
|
||||||
btc.sign_tx(self.client, "Bitcoin", [inp1], [out1])
|
btc.sign_tx(self.client, "Bitcoin", [inp1], [out1], prev_txes=TX_API)
|
||||||
|
|
||||||
if TREZOR_VERSION == 1:
|
if TREZOR_VERSION == 1:
|
||||||
assert exc.value.args[0] == proto.FailureType.ProcessError
|
assert exc.value.args[0] == proto.FailureType.ProcessError
|
||||||
|
@ -18,6 +18,8 @@ from trezorlib import btc, messages as proto
|
|||||||
|
|
||||||
from .common import TrezorTest
|
from .common import TrezorTest
|
||||||
|
|
||||||
|
from ..support.tx_cache import tx_cache
|
||||||
|
|
||||||
TXHASH_d5f65e = bytes.fromhex(
|
TXHASH_d5f65e = bytes.fromhex(
|
||||||
"d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882"
|
"d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882"
|
||||||
)
|
)
|
||||||
@ -75,8 +77,8 @@ class TestZerosig(TrezorTest):
|
|||||||
script_type=proto.OutputScriptType.PAYTOADDRESS,
|
script_type=proto.OutputScriptType.PAYTOADDRESS,
|
||||||
)
|
)
|
||||||
|
|
||||||
(signatures, serialized_tx) = btc.sign_tx(
|
_, serialized_tx = btc.sign_tx(
|
||||||
self.client, "Bitcoin", [inp1], [out1]
|
self.client, "Bitcoin", [inp1], [out1], prev_txes=tx_cache("Bitcoin")
|
||||||
)
|
)
|
||||||
siglen = serialized_tx[44]
|
siglen = serialized_tx[44]
|
||||||
|
|
||||||
@ -100,8 +102,8 @@ class TestZerosig(TrezorTest):
|
|||||||
script_type=proto.OutputScriptType.PAYTOADDRESS,
|
script_type=proto.OutputScriptType.PAYTOADDRESS,
|
||||||
)
|
)
|
||||||
|
|
||||||
(signatures, serialized_tx) = btc.sign_tx(
|
_, serialized_tx = btc.sign_tx(
|
||||||
self.client, "Bitcoin", [inp1], [out1]
|
self.client, "Bitcoin", [inp1], [out1], prev_txes=tx_cache("Bitcoin")
|
||||||
)
|
)
|
||||||
siglen = serialized_tx[44]
|
siglen = serialized_tx[44]
|
||||||
|
|
||||||
|
@ -18,8 +18,10 @@ import os
|
|||||||
|
|
||||||
from trezorlib import coins, tx_api
|
from trezorlib import coins, tx_api
|
||||||
|
|
||||||
|
from ..support.tx_cache import tx_cache
|
||||||
|
|
||||||
TxApiBitcoin = coins.tx_api["Bitcoin"]
|
TxApiBitcoin = coins.tx_api["Bitcoin"]
|
||||||
TxApiTestnet = tx_api.TxApiInsight("insight_testnet")
|
TxApiTestnet = tx_cache("Testnet", allow_fetch=False)
|
||||||
TxApiZencash = coins.tx_api["Zencash"]
|
TxApiZencash = coins.tx_api["Zencash"]
|
||||||
|
|
||||||
tests_dir = os.path.dirname(os.path.abspath(__file__))
|
tests_dir = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
Loading…
Reference in New Issue
Block a user