2020-08-28 19:12:25 +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
|
|
|
|
|
2021-07-23 10:14:29 +00:00
|
|
|
from trezorlib.cardano import (
|
|
|
|
create_address_parameters,
|
|
|
|
get_address,
|
|
|
|
get_public_key,
|
|
|
|
parse_optional_bytes,
|
|
|
|
)
|
2022-01-31 12:25:30 +00:00
|
|
|
from trezorlib.debuglink import TrezorClientDebugLink as Client
|
2021-10-22 14:05:33 +00:00
|
|
|
from trezorlib.messages import CardanoAddressType, CardanoDerivationType
|
2020-08-28 19:12:25 +00:00
|
|
|
from trezorlib.tools import parse_path
|
|
|
|
|
|
|
|
from ...common import parametrize_using_common_fixtures
|
2023-07-26 14:47:01 +00:00
|
|
|
from ...input_flows import InputFlowShowXpubQRCode
|
2020-08-28 19:12:25 +00:00
|
|
|
|
|
|
|
pytestmark = [
|
|
|
|
pytest.mark.altcoin,
|
|
|
|
pytest.mark.cardano,
|
2024-03-11 15:20:08 +00:00
|
|
|
pytest.mark.skip_t1b1,
|
2020-08-28 19:12:25 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
@parametrize_using_common_fixtures(
|
|
|
|
"cardano/get_address_byron.json",
|
|
|
|
"cardano/get_address_byron.slip39.json",
|
|
|
|
"cardano/get_base_address.json",
|
|
|
|
"cardano/get_base_address_with_staking_key_hash.json",
|
2021-07-23 10:14:29 +00:00
|
|
|
"cardano/get_base_address_with_script_hashes.json",
|
2020-08-28 19:12:25 +00:00
|
|
|
"cardano/get_enterprise_address.json",
|
|
|
|
"cardano/get_pointer_address.json",
|
|
|
|
"cardano/get_reward_address.json",
|
2021-10-22 14:05:33 +00:00
|
|
|
"cardano/get_base_address.derivations.json",
|
2020-08-28 19:12:25 +00:00
|
|
|
)
|
2023-09-14 10:22:18 +00:00
|
|
|
@pytest.mark.parametrize("chunkify", (True, False))
|
|
|
|
def test_cardano_get_address(client: Client, chunkify: bool, parameters, result):
|
2021-10-20 11:16:58 +00:00
|
|
|
client.init_device(new_session=True, derive_cardano=True)
|
|
|
|
|
2021-10-22 14:05:33 +00:00
|
|
|
derivation_type = CardanoDerivationType.__members__[
|
|
|
|
parameters.get("derivation_type", "ICARUS_TREZOR")
|
|
|
|
]
|
|
|
|
|
2020-08-28 19:12:25 +00:00
|
|
|
address = get_address(
|
|
|
|
client,
|
|
|
|
address_parameters=create_address_parameters(
|
|
|
|
address_type=getattr(
|
|
|
|
CardanoAddressType, parameters["address_type"].upper()
|
|
|
|
),
|
2024-02-28 14:11:47 +00:00
|
|
|
address_n=(
|
|
|
|
parse_path(parameters.get("path")) if "path" in parameters else None
|
|
|
|
),
|
|
|
|
address_n_staking=(
|
|
|
|
parse_path(parameters.get("staking_path"))
|
|
|
|
if "staking_path" in parameters
|
|
|
|
else None
|
|
|
|
),
|
2021-07-23 10:14:29 +00:00
|
|
|
staking_key_hash=parse_optional_bytes(parameters.get("staking_key_hash")),
|
2020-08-28 19:12:25 +00:00
|
|
|
block_index=parameters.get("block_index"),
|
|
|
|
tx_index=parameters.get("tx_index"),
|
|
|
|
certificate_index=parameters.get("certificate_index"),
|
2021-07-23 10:14:29 +00:00
|
|
|
script_payment_hash=parse_optional_bytes(
|
|
|
|
parameters.get("script_payment_hash")
|
|
|
|
),
|
|
|
|
script_staking_hash=parse_optional_bytes(
|
|
|
|
parameters.get("script_staking_hash")
|
|
|
|
),
|
2020-08-28 19:12:25 +00:00
|
|
|
),
|
|
|
|
protocol_magic=parameters["protocol_magic"],
|
|
|
|
network_id=parameters["network_id"],
|
2021-03-03 22:12:53 +00:00
|
|
|
show_display=True,
|
2021-10-22 14:05:33 +00:00
|
|
|
derivation_type=derivation_type,
|
2023-09-14 10:22:18 +00:00
|
|
|
chunkify=chunkify,
|
2020-08-28 19:12:25 +00:00
|
|
|
)
|
|
|
|
assert address == result["expected_address"]
|
|
|
|
|
|
|
|
|
|
|
|
@parametrize_using_common_fixtures(
|
2021-10-20 11:16:58 +00:00
|
|
|
"cardano/get_public_key.json",
|
|
|
|
"cardano/get_public_key.slip39.json",
|
2021-10-22 14:05:33 +00:00
|
|
|
"cardano/get_public_key.derivations.json",
|
2020-08-28 19:12:25 +00:00
|
|
|
)
|
2022-01-31 12:25:30 +00:00
|
|
|
def test_cardano_get_public_key(client: Client, parameters, result):
|
2023-07-26 14:47:01 +00:00
|
|
|
with client:
|
|
|
|
IF = InputFlowShowXpubQRCode(client, passphrase=bool(client.ui.passphrase))
|
|
|
|
client.set_input_flow(IF.get())
|
|
|
|
client.init_device(new_session=True, derive_cardano=True)
|
2021-10-20 11:16:58 +00:00
|
|
|
|
2023-07-26 14:47:01 +00:00
|
|
|
derivation_type = CardanoDerivationType.__members__[
|
|
|
|
parameters.get("derivation_type", "ICARUS_TREZOR")
|
|
|
|
]
|
|
|
|
key = get_public_key(
|
|
|
|
client, parse_path(parameters["path"]), derivation_type, show_display=True
|
|
|
|
)
|
2020-08-28 19:12:25 +00:00
|
|
|
|
2023-07-26 14:47:01 +00:00
|
|
|
assert key.node.public_key.hex() == result["public_key"]
|
|
|
|
assert key.node.chain_code.hex() == result["chain_code"]
|
|
|
|
assert key.xpub == result["public_key"] + result["chain_code"]
|