Skip to content

Commit

Permalink
Fix exported error messages for invalid tx tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pdobacz authored and chfast committed May 24, 2024
1 parent 633f696 commit 1516682
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
52 changes: 52 additions & 0 deletions test/state/state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -610,4 +610,56 @@ std::variant<TransactionReceipt, std::error_code> transition(State& state, const
withdrawal.amount_in_gwei);
}

[[nodiscard]] std::string get_tests_invalid_tx_message(ErrorCode errc) noexcept
{
switch (errc)
{
case SUCCESS:
return "";
case INTRINSIC_GAS_TOO_LOW:
return "TR_IntrinsicGas";
case TX_TYPE_NOT_SUPPORTED:
return "TR_TypeNotSupported";
case INSUFFICIENT_FUNDS:
return "TR_NoFunds";
case NONCE_HAS_MAX_VALUE:
return "TR_NonceHasMaxValue:";
case NONCE_TOO_HIGH:
return "TR_NonceTooHigh";
case NONCE_TOO_LOW:
return "TR_NonceTooLow";
case TIP_GT_FEE_CAP:
return "TR_TipGtFeeCap";
case FEE_CAP_LESS_THEN_BLOCKS:
return "TR_FeeCapLessThanBlocks";
case GAS_LIMIT_REACHED:
return "TR_GasLimitReached";
case SENDER_NOT_EOA:
return "SenderNotEOA";
case INIT_CODE_SIZE_LIMIT_EXCEEDED:
return "TR_InitCodeLimitExceeded";
case INIT_CODE_EMPTY:
return "TR_InitCodeEmpty";
case INIT_CODE_COUNT_LIMIT_EXCEEDED:
return "TR_InitCodeCountLimitExceeded";
case INIT_CODE_COUNT_ZERO:
return "TR_InitCodeCountZero";
case CREATE_BLOB_TX:
return "TR_BLOBCREATE";
case EMPTY_BLOB_HASHES_LIST:
return "TR_EMPTYBLOB";
case INVALID_BLOB_HASH_VERSION:
return "TR_BLOBVERSION_INVALID";
case BLOB_GAS_LIMIT_EXCEEDED:
return "TR_BLOBLIST_OVERSIZE";
case EOF_CREATION_TRANSACTION:
return "TR_EOFCreationTransaction";
case UNKNOWN_ERROR:
return "Unknown error";
default:
assert(false);
return "Wrong error code";
}
}

} // namespace evmone::state
3 changes: 3 additions & 0 deletions test/state/state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "account.hpp"
#include "bloom_filter.hpp"
#include "errors.hpp"
#include "hash_utils.hpp"
#include <cassert>
#include <optional>
Expand Down Expand Up @@ -293,4 +294,6 @@ void system_call(State& state, const BlockInfo& block, evmc_revision rev, evmc::
/// Defines how to RLP-encode a Withdrawal.
[[nodiscard]] bytes rlp_encode(const Withdrawal& withdrawal);

[[nodiscard]] std::string get_tests_invalid_tx_message(ErrorCode errc) noexcept;

} // namespace evmone::state
3 changes: 2 additions & 1 deletion test/unittests/state_transition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,8 @@ void state_transition::export_state_test(

if (holds_alternative<std::error_code>(res))
{
jpost["expectException"] = std::get<std::error_code>(res).message();
jpost["expectException"] = get_tests_invalid_tx_message(
static_cast<ErrorCode>(std::get<std::error_code>(res).value()));
jpost["logs"] = hex0x(logs_hash(std::vector<Log>()));
}
else
Expand Down

0 comments on commit 1516682

Please sign in to comment.