1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-24 23:38:09 +00:00

chore(cardano): improve get_native_script_hash tests and update ui fixtures

This commit is contained in:
gabrielkerekes 2021-10-08 08:15:49 +02:00 committed by matejcik
parent 4aaf6db9a2
commit b957dfbddb
3 changed files with 278 additions and 211 deletions

View File

@ -7,8 +7,11 @@
{ {
"description": "PUB_KEY script", "description": "PUB_KEY script",
"parameters": { "parameters": {
"type": 0, "display_format": "BECH32",
"key_hash": "c4b9265645fde9536c0795adbcc5291767a0c61fd62448341d7e0386" "native_script": {
"type": 0,
"key_hash": "c4b9265645fde9536c0795adbcc5291767a0c61fd62448341d7e0386"
}
}, },
"result": { "result": {
"expected_hash": "29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd" "expected_hash": "29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd"
@ -17,8 +20,11 @@
{ {
"description": "PUB_KEY script containing a path", "description": "PUB_KEY script containing a path",
"parameters": { "parameters": {
"type": 0, "display_format": "BECH32",
"key_path": "m/1854'/1815'/0'/0/0" "native_script": {
"type": 0,
"key_path": "m/1854'/1815'/0'/0/0"
}
}, },
"result": { "result": {
"expected_hash": "29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd" "expected_hash": "29fb5fd4aa8cadd6705acc8263cee0fc62edca5ac38db593fec2f9fd"
@ -27,17 +33,20 @@
{ {
"description": "ALL script", "description": "ALL script",
"parameters": { "parameters": {
"type": 1, "display_format": "BECH32",
"scripts": [ "native_script": {
{ "type": 1,
"type": 0, "scripts": [
"key_hash": "c4b9265645fde9536c0795adbcc5291767a0c61fd62448341d7e0386" {
}, "type": 0,
{ "key_hash": "c4b9265645fde9536c0795adbcc5291767a0c61fd62448341d7e0386"
"type": 0, },
"key_hash": "0241f2d196f52a92fbd2183d03b370c30b6960cfdeae364ffabac889" {
} "type": 0,
] "key_hash": "0241f2d196f52a92fbd2183d03b370c30b6960cfdeae364ffabac889"
}
]
}
}, },
"result": { "result": {
"expected_hash": "af5c2ce476a6ede1c879f7b1909d6a0b96cb2081391712d4a355cef6" "expected_hash": "af5c2ce476a6ede1c879f7b1909d6a0b96cb2081391712d4a355cef6"
@ -46,17 +55,20 @@
{ {
"description": "ALL script containing a path", "description": "ALL script containing a path",
"parameters": { "parameters": {
"type": 1, "display_format": "BECH32",
"scripts": [ "native_script": {
{ "type": 1,
"type": 0, "scripts": [
"key_path": "m/1854'/1815'/0'/0/0" {
}, "type": 0,
{ "key_path": "m/1854'/1815'/0'/0/0"
"type": 0, },
"key_hash": "0241f2d196f52a92fbd2183d03b370c30b6960cfdeae364ffabac889" {
} "type": 0,
] "key_hash": "0241f2d196f52a92fbd2183d03b370c30b6960cfdeae364ffabac889"
}
]
}
}, },
"result": { "result": {
"expected_hash": "af5c2ce476a6ede1c879f7b1909d6a0b96cb2081391712d4a355cef6" "expected_hash": "af5c2ce476a6ede1c879f7b1909d6a0b96cb2081391712d4a355cef6"
@ -65,17 +77,20 @@
{ {
"description": "ALL script containing a 1855 path", "description": "ALL script containing a 1855 path",
"parameters": { "parameters": {
"type": 1, "display_format": "POLICY_ID",
"scripts": [ "native_script": {
{ "type": 1,
"type": 0, "scripts": [
"key_path": "m/1855'/1815'/0'" {
}, "type": 0,
{ "key_path": "m/1855'/1815'/0'"
"type": 0, },
"key_hash": "0241f2d196f52a92fbd2183d03b370c30b6960cfdeae364ffabac889" {
} "type": 0,
] "key_hash": "0241f2d196f52a92fbd2183d03b370c30b6960cfdeae364ffabac889"
}
]
}
}, },
"result": { "result": {
"expected_hash": "fbf6672eb655c29b0f148fa1429be57c2174b067a7b3e3942e967fe8" "expected_hash": "fbf6672eb655c29b0f148fa1429be57c2174b067a7b3e3942e967fe8"
@ -84,17 +99,20 @@
{ {
"description": "ANY script", "description": "ANY script",
"parameters": { "parameters": {
"type": 2, "display_format": "BECH32",
"scripts": [ "native_script": {
{ "type": 2,
"type": 0, "scripts": [
"key_hash": "c4b9265645fde9536c0795adbcc5291767a0c61fd62448341d7e0386" {
}, "type": 0,
{ "key_hash": "c4b9265645fde9536c0795adbcc5291767a0c61fd62448341d7e0386"
"type": 0, },
"key_hash": "0241f2d196f52a92fbd2183d03b370c30b6960cfdeae364ffabac889" {
} "type": 0,
] "key_hash": "0241f2d196f52a92fbd2183d03b370c30b6960cfdeae364ffabac889"
}
]
}
}, },
"result": { "result": {
"expected_hash": "d6428ec36719146b7b5fb3a2d5322ce702d32762b8c7eeeb797a20db" "expected_hash": "d6428ec36719146b7b5fb3a2d5322ce702d32762b8c7eeeb797a20db"
@ -103,17 +121,20 @@
{ {
"description": "ANY script with a nested script containing a path", "description": "ANY script with a nested script containing a path",
"parameters": { "parameters": {
"type": 2, "display_format": "BECH32",
"scripts": [ "native_script": {
{ "type": 2,
"type": 0, "scripts": [
"key_path": "m/1854'/1815'/0'/0/0" {
}, "type": 0,
{ "key_path": "m/1854'/1815'/0'/0/0"
"type": 0, },
"key_hash": "0241f2d196f52a92fbd2183d03b370c30b6960cfdeae364ffabac889" {
} "type": 0,
] "key_hash": "0241f2d196f52a92fbd2183d03b370c30b6960cfdeae364ffabac889"
}
]
}
}, },
"result": { "result": {
"expected_hash": "d6428ec36719146b7b5fb3a2d5322ce702d32762b8c7eeeb797a20db" "expected_hash": "d6428ec36719146b7b5fb3a2d5322ce702d32762b8c7eeeb797a20db"
@ -122,22 +143,25 @@
{ {
"description": "N_OF_K script", "description": "N_OF_K script",
"parameters": { "parameters": {
"type": 3, "display_format": "BECH32",
"required_signatures_count": 2, "native_script": {
"scripts": [ "type": 3,
{ "required_signatures_count": 2,
"type": 0, "scripts": [
"key_hash": "c4b9265645fde9536c0795adbcc5291767a0c61fd62448341d7e0386" {
}, "type": 0,
{ "key_hash": "c4b9265645fde9536c0795adbcc5291767a0c61fd62448341d7e0386"
"type": 0, },
"key_hash": "0241f2d196f52a92fbd2183d03b370c30b6960cfdeae364ffabac889" {
}, "type": 0,
{ "key_hash": "0241f2d196f52a92fbd2183d03b370c30b6960cfdeae364ffabac889"
"type": 0, },
"key_hash": "cecb1d427c4ae436d28cc0f8ae9bb37501a5b77bcc64cd1693e9ae20" {
} "type": 0,
] "key_hash": "cecb1d427c4ae436d28cc0f8ae9bb37501a5b77bcc64cd1693e9ae20"
}
]
}
}, },
"result": { "result": {
"expected_hash": "2b2b17fd18e18acae4601d4818a1dee00a917ff72e772fa8482e36c9" "expected_hash": "2b2b17fd18e18acae4601d4818a1dee00a917ff72e772fa8482e36c9"
@ -146,22 +170,25 @@
{ {
"description": "N_OF_K script containing a path", "description": "N_OF_K script containing a path",
"parameters": { "parameters": {
"type": 3, "display_format": "BECH32",
"required_signatures_count": 2, "native_script": {
"scripts": [ "type": 3,
{ "required_signatures_count": 2,
"type": 0, "scripts": [
"key_path": "m/1854'/1815'/0'/0/0" {
}, "type": 0,
{ "key_path": "m/1854'/1815'/0'/0/0"
"type": 0, },
"key_hash": "0241f2d196f52a92fbd2183d03b370c30b6960cfdeae364ffabac889" {
}, "type": 0,
{ "key_hash": "0241f2d196f52a92fbd2183d03b370c30b6960cfdeae364ffabac889"
"type": 0, },
"key_hash": "cecb1d427c4ae436d28cc0f8ae9bb37501a5b77bcc64cd1693e9ae20" {
} "type": 0,
] "key_hash": "cecb1d427c4ae436d28cc0f8ae9bb37501a5b77bcc64cd1693e9ae20"
}
]
}
}, },
"result": { "result": {
"expected_hash": "2b2b17fd18e18acae4601d4818a1dee00a917ff72e772fa8482e36c9" "expected_hash": "2b2b17fd18e18acae4601d4818a1dee00a917ff72e772fa8482e36c9"
@ -170,17 +197,20 @@
{ {
"description": "INVALID_BEFORE script", "description": "INVALID_BEFORE script",
"parameters": { "parameters": {
"type": 1, "display_format": "BECH32",
"scripts": [ "native_script": {
{ "type": 1,
"type": 0, "scripts": [
"key_hash": "c4b9265645fde9536c0795adbcc5291767a0c61fd62448341d7e0386" {
}, "type": 0,
{ "key_hash": "c4b9265645fde9536c0795adbcc5291767a0c61fd62448341d7e0386"
"type": 4, },
"invalid_before": 100 {
} "type": 4,
] "invalid_before": 100
}
]
}
}, },
"result": { "result": {
"expected_hash": "c6262ef9bb2b1291c058d93b46dabf458e2d135f803f60713f84b0b7" "expected_hash": "c6262ef9bb2b1291c058d93b46dabf458e2d135f803f60713f84b0b7"
@ -189,17 +219,20 @@
{ {
"description": "INVALID_HEREAFTER script", "description": "INVALID_HEREAFTER script",
"parameters": { "parameters": {
"type": 1, "display_format": "BECH32",
"scripts": [ "native_script": {
{ "type": 1,
"type": 0, "scripts": [
"key_hash": "c4b9265645fde9536c0795adbcc5291767a0c61fd62448341d7e0386" {
}, "type": 0,
{ "key_hash": "c4b9265645fde9536c0795adbcc5291767a0c61fd62448341d7e0386"
"type": 5, },
"invalid_hereafter": 200 {
} "type": 5,
] "invalid_hereafter": 200
}
]
}
}, },
"result": { "result": {
"expected_hash": "b12ac304f89f4cd4d23f59a2b90d2b2697f7540b8f470d6aa05851b5" "expected_hash": "b12ac304f89f4cd4d23f59a2b90d2b2697f7540b8f470d6aa05851b5"
@ -208,56 +241,59 @@
{ {
"description": "Nested script", "description": "Nested script",
"parameters": { "parameters": {
"type": 1, "display_format": "BECH32",
"scripts": [ "native_script": {
{ "type": 1,
"type": 0, "scripts": [
"key_hash": "c4b9265645fde9536c0795adbcc5291767a0c61fd62448341d7e0386" {
}, "type": 0,
{ "key_hash": "c4b9265645fde9536c0795adbcc5291767a0c61fd62448341d7e0386"
"type": 0, },
"key_path": "m/1854'/1815'/0'/0/0" {
}, "type": 0,
{ "key_path": "m/1854'/1815'/0'/0/0"
"type": 2, },
"scripts": [ {
{ "type": 2,
"type": 0, "scripts": [
"key_path": "m/1854'/1815'/0'/0/0" {
}, "type": 0,
{ "key_path": "m/1854'/1815'/0'/0/0"
"type": 0, },
"key_hash": "0241f2d196f52a92fbd2183d03b370c30b6960cfdeae364ffabac889" {
} "type": 0,
] "key_hash": "0241f2d196f52a92fbd2183d03b370c30b6960cfdeae364ffabac889"
}, }
{ ]
"type": 3, },
"required_signatures_count": 2, {
"scripts": [ "type": 3,
{ "required_signatures_count": 2,
"type": 0, "scripts": [
"key_path": "m/1854'/1815'/0'/0/0" {
}, "type": 0,
{ "key_path": "m/1854'/1815'/0'/0/0"
"type": 0, },
"key_hash": "0241f2d196f52a92fbd2183d03b370c30b6960cfdeae364ffabac889" {
}, "type": 0,
{ "key_hash": "0241f2d196f52a92fbd2183d03b370c30b6960cfdeae364ffabac889"
"type": 0, },
"key_hash": "cecb1d427c4ae436d28cc0f8ae9bb37501a5b77bcc64cd1693e9ae20" {
} "type": 0,
] "key_hash": "cecb1d427c4ae436d28cc0f8ae9bb37501a5b77bcc64cd1693e9ae20"
}, }
{ ]
"type": 4, },
"invalid_before": 100 {
}, "type": 4,
{ "invalid_before": 100
"type": 5, },
"invalid_hereafter": 200 {
} "type": 5,
] "invalid_hereafter": 200
}
]
}
}, },
"result": { "result": {
"expected_hash": "4a6b4288459bf34668c0b281f922691460caf0c7c09caee3a726c27a" "expected_hash": "4a6b4288459bf34668c0b281f922691460caf0c7c09caee3a726c27a"
@ -266,52 +302,55 @@
{ {
"description": "Nested script without paths and shared with Ledger", "description": "Nested script without paths and shared with Ledger",
"parameters": { "parameters": {
"type": 1, "display_format": "BECH32",
"scripts": [ "native_script": {
{ "type": 1,
"type": 0, "scripts": [
"key_hash": "c4b9265645fde9536c0795adbcc5291767a0c61fd62448341d7e0386" {
}, "type": 0,
{ "key_hash": "c4b9265645fde9536c0795adbcc5291767a0c61fd62448341d7e0386"
"type": 2, },
"scripts": [ {
{ "type": 2,
"type": 0, "scripts": [
"key_hash": "c4b9265645fde9536c0795adbcc5291767a0c61fd62448341d7e0386" {
}, "type": 0,
{ "key_hash": "c4b9265645fde9536c0795adbcc5291767a0c61fd62448341d7e0386"
"type": 0, },
"key_hash": "0241f2d196f52a92fbd2183d03b370c30b6960cfdeae364ffabac889" {
} "type": 0,
] "key_hash": "0241f2d196f52a92fbd2183d03b370c30b6960cfdeae364ffabac889"
}, }
{ ]
"type": 3, },
"required_signatures_count": 2, {
"scripts": [ "type": 3,
{ "required_signatures_count": 2,
"type": 0, "scripts": [
"key_hash": "c4b9265645fde9536c0795adbcc5291767a0c61fd62448341d7e0386" {
}, "type": 0,
{ "key_hash": "c4b9265645fde9536c0795adbcc5291767a0c61fd62448341d7e0386"
"type": 0, },
"key_hash": "0241f2d196f52a92fbd2183d03b370c30b6960cfdeae364ffabac889" {
}, "type": 0,
{ "key_hash": "0241f2d196f52a92fbd2183d03b370c30b6960cfdeae364ffabac889"
"type": 0, },
"key_hash": "cecb1d427c4ae436d28cc0f8ae9bb37501a5b77bcc64cd1693e9ae20" {
} "type": 0,
] "key_hash": "cecb1d427c4ae436d28cc0f8ae9bb37501a5b77bcc64cd1693e9ae20"
}, }
{ ]
"type": 4, },
"invalid_before": 100 {
}, "type": 4,
{ "invalid_before": 100
"type": 5, },
"invalid_hereafter": 200 {
} "type": 5,
] "invalid_hereafter": 200
}
]
}
}, },
"result": { "result": {
"expected_hash": "0d63e8d2c5a00cbcffbdf9112487c443466e1ea7d8c834df5ac5c425" "expected_hash": "0d63e8d2c5a00cbcffbdf9112487c443466e1ea7d8c834df5ac5c425"

View File

@ -14,15 +14,30 @@
# 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>.
import pytest
from trezorlib import messages
from trezorlib.cardano import get_native_script_hash, parse_native_script from trezorlib.cardano import get_native_script_hash, parse_native_script
from ...common import parametrize_using_common_fixtures from ...common import parametrize_using_common_fixtures
pytestmark = [
pytest.mark.altcoin,
pytest.mark.cardano,
pytest.mark.skip_t1,
]
@parametrize_using_common_fixtures( @parametrize_using_common_fixtures(
"cardano/get_native_script_hash.json", "cardano/get_native_script_hash.json",
) )
def test_cardano_get_native_script_hash(client, parameters, result): def test_cardano_get_native_script_hash(client, parameters, result):
native_script = parse_native_script(parameters) native_script_hash = get_native_script_hash(
native_script_hash = get_native_script_hash(client, native_script).script_hash client,
native_script=parse_native_script(parameters["native_script"]),
display_format=messages.CardanoNativeScriptHashDisplayFormat.__members__[
parameters["display_format"]
],
).script_hash
assert native_script_hash.hex() == result["expected_hash"] assert native_script_hash.hex() == result["expected_hash"]

View File

@ -53,6 +53,19 @@
"cardano-test_address_public_key.py::test_cardano_get_public_key[parameters7-result7]": "095af81ec79e9b510c90d9fa34fed343f3840807190c67bc237af885695ae687", "cardano-test_address_public_key.py::test_cardano_get_public_key[parameters7-result7]": "095af81ec79e9b510c90d9fa34fed343f3840807190c67bc237af885695ae687",
"cardano-test_address_public_key.py::test_cardano_get_public_key[parameters8-result8]": "095af81ec79e9b510c90d9fa34fed343f3840807190c67bc237af885695ae687", "cardano-test_address_public_key.py::test_cardano_get_public_key[parameters8-result8]": "095af81ec79e9b510c90d9fa34fed343f3840807190c67bc237af885695ae687",
"cardano-test_address_public_key.py::test_cardano_get_public_key[parameters9-result9]": "095af81ec79e9b510c90d9fa34fed343f3840807190c67bc237af885695ae687", "cardano-test_address_public_key.py::test_cardano_get_public_key[parameters9-result9]": "095af81ec79e9b510c90d9fa34fed343f3840807190c67bc237af885695ae687",
"cardano-test_get_native_script_hash.py::test_cardano_get_native_script_hash[all_script]": "96dfeb79b33a0b49b761fbd694423e57567ee932da5e75514315159aaad3288b",
"cardano-test_get_native_script_hash.py::test_cardano_get_native_script_hash[all_script_cont-aae1e6c3": "aef99839b7f2706cfb76aed84bfb862647bdd6d0013326aad1fc90d704c98e9e",
"cardano-test_get_native_script_hash.py::test_cardano_get_native_script_hash[all_script_cont-e4ca0ea5": "c488d5e29487e9a75f2146694c11699af6c2c2893f03773434996386f01469ea",
"cardano-test_get_native_script_hash.py::test_cardano_get_native_script_hash[any_script]": "b3ec7695819326137b13443a8580948bde63450c916b554e43097ecbec2f6c9e",
"cardano-test_get_native_script_hash.py::test_cardano_get_native_script_hash[any_script_with-f2466a2e": "6341544281f769b31b22e8a0eab2c46f1006674f7ce4c38230632e53bab07614",
"cardano-test_get_native_script_hash.py::test_cardano_get_native_script_hash[invalid_before_script]": "52da05359fa87e6460c65d6abfc1b8d1a5b8aaaa3e5c9d3dfebe3a73f4441212",
"cardano-test_get_native_script_hash.py::test_cardano_get_native_script_hash[invalid_hereaft-d01d7292": "48f7bdd8fc238eca516d0991f8810e10360a4b0eee0ce110dc5156c786afa294",
"cardano-test_get_native_script_hash.py::test_cardano_get_native_script_hash[n_of_k_script]": "b0205e442793afbcc32354812533afd2d041f5375b0e531ef1a8331a651112c2",
"cardano-test_get_native_script_hash.py::test_cardano_get_native_script_hash[n_of_k_script_c-d93f5fb0": "38c79c1ef3fcada5f375b501b591c11f4c8e5a42162143161f86988cf362b57e",
"cardano-test_get_native_script_hash.py::test_cardano_get_native_script_hash[nested_script]": "65bf0ea7cb4c49dc8dac7ea8a1133370a340e550616148c332fa4562897d5ba2",
"cardano-test_get_native_script_hash.py::test_cardano_get_native_script_hash[nested_script_w-789238e6": "c7f28a6bf21f8a9382fdc068a76f0f5011ef20c3bb443b09ad608183a4336d8e",
"cardano-test_get_native_script_hash.py::test_cardano_get_native_script_hash[pub_key_script]": "191979a434a013c211aba0af707342c2c88efb9414aeaf578b096088c1378bf6",
"cardano-test_get_native_script_hash.py::test_cardano_get_native_script_hash[pub_key_script_-1579fe2a": "9ea8957e0d58d06cb10efe6406ea892e789023fb5ccc5aae6147f0886cb261f5",
"cardano-test_sign_tx.py::test_cardano_sign_tx[byron_to_shelley_transfer]": "db4afddea8a453edd9d3e283387463d1e89dd79f4265bd7648d67b0cbc691b91", "cardano-test_sign_tx.py::test_cardano_sign_tx[byron_to_shelley_transfer]": "db4afddea8a453edd9d3e283387463d1e89dd79f4265bd7648d67b0cbc691b91",
"cardano-test_sign_tx.py::test_cardano_sign_tx[mainnet_transaction_with_change0]": "4cfe4bcfd945876cd8268403b2e89f835793ced525bd35e92e74f188ece4ad01", "cardano-test_sign_tx.py::test_cardano_sign_tx[mainnet_transaction_with_change0]": "4cfe4bcfd945876cd8268403b2e89f835793ced525bd35e92e74f188ece4ad01",
"cardano-test_sign_tx.py::test_cardano_sign_tx[mainnet_transaction_with_change1]": "2a88a1416be6f568ee00f76f65299e8cf127e91ee872df74ef3cc8423d68d5f5", "cardano-test_sign_tx.py::test_cardano_sign_tx[mainnet_transaction_with_change1]": "2a88a1416be6f568ee00f76f65299e8cf127e91ee872df74ef3cc8423d68d5f5",