Skip to content

Commit 32c07da

Browse files
authored
test: Ensure exported tests have accessLists for eip1559 txs (#1027)
1 parent c885db3 commit 32c07da

6 files changed

Lines changed: 41 additions & 8 deletions

test/unittests/state_transition.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,15 +189,15 @@ void state_transition::export_state_test(
189189
jtx["sender"] = hex0x(tx.sender);
190190
jtx["secretKey"] = hex0x(SenderSecretKey);
191191
jtx["nonce"] = hex0x(tx.nonce);
192-
if (rev < EVMC_LONDON)
192+
if (tx.type >= Transaction::Type::eip1559)
193193
{
194-
assert(tx.max_gas_price == tx.max_priority_gas_price);
195-
jtx["gasPrice"] = hex0x(tx.max_gas_price);
194+
jtx["maxFeePerGas"] = hex0x(tx.max_gas_price);
195+
jtx["maxPriorityFeePerGas"] = hex0x(tx.max_priority_gas_price);
196196
}
197197
else
198198
{
199-
jtx["maxFeePerGas"] = hex0x(tx.max_gas_price);
200-
jtx["maxPriorityFeePerGas"] = hex0x(tx.max_priority_gas_price);
199+
assert(tx.max_gas_price == tx.max_priority_gas_price);
200+
jtx["gasPrice"] = hex0x(tx.max_gas_price);
201201
}
202202

203203
jtx["data"][0] = hex0x(tx.data);

test/unittests/state_transition.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ class state_transition : public ExportableFixture
7878
.base_fee = 999,
7979
};
8080
Transaction tx{
81+
// The default type corresponds to the default `rev` and majority of tests.
82+
.type = Transaction::Type::eip1559,
8183
.gas_limit = block.gas_limit,
8284
.max_gas_price = block.base_fee + 1,
8385
.max_priority_gas_price = block.base_fee + 1,

test/unittests/state_transition_create_test.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ TEST_F(state_transition, code_deployment_out_of_gas_tw)
6666
block.base_fee = 0;
6767
const auto initcode = ret(0, 5000); // create contract with a lot of zeros, deploy cost 1M
6868

69+
tx.type = Transaction::Type::legacy;
6970
tx.to = To;
7071
tx.gas_limit = 1000000;
7172
pre.insert(To, {.code = mstore(0, push(initcode)) +
@@ -80,6 +81,7 @@ TEST_F(state_transition, code_deployment_out_of_gas_f)
8081
block.base_fee = 0;
8182
const auto initcode = ret(0, 1000); // create contract with a lot of zeros
8283

84+
tx.type = Transaction::Type::legacy;
8385
tx.to = To;
8486
tx.gas_limit = 100000;
8587
pre.insert(To, {.code = mstore(0, push(initcode)) +
@@ -98,6 +100,7 @@ TEST_F(state_transition, code_deployment_out_of_gas_storage_tw)
98100
const auto initcode = sstore(0, 1) // set storage
99101
+ ret(0, 5000); // create contract with a lot of zeros
100102

103+
tx.type = Transaction::Type::legacy;
101104
tx.to = To;
102105
tx.gas_limit = 1000000;
103106
pre.insert(To, {.code = mstore(0, push(initcode)) +
@@ -113,6 +116,7 @@ TEST_F(state_transition, code_deployment_out_of_gas_storage_f)
113116
const auto initcode = sstore(0, 1) // set storage
114117
+ ret(0, 1000); // create contract with a lot of zeros
115118

119+
tx.type = Transaction::Type::legacy;
116120
tx.to = To;
117121
tx.gas_limit = 100000;
118122
pre.insert(To, {.code = mstore(0, push(initcode)) +
@@ -135,6 +139,7 @@ TEST_F(state_transition, code_deployment_out_of_gas_refund_tw)
135139
+ sstore(0, 0) // gas refund
136140
+ ret(0, 5000); // create contract with a lot of zeros
137141

142+
tx.type = Transaction::Type::legacy;
138143
tx.to = To;
139144
tx.gas_limit = 1000000;
140145
pre.insert(To, {.code = mstore(0, push(initcode)) +
@@ -152,6 +157,7 @@ TEST_F(state_transition, code_deployment_out_of_gas_refund_f)
152157
+ sstore(0, 0) // gas refund
153158
+ ret(0, 1000); // create contract with a lot of zeros
154159

160+
tx.type = Transaction::Type::legacy;
155161
tx.to = To;
156162
tx.gas_limit = 100000;
157163
pre.insert(To, {.code = mstore(0, push(initcode)) +
@@ -255,6 +261,7 @@ TEST_F(state_transition, create_revert_sd)
255261
block.base_fee = 0;
256262
static constexpr auto CREATED = 0x8bbc3514477d75ec797bbe4e19d7961660bb849c_address;
257263

264+
tx.type = Transaction::Type::legacy;
258265
tx.to = To;
259266
pre.insert(*tx.to, {.code = create() + OP_INVALID});
260267

@@ -269,6 +276,7 @@ TEST_F(state_transition, create_revert_tw)
269276
block.base_fee = 0;
270277
static constexpr auto CREATED = 0x8bbc3514477d75ec797bbe4e19d7961660bb849c_address;
271278

279+
tx.type = Transaction::Type::legacy;
272280
tx.to = To;
273281
pre.insert(*tx.to, {.code = create() + OP_INVALID});
274282

@@ -296,6 +304,7 @@ TEST_F(state_transition, create_collision_empty_revert_tw)
296304
block.base_fee = 0;
297305
static constexpr auto CREATED = 0x8bbc3514477d75ec797bbe4e19d7961660bb849c_address;
298306

307+
tx.type = Transaction::Type::legacy;
299308
tx.to = To;
300309
pre.insert(*tx.to, {.code = create() + OP_INVALID});
301310
pre.insert(CREATED, {});
@@ -326,6 +335,7 @@ TEST_F(state_transition, touch_create_collision_empty_revert_tw)
326335
static constexpr auto CREATED = 0x11f72042f0f1c9d8a1aeffc3680d0b41dd7769a7_address;
327336
static constexpr auto REVERT_PROXY = 0x94_address;
328337

338+
tx.type = Transaction::Type::legacy;
329339
tx.to = To;
330340
pre.insert(*tx.to, {.code = call(CREATED) + call(REVERT_PROXY).gas(0xffff)});
331341
pre.insert(REVERT_PROXY, {.code = create() + OP_INVALID});

test/unittests/state_transition_extcode_test.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ TEST_F(state_transition, extcodehash_existent)
1414
block.base_fee = 0;
1515

1616
static constexpr auto EXT = 0xe4_address;
17+
tx.type = Transaction::Type::legacy;
1718
tx.to = To;
1819
pre.insert(To, {.code = sstore(0, push(EXT) + OP_EXTCODEHASH)});
1920
pre.insert(EXT, {.code = bytecode{"1234"}});
@@ -28,6 +29,7 @@ TEST_F(state_transition, extcodesize_existent)
2829
block.base_fee = 0;
2930

3031
static constexpr auto EXT = 0xe4_address;
32+
tx.type = Transaction::Type::legacy;
3133
tx.to = To;
3234
pre.insert(To, {.code = sstore(0, push(EXT) + OP_EXTCODESIZE)});
3335
pre.insert(EXT, {.code = bytes(3, 0)});

test/unittests/state_transition_touch_test.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ TEST_F(state_transition, touch_empty_sd)
1414
block.base_fee = 0;
1515
static constexpr auto EMPTY = 0xee_address;
1616

17+
tx.type = Transaction::Type::legacy;
1718
tx.to = To;
1819
pre.insert(*tx.to, {.code = call(EMPTY)});
1920
pre.insert(EMPTY, {});
@@ -28,6 +29,7 @@ TEST_F(state_transition, touch_empty_tw)
2829
block.base_fee = 0;
2930
static constexpr auto EMPTY = 0xee_address;
3031

32+
tx.type = Transaction::Type::legacy;
3133
tx.to = To;
3234
pre.insert(*tx.to, {.code = call(EMPTY)});
3335
pre.insert(EMPTY, {});
@@ -42,6 +44,7 @@ TEST_F(state_transition, touch_nonexistent_tw)
4244
block.base_fee = 0;
4345
static constexpr auto NONEXISTENT = 0x4e_address;
4446

47+
tx.type = Transaction::Type::legacy;
4548
tx.to = To;
4649
pre.insert(*tx.to, {.code = call(NONEXISTENT)});
4750

@@ -55,6 +58,7 @@ TEST_F(state_transition, touch_nonexistent_sd)
5558
block.base_fee = 0;
5659
static constexpr auto NONEXISTENT = 0x4e_address;
5760

61+
tx.type = Transaction::Type::legacy;
5862
tx.to = To;
5963
pre.insert(*tx.to, {.code = call(NONEXISTENT)});
6064

@@ -67,6 +71,7 @@ TEST_F(state_transition, touch_nonempty_tw)
6771
block.base_fee = 0;
6872
static constexpr auto WITH_BALANCE = 0xba_address;
6973

74+
tx.type = Transaction::Type::legacy;
7075
tx.to = To;
7176
pre.insert(*tx.to, {.code = call(WITH_BALANCE)});
7277
pre.insert(WITH_BALANCE, {.balance = 1});
@@ -81,6 +86,7 @@ TEST_F(state_transition, touch_revert_empty)
8186
block.base_fee = 0;
8287
static constexpr auto EMPTY = 0xee_address;
8388

89+
tx.type = Transaction::Type::legacy;
8490
tx.to = To;
8591
pre.insert(*tx.to, {.code = call(EMPTY) + revert(0, 0)});
8692
pre.insert(EMPTY, {});
@@ -96,6 +102,7 @@ TEST_F(state_transition, touch_revert_nonexistent_istanbul)
96102
block.base_fee = 0;
97103
static constexpr auto EMPTY = 0xee_address;
98104

105+
tx.type = Transaction::Type::legacy;
99106
tx.to = To;
100107
pre.insert(*tx.to, {.code = call(EMPTY) + revert(0, 0)});
101108

@@ -110,6 +117,7 @@ TEST_F(state_transition, touch_revert_nonexistent_tw)
110117
block.base_fee = 0;
111118
static constexpr auto EMPTY = 0xee_address;
112119

120+
tx.type = Transaction::Type::legacy;
113121
tx.to = To;
114122
pre.insert(*tx.to, {.code = call(EMPTY) + OP_INVALID});
115123

@@ -124,6 +132,7 @@ TEST_F(state_transition, touch_revert_nonempty_tw)
124132
block.base_fee = 0;
125133
static constexpr auto WITH_BALANCE = 0xba_address;
126134

135+
tx.type = Transaction::Type::legacy;
127136
tx.to = To;
128137
pre.insert(*tx.to, {.code = call(WITH_BALANCE) + OP_INVALID});
129138
pre.insert(WITH_BALANCE, {.balance = 1});
@@ -140,6 +149,7 @@ TEST_F(state_transition, touch_revert_nonexistent_touch_again_tw)
140149
static constexpr auto EMPTY = 0xee_address;
141150
static constexpr auto REVERT_PROXY = 0x94_address;
142151

152+
tx.type = Transaction::Type::legacy;
143153
tx.to = To;
144154
pre.insert(REVERT_PROXY, {.code = call(EMPTY) + OP_INVALID});
145155
pre.insert(*tx.to, {.code = call(REVERT_PROXY).gas(0xffff) + call(EMPTY)});
@@ -156,6 +166,7 @@ TEST_F(state_transition, touch_touch_revert_nonexistent_tw)
156166
static constexpr auto EMPTY = 0xee_address;
157167
static constexpr auto REVERT_PROXY = 0x94_address;
158168

169+
tx.type = Transaction::Type::legacy;
159170
tx.to = To;
160171
pre.insert(REVERT_PROXY, {.code = call(EMPTY) + OP_INVALID});
161172
pre.insert(*tx.to, {.code = call(EMPTY) + call(REVERT_PROXY).gas(0xffff)});
@@ -172,6 +183,7 @@ TEST_F(state_transition, touch_revert_touch_revert_nonexistent_tw)
172183
static constexpr auto EMPTY = 0xee_address;
173184
static constexpr auto REVERT_PROXY = 0x94_address;
174185

186+
tx.type = Transaction::Type::legacy;
175187
tx.to = To;
176188
pre.insert(REVERT_PROXY, {.code = call(EMPTY) + OP_INVALID});
177189
pre.insert(*tx.to, {.code = 2 * call(REVERT_PROXY).gas(0xffff)});
@@ -187,6 +199,7 @@ TEST_F(state_transition, touch_touch_revert_nonexistent_tw_2)
187199
block.base_fee = 0;
188200
static constexpr auto EMPTY = 0xee_address;
189201

202+
tx.type = Transaction::Type::legacy;
190203
tx.to = To;
191204
pre.insert(*tx.to, {.code = call(EMPTY) + call(EMPTY) + OP_INVALID});
192205

@@ -202,6 +215,7 @@ TEST_F(state_transition, touch_revert_selfdestruct_to_nonexistient_tw)
202215
static constexpr auto DESTRUCTOR = 0xde_address;
203216
static constexpr auto BENEFICIARY = 0xbe_address;
204217

218+
tx.type = Transaction::Type::legacy;
205219
tx.to = To;
206220
pre.insert(*tx.to, {.code = call(DESTRUCTOR).gas(0xffff) + OP_INVALID});
207221
pre.insert(DESTRUCTOR, {.code = selfdestruct(BENEFICIARY)});

test/unittests/state_transition_tx_test.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ TEST_F(state_transition, tx_legacy)
1212
{
1313
rev = EVMC_ISTANBUL;
1414
block.base_fee = 0; // should be 0 before London
15+
tx.type = Transaction::Type::legacy;
1516
tx.to = To;
1617

1718
expect.post.at(Sender).nonce = pre.get(Sender).nonce + 1;
@@ -21,6 +22,7 @@ TEST_F(state_transition, tx_non_existing_sender)
2122
{
2223
rev = EVMC_BERLIN;
2324
block.base_fee = 0; // should be 0 before London
25+
tx.type = Transaction::Type::legacy;
2426
tx.to = To;
2527
tx.max_gas_price = 0;
2628
tx.max_priority_gas_price = 0;
@@ -36,6 +38,7 @@ TEST_F(state_transition, invalid_tx_non_existing_sender)
3638
{
3739
rev = EVMC_BERLIN;
3840
block.base_fee = 0; // should be 0 before London
41+
tx.type = Transaction::Type::legacy;
3942
tx.to = To;
4043
tx.max_gas_price = 1;
4144
tx.max_priority_gas_price = 1;
@@ -49,12 +52,12 @@ TEST_F(state_transition, invalid_tx_non_existing_sender)
4952
TEST_F(state_transition, tx_blob_gas_price)
5053
{
5154
rev = EVMC_CANCUN;
55+
tx.type = Transaction::Type::blob;
5256
tx.to = To;
5357
tx.gas_limit = 25000;
5458
tx.max_gas_price = block.base_fee; // minimal gas price to make it
5559
tx.max_priority_gas_price = 0;
5660
tx.nonce = 1;
57-
tx.type = Transaction::Type::blob;
5861
tx.blob_hashes.emplace_back(
5962
0x0100000000000000000000000000000000000000000000000000000000000000_bytes32);
6063
tx.max_blob_gas_price = 1;
@@ -70,9 +73,10 @@ TEST_F(state_transition, empty_coinbase_fee_0_sd)
7073
rev = EVMC_SPURIOUS_DRAGON;
7174
block_reward = 0;
7275
block.base_fee = 0; // should be 0 before London
76+
tx.type = Transaction::Type::legacy;
77+
tx.to = To;
7378
tx.max_gas_price = 0;
7479
tx.max_priority_gas_price = 0;
75-
tx.to = To;
7680
pre.insert(Coinbase, {});
7781
expect.post[To].exists = false;
7882
expect.post[Coinbase].exists = false;
@@ -83,9 +87,10 @@ TEST_F(state_transition, empty_coinbase_fee_0_tw)
8387
rev = EVMC_TANGERINE_WHISTLE;
8488
block_reward = 0;
8589
block.base_fee = 0; // should be 0 before London
90+
tx.type = Transaction::Type::legacy;
91+
tx.to = To;
8692
tx.max_gas_price = 0;
8793
tx.max_priority_gas_price = 0;
88-
tx.to = To;
8994
pre.insert(Coinbase, {});
9095
expect.post[To].exists = true;
9196
expect.post[Coinbase].balance = 0;

0 commit comments

Comments
 (0)