Skip to content

Commit

Permalink
test: Properly export pre-1559 transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
chfast committed Feb 28, 2024
1 parent a980168 commit 17c3be1
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 6 deletions.
2 changes: 1 addition & 1 deletion test/integration/statetest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ set_tests_properties(
add_test(
NAME ${PREFIX}/execute_exported_tests
# TODO: Broken exported tests are filtered out.
COMMAND evmone-statetest ${EXPORT_DIR}/state_transition --gtest_filter=-*block.*:*tx.tx_non_existing_sender
COMMAND evmone-statetest ${EXPORT_DIR}/state_transition --gtest_filter=-*block.*
)
set_tests_properties(
${PREFIX}/execute_exported_tests PROPERTIES
Expand Down
25 changes: 23 additions & 2 deletions test/unittests/state_transition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,21 @@ class TraceCapture

void state_transition::TearDown()
{
// Validation:

if (rev < EVMC_LONDON)
{
ASSERT_EQ(tx.type, state::Transaction::Type::legacy);
}
if (tx.type == state::Transaction::Type::legacy)
{
ASSERT_EQ(tx.max_gas_price, tx.max_priority_gas_price);
}

validate_state(pre, rev);

// Execution:

auto state = pre;
const auto trace = !expect.trace.empty();
auto& selected_vm = trace ? tracing_vm : vm;
Expand Down Expand Up @@ -155,8 +168,16 @@ void state_transition::export_state_test(const TransactionReceipt& receipt, cons
jtx["sender"] = hex0x(tx.sender);
jtx["secretKey"] = hex0x(SenderSecretKey);
jtx["nonce"] = hex0x(tx.nonce);
jtx["maxFeePerGas"] = hex0x(tx.max_gas_price);
jtx["maxPriorityFeePerGas"] = hex0x(tx.max_priority_gas_price);
if (rev < EVMC_LONDON)
{
assert(tx.max_gas_price == tx.max_priority_gas_price);
jtx["gasPrice"] = hex0x(tx.max_gas_price);
}
else
{
jtx["maxFeePerGas"] = hex0x(tx.max_gas_price);
jtx["maxPriorityFeePerGas"] = hex0x(tx.max_priority_gas_price);
}

jtx["data"][0] = hex0x(tx.data);
jtx["gasLimit"][0] = hex0x(tx.gas_limit);
Expand Down
2 changes: 1 addition & 1 deletion test/unittests/state_transition.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class state_transition : public ExportableFixture
Transaction tx{
.gas_limit = block.gas_limit,
.max_gas_price = block.base_fee + 1,
.max_priority_gas_price = 1,
.max_priority_gas_price = block.base_fee + 1,
.sender = Sender,
.nonce = 1,
};
Expand Down
3 changes: 1 addition & 2 deletions test/unittests/state_transition_eof_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ TEST_F(state_transition, eof_invalid_initcode)

expect.post[tx.sender].nonce = pre.get(tx.sender).nonce + 1;
expect.post[tx.sender].balance =
pre.get(tx.sender).balance -
(block.base_fee + tx.max_priority_gas_price) * static_cast<uint64_t>(*expect.gas_used);
pre.get(tx.sender).balance - tx.max_gas_price * static_cast<uint64_t>(*expect.gas_used);
expect.post[*tx.to].nonce = pre.get(*tx.to).nonce + 1; // CREATE caller's nonce must be bumped
expect.post[*tx.to].storage[0x01_bytes32] = 0x00_bytes32; // CREATE must fail
expect.post[create_address].exists = false;
Expand Down
8 changes: 8 additions & 0 deletions test/unittests/state_transition_tx_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@
using namespace evmc::literals;
using namespace evmone::test;

TEST_F(state_transition, tx_legacy)
{
rev = EVMC_ISTANBUL;
tx.to = To;

expect.post.at(Sender).nonce = pre.get(Sender).nonce + 1;
}

TEST_F(state_transition, tx_non_existing_sender)
{
tx.to = To;
Expand Down

0 comments on commit 17c3be1

Please sign in to comment.