Skip to content
Open
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
2 changes: 1 addition & 1 deletion test/vm/unit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ target_sources(vm-unit-tests PRIVATE
evm-as_tests.cpp
monad_vm_interface_tests.cpp
monad_vm_memory_pool_tests.cpp
mocked_host_tests.cpp
utils_tests.cpp
uint256_tests.cpp
uint128_tests.cpp
Expand Down Expand Up @@ -69,7 +70,6 @@ target_link_libraries(vm-unit-tests
PRIVATE monad-vm::monad-vm-interpreter
PRIVATE monad-vm::monad-vm-utils
PRIVATE GTest::gtest
PRIVATE evmc::mocked_host
PRIVATE monad_execution
PRIVATE monad_core
PRIVATE quill::quill
Expand Down
4 changes: 2 additions & 2 deletions test/vm/unit/evm_fixture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
#include <category/vm/runtime/types.hpp>
#include <category/vm/vm.hpp>
#include <monad/test/traits_test.hpp>
#include <test/vm/utils/mocked_host.hpp>
#include <test/vm/utils/test_message.hpp>

#include <monadml_evm/monadml_evm.hpp>

#include <evmc/evmc.hpp>
#include <evmc/mocked_host.hpp>

#include <gtest/gtest.h>

Expand Down Expand Up @@ -96,7 +96,7 @@ namespace monad::vm::compiler::test
monad::vm::test::TestMessage test_msg_;
evmc_message &msg_{*test_msg_};

evmc::MockedHost host_;
vm::test::MockedHost host_;

evmc::Result result_;

Expand Down
71 changes: 71 additions & 0 deletions test/vm/unit/mocked_host_tests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Copyright (C) 2025-26 Category Labs, Inc.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

#include <category/core/address.hpp>
#include <category/core/bytes.hpp>
#include <test/vm/utils/mocked_host.hpp>

#include <gtest/gtest.h>

#include <evmc/evmc.h>
#include <evmc/evmc.hpp>

using namespace monad;
using namespace monad::vm::test;

TEST(MockedHost, StorageStatus)
{
struct Transition
{
bytes32_t original;
bytes32_t current;
bytes32_t value;
evmc_storage_status status;
};

auto const O = bytes32_t{};
auto const X = bytes32_t{1};
auto const Y = bytes32_t{2};
auto const Z = bytes32_t{3};

Transition const transitions[] = {
{O, O, O, EVMC_STORAGE_ASSIGNED},
{X, O, O, EVMC_STORAGE_ASSIGNED},
{O, Y, Y, EVMC_STORAGE_ASSIGNED},
{X, Y, Y, EVMC_STORAGE_ASSIGNED},
{Y, Y, Y, EVMC_STORAGE_ASSIGNED},
{O, Y, Z, EVMC_STORAGE_ASSIGNED},
{X, Y, Z, EVMC_STORAGE_ASSIGNED},
{O, O, Z, EVMC_STORAGE_ADDED},
{X, X, O, EVMC_STORAGE_DELETED},
{X, X, Z, EVMC_STORAGE_MODIFIED},
{X, O, Z, EVMC_STORAGE_DELETED_ADDED},
{X, Y, O, EVMC_STORAGE_MODIFIED_DELETED},
{X, O, X, EVMC_STORAGE_DELETED_RESTORED},
{O, Y, O, EVMC_STORAGE_ADDED_DELETED},
{X, Y, X, EVMC_STORAGE_MODIFIED_RESTORED},
};

auto const addr = 0x00000000000000000000000000000000000000AA_address;
auto const key = bytes32_t{7};

for (auto const &t : transitions) {
MockedHost host;
host.accounts[addr].storage[key] = {
.current = t.current, .original = t.original};
EXPECT_EQ(host.set_storage(addr, key, t.value), t.status);
EXPECT_EQ(host.get_storage(addr, key), evmc::bytes32{t.value});
}
}
10 changes: 5 additions & 5 deletions test/vm/unit/monad_vm_interface_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
#include <category/vm/varcode_cache.hpp>
#include <category/vm/vm.hpp>

#include <test/vm/utils/mocked_host.hpp>
#include <test/vm/utils/test_context.hpp>
#include <test/vm/utils/test_message.hpp>

#include <asmjit/core/jitruntime.h>

#include <evmc/evmc.hpp>
#include <evmc/mocked_host.hpp>

#include <gtest/gtest.h>

Expand Down Expand Up @@ -416,7 +416,7 @@ TEST(MonadVmInterface, try_insert_varcode)
TEST(MonadVmInterface, execute_bytecode_raw)
{
VM vm;
evmc::MockedHost host;
test::MockedHost host;

auto [bytecode0, hash0] = make_bytecode(0);

Expand All @@ -438,7 +438,7 @@ TEST(MonadVmInterface, execute_bytecode_raw)
TEST(MonadVmInterface, execute_intercode_raw)
{
VM vm;
evmc::MockedHost host;
test::MockedHost host;

auto [bytecode0, hash0] = make_bytecode(0);
auto icode0 = make_shared_intercode(bytecode0);
Expand All @@ -460,7 +460,7 @@ TEST(MonadVmInterface, execute_intercode_raw)
TEST(MonadVmInterface, execute_native_entrypoint_raw)
{
VM vm;
evmc::MockedHost host;
test::MockedHost host;

auto [bytecode0, hash0] = make_bytecode(0);
auto icode0 = make_shared_intercode(bytecode0);
Expand All @@ -485,7 +485,7 @@ TEST(MonadVmInterface, execute_native_entrypoint_raw)
static void test_execute_raw(VM::Mode const mode)
{
VM vm{mode};
evmc::MockedHost host;
test::MockedHost host;

test::TestMessage msg{};
msg->gas = 100'000'000;
Expand Down
7 changes: 3 additions & 4 deletions test/vm/unit/runtime/fixture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
#include <category/core/keccak.hpp>
#include <category/core/runtime/uint256.hpp>
#include <category/vm/runtime/transmute.hpp>
#include <test/vm/utils/mocked_host.hpp>

#include <evmc/evmc.h>
#include <evmc/evmc.hpp>
#include <evmc/mocked_host.hpp>

#include <array>
#include <cstdint>
Expand Down Expand Up @@ -172,9 +172,8 @@ namespace monad::vm::compiler::test
auto const codehash = keccak256({code.data(), code.size()});
bytes32_t codehash_bytes;
std::copy(codehash.bytes, codehash.bytes + 32, codehash_bytes.bytes);
auto const account = evmc::MockedAccount{
.nonce = 0,
.code = evmc::bytes(code.data(), code.size()),
auto const account = vm::test::MockedAccount{
.code = byte_string(code.data(), code.size()),
.codehash = codehash_bytes,
.balance = {},
.storage = {},
Expand Down
2 changes: 1 addition & 1 deletion test/vm/unit/runtime/fixture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include <category/vm/runtime/detail.hpp>
#include <category/vm/runtime/types.hpp>
#include <monad/test/traits_test.hpp>
#include <test/vm/unit/runtime/mocked_host.hpp>
#include <test/vm/utils/mocked_host.hpp>
#include <test/vm/utils/test_context.hpp>

#include <gtest/gtest.h>
Expand Down
Loading
Loading