diff --git a/common/tests/fixtures/cardano/get_address.json b/common/tests/fixtures/cardano/get_address.json new file mode 100644 index 00000000000..4142d13b41d --- /dev/null +++ b/common/tests/fixtures/cardano/get_address.json @@ -0,0 +1,35 @@ +{ + "setup": { + "mnemonic": "alcohol woman abuse must during monitor noble actual mixed trade anger aisle", + "passphrase": false + }, + "tests": [ + { + "parameters": { + "path": "m/44'/1815'/0'/0/0" + }, + "result": { + "success": true, + "expected_address": "Ae2tdPwUPEZLCq3sFv4wVYxwqjMH2nUzBVt1HFr4v87snYrtYq3d3bq2PUQ" + } + }, + { + "parameters":{ + "path": "m/44'/1815'/0'/0/1" + }, + "result": { + "success":true, + "expected_address": "Ae2tdPwUPEZEY6pVJoyuNNdLp7VbMB7U7qfebeJ7XGunk5Z2eHarkcN1bHK" + } + }, + { + "parameters": { + "path": "m/44'/1815'/0'/0/2" + }, + "result": { + "success": true, + "expected_address": "Ae2tdPwUPEZ3gZD1QeUHvAqadAV59Zid6NP9VCR9BG5LLAja9YtBUgr6ttK" + } + } + ] +} diff --git a/common/tests/fixtures/cardano/get_address.slip39.json b/common/tests/fixtures/cardano/get_address.slip39.json new file mode 100644 index 00000000000..c04a6b2cf7b --- /dev/null +++ b/common/tests/fixtures/cardano/get_address.slip39.json @@ -0,0 +1,39 @@ +{ + "setup": { + "mnemonic": [ + "extra extend academic bishop cricket bundle tofu goat apart victim enlarge program behavior permit course armed jerky faint language modern", + "extra extend academic acne away best indicate impact square oasis prospect painting voting guest either argue username racism enemy eclipse", + "extra extend academic arcade born dive legal hush gross briefing talent drug much home firefly toxic analysis idea umbrella slice" + ], + "passphrase": "TREZOR" + }, + "tests": [ + { + "parameters": { + "path": "m/44'/1815'/0'/0/0" + }, + "result":{ + "success":true, + "expected_address": "Ae2tdPwUPEYxF9NAMNdd3v2LZoMeWp7gCZiDb6bZzFQeeVASzoP7HC4V9s6" + } + }, + { + "parameters": { + "path": "m/44'/1815'/0'/0/1" + }, + "result": { + "success": true, + "expected_address": "Ae2tdPwUPEZ1TjYcvfkWAbiHtGVxv4byEHHZoSyQXjPJ362DifCe1ykgqgy" + } + }, + { + "parameters": { + "path": "m/44'/1815'/0'/0/2" + }, + "result": { + "success": true, + "expected_address": "Ae2tdPwUPEZGXmSbda1kBNfyhRQGRcQxJFdk7mhWZXAGnapyejv2b2U3aRb" + } + } + ] +} diff --git a/common/tests/fixtures/cardano/get_public_key.json b/common/tests/fixtures/cardano/get_public_key.json new file mode 100644 index 00000000000..8681f61d658 --- /dev/null +++ b/common/tests/fixtures/cardano/get_public_key.json @@ -0,0 +1,48 @@ +{ + "setup": { + "mnemonic": "all all all all all all all all all all all all", + "passphrase": false + }, + "tests": [ + { + "parameters":{ + "path": "m/44'/1815'/0'" + }, + "result":{ + "success":true, + "public_key": "c0fce1839f1a84c4e770293ac2f5e0875141b29017b7f56ab135352d00ad6966", + "chain_code": "07faa161c9f5464315d2855f70fdf1431d5fa39eb838767bf17b69772137452f" + } + }, + { + "parameters": { + "path": "m/44'/1815'/1'" + }, + "result": { + "success": true, + "public_key": "ea5dde31b9f551e08a5b6b2f98b8c42c726f726c9ce0a7072102ead53bd8f21e", + "chain_code": "70f131bb799fd659c997221ad8cae7dcce4e8da701f8101cf15307fd3a3712a1" + } + }, + { + "parameters": { + "path": "m/44'/1815'/2'" + }, + "result": { + "success": true, + "public_key": "076338cee5ab3dae19f06ccaa80e3d4428cf0e1bdc04243e41bba7be63a90da7", + "chain_code": "5dcdf129f6f2d108292e615c4b67a1fc41a64e6a96130f5c981e5e8e046a6cd7" + } + }, + { + "parameters": { + "path": "m/44'/1815'/3'" + }, + "result": { + "success": true, + "public_key": "5f769380dc6fd17a4e0f2d23aa359442a712e5e96d7838ebb91eb020003cccc3", + "chain_code": "1197ea234f528987cbac9817ebc31344395b837a3bb7c2332f87e095e70550a5" + } + } + ] +} diff --git a/common/tests/fixtures/cardano/get_public_key.slip39.json b/common/tests/fixtures/cardano/get_public_key.slip39.json new file mode 100644 index 00000000000..2d5ff795888 --- /dev/null +++ b/common/tests/fixtures/cardano/get_public_key.slip39.json @@ -0,0 +1,42 @@ +{ + "setup": { + "mnemonic": [ + "extra extend academic bishop cricket bundle tofu goat apart victim enlarge program behavior permit course armed jerky faint language modern", + "extra extend academic acne away best indicate impact square oasis prospect painting voting guest either argue username racism enemy eclipse", + "extra extend academic arcade born dive legal hush gross briefing talent drug much home firefly toxic analysis idea umbrella slice" + ], + "passphrase": "TREZOR" + }, + "tests": [ + { + "parameters": { + "path": "m/44'/1815'/0'/0/0" + }, + "result": { + "success": true, + "public_key": "bc043d84b8b891d49890edb6aced6f2d78395f255c5b6aea8878b913f83e8579", + "chain_code": "dc3f0d2b5cccb822335ef6213fd133f4ca934151ec44a6000aee43b8a101078c" + } + }, + { + "parameters": { + "path": "m/44'/1815'/0'/0/1" + }, + "result": { + "success": true, + "public_key": "24c4fe188a39103db88818bc191fd8571eae7b284ebcbdf2462bde97b058a95c", + "chain_code": "6f7a744035f4b3ddb8f861c18446169643cc3ae85e271b4b4f0eda05cf84c65b" + } + }, + { + "parameters": { + "path": "m/44'/1815'/0'/0/2" + }, + "result": { + "success": true, + "public_key": "831a63d381a8dab1e6e1ee991a4300fc70687aae5f97f4fcf92ed1b6c2bd99de", + "chain_code": "672d6af4707aba201b7940231e83dd357f92f8851b3dfdc224ef311e1b64cdeb" + } + } + ] +} diff --git a/common/tests/fixtures/cardano/sign_tx.failures.json b/common/tests/fixtures/cardano/sign_tx.failures.json new file mode 100644 index 00000000000..474b3b5f405 --- /dev/null +++ b/common/tests/fixtures/cardano/sign_tx.failures.json @@ -0,0 +1,62 @@ +{ + "setup": { + "mnemonic": "all all all all all all all all all all all all", + "passphrase": "" + }, + "tests": [ + { + "description": "Output address is a valid CBOR but invalid Cardano address", + "parameters": { + "protocol_magic": 764824073, + "inputs": [ + { + "path": "m/44'/1815'/0'/0/1", + "prev_hash": "1af8fa0b754ff99253d983894e63a2b09cbb56c833ba18c3384210163f63dcfc", + "prev_index": 0, + "type": 0 + } + ], + "outputs": [ + { + "address": "jsK75PTH2esX8k4Wvxenyz83LJJWToBbVmGrWUer2CHFHanLseh7r3sW5X5q", + "amount": "3003112" + } + ], + "prev_tx": [ + "839f8200d818582482582008abb575fac4c39d5bf80683f7f0c37e48f4e3d96e37d1f6611919a7241b456600ff9f8282d818582183581cda4da43db3fca93695e71dab839e72271204d28b9d964d306b8800a8a0001a7a6916a51a00305becffa0" + ] + }, + "result": { + "success": false, + "error": "Invalid output address!" + } + }, + { + "description": "Output address is invalid CBOR", + "parameters": { + "protocol_magic": 764824073, + "inputs": [ + { + "path": "m/44'/1815'/0'/0/1", + "prev_hash": "1af8fa0b754ff99253d983894e63a2b09cbb56c833ba18c3384210163f63dcfc", + "prev_index": 0, + "type": 0 + } + ], + "outputs": [ + { + "address": "5dnY6xgRcNUSLGa4gfqef2jGAMHb7koQs9EXErXLNC1LiMPUnhn8joXhvEJpWQtN3F4ysATcBvCn5tABgL3e4hPWapPHmcK5GJMSEaET5JafgAGwSrznzL1Mqa", + "amount": "3003112" + } + ], + "prev_tx": [ + "839f8200d818582482582008abb575fac4c39d5bf80683f7f0c37e48f4e3d96e37d1f6611919a7241b456600ff9f8282d818582183581cda4da43db3fca93695e71dab839e72271204d28b9d964d306b8800a8a0001a7a6916a51a00305becffa0" + ] + }, + "result": { + "success": false, + "error": "Invalid output address!" + } + } + ] +} diff --git a/common/tests/fixtures/cardano/sign_tx.json b/common/tests/fixtures/cardano/sign_tx.json new file mode 100644 index 00000000000..f839c30640b --- /dev/null +++ b/common/tests/fixtures/cardano/sign_tx.json @@ -0,0 +1,96 @@ +{ + "setup": { + "mnemonic": "all all all all all all all all all all all all", + "passphrase": "" + }, + "tests": [ + { + "description": "Mainnet transaction without change", + "parameters": { + "protocol_magic": 764824073, + "inputs": [ + { + "path": "m/44'/1815'/0'/0/1", + "prev_hash": "1af8fa0b754ff99253d983894e63a2b09cbb56c833ba18c3384210163f63dcfc", + "prev_index": 0, + "type": 0 + } + ], + "outputs": [ + { + "address": "Ae2tdPwUPEZCanmBz5g2GEwFqKTKpNJcGYPKfDxoNeKZ8bRHr8366kseiK2", + "amount": "3003112" + } + ], + "prev_tx": [ + "839f8200d818582482582008abb575fac4c39d5bf80683f7f0c37e48f4e3d96e37d1f6611919a7241b456600ff9f8282d818582183581cda4da43db3fca93695e71dab839e72271204d28b9d964d306b8800a8a0001a7a6916a51a00305becffa0" + ] + }, + "result": { + "success": true, + "tx_hash": "799c65e8a2c0b1dc4232611728c09d3f3eb0d811c077f8e9798f84605ef1b23d", + "tx_body": "82839f8200d81858248258201af8fa0b754ff99253d983894e63a2b09cbb56c833ba18c3384210163f63dcfc00ff9f8282d818582183581c9e1c71de652ec8b85fec296f0685ca3988781c94a2e1a5d89d92f45fa0001a0d0c25611a002dd2e8ffa0818200d818588582584089053545a6c254b0d9b1464e48d2b5fcf91d4e25c128afb1fcfc61d0843338ea26308151516f3b0e02bb1638142747863c520273ce9bd3e5cd91e1d46fe2a6355840312c01c27317415b0b8acc86aa789da877fe7e15c65b7ea4c4565d8739117f5f6d9d38bf5d058f7be809b2b9b06c1d79fc6b20f9a4d76d8c89bae333edf5680c" + } + }, + { + "description": "Mainnet transaction with change", + "parameters": { + "protocol_magic": 764824073, + "inputs": [ + { + "path": "m/44'/1815'/0'/0/1", + "prev_hash": "1af8fa0b754ff99253d983894e63a2b09cbb56c833ba18c3384210163f63dcfc", + "prev_index": 0, + "type": 0 + } + ], + "outputs": [ + { + "address": "Ae2tdPwUPEZCanmBz5g2GEwFqKTKpNJcGYPKfDxoNeKZ8bRHr8366kseiK2", + "amount": "3003112" + }, + { + "path": "m/44'/1815'/0'/0/1", + "amount": "1000000" + } + ], + "prev_tx": [ + "839f8200d818582482582008abb575fac4c39d5bf80683f7f0c37e48f4e3d96e37d1f6611919a7241b456600ff9f8282d818582183581cda4da43db3fca93695e71dab839e72271204d28b9d964d306b8800a8a0001a7a6916a51a00305becffa0" + ] + }, + "result": { + "success": true, + "tx_hash": "40bf94518f31aba7779dd99aa71fe867887bcb3e0bac2c6dc33d3f20ec74a6b1", + "tx_body": "82839f8200d81858248258201af8fa0b754ff99253d983894e63a2b09cbb56c833ba18c3384210163f63dcfc00ff9f8282d818582183581c9e1c71de652ec8b85fec296f0685ca3988781c94a2e1a5d89d92f45fa0001a0d0c25611a002dd2e88282d818582183581cda4da43db3fca93695e71dab839e72271204d28b9d964d306b8800a8a0001a7a6916a51a000f4240ffa0818200d818588582584089053545a6c254b0d9b1464e48d2b5fcf91d4e25c128afb1fcfc61d0843338ea26308151516f3b0e02bb1638142747863c520273ce9bd3e5cd91e1d46fe2a63558400b47193163462023bdb72f03b2f6afc8e3645dbc9252cb70f7516da402ce3b8468e4a60929674de5862d6253315008e07b60aa189f5c455dd272ff1c84c89d0c" + } + }, + { + "description": "Testnet transaction", + "parameters": { + "protocol_magic": 1097911063, + "inputs": [ + { + "path": "m/44'/1815'/0'/0/1", + "prev_hash": "1af8fa0b754ff99253d983894e63a2b09cbb56c833ba18c3384210163f63dcfc", + "prev_index": 0, + "type": 0 + } + ], + "outputs": [ + { + "address": "Ae2tdPwUPEZCanmBz5g2GEwFqKTKpNJcGYPKfDxoNeKZ8bRHr8366kseiK2", + "amount": "3003112" + } + ], + "prev_tx": [ + "839f8200d818582482582008abb575fac4c39d5bf80683f7f0c37e48f4e3d96e37d1f6611919a7241b456600ff9f8282d818582183581cda4da43db3fca93695e71dab839e72271204d28b9d964d306b8800a8a0001a7a6916a51a00305becffa0" + ] + }, + "result": { + "success": true, + "tx_hash": "799c65e8a2c0b1dc4232611728c09d3f3eb0d811c077f8e9798f84605ef1b23d", + "tx_body": "82839f8200d81858248258201af8fa0b754ff99253d983894e63a2b09cbb56c833ba18c3384210163f63dcfc00ff9f8282d818582183581c9e1c71de652ec8b85fec296f0685ca3988781c94a2e1a5d89d92f45fa0001a0d0c25611a002dd2e8ffa0818200d818588582584089053545a6c254b0d9b1464e48d2b5fcf91d4e25c128afb1fcfc61d0843338ea26308151516f3b0e02bb1638142747863c520273ce9bd3e5cd91e1d46fe2a63558403594ee7e2bfe4c84f886a8336cecb7c42983ce9a057345ebb6294a436087d8db93ca78cf514c7c48edff4c8435f690a5817951e2b55d2db729875ee7cc0f7d08" + } + } + ] +} diff --git a/common/tests/fixtures/cardano/sign_tx.slip39.json b/common/tests/fixtures/cardano/sign_tx.slip39.json new file mode 100644 index 00000000000..b83fd13d719 --- /dev/null +++ b/common/tests/fixtures/cardano/sign_tx.slip39.json @@ -0,0 +1,100 @@ +{ + "setup": { + "mnemonic": [ + "extra extend academic bishop cricket bundle tofu goat apart victim enlarge program behavior permit course armed jerky faint language modern", + "extra extend academic acne away best indicate impact square oasis prospect painting voting guest either argue username racism enemy eclipse", + "extra extend academic arcade born dive legal hush gross briefing talent drug much home firefly toxic analysis idea umbrella slice" + ], + "passphrase": "TREZOR" + }, + "tests": [ + { + "description": "Mainnet transaction without change", + "parameters": { + "protocol_magic": 764824073, + "inputs": [ + { + "path": "m/44'/1815'/0'/0/1", + "prev_hash": "1af8fa0b754ff99253d983894e63a2b09cbb56c833ba18c3384210163f63dcfc", + "prev_index": 0, + "type": 0 + } + ], + "outputs": [ + { + "address": "Ae2tdPwUPEZCanmBz5g2GEwFqKTKpNJcGYPKfDxoNeKZ8bRHr8366kseiK2", + "amount": "3003112" + } + ], + "prev_tx": [ + "839f8200d818582482582008abb575fac4c39d5bf80683f7f0c37e48f4e3d96e37d1f6611919a7241b456600ff9f8282d818582183581cda4da43db3fca93695e71dab839e72271204d28b9d964d306b8800a8a0001a7a6916a51a00305becffa0" + ] + }, + "result": { + "success": true, + "tx_hash": "799c65e8a2c0b1dc4232611728c09d3f3eb0d811c077f8e9798f84605ef1b23d", + "tx_body": "82839f8200d81858248258201af8fa0b754ff99253d983894e63a2b09cbb56c833ba18c3384210163f63dcfc00ff9f8282d818582183581c9e1c71de652ec8b85fec296f0685ca3988781c94a2e1a5d89d92f45fa0001a0d0c25611a002dd2e8ffa0818200d818588582584024c4fe188a39103db88818bc191fd8571eae7b284ebcbdf2462bde97b058a95c6f7a744035f4b3ddb8f861c18446169643cc3ae85e271b4b4f0eda05cf84c65b584032a773bcd60c83880de09676c45e52cc2c2189c1b46d93de596a5cf6e3e93041c22e6e5762144feb65b40e905659c9b5e51528fa6574273279c2507a2b996f0e" + } + }, + { + "description": "Mainnet transaction with change", + "parameters": { + "protocol_magic": 764824073, + "inputs": [ + { + "path": "m/44'/1815'/0'/0/1", + "prev_hash": "1af8fa0b754ff99253d983894e63a2b09cbb56c833ba18c3384210163f63dcfc", + "prev_index": 0, + "type": 0 + } + ], + "outputs": [ + { + "address": "Ae2tdPwUPEZCanmBz5g2GEwFqKTKpNJcGYPKfDxoNeKZ8bRHr8366kseiK2", + "amount": "3003112" + }, + { + "path": "m/44'/1815'/0'/0/1", + "amount": "1000000" + } + ], + "prev_tx": [ + "839f8200d818582482582008abb575fac4c39d5bf80683f7f0c37e48f4e3d96e37d1f6611919a7241b456600ff9f8282d818582183581cda4da43db3fca93695e71dab839e72271204d28b9d964d306b8800a8a0001a7a6916a51a00305becffa0" + ] + }, + "result": { + "success": true, + "tx_hash": "5a3921053daabc6a2ffc1528963352fa8ea842bd04056371effcd58256e0cd55", + "tx_body": "82839f8200d81858248258201af8fa0b754ff99253d983894e63a2b09cbb56c833ba18c3384210163f63dcfc00ff9f8282d818582183581c9e1c71de652ec8b85fec296f0685ca3988781c94a2e1a5d89d92f45fa0001a0d0c25611a002dd2e88282d818582183581c2ea63b3db3a1865f59c11762a5aede800ed8f2dc0605d75df2ed7c9ca0001ae82668161a000f4240ffa0818200d818588582584024c4fe188a39103db88818bc191fd8571eae7b284ebcbdf2462bde97b058a95c6f7a744035f4b3ddb8f861c18446169643cc3ae85e271b4b4f0eda05cf84c65b5840ea38a37167d652fd35ac3517a6b3a5ec73e01a9f3b6d57d645c7727856a17a2c8d9403b497e148811cb087822c49b5ab6e14b1bc78acc21eca434c3e5147260f" + } + }, + { + "description": "Testnet transaction", + "parameters": { + "protocol_magic": 1097911063, + "inputs": [ + { + "path": "m/44'/1815'/0'/0/1", + "prev_hash": "1af8fa0b754ff99253d983894e63a2b09cbb56c833ba18c3384210163f63dcfc", + "prev_index": 0, + "type": 0 + } + ], + "outputs": [ + { + "address": "Ae2tdPwUPEZCanmBz5g2GEwFqKTKpNJcGYPKfDxoNeKZ8bRHr8366kseiK2", + "amount": "3003112" + } + ], + "prev_tx": [ + "839f8200d818582482582008abb575fac4c39d5bf80683f7f0c37e48f4e3d96e37d1f6611919a7241b456600ff9f8282d818582183581cda4da43db3fca93695e71dab839e72271204d28b9d964d306b8800a8a0001a7a6916a51a00305becffa0" + ] + }, + "result": { + "success": true, + "tx_hash": "799c65e8a2c0b1dc4232611728c09d3f3eb0d811c077f8e9798f84605ef1b23d", + "tx_body": "82839f8200d81858248258201af8fa0b754ff99253d983894e63a2b09cbb56c833ba18c3384210163f63dcfc00ff9f8282d818582183581c9e1c71de652ec8b85fec296f0685ca3988781c94a2e1a5d89d92f45fa0001a0d0c25611a002dd2e8ffa0818200d818588582584024c4fe188a39103db88818bc191fd8571eae7b284ebcbdf2462bde97b058a95c6f7a744035f4b3ddb8f861c18446169643cc3ae85e271b4b4f0eda05cf84c65b58407aab2a707a6d295c0a93e396429721c48d2c09238e32112f2e1d14a8296ff463204240e7d9168e2dfe8276f426cd1f73f1254df434cdab7c942e2a920c8ce800" + } + } + ] +} diff --git a/core/src/apps/cardano/seed.py b/core/src/apps/cardano/seed.py index 9c87b4599c8..e91d4e628ee 100644 --- a/core/src/apps/cardano/seed.py +++ b/core/src/apps/cardano/seed.py @@ -5,6 +5,7 @@ from apps.cardano import SEED_NAMESPACE from apps.common import mnemonic from apps.common.passphrase import get as get_passphrase +from apps.common.seed import get_seed if False: from typing import Tuple @@ -41,13 +42,13 @@ async def get_keychain(ctx: wire.Context) -> Keychain: if not device.is_initialized(): raise wire.NotInitialized("Device is not initialized") - passphrase = await get_passphrase(ctx) if mnemonic.is_bip39(): + passphrase = await get_passphrase(ctx) # derive the root node from mnemonic and passphrase via Cardano Icarus algorithm root = bip32.from_mnemonic_cardano(mnemonic.get_secret().decode(), passphrase) else: # derive the root node via SLIP-0023 - seed = mnemonic.get_seed(passphrase) + seed = await get_seed(ctx) root = bip32.from_seed(seed, "ed25519 cardano seed") # derive the namespaced root node diff --git a/core/src/apps/common/seed.py b/core/src/apps/common/seed.py index 988899dbfff..3eac7328ff5 100644 --- a/core/src/apps/common/seed.py +++ b/core/src/apps/common/seed.py @@ -111,7 +111,7 @@ def __exit__(self, exc_type: Any, exc_val: Any, tb: Any) -> None: @cache.stored_async(cache.APP_COMMON_SEED) -async def _get_seed(ctx: wire.Context) -> bytes: +async def get_seed(ctx: wire.Context) -> bytes: if not device.is_initialized(): raise wire.NotInitialized("Device is not initialized") passphrase = await get_passphrase(ctx) @@ -126,7 +126,7 @@ def _get_seed_without_passphrase() -> bytes: async def get_keychain(ctx: wire.Context, namespaces: Sequence[Namespace]) -> Keychain: - seed = await _get_seed(ctx) + seed = await get_seed(ctx) keychain = Keychain(seed, namespaces) return keychain diff --git a/tests/common.py b/tests/common.py index 30eddea98c5..e798444c319 100644 --- a/tests/common.py +++ b/tests/common.py @@ -14,6 +14,11 @@ # You should have received a copy of the License along with this library. # If not, see . +import json +from pathlib import Path + +import pytest + from trezorlib import btc, tools from trezorlib.messages import ButtonRequestType as B @@ -43,6 +48,36 @@ # fmt: on TEST_ADDRESS_N = tools.parse_path("m/44h/1h/0h/0/0") +COMMON_FIXTURES_DIR = ( + Path(__file__).parent.resolve().parent / "common" / "tests" / "fixtures" +) + + +def parametrize_using_common_fixtures(*paths): + fixtures = [] + for path in paths: + json.loads((COMMON_FIXTURES_DIR / path).read_text()) + + tests = [] + for fixture in fixtures: + for test in fixture["tests"]: + tests.append( + pytest.param( + test["parameters"], + test["result"], + marks=pytest.mark.setup_client( + passphrase=fixture["setup"]["passphrase"], + mnemonic=fixture["setup"]["mnemonic"], + ), + ) + ) + + return pytest.mark.parametrize("parameters, result", tests) + + +def _load_fixtures(path: Path): + with path.open() as file: + return json.load(file) def generate_entropy(strength, internal_entropy, external_entropy): diff --git a/tests/conftest.py b/tests/conftest.py index b3f8d113b88..511cc037be8 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -116,18 +116,25 @@ def client(request): if marker: setup_params.update(marker.kwargs) + use_passphrase = setup_params["passphrase"] is True or isinstance( + setup_params["passphrase"], str + ) + if not setup_params["uninitialized"]: debuglink.load_device( client, mnemonic=setup_params["mnemonic"], pin=setup_params["pin"], - passphrase_protection=setup_params["passphrase"], + passphrase_protection=use_passphrase, label="test", language="en-US", needs_backup=setup_params["needs_backup"], no_backup=setup_params["no_backup"], ) + if use_passphrase and isinstance(setup_params["passphrase"], str): + client.use_passphrase(setup_params["passphrase"]) + if setup_params["pin"]: # ClearSession locks the device. We only do that if the PIN is set. client.clear_session() diff --git a/tests/device_tests/cardano/__init__.py b/tests/device_tests/cardano/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/device_tests/cardano/test_address_public_key.py b/tests/device_tests/cardano/test_address_public_key.py new file mode 100644 index 00000000000..4470e0bff6c --- /dev/null +++ b/tests/device_tests/cardano/test_address_public_key.py @@ -0,0 +1,48 @@ +# 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 . + +import pytest + +from trezorlib.cardano import get_address, get_public_key +from trezorlib.tools import parse_path + +from ...common import parametrize_using_common_fixtures + +pytestmark = [ + pytest.mark.altcoin, + pytest.mark.cardano, + pytest.mark.skip_t1, + pytest.mark.skip_ui, +] + + +@parametrize_using_common_fixtures( + "cardano/get_address.json", "cardano/get_address.slip39.json" +) +def test_cardano_get_address(client, parameters, result): + address = get_address(client, parse_path(parameters["path"])) + assert address == result["expected_address"] + + +@parametrize_using_common_fixtures( + "cardano/get_public_key.json", "cardano/get_public_key.slip39.json" +) +def test_cardano_get_public_key(client, parameters, result): + key = get_public_key(client, parse_path(parameters["path"])) + + 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"] diff --git a/tests/device_tests/cardano/test_sign_tx.py b/tests/device_tests/cardano/test_sign_tx.py new file mode 100644 index 00000000000..38ffa294914 --- /dev/null +++ b/tests/device_tests/cardano/test_sign_tx.py @@ -0,0 +1,97 @@ +# 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 . + +import pytest + +from trezorlib import cardano, messages +from trezorlib.exceptions import TrezorFailure + +from ...common import parametrize_using_common_fixtures + +pytestmark = [ + pytest.mark.altcoin, + pytest.mark.cardano, + pytest.mark.skip_t1, +] + + +@parametrize_using_common_fixtures( + "cardano/sign_tx.json", "cardano/sign_tx.slip39.json" +) +def test_cardano_sign_tx(client, parameters, result): + inputs = [cardano.create_input(i) for i in parameters["inputs"]] + outputs = [cardano.create_output(o) for o in parameters["outputs"]] + + expected_responses = [messages.PassphraseRequest()] + + expected_responses += [ + messages.CardanoTxRequest(tx_index=i) for i in range(len(parameters["prev_tx"])) + ] + if result["success"]: + expected_responses += [ + messages.ButtonRequest(code=messages.ButtonRequestType.Other), + messages.ButtonRequest(code=messages.ButtonRequestType.Other), + messages.CardanoSignedTx(), + ] + else: + expected_responses += [messages.Failure()] + + def input_flow(): + yield + client.debug.swipe_up() + client.debug.press_yes() + yield + client.debug.swipe_up() + client.debug.press_yes() + + with client: + client.set_expected_responses(expected_responses) + client.set_input_flow(input_flow) + response = cardano.sign_tx( + client, + inputs, + outputs, + parameters["prev_tx"], + parameters["protocol_magic"], + ) + assert response.tx_hash.hex() == result["tx_hash"] + assert response.tx_body.hex() == result["tx_body"] + + +@parametrize_using_common_fixtures("cardano/sign_tx.failures.json") +def test_cardano_sign_tx_failures(client, parameters, result): + inputs = [cardano.create_input(i) for i in parameters["inputs"]] + outputs = [cardano.create_output(o) for o in parameters["outputs"]] + + expected_responses = [ + messages.PassphraseRequest(), + *( + messages.CardanoTxRequest(tx_index=i) + for i in range(len(parameters["prev_tx"])) + ), + messages.Failure(), + ] + + with client: + client.set_expected_responses(expected_responses) + with pytest.raises(TrezorFailure, match=result["error"]): + cardano.sign_tx( + client, + inputs, + outputs, + parameters["prev_tx"], + parameters["protocol_magic"], + ) diff --git a/tests/device_tests/cardano/test_slip39_passphrase.py b/tests/device_tests/cardano/test_slip39_passphrase.py new file mode 100644 index 00000000000..03e9d24d742 --- /dev/null +++ b/tests/device_tests/cardano/test_slip39_passphrase.py @@ -0,0 +1,54 @@ +# 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 . + +import pytest + +from trezorlib import btc, cardano, messages, tools + +from ...common import MNEMONIC_SLIP39_BASIC_20_3of6 + + +@pytest.mark.altcoin +@pytest.mark.cardano +@pytest.mark.skip_t1 # T1 support is not planned +@pytest.mark.skip_ui +@pytest.mark.setup_client(mnemonic=MNEMONIC_SLIP39_BASIC_20_3of6, passphrase=True) +def test_single_passphrase_entry(client): + # try empty passphrase + with client: + client.use_passphrase("") + client.set_expected_responses( + [messages.PassphraseRequest(), messages.CardanoAddress()] + ) + address_a = cardano.get_address(client, tools.parse_path("m/44'/1815'/0'/0/0")) + + client.clear_session() + + # in a new session, unlock non-Cardano first + with client: + client.use_passphrase("TREZOR") + client.set_expected_responses( + [messages.PassphraseRequest(), messages.Address()] + ) + # invoke passphrase prompt + btc.get_address(client, "Testnet", tools.parse_path("m/44'/1'/0'/0/0")) + + with client: + # Cardano should not ask for passphrase again + client.set_expected_responses([messages.CardanoAddress()]) + address_b = cardano.get_address(client, tools.parse_path("m/44'/1815'/0'/0/0")) + # but it should be using the previously entered passphrase + assert address_a != address_b diff --git a/tests/device_tests/test_msg_cardano_get_address.py b/tests/device_tests/test_msg_cardano_get_address.py deleted file mode 100644 index 22cefe11528..00000000000 --- a/tests/device_tests/test_msg_cardano_get_address.py +++ /dev/null @@ -1,49 +0,0 @@ -# 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 . - -import pytest - -from trezorlib.cardano import get_address -from trezorlib.tools import parse_path - -from ..common import MNEMONIC12 - - -@pytest.mark.altcoin -@pytest.mark.cardano -@pytest.mark.skip_t1 # T1 support is not planned -@pytest.mark.parametrize( - "path,expected_address", - [ - ( - "m/44'/1815'/0'/0/0", - "Ae2tdPwUPEZLCq3sFv4wVYxwqjMH2nUzBVt1HFr4v87snYrtYq3d3bq2PUQ", - ), - ( - "m/44'/1815'/0'/0/1", - "Ae2tdPwUPEZEY6pVJoyuNNdLp7VbMB7U7qfebeJ7XGunk5Z2eHarkcN1bHK", - ), - ( - "m/44'/1815'/0'/0/2", - "Ae2tdPwUPEZ3gZD1QeUHvAqadAV59Zid6NP9VCR9BG5LLAja9YtBUgr6ttK", - ), - ], -) -@pytest.mark.setup_client(mnemonic=MNEMONIC12) -def test_cardano_get_address(client, path, expected_address): - # data from https://iancoleman.io/bip39/ - address = get_address(client, parse_path(path)) - assert address == expected_address diff --git a/tests/device_tests/test_msg_cardano_get_address_slip39_basic.py b/tests/device_tests/test_msg_cardano_get_address_slip39_basic.py deleted file mode 100644 index 159a8a0ac26..00000000000 --- a/tests/device_tests/test_msg_cardano_get_address_slip39_basic.py +++ /dev/null @@ -1,53 +0,0 @@ -# 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 . - -import pytest - -from trezorlib.cardano import get_address -from trezorlib.tools import parse_path - -from ..common import MNEMONIC_SLIP39_BASIC_20_3of6 - - -@pytest.mark.altcoin -@pytest.mark.cardano -@pytest.mark.skip_t1 # T1 support is not planned -@pytest.mark.skip_ui -@pytest.mark.parametrize( - "path,expected_address", - [ - ( - "m/44'/1815'/0'/0/0", - "Ae2tdPwUPEYxF9NAMNdd3v2LZoMeWp7gCZiDb6bZzFQeeVASzoP7HC4V9s6", - ), - ( - "m/44'/1815'/0'/0/1", - "Ae2tdPwUPEZ1TjYcvfkWAbiHtGVxv4byEHHZoSyQXjPJ362DifCe1ykgqgy", - ), - ( - "m/44'/1815'/0'/0/2", - "Ae2tdPwUPEZGXmSbda1kBNfyhRQGRcQxJFdk7mhWZXAGnapyejv2b2U3aRb", - ), - ], -) -@pytest.mark.setup_client(mnemonic=MNEMONIC_SLIP39_BASIC_20_3of6, passphrase=True) -def test_cardano_get_address(client, path, expected_address): - # enter passphrase - assert client.features.passphrase_protection is True - client.use_passphrase("TREZOR") - - address = get_address(client, parse_path(path)) - assert address == expected_address diff --git a/tests/device_tests/test_msg_cardano_get_public_key.py b/tests/device_tests/test_msg_cardano_get_public_key.py deleted file mode 100644 index f09da1235a4..00000000000 --- a/tests/device_tests/test_msg_cardano_get_public_key.py +++ /dev/null @@ -1,56 +0,0 @@ -# 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 . - -import pytest - -from trezorlib.cardano import get_public_key -from trezorlib.tools import parse_path - - -@pytest.mark.altcoin -@pytest.mark.cardano -@pytest.mark.skip_t1 # T1 support is not planned -@pytest.mark.parametrize( - "path,public_key,chain_code", - [ - ( - "m/44'/1815'/0'", - "c0fce1839f1a84c4e770293ac2f5e0875141b29017b7f56ab135352d00ad6966", - "07faa161c9f5464315d2855f70fdf1431d5fa39eb838767bf17b69772137452f", - ), - ( - "m/44'/1815'/1'", - "ea5dde31b9f551e08a5b6b2f98b8c42c726f726c9ce0a7072102ead53bd8f21e", - "70f131bb799fd659c997221ad8cae7dcce4e8da701f8101cf15307fd3a3712a1", - ), - ( - "m/44'/1815'/2'", - "076338cee5ab3dae19f06ccaa80e3d4428cf0e1bdc04243e41bba7be63a90da7", - "5dcdf129f6f2d108292e615c4b67a1fc41a64e6a96130f5c981e5e8e046a6cd7", - ), - ( - "m/44'/1815'/3'", - "5f769380dc6fd17a4e0f2d23aa359442a712e5e96d7838ebb91eb020003cccc3", - "1197ea234f528987cbac9817ebc31344395b837a3bb7c2332f87e095e70550a5", - ), - ], -) -def test_cardano_get_public_key(client, path, public_key, chain_code): - key = get_public_key(client, parse_path(path)) - - assert key.node.public_key.hex() == public_key - assert key.node.chain_code.hex() == chain_code - assert key.xpub == public_key + chain_code diff --git a/tests/device_tests/test_msg_cardano_get_public_key_slip39_basic.py b/tests/device_tests/test_msg_cardano_get_public_key_slip39_basic.py deleted file mode 100644 index 1d28c5f5d2a..00000000000 --- a/tests/device_tests/test_msg_cardano_get_public_key_slip39_basic.py +++ /dev/null @@ -1,59 +0,0 @@ -# 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 . - -import pytest - -from trezorlib.cardano import get_public_key -from trezorlib.tools import parse_path - -from ..common import MNEMONIC_SLIP39_BASIC_20_3of6 - - -@pytest.mark.altcoin -@pytest.mark.cardano -@pytest.mark.skip_t1 # T1 support is not planned -@pytest.mark.skip_ui -@pytest.mark.setup_client(mnemonic=MNEMONIC_SLIP39_BASIC_20_3of6, passphrase=True) -@pytest.mark.parametrize( - "path,public_key,chain_code", - [ - ( - "m/44'/1815'/0'/0/0", - "bc043d84b8b891d49890edb6aced6f2d78395f255c5b6aea8878b913f83e8579", - "dc3f0d2b5cccb822335ef6213fd133f4ca934151ec44a6000aee43b8a101078c", - ), - ( - "m/44'/1815'/0'/0/1", - "24c4fe188a39103db88818bc191fd8571eae7b284ebcbdf2462bde97b058a95c", - "6f7a744035f4b3ddb8f861c18446169643cc3ae85e271b4b4f0eda05cf84c65b", - ), - ( - "m/44'/1815'/0'/0/2", - "831a63d381a8dab1e6e1ee991a4300fc70687aae5f97f4fcf92ed1b6c2bd99de", - "672d6af4707aba201b7940231e83dd357f92f8851b3dfdc224ef311e1b64cdeb", - ), - ], -) -def test_cardano_get_public_key(client, path, public_key, chain_code): - # enter passphrase - assert client.features.passphrase_protection is True - client.use_passphrase("TREZOR") - - key = get_public_key(client, parse_path(path)) - - assert key.node.public_key.hex() == public_key - assert key.node.chain_code.hex() == chain_code - assert key.xpub == public_key + chain_code diff --git a/tests/device_tests/test_msg_cardano_sign_transaction.py b/tests/device_tests/test_msg_cardano_sign_transaction.py deleted file mode 100644 index 6c2aa99f521..00000000000 --- a/tests/device_tests/test_msg_cardano_sign_transaction.py +++ /dev/null @@ -1,231 +0,0 @@ -# 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 . - -import pytest - -from trezorlib import cardano, messages -from trezorlib.exceptions import TrezorFailure - -PROTOCOL_MAGICS = {"mainnet": 764824073, "testnet": 1097911063} - -SAMPLE_INPUTS = [ - { - "input": { - "path": "m/44'/1815'/0'/0/1", - "prev_hash": "1af8fa0b754ff99253d983894e63a2b09cbb56c833ba18c3384210163f63dcfc", - "prev_index": 0, - "type": 0, - }, - "prev_tx": "839f8200d818582482582008abb575fac4c39d5bf80683f7f0c37e48f4e3d96e37d1f6611919a7241b456600ff9f8282d818582183581cda4da43db3fca93695e71dab839e72271204d28b9d964d306b8800a8a0001a7a6916a51a00305becffa0", - } -] - -VALID_VECTORS = [ - # Mainnet transaction without change - ( - # protocol magic - PROTOCOL_MAGICS["mainnet"], - # inputs - [SAMPLE_INPUTS[0]["input"]], - # outputs - [ - { - "address": "Ae2tdPwUPEZCanmBz5g2GEwFqKTKpNJcGYPKfDxoNeKZ8bRHr8366kseiK2", - "amount": "3003112", - } - ], - # transactions - [SAMPLE_INPUTS[0]["prev_tx"]], - # tx hash - "799c65e8a2c0b1dc4232611728c09d3f3eb0d811c077f8e9798f84605ef1b23d", - # tx body - "82839f8200d81858248258201af8fa0b754ff99253d983894e63a2b09cbb56c833ba18c3384210163f63dcfc00ff9f8282d818582183581c9e1c71de652ec8b85fec296f0685ca3988781c94a2e1a5d89d92f45fa0001a0d0c25611a002dd2e8ffa0818200d818588582584089053545a6c254b0d9b1464e48d2b5fcf91d4e25c128afb1fcfc61d0843338ea26308151516f3b0e02bb1638142747863c520273ce9bd3e5cd91e1d46fe2a6355840312c01c27317415b0b8acc86aa789da877fe7e15c65b7ea4c4565d8739117f5f6d9d38bf5d058f7be809b2b9b06c1d79fc6b20f9a4d76d8c89bae333edf5680c", - ), - # Mainnet transaction with change - ( - # protocol magic (mainnet) - 764824073, - # inputs - [ - { - "path": "m/44'/1815'/0'/0/1", - "prev_hash": "1af8fa0b754ff99253d983894e63a2b09cbb56c833ba18c3384210163f63dcfc", - "prev_index": 0, - "type": 0, - } - ], - # outputs - [ - { - "address": "Ae2tdPwUPEZCanmBz5g2GEwFqKTKpNJcGYPKfDxoNeKZ8bRHr8366kseiK2", - "amount": "3003112", - }, - {"path": "m/44'/1815'/0'/0/1", "amount": "1000000"}, - ], - # transactions - [SAMPLE_INPUTS[0]["prev_tx"]], - # tx hash - "40bf94518f31aba7779dd99aa71fe867887bcb3e0bac2c6dc33d3f20ec74a6b1", - # tx body - "82839f8200d81858248258201af8fa0b754ff99253d983894e63a2b09cbb56c833ba18c3384210163f63dcfc00ff9f8282d818582183581c9e1c71de652ec8b85fec296f0685ca3988781c94a2e1a5d89d92f45fa0001a0d0c25611a002dd2e88282d818582183581cda4da43db3fca93695e71dab839e72271204d28b9d964d306b8800a8a0001a7a6916a51a000f4240ffa0818200d818588582584089053545a6c254b0d9b1464e48d2b5fcf91d4e25c128afb1fcfc61d0843338ea26308151516f3b0e02bb1638142747863c520273ce9bd3e5cd91e1d46fe2a63558400b47193163462023bdb72f03b2f6afc8e3645dbc9252cb70f7516da402ce3b8468e4a60929674de5862d6253315008e07b60aa189f5c455dd272ff1c84c89d0c", - ), - # Testnet transaction - ( - # protocol magic - PROTOCOL_MAGICS["testnet"], - # inputs - [SAMPLE_INPUTS[0]["input"]], - # outputs - [ - { - "address": "Ae2tdPwUPEZCanmBz5g2GEwFqKTKpNJcGYPKfDxoNeKZ8bRHr8366kseiK2", - "amount": "3003112", - } - ], - # transactions - [SAMPLE_INPUTS[0]["prev_tx"]], - # tx hash - "799c65e8a2c0b1dc4232611728c09d3f3eb0d811c077f8e9798f84605ef1b23d", - # tx body - "82839f8200d81858248258201af8fa0b754ff99253d983894e63a2b09cbb56c833ba18c3384210163f63dcfc00ff9f8282d818582183581c9e1c71de652ec8b85fec296f0685ca3988781c94a2e1a5d89d92f45fa0001a0d0c25611a002dd2e8ffa0818200d818588582584089053545a6c254b0d9b1464e48d2b5fcf91d4e25c128afb1fcfc61d0843338ea26308151516f3b0e02bb1638142747863c520273ce9bd3e5cd91e1d46fe2a63558403594ee7e2bfe4c84f886a8336cecb7c42983ce9a057345ebb6294a436087d8db93ca78cf514c7c48edff4c8435f690a5817951e2b55d2db729875ee7cc0f7d08", - ), -] - -INVALID_VECTORS = [ - # Output address is a valid CBOR but invalid Cardano address - ( - # protocol magic - PROTOCOL_MAGICS["mainnet"], - # inputs - [SAMPLE_INPUTS[0]["input"]], - # outputs - [ - { - "address": "jsK75PTH2esX8k4Wvxenyz83LJJWToBbVmGrWUer2CHFHanLseh7r3sW5X5q", - "amount": "3003112", - } - ], - # transactions - [SAMPLE_INPUTS[0]["prev_tx"]], - "Invalid output address!", - ), - # Output address is an invalid CBOR - ( - # protocol magic - PROTOCOL_MAGICS["mainnet"], - # inputs - [SAMPLE_INPUTS[0]["input"]], - # outputs - [ - { - "address": "jsK75PTH2esX8k4Wvxenyz83LJJWToBbVmGrWUer2CHFHanLseh7r3sW5X5q", - "amount": "3003112", - } - ], - # transactions - [ - "839f8200d818582482582008abb575fac4c39d5bf80683f7f0c37e48f4e3d96e37d1f6611919a7241b456600ff9f8282d818582183581cda4da43db3fca93695e71dab839e72271204d28b9d964d306b8800a8a0001a7a6916a51a00305becffa0" - ], - "Invalid output address!", - ), - # Output address is invalid CBOR - ( - # protocol magic (mainnet) - 764824073, - # inputs - [ - { - "path": "m/44'/1815'/0'/0/1", - "prev_hash": "1af8fa0b754ff99253d983894e63a2b09cbb56c833ba18c3384210163f63dcfc", - "prev_index": 0, - "type": 0, - } - ], - # outputs - [ - { - "address": "5dnY6xgRcNUSLGa4gfqef2jGAMHb7koQs9EXErXLNC1LiMPUnhn8joXhvEJpWQtN3F4ysATcBvCn5tABgL3e4hPWapPHmcK5GJMSEaET5JafgAGwSrznzL1Mqa", - "amount": "3003112", - } - ], - # transactions - [SAMPLE_INPUTS[0]["prev_tx"]], - "Invalid output address!", - ), -] - - -@pytest.mark.altcoin -@pytest.mark.cardano -@pytest.mark.skip_t1 # T1 support is not planned -@pytest.mark.parametrize( - "protocol_magic,inputs,outputs,transactions,tx_hash,tx_body", VALID_VECTORS -) -def test_cardano_sign_tx( - client, protocol_magic, inputs, outputs, transactions, tx_hash, tx_body -): - inputs = [cardano.create_input(i) for i in inputs] - outputs = [cardano.create_output(o) for o in outputs] - - expected_responses = [ - messages.CardanoTxRequest(tx_index=i) for i in range(len(transactions)) - ] - expected_responses += [ - messages.ButtonRequest(code=messages.ButtonRequestType.Other), - messages.ButtonRequest(code=messages.ButtonRequestType.Other), - messages.CardanoSignedTx(), - ] - - def input_flow(): - yield - client.debug.swipe_up() - client.debug.press_yes() - yield - client.debug.swipe_up() - client.debug.press_yes() - - with client: - client.set_expected_responses(expected_responses) - client.set_input_flow(input_flow) - response = cardano.sign_tx( - client, inputs, outputs, transactions, protocol_magic - ) - assert response.tx_hash.hex() == tx_hash - assert response.tx_body.hex() == tx_body - - -@pytest.mark.altcoin -@pytest.mark.cardano -@pytest.mark.skip_t1 # T1 support is not planned -@pytest.mark.parametrize( - "protocol_magic,inputs,outputs,transactions,expected_error_message", INVALID_VECTORS -) -def test_cardano_sign_tx_validation( - client, protocol_magic, inputs, outputs, transactions, expected_error_message -): - inputs = [cardano.create_input(i) for i in inputs] - outputs = [cardano.create_output(o) for o in outputs] - - expected_responses = [ - messages.CardanoTxRequest(tx_index=i) for i in range(len(transactions)) - ] - expected_responses += [messages.Failure()] - - with client: - client.set_expected_responses(expected_responses) - - with pytest.raises(TrezorFailure, match=expected_error_message): - cardano.sign_tx(client, inputs, outputs, transactions, protocol_magic) diff --git a/tests/device_tests/test_msg_cardano_sign_tx_slip39_basic.py b/tests/device_tests/test_msg_cardano_sign_tx_slip39_basic.py deleted file mode 100644 index 558721616cd..00000000000 --- a/tests/device_tests/test_msg_cardano_sign_tx_slip39_basic.py +++ /dev/null @@ -1,148 +0,0 @@ -# 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 . - -import pytest - -from trezorlib import cardano, messages - -from ..common import MNEMONIC_SLIP39_BASIC_20_3of6 - -PROTOCOL_MAGICS = {"mainnet": 764824073, "testnet": 1097911063} - -SAMPLE_INPUTS = [ - { - "input": { - "path": "m/44'/1815'/0'/0/1", - "prev_hash": "1af8fa0b754ff99253d983894e63a2b09cbb56c833ba18c3384210163f63dcfc", - "prev_index": 0, - "type": 0, - }, - "prev_tx": "839f8200d818582482582008abb575fac4c39d5bf80683f7f0c37e48f4e3d96e37d1f6611919a7241b456600ff9f8282d818582183581cda4da43db3fca93695e71dab839e72271204d28b9d964d306b8800a8a0001a7a6916a51a00305becffa0", - } -] - -VALID_VECTORS = [ - # Mainnet transaction without change - ( - # protocol magic - PROTOCOL_MAGICS["mainnet"], - # inputs - [SAMPLE_INPUTS[0]["input"]], - # outputs - [ - { - "address": "Ae2tdPwUPEZCanmBz5g2GEwFqKTKpNJcGYPKfDxoNeKZ8bRHr8366kseiK2", - "amount": "3003112", - } - ], - # transactions - [SAMPLE_INPUTS[0]["prev_tx"]], - # tx hash - "799c65e8a2c0b1dc4232611728c09d3f3eb0d811c077f8e9798f84605ef1b23d", - # tx body - "82839f8200d81858248258201af8fa0b754ff99253d983894e63a2b09cbb56c833ba18c3384210163f63dcfc00ff9f8282d818582183581c9e1c71de652ec8b85fec296f0685ca3988781c94a2e1a5d89d92f45fa0001a0d0c25611a002dd2e8ffa0818200d818588582584024c4fe188a39103db88818bc191fd8571eae7b284ebcbdf2462bde97b058a95c6f7a744035f4b3ddb8f861c18446169643cc3ae85e271b4b4f0eda05cf84c65b584032a773bcd60c83880de09676c45e52cc2c2189c1b46d93de596a5cf6e3e93041c22e6e5762144feb65b40e905659c9b5e51528fa6574273279c2507a2b996f0e", - ), - # Mainnet transaction with change - ( - # protocol magic (mainnet) - PROTOCOL_MAGICS["mainnet"], - # inputs - [ - { - "path": "m/44'/1815'/0'/0/1", - "prev_hash": "1af8fa0b754ff99253d983894e63a2b09cbb56c833ba18c3384210163f63dcfc", - "prev_index": 0, - "type": 0, - } - ], - # outputs - [ - { - "address": "Ae2tdPwUPEZCanmBz5g2GEwFqKTKpNJcGYPKfDxoNeKZ8bRHr8366kseiK2", - "amount": "3003112", - }, - {"path": "m/44'/1815'/0'/0/1", "amount": "1000000"}, - ], - # transactions - [SAMPLE_INPUTS[0]["prev_tx"]], - # tx hash - "5a3921053daabc6a2ffc1528963352fa8ea842bd04056371effcd58256e0cd55", - # tx body - "82839f8200d81858248258201af8fa0b754ff99253d983894e63a2b09cbb56c833ba18c3384210163f63dcfc00ff9f8282d818582183581c9e1c71de652ec8b85fec296f0685ca3988781c94a2e1a5d89d92f45fa0001a0d0c25611a002dd2e88282d818582183581c2ea63b3db3a1865f59c11762a5aede800ed8f2dc0605d75df2ed7c9ca0001ae82668161a000f4240ffa0818200d818588582584024c4fe188a39103db88818bc191fd8571eae7b284ebcbdf2462bde97b058a95c6f7a744035f4b3ddb8f861c18446169643cc3ae85e271b4b4f0eda05cf84c65b5840ea38a37167d652fd35ac3517a6b3a5ec73e01a9f3b6d57d645c7727856a17a2c8d9403b497e148811cb087822c49b5ab6e14b1bc78acc21eca434c3e5147260f", - ), - # Testnet transaction - ( - # protocol magic - PROTOCOL_MAGICS["testnet"], - # inputs - [SAMPLE_INPUTS[0]["input"]], - # outputs - [ - { - "address": "Ae2tdPwUPEZCanmBz5g2GEwFqKTKpNJcGYPKfDxoNeKZ8bRHr8366kseiK2", - "amount": "3003112", - } - ], - # transactions - [SAMPLE_INPUTS[0]["prev_tx"]], - # tx hash - "799c65e8a2c0b1dc4232611728c09d3f3eb0d811c077f8e9798f84605ef1b23d", - # tx body - "82839f8200d81858248258201af8fa0b754ff99253d983894e63a2b09cbb56c833ba18c3384210163f63dcfc00ff9f8282d818582183581c9e1c71de652ec8b85fec296f0685ca3988781c94a2e1a5d89d92f45fa0001a0d0c25611a002dd2e8ffa0818200d818588582584024c4fe188a39103db88818bc191fd8571eae7b284ebcbdf2462bde97b058a95c6f7a744035f4b3ddb8f861c18446169643cc3ae85e271b4b4f0eda05cf84c65b58407aab2a707a6d295c0a93e396429721c48d2c09238e32112f2e1d14a8296ff463204240e7d9168e2dfe8276f426cd1f73f1254df434cdab7c942e2a920c8ce800", - ), -] - - -@pytest.mark.altcoin -@pytest.mark.cardano -@pytest.mark.skip_t1 # T1 support is not planned -@pytest.mark.setup_client(mnemonic=MNEMONIC_SLIP39_BASIC_20_3of6, passphrase=True) -@pytest.mark.parametrize( - "protocol_magic,inputs,outputs,transactions,tx_hash,tx_body", VALID_VECTORS -) -def test_cardano_sign_tx( - client, protocol_magic, inputs, outputs, transactions, tx_hash, tx_body -): - inputs = [cardano.create_input(i) for i in inputs] - outputs = [cardano.create_output(o) for o in outputs] - - expected_responses = [messages.PassphraseRequest()] - expected_responses += [ - messages.CardanoTxRequest(tx_index=i) for i in range(len(transactions)) - ] - expected_responses += [ - messages.ButtonRequest(code=messages.ButtonRequestType.Other), - messages.ButtonRequest(code=messages.ButtonRequestType.Other), - messages.CardanoSignedTx(), - ] - - def input_flow(): - yield - client.debug.swipe_up() - client.debug.press_yes() - yield - client.debug.swipe_up() - client.debug.press_yes() - - client.use_passphrase("TREZOR") - with client: - client.set_expected_responses(expected_responses) - client.set_input_flow(input_flow) - response = cardano.sign_tx( - client, inputs, outputs, transactions, protocol_magic - ) - assert response.tx_hash.hex() == tx_hash - assert response.tx_body.hex() == tx_body diff --git a/tests/ui_tests/fixtures.json b/tests/ui_tests/fixtures.json index 742b2f1eb8e..ef84ac0d2b1 100644 --- a/tests/ui_tests/fixtures.json +++ b/tests/ui_tests/fixtures.json @@ -1,4 +1,12 @@ { +"cardano-test_sign_tx.py::test_cardano_sign_tx[parameters0-result0]": "b1f022d81fb324a136a8401232b7112bca2b5212b98578a189d3486911d469cc", +"cardano-test_sign_tx.py::test_cardano_sign_tx[parameters1-result1]": "c5f547077924a76527e8cf58abf437e27059386bff775499d21d52105d60ed44", +"cardano-test_sign_tx.py::test_cardano_sign_tx[parameters2-result2]": "fdac7a4eb74827fc2318c3646206c60a10ddfe244c089f5a798e7652f69d313e", +"cardano-test_sign_tx.py::test_cardano_sign_tx[parameters3-result3]": "f504163122424398b008ec86cbd219e543eea7889d52651e0e69f707b4a14649", +"cardano-test_sign_tx.py::test_cardano_sign_tx[parameters4-result4]": "f504163122424398b008ec86cbd219e543eea7889d52651e0e69f707b4a14649", +"cardano-test_sign_tx.py::test_cardano_sign_tx[parameters5-result5]": "85fb1f1bf90131d6cd04e58b2303bf8d3b9a641b1f418852bc27c4432d427976", +"cardano-test_sign_tx.py::test_cardano_sign_tx[parameters6-result6]": "15f55a8fc499364aa239c319100072d16ae5dc1ee9dd0db3cd1795363fde679a", +"cardano-test_sign_tx.py::test_cardano_sign_tx[parameters7-result7]": "32edff90a2fecf74bf7e3e46794a48924082c069b9d1e57adb531749ac71e4af", "test_autolock.py::test_apply_auto_lock_delay": "1997527e85989f3ca5719f93cd76bcfb8f125fb96ef3025073b13fd4de7a5fa2", "test_autolock.py::test_apply_minimal_auto_lock_delay": "adc5da99fcc8b4023d6989fa59f69c3918e70165bdeb693a887364e2009ee2fa", "test_autolock.py::test_autolock_cancels_ui": "eedc6196565bf6d53bc9c3f8984acc2bb91d2d71e57f3a28f8afbe35b02fb4dc", @@ -21,22 +29,6 @@ "test_msg_binance_sign_tx.py::test_binance_sign_message[message0-expected_response0]": "d41ee5e01a50f0f96fd7881db1750fab31cfe62c25b4eabbc092cc3daa039c7f", "test_msg_binance_sign_tx.py::test_binance_sign_message[message1-expected_response1]": "7b8bbe5ba7d7b07c95065608fb1cf9aeafcb3f9671835a6e5e5a6997ff4ff99b", "test_msg_binance_sign_tx.py::test_binance_sign_message[message2-expected_response2]": "813ad1b802dee1ace4dfa378edd840dbcea57c1a1b8eed67134def024c40a6e9", -"test_msg_cardano_get_address.py::test_cardano_get_address[m-44'-1815'-0'-0-0-Ae2tdPwUPEZLCq3sFv4wVYx": "5a80508a71a9ef64f94762b07636f90e464832f0f4a3102af8fa1a8c69e94586", -"test_msg_cardano_get_address.py::test_cardano_get_address[m-44'-1815'-0'-0-1-Ae2tdPwUPEZEY6pVJoyuNNd": "5a80508a71a9ef64f94762b07636f90e464832f0f4a3102af8fa1a8c69e94586", -"test_msg_cardano_get_address.py::test_cardano_get_address[m-44'-1815'-0'-0-2-Ae2tdPwUPEZ3gZD1QeUHvAq": "5a80508a71a9ef64f94762b07636f90e464832f0f4a3102af8fa1a8c69e94586", -"test_msg_cardano_get_public_key.py::test_cardano_get_public_key[m-44'-1815'-0'-c0fce1839f1a84c4e7702": "5a80508a71a9ef64f94762b07636f90e464832f0f4a3102af8fa1a8c69e94586", -"test_msg_cardano_get_public_key.py::test_cardano_get_public_key[m-44'-1815'-1'-ea5dde31b9f551e08a5b6": "5a80508a71a9ef64f94762b07636f90e464832f0f4a3102af8fa1a8c69e94586", -"test_msg_cardano_get_public_key.py::test_cardano_get_public_key[m-44'-1815'-2'-076338cee5ab3dae19f06": "5a80508a71a9ef64f94762b07636f90e464832f0f4a3102af8fa1a8c69e94586", -"test_msg_cardano_get_public_key.py::test_cardano_get_public_key[m-44'-1815'-3'-5f769380dc6fd17a4e0f2": "5a80508a71a9ef64f94762b07636f90e464832f0f4a3102af8fa1a8c69e94586", -"test_msg_cardano_sign_transaction.py::test_cardano_sign_tx[1097911063-inputs2-outputs2-transactions2": "fdac7a4eb74827fc2318c3646206c60a10ddfe244c089f5a798e7652f69d313e", -"test_msg_cardano_sign_transaction.py::test_cardano_sign_tx[764824073-inputs0-outputs0-transactions0-": "b1f022d81fb324a136a8401232b7112bca2b5212b98578a189d3486911d469cc", -"test_msg_cardano_sign_transaction.py::test_cardano_sign_tx[764824073-inputs1-outputs1-transactions1-": "c5f547077924a76527e8cf58abf437e27059386bff775499d21d52105d60ed44", -"test_msg_cardano_sign_transaction.py::test_cardano_sign_tx_validation[764824073-inputs0-outputs0-tra": "f504163122424398b008ec86cbd219e543eea7889d52651e0e69f707b4a14649", -"test_msg_cardano_sign_transaction.py::test_cardano_sign_tx_validation[764824073-inputs1-outputs1-tra": "f504163122424398b008ec86cbd219e543eea7889d52651e0e69f707b4a14649", -"test_msg_cardano_sign_transaction.py::test_cardano_sign_tx_validation[764824073-inputs2-outputs2-tra": "f504163122424398b008ec86cbd219e543eea7889d52651e0e69f707b4a14649", -"test_msg_cardano_sign_tx_slip39_basic.py::test_cardano_sign_tx[1097911063-inputs2-outputs2-transacti": "32edff90a2fecf74bf7e3e46794a48924082c069b9d1e57adb531749ac71e4af", -"test_msg_cardano_sign_tx_slip39_basic.py::test_cardano_sign_tx[764824073-inputs0-outputs0-transactio": "85fb1f1bf90131d6cd04e58b2303bf8d3b9a641b1f418852bc27c4432d427976", -"test_msg_cardano_sign_tx_slip39_basic.py::test_cardano_sign_tx[764824073-inputs1-outputs1-transactio": "15f55a8fc499364aa239c319100072d16ae5dc1ee9dd0db3cd1795363fde679a", "test_msg_change_wipe_code_t2.py::test_set_pin_to_wipe_code": "9e11b251c03ef09127da79d92f8483c4db438c7303328774790d45e3f6fb8c96", "test_msg_change_wipe_code_t2.py::test_set_remove_wipe_code": "d280ed129a2ea4781af9e35542aa31ecf63da75fc6812ed3bd05107809f836a4", "test_msg_change_wipe_code_t2.py::test_set_wipe_code_mismatch": "32c808f00bada2059f933f3515337e494c837bdf65e4ea918b457d1c9f4cb42a",