2018-06-21 14:28:34 +00:00
|
|
|
# This file is part of the Trezor project.
|
2018-03-07 15:41:16 +00:00
|
|
|
#
|
2019-05-29 16:44:09 +00:00
|
|
|
# Copyright (C) 2012-2019 SatoshiLabs and contributors
|
2018-03-07 15:41:16 +00:00
|
|
|
#
|
|
|
|
# This library is free software: you can redistribute it and/or modify
|
2018-06-21 14:28:34 +00:00
|
|
|
# it under the terms of the GNU Lesser General Public License version 3
|
|
|
|
# as published by the Free Software Foundation.
|
2018-03-07 15:41:16 +00:00
|
|
|
#
|
|
|
|
# This library is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Lesser General Public License for more details.
|
|
|
|
#
|
2018-06-21 14:28:34 +00:00
|
|
|
# You should have received a copy of the License along with this library.
|
|
|
|
# If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
|
2018-03-07 15:41:16 +00:00
|
|
|
|
2018-08-13 16:21:24 +00:00
|
|
|
import pytest
|
|
|
|
|
2018-11-02 16:12:41 +00:00
|
|
|
from trezorlib import btc, messages as proto
|
2020-03-24 13:18:08 +00:00
|
|
|
from trezorlib.exceptions import TrezorFailure
|
2020-03-27 08:54:11 +00:00
|
|
|
from trezorlib.tools import H_, btc_hash, parse_path
|
2018-08-13 16:21:24 +00:00
|
|
|
|
2020-03-03 16:29:02 +00:00
|
|
|
from ..tx_cache import TxCache
|
2020-03-26 15:07:04 +00:00
|
|
|
from .signtx import request_finished, request_input, request_meta, request_output
|
2018-03-07 15:41:16 +00:00
|
|
|
|
2020-03-26 14:58:44 +00:00
|
|
|
B = proto.ButtonRequestType
|
2020-03-03 16:29:02 +00:00
|
|
|
TX_API = TxCache("Bgold")
|
2018-04-10 09:42:21 +00:00
|
|
|
|
2020-03-26 14:58:44 +00:00
|
|
|
TXHASH_25526b = bytes.fromhex(
|
|
|
|
"25526bf06c76ad3082bba930cf627cdd5f1b3cd0b9907dd7ff1a07e14addc985"
|
|
|
|
)
|
|
|
|
TXHASH_db77c2 = bytes.fromhex(
|
|
|
|
"db77c2461b840e6edbe7f9280043184a98e020d9795c1b65cb7cef2551a8fb18"
|
|
|
|
)
|
2020-06-20 17:30:26 +00:00
|
|
|
TXHASH_f55c5b = bytes.fromhex(
|
|
|
|
"f55c5bc925eb2a0bf9de0ac142b24bed81ec46dd2151d5f69728070eaea1aded"
|
|
|
|
)
|
2018-03-07 15:41:16 +00:00
|
|
|
|
|
|
|
# All data taken from T1
|
2019-08-22 16:47:01 +00:00
|
|
|
@pytest.mark.altcoin
|
2019-09-11 12:29:39 +00:00
|
|
|
class TestMsgSigntxBitcoinGold:
|
2019-08-27 14:58:59 +00:00
|
|
|
def test_send_bitcoin_gold_change(self, client):
|
2018-03-07 15:41:16 +00:00
|
|
|
inp1 = proto.TxInputType(
|
2018-04-18 13:53:40 +00:00
|
|
|
address_n=parse_path("44'/156'/0'/0/0"),
|
2020-03-27 08:54:11 +00:00
|
|
|
amount=1252382934,
|
2020-03-26 14:58:44 +00:00
|
|
|
prev_hash=TXHASH_25526b,
|
2018-03-07 15:41:16 +00:00
|
|
|
prev_index=0,
|
|
|
|
script_type=proto.InputScriptType.SPENDADDRESS,
|
|
|
|
)
|
|
|
|
out1 = proto.TxOutputType(
|
2018-04-18 13:53:40 +00:00
|
|
|
address_n=parse_path("44'/156'/0'/1/0"),
|
2018-03-07 15:41:16 +00:00
|
|
|
amount=1896050,
|
|
|
|
script_type=proto.OutputScriptType.PAYTOADDRESS,
|
|
|
|
)
|
|
|
|
out2 = proto.TxOutputType(
|
2018-08-13 16:21:24 +00:00
|
|
|
address="GfDB1tvjfm3bukeoBTtfNqrJVFohS2kCTe",
|
2020-03-27 08:54:11 +00:00
|
|
|
amount=1252382934 - 1896050 - 1000,
|
2018-03-07 15:41:16 +00:00
|
|
|
script_type=proto.OutputScriptType.PAYTOADDRESS,
|
|
|
|
)
|
2019-08-27 14:58:59 +00:00
|
|
|
with client:
|
|
|
|
client.set_expected_responses(
|
2018-08-13 16:21:24 +00:00
|
|
|
[
|
2020-03-26 14:58:44 +00:00
|
|
|
request_input(0),
|
2020-03-26 15:07:04 +00:00
|
|
|
request_meta(TXHASH_25526b),
|
|
|
|
request_input(0, TXHASH_25526b),
|
|
|
|
request_output(0, TXHASH_25526b),
|
|
|
|
request_output(1, TXHASH_25526b),
|
2020-03-26 14:58:44 +00:00
|
|
|
request_output(0),
|
|
|
|
request_output(1),
|
|
|
|
proto.ButtonRequest(code=B.ConfirmOutput),
|
|
|
|
proto.ButtonRequest(code=B.SignTx),
|
|
|
|
request_input(0),
|
|
|
|
request_output(0),
|
|
|
|
request_output(1),
|
|
|
|
request_finished(),
|
2018-08-13 16:21:24 +00:00
|
|
|
]
|
|
|
|
)
|
2018-11-02 15:25:51 +00:00
|
|
|
_, serialized_tx = btc.sign_tx(
|
2019-08-27 14:58:59 +00:00
|
|
|
client, "Bgold", [inp1], [out1, out2], prev_txes=TX_API
|
2018-08-13 16:21:24 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
assert (
|
2020-03-27 08:54:11 +00:00
|
|
|
btc_hash(serialized_tx)[::-1].hex()
|
|
|
|
== "39a0716c361610724c7c40916baa20808cbdd7538b6c38689ce80cb73e7f51d1"
|
2018-08-13 16:21:24 +00:00
|
|
|
)
|
2018-03-07 15:41:16 +00:00
|
|
|
|
2019-08-27 14:58:59 +00:00
|
|
|
def test_send_bitcoin_gold_nochange(self, client):
|
2018-03-07 15:41:16 +00:00
|
|
|
inp1 = proto.TxInputType(
|
2018-04-18 13:53:40 +00:00
|
|
|
address_n=parse_path("44'/156'/0'/1/0"),
|
2020-03-27 08:54:11 +00:00
|
|
|
amount=1252382934,
|
2020-03-26 14:58:44 +00:00
|
|
|
prev_hash=TXHASH_25526b,
|
2018-03-07 15:41:16 +00:00
|
|
|
prev_index=0,
|
|
|
|
script_type=proto.InputScriptType.SPENDADDRESS,
|
|
|
|
)
|
|
|
|
inp2 = proto.TxInputType(
|
2018-04-18 13:53:40 +00:00
|
|
|
address_n=parse_path("44'/156'/0'/0/1"),
|
2018-03-07 15:41:16 +00:00
|
|
|
# 1LRspCZNFJcbuNKQkXgHMDucctFRQya5a3
|
2020-03-27 08:54:11 +00:00
|
|
|
amount=38448607,
|
2020-03-26 14:58:44 +00:00
|
|
|
prev_hash=TXHASH_db77c2,
|
2020-03-27 08:54:11 +00:00
|
|
|
prev_index=0,
|
2018-03-07 15:41:16 +00:00
|
|
|
script_type=proto.InputScriptType.SPENDADDRESS,
|
|
|
|
)
|
|
|
|
out1 = proto.TxOutputType(
|
2018-08-13 16:21:24 +00:00
|
|
|
address="GfDB1tvjfm3bukeoBTtfNqrJVFohS2kCTe",
|
2020-03-27 08:54:11 +00:00
|
|
|
amount=1252382934 + 38448607 - 1000,
|
2018-03-07 15:41:16 +00:00
|
|
|
script_type=proto.OutputScriptType.PAYTOADDRESS,
|
|
|
|
)
|
2019-08-27 14:58:59 +00:00
|
|
|
with client:
|
|
|
|
client.set_expected_responses(
|
2018-08-13 16:21:24 +00:00
|
|
|
[
|
2020-03-26 14:58:44 +00:00
|
|
|
request_input(0),
|
2020-03-26 15:07:04 +00:00
|
|
|
request_meta(TXHASH_25526b),
|
|
|
|
request_input(0, TXHASH_25526b),
|
|
|
|
request_output(0, TXHASH_25526b),
|
|
|
|
request_output(1, TXHASH_25526b),
|
2020-03-26 14:58:44 +00:00
|
|
|
request_input(1),
|
2020-03-26 15:07:04 +00:00
|
|
|
request_meta(TXHASH_db77c2),
|
|
|
|
request_input(0, TXHASH_db77c2),
|
|
|
|
request_input(1, TXHASH_db77c2),
|
|
|
|
request_output(0, TXHASH_db77c2),
|
2020-03-26 14:58:44 +00:00
|
|
|
request_output(0),
|
|
|
|
proto.ButtonRequest(code=B.ConfirmOutput),
|
|
|
|
proto.ButtonRequest(code=B.SignTx),
|
|
|
|
request_input(0),
|
|
|
|
request_input(1),
|
|
|
|
request_output(0),
|
|
|
|
request_finished(),
|
2018-08-13 16:21:24 +00:00
|
|
|
]
|
|
|
|
)
|
2018-11-02 15:25:51 +00:00
|
|
|
_, serialized_tx = btc.sign_tx(
|
2019-08-27 14:58:59 +00:00
|
|
|
client, "Bgold", [inp1, inp2], [out1], prev_txes=TX_API
|
2018-08-13 16:21:24 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
assert (
|
2020-03-27 08:54:11 +00:00
|
|
|
btc_hash(serialized_tx)[::-1].hex()
|
|
|
|
== "ac9d452b900eb747d3137e1f3044bb0f46efaeb6e0fc8c27b02d1d08d238a904"
|
2018-08-13 16:21:24 +00:00
|
|
|
)
|
2018-03-07 15:41:16 +00:00
|
|
|
|
2019-08-27 14:58:59 +00:00
|
|
|
def test_attack_change_input(self, client):
|
2018-03-07 15:41:16 +00:00
|
|
|
inp1 = proto.TxInputType(
|
2018-11-06 12:29:37 +00:00
|
|
|
address_n=parse_path("44'/156'/11'/0/0"),
|
2020-03-27 08:54:11 +00:00
|
|
|
amount=1252382934,
|
2020-03-26 14:58:44 +00:00
|
|
|
prev_hash=TXHASH_25526b,
|
2018-03-07 15:41:16 +00:00
|
|
|
prev_index=0,
|
|
|
|
script_type=proto.InputScriptType.SPENDADDRESS,
|
|
|
|
)
|
|
|
|
out1 = proto.TxOutputType(
|
2018-11-06 12:29:37 +00:00
|
|
|
address_n=parse_path("44'/156'/11'/1/0"),
|
2018-03-07 15:41:16 +00:00
|
|
|
amount=1896050,
|
|
|
|
script_type=proto.OutputScriptType.PAYTOADDRESS,
|
|
|
|
)
|
|
|
|
out2 = proto.TxOutputType(
|
2018-08-13 16:21:24 +00:00
|
|
|
address="GfDB1tvjfm3bukeoBTtfNqrJVFohS2kCTe",
|
2020-03-27 08:54:11 +00:00
|
|
|
amount=1252382934 - 1896050 - 1000,
|
2018-03-07 15:41:16 +00:00
|
|
|
script_type=proto.OutputScriptType.PAYTOADDRESS,
|
|
|
|
)
|
|
|
|
|
2018-11-02 15:25:51 +00:00
|
|
|
run_attack = False
|
2018-03-07 15:41:16 +00:00
|
|
|
|
2018-11-02 15:25:51 +00:00
|
|
|
def attack_processor(msg):
|
|
|
|
nonlocal run_attack
|
2018-03-07 15:41:16 +00:00
|
|
|
|
2018-11-02 15:25:51 +00:00
|
|
|
if msg.tx.inputs and msg.tx.inputs[0] == inp1:
|
|
|
|
if run_attack:
|
|
|
|
msg.tx.inputs[0].address_n[2] = H_(1)
|
|
|
|
else:
|
|
|
|
run_attack = True
|
2018-03-07 15:41:16 +00:00
|
|
|
|
|
|
|
return msg
|
|
|
|
|
2019-08-27 14:58:59 +00:00
|
|
|
client.set_filter(proto.TxAck, attack_processor)
|
|
|
|
with client:
|
|
|
|
client.set_expected_responses(
|
2018-08-13 16:21:24 +00:00
|
|
|
[
|
2020-03-26 14:58:44 +00:00
|
|
|
request_input(0),
|
2020-03-26 15:07:04 +00:00
|
|
|
request_meta(TXHASH_25526b),
|
|
|
|
request_input(0, TXHASH_25526b),
|
|
|
|
request_output(0, TXHASH_25526b),
|
|
|
|
request_output(1, TXHASH_25526b),
|
2020-03-26 14:58:44 +00:00
|
|
|
request_output(0),
|
|
|
|
request_output(1),
|
|
|
|
proto.ButtonRequest(code=B.ConfirmOutput),
|
|
|
|
proto.ButtonRequest(code=B.SignTx),
|
|
|
|
request_input(0),
|
2018-08-13 16:21:24 +00:00
|
|
|
proto.Failure(code=proto.FailureType.ProcessError),
|
|
|
|
]
|
|
|
|
)
|
2020-03-24 13:18:08 +00:00
|
|
|
with pytest.raises(TrezorFailure):
|
2019-08-27 14:58:59 +00:00
|
|
|
btc.sign_tx(client, "Bgold", [inp1], [out1, out2], prev_txes=TX_API)
|
2018-03-07 15:41:16 +00:00
|
|
|
|
2019-10-22 14:32:00 +00:00
|
|
|
@pytest.mark.multisig
|
2019-08-27 14:58:59 +00:00
|
|
|
def test_send_btg_multisig_change(self, client):
|
2019-08-06 13:08:48 +00:00
|
|
|
nodes = [
|
2020-05-13 09:36:03 +00:00
|
|
|
btc.get_public_node(
|
|
|
|
client, parse_path(f"48'/156'/{i}'"), coin_name="Bgold"
|
|
|
|
).node
|
2019-08-06 13:08:48 +00:00
|
|
|
for i in range(1, 4)
|
|
|
|
]
|
2018-03-07 15:41:16 +00:00
|
|
|
|
2019-08-06 13:08:48 +00:00
|
|
|
def getmultisig(chain, nr, signatures=[b"", b"", b""], nodes=nodes):
|
2018-03-07 15:41:16 +00:00
|
|
|
return proto.MultisigRedeemScriptType(
|
2019-08-06 13:08:48 +00:00
|
|
|
nodes=nodes, address_n=[chain, nr], signatures=signatures, m=2
|
2018-03-07 15:41:16 +00:00
|
|
|
)
|
2018-08-13 16:21:24 +00:00
|
|
|
|
2018-03-07 15:41:16 +00:00
|
|
|
inp1 = proto.TxInputType(
|
2018-11-06 12:29:37 +00:00
|
|
|
address_n=parse_path("48'/156'/3'/0/0"),
|
2018-03-07 15:41:16 +00:00
|
|
|
multisig=getmultisig(0, 0),
|
|
|
|
# 33Ju286QvonBz5N1V754ZekQv4GLJqcc5R
|
2020-03-27 08:54:11 +00:00
|
|
|
amount=1252382934,
|
2020-03-26 14:58:44 +00:00
|
|
|
prev_hash=TXHASH_25526b,
|
2018-03-07 15:41:16 +00:00
|
|
|
prev_index=0,
|
|
|
|
script_type=proto.InputScriptType.SPENDMULTISIG,
|
|
|
|
)
|
|
|
|
out1 = proto.TxOutputType(
|
2018-08-13 16:21:24 +00:00
|
|
|
address="GfDB1tvjfm3bukeoBTtfNqrJVFohS2kCTe",
|
2018-03-07 15:41:16 +00:00
|
|
|
amount=24000,
|
|
|
|
script_type=proto.OutputScriptType.PAYTOADDRESS,
|
|
|
|
)
|
|
|
|
out2 = proto.TxOutputType(
|
2018-11-06 12:29:37 +00:00
|
|
|
address_n=parse_path("48'/156'/3'/1/0"),
|
2018-03-07 15:41:16 +00:00
|
|
|
multisig=getmultisig(1, 0),
|
|
|
|
script_type=proto.OutputScriptType.PAYTOMULTISIG,
|
2020-03-27 08:54:11 +00:00
|
|
|
amount=1252382934 - 24000 - 1000,
|
2018-03-07 15:41:16 +00:00
|
|
|
)
|
2019-08-27 14:58:59 +00:00
|
|
|
with client:
|
|
|
|
client.set_expected_responses(
|
2018-08-13 16:21:24 +00:00
|
|
|
[
|
2020-03-26 14:58:44 +00:00
|
|
|
request_input(0),
|
2020-03-26 15:07:04 +00:00
|
|
|
request_meta(TXHASH_25526b),
|
|
|
|
request_input(0, TXHASH_25526b),
|
|
|
|
request_output(0, TXHASH_25526b),
|
|
|
|
request_output(1, TXHASH_25526b),
|
2020-03-26 14:58:44 +00:00
|
|
|
request_output(0),
|
|
|
|
proto.ButtonRequest(code=B.ConfirmOutput),
|
|
|
|
request_output(1),
|
|
|
|
proto.ButtonRequest(code=B.SignTx),
|
|
|
|
request_input(0),
|
|
|
|
request_output(0),
|
|
|
|
request_output(1),
|
|
|
|
request_finished(),
|
2018-08-13 16:21:24 +00:00
|
|
|
]
|
|
|
|
)
|
2018-11-02 15:25:51 +00:00
|
|
|
signatures, serialized_tx = btc.sign_tx(
|
2019-08-27 14:58:59 +00:00
|
|
|
client, "Bgold", [inp1], [out1, out2], prev_txes=TX_API
|
2018-08-13 16:21:24 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
assert (
|
2018-11-02 15:25:51 +00:00
|
|
|
signatures[0].hex()
|
2020-03-27 08:54:11 +00:00
|
|
|
== "30440220271c46ef3d7c37bd499804128623da3aa0014f3b4447dd39c4573b23c4537f6902205329167b9eb48427af62b04bf5138295f4c38613f6ba955934d15c499bff0d8a"
|
2018-08-13 16:21:24 +00:00
|
|
|
)
|
2018-03-07 15:41:16 +00:00
|
|
|
|
|
|
|
inp1 = proto.TxInputType(
|
2018-11-06 12:29:37 +00:00
|
|
|
address_n=parse_path("48'/156'/1'/0/0"),
|
2018-11-02 15:25:51 +00:00
|
|
|
multisig=getmultisig(0, 0, [b"", b"", signatures[0]]),
|
2020-03-27 08:54:11 +00:00
|
|
|
amount=1252382934,
|
2020-03-26 14:58:44 +00:00
|
|
|
prev_hash=TXHASH_25526b,
|
2018-03-07 15:41:16 +00:00
|
|
|
prev_index=0,
|
|
|
|
script_type=proto.InputScriptType.SPENDMULTISIG,
|
|
|
|
)
|
2018-08-10 12:37:49 +00:00
|
|
|
out2.address_n[2] = H_(1)
|
2018-03-07 15:41:16 +00:00
|
|
|
|
2019-08-27 14:58:59 +00:00
|
|
|
with client:
|
|
|
|
client.set_expected_responses(
|
2018-08-13 16:21:24 +00:00
|
|
|
[
|
2020-03-26 14:58:44 +00:00
|
|
|
request_input(0),
|
2020-03-26 15:07:04 +00:00
|
|
|
request_meta(TXHASH_25526b),
|
|
|
|
request_input(0, TXHASH_25526b),
|
|
|
|
request_output(0, TXHASH_25526b),
|
|
|
|
request_output(1, TXHASH_25526b),
|
2020-03-26 14:58:44 +00:00
|
|
|
request_output(0),
|
|
|
|
proto.ButtonRequest(code=B.ConfirmOutput),
|
|
|
|
request_output(1),
|
|
|
|
proto.ButtonRequest(code=B.SignTx),
|
|
|
|
request_input(0),
|
|
|
|
request_output(0),
|
|
|
|
request_output(1),
|
|
|
|
request_finished(),
|
2018-08-13 16:21:24 +00:00
|
|
|
]
|
|
|
|
)
|
2018-11-02 15:25:51 +00:00
|
|
|
signatures, serialized_tx = btc.sign_tx(
|
2019-08-27 14:58:59 +00:00
|
|
|
client, "Bgold", [inp1], [out1, out2], prev_txes=TX_API
|
2018-08-13 16:21:24 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
assert (
|
2018-11-02 15:25:51 +00:00
|
|
|
signatures[0].hex()
|
2020-03-27 08:54:11 +00:00
|
|
|
== "3045022100bdf8c4bd14217c183612c7e8f79691f6479bcb35aa403f77d70182f58633ac6e02205b10a79b7894bb40248a120c8fcb7096a46950593e4c5b48a20bc5ebe53d85fa"
|
2018-08-13 16:21:24 +00:00
|
|
|
)
|
|
|
|
assert (
|
2020-03-27 08:54:11 +00:00
|
|
|
btc_hash(serialized_tx)[::-1].hex()
|
|
|
|
== "b45ba21b69e1e1c6ad79f5408fe70d92fb861742d239cb6a952213f60c253e40"
|
2018-08-13 16:21:24 +00:00
|
|
|
)
|
2018-03-08 13:35:54 +00:00
|
|
|
|
2019-08-27 14:58:59 +00:00
|
|
|
def test_send_p2sh(self, client):
|
2018-03-08 13:35:54 +00:00
|
|
|
inp1 = proto.TxInputType(
|
2018-04-18 13:53:40 +00:00
|
|
|
address_n=parse_path("49'/156'/0'/1/0"),
|
2020-03-27 08:54:11 +00:00
|
|
|
amount=1252382934,
|
2020-03-26 14:58:44 +00:00
|
|
|
prev_hash=TXHASH_25526b,
|
2018-03-08 13:35:54 +00:00
|
|
|
prev_index=0,
|
|
|
|
script_type=proto.InputScriptType.SPENDP2SHWITNESS,
|
|
|
|
)
|
|
|
|
out1 = proto.TxOutputType(
|
2018-08-13 16:21:24 +00:00
|
|
|
address="GfDB1tvjfm3bukeoBTtfNqrJVFohS2kCTe",
|
2018-03-08 13:35:54 +00:00
|
|
|
amount=12300000,
|
|
|
|
script_type=proto.OutputScriptType.PAYTOADDRESS,
|
|
|
|
)
|
|
|
|
out2 = proto.TxOutputType(
|
2018-08-13 16:21:24 +00:00
|
|
|
address="GZFLExxrvWFuFT1xRzhfwQWSE2bPDedBfn",
|
2018-03-08 13:35:54 +00:00
|
|
|
script_type=proto.OutputScriptType.PAYTOADDRESS,
|
2020-03-27 08:54:11 +00:00
|
|
|
amount=1252382934 - 11000 - 12300000,
|
2018-03-08 13:35:54 +00:00
|
|
|
)
|
2019-08-27 14:58:59 +00:00
|
|
|
with client:
|
|
|
|
client.set_expected_responses(
|
2018-08-13 16:21:24 +00:00
|
|
|
[
|
2020-03-26 14:58:44 +00:00
|
|
|
request_input(0),
|
2020-03-26 15:07:04 +00:00
|
|
|
request_meta(TXHASH_25526b),
|
|
|
|
request_input(0, TXHASH_25526b),
|
|
|
|
request_output(0, TXHASH_25526b),
|
|
|
|
request_output(1, TXHASH_25526b),
|
2020-03-26 14:58:44 +00:00
|
|
|
request_output(0),
|
|
|
|
proto.ButtonRequest(code=B.ConfirmOutput),
|
|
|
|
request_output(1),
|
|
|
|
proto.ButtonRequest(code=B.ConfirmOutput),
|
|
|
|
proto.ButtonRequest(code=B.SignTx),
|
|
|
|
request_input(0),
|
|
|
|
request_output(0),
|
|
|
|
request_output(1),
|
|
|
|
request_input(0),
|
|
|
|
request_finished(),
|
2018-08-13 16:21:24 +00:00
|
|
|
]
|
|
|
|
)
|
2018-11-02 15:25:51 +00:00
|
|
|
_, serialized_tx = btc.sign_tx(
|
2019-08-27 14:58:59 +00:00
|
|
|
client, "Bgold", [inp1], [out1, out2], prev_txes=TX_API
|
2018-08-13 16:21:24 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
assert (
|
2020-03-27 08:54:11 +00:00
|
|
|
btc_hash(serialized_tx)[::-1].hex()
|
|
|
|
== "d5732fc8a594ae3b7ba695d7b276b2186f8572b0eb157120e0ba35d3511c6060"
|
2018-08-13 16:21:24 +00:00
|
|
|
)
|
2018-03-08 13:35:54 +00:00
|
|
|
|
2019-08-27 14:58:59 +00:00
|
|
|
def test_send_p2sh_witness_change(self, client):
|
2018-03-08 13:35:54 +00:00
|
|
|
inp1 = proto.TxInputType(
|
2018-04-18 13:53:40 +00:00
|
|
|
address_n=parse_path("49'/156'/0'/1/0"),
|
2020-03-27 08:54:11 +00:00
|
|
|
amount=1252382934,
|
2020-03-26 14:58:44 +00:00
|
|
|
prev_hash=TXHASH_25526b,
|
2018-03-08 13:35:54 +00:00
|
|
|
prev_index=0,
|
|
|
|
script_type=proto.InputScriptType.SPENDP2SHWITNESS,
|
|
|
|
)
|
|
|
|
out1 = proto.TxOutputType(
|
2018-08-13 16:21:24 +00:00
|
|
|
address="GfDB1tvjfm3bukeoBTtfNqrJVFohS2kCTe",
|
2018-03-08 13:35:54 +00:00
|
|
|
amount=12300000,
|
|
|
|
script_type=proto.OutputScriptType.PAYTOADDRESS,
|
|
|
|
)
|
|
|
|
out2 = proto.TxOutputType(
|
2018-04-18 13:53:40 +00:00
|
|
|
address_n=parse_path("49'/156'/0'/1/0"),
|
2018-03-08 13:35:54 +00:00
|
|
|
script_type=proto.OutputScriptType.PAYTOP2SHWITNESS,
|
2020-03-27 08:54:11 +00:00
|
|
|
amount=1252382934 - 11000 - 12300000,
|
2018-03-08 13:35:54 +00:00
|
|
|
)
|
2019-08-27 14:58:59 +00:00
|
|
|
with client:
|
|
|
|
client.set_expected_responses(
|
2018-08-13 16:21:24 +00:00
|
|
|
[
|
2020-03-26 14:58:44 +00:00
|
|
|
request_input(0),
|
2020-03-26 15:07:04 +00:00
|
|
|
request_meta(TXHASH_25526b),
|
|
|
|
request_input(0, TXHASH_25526b),
|
|
|
|
request_output(0, TXHASH_25526b),
|
|
|
|
request_output(1, TXHASH_25526b),
|
2020-03-26 14:58:44 +00:00
|
|
|
request_output(0),
|
|
|
|
proto.ButtonRequest(code=B.ConfirmOutput),
|
|
|
|
request_output(1),
|
|
|
|
proto.ButtonRequest(code=B.SignTx),
|
|
|
|
request_input(0),
|
|
|
|
request_output(0),
|
|
|
|
request_output(1),
|
|
|
|
request_input(0),
|
|
|
|
request_finished(),
|
2018-08-13 16:21:24 +00:00
|
|
|
]
|
|
|
|
)
|
2018-11-02 15:25:51 +00:00
|
|
|
_, serialized_tx = btc.sign_tx(
|
2019-08-27 14:58:59 +00:00
|
|
|
client, "Bgold", [inp1], [out1, out2], prev_txes=TX_API
|
2018-08-13 16:21:24 +00:00
|
|
|
)
|
2018-03-08 13:35:54 +00:00
|
|
|
|
2018-08-13 16:21:24 +00:00
|
|
|
assert (
|
2020-03-27 08:54:11 +00:00
|
|
|
btc_hash(serialized_tx)[::-1].hex()
|
|
|
|
== "eed4ef86a408602e35ae416591f349847db38cdaddef1429a9bb0e39520d100d"
|
2018-08-13 16:21:24 +00:00
|
|
|
)
|
2018-03-08 13:35:54 +00:00
|
|
|
|
2019-10-22 14:32:00 +00:00
|
|
|
@pytest.mark.multisig
|
2019-08-27 14:58:59 +00:00
|
|
|
def test_send_multisig_1(self, client):
|
2019-08-06 13:08:48 +00:00
|
|
|
nodes = [
|
2020-05-13 09:36:03 +00:00
|
|
|
btc.get_public_node(
|
|
|
|
client, parse_path(f"49'/156'/{i}'"), coin_name="Bgold"
|
|
|
|
).node
|
2019-08-06 13:08:48 +00:00
|
|
|
for i in range(1, 4)
|
|
|
|
]
|
2018-03-08 13:35:54 +00:00
|
|
|
multisig = proto.MultisigRedeemScriptType(
|
2019-08-06 13:08:48 +00:00
|
|
|
nodes=nodes, address_n=[1, 0], signatures=[b"", b"", b""], m=2
|
2018-03-08 13:35:54 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
inp1 = proto.TxInputType(
|
2018-11-06 12:29:37 +00:00
|
|
|
address_n=parse_path("49'/156'/1'/1/0"),
|
2020-03-26 14:58:44 +00:00
|
|
|
prev_hash=TXHASH_25526b,
|
2020-03-27 08:54:11 +00:00
|
|
|
prev_index=0,
|
2018-03-08 13:35:54 +00:00
|
|
|
script_type=proto.InputScriptType.SPENDP2SHWITNESS,
|
|
|
|
multisig=multisig,
|
2020-03-27 08:54:11 +00:00
|
|
|
amount=1252382934,
|
2018-03-08 13:35:54 +00:00
|
|
|
)
|
|
|
|
|
2018-08-13 16:21:24 +00:00
|
|
|
out1 = proto.TxOutputType(
|
|
|
|
address="GfDB1tvjfm3bukeoBTtfNqrJVFohS2kCTe",
|
2020-03-27 08:54:11 +00:00
|
|
|
amount=1252382934 - 1000,
|
2018-08-13 16:21:24 +00:00
|
|
|
script_type=proto.OutputScriptType.PAYTOADDRESS,
|
|
|
|
)
|
2018-03-08 13:35:54 +00:00
|
|
|
|
2019-08-27 14:58:59 +00:00
|
|
|
with client:
|
|
|
|
client.set_expected_responses(
|
2018-08-13 16:21:24 +00:00
|
|
|
[
|
2020-03-26 14:58:44 +00:00
|
|
|
request_input(0),
|
2020-03-26 15:07:04 +00:00
|
|
|
request_meta(TXHASH_25526b),
|
|
|
|
request_input(0, TXHASH_25526b),
|
|
|
|
request_output(0, TXHASH_25526b),
|
|
|
|
request_output(1, TXHASH_25526b),
|
2020-03-26 14:58:44 +00:00
|
|
|
request_output(0),
|
|
|
|
proto.ButtonRequest(code=B.ConfirmOutput),
|
|
|
|
proto.ButtonRequest(code=B.SignTx),
|
|
|
|
request_input(0),
|
|
|
|
request_output(0),
|
|
|
|
request_input(0),
|
|
|
|
request_finished(),
|
2018-08-13 16:21:24 +00:00
|
|
|
]
|
|
|
|
)
|
2018-11-02 15:25:51 +00:00
|
|
|
signatures, _ = btc.sign_tx(
|
2019-08-27 14:58:59 +00:00
|
|
|
client, "Bgold", [inp1], [out1], prev_txes=TX_API
|
2018-11-02 15:25:51 +00:00
|
|
|
)
|
2018-03-08 13:35:54 +00:00
|
|
|
# store signature
|
2018-11-02 15:25:51 +00:00
|
|
|
inp1.multisig.signatures[0] = signatures[0]
|
2018-03-08 13:35:54 +00:00
|
|
|
# sign with third key
|
2018-08-10 12:37:49 +00:00
|
|
|
inp1.address_n[2] = H_(3)
|
2019-08-27 14:58:59 +00:00
|
|
|
client.set_expected_responses(
|
2018-08-13 16:21:24 +00:00
|
|
|
[
|
2020-03-26 14:58:44 +00:00
|
|
|
request_input(0),
|
2020-03-26 15:07:04 +00:00
|
|
|
request_meta(TXHASH_25526b),
|
|
|
|
request_input(0, TXHASH_25526b),
|
|
|
|
request_output(0, TXHASH_25526b),
|
|
|
|
request_output(1, TXHASH_25526b),
|
2020-03-26 14:58:44 +00:00
|
|
|
request_output(0),
|
|
|
|
proto.ButtonRequest(code=B.ConfirmOutput),
|
|
|
|
proto.ButtonRequest(code=B.SignTx),
|
|
|
|
request_input(0),
|
|
|
|
request_output(0),
|
|
|
|
request_input(0),
|
|
|
|
request_finished(),
|
2018-08-13 16:21:24 +00:00
|
|
|
]
|
|
|
|
)
|
2018-11-02 15:25:51 +00:00
|
|
|
_, serialized_tx = btc.sign_tx(
|
2019-08-27 14:58:59 +00:00
|
|
|
client, "Bgold", [inp1], [out1], prev_txes=TX_API
|
2018-08-13 16:21:24 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
assert (
|
2020-03-27 08:54:11 +00:00
|
|
|
btc_hash(serialized_tx)[::-1].hex()
|
|
|
|
== "efa5b21916ac7ea5316c38b2d7d5520d80cbe563c58304f956ea6ddb241001d1"
|
2018-08-13 16:21:24 +00:00
|
|
|
)
|
2020-03-11 12:07:09 +00:00
|
|
|
|
|
|
|
def test_send_mixed_inputs(self, client):
|
|
|
|
# First is non-segwit, second is segwit.
|
|
|
|
|
|
|
|
inp1 = proto.TxInputType(
|
2020-03-27 08:54:11 +00:00
|
|
|
address_n=parse_path("44'/156'/11'/0/0"),
|
|
|
|
amount=38448607,
|
|
|
|
prev_hash=TXHASH_db77c2,
|
2020-03-11 12:07:09 +00:00
|
|
|
prev_index=0,
|
2020-03-27 08:54:11 +00:00
|
|
|
script_type=proto.InputScriptType.SPENDADDRESS,
|
2020-03-11 12:07:09 +00:00
|
|
|
)
|
|
|
|
inp2 = proto.TxInputType(
|
2020-03-27 08:54:11 +00:00
|
|
|
address_n=parse_path("49'/156'/0'/1/0"),
|
|
|
|
amount=1252382934,
|
|
|
|
prev_hash=TXHASH_25526b,
|
|
|
|
prev_index=0,
|
|
|
|
script_type=proto.InputScriptType.SPENDP2SHWITNESS,
|
2020-03-11 12:07:09 +00:00
|
|
|
)
|
|
|
|
out1 = proto.TxOutputType(
|
|
|
|
address="GfDB1tvjfm3bukeoBTtfNqrJVFohS2kCTe",
|
2020-03-27 08:54:11 +00:00
|
|
|
amount=38448607 + 1252382934 - 1000,
|
2020-03-11 12:07:09 +00:00
|
|
|
script_type=proto.OutputScriptType.PAYTOADDRESS,
|
|
|
|
)
|
|
|
|
|
|
|
|
with client:
|
|
|
|
_, serialized_tx = btc.sign_tx(
|
|
|
|
client, "Bgold", [inp1, inp2], [out1], prev_txes=TX_API
|
|
|
|
)
|
|
|
|
|
|
|
|
assert (
|
2020-03-27 08:54:11 +00:00
|
|
|
btc_hash(serialized_tx)[::-1].hex()
|
|
|
|
== "2c64109fba890657e37f0782efda29bbc277dfd521658f185d302ddffcacffd2"
|
2020-03-11 12:07:09 +00:00
|
|
|
)
|
2020-06-20 17:30:26 +00:00
|
|
|
|
|
|
|
@pytest.mark.skip_t1
|
|
|
|
def test_send_btg_external_presigned(self, client):
|
|
|
|
inp1 = proto.TxInputType(
|
|
|
|
address_n=parse_path("44'/156'/0'/1/0"),
|
|
|
|
amount=1252382934,
|
|
|
|
prev_hash=TXHASH_25526b,
|
|
|
|
prev_index=0,
|
|
|
|
script_type=proto.InputScriptType.SPENDADDRESS,
|
|
|
|
)
|
|
|
|
inp2 = proto.TxInputType(
|
|
|
|
# address_n=parse_path("49'/156'/0'/0/0"),
|
|
|
|
# AXibjT5r96ZaVA8Lu4BQZocdTx7p5Ud8ZP
|
|
|
|
amount=58456,
|
|
|
|
prev_hash=TXHASH_f55c5b,
|
|
|
|
prev_index=0,
|
|
|
|
script_type=proto.InputScriptType.EXTERNAL,
|
|
|
|
script_sig=bytes.fromhex("1600147c5edda9b293db2c8894b9d81efd77764910c445"),
|
|
|
|
witness=bytes.fromhex(
|
|
|
|
"024730440220091eece828409b3a9aa92dd2f9b032f9fb3a12b21b323a3fdea3cb18d08249af022065412107afcf76b0d28b90188c802f8f17b41790ed81c868d0ee23f1dd2ec53441210386789a34fe1a49bfc3e174adc6706c6222b0d80de76b884a0e3d32f8e9c4dc3e"
|
|
|
|
),
|
|
|
|
)
|
|
|
|
out1 = proto.TxOutputType(
|
|
|
|
address="GfDB1tvjfm3bukeoBTtfNqrJVFohS2kCTe",
|
|
|
|
amount=1252382934 + 58456 - 1000,
|
|
|
|
script_type=proto.OutputScriptType.PAYTOADDRESS,
|
|
|
|
)
|
|
|
|
with client:
|
|
|
|
client.set_expected_responses(
|
|
|
|
[
|
|
|
|
request_input(0),
|
|
|
|
request_meta(TXHASH_25526b),
|
|
|
|
request_input(0, TXHASH_25526b),
|
|
|
|
request_output(0, TXHASH_25526b),
|
|
|
|
request_output(1, TXHASH_25526b),
|
|
|
|
request_input(1),
|
|
|
|
request_output(0),
|
|
|
|
proto.ButtonRequest(code=B.ConfirmOutput),
|
|
|
|
proto.ButtonRequest(code=B.SignTx),
|
|
|
|
request_input(1),
|
|
|
|
request_meta(TXHASH_f55c5b),
|
|
|
|
request_input(0, TXHASH_f55c5b),
|
|
|
|
request_output(0, TXHASH_f55c5b),
|
|
|
|
request_output(1, TXHASH_f55c5b),
|
|
|
|
request_input(0),
|
|
|
|
request_input(1),
|
|
|
|
request_output(0),
|
|
|
|
request_input(1),
|
|
|
|
request_finished(),
|
|
|
|
]
|
|
|
|
)
|
|
|
|
_, serialized_tx = btc.sign_tx(
|
|
|
|
client, "Bgold", [inp1, inp2], [out1], prev_txes=TX_API
|
|
|
|
)
|
|
|
|
|
|
|
|
assert (
|
|
|
|
btc_hash(serialized_tx)[::-1].hex()
|
|
|
|
== "95ebe5cdfb8dc3c112eb0107fc3bd7701689ac5ec4a74a3d12e203333d0832d3"
|
|
|
|
)
|