From 8da09ec892a6bdabf622f3e0c024ccec06094a81 Mon Sep 17 00:00:00 2001 From: Coline Date: Fri, 22 Jul 2022 11:59:45 +0200 Subject: [PATCH] fix: real errors test --- tests/speculos/test_eip191.py | 6 +++--- tests/speculos/test_eip712.py | 14 +++++++------- tests/speculos/test_erc1155.py | 16 +++++++++------- tests/speculos/test_erc20information.py | 6 +++--- tests/speculos/test_erc721.py | 10 ++++++---- tests/speculos/test_pubkey_cmd.py | 11 +++++++---- tests/speculos/test_sign_cmd.py | 22 ++++++++++++---------- 7 files changed, 47 insertions(+), 38 deletions(-) diff --git a/tests/speculos/test_eip191.py b/tests/speculos/test_eip191.py index b76bad2..d24ad0b 100644 --- a/tests/speculos/test_eip191.py +++ b/tests/speculos/test_eip191.py @@ -1,5 +1,7 @@ from time import sleep +import pytest + import ethereum_client from ethereum_client.utils import compare_screenshot, compare_screenshot, parse_sign_response, save_screenshot, PATH_IMG from ethereum_client.transaction import PersonalTransaction @@ -56,7 +58,7 @@ def test_personal_sign_reject(cmd): msg="This is an reject sign" ) - try: + with pytest.raises(ethereum_client.exception.errors.DenyError) as error: with cmd.personal_sign_tx(bip32_path=bip32_path, transaction=transaction, result=result) as ex: sleep(0.5) @@ -95,8 +97,6 @@ def test_personal_sign_reject(cmd): # Cancel signature compare_screenshot(cmd, f"screenshots/eip191/{PATH_IMG[cmd.model]}/personal_sign_reject/00003.png") cmd.client.press_and_release('both') - - except ethereum_client.exception.errors.DenyError as error: assert error.args[0] == '0x6985' def test_personal_sign_non_ascii(cmd): diff --git a/tests/speculos/test_eip712.py b/tests/speculos/test_eip712.py index 2c2b3ea..6a72aa4 100644 --- a/tests/speculos/test_eip712.py +++ b/tests/speculos/test_eip712.py @@ -1,5 +1,7 @@ from time import sleep +import pytest + from ethereum_client.utils import compare_screenshot, save_screenshot, PATH_IMG, parse_sign_response from ethereum_client.transaction import EIP712 import ethereum_client @@ -81,7 +83,7 @@ def test_sign_eip_712_hashed_msg_reject(cmd): msg_hash="9d96be8a7cca396e711a3ba356bd9878df02a726d753ddb6cda3c507d888bc77" ) - try: + with pytest.raises(ethereum_client.exception.errors.DenyError) as error: with cmd.sign_eip712(bip32_path=bip32_path, transaction=transaction, result=result) as ex: sleep(0.5) @@ -142,8 +144,6 @@ def test_sign_eip_712_hashed_msg_reject(cmd): # Cancel signature compare_screenshot(cmd, f"screenshots/eip712/{PATH_IMG[cmd.model]}/sign_eip_712_hashed_msg_reject/00006.png") cmd.client.press_and_release('both') - - except ethereum_client.exception.errors.DenyError as error: assert error.args[0] == '0x6985' def test_sign_eip_712_bad_domain(cmd): @@ -155,11 +155,11 @@ def test_sign_eip_712_bad_domain(cmd): msg_hash="9d96be8a7cca396e711a3ba356bd9878df02a726d753ddb6cda3c507d888bc77" ) - try: + with pytest.raises(ethereum_client.exception.errors.UnknownDeviceError) as error: + with cmd.sign_eip712(bip32_path=bip32_path, transaction=transaction, result=result) as ex: pass - except ethereum_client.exception.errors.UnknownDeviceError as error: assert error.args[0] == '0x6a80' def test_sign_eip_712_bad_msg(cmd): @@ -171,9 +171,9 @@ def test_sign_eip_712_bad_msg(cmd): msg_hash="deadbeef" ) - try: + with pytest.raises(ethereum_client.exception.errors.UnknownDeviceError) as error: + with cmd.sign_eip712(bip32_path=bip32_path, transaction=transaction, result=result) as ex: pass - except ethereum_client.exception.errors.UnknownDeviceError as error: assert error.args[0] == '0x6a80' \ No newline at end of file diff --git a/tests/speculos/test_erc1155.py b/tests/speculos/test_erc1155.py index 26d278e..b0692ec 100644 --- a/tests/speculos/test_erc1155.py +++ b/tests/speculos/test_erc1155.py @@ -1,5 +1,7 @@ from time import sleep +import pytest + import ethereum_client from ethereum_client.utils import compare_screenshot, save_screenshot, PATH_IMG, parse_sign_response from ethereum_client.plugin import Plugin @@ -92,7 +94,8 @@ def test_transfer_erc1155_without_nft_provide_info(cmd): result: list = [] if cmd.model == "nanox" or cmd.model == "nanosp": - try: + with pytest.raises(ethereum_client.exception.errors.UnknownDeviceError) as error: + cmd.set_plugin(plugin=PLUGIN) @@ -100,24 +103,23 @@ def test_transfer_erc1155_without_nft_provide_info(cmd): with cmd.send_apdu_context(SIGN_MORE, result) as ex: pass - - except ethereum_client.exception.errors.UnknownDeviceError as error: - assert error.args[0] == '0x6a80' + + assert error.args[0] == '0x6a80' def test_transfer_erc1155_without_set_plugin(cmd): result: list = [] if cmd.model == "nanox" or cmd.model == "nanosp": - try: + with pytest.raises(ethereum_client.exception.errors.DenyError) as error: + cmd.provide_nft_information(plugin=PROVIDE_NFT_INFORMATION) cmd.send_apdu(SIGN_FIRST) with cmd.send_apdu_context(SIGN_MORE, result) as ex: pass - - except ethereum_client.exception.errors.DenyError as error: + assert error.args[0] == '0x6985' diff --git a/tests/speculos/test_erc20information.py b/tests/speculos/test_erc20information.py index 87dbee6..9af2c7b 100644 --- a/tests/speculos/test_erc20information.py +++ b/tests/speculos/test_erc20information.py @@ -1,3 +1,4 @@ +import pytest from ethereum_client.plugin import ERC20Information import ethereum_client @@ -25,7 +26,6 @@ def test_provide_erc20_token_error(cmd): sign="deadbeef" ) - try: + with pytest.raises(ethereum_client.exception.errors.UnknownDeviceError) as error: cmd.provide_erc20_token_information(info=erc20_info) - except ethereum_client.exception.errors.UnknownDeviceError as error: - assert error.args[0] == '0x6a80' \ No newline at end of file + assert error.args[0] == '0x6a80' \ No newline at end of file diff --git a/tests/speculos/test_erc721.py b/tests/speculos/test_erc721.py index 7997616..8652501 100644 --- a/tests/speculos/test_erc721.py +++ b/tests/speculos/test_erc721.py @@ -1,5 +1,7 @@ from time import sleep +import pytest + import ethereum_client from ethereum_client.utils import compare_screenshot, save_screenshot, PATH_IMG, parse_sign_response from ethereum_client.plugin import Plugin @@ -85,14 +87,15 @@ def test_transfer_erc721_without_nft_provide_info(cmd): result: list = [] if cmd.model == "nanox" or cmd.model == "nanosp": - try: + with pytest.raises(ethereum_client.exception.errors.UnknownDeviceError) as error: + cmd.set_plugin(plugin=PLUGIN) cmd.send_apdu(SIGN_FIRST) with cmd.send_apdu_context(SIGN_MORE, result) as ex: pass - except ethereum_client.exception.errors.UnknownDeviceError as error: + assert error.args[0] == '0x6a80' @@ -101,7 +104,7 @@ def test_transfer_erc721_without_set_plugin(cmd): result: list = [] if cmd.model == "nanox" or cmd.model == "nanosp": - try: + with pytest.raises(ethereum_client.exception.errors.DenyError) as error: cmd.provide_nft_information(plugin=PROVIDE_NFT_INFORMATION) cmd.send_apdu(SIGN_FIRST) @@ -109,5 +112,4 @@ def test_transfer_erc721_without_set_plugin(cmd): with cmd.send_apdu_context(SIGN_MORE, result) as ex: pass - except ethereum_client.exception.errors.DenyError as error: assert error.args[0] == '0x6985' \ No newline at end of file diff --git a/tests/speculos/test_pubkey_cmd.py b/tests/speculos/test_pubkey_cmd.py index 8e6bfca..17f1d78 100644 --- a/tests/speculos/test_pubkey_cmd.py +++ b/tests/speculos/test_pubkey_cmd.py @@ -1,5 +1,7 @@ from time import sleep +import pytest + import ethereum_client from ethereum_client.utils import compare_screenshot, save_screenshot, PATH_IMG @@ -66,9 +68,11 @@ def test_get_public_key(cmd): def test_reject_get_public_key(cmd): - try: - # DAI COIN with display - result: list = [] + # DAI COIN with display + result: list = [] + + with pytest.raises(ethereum_client.exception.errors.DenyError) as error: + with cmd.get_public_key(bip32_path="44'/700'/1'/0/0", display=True, result=result) as exchange: sleep(0.5) @@ -110,5 +114,4 @@ def test_reject_get_public_key(cmd): compare_screenshot(cmd, f"screenshots/pubkey/{PATH_IMG[cmd.model]}/reject_get_public_key/00003.png") cmd.client.press_and_release('both') - except ethereum_client.exception.errors.DenyError as error: assert error.args[0] == '0x6985' diff --git a/tests/speculos/test_sign_cmd.py b/tests/speculos/test_sign_cmd.py index 2076459..0e0207a 100644 --- a/tests/speculos/test_sign_cmd.py +++ b/tests/speculos/test_sign_cmd.py @@ -1,5 +1,7 @@ from time import sleep +import pytest + import ethereum_client from ethereum_client.utils import compare_screenshot, compare_screenshot, save_screenshot, PATH_IMG from ethereum_client.transaction import Transaction @@ -183,7 +185,8 @@ def test_sign_reject(cmd): chainID=1, ) - try: + with pytest.raises(ethereum_client.exception.errors.DenyError) as error: + with cmd.simple_sign_tx(bip32_path=bip32_path, transaction=transaction, result=result) as ex: sleep(0.5) @@ -245,7 +248,6 @@ def test_sign_reject(cmd): compare_screenshot(cmd, f"screenshots/sign/{PATH_IMG[cmd.model]}/reject/00005.png") cmd.client.press_and_release('both') - except ethereum_client.exception.errors.DenyError as error: assert error.args[0] == '0x6985' @@ -343,19 +345,18 @@ def test_sign_error_transaction_type(cmd): chainID=1, ) - try: + with pytest.raises(ethereum_client.exception.errors.UnknownDeviceError) as error: + with cmd.simple_sign_tx(bip32_path=bip32_path, transaction=transaction, result=result) as ex: pass - except ethereum_client.exception.errors.UnknownDeviceError as error: - # Throw error of transaction type not supported + assert error.args[0] == '0x6501' transaction.txType = 0x7F - try: + with pytest.raises(ethereum_client.exception.errors.UnknownDeviceError) as error: with cmd.simple_sign_tx(bip32_path=bip32_path, transaction=transaction, result=result) as ex: pass - except ethereum_client.exception.errors.UnknownDeviceError as error: - # Throw error of transaction type not supported + assert error.args[0] == '0x6501' @@ -579,7 +580,8 @@ def test_sign_blind_error_disabled(cmd): data="ok", ) - try: + with pytest.raises(ethereum_client.exception.errors.UnknownDeviceError) as error: + with cmd.simple_sign_tx(bip32_path=bip32_path, transaction=transaction, result=result) as ex: sleep(0.5) @@ -587,7 +589,7 @@ def test_sign_blind_error_disabled(cmd): pass if cmd.model == "nanox" or cmd.model == "nanosp": pass - except ethereum_client.exception.errors.UnknownDeviceError as error: + assert error.args[0] == '0x6a80'