2019-12-05 03:32:13 +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
2024-11-15 16:31:22 +00:00
from trezorlib . debuglink import SessionDebugWrapper as Session
2020-03-13 12:09:02 +00:00
from trezorlib . exceptions import TrezorFailure
2019-12-05 03:32:13 +00:00
from trezorlib . tools import parse_path
2021-11-29 11:00:01 +00:00
from . . . tx_cache import TxCache
2019-12-05 03:32:13 +00:00
2020-04-15 12:57:21 +00:00
TX_CACHE = TxCache ( " Peercoin " )
2019-12-05 03:32:13 +00:00
TXHASH_41b29a = bytes . fromhex (
" 41b29ad615d8eea40a4654a052d18bb10cd08f203c351f4d241f88b031357d3d "
)
@pytest.mark.altcoin
@pytest.mark.peercoin
2024-11-15 16:31:22 +00:00
def test_timestamp_included ( session : Session ) :
2019-12-05 03:32:13 +00:00
# tx: 41b29ad615d8eea40a4654a052d18bb10cd08f203c351f4d241f88b031357d3d
# input 0: 0.1 PPC
inp1 = messages . TxInputType (
2022-01-31 12:25:30 +00:00
address_n = parse_path ( " m/44h/6h/0h/0/0 " ) ,
amount = 100_000 ,
2020-07-14 18:43:53 +00:00
prev_hash = TXHASH_41b29a ,
prev_index = 0 ,
2019-12-05 03:32:13 +00:00
)
out1 = messages . TxOutputType (
address = " PXtfyTjzgXSgTwK5AbszdHQSSxyQN3BLM5 " ,
2022-01-31 12:25:30 +00:00
amount = 100_000 - 10_000 ,
2019-12-05 03:32:13 +00:00
script_type = messages . OutputScriptType . PAYTOADDRESS ,
)
2020-03-13 12:09:02 +00:00
_ , timestamp_tx = btc . sign_tx (
2024-11-15 16:31:22 +00:00
session ,
2020-09-15 11:06:41 +00:00
" Peercoin " ,
[ inp1 ] ,
[ out1 ] ,
version = 1 ,
timestamp = 0x5DC5448A ,
prev_txes = TX_CACHE ,
2020-03-13 12:09:02 +00:00
)
# Accepted by network https://explorer.peercoin.net/api/getrawtransaction?txid=f7e3624c143b6a170cc44f9337d0fa8ea8564a211de9c077c6889d8c78f80909&decrypt=1
accepted_txhex = " 010000008a44c55d013d7d3531b0881f244d1f353c208fd00cb18bd152a054460aa4eed815d69ab241000000006a473044022025c0ea702390c702c7ae8b5ea469820bea8d942c8c16439f8f0ba2e91e699efc02200db9b0a48fa2861695fa91df4831a4c7306587e5d2dc85419647f462717bc8f001210274cb0ee652d9457fbb0f3872d43155a6bc16f77bd5749d8826b53db443b1b278ffffffff01905f0100000000001976a914ff9a05654150fdc92b1655f49d7f2a8aaf6a3a2a88ac00000000 "
assert timestamp_tx . hex ( ) == accepted_txhex
@pytest.mark.altcoin
@pytest.mark.peercoin
2024-11-15 16:31:22 +00:00
def test_timestamp_missing ( session : Session ) :
2020-03-13 12:09:02 +00:00
inp1 = messages . TxInputType (
2022-01-31 12:25:30 +00:00
address_n = parse_path ( " m/44h/6h/0h/0/0 " ) ,
amount = 100_000 ,
2020-07-14 18:43:53 +00:00
prev_hash = TXHASH_41b29a ,
prev_index = 0 ,
2020-03-13 12:09:02 +00:00
)
out1 = messages . TxOutputType (
address = " PXtfyTjzgXSgTwK5AbszdHQSSxyQN3BLM5 " ,
2022-01-31 12:25:30 +00:00
amount = 100_000 - 10_000 ,
2020-03-13 12:09:02 +00:00
script_type = messages . OutputScriptType . PAYTOADDRESS ,
)
2020-04-15 12:57:21 +00:00
with pytest . raises ( TrezorFailure , match = " Timestamp must be set. " ) :
2020-03-13 12:09:02 +00:00
btc . sign_tx (
2024-11-15 16:31:22 +00:00
session ,
2020-09-15 11:06:41 +00:00
" Peercoin " ,
[ inp1 ] ,
[ out1 ] ,
version = 1 ,
timestamp = None ,
prev_txes = TX_CACHE ,
2019-12-05 03:32:13 +00:00
)
2020-04-15 12:57:21 +00:00
with pytest . raises ( TrezorFailure , match = " Timestamp must be set. " ) :
2020-03-13 12:09:02 +00:00
btc . sign_tx (
2024-11-15 16:31:22 +00:00
session ,
2020-09-15 11:06:41 +00:00
" Peercoin " ,
[ inp1 ] ,
[ out1 ] ,
version = 1 ,
timestamp = 0 ,
prev_txes = TX_CACHE ,
2020-03-13 12:09:02 +00:00
)
@pytest.mark.altcoin
@pytest.mark.peercoin
2024-11-15 16:31:22 +00:00
def test_timestamp_missing_prevtx ( session : Session ) :
2020-03-13 12:09:02 +00:00
inp1 = messages . TxInputType (
2022-01-31 12:25:30 +00:00
address_n = parse_path ( " m/44h/6h/0h/0/0 " ) ,
amount = 100_000 ,
2020-07-14 18:43:53 +00:00
prev_hash = TXHASH_41b29a ,
prev_index = 0 ,
2020-03-13 12:09:02 +00:00
)
out1 = messages . TxOutputType (
address = " PXtfyTjzgXSgTwK5AbszdHQSSxyQN3BLM5 " ,
2022-01-31 12:25:30 +00:00
a mount = 100_000 - 10_000 ,
2020-03-13 12:09:02 +00:00
script_type = messages . OutputScriptType . PAYTOADDRESS ,
)
2020-04-15 12:57:21 +00:00
prevtx = TX_CACHE [ TXHASH_41b29a ]
2020-03-13 12:09:02 +00:00
prevtx . timestamp = 0
2020-04-15 12:57:21 +00:00
with pytest . raises ( TrezorFailure , match = " Timestamp must be set. " ) :
2020-03-13 12:09:02 +00:00
btc . sign_tx (
2024-11-15 16:31:22 +00:00
session ,
2019-12-05 03:32:13 +00:00
" Peercoin " ,
[ inp1 ] ,
[ out1 ] ,
2020-09-15 11:06:41 +00:00
version = 1 ,
timestamp = 0x5DC5448A ,
2020-03-13 12:09:02 +00:00
prev_txes = { TXHASH_41b29a : prevtx } ,
2019-12-05 03:32:13 +00:00
)
2020-03-13 12:09:02 +00:00
prevtx . timestamp = None
2020-04-15 12:57:21 +00:00
with pytest . raises ( TrezorFailure , match = " Timestamp must be set. " ) :
2020-03-13 12:09:02 +00:00
btc . sign_tx (
2024-11-15 16:31:22 +00:00
session ,
2020-03-13 12:09:02 +00:00
" Peercoin " ,
[ inp1 ] ,
[ out1 ] ,
2020-09-15 11:06:41 +00:00
version = 1 ,
timestamp = 0x5DC5448A ,
2020-03-13 12:09:02 +00:00
prev_txes = { TXHASH_41b29a : prevtx } ,
)