From 69b3c353154edd184b3fa4203ff1afab6f6b1538 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Fri, 13 Sep 2024 12:09:12 +0200 Subject: [PATCH] test: Add a state test reaching CALL max depth --- test/unittests/state_transition.cpp | 2 +- test/unittests/state_transition_call_test.cpp | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/test/unittests/state_transition.cpp b/test/unittests/state_transition.cpp index 804daa6d05..2a6a7d3979 100644 --- a/test/unittests/state_transition.cpp +++ b/test/unittests/state_transition.cpp @@ -13,7 +13,7 @@ namespace evmone::test { void state_transition::SetUp() { - pre.insert(tx.sender, {.nonce = 1, .balance = tx.gas_limit * tx.max_gas_price + tx.value + 1}); + pre[tx.sender] = {.nonce = 1, .balance = tx.gas_limit * tx.max_gas_price + tx.value + 1}; // Default expectation (coinbase is added later for valid txs only). expect.post[tx.sender].exists = true; diff --git a/test/unittests/state_transition_call_test.cpp b/test/unittests/state_transition_call_test.cpp index 551310d482..bc3a92d4ae 100644 --- a/test/unittests/state_transition_call_test.cpp +++ b/test/unittests/state_transition_call_test.cpp @@ -50,3 +50,20 @@ TEST_F(state_transition, delegatecall_static_legacy) expect.post[CALLEE1].storage[0x01_bytes32] = 0xdd_bytes32; expect.post[CALLEE2].storage[0x01_bytes32] = 0xdd_bytes32; } + +TEST_F(state_transition, call_max_depth) +{ + static constexpr auto JUMPDEST_POS = 38; + const auto code = jumpi(JUMPDEST_POS, eq(calldataload(0), 1024)) + + mstore(0, add(calldataload(0), 1)) + + call(OP_ADDRESS).input(0, 32).gas(0xffffffffff) + OP_STOP + OP_JUMPDEST + + sstore(0, calldataload(0)); + ASSERT_EQ(code.find(OP_JUMPDEST), JUMPDEST_POS); + + block.gas_limit = 1'000'000'000'000; + tx.gas_limit = block.gas_limit; + tx.to = To; + pre[To].code = code; + pre[Sender].balance = tx.gas_limit * tx.max_gas_price; + expect.post[To].storage[0x00_bytes32] = 0x0400_bytes32; +}