2021-08-25 14:32:52 +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
|
|
|
|
|
2024-03-09 21:05:05 +00:00
|
|
|
from trezorlib import ethereum, exceptions, messages, models
|
2023-08-15 15:58:32 +00:00
|
|
|
from trezorlib.debuglink import TrezorClientDebugLink as Client
|
|
|
|
from trezorlib.debuglink import message_filters
|
2021-08-25 14:32:52 +00:00
|
|
|
from trezorlib.exceptions import TrezorFailure
|
2023-03-16 15:36:34 +00:00
|
|
|
from trezorlib.tools import parse_path, unharden
|
2021-08-25 14:32:52 +00:00
|
|
|
|
|
|
|
from ...common import parametrize_using_common_fixtures
|
2023-05-04 12:18:55 +00:00
|
|
|
from ...input_flows import (
|
2023-08-01 14:54:01 +00:00
|
|
|
InputFlowEthereumSignTxDataGoBack,
|
|
|
|
InputFlowEthereumSignTxDataScrollDown,
|
|
|
|
InputFlowEthereumSignTxDataSkip,
|
2023-12-05 10:50:13 +00:00
|
|
|
InputFlowEthereumSignTxGoBackFromSummary,
|
2023-08-01 14:54:01 +00:00
|
|
|
InputFlowEthereumSignTxShowFeeInfo,
|
2024-02-21 15:03:48 +00:00
|
|
|
InputFlowEthereumSignTxStaking,
|
2023-05-04 12:18:55 +00:00
|
|
|
)
|
2023-03-16 15:36:34 +00:00
|
|
|
from .common import encode_network
|
2021-08-25 14:32:52 +00:00
|
|
|
|
|
|
|
TO_ADDR = "0x1d1c328764a41bda0492b66baa30c4a339ff85ef"
|
2023-05-04 12:18:55 +00:00
|
|
|
|
2021-08-25 14:32:52 +00:00
|
|
|
|
|
|
|
pytestmark = [pytest.mark.altcoin, pytest.mark.ethereum]
|
|
|
|
|
|
|
|
|
2023-03-16 15:36:34 +00:00
|
|
|
def make_defs(parameters: dict) -> messages.EthereumDefinitions:
|
|
|
|
# With removal of most built-in defs from firmware, we have test vectors
|
|
|
|
# that no longer run. Because this is not the place to test the definitions,
|
|
|
|
# we generate fake entries so that we can check the signing results.
|
|
|
|
address_n = parse_path(parameters["path"])
|
|
|
|
slip44 = unharden(address_n[1])
|
|
|
|
network = encode_network(chain_id=parameters["chain_id"], slip44=slip44)
|
|
|
|
|
|
|
|
return messages.EthereumDefinitions(encoded_network=network)
|
|
|
|
|
|
|
|
|
2021-08-25 14:32:52 +00:00
|
|
|
@parametrize_using_common_fixtures(
|
|
|
|
"ethereum/sign_tx.json",
|
|
|
|
"ethereum/sign_tx_eip155.json",
|
|
|
|
)
|
2023-09-14 10:22:18 +00:00
|
|
|
@pytest.mark.parametrize("chunkify", (True, False))
|
|
|
|
def test_signtx(client: Client, chunkify: bool, parameters: dict, result: dict):
|
|
|
|
_do_test_signtx(client, parameters, result, chunkify=chunkify)
|
|
|
|
|
|
|
|
|
|
|
|
def _do_test_signtx(
|
|
|
|
client: Client,
|
|
|
|
parameters: dict,
|
|
|
|
result: dict,
|
|
|
|
input_flow=None,
|
|
|
|
chunkify: bool = False,
|
|
|
|
):
|
2021-08-25 14:32:52 +00:00
|
|
|
with client:
|
2023-08-01 14:54:01 +00:00
|
|
|
if input_flow:
|
|
|
|
client.watch_layout()
|
|
|
|
client.set_input_flow(input_flow)
|
2021-08-25 14:32:52 +00:00
|
|
|
sig_v, sig_r, sig_s = ethereum.sign_tx(
|
|
|
|
client,
|
|
|
|
n=parse_path(parameters["path"]),
|
2021-09-15 08:35:31 +00:00
|
|
|
nonce=int(parameters["nonce"], 16),
|
|
|
|
gas_price=int(parameters["gas_price"], 16),
|
|
|
|
gas_limit=int(parameters["gas_limit"], 16),
|
2021-08-25 14:32:52 +00:00
|
|
|
to=parameters["to_address"],
|
|
|
|
chain_id=parameters["chain_id"],
|
2021-09-15 08:35:31 +00:00
|
|
|
value=int(parameters["value"], 16),
|
2021-08-25 14:32:52 +00:00
|
|
|
tx_type=parameters["tx_type"],
|
|
|
|
data=bytes.fromhex(parameters["data"]),
|
2023-03-16 15:36:34 +00:00
|
|
|
definitions=make_defs(parameters),
|
2023-09-14 10:22:18 +00:00
|
|
|
chunkify=chunkify,
|
2021-08-25 14:32:52 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
expected_v = 2 * parameters["chain_id"] + 35
|
|
|
|
assert sig_v in (expected_v, expected_v + 1)
|
|
|
|
assert sig_r.hex() == result["sig_r"]
|
|
|
|
assert sig_s.hex() == result["sig_s"]
|
|
|
|
assert sig_v == result["sig_v"]
|
|
|
|
|
|
|
|
|
2023-12-05 10:50:13 +00:00
|
|
|
# Data taken from sign_tx_eip1559.json["tests"][0]
|
|
|
|
example_input_data = {
|
|
|
|
"parameters": {
|
2023-08-01 14:54:01 +00:00
|
|
|
"chain_id": 1,
|
|
|
|
"path": "m/44'/60'/0'/0/0",
|
|
|
|
"nonce": "0x0",
|
|
|
|
"gas_price": "0x4a817c800",
|
|
|
|
"gas_limit": "0x5208",
|
|
|
|
"value": "0x2540be400",
|
|
|
|
"to_address": "0x8eA7a3fccC211ED48b763b4164884DDbcF3b0A98",
|
|
|
|
"tx_type": None,
|
|
|
|
"data": "",
|
2023-12-05 10:50:13 +00:00
|
|
|
},
|
|
|
|
"result": {
|
2023-08-01 14:54:01 +00:00
|
|
|
"sig_v": 38,
|
|
|
|
"sig_r": "6a6349bddb5749bb8b96ce2566a035ef87a09dbf89b5c7e3dfdf9ed725912f24",
|
|
|
|
"sig_s": "4ae58ccd3bacee07cdc4a3e8540544fd009c4311af7048122da60f2054c07ee4",
|
2023-12-05 10:50:13 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-03-11 15:20:08 +00:00
|
|
|
@pytest.mark.skip_t1b1("T1 does not support input flows")
|
2023-12-05 10:50:13 +00:00
|
|
|
def test_signtx_fee_info(client: Client):
|
|
|
|
input_flow = InputFlowEthereumSignTxShowFeeInfo(client).get()
|
|
|
|
_do_test_signtx(
|
|
|
|
client,
|
|
|
|
example_input_data["parameters"],
|
|
|
|
example_input_data["result"],
|
|
|
|
input_flow,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2024-03-11 15:20:08 +00:00
|
|
|
@pytest.mark.skip_t1b1("T1 does not support input flows")
|
2023-12-05 10:50:13 +00:00
|
|
|
def test_signtx_go_back_from_summary(client: Client):
|
|
|
|
input_flow = InputFlowEthereumSignTxGoBackFromSummary(client).get()
|
|
|
|
_do_test_signtx(
|
|
|
|
client,
|
|
|
|
example_input_data["parameters"],
|
|
|
|
example_input_data["result"],
|
|
|
|
input_flow,
|
|
|
|
)
|
2023-08-01 14:54:01 +00:00
|
|
|
|
|
|
|
|
2021-09-15 08:35:31 +00:00
|
|
|
@parametrize_using_common_fixtures("ethereum/sign_tx_eip1559.json")
|
2023-09-14 10:22:18 +00:00
|
|
|
@pytest.mark.parametrize("chunkify", (True, False))
|
|
|
|
def test_signtx_eip1559(client: Client, chunkify: bool, parameters: dict, result: dict):
|
2021-08-25 14:32:52 +00:00
|
|
|
with client:
|
|
|
|
sig_v, sig_r, sig_s = ethereum.sign_tx_eip1559(
|
|
|
|
client,
|
|
|
|
n=parse_path(parameters["path"]),
|
2021-09-15 08:35:31 +00:00
|
|
|
nonce=int(parameters["nonce"], 16),
|
|
|
|
gas_limit=int(parameters["gas_limit"], 16),
|
|
|
|
max_gas_fee=int(parameters["max_gas_fee"], 16),
|
|
|
|
max_priority_fee=int(parameters["max_priority_fee"], 16),
|
2021-08-25 14:32:52 +00:00
|
|
|
to=parameters["to_address"],
|
|
|
|
chain_id=parameters["chain_id"],
|
2021-09-15 08:35:31 +00:00
|
|
|
value=int(parameters["value"], 16),
|
2021-08-25 14:32:52 +00:00
|
|
|
data=bytes.fromhex(parameters["data"]),
|
2023-03-16 15:36:34 +00:00
|
|
|
definitions=make_defs(parameters),
|
2023-09-14 10:22:18 +00:00
|
|
|
chunkify=chunkify,
|
2021-08-25 14:32:52 +00:00
|
|
|
)
|
|
|
|
|
2021-09-15 08:35:31 +00:00
|
|
|
assert sig_r.hex() == result["sig_r"]
|
|
|
|
assert sig_s.hex() == result["sig_s"]
|
2021-08-25 14:32:52 +00:00
|
|
|
assert sig_v == result["sig_v"]
|
|
|
|
|
|
|
|
|
2022-01-31 12:25:30 +00:00
|
|
|
def test_sanity_checks(client: Client):
|
2021-08-25 14:32:52 +00:00
|
|
|
"""Is not vectorized because these are internal-only tests that do not
|
|
|
|
need to be exposed to the public.
|
|
|
|
"""
|
|
|
|
# contract creation without data should fail.
|
2021-09-08 13:06:20 +00:00
|
|
|
with pytest.raises(TrezorFailure, match=r"DataError"):
|
2021-08-25 14:32:52 +00:00
|
|
|
ethereum.sign_tx(
|
|
|
|
client,
|
2022-01-31 12:25:30 +00:00
|
|
|
n=parse_path("m/44h/60h/0h/0/0"),
|
|
|
|
nonce=123_456,
|
|
|
|
gas_price=20_000,
|
|
|
|
gas_limit=20_000,
|
2021-08-25 14:32:52 +00:00
|
|
|
to="",
|
2022-01-31 12:25:30 +00:00
|
|
|
value=12_345_678_901_234_567_890,
|
2021-09-08 13:06:20 +00:00
|
|
|
chain_id=1,
|
2021-08-25 14:32:52 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# gas overflow
|
2021-09-08 13:06:20 +00:00
|
|
|
with pytest.raises(TrezorFailure, match=r"DataError"):
|
2021-08-25 14:32:52 +00:00
|
|
|
ethereum.sign_tx(
|
|
|
|
client,
|
2022-01-31 12:25:30 +00:00
|
|
|
n=parse_path("m/44h/60h/0h/0/0"),
|
|
|
|
nonce=123_456,
|
2021-08-25 14:32:52 +00:00
|
|
|
gas_price=0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF,
|
|
|
|
gas_limit=0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF,
|
|
|
|
to=TO_ADDR,
|
2022-01-31 12:25:30 +00:00
|
|
|
value=12_345_678_901_234_567_890,
|
2021-09-08 13:06:20 +00:00
|
|
|
chain_id=1,
|
|
|
|
)
|
|
|
|
|
|
|
|
# bad chain ID
|
|
|
|
with pytest.raises(TrezorFailure, match=r"Chain ID out of bounds"):
|
|
|
|
ethereum.sign_tx(
|
|
|
|
client,
|
2022-01-31 12:25:30 +00:00
|
|
|
n=parse_path("m/44h/60h/0h/0/0"),
|
|
|
|
nonce=123_456,
|
|
|
|
gas_price=20_000,
|
|
|
|
gas_limit=20_000,
|
2021-09-08 13:06:20 +00:00
|
|
|
to=TO_ADDR,
|
2022-01-31 12:25:30 +00:00
|
|
|
value=12_345_678_901_234_567_890,
|
2021-09-08 13:06:20 +00:00
|
|
|
chain_id=0,
|
2021-08-25 14:32:52 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-01-31 12:25:30 +00:00
|
|
|
def test_data_streaming(client: Client):
|
2021-08-25 14:32:52 +00:00
|
|
|
"""Only verifying the expected responses, the signatures are
|
|
|
|
checked in vectorized function above.
|
|
|
|
"""
|
|
|
|
with client:
|
2024-03-09 21:05:05 +00:00
|
|
|
is_t1 = client.model is models.T1B1
|
2021-08-25 14:32:52 +00:00
|
|
|
client.set_expected_responses(
|
|
|
|
[
|
|
|
|
messages.ButtonRequest(code=messages.ButtonRequestType.SignTx),
|
2023-09-14 15:22:21 +00:00
|
|
|
(is_t1, messages.ButtonRequest(code=messages.ButtonRequestType.SignTx)),
|
2023-11-07 09:00:07 +00:00
|
|
|
(
|
|
|
|
not is_t1,
|
|
|
|
messages.ButtonRequest(code=messages.ButtonRequestType.Other),
|
|
|
|
),
|
2023-05-04 12:18:55 +00:00
|
|
|
messages.ButtonRequest(code=messages.ButtonRequestType.SignTx),
|
2021-08-25 14:32:52 +00:00
|
|
|
message_filters.EthereumTxRequest(
|
2022-01-31 12:25:30 +00:00
|
|
|
data_length=1_024,
|
2021-08-25 14:32:52 +00:00
|
|
|
signature_r=None,
|
|
|
|
signature_s=None,
|
|
|
|
signature_v=None,
|
|
|
|
),
|
|
|
|
message_filters.EthereumTxRequest(
|
2022-01-31 12:25:30 +00:00
|
|
|
data_length=1_024,
|
2021-08-25 14:32:52 +00:00
|
|
|
signature_r=None,
|
|
|
|
signature_s=None,
|
|
|
|
signature_v=None,
|
|
|
|
),
|
|
|
|
message_filters.EthereumTxRequest(
|
2022-01-31 12:25:30 +00:00
|
|
|
data_length=1_024,
|
2021-08-25 14:32:52 +00:00
|
|
|
signature_r=None,
|
|
|
|
signature_s=None,
|
|
|
|
signature_v=None,
|
|
|
|
),
|
|
|
|
message_filters.EthereumTxRequest(
|
|
|
|
data_length=3,
|
|
|
|
signature_r=None,
|
|
|
|
signature_s=None,
|
|
|
|
signature_v=None,
|
|
|
|
),
|
|
|
|
message_filters.EthereumTxRequest(data_length=None),
|
|
|
|
]
|
|
|
|
)
|
|
|
|
|
|
|
|
ethereum.sign_tx(
|
|
|
|
client,
|
2022-01-31 12:25:30 +00:00
|
|
|
n=parse_path("m/44h/60h/0h/0/0"),
|
2021-08-25 14:32:52 +00:00
|
|
|
nonce=0,
|
2022-01-31 12:25:30 +00:00
|
|
|
gas_price=20_000,
|
|
|
|
gas_limit=20_000,
|
2021-08-25 14:32:52 +00:00
|
|
|
to=TO_ADDR,
|
|
|
|
value=0,
|
|
|
|
data=b"ABCDEFGHIJKLMNOP" * 256 + b"!!!",
|
2021-09-01 10:04:39 +00:00
|
|
|
chain_id=1,
|
2021-08-25 14:32:52 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-01-31 12:25:30 +00:00
|
|
|
def test_signtx_eip1559_access_list(client: Client):
|
2021-08-25 14:32:52 +00:00
|
|
|
with client:
|
|
|
|
|
|
|
|
sig_v, sig_r, sig_s = ethereum.sign_tx_eip1559(
|
|
|
|
client,
|
2022-01-31 12:25:30 +00:00
|
|
|
n=parse_path("m/44h/60h/0h/0/100"),
|
2021-08-25 14:32:52 +00:00
|
|
|
nonce=0,
|
|
|
|
gas_limit=20,
|
|
|
|
to="0x1d1c328764a41bda0492b66baa30c4a339ff85ef",
|
|
|
|
chain_id=1,
|
|
|
|
value=10,
|
|
|
|
max_gas_fee=20,
|
|
|
|
max_priority_fee=1,
|
|
|
|
access_list=[
|
|
|
|
messages.EthereumAccessList(
|
|
|
|
address="0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae",
|
|
|
|
storage_keys=[
|
|
|
|
bytes.fromhex(
|
|
|
|
"0000000000000000000000000000000000000000000000000000000000000003"
|
|
|
|
),
|
|
|
|
bytes.fromhex(
|
|
|
|
"0000000000000000000000000000000000000000000000000000000000000007"
|
|
|
|
),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
],
|
|
|
|
)
|
|
|
|
|
|
|
|
assert sig_v == 1
|
|
|
|
assert (
|
|
|
|
sig_r.hex()
|
|
|
|
== "9f8763f3ff8d4d409f6b96bc3f1d84dd504e2c667b162778508478645401f121"
|
|
|
|
)
|
|
|
|
assert (
|
|
|
|
sig_s.hex()
|
|
|
|
== "51e30b68b9091cf8138c07380c4378c2711779b68b2e5264d141479f13a12f57"
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-01-31 12:25:30 +00:00
|
|
|
def test_signtx_eip1559_access_list_larger(client: Client):
|
2021-08-25 14:32:52 +00:00
|
|
|
with client:
|
|
|
|
|
|
|
|
sig_v, sig_r, sig_s = ethereum.sign_tx_eip1559(
|
|
|
|
client,
|
2022-01-31 12:25:30 +00:00
|
|
|
n=parse_path("m/44h/60h/0h/0/100"),
|
2021-08-25 14:32:52 +00:00
|
|
|
nonce=0,
|
|
|
|
gas_limit=20,
|
|
|
|
to="0x1d1c328764a41bda0492b66baa30c4a339ff85ef",
|
|
|
|
chain_id=1,
|
|
|
|
value=10,
|
|
|
|
max_gas_fee=20,
|
|
|
|
max_priority_fee=1,
|
|
|
|
access_list=[
|
|
|
|
messages.EthereumAccessList(
|
|
|
|
address="0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae",
|
|
|
|
storage_keys=[
|
|
|
|
bytes.fromhex(
|
|
|
|
"0000000000000000000000000000000000000000000000000000000000000003"
|
|
|
|
),
|
|
|
|
bytes.fromhex(
|
|
|
|
"0000000000000000000000000000000000000000000000000000000000000007"
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
messages.EthereumAccessList(
|
|
|
|
address="0xbb9bc244d798123fde783fcc1c72d3bb8c189413",
|
|
|
|
storage_keys=[
|
|
|
|
bytes.fromhex(
|
|
|
|
"0000000000000000000000000000000000000000000000000000000000000006"
|
|
|
|
),
|
|
|
|
bytes.fromhex(
|
|
|
|
"0000000000000000000000000000000000000000000000000000000000000007"
|
|
|
|
),
|
|
|
|
bytes.fromhex(
|
|
|
|
"0000000000000000000000000000000000000000000000000000000000000009"
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
|
|
|
|
assert sig_v == 1
|
|
|
|
assert (
|
|
|
|
sig_r.hex()
|
|
|
|
== "718a3a30827c979975c846d2f60495310c4959ee3adce2d89e0211785725465c"
|
|
|
|
)
|
|
|
|
assert (
|
|
|
|
sig_s.hex()
|
|
|
|
== "7d0ea2a28ef5702ca763c1f340427c0020292ffcbb4553dd1c8ea8e2b9126dbc"
|
|
|
|
)
|
2021-09-08 13:06:20 +00:00
|
|
|
|
|
|
|
|
2022-01-31 12:25:30 +00:00
|
|
|
def test_sanity_checks_eip1559(client: Client):
|
2021-09-08 13:06:20 +00:00
|
|
|
"""Is not vectorized because these are internal-only tests that do not
|
|
|
|
need to be exposed to the public.
|
|
|
|
"""
|
|
|
|
# contract creation without data should fail.
|
|
|
|
with pytest.raises(TrezorFailure, match=r"DataError"):
|
|
|
|
ethereum.sign_tx_eip1559(
|
|
|
|
client,
|
2022-01-31 12:25:30 +00:00
|
|
|
n=parse_path("m/44h/60h/0h/0/100"),
|
2021-09-08 13:06:20 +00:00
|
|
|
nonce=0,
|
|
|
|
gas_limit=20,
|
|
|
|
to="",
|
|
|
|
chain_id=1,
|
|
|
|
value=10,
|
|
|
|
max_gas_fee=20,
|
|
|
|
max_priority_fee=1,
|
|
|
|
)
|
|
|
|
|
|
|
|
# max fee overflow
|
|
|
|
with pytest.raises(TrezorFailure, match=r"DataError"):
|
|
|
|
ethereum.sign_tx_eip1559(
|
|
|
|
client,
|
2022-01-31 12:25:30 +00:00
|
|
|
n=parse_path("m/44h/60h/0h/0/100"),
|
2021-09-08 13:06:20 +00:00
|
|
|
nonce=0,
|
|
|
|
gas_limit=0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF,
|
|
|
|
to=TO_ADDR,
|
|
|
|
chain_id=1,
|
|
|
|
value=10,
|
|
|
|
max_gas_fee=0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF,
|
|
|
|
max_priority_fee=1,
|
|
|
|
)
|
|
|
|
|
|
|
|
# priority fee overflow
|
|
|
|
with pytest.raises(TrezorFailure, match=r"DataError"):
|
|
|
|
ethereum.sign_tx_eip1559(
|
|
|
|
client,
|
2022-01-31 12:25:30 +00:00
|
|
|
n=parse_path("m/44h/60h/0h/0/100"),
|
2021-09-08 13:06:20 +00:00
|
|
|
nonce=0,
|
|
|
|
gas_limit=0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF,
|
|
|
|
to=TO_ADDR,
|
|
|
|
chain_id=1,
|
|
|
|
value=10,
|
|
|
|
max_gas_fee=20,
|
|
|
|
max_priority_fee=0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF,
|
|
|
|
)
|
|
|
|
|
|
|
|
# bad chain ID
|
|
|
|
with pytest.raises(TrezorFailure, match=r"Chain ID out of bounds"):
|
|
|
|
ethereum.sign_tx_eip1559(
|
|
|
|
client,
|
2022-01-31 12:25:30 +00:00
|
|
|
n=parse_path("m/44h/60h/0h/0/100"),
|
2021-09-08 13:06:20 +00:00
|
|
|
nonce=0,
|
|
|
|
gas_limit=20,
|
|
|
|
to=TO_ADDR,
|
|
|
|
chain_id=0,
|
|
|
|
value=10,
|
|
|
|
max_gas_fee=20,
|
|
|
|
max_priority_fee=1,
|
|
|
|
)
|
2021-10-14 21:52:58 +00:00
|
|
|
|
|
|
|
|
2023-08-01 14:54:01 +00:00
|
|
|
def input_flow_data_skip(client: Client, cancel: bool = False):
|
|
|
|
return InputFlowEthereumSignTxDataSkip(client, cancel).get()
|
2021-10-14 21:52:58 +00:00
|
|
|
|
|
|
|
|
2023-08-01 14:54:01 +00:00
|
|
|
def input_flow_data_scroll_down(client: Client, cancel: bool = False):
|
|
|
|
return InputFlowEthereumSignTxDataScrollDown(client, cancel).get()
|
2021-10-14 21:52:58 +00:00
|
|
|
|
|
|
|
|
2023-08-01 14:54:01 +00:00
|
|
|
def input_flow_data_go_back(client: Client, cancel: bool = False):
|
|
|
|
return InputFlowEthereumSignTxDataGoBack(client, cancel).get()
|
2021-10-14 21:52:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
HEXDATA = "0123456789abcd000023456789abcd010003456789abcd020000456789abcd030000056789abcd040000006789abcd050000000789abcd060000000089abcd070000000009abcd080000000000abcd090000000001abcd0a0000000011abcd0b0000000111abcd0c0000001111abcd0d0000011111abcd0e0000111111abcd0f0000000002abcd100000000022abcd110000000222abcd120000002222abcd130000022222abcd140000222222abcd15"
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
2023-08-01 14:54:01 +00:00
|
|
|
"flow", (input_flow_data_skip, input_flow_data_scroll_down, input_flow_data_go_back)
|
2021-10-14 21:52:58 +00:00
|
|
|
)
|
2024-06-04 22:27:48 +00:00
|
|
|
@pytest.mark.skip_t3t1(reason="Not yet implemented in new UI")
|
2024-03-11 15:20:08 +00:00
|
|
|
@pytest.mark.skip_t1b1
|
2022-01-31 12:25:30 +00:00
|
|
|
def test_signtx_data_pagination(client: Client, flow):
|
2023-05-04 12:18:55 +00:00
|
|
|
def _sign_tx_call():
|
2021-10-14 21:52:58 +00:00
|
|
|
ethereum.sign_tx(
|
|
|
|
client,
|
2022-01-31 12:25:30 +00:00
|
|
|
n=parse_path("m/44h/60h/0h/0/0"),
|
2021-10-14 21:52:58 +00:00
|
|
|
nonce=0x0,
|
|
|
|
gas_price=0x14,
|
|
|
|
gas_limit=0x14,
|
|
|
|
to="0x1d1c328764a41bda0492b66baa30c4a339ff85ef",
|
|
|
|
chain_id=1,
|
|
|
|
value=0xA,
|
|
|
|
tx_type=None,
|
|
|
|
data=bytes.fromhex(HEXDATA),
|
|
|
|
)
|
|
|
|
|
2023-05-04 12:18:55 +00:00
|
|
|
with client:
|
|
|
|
client.watch_layout()
|
|
|
|
client.set_input_flow(flow(client))
|
|
|
|
_sign_tx_call()
|
|
|
|
|
2021-10-14 21:52:58 +00:00
|
|
|
with client, pytest.raises(exceptions.Cancelled):
|
|
|
|
client.watch_layout()
|
|
|
|
client.set_input_flow(flow(client, cancel=True))
|
2023-05-04 12:18:55 +00:00
|
|
|
_sign_tx_call()
|
2024-02-11 17:30:20 +00:00
|
|
|
|
|
|
|
|
2024-05-31 00:39:13 +00:00
|
|
|
@pytest.mark.skip_t3t1(reason="Not yet implemented in new UI")
|
2024-03-11 15:20:08 +00:00
|
|
|
@pytest.mark.skip_t1b1("T1 does not support Everstake")
|
2024-02-11 17:30:20 +00:00
|
|
|
@parametrize_using_common_fixtures("ethereum/sign_tx_staking.json")
|
2024-02-21 15:03:48 +00:00
|
|
|
@pytest.mark.parametrize("chunkify", (True, False))
|
|
|
|
def test_signtx_staking(client: Client, chunkify: bool, parameters: dict, result: dict):
|
|
|
|
input_flow = InputFlowEthereumSignTxStaking(client).get()
|
|
|
|
_do_test_signtx(
|
|
|
|
client, parameters, result, input_flow=input_flow, chunkify=chunkify
|
|
|
|
)
|
2024-02-11 17:30:20 +00:00
|
|
|
|
|
|
|
|
2024-03-11 15:20:08 +00:00
|
|
|
@pytest.mark.skip_t1b1("T1 does not support Everstake")
|
2024-02-11 17:30:20 +00:00
|
|
|
@parametrize_using_common_fixtures("ethereum/sign_tx_staking_data_error.json")
|
|
|
|
def test_signtx_staking_bad_inputs(client: Client, parameters: dict, result: dict):
|
|
|
|
# result not needed
|
|
|
|
with pytest.raises(TrezorFailure, match=r"DataError"):
|
|
|
|
ethereum.sign_tx(
|
|
|
|
client,
|
|
|
|
n=parse_path(parameters["path"]),
|
|
|
|
nonce=int(parameters["nonce"], 16),
|
|
|
|
gas_price=int(parameters["gas_price"], 16),
|
|
|
|
gas_limit=int(parameters["gas_limit"], 16),
|
|
|
|
to=parameters["to_address"],
|
|
|
|
value=int(parameters["value"], 16),
|
|
|
|
data=bytes.fromhex(parameters["data"]),
|
|
|
|
chain_id=parameters["chain_id"],
|
|
|
|
tx_type=parameters["tx_type"],
|
|
|
|
definitions=None,
|
|
|
|
chunkify=False,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2024-03-11 15:20:08 +00:00
|
|
|
@pytest.mark.skip_t1b1("T1 does not support Everstake")
|
2024-02-11 17:30:20 +00:00
|
|
|
@parametrize_using_common_fixtures("ethereum/sign_tx_staking_eip1559.json")
|
|
|
|
def test_signtx_staking_eip1559(client: Client, parameters: dict, result: dict):
|
|
|
|
with client:
|
|
|
|
sig_v, sig_r, sig_s = ethereum.sign_tx_eip1559(
|
|
|
|
client,
|
|
|
|
n=parse_path(parameters["path"]),
|
|
|
|
nonce=int(parameters["nonce"], 16),
|
|
|
|
max_gas_fee=int(parameters["max_gas_fee"], 16),
|
|
|
|
max_priority_fee=int(parameters["max_priority_fee"], 16),
|
|
|
|
gas_limit=int(parameters["gas_limit"], 16),
|
|
|
|
to=parameters["to_address"],
|
|
|
|
value=int(parameters["value"], 16),
|
|
|
|
data=bytes.fromhex(parameters["data"]),
|
|
|
|
chain_id=parameters["chain_id"],
|
|
|
|
definitions=None,
|
|
|
|
chunkify=True,
|
|
|
|
)
|
|
|
|
assert sig_r.hex() == result["sig_r"]
|
|
|
|
assert sig_s.hex() == result["sig_s"]
|
|
|
|
assert sig_v == result["sig_v"]
|