fix: Fix build issues post-clang-tidy changes (#7298)

This commit is contained in:
Mayukha Vadari
2026-05-20 13:44:18 -04:00
committed by GitHub
parent b664989cfb
commit d85bf722ea
11 changed files with 408 additions and 361 deletions

View File

@@ -48,7 +48,7 @@ class WasmHostFunctionsImpl : public HostFunctions
#ifdef DEBUG_OUTPUT
auto& j = std::cerr;
#else
if (!getJournal().active(beast::severities::kTrace))
if (!getJournal().active(beast::Severity::Trace))
return;
auto j = getJournal().trace();
#endif

View File

@@ -7,14 +7,22 @@
#include <boost/function_types/result_type.hpp>
#include <boost/mpl/vector.hpp>
#include <bit>
#include <cstdint>
#include <optional>
#include <string>
#include <type_traits>
#include <unordered_map>
#include <utility>
#include <vector>
namespace bft = boost::function_types;
namespace xrpl {
template <typename>
inline constexpr bool wasmDependentFalse = false;
using Bytes = std::vector<std::uint8_t>;
using Hash = xrpl::uint256;
@@ -48,7 +56,7 @@ struct WasmRuntimeWrapper
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
enum WasmTypes { WtI32, WtI64 };
enum class WasmTypes { WtI32, WtI64 };
struct WasmImportFunc
{
@@ -80,15 +88,15 @@ WasmImpArgs(WasmImportFunc& e)
using at = typename boost::mpl::at_c<Mpl, N>::type;
if constexpr (std::is_pointer_v<at>)
{
e.params.push_back(WtI32);
e.params.push_back(WasmTypes::WtI32);
}
else if constexpr (std::is_same_v<at, std::int32_t>)
{
e.params.push_back(WtI32);
e.params.push_back(WasmTypes::WtI32);
}
else if constexpr (std::is_same_v<at, std::int64_t>)
{
e.params.push_back(WtI64);
e.params.push_back(WasmTypes::WtI64);
}
else
{
@@ -106,27 +114,24 @@ WasmImpRet(WasmImportFunc& e)
{
if constexpr (std::is_pointer_v<Rt>)
{
e.result = WtI32;
e.result = WasmTypes::WtI32;
}
else if constexpr (std::is_same_v<Rt, std::int32_t>)
{
e.result = WtI32;
e.result = WasmTypes::WtI32;
}
else if constexpr (std::is_same_v<Rt, std::int64_t>)
{
e.result = WtI64;
e.result = WasmTypes::WtI64;
}
else if constexpr (std::is_void_v<Rt>)
{
e.result.reset();
#if (defined(__GNUC__) && (__GNUC__ >= 14)) || \
((defined(__clang_major__)) && (__clang_major__ >= 18))
}
else
{
static_assert(false, "Unsupported return type");
static_assert(wasmDependentFalse<Rt>, "Unsupported return type");
}
#endif
}
template <typename F>
@@ -166,7 +171,7 @@ struct WasmParam
{
// We are not supporting float/double
WasmTypes type = WtI32;
WasmTypes type = WasmTypes::WtI32;
union
{
std::int32_t i32;
@@ -178,7 +183,7 @@ template <class... Types>
inline void
wasmParamsHlp(std::vector<WasmParam>& v, std::int32_t p, Types&&... args)
{
v.push_back({.type = WtI32, .of = {.i32 = p}});
v.push_back({.type = WasmTypes::WtI32, .of = {.i32 = p}});
wasmParamsHlp(v, std::forward<Types>(args)...);
}
@@ -186,7 +191,7 @@ template <class... Types>
inline void
wasmParamsHlp(std::vector<WasmParam>& v, std::int64_t p, Types&&... args)
{
v.push_back({.type = WtI64, .of = {.i64 = p}});
v.push_back({.type = WasmTypes::WtI64, .of = {.i64 = p}});
wasmParamsHlp(v, std::forward<Types>(args)...);
}

View File

@@ -28,6 +28,7 @@ class WasmEngine
WasmEngine();
public:
WasmEngine(WasmEngine const&) = delete;
WasmEngine(WasmEngine&&) = delete;
WasmEngine&
@@ -35,7 +36,6 @@ class WasmEngine
WasmEngine&
operator=(WasmEngine&&) = delete;
public:
static WasmEngine&
instance();

View File

@@ -59,14 +59,14 @@ public:
{
try
{
Number const n;
Number n;
if constexpr (std::is_signed_v<T>)
{
n = Number(static_cast<int64_t>(mantissa), exponent);
}
else
{
n = Number(static_cast<uint64_t>(mantissa), exponent, Number::normalized());
n = Number(static_cast<uint64_t>(mantissa), exponent, Number::Normalized{});
}
*static_cast<Number*>(this) = n;
}
@@ -118,7 +118,8 @@ struct FloatState
FloatState(int32_t mode) : oldMode(Number::getround())
{
if (mode < Number::RoundingMode::ToNearest || mode > Number::RoundingMode::Upward)
if (mode < static_cast<int32_t>(Number::RoundingMode::ToNearest) ||
mode > static_cast<int32_t>(Number::RoundingMode::Upward))
return;
Number::setround(static_cast<Number::RoundingMode>(mode));
good = true;
@@ -141,7 +142,7 @@ std::string
floatToString(Slice const& data)
{
// set default mode as we don't expect it will be used here
detail::FloatState const rm(Number::RoundingMode::to_nearest);
detail::FloatState const rm(static_cast<int32_t>(Number::RoundingMode::ToNearest));
detail::WasmNumber const num(data);
if (!num)
{
@@ -274,7 +275,7 @@ floatToMantExpImpl(Slice const& x)
{
try
{
detail::FloatState const rm(Number::RoundingMode::to_nearest);
detail::FloatState const rm(static_cast<int32_t>(Number::RoundingMode::ToNearest));
if (!rm)
return Unexpected(HostFunctionError::FloatInputMalformed);
@@ -317,7 +318,7 @@ floatCompareImpl(Slice const& x, Slice const& y)
try
{
// set default mode as we don't expect it will be used here
detail::FloatState const rm(Number::RoundingMode::to_nearest);
detail::FloatState const rm(static_cast<int32_t>(Number::RoundingMode::ToNearest));
detail::WasmNumber const xx(x);
if (!xx)

View File

@@ -6,7 +6,6 @@
#include <xrpl/protocol/MPTIssue.h>
#include <xrpl/protocol/Protocol.h>
#include <xrpl/protocol/UintTypes.h>
#include <xrpl/protocol/jss.h>
#include <xrpl/tx/wasm/HostFunc.h>
#include <xrpl/tx/wasm/HostFuncImpl.h>
#include <xrpl/tx/wasm/ParamsHelper.h>
@@ -208,7 +207,7 @@ WasmHostFunctionsImpl::ticketKeylet(AccountID const& account, std::uint32_t seq)
{
if (!account)
return Unexpected(HostFunctionError::InvalidAccount);
auto const keylet = jss::ticket(account, seq);
auto const keylet = keylet::kTicket(account, seq);
return Bytes{keylet.key.begin(), keylet.key.end()};
}

View File

@@ -182,7 +182,7 @@ getDataUInt256(IW* runtime, wasm_val_vec_t const* params, int32_t& i)
return Unexpected(slice.error());
}
if (slice->size() != Bytes)
if (slice->size() != uint256::size())
{
return Unexpected(HostFunctionError::InvalidParams);
}
@@ -199,7 +199,7 @@ getDataAccountID(IW* runtime, wasm_val_vec_t const* params, int32_t& i)
return Unexpected(slice.error());
}
if (slice->size() != Bytes)
if (slice->size() != AccountID::size())
{
return Unexpected(HostFunctionError::InvalidParams);
}
@@ -217,7 +217,7 @@ getDataCurrency(IW* runtime, wasm_val_vec_t const* params, int32_t& i)
return Unexpected(slice.error());
}
if (slice->size() != Bytes)
if (slice->size() != Currency::size())
{
return Unexpected(HostFunctionError::InvalidParams);
}
@@ -235,13 +235,13 @@ getDataAsset(IW* runtime, wasm_val_vec_t const* params, int32_t& i)
return Unexpected(slice.error());
}
if (slice->size() == Bytes)
if (slice->size() == MPTID::size())
{
auto const mptid = MPTID::fromVoid(slice->data());
return Asset{mptid};
}
if (slice->size() == Bytes)
if (slice->size() == Currency::size())
{
auto const currency = Currency::fromVoid(slice->data());
auto const issue = Issue{currency, xrpAccount()};
@@ -250,10 +250,11 @@ getDataAsset(IW* runtime, wasm_val_vec_t const* params, int32_t& i)
return Asset{issue};
}
if (slice->size() == (Bytes + Bytes))
if (slice->size() == (Currency::size() + AccountID::size()))
{
auto const issue =
Issue(Currency::fromVoid(slice->data()), AccountID::fromVoid(slice->data() + Bytes));
auto const issue = Issue(
Currency::fromVoid(slice->data()),
AccountID::fromVoid(slice->data() + Currency::size()));
if (issue.native())
return Unexpected(HostFunctionError::InvalidParams);
@@ -507,7 +508,7 @@ isAmendmentEnabled_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t*
return hfResult(results, slice.error());
}
if (slice->size() == Bytes)
if (slice->size() == uint256::size())
{
if (auto const ret = hf->isAmendmentEnabled(uint256::fromVoid(slice->data()));
ret && *ret == 1)
@@ -1125,7 +1126,7 @@ mptokenKeylet_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* resu
return hfResult(results, slice.error());
}
if (slice->size() != Bytes)
if (slice->size() != MPTID::size())
{
return hfResult(results, HostFunctionError::InvalidParams);
}
@@ -2065,7 +2066,7 @@ testGetDataIncrement()
// test SFieldCRef
wasm_val_vec_t const params = {1, &values[0]};
values[0] = WASM_I32_VAL(sfAccount.fieldCode);
values[0] = WASM_I32_VAL(sfAccount.getCode());
int index = 0;
auto const result = getDataSField(&runtime, &params, index);
@@ -2109,8 +2110,8 @@ testGetDataIncrement()
wasm_val_vec_t const params = {2, &values[0]};
values[0] = WASM_I32_VAL(0);
values[1] = WASM_I32_VAL(id.bytes);
memcpy(&buffer[0], id.data(), id.bytes);
values[1] = WASM_I32_VAL(AccountID::size());
memcpy(&buffer[0], id.data(), AccountID::size());
int index = 0;
auto const result = getDataAccountID(&runtime, &params, index);
@@ -2125,8 +2126,8 @@ testGetDataIncrement()
wasm_val_vec_t const params = {2, &values[0]};
values[0] = WASM_I32_VAL(0);
values[1] = WASM_I32_VAL(h1.bytes);
memcpy(&buffer[0], h1.data(), h1.bytes);
values[1] = WASM_I32_VAL(Hash::size());
memcpy(&buffer[0], h1.data(), Hash::size());
int index = 0;
auto const result = getDataUInt256(&runtime, &params, index);
@@ -2141,10 +2142,10 @@ testGetDataIncrement()
wasm_val_vec_t const params = {2, &values[0]};
values[0] = WASM_I32_VAL(0);
values[1] = WASM_I32_VAL(c.bytes);
memcpy(&buffer[0], c.data(), c.bytes);
values[1] = WASM_I32_VAL(Currency::size());
memcpy(&buffer[0], c.data(), Currency::size());
int const index = 0;
int index = 0;
auto const result = getDataCurrency(&runtime, &params, index);
if (!result || result.value() != c || index != 2)
return false;

View File

@@ -3,6 +3,7 @@
#include <xrpl/basics/Expected.h>
#include <xrpl/beast/utility/Journal.h>
#include <xrpl/protocol/TER.h>
#include <xrpl/tx/wasm/HostFuncWrapper.h> // IWYU pragma: keep
#include <xrpl/tx/wasm/ParamsHelper.h>
#include <cstdint>

View File

@@ -43,7 +43,7 @@ printWasmError(std::string_view msg, wasm_trap_t* trap, beast::Journal jlog)
auto& j = std::cerr;
#else
auto j = jlog.warn();
if (jlog.active(beast::severities::kWarning))
if (jlog.active(beast::Severity::Warning))
#endif
{
wasm_byte_vec_t errorMessage WASM_EMPTY_VEC;
@@ -349,10 +349,10 @@ makeImpParams(WasmImportFunc const& imp)
auto const vt = imp.params[i];
switch (vt)
{
case WtI32:
case WasmTypes::WtI32:
v[i] = wasm_valtype_new_i32();
break;
case WtI64:
case WasmTypes::WtI64:
v[i] = wasm_valtype_new_i64();
break;
// LCOV_EXCL_START
@@ -373,11 +373,11 @@ makeImpReturn(WasmImportFunc const& imp)
WasmValtypeVec v(1);
switch (*imp.result)
{
case WtI32:
case WasmTypes::WtI32:
v[0] = wasm_valtype_new_i32();
break;
// LCOV_EXCL_START
case WtI64:
case WasmTypes::WtI64:
v[0] = wasm_valtype_new_i64();
break;
default:
@@ -623,15 +623,16 @@ WasmiEngine::convertParams(std::vector<WasmParam> const& params)
{
switch (p.type)
{
case WtI32:
case WasmTypes::WtI32:
v.push_back(WASM_I32_VAL(p.of.i32));
break;
// LCOV_EXCL_START
case WtI64:
case WasmTypes::WtI64:
v.push_back(WASM_I64_VAL(p.of.i64));
break;
default:
throw std::runtime_error("unknown parameter type: " + std::to_string(p.type));
throw std::runtime_error(
"unknown parameter type: " + std::to_string(static_cast<int>(p.type)));
break;
// LCOV_EXCL_STOP
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,5 +1,6 @@
#include <test/app/wasm_fixtures/fixtures.h>
#include <test/jtx.h>
#include <test/jtx/Env.h>
#include <test/unit_test/SuiteJournal.h>
#include <xrpl/ledger/AmendmentTable.h>
#include <xrpl/ledger/detail/ApplyViewBase.h>
@@ -8,6 +9,13 @@
#include <xrpl/tx/wasm/HostFunc.h>
#include <xrpl/tx/wasm/WasmVM.h>
#include <boost/algorithm/hex.hpp>
#include <cstdint>
#include <iterator>
#include <string>
#include <string_view>
namespace xrpl::test {
struct TestLedgerDataProvider : public HostFunctions
@@ -23,7 +31,7 @@ public:
void
setRT(void* rt) override
{
rt = rt;
this->rt = rt;
}
[[nodiscard]] void*
@@ -41,25 +49,25 @@ public:
struct TestHostFunctions : public HostFunctions
{
test::jtx::Env& env_;
AccountID accountID_;
Bytes data_;
test::jtx::Env& env;
AccountID accountID;
Bytes data;
int clock_drift = 0;
void* rt = nullptr;
public:
TestHostFunctions(test::jtx::Env& env, int cd = 0)
: HostFunctions(env.journal), env_(env), clock_drift(cd)
: HostFunctions(env.journal), env(env), clock_drift(cd)
{
accountID_ = env_.master.id();
accountID = env.master.id();
std::string t = "10000";
data_ = Bytes{t.begin(), t.end()};
data = Bytes{t.begin(), t.end()};
}
void
setRT(void* rt) override
{
rt = rt;
this->rt = rt;
}
[[nodiscard]] void*
@@ -83,7 +91,7 @@ public:
Expected<Hash, HostFunctionError>
getParentLedgerHash() const override
{
return env_.current()->header().parentHash;
return env.current()->header().parentHash;
}
Expected<std::uint32_t, HostFunctionError>
@@ -115,7 +123,7 @@ public:
{
if (fname == sfAccount)
{
return Bytes(accountID_.begin(), accountID_.end());
return Bytes(accountID.begin(), accountID.end());
}
if (fname == sfFee)
{
@@ -123,7 +131,7 @@ public:
uint8_t const* p = reinterpret_cast<uint8_t const*>(&x);
return Bytes{p, p + sizeof(x)};
}
else if (fname == sfSequence)
if (fname == sfSequence)
{
auto const x = getLedgerSqn();
if (!x)
@@ -142,13 +150,15 @@ public:
auto const& sn = fname.getName();
if (sn == "Destination" || sn == "Account")
{
return Bytes(accountID_.begin(), accountID_.end());
return Bytes(accountID.begin(), accountID.end());
}
if (sn == "Data")
return data_;
else if (sn == "FinishAfter")
{
auto t = env_.current()->parentCloseTime().time_since_epoch().count();
return data;
}
if (sn == "FinishAfter")
{
auto t = env.current()->parentCloseTime().time_since_epoch().count();
std::string s = std::to_string(t);
return Bytes{s.begin(), s.end()};
}
@@ -167,9 +177,9 @@ public:
}
if (fname == sfAccount)
{
return Bytes(accountID_.begin(), accountID_.end());
return Bytes(accountID.begin(), accountID.end());
}
return data_;
return data;
}
Expected<Bytes, HostFunctionError>
@@ -179,9 +189,9 @@ public:
{
int32_t const* l = reinterpret_cast<int32_t const*>(locator.data());
int32_t const sfield = l[0];
if (sfield == sfAccount.fieldCode)
if (sfield == sfAccount.getCode())
{
return Bytes(accountID_.begin(), accountID_.end());
return Bytes(accountID.begin(), accountID.end());
}
}
uint8_t const a[] = {0x2b, 0x6a, 0x23, 0x2a, 0xa4, 0xc4, 0xbe, 0x41, 0xbf, 0x49, 0xd2,
@@ -197,9 +207,9 @@ public:
{
int32_t const* l = reinterpret_cast<int32_t const*>(locator.data());
int32_t const sfield = l[0];
if (sfield == sfAccount.fieldCode)
if (sfield == sfAccount.getCode())
{
return Bytes(accountID_.begin(), accountID_.end());
return Bytes(accountID.begin(), accountID.end());
}
}
uint8_t const a[] = {0x2b, 0x6a, 0x23, 0x2a, 0xa4, 0xc4, 0xbe, 0x41, 0xbf, 0x49, 0xd2,
@@ -215,9 +225,9 @@ public:
{
int32_t const* l = reinterpret_cast<int32_t const*>(locator.data());
int32_t const sfield = l[0];
if (sfield == sfAccount.fieldCode)
if (sfield == sfAccount.getCode())
{
return Bytes(accountID_.begin(), accountID_.end());
return Bytes(accountID.begin(), accountID.end());
}
}
uint8_t const a[] = {0x2b, 0x6a, 0x23, 0x2a, 0xa4, 0xc4, 0xbe, 0x41, 0xbf, 0x49, 0xd2,
@@ -277,7 +287,7 @@ public:
Expected<Hash, HostFunctionError>
computeSha512HalfHash(Slice const& data) const override
{
return env_.current()->header().parentHash;
return env.current()->header().parentHash;
}
Expected<Bytes, HostFunctionError>
@@ -353,7 +363,7 @@ public:
Expected<Bytes, HostFunctionError>
getNFTIssuer(uint256 const& nftId) const override
{
return Bytes(accountID_.begin(), accountID_.end());
return Bytes(accountID.begin(), accountID.end());
}
Expected<std::uint32_t, HostFunctionError>
@@ -387,7 +397,7 @@ public:
#ifdef DEBUG_OUTPUT
auto& j = std::cerr;
#else
if (!getJournal().active(beast::severities::kTrace))
if (!getJournal().active(beast::Severity::Trace))
return;
auto j = getJournal().trace();
#endif
@@ -540,7 +550,7 @@ struct TestHostFunctionsSink : public TestHostFunctions
public:
explicit TestHostFunctionsSink(test::jtx::Env& env, int cd = 0)
: TestHostFunctions(env, cd), sink_(beast::severities::kDebug)
: TestHostFunctions(env, cd), sink(beast::Severity::Debug)
{
j = beast::Journal(sink);
}

View File

@@ -6,6 +6,7 @@
#include <xrpl/protocol/SField.h>
#include <xrpl/protocol/TER.h>
#include <xrpl/tx/wasm/HostFunc.h>
#include <xrpl/tx/wasm/HostFuncWrapper.h> // IWYU pragma: keep
#include <xrpl/tx/wasm/ParamsHelper.h>
#include <xrpl/tx/wasm/WasmVM.h>
@@ -95,7 +96,7 @@ uleb128(IT&& it)
return {val, count};
}
std::pair<unsigned, unsigned>
static std::pair<unsigned, unsigned>
getSection(Bytes const& module, std::uint8_t n)
{
static std::uint8_t const kHdr[] = {0x00, 0x61, 0x73, 0x6D};
@@ -134,7 +135,7 @@ getSection(Bytes const& module, std::uint8_t n)
return {0, 0};
}
std::optional<int32_t>
static std::optional<int32_t>
runFinishFunction(std::string const& code)
{
auto& engine = WasmEngine::instance();
@@ -149,6 +150,13 @@ runFinishFunction(std::string const& code)
return std::nullopt;
}
static bool
finishFunctionReturns(std::string const& code, int32_t expected)
{
auto const result = runFinishFunction(code);
return result.has_value() && *result == expected;
}
struct Wasm_test : public beast::unit_test::Suite
{
void
@@ -692,82 +700,82 @@ struct Wasm_test : public beast::unit_test::Suite
testWasmMemory()
{
testcase("Wasm additional memory limit tests");
BEAST_EXPECT(runFinishFunction(kMemoryPointerAtLimitHex).value() == 1);
BEAST_EXPECT(runFinishFunction(kMemoryPointerOverLimitHex).has_value() == false);
BEAST_EXPECT(runFinishFunction(kMemoryOffsetOverLimitHex).has_value() == false);
BEAST_EXPECT(runFinishFunction(kMemoryEndOfWordOverLimitHex).has_value() == false);
BEAST_EXPECT(runFinishFunction(kMemoryGrow0To1PageHex).value() == 1);
BEAST_EXPECT(runFinishFunction(kMemoryGrow1To0PageHex).value() == -1);
BEAST_EXPECT(runFinishFunction(kMemoryLastByteOf8MbHex).value() == 1);
BEAST_EXPECT(runFinishFunction(kMemoryGrow1MoreThan8MbHex).value() == -1);
BEAST_EXPECT(runFinishFunction(kMemoryGrow0MoreThan8MbHex).value() == 1);
BEAST_EXPECT(runFinishFunction(kMemoryInit1MoreThan8MbHex).has_value() == false);
BEAST_EXPECT(runFinishFunction(kMemoryNegativeAddressHex).has_value() == false);
BEAST_EXPECT(finishFunctionReturns(kMemoryPointerAtLimitHex, 1));
BEAST_EXPECT(!runFinishFunction(kMemoryPointerOverLimitHex).has_value());
BEAST_EXPECT(!runFinishFunction(kMemoryOffsetOverLimitHex).has_value());
BEAST_EXPECT(!runFinishFunction(kMemoryEndOfWordOverLimitHex).has_value());
BEAST_EXPECT(finishFunctionReturns(kMemoryGrow0To1PageHex, 1));
BEAST_EXPECT(finishFunctionReturns(kMemoryGrow1To0PageHex, -1));
BEAST_EXPECT(finishFunctionReturns(kMemoryLastByteOf8MbHex, 1));
BEAST_EXPECT(finishFunctionReturns(kMemoryGrow1MoreThan8MbHex, -1));
BEAST_EXPECT(finishFunctionReturns(kMemoryGrow0MoreThan8MbHex, 1));
BEAST_EXPECT(!runFinishFunction(kMemoryInit1MoreThan8MbHex).has_value());
BEAST_EXPECT(!runFinishFunction(kMemoryNegativeAddressHex).has_value());
}
void
testWasmTable()
{
testcase("Wasm table limit tests");
BEAST_EXPECT(runFinishFunction(kTable64ElementsHex).value() == 1);
BEAST_EXPECT(runFinishFunction(kTable65ElementsHex).has_value() == false);
BEAST_EXPECT(runFinishFunction(kTable2TablesHex).has_value() == false);
BEAST_EXPECT(runFinishFunction(kTable0ElementsHex).value() == 1);
BEAST_EXPECT(runFinishFunction(kTableUintMaxHex).has_value() == false);
BEAST_EXPECT(finishFunctionReturns(kTable64ElementsHex, 1));
BEAST_EXPECT(!runFinishFunction(kTable65ElementsHex).has_value());
BEAST_EXPECT(!runFinishFunction(kTable2TablesHex).has_value());
BEAST_EXPECT(finishFunctionReturns(kTable0ElementsHex, 1));
BEAST_EXPECT(!runFinishFunction(kTableUintMaxHex).has_value());
}
void
testWasmProposal()
{
testcase("Wasm disabled proposal tests");
BEAST_EXPECT(runFinishFunction(kProposalMutableGlobalHex).has_value() == false);
BEAST_EXPECT(runFinishFunction(kProposalGcStructNewHex).has_value() == false);
BEAST_EXPECT(runFinishFunction(kProposalMultiValueHex).has_value() == false);
BEAST_EXPECT(runFinishFunction(kProposalSignExtHex).has_value() == false);
BEAST_EXPECT(runFinishFunction(kProposalFloatToIntHex).has_value() == false);
BEAST_EXPECT(runFinishFunction(kProposalBulkMemoryHex).has_value() == false);
BEAST_EXPECT(runFinishFunction(kProposalRefTypesHex).has_value() == false);
BEAST_EXPECT(runFinishFunction(kProposalTailCallHex).has_value() == false);
BEAST_EXPECT(runFinishFunction(kProposalExtendedConstHex).has_value() == false);
BEAST_EXPECT(runFinishFunction(kProposalMultiMemoryHex).has_value() == false);
BEAST_EXPECT(runFinishFunction(kProposalCustomPageSizesHex).has_value() == false);
BEAST_EXPECT(runFinishFunction(kProposalMemory64Hex).has_value() == false);
BEAST_EXPECT(runFinishFunction(kProposalWideArithmeticHex).has_value() == false);
BEAST_EXPECT(!runFinishFunction(kProposalMutableGlobalHex).has_value());
BEAST_EXPECT(!runFinishFunction(kProposalGcStructNewHex).has_value());
BEAST_EXPECT(!runFinishFunction(kProposalMultiValueHex).has_value());
BEAST_EXPECT(!runFinishFunction(kProposalSignExtHex).has_value());
BEAST_EXPECT(!runFinishFunction(kProposalFloatToIntHex).has_value());
BEAST_EXPECT(!runFinishFunction(kProposalBulkMemoryHex).has_value());
BEAST_EXPECT(!runFinishFunction(kProposalRefTypesHex).has_value());
BEAST_EXPECT(!runFinishFunction(kProposalTailCallHex).has_value());
BEAST_EXPECT(!runFinishFunction(kProposalExtendedConstHex).has_value());
BEAST_EXPECT(!runFinishFunction(kProposalMultiMemoryHex).has_value());
BEAST_EXPECT(!runFinishFunction(kProposalCustomPageSizesHex).has_value());
BEAST_EXPECT(!runFinishFunction(kProposalMemory64Hex).has_value());
BEAST_EXPECT(!runFinishFunction(kProposalWideArithmeticHex).has_value());
}
void
testWasmTrap()
{
testcase("Wasm trap tests");
BEAST_EXPECT(runFinishFunction(kTrapDivideBy0Hex).has_value() == false);
BEAST_EXPECT(runFinishFunction(kTrapIntOverflowHex).has_value() == false);
BEAST_EXPECT(runFinishFunction(kTrapUnreachableHex).has_value() == false);
BEAST_EXPECT(runFinishFunction(kTrapNullCallHex).has_value() == false);
BEAST_EXPECT(runFinishFunction(kTrapFuncSigMismatchHex).has_value() == false);
BEAST_EXPECT(!runFinishFunction(kTrapDivideBy0Hex).has_value());
BEAST_EXPECT(!runFinishFunction(kTrapIntOverflowHex).has_value());
BEAST_EXPECT(!runFinishFunction(kTrapUnreachableHex).has_value());
BEAST_EXPECT(!runFinishFunction(kTrapNullCallHex).has_value());
BEAST_EXPECT(!runFinishFunction(kTrapFuncSigMismatchHex).has_value());
}
void
testWasmWasi()
{
testcase("Wasm Wasi tests");
BEAST_EXPECT(runFinishFunction(kWasiGetTimeHex).has_value() == false);
BEAST_EXPECT(runFinishFunction(kWasiPrintHex).has_value() == false);
BEAST_EXPECT(!runFinishFunction(kWasiGetTimeHex).has_value());
BEAST_EXPECT(!runFinishFunction(kWasiPrintHex).has_value());
}
void
testWasmSectionCorruption()
{
testcase("Wasm Section Corruption tests");
BEAST_EXPECT(runFinishFunction(kBadMagicNumberHex).has_value() == false);
BEAST_EXPECT(runFinishFunction(kBadVersionNumberHex).has_value() == false);
BEAST_EXPECT(runFinishFunction(kLyingHeaderHex).has_value() == false);
BEAST_EXPECT(runFinishFunction(kNeverEndingNumberHex).has_value() == false);
BEAST_EXPECT(runFinishFunction(kVectorLieHex).has_value() == false);
BEAST_EXPECT(runFinishFunction(kSectionOrderingHex).has_value() == false);
BEAST_EXPECT(runFinishFunction(kGhostPayloadHex).has_value() == false);
BEAST_EXPECT(runFinishFunction(kJunkAfterSectionHex).has_value() == false);
BEAST_EXPECT(runFinishFunction(kInvalidSectionIdHex).has_value() == false);
BEAST_EXPECT(runFinishFunction(kLocalVariableBombHex).has_value() == false);
BEAST_EXPECT(!runFinishFunction(kBadMagicNumberHex).has_value());
BEAST_EXPECT(!runFinishFunction(kBadVersionNumberHex).has_value());
BEAST_EXPECT(!runFinishFunction(kLyingHeaderHex).has_value());
BEAST_EXPECT(!runFinishFunction(kNeverEndingNumberHex).has_value());
BEAST_EXPECT(!runFinishFunction(kVectorLieHex).has_value());
BEAST_EXPECT(!runFinishFunction(kSectionOrderingHex).has_value());
BEAST_EXPECT(!runFinishFunction(kGhostPayloadHex).has_value());
BEAST_EXPECT(!runFinishFunction(kJunkAfterSectionHex).has_value());
BEAST_EXPECT(!runFinishFunction(kInvalidSectionIdHex).has_value());
BEAST_EXPECT(!runFinishFunction(kLocalVariableBombHex).has_value());
}
void
@@ -998,7 +1006,7 @@ struct Wasm_test : public beast::unit_test::Suite
std::vector<WasmParam> params;
params.reserve(1000);
for (int i = 0; i < 1000; ++i)
params.push_back({.type = WtI32, .of = {.i32 = 2 * i}});
params.push_back({.type = WasmTypes::WtI32, .of = {.i32 = 2 * i}});
auto& engine = WasmEngine::instance();
{
@@ -1007,7 +1015,7 @@ struct Wasm_test : public beast::unit_test::Suite
}
// add 1 more parameter, module can't be created now
params.push_back({.type = WtI32, .of = {.i32 = 2 * 1000}});
params.push_back({.type = WasmTypes::WtI32, .of = {.i32 = 2 * 1000}});
{
auto re = engine.run(params1k1, hfs, 1'000'000, "test", params, imports, env.journal);
BEAST_EXPECT(!re);