1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-22 15:38:11 +00:00
trezor-firmware/tests/device_tests/test_msg_signtx_komodo.py

164 lines
6.1 KiB
Python
Raw Normal View History

2019-02-08 19:45:49 +00:00
# This file is part of the Trezor project.
#
# Copyright (C) 2012-2019 SatoshiLabs and contributors
#
# This library is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License version 3
# as published by the Free Software Foundation.
#
# 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.
#
# 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>.
import pytest
from trezorlib import btc, messages as proto
from trezorlib.tools import parse_path
2020-03-03 16:29:02 +00:00
from ..tx_cache import TxCache
from .signtx import (
request_extra_data,
request_finished,
request_input,
request_meta,
request_output,
)
2019-02-08 19:45:49 +00:00
B = proto.ButtonRequestType
2020-03-03 16:29:02 +00:00
TX_API = TxCache("Komodo")
2019-02-08 19:45:49 +00:00
TXHASH_2807c = bytes.fromhex(
"2807c5b126ec8e2b078cab0f12e4c8b4ce1d7724905f8ebef8dca26b0c8e0f1d"
)
TXHASH_7b28bd = bytes.fromhex(
"7b28bd91119e9776f0d4ebd80e570165818a829bbf4477cd1afe5149dbcd34b1"
2019-02-08 19:45:49 +00:00
)
@pytest.mark.altcoin
2019-02-08 19:45:49 +00:00
@pytest.mark.komodo
2019-09-11 12:29:39 +00:00
class TestMsgSigntxKomodo:
def test_one_one_fee_sapling(self, client):
# prevout: 2807c5b126ec8e2b078cab0f12e4c8b4ce1d7724905f8ebef8dca26b0c8e0f1d:0
# input 1: 10.9998 KMD
2019-02-08 19:45:49 +00:00
inp1 = proto.TxInputType(
# R9HgJZo6JBKmPvhm7whLSR8wiHyZrEDVRi
address_n=parse_path("44'/141'/0'/0/0"),
amount=1099980000,
prev_hash=TXHASH_2807c,
2019-02-08 19:45:49 +00:00
prev_index=0,
)
out1 = proto.TxOutputType(
address="R9HgJZo6JBKmPvhm7whLSR8wiHyZrEDVRi",
amount=1099980000 - 10000,
2019-02-08 19:45:49 +00:00
script_type=proto.OutputScriptType.PAYTOADDRESS,
)
with client:
client.set_expected_responses(
[
request_input(0),
request_output(0),
proto.ButtonRequest(code=B.ConfirmOutput),
proto.ButtonRequest(code=B.SignTx),
proto.ButtonRequest(code=B.SignTx),
request_input(0),
request_meta(TXHASH_2807c),
request_input(0, TXHASH_2807c),
request_output(0, TXHASH_2807c),
request_extra_data(0, 11, TXHASH_2807c),
request_input(0),
request_output(0),
request_finished(),
]
)
2019-02-08 19:45:49 +00:00
_, serialized_tx = btc.sign_tx(
client,
"Komodo",
[inp1],
[out1],
2019-02-08 19:45:49 +00:00
version=4,
version_group_id=0x892F2085,
branch_id=0x76B809BB,
lock_time=0x5D2A30B8,
prev_txes=TX_API,
2019-02-08 19:45:49 +00:00
)
# Accepted by network: tx 7b28bd91119e9776f0d4ebd80e570165818a829bbf4477cd1afe5149dbcd34b1
assert (
serialized_tx.hex()
== "0400008085202f89011d0f8e0c6ba2dcf8be8e5f9024771dceb4c8e4120fab8c072b8eec26b1c50728000000006a4730440220158c970ca2fc6bcc33026eb5366f0342f63b35d178f7efb334b1df78fe90b67202207bc4ff69f67cf843b08564a5adc77bf5593e28ab4d5104911824ac13fe885d8f012102a87aef7b1a8f676e452d6240767699719cd58b0261c822472c25df146938bca5ffffffff01d0359041000000001976a91400178fa0b6fc253a3a402ee2cadd8a7bfec08f6388acb8302a5d000000000000000000000000000000"
)
def test_one_one_rewards_claim(self, client):
# prevout: 7b28bd91119e9776f0d4ebd80e570165818a829bbf4477cd1afe5149dbcd34b1:0
# input 1: 10.9997 KMD
inp1 = proto.TxInputType(
# R9HgJZo6JBKmPvhm7whLSR8wiHyZrEDVRi
address_n=parse_path("44'/141'/0'/0/0"),
amount=1099970000,
prev_hash=TXHASH_7b28bd,
prev_index=0,
)
out1 = proto.TxOutputType(
address="R9HgJZo6JBKmPvhm7whLSR8wiHyZrEDVRi",
amount=1099970000 - 10000,
script_type=proto.OutputScriptType.PAYTOADDRESS,
)
# kmd interest, vout sum > vin sum
out2 = proto.TxOutputType(
address="R9HgJZo6JBKmPvhm7whLSR8wiHyZrEDVRi",
amount=79605,
script_type=proto.OutputScriptType.PAYTOADDRESS,
)
with client:
client.set_expected_responses(
[
request_input(0),
request_output(0),
proto.ButtonRequest(code=B.ConfirmOutput),
request_output(1),
proto.ButtonRequest(code=B.ConfirmOutput),
proto.ButtonRequest(code=B.SignTx),
proto.ButtonRequest(code=B.SignTx),
request_input(0),
request_meta(TXHASH_7b28bd),
request_input(0, TXHASH_7b28bd),
request_output(0, TXHASH_7b28bd),
request_extra_data(0, 11, TXHASH_7b28bd),
request_input(0),
request_output(0),
request_output(1),
request_finished(),
]
)
_, serialized_tx = btc.sign_tx(
client,
"Komodo",
[inp1],
[out1, out2],
prev_txes=TX_API,
version=4,
version_group_id=0x892F2085,
branch_id=0x76B809BB,
lock_time=0x5D2AF1F2,
)
# Accepted by network: tx c775678ceb18277729b427c7acf2f8ce63ac02fc2366f47ce08a3f443ff0e059
2019-02-08 19:45:49 +00:00
assert (
serialized_tx.hex()
== "0400008085202f8901b134cddb4951fe1acd7744bf9b828a816501570ed8ebd4f076979e1191bd287b000000006a4730440220483a58f5be3a147c773c663008c992a7fcea4d03bdf4c1d4bc0535c0d98ddf0602207b19d69140dd00c7a94f048c712aeaed55dfd27f581c7212d9cc5e476fe1dc9f012102a87aef7b1a8f676e452d6240767699719cd58b0261c822472c25df146938bca5ffffffff02c00e9041000000001976a91400178fa0b6fc253a3a402ee2cadd8a7bfec08f6388acf5360100000000001976a91400178fa0b6fc253a3a402ee2cadd8a7bfec08f6388acf2f12a5d000000000000000000000000000000"
2019-02-08 19:45:49 +00:00
)