Ethereum Test Tools Package¶
Module containing tools for generating cross-client Ethereum execution layer tests.
CalldataCase
¶
Bases: Case
Small helper class to represent a single case whose condition depends on the value of the contract's calldata in a Switch case statement.
By default the calldata is read from position zero, but this can be
overridden using position.
The condition is generated automatically based on the value (and
optionally position) and may not be set directly.
Source code in packages/testing/src/execution_testing/tools/tools_code/generators.py
322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 | |
__init__(value, position=0, **kwargs)
¶
Generate the condition base on value and position.
Source code in packages/testing/src/execution_testing/tools/tools_code/generators.py
334 335 336 337 338 339 | |
Case
dataclass
¶
Small helper class to represent a single, generic case in a Switch cases
list.
Source code in packages/testing/src/execution_testing/tools/tools_code/generators.py
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 | |
is_terminating
property
¶
Returns whether the case is terminating.
CodeGasMeasure
¶
Bases: Bytecode
Helper class used to generate bytecode that measures gas usage of a bytecode, taking into account and subtracting any extra overhead gas costs required to execute. By default, the result gas calculation is saved to storage key 0.
Source code in packages/testing/src/execution_testing/tools/tools_code/generators.py
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 | |
code
instance-attribute
¶
Bytecode to be executed to measure the gas usage.
overhead_cost
instance-attribute
¶
Extra gas cost to be subtracted from extra operations.
extra_stack_items
instance-attribute
¶
Extra stack items that remain at the end of the execution. To be considered when subtracting the value of the previous GAS operation, and to be popped at the end of the execution.
sstore_key
instance-attribute
¶
Storage key to save the gas used.
__new__(*, code, overhead_cost=0, extra_stack_items=0, sstore_key=0, stop=True)
¶
Assemble the bytecode that measures gas usage.
Source code in packages/testing/src/execution_testing/tools/tools_code/generators.py
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 | |
Conditional
¶
Bases: Bytecode
Helper class used to generate conditional bytecode.
Source code in packages/testing/src/execution_testing/tools/tools_code/generators.py
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 | |
__new__(*, condition, if_true=None, if_false=None)
¶
Assemble the conditional bytecode by generating the necessary jump and jumpdest opcodes surrounding the condition and the two possible execution paths.
In the future, PC usage should be replaced by using RJUMP and RJUMPI
Source code in packages/testing/src/execution_testing/tools/tools_code/generators.py
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 | |
Create2PreimageLayout
¶
Bases: Bytecode
Set up the preimage in memory for CREATE2 address computation.
Creates the standard memory layout required to compute a CREATE2 address using keccak256(0xFF ++ factory_address ++ salt ++ init_code_hash).
Memory layout after execution: - MEM[offset + 0: offset + 32] = zero padding + factory_address (20 bytes) - MEM[offset + 11] = 0xFF prefix byte - MEM[offset + 32: offset + 64] = salt (32 bytes) - MEM[offset + 64: offset + 96] = init_code_hash (32 bytes)
To compute the CREATE2 address, use: .address_op or
Op.SHA3(offset + 11, 85).
The resulting hash's lower 20 bytes (bytes 12-31) form the address.
Source code in packages/testing/src/execution_testing/tools/tools_code/generators.py
438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 | |
__new__(*, factory_address, salt, init_code_hash, offset=0, old_memory_size=0)
¶
Assemble the bytecode that sets up the memory layout for CREATE2 address computation.
Source code in packages/testing/src/execution_testing/tools/tools_code/generators.py
458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 | |
salt_offset
property
¶
Return the salt memory offset of the preimage.
address_op()
¶
Return the bytecode that computes the CREATE2 address.
Source code in packages/testing/src/execution_testing/tools/tools_code/generators.py
496 497 498 499 500 501 502 503 504 505 | |
increment_salt_op(increment=1)
¶
Return the bytecode that increments the current salt.
Source code in packages/testing/src/execution_testing/tools/tools_code/generators.py
507 508 509 510 511 512 | |
CreatePreimageLayout
¶
Bases: Bytecode
Set up the preimage in memory for CREATE address computation.
Create the standard memory layout required to compute a CREATE address using keccak256(rlp.encode([sender_address, nonce])).
Memory layout after execution: - MEM[offset + 10] = RLP list prefix byte - MEM[offset + 11] = 0x94 (RLP prefix for 20-byte string) - MEM[offset + 12: offset + 32] = sender_address (20 bytes) - MEM[offset + 32:] = RLP-encoded nonce bytes - MEM[offset + 64: offset + 96] = preimage_size - MEM[offset + 96: offset + 128] = raw nonce (scratch)
Supported nonce range: 1 to 2^64 - 1. Requires Osaka (CLZ opcode).
To compute the CREATE address, use .address_op().
The resulting hash's lower 20 bytes form the address.
Source code in packages/testing/src/execution_testing/tools/tools_code/generators.py
621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 | |
__new__(*, sender_address, nonce, offset=0, old_memory_size=0)
¶
Assemble the bytecode that sets up the memory layout for CREATE address computation.
Source code in packages/testing/src/execution_testing/tools/tools_code/generators.py
647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 | |
nonce_offset
property
¶
Return the nonce memory offset of the preimage.
address_op()
¶
Return bytecode that computes the CREATE address.
Source code in packages/testing/src/execution_testing/tools/tools_code/generators.py
682 683 684 685 686 687 688 689 690 691 692 | |
set_nonce_op(nonce)
¶
Re-encode a nonce and update the memory layout.
Update the RLP list prefix, encoded nonce, and preimage_size in memory. The sender address and 0x94 prefix are unchanged.
Source code in packages/testing/src/execution_testing/tools/tools_code/generators.py
694 695 696 697 698 699 700 701 702 | |
increment_nonce_op(increment=1)
¶
Increment the nonce, re-encode, and update memory.
Read the raw nonce from scratch memory, add the increment, and re-encode.
Source code in packages/testing/src/execution_testing/tools/tools_code/generators.py
704 705 706 707 708 709 710 711 712 | |
FixedIterationsBytecode
¶
Bases: IteratingBytecode
Bytecode that contains a setup phase, an iterating phase, and a cleanup phase, with a fixed number of iterations.
This type can be used in place of a normal Bytecode and will return the appropriate gas cost for the given number of iterations.
Source code in packages/testing/src/execution_testing/tools/tools_code/generators.py
1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 | |
iteration_count
instance-attribute
¶
The fixed number of times the iterating bytecode will be executed.
__new__(*, setup, iterating, cleanup, iteration_count, warm_iterating=None, iterating_subcall=None)
¶
Create a new FixedIterationsBytecode instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
setup
|
Bytecode
|
Bytecode executed once at the beginning before iterations start. |
required |
iterating
|
Bytecode
|
Bytecode executed in the first iteration. |
required |
cleanup
|
Bytecode
|
Bytecode executed once at the end after all iterations complete. |
required |
iteration_count
|
int
|
The fixed number of times the iterating bytecode will be executed. |
required |
warm_iterating
|
Bytecode | None
|
Bytecode executed in subsequent iterations after the first. If None, uses the same bytecode as iterating. |
None
|
iterating_subcall
|
Bytecode | int | None
|
Analytical bytecode representing a subcall performed during each iteration. This bytecode is not included in the final bytecode, and it's only used for gas calculation. The value can also be an integer, in which case it represents the gas cost of the subcall (e.g. the subcall is a precompiled contract). |
None
|
Returns:
| Type | Description |
|---|---|
Self
|
A new FixedIterationsBytecode instance. |
Source code in packages/testing/src/execution_testing/tools/tools_code/generators.py
1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 | |
gas_cost(fork)
¶
Return the cost of iterating through the bytecode N times.
Source code in packages/testing/src/execution_testing/tools/tools_code/generators.py
1354 1355 1356 1357 1358 1359 | |
Initcode
¶
Bases: Bytecode
Helper class used to generate initcode for the specified deployment code.
The execution gas cost of the initcode is calculated, and also the deployment gas costs for the deployed code.
The initcode can be padded to a certain length if necessary, which does not affect the deployed code.
Other costs such as the CREATE2 hashing costs or the initcode_word_cost of EIP-3860 are not taken into account by any of these calculated costs.
Source code in packages/testing/src/execution_testing/tools/tools_code/generators.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | |
deploy_code
instance-attribute
¶
Bytecode to be deployed by the initcode.
__new__(*, deploy_code=None, initcode_length=None, initcode_prefix=None, padding_byte=0, name='')
¶
Generate an initcode that returns a contract with the specified code. The initcode can be padded to a specified length for testing purposes.
Source code in packages/testing/src/execution_testing/tools/tools_code/generators.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | |
execution_gas(fork)
¶
Gas cost of executing the initcode, charged before the code deposit fee.
Source code in packages/testing/src/execution_testing/tools/tools_code/generators.py
111 112 113 114 115 116 | |
deployment_gas(fork)
¶
Gas cost of deploying the contract.
Source code in packages/testing/src/execution_testing/tools/tools_code/generators.py
118 119 120 121 122 123 124 | |
IteratingBytecode
¶
Bases: Bytecode
Bytecode composed of distinct execution phases: setup, iteration, and cleanup.
Some phases (warm_iterating and iterating_subcall) are analytical only and exist solely to model gas costs; they are not emitted in the final bytecode.
Source code in packages/testing/src/execution_testing/tools/tools_code/generators.py
776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 | |
setup
instance-attribute
¶
Bytecode executed once at the beginning before iterations start.
iterating
instance-attribute
¶
Bytecode executed in the first iteration.
warm_iterating
instance-attribute
¶
Analytical bytecode representing subsequent iterations after the first (warm state). This bytecode is not included in the final bytecode, and it's only used for the gas accounting properties of its opcodes and therefore gas calculation.
iterating_subcall
instance-attribute
¶
Analytical bytecode representing a subcall performed during each iteration. This bytecode is not included in the final bytecode, and it's only used for gas calculation.
The value can also be an integer, in which case it represents the gas cost of the subcall (e.g. the subcall is a precompiled contract)
cleanup
instance-attribute
¶
Bytecode executed once at the end after all iterations complete.
__new__(*, setup=None, iterating, cleanup=None, warm_iterating=None, iterating_subcall=None)
¶
Create a new iterating bytecode.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
setup
|
Bytecode | None
|
Bytecode executed once at the beginning before iterations start. |
None
|
iterating
|
Bytecode
|
Bytecode executed in the first iteration. |
required |
cleanup
|
Bytecode | None
|
Bytecode executed once at the end after all iterations complete. |
None
|
warm_iterating
|
Bytecode | None
|
Analytical bytecode representing subsequent iterations after the first (warm state). |
None
|
iterating_subcall
|
Bytecode | int | None
|
Analytical bytecode representing a subcall performed during each iteration. This bytecode is not included in the final bytecode, and it's only used for gas calculation. The value can also be an integer, in which case it represents the gas cost of the subcall (e.g. the subcall is a precompiled contract). |
None
|
Returns:
| Type | Description |
|---|---|
Self
|
A new IteratingBytecode instance. |
Source code in packages/testing/src/execution_testing/tools/tools_code/generators.py
810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 | |
iterating_subcall_gas_cost(*, fork)
¶
Return the gas cost of the iterating subcall.
Source code in packages/testing/src/execution_testing/tools/tools_code/generators.py
865 866 867 868 869 870 871 | |
iterating_subcall_reserve(*, fork)
¶
Return the gas reserve needed so that the last iterating subcall does not fail due to the 63/64 rule.
Source code in packages/testing/src/execution_testing/tools/tools_code/generators.py
873 874 875 876 877 878 879 880 881 882 883 | |
gas_cost_by_iteration_count(*, fork, iteration_count)
¶
Return the cost of iterating through the bytecode N times.
Source code in packages/testing/src/execution_testing/tools/tools_code/generators.py
885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 | |
with_fixed_iteration_count(*, iteration_count)
¶
Return a new FixedIterationsBytecode with the iteration count fixed.
Source code in packages/testing/src/execution_testing/tools/tools_code/generators.py
907 908 909 910 911 912 913 914 915 916 917 918 919 920 | |
tx_gas_cost_by_iteration_count(*, fork, iteration_count, start_iteration=0, **intrinsic_cost_kwargs)
¶
Calculate the exact gas cost of a transaction calling the bytecode for a given number of iterations.
The method accepts intrinsic gas cost kwargs to allow for the calculation of the intrinsic gas cost of the transaction.
If any of the intrinsic gas cost kwarg is callable, it will be called with iteration_count and start_iteration as keyword arguments.
Source code in packages/testing/src/execution_testing/tools/tools_code/generators.py
925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 | |
tx_gas_limit_by_iteration_count(*, fork, iteration_count, start_iteration=0, **intrinsic_cost_kwargs)
¶
Calculate the minimum gas limit of a transaction calling the bytecode for a given number of iterations.
The gas limit is calculated by adding the required extra gas for the last iteration due to the 63/64 rule.
Source code in packages/testing/src/execution_testing/tools/tools_code/generators.py
966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 | |
tx_iterations_by_gas_limit(*, fork, gas_limit, start_iteration=0, **intrinsic_cost_kwargs)
¶
Calculate the number of iterations needed to reach the given a gas-to-be-used value.
Each element of the returned list represents the number of iterations for a single transaction.
If the fork's transaction gas limit cap is not None, the returned
list will contain one item per transaction that represents the
iteration count for that transaction, and no transaction will exceed
the gas limit cap.
Source code in packages/testing/src/execution_testing/tools/tools_code/generators.py
1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 | |
tx_iterations_by_total_iteration_count(*, fork, total_iterations, start_iteration=0, **intrinsic_cost_kwargs)
¶
Calculate how to split a total number of iterations across multiple transactions so that each transaction fits within the gas limit cap.
Returns a list where each element represents the number of iterations for that transaction, and the sum equals total_iterations.
Source code in packages/testing/src/execution_testing/tools/tools_code/generators.py
1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 | |
transactions_by_gas_limit(*, fork, gas_limit, start_iteration=0, sender, to, tx_gas_limit_delta=0, **tx_kwargs)
¶
Generate a list of transactions calling the bytecode with a given gas limit.
The method accepts all keyword arguments that can be passed to the
Transaction constructor.
If any of the keyword arguments is callable, it will be called with iteration_count and start_iteration as keyword arguments. E.g. when the calldata that needs to be passed to the iterating bytecode changes with each iteration, the calldata can be generated dynamically by passing a callable to the calldata keyword argument.
The returned object also contains an extra field with the expected gas cost of the transaction by the end of execution.
Source code in packages/testing/src/execution_testing/tools/tools_code/generators.py
1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 | |
transactions_by_total_iteration_count(*, fork, total_iterations, start_iteration=0, sender, to, tx_gas_limit_delta=0, **tx_kwargs)
¶
Generate a list of transactions calling the bytecode with a given total iteration count.
The method accepts all keyword arguments that can be passed to the
Transaction constructor.
If any of the keyword arguments is callable, it will be called with iteration_count and start_iteration as keyword arguments. E.g. when the calldata that needs to be passed to the iterating bytecode changes with each iteration, the calldata can be generated dynamically by passing a callable to the calldata keyword argument.
The returned object also contains an extra field with the expected gas cost of the transaction by the end of execution.
Source code in packages/testing/src/execution_testing/tools/tools_code/generators.py
1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 | |
SequentialAddressLayout
¶
Bases: Bytecode
Set up sequential address iteration in memory.
Store a starting address in a single memory word and provide methods to read the current address and advance to the next one.
Memory layout after execution: - MEM[offset: offset + 32] = current address
To obtain the address, use .address_op() which returns
Op.MLOAD(offset).
Source code in packages/testing/src/execution_testing/tools/tools_code/generators.py
715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 | |
__new__(*, starting_address=4096, offset=0, old_memory_size=0, increment=1)
¶
Assemble the bytecode that stores the starting address in memory.
Source code in packages/testing/src/execution_testing/tools/tools_code/generators.py
732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 | |
address_op()
¶
Return bytecode that loads the current address from memory.
Source code in packages/testing/src/execution_testing/tools/tools_code/generators.py
757 758 759 | |
increment_address_op(increment=None)
¶
Return bytecode that advances to the next address.
Source code in packages/testing/src/execution_testing/tools/tools_code/generators.py
761 762 763 764 765 766 767 | |
Switch
¶
Bases: Bytecode
Helper class used to generate switch-case expressions in EVM bytecode.
Switch-case behavior
-
If no condition is met in the list of BytecodeCases conditions, the
default_actionbytecode is executed. -
If multiple conditions are met, the action from the first valid condition is the only one executed.
-
There is no fall through; it is not possible to execute multiple actions.
Source code in packages/testing/src/execution_testing/tools/tools_code/generators.py
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 | |
default_action
instance-attribute
¶
The default bytecode to execute; if no condition is met, this bytecode is executed.
cases
instance-attribute
¶
A list of Cases: The first element with a condition that evaluates to a non-zero value is the one that is executed.
__new__(*, default_action=None, cases)
¶
Assemble the bytecode by looping over the list of cases and adding the necessary [R]JUMPI and JUMPDEST opcodes in order to replicate switch-case behavior.
Source code in packages/testing/src/execution_testing/tools/tools_code/generators.py
369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 | |
TransactionWithCost
¶
Bases: Transaction
Transaction object that can include the expected gas to be consumed.
Source code in packages/testing/src/execution_testing/tools/tools_code/generators.py
770 771 772 773 | |
While
¶
Bases: Bytecode
Helper class used to generate while-loop bytecode.
Source code in packages/testing/src/execution_testing/tools/tools_code/generators.py
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 | |
__new__(*, body, condition=None)
¶
Assemble the loop bytecode.
The condition nor the body can leave a stack item on the stack.
Source code in packages/testing/src/execution_testing/tools/tools_code/generators.py
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 | |
WhileGas
¶
Bases: Bytecode
Helper class to generate a gas-bounded while-loop.
Similar to While but automatically generates a condition that checks whether there is sufficient remaining gas for another iteration.
Source code in packages/testing/src/execution_testing/tools/tools_code/generators.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 | |
__new__(*, body, fork, extra_gas=0)
¶
Assemble the loop bytecode with an automatic gas check condition.
The loop continues while the remaining gas exceeds the cost of one full iteration (body + loop overhead + extra_gas).
Source code in packages/testing/src/execution_testing/tools/tools_code/generators.py
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 | |
DeploymentTestType
¶
Bases: StrEnum
Represents the type of deployment test.
Source code in packages/testing/src/execution_testing/tools/utility/generators.py
21 22 23 24 25 26 | |
gas_test(*, fork, state_test, pre, setup_code, subject_code, subject_code_warm=None, tear_down_code=None, cold_gas=None, warm_gas=None, subject_address=None, subject_balance=0, oog_difference=1, out_of_gas_testing=True, prelude_code=None, tx_gas=None)
¶
Create State Test to check the gas cost of a sequence of code.
setup_code and tear_down_code are called multiple times during the
test, and MUST NOT have any side-effects which persist across message
calls, and in particular, any effects on the gas usage of subject_code.
Source code in packages/testing/src/execution_testing/tools/utility/generators.py
453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 | |
generate_system_contract_deploy_test(*, fork, tx_json_path, expected_deploy_address, fail_on_empty_code, expected_system_contract_storage=None)
¶
Generate a test that verifies the correct deployment of a system contract.
Generates following test cases:
| before/after fork | fail on | invalid block |
empty block | |
--------------------|-------------------|--------------|----------------|
deploy_before_fork-| before | False | False |
nonzero_balance
deploy_before_fork-| before | True | False |
zero_balance
deploy_on_fork_ | on fork block | False | False |
block-nonzero_
balance
deploy_on_fork_ | on fork block | True | False |
block-zero_balance
deploy_after_fork | after | False | False |
-nonzero_balance
deploy_after_fork | after | True | True |
-zero_balance
The has balance parametrization does not have an effect on the
expectation of the test.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fork
|
Fork
|
The fork to test. |
required |
tx_json_path
|
Path
|
Path to the JSON file with the transaction to deploy the system contract. Providing a JSON file is useful to copy-paste the transaction from the EIP. |
required |
expected_deploy_address
|
Address
|
The expected address of the deployed contract. |
required |
fail_on_empty_code
|
bool
|
If True, the test is expected to fail on empty code. |
required |
expected_system_contract_storage
|
Dict | None
|
The expected storage of the system contract. |
None
|
Source code in packages/testing/src/execution_testing/tools/utility/generators.py
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 | |
generate_system_contract_error_test(*, max_gas_limit)
¶
Generate a test that verifies the correct behavior when a system contract fails execution.
Parametrizations required: - system_contract (Address): The address of the system contract to deploy. - valid_from (Fork): The fork from which the test is valid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_gas_limit
|
int
|
The maximum gas limit for the system transaction. |
required |
Source code in packages/testing/src/execution_testing/tools/utility/generators.py
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 | |
extend_with_defaults(defaults, cases, **parametrize_kwargs)
¶
Extend test cases with default parameter values.
This utility function extends test case parameters by adding default values
from the defaults dictionary to each case in the cases list. If a case
already specifies a value for a parameter, its default is ignored.
This function is particularly useful in scenarios where you want to define a common set of default values but allow individual test cases to override them as needed.
The function returns a dictionary that can be directly unpacked and passed
to the @pytest.mark.parametrize decorator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
defaults
|
Dict[str, Any]
|
A dictionary of default parameter names and their values. These values will be added to each case unless the case already defines a value for each parameter. |
required |
cases
|
List[ParameterSet]
|
A list of |
required |
parametrize_kwargs
|
Any
|
Additional keyword arguments to be passed to
|
{}
|
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dict[str, Any]: A dictionary with the following structure:
|
Example:
@pytest.mark.parametrize(**extend_with_defaults(
defaults=dict(
min_value=0, # default minimum value is 0
max_value=100, # default maximum value is 100
average=50, # default average value is 50
),
cases=[
pytest.param(
dict(), # use default
values id='default_case',
),
pytest.param(
dict(min_value=10), # override with min_value=10
id='min_value_10',
),
pytest.param(
dict(max_value=200), # override with max_value=200
id='max_value_200',
),
pytest.param(
dict(min_value=-10, max_value=50), # override both min_value
# and max_value
id='min_-10_max_50',
),
pytest.param(
# all defaults are overridden
dict(min_value=20, max_value=80, average=50),
id="min_20_max_80_avg_50",
),
pytest.param(
dict(min_value=100, max_value=0), # invalid range
id='invalid_range',
marks=pytest.mark.xfail(reason='invalid range'),
)
],
))
def test_range(min_value, max_value, average):
assert min_value <= max_value
assert min_value <= average <= max_value
The above test will execute with the following sets of parameters:
"default_case": {"min_value": 0, "max_value": 100, "average": 50}
"min_value_10": {"min_value": 10, "max_value": 100, "average": 50}
"max_value_200": {"min_value": 0, "max_value": 200, "average": 50}
"min_-10_max_50": {"min_value": -10, "max_value": 50, "average": 50}
"min_20_max_80_avg_50": {"min_value": 20, "max_value": 80, "average": 50}
# expected to fail
"invalid_range": {"min_value": 100, "max_value": 0, "average": 50}
Notes:
- Each case in cases must contain exactly one value, which is a
dictionary of parameter values.
- The function performs an in-place update of the cases list, so
the original cases list is modified.
Source code in packages/testing/src/execution_testing/tools/utility/pytest.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | |
get_current_commit_hash_or_tag(repo_path='.', shorten_hash=False)
¶
Get the latest commit tag or commit hash from the repository.
If a tag points to the current commit, return the tag name. If no tag exists: - If shorten_hash is True, return the first 8 characters of the commit hash. - Otherwise, return the full commit hash.
Source code in packages/testing/src/execution_testing/tools/utility/versioning.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | |