Skip to content

Commit bd5dfab

Browse files
authored
test: Move invalid tx messages to state utils (#1030)
Moves the function `get_invalid_tx_message()` function from `evmone::state` (state.cpp) to `evmone::test` (statetest_export.cpp).
1 parent d37b501 commit bd5dfab

5 files changed

Lines changed: 52 additions & 51 deletions

File tree

test/state/state.cpp

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -568,49 +568,4 @@ std::variant<TransactionReceipt, std::error_code> transition(State& state, const
568568
return rlp::encode_tuple(withdrawal.index, withdrawal.validator_index, withdrawal.recipient,
569569
withdrawal.amount_in_gwei);
570570
}
571-
572-
[[nodiscard]] std::string get_tests_invalid_tx_message(ErrorCode errc) noexcept
573-
{
574-
switch (errc)
575-
{
576-
case SUCCESS:
577-
return "";
578-
case INTRINSIC_GAS_TOO_LOW:
579-
return "TR_IntrinsicGas";
580-
case TX_TYPE_NOT_SUPPORTED:
581-
return "TR_TypeNotSupported";
582-
case INSUFFICIENT_FUNDS:
583-
return "TR_NoFunds";
584-
case NONCE_HAS_MAX_VALUE:
585-
return "TR_NonceHasMaxValue:";
586-
case NONCE_TOO_HIGH:
587-
return "TR_NonceTooHigh";
588-
case NONCE_TOO_LOW:
589-
return "TR_NonceTooLow";
590-
case TIP_GT_FEE_CAP:
591-
return "TR_TipGtFeeCap";
592-
case FEE_CAP_LESS_THEN_BLOCKS:
593-
return "TR_FeeCapLessThanBlocks";
594-
case GAS_LIMIT_REACHED:
595-
return "TR_GasLimitReached";
596-
case SENDER_NOT_EOA:
597-
return "SenderNotEOA";
598-
case INIT_CODE_SIZE_LIMIT_EXCEEDED:
599-
return "TR_InitCodeLimitExceeded";
600-
case CREATE_BLOB_TX:
601-
return "TR_BLOBCREATE";
602-
case EMPTY_BLOB_HASHES_LIST:
603-
return "TR_EMPTYBLOB";
604-
case INVALID_BLOB_HASH_VERSION:
605-
return "TR_BLOBVERSION_INVALID";
606-
case BLOB_GAS_LIMIT_EXCEEDED:
607-
return "TR_BLOBLIST_OVERSIZE";
608-
case UNKNOWN_ERROR:
609-
return "Unknown error";
610-
default:
611-
assert(false);
612-
return "Wrong error code";
613-
}
614-
}
615-
616571
} // namespace evmone::state

test/state/state.hpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include "bloom_filter.hpp"
99
#include "errors.hpp"
1010
#include "hash_utils.hpp"
11-
#include <cassert>
1211
#include <optional>
1312
#include <variant>
1413
#include <vector>
@@ -286,7 +285,4 @@ std::variant<int64_t, std::error_code> validate_transaction(const Account& sende
286285

287286
/// Defines how to RLP-encode a Withdrawal.
288287
[[nodiscard]] bytes rlp_encode(const Withdrawal& withdrawal);
289-
290-
[[nodiscard]] std::string get_tests_invalid_tx_message(ErrorCode errc) noexcept;
291-
292288
} // namespace evmone::state

test/statetest/statetest.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ state::Transaction from_json<state::Transaction>(const json::json& j);
9595
/// Exports the State (accounts) to JSON format (aka pre/post/alloc state).
9696
json::json to_json(const TestState& state);
9797

98+
/// Returns the standardized error message for the transaction validation error.
99+
[[nodiscard]] std::string get_invalid_tx_message(state::ErrorCode errc) noexcept;
100+
101+
98102
std::vector<StateTransitionTest> load_state_tests(std::istream& input);
99103

100104
/// Validates an Ethereum state:

test/statetest/statetest_export.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,52 @@
66

77
namespace evmone::test
88
{
9+
[[nodiscard]] std::string get_invalid_tx_message(state::ErrorCode errc) noexcept
10+
{
11+
using namespace state;
12+
switch (errc)
13+
{
14+
case SUCCESS:
15+
return "";
16+
case INTRINSIC_GAS_TOO_LOW:
17+
return "TR_IntrinsicGas";
18+
case TX_TYPE_NOT_SUPPORTED:
19+
return "TR_TypeNotSupported";
20+
case INSUFFICIENT_FUNDS:
21+
return "TR_NoFunds";
22+
case NONCE_HAS_MAX_VALUE:
23+
return "TR_NonceHasMaxValue:";
24+
case NONCE_TOO_HIGH:
25+
return "TR_NonceTooHigh";
26+
case NONCE_TOO_LOW:
27+
return "TR_NonceTooLow";
28+
case TIP_GT_FEE_CAP:
29+
return "TR_TipGtFeeCap";
30+
case FEE_CAP_LESS_THEN_BLOCKS:
31+
return "TR_FeeCapLessThanBlocks";
32+
case GAS_LIMIT_REACHED:
33+
return "TR_GasLimitReached";
34+
case SENDER_NOT_EOA:
35+
return "SenderNotEOA";
36+
case INIT_CODE_SIZE_LIMIT_EXCEEDED:
37+
return "TR_InitCodeLimitExceeded";
38+
case CREATE_BLOB_TX:
39+
return "TR_BLOBCREATE";
40+
case EMPTY_BLOB_HASHES_LIST:
41+
return "TR_EMPTYBLOB";
42+
case INVALID_BLOB_HASH_VERSION:
43+
return "TR_BLOBVERSION_INVALID";
44+
case BLOB_GAS_LIMIT_EXCEEDED:
45+
return "TR_BLOBLIST_OVERSIZE";
46+
case UNKNOWN_ERROR:
47+
return "Unknown error";
48+
default:
49+
assert(false);
50+
return "Wrong error code";
51+
}
52+
}
53+
54+
955
json::json to_json(const TestState& state)
1056
{
1157
json::json j = json::json::object();

test/unittests/state_transition.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,8 @@ void state_transition::export_state_test(
228228

229229
if (holds_alternative<std::error_code>(res))
230230
{
231-
jpost["expectException"] = get_tests_invalid_tx_message(
232-
static_cast<ErrorCode>(std::get<std::error_code>(res).value()));
231+
jpost["expectException"] =
232+
get_invalid_tx_message(static_cast<ErrorCode>(std::get<std::error_code>(res).value()));
233233
jpost["logs"] = hex0x(logs_hash(std::vector<Log>()));
234234
}
235235
else

0 commit comments

Comments
 (0)