@@ -15,8 +15,7 @@ void state_transition::SetUp()
15
15
{
16
16
pre.insert (tx.sender , {.nonce = 1 , .balance = tx.gas_limit * tx.max_gas_price + tx.value + 1 });
17
17
18
- // Default expectations.
19
- expect.post [Coinbase].exists = true ;
18
+ // Default expectation (coinbase is added later for valid txs only).
20
19
expect.post [tx.sender ].exists = true ;
21
20
}
22
21
@@ -69,20 +68,28 @@ void state_transition::TearDown()
69
68
EXPECT_EQ (tx_error, expected_error)
70
69
<< tx_error.message () << " vs " << expected_error.message ();
71
70
72
- // TODO: Compare states carefully, they should be identical.
73
71
EXPECT_EQ (state.get_accounts ().size (), pre.get_accounts ().size ());
74
72
for (const auto & [addr, acc] : state.get_accounts ())
75
73
{
76
74
EXPECT_TRUE (pre.get_accounts ().contains (addr)) << " unexpected account " << addr;
77
75
}
78
-
79
- // TODO: Export also tests with invalid transactions.
80
- return ; // Do not check anything else.
81
76
}
77
+ else
78
+ {
79
+ ASSERT_TRUE (holds_alternative<TransactionReceipt>(res))
80
+ << std::get<std::error_code>(res).message ();
81
+ const auto & receipt = std::get<TransactionReceipt>(res);
82
82
83
- ASSERT_TRUE (holds_alternative<TransactionReceipt>(res))
84
- << std::get<std::error_code>(res).message ();
85
- const auto & receipt = std::get<TransactionReceipt>(res);
83
+ EXPECT_EQ (receipt.status , expect.status );
84
+ if (expect.gas_used .has_value ())
85
+ {
86
+ EXPECT_EQ (receipt.gas_used , *expect.gas_used );
87
+ }
88
+ // Update default expectations - valid transaction means coinbase exists unless explicitly
89
+ // requested otherwise
90
+ if (expect.post .find (Coinbase) == expect.post .end ())
91
+ expect.post [Coinbase].exists = true ;
92
+ }
86
93
state::finalize (state, rev, block.coinbase , block_reward, block.ommers , block.withdrawals );
87
94
88
95
if (trace)
@@ -92,12 +99,6 @@ void state_transition::TearDown()
92
99
EXPECT_EQ (trace_capture->get_capture (), expect.trace );
93
100
}
94
101
95
- EXPECT_EQ (receipt.status , expect.status );
96
- if (expect.gas_used .has_value ())
97
- {
98
- EXPECT_EQ (receipt.gas_used , *expect.gas_used );
99
- }
100
-
101
102
for (const auto & [addr, expected_acc] : expect.post )
102
103
{
103
104
const auto acc = state.find (addr);
@@ -146,7 +147,7 @@ void state_transition::TearDown()
146
147
}
147
148
148
149
if (!export_file_path.empty ())
149
- export_state_test (receipt , state);
150
+ export_state_test (res , state);
150
151
}
151
152
152
153
namespace
@@ -166,7 +167,8 @@ std::string_view to_test_fork_name(evmc_revision rev) noexcept
166
167
}
167
168
} // namespace
168
169
169
- void state_transition::export_state_test (const TransactionReceipt& receipt, const State& post)
170
+ void state_transition::export_state_test (
171
+ const std::variant<TransactionReceipt, std::error_code>& res, const State& post)
170
172
{
171
173
json::json j;
172
174
auto & jt = j[export_test_name];
@@ -225,7 +227,16 @@ void state_transition::export_state_test(const TransactionReceipt& receipt, cons
225
227
auto & jpost = jt[" post" ][to_test_fork_name (rev)][0 ];
226
228
jpost[" indexes" ] = {{" data" , 0 }, {" gas" , 0 }, {" value" , 0 }};
227
229
jpost[" hash" ] = hex0x (mpt_hash (post.get_accounts ()));
228
- jpost[" logs" ] = hex0x (logs_hash (receipt.logs ));
230
+
231
+ if (holds_alternative<std::error_code>(res))
232
+ {
233
+ jpost[" expectException" ] = std::get<std::error_code>(res).message ();
234
+ jpost[" logs" ] = hex0x (logs_hash (std::vector<Log>()));
235
+ }
236
+ else
237
+ {
238
+ jpost[" logs" ] = hex0x (logs_hash (std::get<TransactionReceipt>(res).logs ));
239
+ }
229
240
230
241
std::ofstream{export_file_path} << std::setw (2 ) << j;
231
242
}
0 commit comments