Ethereum Test Tools Package¶
Module containing tools for generating cross-client Ethereum execution layer tests.
Code
dataclass
¶
Generic code object.
Source code in src/ethereum_test_tools/code/code.py
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 37 38 39 40 41 42 43 44 45 46 | |
bytecode: Optional[bytes] = None
instance-attribute
class-attribute
¶
bytes array that represents the bytecode of this object.
name: Optional[str] = None
instance-attribute
class-attribute
¶
Name used to describe this code. Usually used to add extra information to a test case.
assemble()
¶
Transform the Code object into bytes. Normally will be overriden by the classes that inherit this class.
Source code in src/ethereum_test_tools/code/code.py
26 27 28 29 30 31 32 33 34 | |
__add__(other)
¶
Adds two code objects together, by converting both to bytes first.
Source code in src/ethereum_test_tools/code/code.py
36 37 38 39 40 | |
__radd__(other)
¶
Adds two code objects together, by converting both to bytes first.
Source code in src/ethereum_test_tools/code/code.py
42 43 44 45 46 | |
Initcode
¶
Bases: Code
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 src/ethereum_test_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 | |
__init__(*, deploy_code, initcode_length=None, padding_byte=0, name=None)
¶
Generate legacy initcode that inits a contract with the specified code. The initcode can be padded to a specified length for testing purposes.
Source code in src/ethereum_test_tools/code/generators.py
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 | |
execution_gas: int = 0
instance-attribute
¶
Gas cost of executing the initcode, without considering deployment gas costs.
deploy_code: bytes | str | Code = deploy_code
instance-attribute
¶
Bytecode to be deployed by the initcode.
deployment_gas: int = GAS_PER_DEPLOYED_CODE_BYTE * len(deploy_code_bytes)
instance-attribute
¶
Gas cost of deploying the cost, subtracted after initcode execution,
ceiling_division(a, b)
¶
Calculates the ceil without using floating point. Used by many of the EVM's formulas
Source code in src/ethereum_test_tools/common/helpers.py
15 16 17 18 19 20 | |
fill_test(t8n, test_spec, fork, engine, spec, eips=None)
¶
Fills fixtures for the specified fork.
Source code in src/ethereum_test_tools/filling/fill.py
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 | |
compute_create_address(address, nonce)
¶
Compute address of the resulting contract created using a transaction
or the CREATE opcode.
Source code in src/ethereum_test_tools/common/helpers.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | |
EngineAPIError
¶
Bases: IntEnum
List of Engine API errors
Source code in src/ethereum_test_tools/common/constants.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | |
Opcode
¶
Bases: bytes
Represents a single Opcode instruction in the EVM, with extra metadata useful to parametrize tests.
Parameters¶
- popped_stack_items: number of items the opcode pops from the stack
- pushed_stack_items: number of items the opcode pushes to the stack
- min_stack_height: minimum stack height required by the opcode
- data_portion_length: number of bytes after the opcode in the bytecode that represent data
Source code in src/ethereum_test_tools/vm/opcode.py
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 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 | |
__new__(opcode_or_byte, *, popped_stack_items=0, pushed_stack_items=0, min_stack_height=0, data_portion_length=0)
¶
Creates a new opcode instance.
Source code in src/ethereum_test_tools/vm/opcode.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | |
__call__(*args_t)
¶
Makes all opcode instances callable to return formatted bytecode, which constitutes a data portion, that is located after the opcode byte, and pre-opcode bytecode, which is normally used to set up the stack.
This useful to automatically format, e.g., push opcodes and their
data sections as Opcodes.PUSH1(0x00).
Data sign is automatically detected but for this reason the range
of the input must be:
[-2^(data_portion_bits-1), 2^(data_portion_bits)]
where:
data_portion_bits == data_portion_length * 8
For the stack, the arguments are set up in the opposite order they are given, so the first argument is the last item pushed to the stack.
The resulting stack arrangement does not take into account opcode stack element consumption, so the stack height is not guaranteed to be correct and the user must take this into consideration.
Integers can also be used as stack elements, in which case they are automatically converted to PUSH operations, and negative numbers always use a PUSH32 operation.
Source code in src/ethereum_test_tools/vm/opcode.py
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 | |
__len__()
¶
Returns the total bytecode length of the opcode, taking into account its data portion.
Source code in src/ethereum_test_tools/vm/opcode.py
149 150 151 152 153 154 | |
int()
¶
Returns the integer representation of the opcode.
Source code in src/ethereum_test_tools/vm/opcode.py
156 157 158 159 160 | |
__str__()
¶
Return the name of the opcode, assigned at Enum creation.
Source code in src/ethereum_test_tools/vm/opcode.py
162 163 164 165 166 | |
BlockchainTest
dataclass
¶
Bases: BaseTest
Filler type that tests multiple blocks (valid or invalid) in a chain.
Source code in src/ethereum_test_tools/spec/blockchain_test.py
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 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 | |
pytest_parameter_name()
classmethod
¶
Returns the parameter name used to identify this filler in a test.
Source code in src/ethereum_test_tools/spec/blockchain_test.py
41 42 43 44 45 46 | |
make_genesis(t8n, fork)
¶
Create a genesis block from the state test definition.
Source code in src/ethereum_test_tools/spec/blockchain_test.py
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 | |
make_block(t8n, fork, block, previous_env, previous_alloc, previous_head, chain_id=1, eips=None)
¶
Produces a block based on the previous environment and allocation. If the block is an invalid block, the environment and allocation returned are the same as passed as parameters. Raises exception on invalid test behavior.
Returns¶
FixtureBlock: Block to be appended to the fixture.
Environment: Environment for the next block to produce.
If the produced block is invalid, this is exactly the same
environment as the one passed as parameter.
Dict[str, Any]: Allocation for the next block to produce.
If the produced block is invalid, this is exactly the same
allocation as the one passed as parameter.
str: Hash of the head of the chain, only updated if the produced
block is not invalid.
Source code in src/ethereum_test_tools/spec/blockchain_test.py
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 | |
make_blocks(t8n, genesis, fork, chain_id=1, eips=None)
¶
Create a block list from the blockchain test definition. Performs checks against the expected behavior of the test. Raises exception on invalid test behavior.
Source code in src/ethereum_test_tools/spec/blockchain_test.py
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 | |
ReferenceSpec
¶
Reference Specification Description Abstract Class.
Source code in src/ethereum_test_tools/reference_spec/reference_spec.py
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 | |
name()
abstractmethod
¶
Returns the name of the spec.
Source code in src/ethereum_test_tools/reference_spec/reference_spec.py
35 36 37 38 39 40 | |
has_known_version()
abstractmethod
¶
Returns true if the reference spec object is hard-coded with a latest known version.
Source code in src/ethereum_test_tools/reference_spec/reference_spec.py
42 43 44 45 46 47 48 | |
known_version()
abstractmethod
¶
Returns the latest known version in the reference.
Source code in src/ethereum_test_tools/reference_spec/reference_spec.py
50 51 52 53 54 55 | |
api_url()
abstractmethod
¶
Returns the URL required to poll the version from an API, if needed.
Source code in src/ethereum_test_tools/reference_spec/reference_spec.py
57 58 59 60 61 62 | |
latest_version()
abstractmethod
¶
Returns a digest that points to the latest version of the spec.
Source code in src/ethereum_test_tools/reference_spec/reference_spec.py
64 65 66 67 68 69 | |
is_outdated()
abstractmethod
¶
Checks whether the reference specification has been updated since the test was last updated.
Source code in src/ethereum_test_tools/reference_spec/reference_spec.py
71 72 73 74 75 76 77 | |
write_info(info)
abstractmethod
¶
Writes info about the reference specification used into the output fixture.
Source code in src/ethereum_test_tools/reference_spec/reference_spec.py
79 80 81 82 83 84 85 | |
parseable_from_module(module_dict)
staticmethod
abstractmethod
¶
Checks whether the module's dict contains required reference spec information.
Source code in src/ethereum_test_tools/reference_spec/reference_spec.py
87 88 89 90 91 92 93 94 | |
parse_from_module(module_dict)
staticmethod
abstractmethod
¶
Parses the module's dict into a reference spec.
Source code in src/ethereum_test_tools/reference_spec/reference_spec.py
96 97 98 99 100 101 102 | |
StateTest
dataclass
¶
Bases: BaseTest
Filler type that tests transactions over the period of a single block.
Source code in src/ethereum_test_tools/spec/state_test.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 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 | |
pytest_parameter_name()
classmethod
¶
Returns the parameter name used to identify this filler in a test.
Source code in src/ethereum_test_tools/spec/state_test.py
46 47 48 49 50 51 | |
make_genesis(t8n, fork)
¶
Create a genesis block from the state test definition.
Source code in src/ethereum_test_tools/spec/state_test.py
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 | |
make_blocks(t8n, genesis, fork, chain_id=1, eips=None)
¶
Create a block from the state test definition. Performs checks against the expected behavior of the test. Raises exception on invalid test behavior.
Source code in src/ethereum_test_tools/spec/state_test.py
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 | |
Yul
¶
Bases: Code
Yul compiler. Compiles Yul source code into bytecode.
Source code in src/ethereum_test_tools/code/yul.py
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 | |
assemble()
¶
Assembles using solc --assemble.
Source code in src/ethereum_test_tools/code/yul.py
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 | |
version()
¶
Return solc's version string
Source code in src/ethereum_test_tools/code/yul.py
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | |
compute_create2_address(address, salt, initcode)
¶
Compute address of the resulting contract created using the CREATE2
opcode.
Source code in src/ethereum_test_tools/common/helpers.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | |
cost_memory_bytes(new_bytes, previous_bytes)
¶
Calculates the cost of memory expansion, based on the costs specified in the yellow paper: https://ethereum.github.io/yellowpaper/paper.pdf
Source code in src/ethereum_test_tools/common/helpers.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | |
Auto
¶
Class to use as a sentinel value for parameters that should be automatically calculated.
Source code in src/ethereum_test_tools/common/types.py
68 69 70 71 72 73 74 75 76 | |
__repr__()
¶
Print the correct test id.
Source code in src/ethereum_test_tools/common/types.py
74 75 76 | |
BaseTest
¶
Represents a base Ethereum test which must return a genesis and a blockchain.
Source code in src/ethereum_test_tools/spec/base_test.py
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 | |
make_genesis(t8n, fork)
abstractmethod
¶
Create a genesis block from the test definition.
Source code in src/ethereum_test_tools/spec/base_test.py
80 81 82 83 84 85 86 87 88 89 | |
make_blocks(t8n, genesis, fork, chain_id=1, eips=None)
abstractmethod
¶
Generate the blockchain that must be executed sequentially during test.
Source code in src/ethereum_test_tools/spec/base_test.py
91 92 93 94 95 96 97 98 99 100 101 102 103 | |
pytest_parameter_name()
classmethod
abstractmethod
¶
Must return the name of the parameter used in pytest to select this spec type as filler for the test.
Source code in src/ethereum_test_tools/spec/base_test.py
105 106 107 108 109 110 111 112 | |
copy_opcode_cost(length)
¶
Calculates the cost of the COPY opcodes, assuming memory expansion from empty memory, based on the costs specified in the yellow paper: https://ethereum.github.io/yellowpaper/paper.pdf
Source code in src/ethereum_test_tools/common/helpers.py
77 78 79 80 81 82 83 | |
Storage
¶
Definition of a storage in pre or post state of a test
Source code in src/ethereum_test_tools/common/types.py
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 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 315 316 317 318 319 320 321 322 323 324 325 326 | |
StorageDictType: TypeAlias = Dict[str | int | bytes, str | int | bytes]
class-attribute
¶
Dictionary type to be used when defining an input to initialize a storage.
InvalidType
¶
Bases: Exception
Invalid type used when describing test's expected storage key or value.
Source code in src/ethereum_test_tools/common/types.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 | |
__str__()
¶
Print exception string
Source code in src/ethereum_test_tools/common/types.py
103 104 105 | |
InvalidValue
¶
Bases: Exception
Invalid value used when describing test's expected storage key or value.
Source code in src/ethereum_test_tools/common/types.py
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | |
__str__()
¶
Print exception string
Source code in src/ethereum_test_tools/common/types.py
119 120 121 | |
AmbiguousKeyValue
¶
Bases: Exception
Key is represented twice in the storage.
Source code in src/ethereum_test_tools/common/types.py
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 | |
__str__()
¶
Print exception string
Source code in src/ethereum_test_tools/common/types.py
147 148 149 150 151 152 153 | |
MissingKey
¶
Bases: Exception
Test expected to find a storage key set but key was missing.
Source code in src/ethereum_test_tools/common/types.py
155 156 157 158 159 160 161 162 163 164 165 166 167 168 | |
__str__()
¶
Print exception string
Source code in src/ethereum_test_tools/common/types.py
166 167 168 | |
KeyValueMismatch
¶
Bases: Exception
Test expected a certain value in a storage key but value found was different.
Source code in src/ethereum_test_tools/common/types.py
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 | |
__str__()
¶
Print exception string
Source code in src/ethereum_test_tools/common/types.py
186 187 188 189 190 191 192 193 194 195 196 | |
parse_key_value(input)
staticmethod
¶
Parses a key or value to a valid int key for storage.
Source code in src/ethereum_test_tools/common/types.py
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 | |
key_value_to_string(value)
staticmethod
¶
Transforms a key or value into an hex string.
Source code in src/ethereum_test_tools/common/types.py
216 217 218 219 220 221 222 223 224 225 226 | |
__init__(input)
¶
Initializes the storage using a given mapping which can have keys and values either as string or int. Strings must be valid decimal or hexadecimal (starting with 0x) numbers.
Source code in src/ethereum_test_tools/common/types.py
228 229 230 231 232 233 234 235 236 237 238 239 240 | |
__len__()
¶
Returns number of elements in the storage
Source code in src/ethereum_test_tools/common/types.py
242 243 244 | |
__contains__(key)
¶
Checks for an item in the storage
Source code in src/ethereum_test_tools/common/types.py
246 247 248 249 | |
__getitem__(key)
¶
Returns an item from the storage
Source code in src/ethereum_test_tools/common/types.py
251 252 253 254 255 256 | |
__setitem__(key, value)
¶
Sets an item in the storage
Source code in src/ethereum_test_tools/common/types.py
258 259 260 | |
__delitem__(key)
¶
Deletes an item from the storage
Source code in src/ethereum_test_tools/common/types.py
262 263 264 | |
to_dict()
¶
Converts the storage into a string dict with appropriate 32-byte hex string formatting.
Source code in src/ethereum_test_tools/common/types.py
266 267 268 269 270 271 272 273 274 275 276 277 278 | |
contains(other)
¶
Returns True if self contains all keys with equal value as contained by second storage. Used for comparison with test expected post state and alloc returned by the transition tool.
Source code in src/ethereum_test_tools/common/types.py
280 281 282 283 284 285 286 287 288 289 290 291 292 | |
must_contain(other)
¶
Succeeds only if self contains all keys with equal value as contained by second storage. Used for comparison with test expected post state and alloc returned by the transition tool. Raises detailed exception when a difference is found.
Source code in src/ethereum_test_tools/common/types.py
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 | |
must_be_equal(other)
¶
Succeeds only if "self" is equal to "other" storage.
Source code in src/ethereum_test_tools/common/types.py
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 | |
eip_2028_transaction_data_cost(data)
¶
Calculates the cost of a given data as part of a transaction, based on the costs specified in EIP-2028: https://eips.ethereum.org/EIPS/eip-2028
Source code in src/ethereum_test_tools/common/helpers.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | |
to_address(input)
¶
Converts an int or str into proper address 20-byte hex string.
Source code in src/ethereum_test_tools/common/helpers.py
104 105 106 107 108 109 110 111 112 113 | |
CodeGasMeasure
dataclass
¶
Bases: Code
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 src/ethereum_test_tools/code/generators.py
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 | |
code: bytes | str | Code
instance-attribute
¶
Bytecode to be executed to measure the gas usage.
overhead_cost: int = 0
instance-attribute
class-attribute
¶
Extra gas cost to be subtracted from extra operations.
extra_stack_items: int = 0
instance-attribute
class-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: int = 0
instance-attribute
class-attribute
¶
Storage key to save the gas used.
assemble()
¶
Assemble the bytecode that measures gas usage.
Source code in src/ethereum_test_tools/code/generators.py
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 | |
to_hash_bytes(input)
¶
Converts an int or str into proper 32-byte hash.
Source code in src/ethereum_test_tools/common/helpers.py
116 117 118 119 120 121 122 123 124 125 | |
to_hash(input)
¶
Converts an int or str into proper 32-byte hash hex string.
Source code in src/ethereum_test_tools/common/helpers.py
128 129 130 131 132 | |
add_kzg_version(b_hashes, kzg_version)
¶
Adds the Kzg Version to each blob hash.
Source code in src/ethereum_test_tools/common/helpers.py
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | |
Opcodes
¶
Bases: Opcode, Enum
Enum containing all known opcodes.
Contains deprecated and not yet implemented opcodes.
This enum is !! NOT !! meant to be iterated over by the tests. Instead, create a list with cherry-picked opcodes from this Enum within the test if iteration is needed.
Do !! NOT !! remove or modify existing opcodes from this list.
Source code in src/ethereum_test_tools/vm/opcode.py
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 315 316 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 | |
Account
¶
State associated with an address.
Source code in src/ethereum_test_tools/common/types.py
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 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 | |
storage: Storage | None = None
instance-attribute
class-attribute
¶
Storage within a contract.
NONEXISTENT: object = object()
class-attribute
¶
Sentinel object used to specify when an account should not exist in the state.
NonceMismatch
¶
Bases: Exception
Test expected a certain nonce value for an account but a different value was found.
Source code in src/ethereum_test_tools/common/types.py
359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 | |
__str__()
¶
Print exception string
Source code in src/ethereum_test_tools/common/types.py
375 376 377 378 379 380 | |
BalanceMismatch
¶
Bases: Exception
Test expected a certain balance for an account but a different value was found.
Source code in src/ethereum_test_tools/common/types.py
382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 | |
__str__()
¶
Print exception string
Source code in src/ethereum_test_tools/common/types.py
398 399 400 401 402 403 | |
CodeMismatch
¶
Bases: Exception
Test expected a certain bytecode for an account but a different one was found.
Source code in src/ethereum_test_tools/common/types.py
405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 | |
__str__()
¶
Print exception string
Source code in src/ethereum_test_tools/common/types.py
421 422 423 424 425 426 | |
__init__(*, nonce=None, balance=None, code=None, storage=None)
¶
Init account members
Source code in src/ethereum_test_tools/common/types.py
428 429 430 431 432 433 434 435 436 437 438 439 440 441 | |
nonce: int | None = nonce
instance-attribute
class-attribute
¶
The scalar value equal to a) the number of transactions sent by an Externally Owned Account, b) the amount of contracts created by a contract.
balance: int | None = balance
instance-attribute
class-attribute
¶
The amount of Wei (10-18 Eth) the account has.
code: str | bytes | Code | None = code
instance-attribute
class-attribute
¶
Bytecode contained by the account.
check_alloc(address, alloc)
¶
Checks the returned alloc against an expected account in post state. Raises exception on failure.
Source code in src/ethereum_test_tools/common/types.py
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 | |
with_code(code)
classmethod
¶
Create account with provided code and nonce of 1.
Source code in src/ethereum_test_tools/common/types.py
483 484 485 486 487 488 | |
Withdrawal
dataclass
¶
Structure to represent a single withdrawal of a validator's balance from the beacon chain.
Source code in src/ethereum_test_tools/common/types.py
507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 | |
to_serializable_list()
¶
Returns a list of the withdrawal's attributes in the order they should be serialized.
Source code in src/ethereum_test_tools/common/types.py
519 520 521 522 523 524 525 526 527 528 529 | |
Environment
dataclass
¶
Structure used to keep track of the context in which a block must be executed.
Source code in src/ethereum_test_tools/common/types.py
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 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 | |
from_parent_header(parent)
staticmethod
¶
Instantiates a new environment with the provided header as parent.
Source code in src/ethereum_test_tools/common/types.py
562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 | |
parent_hash()
¶
Obtjains the latest hash according to the highest block number in
block_hashes.
Source code in src/ethereum_test_tools/common/types.py
581 582 583 584 585 586 587 588 589 590 | |
apply_new_parent(new_parent)
¶
Applies a header as parent to a copy of this environment.
Source code in src/ethereum_test_tools/common/types.py
592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 | |
set_fork_requirements(fork)
¶
Fills the required fields in an environment depending on the fork.
Source code in src/ethereum_test_tools/common/types.py
610 611 612 613 614 615 616 617 618 619 620 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 | |
AccessList
¶
Access List for transactions.
Source code in src/ethereum_test_tools/common/types.py
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 | |
__init__(*, address, storage_keys)
¶
Ensures the access list has the correct byte length for each field.
Source code in src/ethereum_test_tools/common/types.py
663 664 665 666 667 668 669 670 671 672 673 | |
to_list()
¶
Returns the access list as a list of serializable elements.
Source code in src/ethereum_test_tools/common/types.py
675 676 677 678 679 | |
Transaction
dataclass
¶
Generic object that can represent all Ethereum transaction types.
Source code in src/ethereum_test_tools/common/types.py
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 713 714 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 768 769 770 771 772 773 774 775 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 | |
ty: Optional[int] = None
instance-attribute
class-attribute
¶
Transaction type value.
InvalidFeePayment
¶
Bases: Exception
Transaction described more than one fee payment type.
Source code in src/ethereum_test_tools/common/types.py
718 719 720 721 722 723 724 725 | |
__str__()
¶
Print exception string
Source code in src/ethereum_test_tools/common/types.py
723 724 725 | |
InvalidSignaturePrivateKey
¶
Bases: Exception
Transaction describes both the signature and private key of source account.
Source code in src/ethereum_test_tools/common/types.py
727 728 729 730 731 732 733 734 735 | |
__str__()
¶
Print exception string
Source code in src/ethereum_test_tools/common/types.py
733 734 735 | |
__post_init__()
¶
Ensures the transaction has no conflicting properties.
Source code in src/ethereum_test_tools/common/types.py
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 768 769 770 | |
with_error(error)
¶
Create a copy of the transaction with an added error.
Source code in src/ethereum_test_tools/common/types.py
772 773 774 775 776 777 778 | |
with_nonce(nonce)
¶
Create a copy of the transaction with a modified nonce.
Source code in src/ethereum_test_tools/common/types.py
780 781 782 783 784 785 786 | |
with_fields(**kwargs)
¶
Create a deepcopy of the transaction with modified fields.
Source code in src/ethereum_test_tools/common/types.py
788 789 790 791 792 793 794 795 796 797 798 | |
payload_body()
¶
Returns the list of values included in the transaction body.
Source code in src/ethereum_test_tools/common/types.py
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 | |
serialized_bytes()
¶
Returns bytes of the serialized representation of the transaction, which is almost always RLP encoding.
Source code in src/ethereum_test_tools/common/types.py
932 933 934 935 936 937 938 939 940 941 942 943 | |
signing_envelope()
¶
Returns the list of values included in the envelope used for signing.
Source code in src/ethereum_test_tools/common/types.py
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 | |
signing_bytes()
¶
Returns the serialized bytes of the transaction used for signing.
Source code in src/ethereum_test_tools/common/types.py
1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 | |
with_signature_and_sender()
¶
Returns a signed version of the transaction using the private key.
Source code in src/ethereum_test_tools/common/types.py
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 | |
Header
dataclass
¶
Header type used to describe block header properties in test specs.
Source code in src/ethereum_test_tools/common/types.py
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 | |
REMOVE_FIELD: Removable = Removable()
class-attribute
¶
Sentinel object used to specify that a header field should be removed.
Block
dataclass
¶
Bases: Header
Block type used to describe block properties in test specs
Source code in src/ethereum_test_tools/common/types.py
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 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 | |
rlp: Optional[bytes] = None
instance-attribute
class-attribute
¶
If set, blockchain test will skip generating the block and will pass this value directly to the Fixture.
Only meant to be used to simulate blocks with bad formats, and therefore requires the block to produce an exception.
rlp_modifier: Optional[Header] = None
instance-attribute
class-attribute
¶
An RLP modifying header which values would be used to override the ones
returned by the evm_transition_tool.
exception: Optional[str] = None
instance-attribute
class-attribute
¶
If set, the block is expected to be rejected by the client.
engine_api_error_code: Optional[EngineAPIError] = None
instance-attribute
class-attribute
¶
If set, the block is expected to produce an error response from the Engine API.
txs: Optional[List[Transaction]] = None
instance-attribute
class-attribute
¶
List of transactions included in the block.
ommers: Optional[List[Header]] = None
instance-attribute
class-attribute
¶
List of ommer headers included in the block.
withdrawals: Optional[List[Withdrawal]] = None
instance-attribute
class-attribute
¶
List of withdrawals to perform for this block.
set_environment(env)
¶
Creates a copy of the environment with the characteristics of this specific block.
Source code in src/ethereum_test_tools/common/types.py
1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 | |
copy_with_rlp(rlp)
¶
Creates a copy of the block and adds the specified RLP.
Source code in src/ethereum_test_tools/common/types.py
1413 1414 1415 1416 1417 1418 1419 | |
FixtureEngineNewPayload
dataclass
¶
Representation of the engine_newPayloadVX information to be
sent using the block information.
Source code in src/ethereum_test_tools/common/types.py
1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 | |
from_fixture_header(fork, header, transactions, withdrawals, error_code)
classmethod
¶
Creates a FixtureEngineNewPayload from a FixtureHeader.
Source code in src/ethereum_test_tools/common/types.py
1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 | |
Fixture
dataclass
¶
Cross-client compatible Ethereum test fixture.
Source code in src/ethereum_test_tools/common/types.py
1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 | |
__post_init__()
¶
Post init hook to convert to JSON after instantiation.
Source code in src/ethereum_test_tools/common/types.py
1513 1514 1515 1516 1517 | |
fill_info(t8n, ref_spec)
¶
Fill the info field for this fixture
Source code in src/ethereum_test_tools/common/types.py
1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 | |
JSONEncoder
¶
Bases: json.JSONEncoder
Custom JSON encoder for ethereum_test types.
Source code in src/ethereum_test_tools/common/types.py
1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 | |
default(obj)
¶
Enocdes types defined in this module using basic python facilities.
Source code in src/ethereum_test_tools/common/types.py
1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 | |