|
| 1 | +"""Test T8N compatibility.""" |
| 2 | + |
| 3 | +import pytest |
| 4 | + |
| 5 | +from ethereum_test_forks import Berlin, Byzantium, Cancun, Fork, London, Paris, Prague |
| 6 | +from ethereum_test_tools import ( |
| 7 | + AccessList, |
| 8 | + Account, |
| 9 | + Alloc, |
| 10 | + AuthorizationTuple, |
| 11 | + Block, |
| 12 | + BlockchainTestFiller, |
| 13 | + Environment, |
| 14 | + Storage, |
| 15 | + Transaction, |
| 16 | + add_kzg_version, |
| 17 | +) |
| 18 | +from ethereum_test_tools.vm.opcode import Opcodes as Op |
| 19 | + |
| 20 | +from ...cancun.eip4844_blobs.spec import Spec as BlobSpec |
| 21 | + |
| 22 | + |
| 23 | +@pytest.mark.valid_from("Frontier") |
| 24 | +def test_t8n_structures(blockchain_test: BlockchainTestFiller, pre: Alloc, fork: Fork): |
| 25 | + """Feed t8n with all kinds of possible input.""" |
| 26 | + env = Environment() |
| 27 | + sender = pre.fund_eoa() |
| 28 | + storage_1 = Storage() |
| 29 | + storage_2 = Storage() |
| 30 | + |
| 31 | + code_account_1 = pre.deploy_contract( |
| 32 | + code=Op.SSTORE(storage_1.store_next(1, "blockhash_0_is_set"), Op.GT(Op.BLOCKHASH(0), 0)) |
| 33 | + + Op.SSTORE(storage_1.store_next(0, "blockhash_1"), Op.BLOCKHASH(1)) |
| 34 | + + Op.SSTORE( |
| 35 | + storage_1.store_next(1 if fork < Paris else 0, "difficulty_1_is_near_20000"), |
| 36 | + Op.AND(Op.GT(Op.PREVRANDAO(), 0x19990), Op.LT(Op.PREVRANDAO(), 0x20100)), |
| 37 | + ) |
| 38 | + ) |
| 39 | + code_account_2 = pre.deploy_contract( |
| 40 | + code=Op.SSTORE(storage_2.store_next(1, "blockhash_1_is_set"), Op.GT(Op.BLOCKHASH(1), 0)) |
| 41 | + + Op.SSTORE( |
| 42 | + storage_2.store_next(1 if fork < Paris else 0, "difficulty_2_is_near_20000"), |
| 43 | + Op.AND(Op.GT(Op.PREVRANDAO(), 0x19990), Op.LT(Op.PREVRANDAO(), 0x20100)), |
| 44 | + ) |
| 45 | + ) |
| 46 | + |
| 47 | + tx_1 = Transaction( |
| 48 | + gas_limit=100_000, to=code_account_1, data=b"", sender=sender, protected=fork >= Byzantium |
| 49 | + ) |
| 50 | + if fork < Berlin: |
| 51 | + # Feed legacy transaction |
| 52 | + tx_2 = Transaction( |
| 53 | + gas_limit=100_000, |
| 54 | + to=code_account_2, |
| 55 | + data=b"", |
| 56 | + sender=sender, |
| 57 | + protected=fork >= Byzantium, |
| 58 | + ) |
| 59 | + elif fork < London: |
| 60 | + # Feed access list transaction |
| 61 | + tx_2 = Transaction( |
| 62 | + gas_limit=100_000, |
| 63 | + to=code_account_2, |
| 64 | + data=b"", |
| 65 | + sender=sender, |
| 66 | + protected=fork >= Byzantium, |
| 67 | + access_list=[ |
| 68 | + AccessList( |
| 69 | + address=0x1234, |
| 70 | + storage_keys=[0, 1], |
| 71 | + ) |
| 72 | + ], |
| 73 | + ) |
| 74 | + elif fork < Cancun: |
| 75 | + # Feed base fee transaction |
| 76 | + tx_2 = Transaction( |
| 77 | + to=code_account_2, |
| 78 | + data=b"", |
| 79 | + sender=sender, |
| 80 | + protected=fork >= Byzantium, |
| 81 | + gas_limit=100_000, |
| 82 | + max_priority_fee_per_gas=5, |
| 83 | + max_fee_per_gas=10, |
| 84 | + access_list=[ |
| 85 | + AccessList( |
| 86 | + address=0x1234, |
| 87 | + storage_keys=[0, 1], |
| 88 | + ) |
| 89 | + ], |
| 90 | + ) |
| 91 | + elif fork < Prague: |
| 92 | + # Feed blob transaction |
| 93 | + tx_2 = Transaction( |
| 94 | + to=code_account_2, |
| 95 | + data=b"", |
| 96 | + sender=sender, |
| 97 | + protected=fork >= Byzantium, |
| 98 | + gas_limit=100_000, |
| 99 | + max_priority_fee_per_gas=5, |
| 100 | + max_fee_per_gas=10, |
| 101 | + max_fee_per_blob_gas=30, |
| 102 | + blob_versioned_hashes=add_kzg_version([1], BlobSpec.BLOB_COMMITMENT_VERSION_KZG), |
| 103 | + access_list=[ |
| 104 | + AccessList( |
| 105 | + address=0x1234, |
| 106 | + storage_keys=[0, 1], |
| 107 | + ) |
| 108 | + ], |
| 109 | + ) |
| 110 | + else: |
| 111 | + # Feed set code transaction |
| 112 | + tx_2 = Transaction( |
| 113 | + to=sender, |
| 114 | + data=b"", |
| 115 | + sender=sender, |
| 116 | + protected=fork >= Byzantium, |
| 117 | + gas_limit=100_000, |
| 118 | + max_priority_fee_per_gas=5, |
| 119 | + max_fee_per_gas=10, |
| 120 | + nonce=1, |
| 121 | + access_list=[ |
| 122 | + AccessList( |
| 123 | + address=0x1234, |
| 124 | + storage_keys=[0, 1], |
| 125 | + ) |
| 126 | + ], |
| 127 | + authorization_list=[ |
| 128 | + AuthorizationTuple( |
| 129 | + address=code_account_2, |
| 130 | + nonce=2, |
| 131 | + signer=sender, |
| 132 | + ), |
| 133 | + ], |
| 134 | + ) |
| 135 | + |
| 136 | + block_1 = Block( |
| 137 | + txs=[tx_1], |
| 138 | + expected_post_state={ |
| 139 | + code_account_1: Account( |
| 140 | + storage=storage_1, |
| 141 | + ), |
| 142 | + }, |
| 143 | + ) |
| 144 | + |
| 145 | + block_2 = Block( |
| 146 | + txs=[tx_2], |
| 147 | + expected_post_state={ |
| 148 | + code_account_2: Account( |
| 149 | + storage=storage_2, |
| 150 | + ), |
| 151 | + } |
| 152 | + if fork < Prague |
| 153 | + else { |
| 154 | + sender: Account( |
| 155 | + storage=storage_2, |
| 156 | + ), |
| 157 | + }, |
| 158 | + ) |
| 159 | + |
| 160 | + blockchain_test( |
| 161 | + genesis_environment=env, |
| 162 | + pre=pre, |
| 163 | + post=block_1.expected_post_state, |
| 164 | + blocks=[block_1, block_2], |
| 165 | + ) |
0 commit comments