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 committed May 8, 2024
1 parent af17b74 commit 3ed337c
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";

Check warning on line 620 in test/state/state.cpp

View check run for this annotation

Codecov / codecov/patch

test/state/state.cpp#L617-L620

Added lines #L617 - L620 were not covered by tests
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";

Check warning on line 638 in test/state/state.cpp

View check run for this annotation

Codecov / codecov/patch

test/state/state.cpp#L625-L638

Added lines #L625 - L638 were not covered by tests
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_CreateBlobTx";
case EMPTY_BLOB_HASHES_LIST:
return "TR_EmptyBlobHashesList";
case INVALID_BLOB_HASH_VERSION:
return "TR_InvalidBlobHashVersion";
case BLOB_GAS_LIMIT_EXCEEDED:
return "TR_BlobGasLimitExceeded";

Check warning on line 654 in test/state/state.cpp

View check run for this annotation

Codecov / codecov/patch

test/state/state.cpp#L647-L654

Added lines #L647 - L654 were not covered by tests
case EOF_CREATION_TRANSACTION:
return "TR_EOFCreationTransaction";
case UNKNOWN_ERROR:
return "Unknown error";
default:
assert(false);

Check warning on line 660 in test/state/state.cpp

View check run for this annotation

Codecov / codecov/patch

test/state/state.cpp#L657-L660

Added lines #L657 - L660 were not covered by tests
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 3ed337c

Please sign in to comment.