Skip to content

Commit f8e5a2b

Browse files
committed
test: Add a logs expectation to the state_transition fixture
The state_transition fixture could assert state, gas, and trace, but not emitted logs. Add an optional Expectation::logs, compared field-by-field (count, address, data, topics, and order) in the runner, with a LOG1 smoke test pinning the mechanism.
1 parent 1164d38 commit f8e5a2b

3 files changed

Lines changed: 27 additions & 0 deletions

File tree

test/unittests/state_transition.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,17 @@ void state_transition::TearDown()
8888
{
8989
EXPECT_EQ(receipt.gas_refund, *expect.gas_refund);
9090
}
91+
if (expect.logs.has_value())
92+
{
93+
ASSERT_EQ(receipt.logs.size(), expect.logs->size()) << "unexpected number of logs";
94+
for (size_t i = 0; i < expect.logs->size(); ++i)
95+
{
96+
EXPECT_EQ(receipt.logs[i].addr, (*expect.logs)[i].addr) << "log " << i << " addr";
97+
EXPECT_EQ(receipt.logs[i].data, (*expect.logs)[i].data) << "log " << i << " data";
98+
EXPECT_EQ(receipt.logs[i].topics, (*expect.logs)[i].topics)
99+
<< "log " << i << " topics";
100+
}
101+
}
91102
// Update default expectations - valid transaction means coinbase exists unless explicitly
92103
// requested otherwise
93104
if (!expect.post.contains(Coinbase))

test/unittests/state_transition.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ class state_transition : public ExportableFixture
6262
/// (`gas_used + gas_refund` equals `max(pre-refund gas, EIP-7623 floor)`).
6363
std::optional<int64_t> gas_refund;
6464

65+
/// The expected logs emitted by the transaction. When set, the receipt's logs must match
66+
/// exactly: count, address, data, topics, and order.
67+
std::optional<std::vector<Log>> logs;
68+
6569
/// The expected post-execution state.
6670
std::unordered_map<address, ExpectedAccount> post;
6771

test/unittests/state_transition_tx_test.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,3 +268,15 @@ TEST_F(state_transition, invalid_access_list_amsterdam_gas_limit_below_floor)
268268
tx.gas_limit = 28679;
269269
expect.tx_error = INTRINSIC_GAS_TOO_LOW;
270270
}
271+
272+
TEST_F(state_transition, tx_emits_log)
273+
{
274+
// Smoke test for the `expect.logs` mechanism: assert a log with data and a topic from LOG1.
275+
static constexpr auto TOPIC = 0xaa_bytes32;
276+
tx.to = To;
277+
// Store 0xaabbccdd at mem[28..31], then LOG1(offset=28, size=4, TOPIC) over those bytes.
278+
pre[To] = {.code = mstore(0, 0xaabbccdd) + push(TOPIC) + push(4) + push(28) + OP_LOG1};
279+
280+
expect.post[To] = {}; // the contract survives (has code).
281+
expect.logs = {Log{To, bytes{0xaa, 0xbb, 0xcc, 0xdd}, {TOPIC}}};
282+
}

0 commit comments

Comments
 (0)