Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions test/unittests/state_transition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,17 @@ void state_transition::TearDown()
{
EXPECT_EQ(receipt.gas_refund, *expect.gas_refund);
}
if (expect.logs.has_value())
{
ASSERT_EQ(receipt.logs.size(), expect.logs->size()) << "unexpected number of logs";
for (size_t i = 0; i < expect.logs->size(); ++i)
{
EXPECT_EQ(receipt.logs[i].addr, (*expect.logs)[i].addr) << "log " << i << " addr";
EXPECT_EQ(receipt.logs[i].data, (*expect.logs)[i].data) << "log " << i << " data";
EXPECT_EQ(receipt.logs[i].topics, (*expect.logs)[i].topics)
<< "log " << i << " topics";
}
}
// Update default expectations - valid transaction means coinbase exists unless explicitly
// requested otherwise
if (!expect.post.contains(Coinbase))
Expand Down
4 changes: 4 additions & 0 deletions test/unittests/state_transition.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ class state_transition : public ExportableFixture
/// (`gas_used + gas_refund` equals `max(pre-refund gas, EIP-7623 floor)`).
std::optional<int64_t> gas_refund;

/// The expected logs emitted by the transaction. When set, the receipt's logs must match
/// exactly: count, address, data, topics, and order.
std::optional<std::vector<Log>> logs;

/// The expected post-execution state.
std::unordered_map<address, ExpectedAccount> post;

Expand Down
12 changes: 12 additions & 0 deletions test/unittests/state_transition_tx_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,3 +268,15 @@ TEST_F(state_transition, invalid_access_list_amsterdam_gas_limit_below_floor)
tx.gas_limit = 28679;
expect.tx_error = INTRINSIC_GAS_TOO_LOW;
}

TEST_F(state_transition, tx_emits_log)
{
// Smoke test for the `expect.logs` mechanism: assert a log with data and a topic from LOG1.
static constexpr auto TOPIC = 0xaa_bytes32;
tx.to = To;
// Store 0xaabbccdd at mem[28..31], then LOG1(offset=28, size=4, TOPIC) over those bytes.
pre[To] = {.code = mstore(0, 0xaabbccdd) + push(TOPIC) + push(4) + push(28) + OP_LOG1};

expect.post[To] = {}; // the contract survives (has code).
expect.logs = {Log{To, bytes{0xaa, 0xbb, 0xcc, 0xdd}, {TOPIC}}};
Comment thread
chfast marked this conversation as resolved.
}