From 62215e3e5f091bce423b140bcadd256e712afd36 Mon Sep 17 00:00:00 2001 From: Alexandre Paillier Date: Thu, 9 Nov 2023 15:30:21 +0100 Subject: [PATCH] Now uses Web3.py to get function selectors --- client/src/ledger_app_clients/ethereum/utils.py | 5 ----- tests/ragger/test_nft.py | 16 ++++++++-------- 2 files changed, 8 insertions(+), 13 deletions(-) delete mode 100644 client/src/ledger_app_clients/ethereum/utils.py diff --git a/client/src/ledger_app_clients/ethereum/utils.py b/client/src/ledger_app_clients/ethereum/utils.py deleted file mode 100644 index e617745..0000000 --- a/client/src/ledger_app_clients/ethereum/utils.py +++ /dev/null @@ -1,5 +0,0 @@ -import sha3 - - -def get_selector_from_function(fn: str) -> bytes: - return sha3.keccak_256(fn.encode()).digest()[0:4] diff --git a/tests/ragger/test_nft.py b/tests/ragger/test_nft.py index bba13cf..1a96a53 100644 --- a/tests/ragger/test_nft.py +++ b/tests/ragger/test_nft.py @@ -7,7 +7,7 @@ from ragger.backend import BackendInterface from ragger.navigator import Navigator, NavInsID from ledger_app_clients.ethereum.client import EthAppClient, TxData, StatusWord from ledger_app_clients.ethereum.settings import SettingID, settings_toggle -from ledger_app_clients.ethereum.utils import get_selector_from_function +from eth_utils import function_signature_to_4byte_selector import struct @@ -72,7 +72,7 @@ def common_test_nft(fw: Firmware, reject: bool, plugin_name: str): app_client = EthAppClient(back) - selector = get_selector_from_function(action.fn) + selector = function_signature_to_4byte_selector(action.fn) if app_client._client.firmware.name == "nanos": pytest.skip("Not supported on LNS") @@ -126,7 +126,7 @@ ERC721_SET_APPROVAL_FOR_ALL = "setApprovalForAll(address,bool)" def data_erc721_transfer_from(action: Action) -> TxData: return TxData( - get_selector_from_function(action.fn), + function_signature_to_4byte_selector(action.fn), [ FROM, TO, @@ -141,7 +141,7 @@ def data_erc721_safe_transfer_from_data(action: Action) -> TxData: def data_erc721_approve(action: Action) -> TxData: return TxData( - get_selector_from_function(action.fn), + function_signature_to_4byte_selector(action.fn), [ TO, struct.pack(">H", NFTS[0][0]) @@ -150,7 +150,7 @@ def data_erc721_approve(action: Action) -> TxData: def data_erc721_set_approval_for_all(action: Action) -> TxData: return TxData( - get_selector_from_function(action.fn), + function_signature_to_4byte_selector(action.fn), [ TO, struct.pack("b", False) @@ -259,7 +259,7 @@ ERC1155_SET_APPROVAL_FOR_ALL = "setApprovalForAll(address,bool)" def data_erc1155_safe_transfer_from(action: Action) -> TxData: return TxData( - get_selector_from_function(action.fn), + function_signature_to_4byte_selector(action.fn), [ FROM, TO, @@ -271,7 +271,7 @@ def data_erc1155_safe_transfer_from(action: Action) -> TxData: def data_erc1155_safe_batch_transfer_from(action: Action) -> TxData: data = TxData( - get_selector_from_function(action.fn), + function_signature_to_4byte_selector(action.fn), [ FROM, TO @@ -288,7 +288,7 @@ def data_erc1155_safe_batch_transfer_from(action: Action) -> TxData: def data_erc1155_set_approval_for_all(action: Action) -> TxData: return TxData( - get_selector_from_function(action.fn), + function_signature_to_4byte_selector(action.fn), [ TO, struct.pack("b", False)