1+ # pylint: disable=too-many-lines
2+ # Large test file containing multiple test cases for EIP-712 signing
13import fnmatch
24import os
35from pathlib import Path
911import pytest
1012from eth_account .messages import encode_typed_data
1113from constants import ABIS_FOLDER
14+ from test_gcs import compute_inst_hash
15+ from fields_utils import get_all_tuple_array_paths , get_all_paths
16+
1217import web3
1318
1419from ragger .backend import BackendInterface
2530from client .proxy_info import ProxyInfo
2631
2732from client .gcs import (
28- Field , ParamType , ParamRaw , Value , TypeFamily , DataPath , PathTuple , ParamTrustedName ,
29- ParamNFT , ParamDatetime , DatetimeType , ParamTokenAmount , ParamToken , ParamCalldata ,
30- ParamAmount , ContainerPath , PathLeaf , PathLeafType , PathRef , PathArray , TxInfo
33+ Field , ParamRaw , Value , TypeFamily , DataPath , PathTuple , ParamTokenAmount , ParamCalldata ,
34+ ContainerPath , PathLeaf , PathLeafType , TxInfo
3135)
3236
3337
@@ -375,13 +379,12 @@ def data_set_fixture(request) -> DataSet:
375379
376380
377381def test_eip712_advanced_filtering (scenario_navigator : NavigateWithScenario ,
378- test_name : str ,
379382 data_set : DataSet ,
380383 verbose_raw : bool ):
381384 if verbose_raw and data_set .suffix :
382385 pytest .skip ("Skipping Verbose mode for this data sets" )
383386
384- snapshots_dirname = test_name + data_set .suffix
387+ snapshots_dirname = scenario_navigator . test_name + data_set .suffix
385388 if verbose_raw :
386389 settings_toggle (scenario_navigator .backend .device , scenario_navigator .navigator , [SettingID .DISPLAY_HASH ])
387390 snapshots_dirname += "-verbose"
@@ -390,7 +393,6 @@ def test_eip712_advanced_filtering(scenario_navigator: NavigateWithScenario,
390393
391394
392395def test_eip712_filtering_empty_array (scenario_navigator : NavigateWithScenario ,
393- test_name : str ,
394396 simu_params : Optional [TxSimu ] = None ):
395397 app_client = EthAppClient (scenario_navigator .backend )
396398
@@ -466,7 +468,7 @@ def test_eip712_filtering_empty_array(scenario_navigator: NavigateWithScenario,
466468 response = app_client .provide_tx_simulation (simu_params )
467469 assert response .status == StatusWord .OK
468470
469- eip712_new_common (scenario_navigator , data , filters , test_name , with_warning = bool (simu_params is not None ))
471+ eip712_new_common (scenario_navigator , data , filters , scenario_navigator . test_name , with_warning = bool (simu_params is not None ))
470472
471473
472474TOKENS = [
@@ -497,9 +499,8 @@ def tokens_fixture(request) -> list[dict]:
497499
498500
499501def test_eip712_advanced_missing_token (scenario_navigator : NavigateWithScenario ,
500- test_name : str ,
501502 tokens : list [dict ]):
502- test_name + = f"-{ len (tokens [0 ]) == 0 } -{ len (tokens [1 ]) == 0 } "
503+ test_name = f"{ scenario_navigator . test_name } -{ len (tokens [0 ]) == 0 } -{ len (tokens [1 ]) == 0 } "
503504
504505 data = {
505506 "types" : {
@@ -583,10 +584,9 @@ def filt_tn_types_fixture(request) -> list[TrustedNameType]:
583584
584585
585586def test_eip712_advanced_trusted_name (scenario_navigator : NavigateWithScenario ,
586- test_name : str ,
587587 trusted_name : tuple ,
588588 filt_tn_types : list [TrustedNameType ]):
589- test_name + = f"_{ trusted_name [0 ].name .lower ()} _with"
589+ test_name = f"{ scenario_navigator . test_name } _{ trusted_name [0 ].name .lower ()} _with"
590590 for t in filt_tn_types :
591591 test_name += f"_{ t .name .lower ()} "
592592
@@ -706,15 +706,13 @@ def gcs_handler(app_client: EthAppClient, json_data: dict) -> None:
706706 ),
707707 ]
708708 # compute instructions hash
709- inst_hash = hashlib .sha3_256 ()
710- for field in fields :
711- inst_hash .update (field .serialize ())
709+ inst_hash = compute_inst_hash (fields )
712710 tx_info = TxInfo (
713711 1 ,
714712 json_data ["domain" ]["chainId" ],
715713 bytes .fromhex (json_data ["message" ]["to" ][2 :]),
716714 get_selector_from_data (json_data ["message" ]["data" ]),
717- inst_hash . digest () ,
715+ inst_hash ,
718716 "Token transfer" ,
719717 contract_name = "USDC" ,
720718 )
@@ -728,8 +726,7 @@ def gcs_handler(app_client: EthAppClient, json_data: dict) -> None:
728726
729727def gcs_handler_batch (app_client : EthAppClient , json_data : dict ) -> None :
730728 # Load EIP-712 JSON data
731- filename = "safe_batch"
732- with open (f"{ eip712_json_path ()} /{ filename } .json" , encoding = "utf-8" ) as file :
729+ with open (f"{ eip712_json_path ()} /safe_batch.json" , encoding = "utf-8" ) as file :
733730 data = json .load (file )
734731
735732 # Define tokens
@@ -780,7 +777,7 @@ def gcs_handler_batch(app_client: EthAppClient, json_data: dict) -> None:
780777 ]])
781778
782779 # Top level transaction fields definition
783- # Intermediate execTransaction transaction fields definition
780+ param_paths = get_all_tuple_array_paths ( f" { ABIS_FOLDER } /batch.json" , "batchExecute" , "calls" )
784781 L0_fields = [
785782 Field (
786783 1 ,
@@ -792,62 +789,38 @@ def gcs_handler_batch(app_client: EthAppClient, json_data: dict) -> None:
792789 TypeFamily .BYTES ,
793790 data_path = DataPath (
794791 1 ,
795- [
796- PathTuple (0 ),
797- PathRef (),
798- PathArray (),
799- PathRef (),
800- PathTuple (2 ),
801- PathRef (),
802- PathLeaf (PathLeafType .DYNAMIC ),
803- ]
792+ param_paths ["data" ]
804793 ),
805794 ),
806795 Value (
807796 1 ,
808797 TypeFamily .ADDRESS ,
809798 data_path = DataPath (
810799 1 ,
811- [
812- PathTuple (0 ),
813- PathRef (),
814- PathArray (),
815- PathRef (),
816- PathTuple (0 ),
817- PathLeaf (PathLeafType .STATIC ),
818- ]
800+ param_paths ["to" ]
819801 ),
820802 ),
821803 amount = Value (
822804 1 ,
823805 TypeFamily .UINT ,
824806 data_path = DataPath (
825807 1 ,
826- [
827- PathTuple (0 ),
828- PathRef (),
829- PathArray (),
830- PathRef (),
831- PathTuple (1 ),
832- PathLeaf (PathLeafType .STATIC ),
833- ]
808+ param_paths ["value" ]
834809 ),
835810 ),
836811 )
837812 ),
838813 ]
839814 # compute instructions hash
840- L0_hash = hashlib .sha3_256 ()
841- for field in L0_fields :
842- L0_hash .update (field .serialize ())
815+ L0_hash = compute_inst_hash (L0_fields )
843816
844817 # Define intermediate execTransaction transaction info
845818 L0_tx_info = TxInfo (
846819 1 ,
847820 data ["domain" ]["chainId" ],
848821 bytes .fromhex (json_data ["domain" ]["verifyingContract" ][2 :]),
849822 get_selector_from_data (batchData ),
850- L0_hash . digest () ,
823+ L0_hash ,
851824 "Batch transactions" ,
852825 creator_name = "Ledger" ,
853826 creator_legal_name = "Ledger Multisig" ,
@@ -856,6 +829,7 @@ def gcs_handler_batch(app_client: EthAppClient, json_data: dict) -> None:
856829 )
857830
858831 # Lower batchExecute transaction fields definition
832+ param_paths = get_all_paths (f"{ ABIS_FOLDER } /erc20.json" , "transfer" )
859833 L1_fields = [
860834 Field (
861835 1 ,
@@ -867,10 +841,7 @@ def gcs_handler_batch(app_client: EthAppClient, json_data: dict) -> None:
867841 TypeFamily .UINT ,
868842 data_path = DataPath (
869843 1 ,
870- [
871- PathTuple (1 ),
872- PathLeaf (PathLeafType .STATIC ),
873- ]
844+ param_paths ["_value" ]
874845 ),
875846 type_size = 32 ,
876847 ),
@@ -891,19 +862,14 @@ def gcs_handler_batch(app_client: EthAppClient, json_data: dict) -> None:
891862 TypeFamily .ADDRESS ,
892863 data_path = DataPath (
893864 1 ,
894- [
895- PathTuple (0 ),
896- PathLeaf (PathLeafType .STATIC ),
897- ]
865+ param_paths ["_to" ]
898866 ),
899867 )
900868 )
901869 ),
902870 ]
903871 # compute instructions hash
904- L1_hash = hashlib .sha3_256 ()
905- for sub_field in L1_fields :
906- L1_hash .update (sub_field .serialize ())
872+ L1_hash = compute_inst_hash (L1_fields )
907873
908874 # Define lower batchExecute transaction info
909875 L1_tx_info = [
@@ -912,7 +878,7 @@ def gcs_handler_batch(app_client: EthAppClient, json_data: dict) -> None:
912878 data ["domain" ]["chainId" ],
913879 tokens [0 ]["address" ],
914880 get_selector_from_data (tokenData0 ),
915- L1_hash . digest () ,
881+ L1_hash ,
916882 "Send" ,
917883 contract_name = "USD_Coin" ,
918884 ),
@@ -921,7 +887,7 @@ def gcs_handler_batch(app_client: EthAppClient, json_data: dict) -> None:
921887 data ["domain" ]["chainId" ],
922888 tokens [1 ]["address" ],
923889 get_selector_from_data (tokenData1 ),
924- L1_hash . digest () ,
890+ L1_hash ,
925891 "Send" ,
926892 contract_name = "USD_Coin" ,
927893 )
@@ -1090,8 +1056,7 @@ def test_eip712_gondi(scenario_navigator: NavigateWithScenario):
10901056
10911057
10921058def test_eip712_batch (scenario_navigator : NavigateWithScenario ):
1093- filename = "safe_batch"
1094- with open (f"{ eip712_json_path ()} /{ filename } .json" , encoding = "utf-8" ) as file :
1059+ with open (f"{ eip712_json_path ()} /safe_batch.json" , encoding = "utf-8" ) as file :
10951060 data = json .load (file )
10961061
10971062 filters = {
0 commit comments