Skip to content

Commit

Permalink
test: Export transaction access list
Browse files Browse the repository at this point in the history
  • Loading branch information
chfast committed Feb 2, 2024
1 parent 170ba31 commit 2e07baf
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
14 changes: 14 additions & 0 deletions test/unittests/state_transition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,20 @@ void state_transition::export_state_test(
jtx["gasLimit"][0] = hex0x(tx.gas_limit);
jtx["value"][0] = hex0x(tx.value);

if (!tx.access_list.empty())
{
auto& ja = jtx["accessLists"][0];
for (const auto& [addr, storage_keys] : tx.access_list)
{
json::json je;
je["address"] = hex0x(addr);
auto& jstorage_keys = je["storageKeys"] = json::json::array();
for (const auto& k : storage_keys)
jstorage_keys.push_back(hex0x(k));
ja.push_back(je);
}
}

auto& jpost = jt["post"][evmc::to_string(rev)][0];
jpost["indexes"] = {{"data", 0}, {"gas", 0}, {"value", 0}};
jpost["hash"] = hex0x(mpt_hash(post.get_accounts()));
Expand Down
14 changes: 14 additions & 0 deletions test/unittests/state_transition_tx_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// SPDX-License-Identifier: Apache-2.0

#include "state_transition.hpp"
#include <test/utils/bytecode.hpp>

using namespace evmc::literals;
using namespace evmone::test;
Expand Down Expand Up @@ -93,3 +94,16 @@ TEST_F(state_transition, empty_coinbase_fee_0_tw)
expect.post[To].exists = true;
expect.post[Coinbase].balance = 0;
}

TEST_F(state_transition, access_list_storage)
{
tx.to = To;
tx.access_list = {{To, {0x01_bytes32}}};

pre.insert(To,
{.storage = {{0x01_bytes32, {0x01_bytes32, 0x01_bytes32}}}, .code = sstore(2, sload(1))});

expect.post[To].storage[0x01_bytes32] = 0x01_bytes32;
expect.post[To].storage[0x02_bytes32] = 0x01_bytes32;
expect.gas_used = 47506; // Without access list: 45206
}

0 comments on commit 2e07baf

Please sign in to comment.