From c19a78e37e74fbc4b10e1f93deb47c0b492ceee3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Thu, 1 Feb 2024 19:49:38 +0100 Subject: [PATCH] test: Export transaction access list --- test/unittests/state_transition.cpp | 14 ++++++++++++++ test/unittests/state_transition_tx_test.cpp | 14 ++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/test/unittests/state_transition.cpp b/test/unittests/state_transition.cpp index 68d41273b9..8d289b7d92 100644 --- a/test/unittests/state_transition.cpp +++ b/test/unittests/state_transition.cpp @@ -201,6 +201,20 @@ void state_transition::export_state_test(const TransactionReceipt& receipt, cons 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.emplace_back(hex0x(k)); + ja.emplace_back(std::move(je)); + } + } + auto& jpost = jt["post"][to_test_fork_name(rev)][0]; jpost["indexes"] = {{"data", 0}, {"gas", 0}, {"value", 0}}; jpost["hash"] = hex0x(mpt_hash(post.get_accounts())); diff --git a/test/unittests/state_transition_tx_test.cpp b/test/unittests/state_transition_tx_test.cpp index e5a06853ce..c29054b053 100644 --- a/test/unittests/state_transition_tx_test.cpp +++ b/test/unittests/state_transition_tx_test.cpp @@ -3,6 +3,7 @@ // SPDX-License-Identifier: Apache-2.0 #include "state_transition.hpp" +#include using namespace evmc::literals; using namespace evmone::test; @@ -89,3 +90,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 +}