mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-07-14 02:28:19 +00:00
tests(core): built-in Ethereum definitions
This commit is contained in:
parent
c1f27e0a11
commit
7fbbfaa665
Binary file not shown.
BIN
common/tests/fixtures/ethereum/definitions-latest/by_chain_id/11297108109/network.dat
vendored
Normal file
BIN
common/tests/fixtures/ethereum/definitions-latest/by_chain_id/11297108109/network.dat
vendored
Normal file
Binary file not shown.
BIN
common/tests/fixtures/ethereum/definitions-latest/by_chain_id/28945486/network.dat
vendored
Normal file
BIN
common/tests/fixtures/ethereum/definitions-latest/by_chain_id/28945486/network.dat
vendored
Normal file
Binary file not shown.
BIN
common/tests/fixtures/ethereum/definitions-latest/by_chain_id/3125659152/network.dat
vendored
Normal file
BIN
common/tests/fixtures/ethereum/definitions-latest/by_chain_id/3125659152/network.dat
vendored
Normal file
Binary file not shown.
BIN
common/tests/fixtures/ethereum/definitions-latest/by_chain_id/4/network.dat
vendored
Normal file
BIN
common/tests/fixtures/ethereum/definitions-latest/by_chain_id/4/network.dat
vendored
Normal file
Binary file not shown.
BIN
common/tests/fixtures/ethereum/definitions-latest/by_chain_id/61/network.dat
vendored
Normal file
BIN
common/tests/fixtures/ethereum/definitions-latest/by_chain_id/61/network.dat
vendored
Normal file
Binary file not shown.
BIN
common/tests/fixtures/ethereum/definitions-latest/by_chain_id/888/network.dat
vendored
Normal file
BIN
common/tests/fixtures/ethereum/definitions-latest/by_chain_id/888/network.dat
vendored
Normal file
Binary file not shown.
BIN
common/tests/fixtures/ethereum/definitions-latest/by_slip44/5718350/network.dat
vendored
Normal file
BIN
common/tests/fixtures/ethereum/definitions-latest/by_slip44/5718350/network.dat
vendored
Normal file
Binary file not shown.
BIN
common/tests/fixtures/ethereum/definitions-latest/by_slip44/6060/network.dat
vendored
Normal file
BIN
common/tests/fixtures/ethereum/definitions-latest/by_slip44/6060/network.dat
vendored
Normal file
Binary file not shown.
BIN
common/tests/fixtures/ethereum/definitions-latest/by_slip44/61/network.dat
vendored
Normal file
BIN
common/tests/fixtures/ethereum/definitions-latest/by_slip44/61/network.dat
vendored
Normal file
Binary file not shown.
@ -39,6 +39,8 @@
|
|||||||
{
|
{
|
||||||
"name": "ETC",
|
"name": "ETC",
|
||||||
"parameters": {
|
"parameters": {
|
||||||
|
"builtin_network": false,
|
||||||
|
"slip44": 61,
|
||||||
"path": "m/44'/61'/0'/0/0"
|
"path": "m/44'/61'/0'/0/0"
|
||||||
},
|
},
|
||||||
"result": {
|
"result": {
|
||||||
@ -48,6 +50,8 @@
|
|||||||
{
|
{
|
||||||
"name": "GoChain",
|
"name": "GoChain",
|
||||||
"parameters": {
|
"parameters": {
|
||||||
|
"builtin_network": false,
|
||||||
|
"slip44": 6060,
|
||||||
"path": "m/44'/6060'/0'/0/0"
|
"path": "m/44'/6060'/0'/0/0"
|
||||||
},
|
},
|
||||||
"result": {
|
"result": {
|
||||||
@ -57,6 +61,8 @@
|
|||||||
{
|
{
|
||||||
"name": "Wanchain",
|
"name": "Wanchain",
|
||||||
"parameters": {
|
"parameters": {
|
||||||
|
"builtin_network": false,
|
||||||
|
"slip44": 5718350,
|
||||||
"path": "m/44'/5718350'/0'/0/0"
|
"path": "m/44'/5718350'/0'/0/0"
|
||||||
},
|
},
|
||||||
"result": {
|
"result": {
|
||||||
|
6
common/tests/fixtures/ethereum/sign_tx.json
vendored
6
common/tests/fixtures/ethereum/sign_tx.json
vendored
@ -16,7 +16,8 @@
|
|||||||
"gas_price": "0x14",
|
"gas_price": "0x14",
|
||||||
"gas_limit": "0x14",
|
"gas_limit": "0x14",
|
||||||
"tx_type": null,
|
"tx_type": null,
|
||||||
"value": "0x0"
|
"value": "0x0",
|
||||||
|
"builtin_token": false
|
||||||
},
|
},
|
||||||
"result": {
|
"result": {
|
||||||
"sig_v": 37,
|
"sig_v": 37,
|
||||||
@ -55,7 +56,8 @@
|
|||||||
"gas_price": "0x14",
|
"gas_price": "0x14",
|
||||||
"gas_limit": "0x14",
|
"gas_limit": "0x14",
|
||||||
"tx_type": 1,
|
"tx_type": 1,
|
||||||
"value": "0x64"
|
"value": "0x64",
|
||||||
|
"builtin_network": false
|
||||||
},
|
},
|
||||||
"result": {
|
"result": {
|
||||||
"sig_v": 1811,
|
"sig_v": 1811,
|
||||||
|
@ -53,7 +53,8 @@
|
|||||||
"value": "0x2540be400",
|
"value": "0x2540be400",
|
||||||
"to_address": "0x8eA7a3fccC211ED48b763b4164884DDbcF3b0A98",
|
"to_address": "0x8eA7a3fccC211ED48b763b4164884DDbcF3b0A98",
|
||||||
"tx_type": null,
|
"tx_type": null,
|
||||||
"data": ""
|
"data": "",
|
||||||
|
"builtin_network": false
|
||||||
},
|
},
|
||||||
"result": {
|
"result": {
|
||||||
"sig_v": 43,
|
"sig_v": 43,
|
||||||
@ -72,7 +73,8 @@
|
|||||||
"value": "0x2540be400",
|
"value": "0x2540be400",
|
||||||
"to_address": "0x8eA7a3fccC211ED48b763b4164884DDbcF3b0A98",
|
"to_address": "0x8eA7a3fccC211ED48b763b4164884DDbcF3b0A98",
|
||||||
"tx_type": null,
|
"tx_type": null,
|
||||||
"data": ""
|
"data": "",
|
||||||
|
"builtin_network": false
|
||||||
},
|
},
|
||||||
"result": {
|
"result": {
|
||||||
"sig_v": 158,
|
"sig_v": 158,
|
||||||
@ -91,7 +93,8 @@
|
|||||||
"value": "0x2540be400",
|
"value": "0x2540be400",
|
||||||
"to_address": "0x8eA7a3fccC211ED48b763b4164884DDbcF3b0A98",
|
"to_address": "0x8eA7a3fccC211ED48b763b4164884DDbcF3b0A98",
|
||||||
"tx_type": null,
|
"tx_type": null,
|
||||||
"data": ""
|
"data": "",
|
||||||
|
"builtin_network": false
|
||||||
},
|
},
|
||||||
"result": {
|
"result": {
|
||||||
"sig_v": 57891008,
|
"sig_v": 57891008,
|
||||||
@ -110,7 +113,8 @@
|
|||||||
"value": "0x2540be400",
|
"value": "0x2540be400",
|
||||||
"to_address": "0x8eA7a3fccC211ED48b763b4164884DDbcF3b0A98",
|
"to_address": "0x8eA7a3fccC211ED48b763b4164884DDbcF3b0A98",
|
||||||
"tx_type": null,
|
"tx_type": null,
|
||||||
"data": ""
|
"data": "",
|
||||||
|
"builtin_network": false
|
||||||
},
|
},
|
||||||
"result": {
|
"result": {
|
||||||
"sig_v": 6251318340,
|
"sig_v": 6251318340,
|
||||||
@ -167,7 +171,8 @@
|
|||||||
"value": "0x2540be400",
|
"value": "0x2540be400",
|
||||||
"to_address": "0x8eA7a3fccC211ED48b763b4164884DDbcF3b0A98",
|
"to_address": "0x8eA7a3fccC211ED48b763b4164884DDbcF3b0A98",
|
||||||
"tx_type": null,
|
"tx_type": null,
|
||||||
"data": ""
|
"data": "",
|
||||||
|
"builtin_network": false
|
||||||
},
|
},
|
||||||
"result": {
|
"result": {
|
||||||
"sig_v": 22594216254,
|
"sig_v": 22594216254,
|
||||||
|
@ -73,7 +73,8 @@
|
|||||||
"gas_limit": "0x14",
|
"gas_limit": "0x14",
|
||||||
"max_gas_fee": "0x14",
|
"max_gas_fee": "0x14",
|
||||||
"max_priority_fee": "0x1",
|
"max_priority_fee": "0x1",
|
||||||
"value": "0x0"
|
"value": "0x0",
|
||||||
|
"builtin_token": false
|
||||||
},
|
},
|
||||||
"result": {
|
"result": {
|
||||||
"sig_v": 1,
|
"sig_v": 1,
|
||||||
@ -113,7 +114,8 @@
|
|||||||
"gas_limit": "0x14",
|
"gas_limit": "0x14",
|
||||||
"max_gas_fee": "0x14",
|
"max_gas_fee": "0x14",
|
||||||
"max_priority_fee": "0x1",
|
"max_priority_fee": "0x1",
|
||||||
"value": "0xa"
|
"value": "0xa",
|
||||||
|
"builtin_network": false
|
||||||
},
|
},
|
||||||
"result": {
|
"result": {
|
||||||
"sig_v": 0,
|
"sig_v": 0,
|
||||||
|
@ -23,6 +23,7 @@ if TYPE_CHECKING:
|
|||||||
bool # rskip60
|
bool # rskip60
|
||||||
]
|
]
|
||||||
# fmt: on
|
# fmt: on
|
||||||
|
|
||||||
UNKNOWN_NETWORK_SHORTCUT = "UNKN"
|
UNKNOWN_NETWORK_SHORTCUT = "UNKN"
|
||||||
|
|
||||||
|
|
||||||
|
@ -37,6 +37,7 @@ from typing import (
|
|||||||
import click
|
import click
|
||||||
|
|
||||||
from .. import ethereum, tools
|
from .. import ethereum, tools
|
||||||
|
from ..tools import UH_
|
||||||
from . import with_client
|
from . import with_client
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
@ -194,7 +195,7 @@ def _get_ethereum_definitions(
|
|||||||
if definitions_dir is not None:
|
if definitions_dir is not None:
|
||||||
if chain_id is not None or slip44_hardened is not None:
|
if chain_id is not None or slip44_hardened is not None:
|
||||||
defs.encoded_network = ethereum.network_definition_from_dir(
|
defs.encoded_network = ethereum.network_definition_from_dir(
|
||||||
definitions_dir, chain_id, slip44_hardened
|
definitions_dir, chain_id, UH_(slip44_hardened) # type: ignore [Argument of type "int | None" cannot be assigned to parameter "x" of type "int" in function "UH_"]
|
||||||
)
|
)
|
||||||
if chain_id is not None and token_address is not None:
|
if chain_id is not None and token_address is not None:
|
||||||
defs.encoded_token = ethereum.token_definition_from_dir(
|
defs.encoded_token = ethereum.token_definition_from_dir(
|
||||||
@ -210,7 +211,7 @@ def _get_ethereum_definitions(
|
|||||||
elif download_definitions:
|
elif download_definitions:
|
||||||
if chain_id is not None or slip44_hardened is not None:
|
if chain_id is not None or slip44_hardened is not None:
|
||||||
defs.encoded_network = ethereum.download_network_definition(
|
defs.encoded_network = ethereum.download_network_definition(
|
||||||
chain_id, slip44_hardened
|
chain_id, UH_(slip44_hardened) # type: ignore [Argument of type "int | None" cannot be assigned to parameter "x" of type "int" in function "UH_"]
|
||||||
)
|
)
|
||||||
if chain_id is not None and token_address is not None:
|
if chain_id is not None and token_address is not None:
|
||||||
defs.encoded_token = ethereum.download_token_definition(
|
defs.encoded_token = ethereum.download_token_definition(
|
||||||
|
@ -21,7 +21,7 @@ from typing import TYPE_CHECKING, Any, AnyStr, Dict, List, Optional, Tuple
|
|||||||
import requests
|
import requests
|
||||||
|
|
||||||
from . import exceptions, messages
|
from . import exceptions, messages
|
||||||
from .tools import UH_, expect, prepare_message_bytes, session
|
from .tools import expect, prepare_message_bytes, session
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from .client import TrezorClient
|
from .client import TrezorClient
|
||||||
@ -162,11 +162,11 @@ def download_from_url(url: str, error_msg: str = "") -> bytes:
|
|||||||
|
|
||||||
|
|
||||||
def download_network_definition(
|
def download_network_definition(
|
||||||
chain_id: Optional[int] = None, slip44_hardened: Optional[int] = None
|
chain_id: Optional[int] = None, slip44: Optional[int] = None
|
||||||
) -> Optional[bytes]:
|
) -> Optional[bytes]:
|
||||||
if not ((chain_id is None) != (slip44_hardened is None)): # not XOR
|
if not ((chain_id is None) != (slip44 is None)): # not XOR
|
||||||
raise RuntimeError(
|
raise RuntimeError(
|
||||||
"Exactly one of chain_id or slip44_hardened parameters are needed to load network definition from directory."
|
"Exactly one of chain_id or slip44 parameters are needed to load network definition from directory."
|
||||||
)
|
)
|
||||||
|
|
||||||
if chain_id is not None:
|
if chain_id is not None:
|
||||||
@ -178,7 +178,7 @@ def download_network_definition(
|
|||||||
else:
|
else:
|
||||||
url = DEFS_BASE_URL.format(
|
url = DEFS_BASE_URL.format(
|
||||||
lookup_type=DEFS_NETWORK_BY_SLIP44_LOOKUP_TYPE,
|
lookup_type=DEFS_NETWORK_BY_SLIP44_LOOKUP_TYPE,
|
||||||
id=UH_(slip44_hardened), # type: ignore [Argument of type "int | None" cannot be assigned to parameter "x" of type "int" in function "UH_"]
|
id=slip44,
|
||||||
name=DEFS_NETWORK_URI_NAME,
|
name=DEFS_NETWORK_URI_NAME,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -207,11 +207,11 @@ def download_token_definition(
|
|||||||
def network_definition_from_dir(
|
def network_definition_from_dir(
|
||||||
path: pathlib.Path,
|
path: pathlib.Path,
|
||||||
chain_id: Optional[int] = None,
|
chain_id: Optional[int] = None,
|
||||||
slip44_hardened: Optional[int] = None,
|
slip44: Optional[int] = None,
|
||||||
) -> Optional[bytes]:
|
) -> Optional[bytes]:
|
||||||
if not ((chain_id is None) != (slip44_hardened is None)): # not XOR
|
if not ((chain_id is None) != (slip44 is None)): # not XOR
|
||||||
raise RuntimeError(
|
raise RuntimeError(
|
||||||
"Exactly one of chain_id or slip44_hardened parameters are needed to load network definition from directory."
|
"Exactly one of chain_id or slip44 parameters are needed to load network definition from directory."
|
||||||
)
|
)
|
||||||
|
|
||||||
def read_definition(path: pathlib.Path) -> Optional[bytes]:
|
def read_definition(path: pathlib.Path) -> Optional[bytes]:
|
||||||
@ -232,7 +232,7 @@ def network_definition_from_dir(
|
|||||||
return read_definition(
|
return read_definition(
|
||||||
path
|
path
|
||||||
/ DEFS_NETWORK_BY_SLIP44_LOOKUP_TYPE
|
/ DEFS_NETWORK_BY_SLIP44_LOOKUP_TYPE
|
||||||
/ str(UH_(slip44_hardened)) # type: ignore [Argument of type "int | None" cannot be assigned to parameter "x" of type "int" in function "UH_"]
|
/ str(slip44)
|
||||||
/ (DEFS_NETWORK_URI_NAME + ".dat")
|
/ (DEFS_NETWORK_URI_NAME + ".dat")
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -247,6 +247,9 @@ def token_definition_from_dir(
|
|||||||
"Both chain_id and token_address parameters are needed to load token definition from directory."
|
"Both chain_id and token_address parameters are needed to load token definition from directory."
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if token_address is not None and token_address.startswith("0x"):
|
||||||
|
token_address = token_address[2:]
|
||||||
|
|
||||||
path = (
|
path = (
|
||||||
path
|
path
|
||||||
/ DEFS_NETWORK_BY_CHAINID_LOOKUP_TYPE
|
/ DEFS_NETWORK_BY_CHAINID_LOOKUP_TYPE
|
||||||
|
@ -20,12 +20,21 @@ from trezorlib import ethereum
|
|||||||
from trezorlib.debuglink import TrezorClientDebugLink as Client
|
from trezorlib.debuglink import TrezorClientDebugLink as Client
|
||||||
from trezorlib.tools import parse_path
|
from trezorlib.tools import parse_path
|
||||||
|
|
||||||
from ...common import parametrize_using_common_fixtures
|
from ...common import COMMON_FIXTURES_DIR, parametrize_using_common_fixtures
|
||||||
|
|
||||||
pytestmark = [pytest.mark.altcoin, pytest.mark.ethereum]
|
pytestmark = [pytest.mark.altcoin, pytest.mark.ethereum]
|
||||||
|
|
||||||
|
|
||||||
@parametrize_using_common_fixtures("ethereum/getaddress.json")
|
@parametrize_using_common_fixtures("ethereum/getaddress.json")
|
||||||
def test_getaddress(client: Client, parameters, result):
|
def test_getaddress(client: Client, parameters, result):
|
||||||
|
encoded_network = None
|
||||||
|
if not parameters.get("builtin_network", True):
|
||||||
|
encoded_network = ethereum.network_definition_from_dir(
|
||||||
|
path=COMMON_FIXTURES_DIR / "ethereum" / "definitions-latest",
|
||||||
|
slip44=parameters["slip44"],
|
||||||
|
)
|
||||||
address_n = parse_path(parameters["path"])
|
address_n = parse_path(parameters["path"])
|
||||||
assert ethereum.get_address(client, address_n) == result["address"]
|
assert (
|
||||||
|
ethereum.get_address(client, address_n, encoded_network=encoded_network)
|
||||||
|
== result["address"]
|
||||||
|
)
|
||||||
|
@ -14,6 +14,8 @@
|
|||||||
# You should have received a copy of the License along with this library.
|
# 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>.
|
# If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
|
||||||
|
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from trezorlib import ethereum, exceptions, messages
|
from trezorlib import ethereum, exceptions, messages
|
||||||
@ -21,7 +23,7 @@ from trezorlib.debuglink import TrezorClientDebugLink as Client, message_filters
|
|||||||
from trezorlib.exceptions import TrezorFailure
|
from trezorlib.exceptions import TrezorFailure
|
||||||
from trezorlib.tools import parse_path
|
from trezorlib.tools import parse_path
|
||||||
|
|
||||||
from ...common import parametrize_using_common_fixtures
|
from ...common import COMMON_FIXTURES_DIR, parametrize_using_common_fixtures
|
||||||
|
|
||||||
TO_ADDR = "0x1d1c328764a41bda0492b66baa30c4a339ff85ef"
|
TO_ADDR = "0x1d1c328764a41bda0492b66baa30c4a339ff85ef"
|
||||||
SHOW_ALL = (143, 167)
|
SHOW_ALL = (143, 167)
|
||||||
@ -30,6 +32,31 @@ GO_BACK = (16, 220)
|
|||||||
pytestmark = [pytest.mark.altcoin, pytest.mark.ethereum]
|
pytestmark = [pytest.mark.altcoin, pytest.mark.ethereum]
|
||||||
|
|
||||||
|
|
||||||
|
def get_EthereumEncodedDefinitions(
|
||||||
|
parameters: dict,
|
||||||
|
) -> Optional[messages.EthereumEncodedDefinitions]:
|
||||||
|
encoded_network = None
|
||||||
|
encoded_token = None
|
||||||
|
if not parameters.get("builtin_network", True):
|
||||||
|
encoded_network = ethereum.network_definition_from_dir(
|
||||||
|
path=COMMON_FIXTURES_DIR / "ethereum" / "definitions-latest",
|
||||||
|
chain_id=parameters["chain_id"],
|
||||||
|
)
|
||||||
|
if not parameters.get("builtin_token", True):
|
||||||
|
encoded_token = ethereum.token_definition_from_dir(
|
||||||
|
path=COMMON_FIXTURES_DIR / "ethereum" / "definitions-latest",
|
||||||
|
chain_id=parameters["chain_id"],
|
||||||
|
token_address=parameters["to_address"],
|
||||||
|
)
|
||||||
|
|
||||||
|
if encoded_network is not None or encoded_token is not None:
|
||||||
|
return messages.EthereumEncodedDefinitions(
|
||||||
|
encoded_network=encoded_network, encoded_token=encoded_token
|
||||||
|
)
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
@parametrize_using_common_fixtures(
|
@parametrize_using_common_fixtures(
|
||||||
"ethereum/sign_tx.json",
|
"ethereum/sign_tx.json",
|
||||||
"ethereum/sign_tx_eip155.json",
|
"ethereum/sign_tx_eip155.json",
|
||||||
@ -47,6 +74,7 @@ def test_signtx(client: Client, parameters, result):
|
|||||||
value=int(parameters["value"], 16),
|
value=int(parameters["value"], 16),
|
||||||
tx_type=parameters["tx_type"],
|
tx_type=parameters["tx_type"],
|
||||||
data=bytes.fromhex(parameters["data"]),
|
data=bytes.fromhex(parameters["data"]),
|
||||||
|
definitions=get_EthereumEncodedDefinitions(parameters),
|
||||||
)
|
)
|
||||||
|
|
||||||
expected_v = 2 * parameters["chain_id"] + 35
|
expected_v = 2 * parameters["chain_id"] + 35
|
||||||
@ -70,6 +98,7 @@ def test_signtx_eip1559(client: Client, parameters, result):
|
|||||||
chain_id=parameters["chain_id"],
|
chain_id=parameters["chain_id"],
|
||||||
value=int(parameters["value"], 16),
|
value=int(parameters["value"], 16),
|
||||||
data=bytes.fromhex(parameters["data"]),
|
data=bytes.fromhex(parameters["data"]),
|
||||||
|
definitions=get_EthereumEncodedDefinitions(parameters),
|
||||||
)
|
)
|
||||||
|
|
||||||
assert sig_r.hex() == result["sig_r"]
|
assert sig_r.hex() == result["sig_r"]
|
||||||
|
Loading…
Reference in New Issue
Block a user