You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
134 lines
4.5 KiB
134 lines
4.5 KiB
6 years ago
|
# This file is part of the Trezor project.
|
||
8 years ago
|
#
|
||
5 years ago
|
# Copyright (C) 2012-2019 SatoshiLabs and contributors
|
||
8 years ago
|
#
|
||
|
# This library is free software: you can redistribute it and/or modify
|
||
6 years ago
|
# it under the terms of the GNU Lesser General Public License version 3
|
||
|
# as published by the Free Software Foundation.
|
||
8 years ago
|
#
|
||
|
# 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.
|
||
|
#
|
||
6 years ago
|
# 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>.
|
||
|
|
||
6 years ago
|
import pytest
|
||
8 years ago
|
|
||
3 years ago
|
from trezorlib import btc, messages
|
||
4 years ago
|
from trezorlib.exceptions import TrezorFailure
|
||
|
from trezorlib.tools import parse_path
|
||
6 years ago
|
|
||
3 years ago
|
from ...tx_cache import TxCache
|
||
|
from ..signtx import request_finished, request_input, request_meta, request_output
|
||
7 years ago
|
|
||
3 years ago
|
B = messages.ButtonRequestType
|
||
4 years ago
|
TX_API = TxCache("Bitcoin")
|
||
6 years ago
|
|
||
6 years ago
|
TXHASH_d5f65e = bytes.fromhex(
|
||
6 years ago
|
"d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882"
|
||
|
)
|
||
7 years ago
|
|
||
|
|
||
3 years ago
|
def test_opreturn(client):
|
||
3 years ago
|
inp1 = messages.TxInputType(
|
||
3 years ago
|
address_n=parse_path("44'/0'/0'/0/2"),
|
||
|
amount=390000,
|
||
|
prev_hash=TXHASH_d5f65e,
|
||
|
prev_index=0,
|
||
|
)
|
||
|
|
||
3 years ago
|
out1 = messages.TxOutputType(
|
||
3 years ago
|
address="1MJ2tj2ThBE62zXbBYA5ZaN3fdve5CPAz1",
|
||
|
amount=390000 - 10000,
|
||
3 years ago
|
script_type=messages.OutputScriptType.PAYTOADDRESS,
|
||
3 years ago
|
)
|
||
|
|
||
3 years ago
|
out2 = messages.TxOutputType(
|
||
3 years ago
|
op_return_data=b"test of the op_return data",
|
||
|
amount=0,
|
||
3 years ago
|
script_type=messages.OutputScriptType.PAYTOOPRETURN,
|
||
3 years ago
|
)
|
||
|
|
||
|
with client:
|
||
|
client.set_expected_responses(
|
||
|
[
|
||
|
request_input(0),
|
||
|
request_output(0),
|
||
3 years ago
|
messages.ButtonRequest(code=B.ConfirmOutput),
|
||
3 years ago
|
request_output(1),
|
||
3 years ago
|
messages.ButtonRequest(code=B.ConfirmOutput),
|
||
|
messages.ButtonRequest(code=B.SignTx),
|
||
3 years ago
|
request_input(0),
|
||
|
request_meta(TXHASH_d5f65e),
|
||
|
request_input(0, TXHASH_d5f65e),
|
||
|
request_input(1, TXHASH_d5f65e),
|
||
|
request_output(0, TXHASH_d5f65e),
|
||
|
request_input(0),
|
||
|
request_output(0),
|
||
|
request_output(1),
|
||
|
request_output(0),
|
||
|
request_output(1),
|
||
|
request_finished(),
|
||
|
]
|
||
7 years ago
|
)
|
||
3 years ago
|
_, serialized_tx = btc.sign_tx(
|
||
|
client, "Bitcoin", [inp1], [out1, out2], prev_txes=TX_API
|
||
6 years ago
|
)
|
||
9 years ago
|
|
||
3 years ago
|
assert (
|
||
|
serialized_tx.hex()
|
||
|
== "010000000182488650ef25a58fef6788bd71b8212038d7f2bbe4750bc7bcb44701e85ef6d5000000006b483045022100bc36e1227b334e856c532bbef86d30a96823a5f2461738f4dbf969dfbcf1b40b022078c5353ec9a4bce2bb05bd1ec466f2ab379c1aad926e208738407bba4e09784b012103330236b68aa6fdcaca0ea72e11b360c84ed19a338509aa527b678a7ec9076882ffffffff0260cc0500000000001976a914de9b2a8da088824e8fe51debea566617d851537888ac00000000000000001c6a1a74657374206f6620746865206f705f72657475726e206461746100000000"
|
||
|
)
|
||
|
|
||
|
|
||
|
def test_nonzero_opreturn(client):
|
||
3 years ago
|
inp1 = messages.TxInputType(
|
||
3 years ago
|
address_n=parse_path("44'/0'/10'/0/5"),
|
||
|
amount=390000,
|
||
|
prev_hash=TXHASH_d5f65e,
|
||
|
prev_index=0,
|
||
|
)
|
||
|
|
||
3 years ago
|
out1 = messages.TxOutputType(
|
||
3 years ago
|
op_return_data=b"test of the op_return data",
|
||
|
amount=10000,
|
||
3 years ago
|
script_type=messages.OutputScriptType.PAYTOOPRETURN,
|
||
3 years ago
|
)
|
||
|
|
||
|
with client:
|
||
|
client.set_expected_responses(
|
||
3 years ago
|
[request_input(0), request_output(0), messages.Failure()]
|
||
7 years ago
|
)
|
||
|
|
||
3 years ago
|
with pytest.raises(
|
||
|
TrezorFailure, match="OP_RETURN output with non-zero amount"
|
||
|
):
|
||
|
btc.sign_tx(client, "Bitcoin", [inp1], [out1], prev_txes=TX_API)
|
||
|
|
||
|
|
||
|
def test_opreturn_address(client):
|
||
3 years ago
|
inp1 = messages.TxInputType(
|
||
3 years ago
|
address_n=parse_path("44'/0'/0'/0/2"),
|
||
|
amount=390000,
|
||
|
prev_hash=TXHASH_d5f65e,
|
||
|
prev_index=0,
|
||
|
)
|
||
|
|
||
3 years ago
|
out1 = messages.TxOutputType(
|
||
3 years ago
|
address_n=parse_path("44'/0'/0'/1/2"),
|
||
|
amount=0,
|
||
|
op_return_data=b"OMNI TRANSACTION GOES HERE",
|
||
3 years ago
|
script_type=messages.OutputScriptType.PAYTOOPRETURN,
|
||
3 years ago
|
)
|
||
|
|
||
|
with client:
|
||
|
client.set_expected_responses(
|
||
3 years ago
|
[request_input(0), request_output(0), messages.Failure()]
|
||
7 years ago
|
)
|
||
3 years ago
|
with pytest.raises(
|
||
|
TrezorFailure, match="Output's address_n provided but not expected."
|
||
|
):
|
||
|
btc.sign_tx(client, "Bitcoin", [inp1], [out1], prev_txes=TX_API)
|