From d85bf722ea2acf0a080ad2bcf1f9dc56e0586b47 Mon Sep 17 00:00:00 2001 From: Mayukha Vadari Date: Wed, 20 May 2026 13:44:18 -0400 Subject: [PATCH] fix: Fix build issues post-clang-tidy changes (#7298) --- include/xrpl/tx/wasm/HostFuncImpl.h | 2 +- include/xrpl/tx/wasm/ParamsHelper.h | 33 +- include/xrpl/tx/wasm/WasmVM.h | 2 +- src/libxrpl/tx/wasm/HostFuncImplFloat.cpp | 13 +- src/libxrpl/tx/wasm/HostFuncImplKeylet.cpp | 3 +- src/libxrpl/tx/wasm/HostFuncWrapper.cpp | 37 +- src/libxrpl/tx/wasm/WasmVM.cpp | 1 + src/libxrpl/tx/wasm/WasmiVM.cpp | 17 +- src/test/app/HostFuncImpl_test.cpp | 487 +++++++++++---------- src/test/app/TestHostFunctions.h | 66 +-- src/test/app/Wasm_test.cpp | 108 ++--- 11 files changed, 408 insertions(+), 361 deletions(-) diff --git a/include/xrpl/tx/wasm/HostFuncImpl.h b/include/xrpl/tx/wasm/HostFuncImpl.h index 4033a4aaf9..689ce85a59 100644 --- a/include/xrpl/tx/wasm/HostFuncImpl.h +++ b/include/xrpl/tx/wasm/HostFuncImpl.h @@ -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 diff --git a/include/xrpl/tx/wasm/ParamsHelper.h b/include/xrpl/tx/wasm/ParamsHelper.h index 4a2e99d490..266b1dd334 100644 --- a/include/xrpl/tx/wasm/ParamsHelper.h +++ b/include/xrpl/tx/wasm/ParamsHelper.h @@ -7,14 +7,22 @@ #include #include +#include +#include #include #include +#include +#include +#include #include namespace bft = boost::function_types; namespace xrpl { +template +inline constexpr bool wasmDependentFalse = false; + using Bytes = std::vector; 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::type; if constexpr (std::is_pointer_v) { - e.params.push_back(WtI32); + e.params.push_back(WasmTypes::WtI32); } else if constexpr (std::is_same_v) { - e.params.push_back(WtI32); + e.params.push_back(WasmTypes::WtI32); } else if constexpr (std::is_same_v) { - 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) { - e.result = WtI32; + e.result = WasmTypes::WtI32; } else if constexpr (std::is_same_v) { - e.result = WtI32; + e.result = WasmTypes::WtI32; } else if constexpr (std::is_same_v) { - e.result = WtI64; + e.result = WasmTypes::WtI64; } else if constexpr (std::is_void_v) { e.result.reset(); -#if (defined(__GNUC__) && (__GNUC__ >= 14)) || \ - ((defined(__clang_major__)) && (__clang_major__ >= 18)) } else { - static_assert(false, "Unsupported return type"); + static_assert(wasmDependentFalse, "Unsupported return type"); } -#endif } template @@ -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 inline void wasmParamsHlp(std::vector& 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(args)...); } @@ -186,7 +191,7 @@ template inline void wasmParamsHlp(std::vector& 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(args)...); } diff --git a/include/xrpl/tx/wasm/WasmVM.h b/include/xrpl/tx/wasm/WasmVM.h index 1e371a92b4..761ed4c618 100644 --- a/include/xrpl/tx/wasm/WasmVM.h +++ b/include/xrpl/tx/wasm/WasmVM.h @@ -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(); diff --git a/src/libxrpl/tx/wasm/HostFuncImplFloat.cpp b/src/libxrpl/tx/wasm/HostFuncImplFloat.cpp index f85a17a2d2..c950aed947 100644 --- a/src/libxrpl/tx/wasm/HostFuncImplFloat.cpp +++ b/src/libxrpl/tx/wasm/HostFuncImplFloat.cpp @@ -59,14 +59,14 @@ public: { try { - Number const n; + Number n; if constexpr (std::is_signed_v) { n = Number(static_cast(mantissa), exponent); } else { - n = Number(static_cast(mantissa), exponent, Number::normalized()); + n = Number(static_cast(mantissa), exponent, Number::Normalized{}); } *static_cast(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(Number::RoundingMode::ToNearest) || + mode > static_cast(Number::RoundingMode::Upward)) return; Number::setround(static_cast(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(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(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(Number::RoundingMode::ToNearest)); detail::WasmNumber const xx(x); if (!xx) diff --git a/src/libxrpl/tx/wasm/HostFuncImplKeylet.cpp b/src/libxrpl/tx/wasm/HostFuncImplKeylet.cpp index e9d54d89fa..1c589dee09 100644 --- a/src/libxrpl/tx/wasm/HostFuncImplKeylet.cpp +++ b/src/libxrpl/tx/wasm/HostFuncImplKeylet.cpp @@ -6,7 +6,6 @@ #include #include #include -#include #include #include #include @@ -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()}; } diff --git a/src/libxrpl/tx/wasm/HostFuncWrapper.cpp b/src/libxrpl/tx/wasm/HostFuncWrapper.cpp index b303fcc47e..1b10608667 100644 --- a/src/libxrpl/tx/wasm/HostFuncWrapper.cpp +++ b/src/libxrpl/tx/wasm/HostFuncWrapper.cpp @@ -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, ¶ms, 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, ¶ms, 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, ¶ms, 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, ¶ms, index); if (!result || result.value() != c || index != 2) return false; diff --git a/src/libxrpl/tx/wasm/WasmVM.cpp b/src/libxrpl/tx/wasm/WasmVM.cpp index 9dd0d2c736..c3c724cd43 100644 --- a/src/libxrpl/tx/wasm/WasmVM.cpp +++ b/src/libxrpl/tx/wasm/WasmVM.cpp @@ -3,6 +3,7 @@ #include #include #include +#include // IWYU pragma: keep #include #include diff --git a/src/libxrpl/tx/wasm/WasmiVM.cpp b/src/libxrpl/tx/wasm/WasmiVM.cpp index a961f8bc16..e22380741b 100644 --- a/src/libxrpl/tx/wasm/WasmiVM.cpp +++ b/src/libxrpl/tx/wasm/WasmiVM.cpp @@ -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 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(p.type))); break; // LCOV_EXCL_STOP } diff --git a/src/test/app/HostFuncImpl_test.cpp b/src/test/app/HostFuncImpl_test.cpp index 01355237ae..04d3429bfe 100644 --- a/src/test/app/HostFuncImpl_test.cpp +++ b/src/test/app/HostFuncImpl_test.cpp @@ -2,21 +2,26 @@ #include #include #include +#include #include +#include #include #include #include #include #include +#include #include #include +#include #include #include #include #include #include #include +#include #include #include #include @@ -30,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -42,9 +48,12 @@ #include #include +#include + #include #include +#include #include #include #include @@ -52,11 +61,13 @@ #include #include #include +#include #include #include #include #include #include +#include namespace xrpl::test { @@ -137,7 +148,7 @@ createApplyContext( beast::Journal j, STTx const& tx = STTx(ttESCROW_FINISH, [](STObject&) {})) { - ApplyContext ac{env.app(), ov, tx, tesSUCCESS, env.current()->fees().base, tapNONE, j}; + ApplyContext ac{env.app(), ov, tx, tesSUCCESS, env.current()->fees().base, TapNone, j}; return ac; } @@ -310,8 +321,7 @@ wasm_trap_t* ww(F&& f, E&& e, P&& params, P&& result, Args... args) { size_t idx = 0; - (ww_hlp(idx, std::forward(e), std::forward

(params), std::forward(args)), - ...); // NOLINT + (ww_hlp(idx, e, params, std::forward(args)), ...); // NOLINT return f(std::forward(e), params.get(), result.get()); // NOLINT } @@ -414,15 +424,15 @@ struct HostFuncImpl_test : public beast::unit_test::Suite params, result, 0, - Bytes); + uint256::size()); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && - BEAST_EXPECT(result[0].of.i32 == Bytes); + BEAST_EXPECT(result[0].of.i32 == uint256::size()); auto const resultBytes = vrt.getBytes(params, 0); auto const expectedHash = env.current()->header().parentHash; BEAST_EXPECT( - resultBytes.size() == Bytes && - std::memcmp(resultBytes.data(), expectedHash.data(), Bytes) == 0); + resultBytes.size() == uint256::size() && + std::memcmp(resultBytes.data(), expectedHash.data(), uint256::size()) == 0); } } @@ -481,9 +491,14 @@ struct HostFuncImpl_test : public beast::unit_test::Suite // hfs.isAmendmentEnabled(amendmentId); { WasmValVec params(2), result(1); - vrt.setBytes(0, amendmentId.data(), Bytes); - auto* trap = ww( - isAmendmentEnabled_wrap, &import.at("amendment_enabled"), params, result, 0, Bytes); + vrt.setBytes(0, amendmentId.data(), uint256::size()); + auto* trap = + ww(isAmendmentEnabled_wrap, + &import.at("amendment_enabled"), + params, + result, + 0, + uint256::size()); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && BEAST_EXPECT(result[0].of.i32 == 1); @@ -510,9 +525,14 @@ struct HostFuncImpl_test : public beast::unit_test::Suite // hfs.isAmendmentEnabled(fakeId); { WasmValVec params(2), result(1); - vrt.setBytes(0, fakeId.data(), Bytes); - auto* trap = ww( - isAmendmentEnabled_wrap, &import.at("amendment_enabled"), params, result, 0, Bytes); + vrt.setBytes(0, fakeId.data(), uint256::size()); + auto* trap = + ww(isAmendmentEnabled_wrap, + &import.at("amendment_enabled"), + params, + result, + 0, + uint256::size()); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && BEAST_EXPECT(result[0].of.i32 == 0); @@ -557,14 +577,14 @@ struct HostFuncImpl_test : public beast::unit_test::Suite // hfs.cacheLedgerObj(accountKeylet.key, -1); { WasmValVec params(3), result(1); - vrt.setBytes(0, accountKeylet.key.data(), Bytes); + vrt.setBytes(0, accountKeylet.key.data(), uint256::size()); auto* trap = ww(cacheLedgerObj_wrap, &import.at("cache_ledger_obj"), params, result, 0, - Bytes, + uint256::size(), -1); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && @@ -575,14 +595,14 @@ struct HostFuncImpl_test : public beast::unit_test::Suite // hfs.cacheLedgerObj(accountKeylet.key, 257); { WasmValVec params(3), result(1); - vrt.setBytes(0, accountKeylet.key.data(), Bytes); + vrt.setBytes(0, accountKeylet.key.data(), uint256::size()); auto* trap = ww(cacheLedgerObj_wrap, &import.at("cache_ledger_obj"), params, result, 0, - Bytes, + uint256::size(), 257); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && @@ -593,14 +613,14 @@ struct HostFuncImpl_test : public beast::unit_test::Suite // hfs.cacheLedgerObj(dummyEscrow.key, 0); { WasmValVec params(3), result(1); - vrt.setBytes(0, dummyEscrow.key.data(), Bytes); + vrt.setBytes(0, dummyEscrow.key.data(), uint256::size()); auto* trap = ww(cacheLedgerObj_wrap, &import.at("cache_ledger_obj"), params, result, 0, - Bytes, + uint256::size(), 0); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && @@ -612,14 +632,14 @@ struct HostFuncImpl_test : public beast::unit_test::Suite // hfs.cacheLedgerObj(accountKeylet.key, 0); { WasmValVec params(3), result(1); - vrt.setBytes(0, accountKeylet.key.data(), Bytes); + vrt.setBytes(0, accountKeylet.key.data(), uint256::size()); auto* trap = ww(cacheLedgerObj_wrap, &import.at("cache_ledger_obj"), params, result, 0, - uint256::bytes, + uint256::size(), 0); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && @@ -631,14 +651,14 @@ struct HostFuncImpl_test : public beast::unit_test::Suite { // hfs.cacheLedgerObj(accountKeylet.key, i); WasmValVec params(3), result(1); - vrt.setBytes(0, accountKeylet.key.data(), uint256::bytes); + vrt.setBytes(0, accountKeylet.key.data(), uint256::size()); auto* trap = ww(cacheLedgerObj_wrap, &import.at("cache_ledger_obj"), params, result, 0, - uint256::bytes, + uint256::size(), i); if (!(BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && @@ -652,14 +672,14 @@ struct HostFuncImpl_test : public beast::unit_test::Suite // hfs.cacheLedgerObj(accountKeylet.key, 0); { WasmValVec params(3), result(1); - vrt.setBytes(0, accountKeylet.key.data(), uint256::bytes); + vrt.setBytes(0, accountKeylet.key.data(), uint256::size()); auto* trap = ww(cacheLedgerObj_wrap, &import.at("cache_ledger_obj"), params, result, 0, - uint256::bytes, + uint256::size(), 0); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && @@ -680,14 +700,14 @@ struct HostFuncImpl_test : public beast::unit_test::Suite { // hfs.cacheLedgerObj(accountKeylet.key, 0); WasmValVec params(3), result(1); - vrt.setBytes(0, accountKeylet.key.data(), uint256::bytes); + vrt.setBytes(0, accountKeylet.key.data(), uint256::size()); auto* trap = ww(cacheLedgerObj_wrap, &import.at("cache_ledger_obj"), params, result, 0, - uint256::bytes, + uint256::size(), 0); if (!(BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && @@ -701,14 +721,14 @@ struct HostFuncImpl_test : public beast::unit_test::Suite // hfs.cacheLedgerObj(accountKeylet.key, 0); { WasmValVec params(3), result(1); - vrt.setBytes(0, accountKeylet.key.data(), uint256::bytes); + vrt.setBytes(0, accountKeylet.key.data(), uint256::size()); auto* trap = ww(cacheLedgerObj_wrap, &import.at("cache_ledger_obj"), params, result, 0, - uint256::bytes, + uint256::size(), 0); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && @@ -737,7 +757,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite obj.setFieldU32(sfOfferSequence, env.seq(env.master)); obj.setFieldArray(sfMemos, STArray{}); STVector256 credIds; - credIds.push_back(credId); + credIds.pushBack(credId); obj.setFieldV256(sfCredentialIDs, credIds); }); ApplyContext ac = createApplyContext(env, ov, stx); @@ -760,10 +780,10 @@ struct HostFuncImpl_test : public beast::unit_test::Suite result, sfAccount.getCode(), 0, - AccountID::bytes); + AccountID::size()); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && - BEAST_EXPECT(result[0].of.i32 == AccountID::bytes); + BEAST_EXPECT(result[0].of.i32 == AccountID::size()); auto const accountBytes = vrt.getBytes(params, 1); BEAST_EXPECT(std::ranges::equal(accountBytes, env.master.id())); } @@ -778,10 +798,10 @@ struct HostFuncImpl_test : public beast::unit_test::Suite result, sfOwner.getCode(), 0, - AccountID::bytes); + AccountID::size()); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && - BEAST_EXPECT(result[0].of.i32 == AccountID::bytes); + BEAST_EXPECT(result[0].of.i32 == AccountID::size()); auto const ownerBytes = vrt.getBytes(params, 1); BEAST_EXPECT(std::ranges::equal(ownerBytes, env.master.id())); } @@ -876,7 +896,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite std::to_string(result[0].of.i32)); } - // hfs.getTxField(sfInvalid); + // hfs.getTxField(kSfInvalid); { WasmValVec params(3), result(1); auto* trap = @@ -884,7 +904,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite &import.at("get_tx_field"), params, result, - sfInvalid.getCode(), + kSfInvalid.getCode(), 0, 256); @@ -893,7 +913,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite result[0].of.i32 == static_cast(HostFunctionError::FieldNotFound)); } - // hfs.getTxField(sfGeneric); + // hfs.getTxField(kSfGeneric); { WasmValVec params(3), result(1); auto* trap = @@ -901,7 +921,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite &import.at("get_tx_field"), params, result, - sfGeneric.getCode(), + kSfGeneric.getCode(), 0, 256); @@ -1069,7 +1089,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite Env env{*this}; // Fund the account and create an escrow so the ledger object exists - env(escrow::create(env.master, env.master, XRP(100)), escrow::finish_time(env.now() + 1s)); + env(escrow::create(env.master, env.master, XRP(100)), escrow::kFinishTime(env.now() + 1s)); env.close(); OpenView ov{*env.current()}; @@ -1202,7 +1222,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite Env env{*this}; // Fund the account and create an escrow so the ledger object exists - env(escrow::create(env.master, env.master, XRP(100)), escrow::finish_time(env.now() + 1s)); + env(escrow::create(env.master, env.master, XRP(100)), escrow::kFinishTime(env.now() + 1s)); env.close(); OpenView ov{*env.current()}; @@ -1219,14 +1239,14 @@ struct HostFuncImpl_test : public beast::unit_test::Suite // hfs.cacheLedgerObj(accountKeylet.key, 1); { WasmValVec params(3), result(1); - vrt.setBytes(0, accountKeylet.key.data(), uint256::bytes); + vrt.setBytes(0, accountKeylet.key.data(), uint256::size()); auto* trap = ww(cacheLedgerObj_wrap, &import.at("cache_ledger_obj"), params, result, 0, - uint256::bytes, + uint256::size(), 1); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && @@ -1373,7 +1393,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite memos.push_back(memoObj); obj.setFieldArray(sfMemos, memos); STVector256 credIds; - credIds.push_back(credId); + credIds.pushBack(credId); obj.setFieldV256(sfCredentialIDs, credIds); }); @@ -1389,8 +1409,8 @@ struct HostFuncImpl_test : public beast::unit_test::Suite { // Locator for sfMemos[0].sfMemo.sfMemoData // Locator is a sequence of int32_t codes: - // [sfMemos.fieldCode, 0, sfMemoData.fieldCode] - std::vector const locatorVec = {sfMemos.fieldCode, 0, sfMemoData.fieldCode}; + // [sfMemos.getCode(), 0, sfMemoData.getCode()] + std::vector const locatorVec = {sfMemos.getCode(), 0, sfMemoData.getCode()}; vrt.setBytes(0, locatorVec.data(), locatorVec.size() * sizeof(int32_t)); WasmValVec params(4), result(1); @@ -1417,7 +1437,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite // hfs.getTxNestedField(locator); { // Locator for sfCredentialIDs[0] - std::vector locatorVec = {sfCredentialIDs.fieldCode, 0}; + std::vector locatorVec = {sfCredentialIDs.getCode(), 0}; vrt.setBytes( 0, reinterpret_cast(locatorVec.data()), @@ -1447,7 +1467,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite // hfs.getTxNestedField(locator); { // can use the nested locator for base fields too - std::vector locatorVec = {sfAccount.fieldCode}; + std::vector locatorVec = {sfAccount.getCode()}; vrt.setBytes(0, locatorVec.data(), locatorVec.size() * sizeof(int32_t)); WasmValVec params(4), result(1); @@ -1474,7 +1494,8 @@ struct HostFuncImpl_test : public beast::unit_test::Suite { // unaligned locator std::vector locatorVec(sizeof(int32_t) + 1); - memcpy(locatorVec.data() + 1, &sfAccount.fieldCode, sizeof(int32_t)); + auto const accountFieldCode = sfAccount.getCode(); + memcpy(locatorVec.data() + 1, &accountFieldCode, sizeof(int32_t)); vrt.setBytes(0, locatorVec.data() + 1, sizeof(int32_t)); WasmValVec params(4), result(1); @@ -1522,104 +1543,104 @@ struct HostFuncImpl_test : public beast::unit_test::Suite // hfs.getTxNestedField(locator); // Locator for non-existent base field expectError( - {sfSigners.fieldCode, // sfSigners does not exist + {sfSigners.getCode(), // sfSigners does not exist 0, - sfAccount.fieldCode}, + sfAccount.getCode()}, HostFunctionError::FieldNotFound); // hfs.getTxNestedField(locator); // Locator for non-existent index expectError( - {sfMemos.fieldCode, + {sfMemos.getCode(), 1, // index 1 does not exist - sfMemoData.fieldCode}, + sfMemoData.getCode()}, HostFunctionError::IndexOutOfBounds); // hfs.getTxNestedField(locator); // Locator for non-existent index expectError( - {sfCredentialIDs.fieldCode, 1}, // index 1 does not exist + {sfCredentialIDs.getCode(), 1}, // index 1 does not exist HostFunctionError::IndexOutOfBounds); // hfs.getTxNestedField(locator); // Locator for negative index (STArray) expectError( - {sfMemos.fieldCode, + {sfMemos.getCode(), -1, // negative index - sfMemoData.fieldCode}, + sfMemoData.getCode()}, HostFunctionError::IndexOutOfBounds); // hfs.getTxNestedField(locator); // Locator for negative index (STVector256) expectError( - {sfCredentialIDs.fieldCode, -1}, // negative index + {sfCredentialIDs.getCode(), -1}, // negative index HostFunctionError::IndexOutOfBounds); // hfs.getTxNestedField(locator); // Locator for non-existent nested field expectError( - {sfMemos.fieldCode, 0, sfURI.fieldCode}, // sfURI does not exist in the memo + {sfMemos.getCode(), 0, sfURI.getCode()}, // sfURI does not exist in the memo HostFunctionError::FieldNotFound); // hfs.getTxNestedField(locator); // Locator for non-existent base sfield expectError( - {field_code(20000, 20000), // nonexistent SField code + {fieldCode(20000, 20000), // nonexistent SField code 0, - sfAccount.fieldCode}, + sfAccount.getCode()}, HostFunctionError::InvalidField); // hfs.getTxNestedField(locator); // Locator for non-existent nested sfield expectError( - {sfMemos.fieldCode, // nonexistent SField code + {sfMemos.getCode(), // nonexistent SField code 0, - field_code(20000, 20000)}, + fieldCode(20000, 20000)}, HostFunctionError::InvalidField); // hfs.getTxNestedField(locator); - // Locator for negative base sfield code (-1 = sfInvalid, exists in map but not in tx) + // Locator for negative base sfield code (-1 = kSfInvalid, exists in map but not in tx) expectError( - {-1, // sfInvalid's field code + {-1, // kSfInvalid's field code 0, - sfAccount.fieldCode}, + sfAccount.getCode()}, HostFunctionError::FieldNotFound); // hfs.getTxNestedField(locator); - // Locator for zero base sfield code (0 = sfGeneric, exists in map but not in tx) + // Locator for zero base sfield code (0 = kSfGeneric, exists in map but not in tx) expectError( - {0, // sfGeneric's field code + {0, // kSfGeneric's field code 0, - sfAccount.fieldCode}, + sfAccount.getCode()}, HostFunctionError::FieldNotFound); // hfs.getTxNestedField(locator); // Locator for very negative base sfield code (not in knownCodeToField map) expectError( - {std::numeric_limits::min(), 0, sfAccount.fieldCode}, + {std::numeric_limits::min(), 0, sfAccount.getCode()}, HostFunctionError::InvalidField); // hfs.getTxNestedField(locator); // Locator for negative nested sfield code in STObject context // (sfMemos[0] is an STObject, then -1 is looked up as SField) expectError( - {sfMemos.fieldCode, 0, -1}, // -1 = sfInvalid, exists in map but not in memo object + {sfMemos.getCode(), 0, -1}, // -1 = kSfInvalid, exists in map but not in memo object HostFunctionError::FieldNotFound); // hfs.getTxNestedField(locator); // Locator for STArray - expectError({sfMemos.fieldCode}, HostFunctionError::NotLeafField); + expectError({sfMemos.getCode()}, HostFunctionError::NotLeafField); // hfs.getTxNestedField(locator); // Locator for STVector256 - expectError({sfCredentialIDs.fieldCode}, HostFunctionError::NotLeafField); + expectError({sfCredentialIDs.getCode()}, HostFunctionError::NotLeafField); // hfs.getTxNestedField(locator); // Locator for nesting into non-array/object field expectError( - {sfAccount.fieldCode, // sfAccount is not an array or object + {sfAccount.getCode(), // sfAccount is not an array or object 0, - sfAccount.fieldCode}, + sfAccount.getCode()}, HostFunctionError::LocatorMalformed); // hfs.getTxNestedField(locator); @@ -1629,7 +1650,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite // hfs.getTxNestedField(locator); // Locator for malformed locator (not multiple of 4) { - std::vector locatorVec = {sfMemos.fieldCode}; + std::vector locatorVec = {sfMemos.getCode()}; vrt.setBytes(0, locatorVec.data(), 3); WasmValVec params(4), result(1); @@ -1677,7 +1698,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite // hfs.getCurrentLedgerObjNestedField(baseLocatorSlice); // Locator for base field { - std::vector baseLocator = {sfSignerQuorum.fieldCode}; + std::vector baseLocator = {sfSignerQuorum.getCode()}; vrt.setBytes(0, baseLocator.data(), baseLocator.size() * sizeof(int32_t)); WasmValVec params(4), result(1); @@ -1724,17 +1745,17 @@ struct HostFuncImpl_test : public beast::unit_test::Suite // hfs.getCurrentLedgerObjNestedField(locator); // Locator for non-existent base field expectError( - {sfSigners.fieldCode, // sfSigners does not exist + {sfSigners.getCode(), // sfSigners does not exist 0, - sfAccount.fieldCode}, + sfAccount.getCode()}, HostFunctionError::FieldNotFound); // hfs.getCurrentLedgerObjNestedField(locator); // Locator for nesting into non-array/object field expectError( - {sfSignerQuorum.fieldCode, // sfSignerQuorum is not an array or object + {sfSignerQuorum.getCode(), // sfSignerQuorum is not an array or object 0, - sfAccount.fieldCode}, + sfAccount.getCode()}, HostFunctionError::LocatorMalformed); // hfs.getCurrentLedgerObjNestedField(emptyLocator); @@ -1759,7 +1780,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite // hfs.getCurrentLedgerObjNestedField(malformedLocator); // Locator for malformed locator (not multiple of 4) { - std::vector malformedLocatorVec = {sfMemos.fieldCode}; + std::vector malformedLocatorVec = {sfMemos.getCode()}; vrt.setBytes(0, malformedLocatorVec.data(), 3); WasmValVec params(4), result(1); @@ -1787,7 +1808,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite auto import2 = xrpl::createWasmImport(dummyHfs); dummyHfs.setRT(&vrt2); - std::vector const locatorVec = {sfAccount.fieldCode}; + std::vector const locatorVec = {sfAccount.getCode()}; vrt2.setBytes(0, locatorVec.data(), locatorVec.size() * sizeof(int32_t)); WasmValVec params(4), result(1); @@ -1836,14 +1857,14 @@ struct HostFuncImpl_test : public beast::unit_test::Suite // hfs.cacheLedgerObj(signerListKeylet.key, 1); { WasmValVec params(3), result(1); - vrt.setBytes(0, signerListKeylet.key.data(), uint256::bytes); + vrt.setBytes(0, signerListKeylet.key.data(), uint256::size()); auto* trap = ww(cacheLedgerObj_wrap, &import.at("cache_ledger_obj"), params, result, 0, - uint256::bytes, + uint256::size(), 1); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && BEAST_EXPECT(result[0].of.i32 == 1); @@ -1852,7 +1873,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite // Locator for sfSignerEntries[0].sfAccount { std::vector const locatorVec = { - sfSignerEntries.fieldCode, 0, sfAccount.fieldCode}; + sfSignerEntries.getCode(), 0, sfAccount.getCode()}; // hfs.getLedgerObjNestedField(1, locator); vrt.setBytes(0, locatorVec.data(), locatorVec.size() * sizeof(int32_t)); WasmValVec params(5), result(1); @@ -1879,7 +1900,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite // Locator for sfSignerEntries[1].sfAccount { std::vector const locatorVec = { - sfSignerEntries.fieldCode, 1, sfAccount.fieldCode}; + sfSignerEntries.getCode(), 1, sfAccount.getCode()}; // hfs.getLedgerObjNestedField(1, locator); vrt.setBytes(0, locatorVec.data(), locatorVec.size() * sizeof(int32_t)); WasmValVec params(5), result(1); @@ -1906,7 +1927,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite // Locator for sfSignerEntries[0].sfSignerWeight { std::vector const locatorVec = { - sfSignerEntries.fieldCode, 0, sfSignerWeight.fieldCode}; + sfSignerEntries.getCode(), 0, sfSignerWeight.getCode()}; // hfs.getLedgerObjNestedField(1, locator); vrt.setBytes(0, locatorVec.data(), locatorVec.size() * sizeof(int32_t)); WasmValVec params(5), result(1); @@ -1934,7 +1955,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite // Locator for base field sfSignerQuorum { - std::vector const locatorVec = {sfSignerQuorum.fieldCode}; + std::vector const locatorVec = {sfSignerQuorum.getCode()}; // hfs.getLedgerObjNestedField(1, locator); vrt.setBytes(0, locatorVec.data(), locatorVec.size() * sizeof(int32_t)); WasmValVec params(5), result(1); @@ -1984,49 +2005,49 @@ struct HostFuncImpl_test : public beast::unit_test::Suite // Error: base field not found expectError( - {sfSigners.fieldCode, // sfSigners does not exist + {sfSigners.getCode(), // sfSigners does not exist 0, - sfAccount.fieldCode}, + sfAccount.getCode()}, HostFunctionError::FieldNotFound); // Error: index out of bounds expectError( - {sfSignerEntries.fieldCode, + {sfSignerEntries.getCode(), 2, // index 2 does not exist - sfAccount.fieldCode}, + sfAccount.getCode()}, HostFunctionError::IndexOutOfBounds); // Error: nested field not found expectError( { - sfSignerEntries.fieldCode, + sfSignerEntries.getCode(), 0, - sfDestination.fieldCode // sfDestination does not exist + sfDestination.getCode() // sfDestination does not exist }, HostFunctionError::FieldNotFound); // Error: invalid field code expectError( - {field_code(99999, 99999), 0, sfAccount.fieldCode}, HostFunctionError::InvalidField); + {fieldCode(99999, 99999), 0, sfAccount.getCode()}, HostFunctionError::InvalidField); // Error: invalid nested field code expectError( - {sfSignerEntries.fieldCode, 0, field_code(99999, 99999)}, + {sfSignerEntries.getCode(), 0, fieldCode(99999, 99999)}, HostFunctionError::InvalidField); // Error: slot out of range - expectError({sfSignerQuorum.fieldCode}, HostFunctionError::SlotOutRange, 0); - expectError({sfSignerQuorum.fieldCode}, HostFunctionError::SlotOutRange, 257); + expectError({sfSignerQuorum.getCode()}, HostFunctionError::SlotOutRange, 0); + expectError({sfSignerQuorum.getCode()}, HostFunctionError::SlotOutRange, 257); // Error: empty slot - expectError({sfSignerQuorum.fieldCode}, HostFunctionError::EmptySlot, 2); + expectError({sfSignerQuorum.getCode()}, HostFunctionError::EmptySlot, 2); // Error: locator for STArray (not leaf field) - expectError({sfSignerEntries.fieldCode}, HostFunctionError::NotLeafField); + expectError({sfSignerEntries.getCode()}, HostFunctionError::NotLeafField); // Error: nesting into non-array/object field expectError( - {sfSignerQuorum.fieldCode, 0, sfAccount.fieldCode}, + {sfSignerQuorum.getCode(), 0, sfAccount.getCode()}, HostFunctionError::LocatorMalformed); // Error: empty locator @@ -2034,7 +2055,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite // Error: locator malformed (not multiple of 4) { - std::vector const locatorVec = {sfSignerEntries.fieldCode}; + std::vector const locatorVec = {sfSignerEntries.getCode()}; // hfs.getLedgerObjNestedField(1, locator); vrt.setBytes(0, locatorVec.data(), 3); WasmValVec params(5), result(1); @@ -2085,7 +2106,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite } obj.setFieldArray(sfMemos, memos); STVector256 credIds; - credIds.push_back(credId); + credIds.pushBack(credId); obj.setFieldV256(sfCredentialIDs, credIds); }); @@ -2106,7 +2127,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite &import.at("get_tx_array_len"), params, result, - sfMemos.fieldCode); + sfMemos.getCode()); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32); if (BEAST_EXPECT(result[0].of.i32 > 0)) @@ -2122,7 +2143,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite &import.at("get_tx_array_len"), params, result, - sfAccount.fieldCode); + sfAccount.getCode()); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32); BEAST_EXPECT(result[0].of.i32 == static_cast(HostFunctionError::NoArray)); @@ -2137,7 +2158,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite &import.at("get_tx_array_len"), params, result, - sfSigners.fieldCode); + sfSigners.getCode()); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32); BEAST_EXPECT( @@ -2153,7 +2174,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite &import.at("get_tx_array_len"), params, result, - sfCredentialIDs.fieldCode); + sfCredentialIDs.getCode()); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32); if (BEAST_EXPECT(result[0].of.i32 > 0)) @@ -2192,7 +2213,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite &import.at("get_current_ledger_obj_array_len"), params, result, - sfSignerEntries.fieldCode); + sfSignerEntries.getCode()); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32); if (BEAST_EXPECT(result[0].of.i32 > 0)) @@ -2207,7 +2228,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite &import.at("get_current_ledger_obj_array_len"), params, result, - sfMemos.fieldCode); + sfMemos.getCode()); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32); BEAST_EXPECT( @@ -2223,7 +2244,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite &import.at("get_current_ledger_obj_array_len"), params, result, - sfAccount.fieldCode); + sfAccount.getCode()); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32); BEAST_EXPECT(result[0].of.i32 == static_cast(HostFunctionError::NoArray)); @@ -2244,7 +2265,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite &import2.at("get_current_ledger_obj_array_len"), params, result, - sfMemos.fieldCode); + sfMemos.getCode()); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32); BEAST_EXPECT( @@ -2279,14 +2300,14 @@ struct HostFuncImpl_test : public beast::unit_test::Suite // hfs.cacheLedgerObj(signerListKeylet.key, 1); { WasmValVec params(3), result(1); - vrt.setBytes(0, signerListKeylet.key.data(), uint256::bytes); + vrt.setBytes(0, signerListKeylet.key.data(), uint256::size()); auto* trap = ww(cacheLedgerObj_wrap, &import.at("cache_ledger_obj"), params, result, 0, - uint256::bytes, + uint256::size(), 1); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && BEAST_EXPECT(result[0].of.i32 == 1); @@ -2301,7 +2322,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite params, result, 1, - sfSignerEntries.fieldCode); + sfSignerEntries.getCode()); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32); if (BEAST_EXPECT(result[0].of.i32 > 0)) @@ -2319,7 +2340,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite params, result, 0, - sfSignerEntries.fieldCode); + sfSignerEntries.getCode()); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32); BEAST_EXPECT(result[0].of.i32 == static_cast(HostFunctionError::SlotOutRange)); @@ -2335,7 +2356,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite params, result, 1, - sfAccount.fieldCode); + sfAccount.getCode()); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32); BEAST_EXPECT(result[0].of.i32 == static_cast(HostFunctionError::NoArray)); @@ -2351,7 +2372,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite params, result, 2, - sfSignerEntries.fieldCode); + sfSignerEntries.getCode()); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32); BEAST_EXPECT(result[0].of.i32 == static_cast(HostFunctionError::EmptySlot)); @@ -2367,7 +2388,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite params, result, 1, - sfMemos.fieldCode); + sfMemos.getCode()); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32); BEAST_EXPECT( @@ -2422,7 +2443,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite // Locator for sfMemos { - std::vector locatorVec = {sfMemos.fieldCode}; + std::vector locatorVec = {sfMemos.getCode()}; // hfs.getTxNestedArrayLen(locator); vrt.setBytes(0, locatorVec.data(), locatorVec.size() * sizeof(int32_t)); WasmValVec params(2), result(1); @@ -2439,10 +2460,10 @@ struct HostFuncImpl_test : public beast::unit_test::Suite } // Error: non-array field - expectError({sfAccount.fieldCode}, HostFunctionError::NoArray); + expectError({sfAccount.getCode()}, HostFunctionError::NoArray); // Error: missing field - expectError({sfSigners.fieldCode}, HostFunctionError::FieldNotFound); + expectError({sfSigners.getCode()}, HostFunctionError::FieldNotFound); } void @@ -2490,7 +2511,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite // Locator for sfSignerEntries { - std::vector locatorVec = {sfSignerEntries.fieldCode}; + std::vector locatorVec = {sfSignerEntries.getCode()}; // hfs.getCurrentLedgerObjNestedArrayLen(locator); vrt.setBytes(0, locatorVec.data(), locatorVec.size() * sizeof(int32_t)); WasmValVec params(2), result(1); @@ -2507,10 +2528,10 @@ struct HostFuncImpl_test : public beast::unit_test::Suite } // Error: non-array field - expectError({sfSignerQuorum.fieldCode}, HostFunctionError::NoArray); + expectError({sfSignerQuorum.getCode()}, HostFunctionError::NoArray); // Error: missing field - expectError({sfSigners.fieldCode}, HostFunctionError::FieldNotFound); + expectError({sfSigners.getCode()}, HostFunctionError::FieldNotFound); { auto const dummyEscrow = keylet::escrow(env.master, env.seq(env.master) + 5); @@ -2520,7 +2541,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite auto import2 = xrpl::createWasmImport(dummyHfs); dummyHfs.setRT(&vrt2); - std::vector locatorVec = {sfAccount.fieldCode}; + std::vector locatorVec = {sfAccount.getCode()}; // auto const result = dummyHfs.getCurrentLedgerObjNestedArrayLen(locator); vrt2.setBytes(0, locatorVec.data(), locatorVec.size() * sizeof(int32_t)); WasmValVec params(2), result(1); @@ -2565,21 +2586,21 @@ struct HostFuncImpl_test : public beast::unit_test::Suite // hfs.cacheLedgerObj(signerListKeylet.key, 1); { WasmValVec params(3), result(1); - vrt.setBytes(0, signerListKeylet.key.data(), uint256::bytes); + vrt.setBytes(0, signerListKeylet.key.data(), uint256::size()); auto* trap = ww(cacheLedgerObj_wrap, &import.at("cache_ledger_obj"), params, result, 0, - uint256::bytes, + uint256::size(), 1); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && BEAST_EXPECT(result[0].of.i32 == 1); } // Locator for sfSignerEntries - std::vector locatorVec = {sfSignerEntries.fieldCode}; + std::vector locatorVec = {sfSignerEntries.getCode()}; // hfs.getLedgerObjNestedArrayLen(1, locator); { vrt.setBytes(0, locatorVec.data(), locatorVec.size() * sizeof(int32_t)); @@ -2621,10 +2642,10 @@ struct HostFuncImpl_test : public beast::unit_test::Suite }; // Error: non-array field - expectError({sfSignerQuorum.fieldCode}, HostFunctionError::NoArray); + expectError({sfSignerQuorum.getCode()}, HostFunctionError::NoArray); // Error: missing field - expectError({sfSigners.fieldCode}, HostFunctionError::FieldNotFound); + expectError({sfSigners.getCode()}, HostFunctionError::FieldNotFound); // Slot out of range expectError(locatorVec, HostFunctionError::SlotOutRange, 0); @@ -2657,7 +2678,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite // Error: locator for non-STArray field expectError( - {sfSignerQuorum.fieldCode, 0, sfAccount.fieldCode}, + {sfSignerQuorum.getCode(), 0, sfAccount.getCode()}, HostFunctionError::LocatorMalformed); } @@ -2669,7 +2690,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite Env env{*this}; env(escrow::create(env.master, env.master, XRP(100)), - escrow::finish_time(env.now() + std::chrono::seconds(1))); + escrow::kFinishTime(env.now() + std::chrono::seconds(1))); env.close(); OpenView ov{*env.current()}; @@ -2729,7 +2750,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite hfs.setRT(&vrt); // Generate a keypair and sign a message - auto const kp = generateKeyPair(KeyType::secp256k1, randomSeed()); + auto const kp = generateKeyPair(KeyType::Secp256k1, randomSeed()); PublicKey const& pk = kp.first; SecretKey const& sk = kp.second; std::string const& message = "hello signature"; @@ -2919,10 +2940,10 @@ struct HostFuncImpl_test : public beast::unit_test::Suite 0, data.size(), 256, - uint256::bytes); + uint256::size()); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && - BEAST_EXPECT(result[0].of.i32 == uint256::bytes); + BEAST_EXPECT(result[0].of.i32 == uint256::size()); // Should match direct call to sha512Half auto expected = sha512Half(Slice(data.data(), data.size())); @@ -3085,7 +3106,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite "abcdefghijklmnopqrstuvwxyz01234567890qwertyuiop[]" "asdfghjkl;'zxcvbnm8237tr28weufwldebvfv8734t07p"; Slice const longCredType(longCredTypeStr.data(), longCredTypeStr.size()); - static_assert(longCredTypeStr.size() > maxCredentialTypeLength); + static_assert(longCredTypeStr.size() > kMaxCredentialTypeLength); auto* trap2 = ww(credentialKeylet_wrap, &imp.at("credential_keylet"), @@ -3295,7 +3316,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite result[0].of.i32 == static_cast(HostFunctionError::InvalidAccount)); } - Currency const usd = to_currency("USD"); + Currency const usd = toCurrency("USD"); { auto const expected = keylet::line(masterID, alice.id(), usd); WasmValVec params(8), result(1); @@ -3364,7 +3385,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite result, masterID, alice.id(), - to_currency(""), + toCurrency(""), 1024, 32); BEAST_EXPECT( @@ -3664,7 +3685,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite } { - auto const expected = keylet::ticket(masterID, 1u); + auto const expected = keylet::kTicket(masterID, 1u); WasmValVec params(6), result(1); auto* trap = ww(ticketKeylet_wrap, @@ -3742,7 +3763,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite // Mint NFT for alice uint256 const nftId = token::getNextID(env, alice, 0u, 0u); std::string const uri = "https://example.com/nft"; - env(token::mint(alice), token::uri(uri)); + env(token::mint(alice), token::Uri(uri)); env.close(); uint256 const nftId2 = token::getNextID(env, alice, 0u, 0u); env(token::mint(alice)); @@ -3761,8 +3782,8 @@ struct HostFuncImpl_test : public beast::unit_test::Suite // Should succeed for valid NFT { // hfs.getNFT(alice.id(), nftId); - vrt.setBytes(0, alice.id().data(), AccountID::bytes); - vrt.setBytes(256, nftId.data(), uint256::bytes); + vrt.setBytes(0, alice.id().data(), AccountID::size()); + vrt.setBytes(256, nftId.data(), uint256::size()); WasmValVec params(6), result(1); auto* trap = ww(getNFT_wrap, @@ -3770,9 +3791,9 @@ struct HostFuncImpl_test : public beast::unit_test::Suite params, result, 0, - AccountID::bytes, + AccountID::size(), 256, - uint256::bytes, + uint256::size(), 512, 256); @@ -3788,8 +3809,8 @@ struct HostFuncImpl_test : public beast::unit_test::Suite // Should fail for invalid account { // hfs.getNFT(xrpAccount(), nftId); - vrt.setBytes(0, xrpAccount().data(), AccountID::bytes); - vrt.setBytes(256, nftId.data(), uint256::bytes); + vrt.setBytes(0, xrpAccount().data(), AccountID::size()); + vrt.setBytes(256, nftId.data(), uint256::size()); WasmValVec params(6), result(1); auto* trap = ww(getNFT_wrap, @@ -3797,9 +3818,9 @@ struct HostFuncImpl_test : public beast::unit_test::Suite params, result, 0, - AccountID::bytes, + AccountID::size(), 256, - uint256::bytes, + uint256::size(), 512, 256); @@ -3811,8 +3832,8 @@ struct HostFuncImpl_test : public beast::unit_test::Suite { // hfs.getNFT(alice.id(), uint256()); uint256 zeroId; - vrt.setBytes(0, alice.id().data(), AccountID::bytes); - vrt.setBytes(256, zeroId.data(), uint256::bytes); + vrt.setBytes(0, alice.id().data(), AccountID::size()); + vrt.setBytes(256, zeroId.data(), uint256::size()); WasmValVec params(6), result(1); auto* trap = ww(getNFT_wrap, @@ -3820,9 +3841,9 @@ struct HostFuncImpl_test : public beast::unit_test::Suite params, result, 0, - AccountID::bytes, + AccountID::size(), 256, - uint256::bytes, + uint256::size(), 512, 256); @@ -3834,8 +3855,8 @@ struct HostFuncImpl_test : public beast::unit_test::Suite { auto const badId = token::getNextID(env, alice, 0u, 1u); // hfs.getNFT(alice.id(), badId); - vrt.setBytes(0, alice.id().data(), AccountID::bytes); - vrt.setBytes(256, badId.data(), uint256::bytes); + vrt.setBytes(0, alice.id().data(), AccountID::size()); + vrt.setBytes(256, badId.data(), uint256::size()); WasmValVec params(6), result(1); auto* trap = ww(getNFT_wrap, @@ -3843,9 +3864,9 @@ struct HostFuncImpl_test : public beast::unit_test::Suite params, result, 0, - AccountID::bytes, + AccountID::size(), 256, - uint256::bytes, + uint256::size(), 512, 256); @@ -3856,8 +3877,8 @@ struct HostFuncImpl_test : public beast::unit_test::Suite { // hfs.getNFT(alice.id(), nftId2); - vrt.setBytes(0, alice.id().data(), AccountID::bytes); - vrt.setBytes(256, nftId2.data(), uint256::bytes); + vrt.setBytes(0, alice.id().data(), AccountID::size()); + vrt.setBytes(256, nftId2.data(), uint256::size()); WasmValVec params(6), result(1); auto* trap = ww(getNFT_wrap, @@ -3865,9 +3886,9 @@ struct HostFuncImpl_test : public beast::unit_test::Suite params, result, 0, - AccountID::bytes, + AccountID::size(), 256, - uint256::bytes, + uint256::size(), 512, 256); @@ -3902,7 +3923,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite // Should succeed for valid NFT id { // hfs.getNFTIssuer(nftId); - vrt.setBytes(0, nftId.data(), uint256::bytes); + vrt.setBytes(0, nftId.data(), uint256::size()); WasmValVec params(4), result(1); auto* trap = ww(getNFTIssuer_wrap, @@ -3910,12 +3931,12 @@ struct HostFuncImpl_test : public beast::unit_test::Suite params, result, 0, - uint256::bytes, + uint256::size(), 256, - AccountID::bytes); + AccountID::size()); if (BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && - BEAST_EXPECT(result[0].of.i32 == AccountID::bytes)) + BEAST_EXPECT(result[0].of.i32 == AccountID::size())) { auto issuerBytes = vrt.getBytes(params, 2); BEAST_EXPECT(std::ranges::equal(issuerBytes, env.master.id())); @@ -3926,7 +3947,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite { // hfs.getNFTIssuer(uint256()); uint256 zeroId; - vrt.setBytes(0, zeroId.data(), uint256::bytes); + vrt.setBytes(0, zeroId.data(), uint256::size()); WasmValVec params(4), result(1); auto* trap = ww(getNFTIssuer_wrap, @@ -3934,9 +3955,9 @@ struct HostFuncImpl_test : public beast::unit_test::Suite params, result, 0, - uint256::bytes, + uint256::size(), 256, - AccountID::bytes); + AccountID::size()); if (BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32)) BEAST_EXPECT(result[0].of.i32 == HfErrorToInt(HostFunctionError::InvalidParams)); @@ -3967,7 +3988,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite hfs.setRT(&vrt); // hfs.getNFTTaxon(nftId); - vrt.setBytes(0, nftId.data(), uint256::bytes); + vrt.setBytes(0, nftId.data(), uint256::size()); WasmValVec params(4), result(1); auto* trap = ww(getNFTTaxon_wrap, @@ -3975,7 +3996,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite params, result, 0, - uint256::bytes, + uint256::size(), 256, sizeof(uint32_t)); @@ -3996,7 +4017,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite // Mint NFT with default flags uint256 const nftId = token::getNextID(env, env.master, 0u, tfTransferable); - env(token::mint(env.master, 0), txflags(tfTransferable)); + env(token::mint(env.master, 0), Txflags(tfTransferable)); env.close(); OpenView ov{*env.current()}; @@ -4011,10 +4032,10 @@ struct HostFuncImpl_test : public beast::unit_test::Suite { // hfs.getNFTFlags(nftId); - vrt.setBytes(0, nftId.data(), uint256::bytes); + vrt.setBytes(0, nftId.data(), uint256::size()); WasmValVec params(2), result(1); auto* trap = ww( - getNFTFlags_wrap, &import.at("get_nft_flags"), params, result, 0, uint256::bytes); + getNFTFlags_wrap, &import.at("get_nft_flags"), params, result, 0, uint256::size()); if (BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32)) BEAST_EXPECT(result[0].of.i32 == tfTransferable); @@ -4024,10 +4045,10 @@ struct HostFuncImpl_test : public beast::unit_test::Suite { // hfs.getNFTFlags(uint256()); uint256 zeroId; - vrt.setBytes(0, zeroId.data(), uint256::bytes); + vrt.setBytes(0, zeroId.data(), uint256::size()); WasmValVec params(2), result(1); auto* trap = ww( - getNFTFlags_wrap, &import.at("get_nft_flags"), params, result, 0, uint256::bytes); + getNFTFlags_wrap, &import.at("get_nft_flags"), params, result, 0, uint256::size()); if (BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32)) BEAST_EXPECT(result[0].of.i32 == 0); @@ -4044,7 +4065,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite uint16_t const transferFee = 250; uint256 const nftId = token::getNextID(env, env.master, 0u, tfTransferable, transferFee); - env(token::mint(env.master, 0), token::xferFee(transferFee), txflags(tfTransferable)); + env(token::mint(env.master, 0), token::XferFee(transferFee), Txflags(tfTransferable)); env.close(); OpenView ov{*env.current()}; @@ -4059,7 +4080,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite { // hfs.getNFTTransferFee(nftId); - vrt.setBytes(0, nftId.data(), uint256::bytes); + vrt.setBytes(0, nftId.data(), uint256::size()); WasmValVec params(2), result(1); auto* trap = ww(getNFTTransferFee_wrap, @@ -4067,7 +4088,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite params, result, 0, - uint256::bytes); + uint256::size()); if (BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32)) BEAST_EXPECT(result[0].of.i32 == transferFee); @@ -4077,7 +4098,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite { // hfs.getNFTTransferFee(uint256()); uint256 zeroId; - vrt.setBytes(0, zeroId.data(), uint256::bytes); + vrt.setBytes(0, zeroId.data(), uint256::size()); WasmValVec params(2), result(1); auto* trap = ww(getNFTTransferFee_wrap, @@ -4085,7 +4106,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite params, result, 0, - uint256::bytes); + uint256::size()); if (BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32)) BEAST_EXPECT(result[0].of.i32 == 0); @@ -4118,7 +4139,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite { // hfs.getNFTSerial(nftId); - vrt.setBytes(0, nftId.data(), uint256::bytes); + vrt.setBytes(0, nftId.data(), uint256::size()); WasmValVec params(4), result(1); auto* trap = ww(getNFTSerial_wrap, @@ -4126,7 +4147,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite params, result, 0, - uint256::bytes, + uint256::size(), 256, sizeof(uint32_t)); @@ -4141,7 +4162,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite { // hfs.getNFTSerial(uint256()); uint256 zeroId; - vrt.setBytes(0, zeroId.data(), uint256::bytes); + vrt.setBytes(0, zeroId.data(), uint256::size()); WasmValVec params(4), result(1); auto* trap = ww(getNFTSerial_wrap, @@ -4149,7 +4170,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite params, result, 0, - uint256::bytes, + uint256::size(), 256, sizeof(uint32_t)); @@ -4170,7 +4191,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite { Env env(*this); OpenView ov{*env.current()}; - test::StreamSink sink{beast::severities::kTrace}; + test::StreamSink sink{beast::Severity::Trace}; beast::Journal const jlog{sink}; ApplyContext ac = createApplyContext(env, ov, jlog); @@ -4242,7 +4263,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite // logs disabled (trace < error) Env env(*this); OpenView ov{*env.current()}; - test::StreamSink sink{beast::severities::kError}; + test::StreamSink sink{beast::Severity::Error}; beast::Journal const jlog{sink}; ApplyContext ac = createApplyContext(env, ov, jlog); @@ -4288,7 +4309,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite { Env env(*this); OpenView ov{*env.current()}; - test::StreamSink sink{beast::severities::kTrace}; + test::StreamSink sink{beast::Severity::Trace}; beast::Journal const jlog{sink}; ApplyContext ac = createApplyContext(env, ov, jlog); @@ -4321,7 +4342,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite // logs disabled Env env(*this); OpenView ov{*env.current()}; - test::StreamSink sink{beast::severities::kError}; + test::StreamSink sink{beast::Severity::Error}; beast::Journal const jlog{sink}; ApplyContext ac = createApplyContext(env, ov, jlog); @@ -4357,7 +4378,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite { Env env(*this); OpenView ov{*env.current()}; - test::StreamSink sink{beast::severities::kTrace}; + test::StreamSink sink{beast::Severity::Trace}; beast::Journal const jlog{sink}; ApplyContext ac = createApplyContext(env, ov, jlog); @@ -4398,7 +4419,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite // logs disabled Env env(*this); OpenView ov{*env.current()}; - test::StreamSink sink{beast::severities::kError}; + test::StreamSink sink{beast::Severity::Error}; beast::Journal const jlog{sink}; ApplyContext ac = createApplyContext(env, ov, jlog); @@ -4442,7 +4463,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite { Env env(*this); OpenView ov{*env.current()}; - test::StreamSink sink{beast::severities::kTrace}; + test::StreamSink sink{beast::Severity::Trace}; beast::Journal const jlog{sink}; ApplyContext ac = createApplyContext(env, ov, jlog); @@ -4535,7 +4556,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite // logs disabled Env env(*this); OpenView ov{*env.current()}; - test::StreamSink sink{beast::severities::kError}; + test::StreamSink sink{beast::Severity::Error}; beast::Journal const jlog{sink}; ApplyContext ac = createApplyContext(env, ov, jlog); @@ -4580,11 +4601,11 @@ struct HostFuncImpl_test : public beast::unit_test::Suite Bytes const floatIntMax = {0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00}; // 2^63-1 Bytes const floatUIntMax = {0x19, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x9A, 0x00, 0x00, 0x00, 0x01}; // 2^64-1 - Bytes const floatMaxExp = {0x0D, 0xE0, 0xB6, 0xB3, 0xA7, 0x64, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00}; // 1e(Number::maxExponent + normalExp) - Bytes const floatPreMaxExp = {0x0D, 0xE0, 0xB6, 0xB3, 0xA7, 0x64, 0x00, 0x00, 0x00, 0x00, 0x7F, 0xFF}; // 1e(Number::maxExponent + normalExp - 1) - Bytes const floatMinusMaxExp = {0xF2, 0x1F, 0x49, 0x4C, 0x58, 0x9C, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00}; // -1e(Number::maxExponent + normalExp) - Bytes const floatMinExp = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00}; // 1e(Number::minExponent - normalExp) - Bytes const floatMax = {0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x80, 0x00}; // Number::maxRep e(Number::maxExponent - normalExp) + Bytes const floatMaxExp = {0x0D, 0xE0, 0xB6, 0xB3, 0xA7, 0x64, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00}; // 1e(Number::kMaxExponent + normalExp) + Bytes const floatPreMaxExp = {0x0D, 0xE0, 0xB6, 0xB3, 0xA7, 0x64, 0x00, 0x00, 0x00, 0x00, 0x7F, 0xFF}; // 1e(Number::kMaxExponent + normalExp - 1) + Bytes const floatMinusMaxExp = {0xF2, 0x1F, 0x49, 0x4C, 0x58, 0x9C, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00}; // -1e(Number::kMaxExponent + normalExp) + Bytes const floatMinExp = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00}; // 1e(Number::kMinExponent - normalExp) + Bytes const floatMax = {0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x80, 0x00}; // Number::kMaxRep e(Number::kMaxExponent - normalExp) Bytes const floatMaxIOU = {0x0D, 0xE0, 0xB6, 0xB3, 0xA7, 0x63, 0xFF, 0x9C, 0x00, 0x00, 0x00, 0x4E}; // 9999999999999999e(96) Bytes const floatMinIOU = {0x0D, 0xE0, 0xB6, 0xB3, 0xA7, 0x64, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x9D}; // 1e(-96 - 3 + normalExp = -81) @@ -4615,7 +4636,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite } else { - n = Number(static_cast(m), e, Number::normalized()); + n = Number(static_cast(m), e, Number::Normalized{}); } STNumber(sfNumber, n).add(msg); @@ -4628,7 +4649,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite std::cout << std::dec << std::setfill(' ') << std::endl; } - static void + void printNumbersBin() { printFloats("int64.min", std::numeric_limits::min(), 0); @@ -4636,16 +4657,16 @@ struct HostFuncImpl_test : public beast::unit_test::Suite printFloats("int64.max", std::numeric_limits::max(), 0); printFloats("uint64.max", std::numeric_limits::max(), 0); - printFloats("Number 1 max exp", 1, Number::maxExponent + normalExp); - printFloats("Number (max exp - 1)", 1, Number::maxExponent + normalExp - 1); - printFloats("Number -1 max exp", -1, Number::maxExponent + normalExp); + printFloats("Number 1 max exp", 1, Number::kMaxExponent + normalExp); + printFloats("Number (max exp - 1)", 1, Number::kMaxExponent + normalExp - 1); + printFloats("Number -1 max exp", -1, Number::kMaxExponent + normalExp); - printFloats("Number.max", Number::maxRep, Number::maxExponent); - printFloats("Number min positive", 1, Number::minExponent + normalExp); + printFloats("Number.max", Number::kMaxRep, Number::kMaxExponent); + printFloats("Number min positive", 1, Number::kMinExponent + normalExp); printFloats( - "Number.min", std::numeric_limits::min(), Number::maxExponent - normalExp); - printFloats("STAmount.max", STAmount::cMaxValue, STAmount::cMaxOffset); - printFloats("STAmount min positive", STAmount::cMinValue, STAmount::cMinOffset); + "Number.min", std::numeric_limits::min(), Number::kMaxExponent - normalExp); + printFloats("STAmount.max", STAmount::kMaxValue, STAmount::kMaxOffset); + printFloats("STAmount min positive", STAmount::kMinValue, STAmount::kMinOffset); printFloats("one", 1, 0); printFloats("-one", -1, 0); @@ -4720,7 +4741,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite // logs disabled Env env(*this); OpenView ov{*env.current()}; - test::StreamSink sink{beast::severities::kError}; + test::StreamSink sink{beast::Severity::Error}; beast::Journal const jlog{sink}; ApplyContext ac = createApplyContext(env, ov, jlog); @@ -5029,7 +5050,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite } { - // hfs.floatFromMantExp(1, Number::maxExponent + normalExp + 1, 0); + // hfs.floatFromMantExp(1, Number::kMaxExponent + normalExp + 1, 0); WasmValVec params(5), result(1); auto* trap = ww(floatFromMantExp_wrap, @@ -5037,7 +5058,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite params, result, 1ll, - Number::maxExponent + normalExp + 1, + Number::kMaxExponent + normalExp + 1, 0, floatSize, 0); @@ -5049,7 +5070,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite } { - // hfs.floatFromMantExp(1, Number::minExponent + normalExp - 1, 0); + // hfs.floatFromMantExp(1, Number::kMinExponent + normalExp - 1, 0); WasmValVec params(5), result(1); auto* trap = ww(floatFromMantExp_wrap, @@ -5057,7 +5078,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite params, result, 1ll, - Number::minExponent + normalExp - 1, + Number::kMinExponent + normalExp - 1, 0, floatSize, 0); @@ -5069,7 +5090,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite } { - // hfs.floatFromMantExp(1, Number::maxExponent + normalExp, 0); + // hfs.floatFromMantExp(1, Number::kMaxExponent + normalExp, 0); WasmValVec params(5), result(1); auto* trap = ww(floatFromMantExp_wrap, @@ -5077,7 +5098,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite params, result, 1ll, - Number::maxExponent + normalExp, + Number::kMaxExponent + normalExp, 0, floatSize, 0); @@ -5089,7 +5110,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite } { - // hfs.floatFromMantExp(-1, Number::maxExponent + normalExp, 0); + // hfs.floatFromMantExp(-1, Number::kMaxExponent + normalExp, 0); WasmValVec params(5), result(1); auto* trap = ww(floatFromMantExp_wrap, @@ -5097,7 +5118,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite params, result, -1ll, - Number::maxExponent + normalExp, + Number::kMaxExponent + normalExp, 0, floatSize, 0); @@ -5109,7 +5130,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite } { - // hfs.floatFromMantExp(1, Number::maxExponent + normalExp - 1, 0); + // hfs.floatFromMantExp(1, Number::kMaxExponent + normalExp - 1, 0); WasmValVec params(5), result(1); auto* trap = ww(floatFromMantExp_wrap, @@ -5117,7 +5138,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite params, result, 1ll, - Number::maxExponent + normalExp - 1, + Number::kMaxExponent + normalExp - 1, 0, floatSize, 0); @@ -5129,15 +5150,15 @@ struct HostFuncImpl_test : public beast::unit_test::Suite } { - // hfs.floatFromMantExp(STAmount::cMaxValue, STAmount::cMaxOffset, 0); + // hfs.floatFromMantExp(STAmount::kMaxValue, STAmount::kMaxOffset, 0); WasmValVec params(5), result(1); auto* trap = ww(floatFromMantExp_wrap, &import.at("float_compare"), params, result, - static_cast(STAmount::cMaxValue), - STAmount::cMaxOffset, + static_cast(STAmount::kMaxValue), + STAmount::kMaxOffset, 0, floatSize, 0); @@ -5149,7 +5170,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite } { - // hfs.floatFromMantExp(1, Number::minExponent + normalExp, 0); + // hfs.floatFromMantExp(1, Number::kMinExponent + normalExp, 0); WasmValVec params(5), result(1); auto* trap = ww(floatFromMantExp_wrap, @@ -5157,7 +5178,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite params, result, 1ll, - Number::minExponent - normalExp, + Number::kMinExponent - normalExp, 0, floatSize, 0); @@ -5189,7 +5210,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite } { - // hfs.floatFromMantExp(1, Number::maxExponent + normalExp + 1, 0); + // hfs.floatFromMantExp(1, Number::kMaxExponent + normalExp + 1, 0); WasmValVec params(5), result(1); auto* trap = ww(floatFromMantExp_wrap, @@ -5197,7 +5218,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite params, result, 1ll, - Number::maxExponent + normalExp + 1, + Number::kMaxExponent + normalExp + 1, 0, floatSize, 0); @@ -5933,7 +5954,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite { // hfs.floatDivide(makeSlice(floatMax), makeSlice(*y), 0); auto const y = - hfs.floatFromMantExp(STAmount::cMaxValue, -normalExp - 1, 0); // 0.9999999... + hfs.floatFromMantExp(STAmount::kMaxValue, -normalExp - 1, 0); // 0.9999999... if (BEAST_EXPECT(y)) { WasmValVec params(7), result(1); @@ -6307,7 +6328,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite } { - // hfs.floatPower(makeSlice(floatMax), Number::maxExponent + 1, 0); + // hfs.floatPower(makeSlice(floatMax), Number::kMaxExponent + 1, 0); WasmValVec params(6), result(1); vrt.setBytes(0, floatMax.data(), floatMax.size()); auto* trap = @@ -6317,7 +6338,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite result, 0, floatSize, - Number::maxExponent + 1, + Number::kMaxExponent + 1, floatSize, floatSize, 0); @@ -6586,7 +6607,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite bool ex = false; try { - STAmount const amount(noIssue(), -1, Number::maxExponent + normalExp); + STAmount const amount(noIssue(), -1, Number::kMaxExponent + normalExp); [[maybe_unused]] Bytes const amountBytes = toBytes(amount); } catch (...) @@ -6601,7 +6622,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite { // hfs.floatFromSTAmount(amount, 0); STAmount const amount( - IOUAmount(STAmount::cMinValue, STAmount::cMinOffset), USD.issue()); + IOUAmount(STAmount::kMinValue, STAmount::kMinOffset), usd.issue()); Bytes amountBytes = toBytes(amount); vrt.setBytes(0, amountBytes.data(), amountBytes.size()); WasmValVec params(5), result(1); @@ -6625,7 +6646,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite { // hfs.floatFromSTAmount(amount, 0); STAmount const amount( - IOUAmount(STAmount::cMaxValue, STAmount::cMaxOffset), USD.issue()); + IOUAmount(STAmount::kMaxValue, STAmount::kMaxOffset), usd.issue()); Bytes amountBytes = toBytes(amount); vrt.setBytes(0, amountBytes.data(), amountBytes.size()); WasmValVec params(5), result(1); @@ -6713,7 +6734,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite { // hfs.floatFromSTNumber(num, 0); STNumber const num( - sfNumber, Number(std::numeric_limits::max(), 0, Number::normalized())); + sfNumber, Number(std::numeric_limits::max(), 0, Number::Normalized{})); Bytes numBytes = toBytes(num); vrt.setBytes(0, numBytes.data(), numBytes.size()); WasmValVec params(5), result(1); @@ -6736,7 +6757,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite { // hfs.floatFromSTNumber(num, 0); - STNumber const num(sfNumber, Number(-1, Number::maxExponent + normalExp)); + STNumber const num(sfNumber, Number(-1, Number::kMaxExponent + normalExp)); Bytes numBytes = toBytes(num); vrt.setBytes(0, numBytes.data(), numBytes.size()); WasmValVec params(5), result(1); @@ -7334,8 +7355,8 @@ struct HostFuncImpl_test : public beast::unit_test::Suite BEAST_EXPECT(result[0].of.i32 == floatSize); auto const mantissa = vrt.getInt64(params, 2); auto const exponent = vrt.getInt32(params, 4); - BEAST_EXPECT(mantissa == Number::maxRep) && - BEAST_EXPECT(exponent == Number::maxExponent); + BEAST_EXPECT(mantissa == Number::kMaxRep) && + BEAST_EXPECT(exponent == Number::kMaxExponent); // roundtrip auto const result2 = hfs.floatFromMantExp(mantissa, exponent, 0); diff --git a/src/test/app/TestHostFunctions.h b/src/test/app/TestHostFunctions.h index 524a3e3379..26d30dd53c 100644 --- a/src/test/app/TestHostFunctions.h +++ b/src/test/app/TestHostFunctions.h @@ -1,5 +1,6 @@ #include -#include +#include +#include #include #include @@ -8,6 +9,13 @@ #include #include +#include + +#include +#include +#include +#include + 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 getParentLedgerHash() const override { - return env_.current()->header().parentHash; + return env.current()->header().parentHash; } Expected @@ -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(&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 @@ -179,9 +189,9 @@ public: { int32_t const* l = reinterpret_cast(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(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(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 computeSha512HalfHash(Slice const& data) const override { - return env_.current()->header().parentHash; + return env.current()->header().parentHash; } Expected @@ -353,7 +363,7 @@ public: Expected getNFTIssuer(uint256 const& nftId) const override { - return Bytes(accountID_.begin(), accountID_.end()); + return Bytes(accountID.begin(), accountID.end()); } Expected @@ -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); } diff --git a/src/test/app/Wasm_test.cpp b/src/test/app/Wasm_test.cpp index 37a91c6778..c1879d1fe9 100644 --- a/src/test/app/Wasm_test.cpp +++ b/src/test/app/Wasm_test.cpp @@ -6,6 +6,7 @@ #include #include #include +#include // IWYU pragma: keep #include #include @@ -95,7 +96,7 @@ uleb128(IT&& it) return {val, count}; } -std::pair +static std::pair 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 +static std::optional 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 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);