From b664989cfb1fdfa9bdbada52dc88d4a9bd882e6c Mon Sep 17 00:00:00 2001 From: Mayukha Vadari Date: Tue, 19 May 2026 15:11:55 -0400 Subject: [PATCH] fix clang-tidy issues --- include/xrpl/tx/wasm/HostFunc.h | 52 +- include/xrpl/tx/wasm/HostFuncImpl.h | 20 +- include/xrpl/tx/wasm/ParamsHelper.h | 94 +- include/xrpl/tx/wasm/WasmVM.h | 28 +- include/xrpl/tx/wasm/WasmiVM.h | 44 +- src/libxrpl/tx/wasm/HostFuncImpl.cpp | 16 +- src/libxrpl/tx/wasm/HostFuncImplFloat.cpp | 139 +-- src/libxrpl/tx/wasm/HostFuncImplGetter.cpp | 69 +- src/libxrpl/tx/wasm/HostFuncImplKeylet.cpp | 73 +- .../tx/wasm/HostFuncImplLedgerHeader.cpp | 9 +- src/libxrpl/tx/wasm/HostFuncImplNFT.cpp | 22 +- src/libxrpl/tx/wasm/HostFuncImplTrace.cpp | 14 +- src/libxrpl/tx/wasm/HostFuncWrapper.cpp | 133 ++- src/libxrpl/tx/wasm/WasmVM.cpp | 15 +- src/libxrpl/tx/wasm/WasmiVM.cpp | 212 ++-- src/test/app/HostFuncImpl_test.cpp | 998 +++++++++--------- src/test/app/TestHostFunctions.h | 77 +- src/test/app/Wasm_test.cpp | 311 +++--- .../wasm_fixtures/fixture_functions_5k.cpp | 4 +- .../app/wasm_fixtures/fixture_locals_10k.cpp | 4 +- src/test/app/wasm_fixtures/fixtures.cpp | 126 +-- src/test/app/wasm_fixtures/fixtures.h | 128 +-- 22 files changed, 1397 insertions(+), 1191 deletions(-) diff --git a/include/xrpl/tx/wasm/HostFunc.h b/include/xrpl/tx/wasm/HostFunc.h index b385ab9af6..7c5eb18b0c 100644 --- a/include/xrpl/tx/wasm/HostFunc.h +++ b/include/xrpl/tx/wasm/HostFunc.h @@ -14,27 +14,27 @@ namespace xrpl { enum class HostFunctionError : int32_t { INTERNAL = -1, - FIELD_NOT_FOUND = -2, - BUFFER_TOO_SMALL = -3, - NO_ARRAY = -4, - NOT_LEAF_FIELD = -5, - LOCATOR_MALFORMED = -6, - SLOT_OUT_RANGE = -7, - SLOTS_FULL = -8, - EMPTY_SLOT = -9, - LEDGER_OBJ_NOT_FOUND = -10, + FieldNotFound = -2, + BufferTooSmall = -3, + NoArray = -4, + NotLeafField = -5, + LocatorMalformed = -6, + SlotOutRange = -7, + SlotsFull = -8, + EmptySlot = -9, + LedgerObjNotFound = -10, DECODING = -11, - DATA_FIELD_TOO_LARGE = -12, - POINTER_OUT_OF_BOUNDS = -13, - NO_MEM_EXPORTED = -14, - INVALID_PARAMS = -15, - INVALID_ACCOUNT = -16, - INVALID_FIELD = -17, - INDEX_OUT_OF_BOUNDS = -18, - FLOAT_INPUT_MALFORMED = -19, - FLOAT_COMPUTATION_ERROR = -20, - NO_RUNTIME = -21, - OUT_OF_GAS = -22, + DataFieldTooLarge = -12, + PointerOutOfBounds = -13, + NoMemExported = -14, + InvalidParams = -15, + InvalidAccount = -16, + InvalidField = -17, + IndexOutOfBounds = -18, + FloatInputMalformed = -19, + FloatComputationError = -20, + NoRuntime = -21, + OutOfGas = -22, }; using FloatPair = std::pair; @@ -97,9 +97,9 @@ floatPowerImpl(Slice const& x, int32_t n, int32_t mode); // Intended to work only through wasm runtime. Don't call them directly, except with unit tests struct HostFunctions { - beast::Journal j_; + beast::Journal j; - HostFunctions(beast::Journal j = beast::Journal{beast::Journal::getNullSink()}) : j_(j) + HostFunctions(beast::Journal j = beast::Journal{beast::Journal::getNullSink()}) : j(j) { } @@ -109,19 +109,19 @@ struct HostFunctions { } - virtual void* + [[nodiscard]] virtual void* getRT() const { return nullptr; } - beast::Journal + [[nodiscard]] beast::Journal getJournal() const { - return j_; + return j; } - virtual bool + [[nodiscard]] virtual bool checkSelf() const { return true; diff --git a/include/xrpl/tx/wasm/HostFuncImpl.h b/include/xrpl/tx/wasm/HostFuncImpl.h index 864416043a..4033a4aaf9 100644 --- a/include/xrpl/tx/wasm/HostFuncImpl.h +++ b/include/xrpl/tx/wasm/HostFuncImpl.h @@ -13,8 +13,8 @@ class WasmHostFunctionsImpl : public HostFunctions Keylet leKey_; mutable std::optional> currentLedgerObj_; - static int constexpr MAX_CACHE = 256; - std::array, MAX_CACHE> cache_; + static int constexpr maxCache = 256; + std::array, maxCache> cache_; std::optional data_; @@ -27,17 +27,17 @@ class WasmHostFunctionsImpl : public HostFunctions currentLedgerObj_ = ctx_.view().read(leKey_); if (*currentLedgerObj_) return *currentLedgerObj_; - return Unexpected(HostFunctionError::LEDGER_OBJ_NOT_FOUND); + return Unexpected(HostFunctionError::LedgerObjNotFound); } Expected normalizeCacheIndex(int32_t cacheIdx) const { --cacheIdx; - if (cacheIdx < 0 || cacheIdx >= MAX_CACHE) - return Unexpected(HostFunctionError::SLOT_OUT_RANGE); + if (cacheIdx < 0 || cacheIdx >= maxCache) + return Unexpected(HostFunctionError::SlotOutRange); if (!cache_[cacheIdx]) - return Unexpected(HostFunctionError::EMPTY_SLOT); + return Unexpected(HostFunctionError::EmptySlot); return cacheIdx; } @@ -52,7 +52,7 @@ class WasmHostFunctionsImpl : public HostFunctions return; auto j = getJournal().trace(); #endif - j << "WasmTrace[" << to_short_string(leKey_.key) << "]: " << msg << " " << dataFn(); + j << "WasmTrace[" << toShortString(leKey_.key) << "]: " << msg << " " << dataFn(); #ifdef DEBUG_OUTPUT j << std::endl; @@ -65,19 +65,19 @@ public: { } - virtual void + void setRT(void* rt) override { rt_ = rt; } - virtual void* + void* getRT() const override { return rt_; } - virtual bool + bool checkSelf() const override { return !currentLedgerObj_ && !data_ && diff --git a/include/xrpl/tx/wasm/ParamsHelper.h b/include/xrpl/tx/wasm/ParamsHelper.h index 4d2a1013b6..4a2e99d490 100644 --- a/include/xrpl/tx/wasm/ParamsHelper.h +++ b/include/xrpl/tx/wasm/ParamsHelper.h @@ -18,7 +18,7 @@ namespace xrpl { using Bytes = std::vector; using Hash = xrpl::uint256; -struct wmem +struct Wmem { std::uint8_t* p = nullptr; std::size_t s = 0; @@ -30,13 +30,13 @@ struct WasmResult T result; int64_t cost; }; -typedef WasmResult EscrowResult; +using EscrowResult = WasmResult; struct WasmRuntimeWrapper { virtual ~WasmRuntimeWrapper() = default; - virtual wmem + virtual Wmem getMem() = 0; virtual std::int64_t @@ -48,7 +48,7 @@ struct WasmRuntimeWrapper //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -enum WasmTypes { WT_I32, WT_I64 }; +enum WasmTypes { WtI32, WtI64 }; struct WasmImportFunc { @@ -61,8 +61,8 @@ struct WasmImportFunc uint32_t gas = 0; }; -typedef std::pair WasmUserData; -typedef std::unordered_map ImportVec; +using WasmUserData = std::pair; +using ImportVec = std::unordered_map; #define WASM_IMPORT_FUNC(v, f, ...) \ WasmImpFunc(v, #f, reinterpret_cast(&f##_wrap), ##__VA_ARGS__) @@ -71,43 +71,61 @@ typedef std::unordered_map ImportVec; #define WASM_IMPORT_FUNC2(v, f, n, ...) \ WasmImpFunc(v, n, reinterpret_cast(&f##_wrap), ##__VA_ARGS__) -template +template void WasmImpArgs(WasmImportFunc& e) { if constexpr (N < C) { - using at = typename boost::mpl::at_c::type; + using at = typename boost::mpl::at_c::type; if constexpr (std::is_pointer_v) - e.params.push_back(WT_I32); + { + e.params.push_back(WtI32); + } else if constexpr (std::is_same_v) - e.params.push_back(WT_I32); + { + e.params.push_back(WtI32); + } else if constexpr (std::is_same_v) - e.params.push_back(WT_I64); + { + e.params.push_back(WtI64); + } else + { static_assert(std::is_pointer_v, "Unsupported argument type"); + } - return WasmImpArgs(e); + return WasmImpArgs(e); } return; } -template +template void WasmImpRet(WasmImportFunc& e) { - if constexpr (std::is_pointer_v) - e.result = WT_I32; - else if constexpr (std::is_same_v) - e.result = WT_I32; - else if constexpr (std::is_same_v) - e.result = WT_I64; - else if constexpr (std::is_void_v) + if constexpr (std::is_pointer_v) + { + e.result = WtI32; + } + else if constexpr (std::is_same_v) + { + e.result = WtI32; + } + else if constexpr (std::is_same_v) + { + e.result = 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"); + } #endif } @@ -129,17 +147,17 @@ template void WasmImpFunc( ImportVec& v, - std::string_view imp_name, - void* f_wrap, + std::string_view impName, + void* fWrap, void* data = nullptr, uint32_t gas = 0) { WasmImportFunc e; - e.name = imp_name; - e.wrap = f_wrap; + e.name = impName; + e.wrap = fWrap; e.gas = gas; WasmImpFuncHelper(e); - v.emplace(imp_name, std::make_pair(data, std::move(e))); + v.emplace(impName, std::make_pair(data, std::move(e))); } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -148,7 +166,7 @@ struct WasmParam { // We are not supporting float/double - WasmTypes type = WT_I32; + WasmTypes type = WtI32; union { std::int32_t i32; @@ -160,7 +178,7 @@ template inline void wasmParamsHlp(std::vector& v, std::int32_t p, Types&&... args) { - v.push_back({.type = WT_I32, .of = {.i32 = p}}); + v.push_back({.type = WtI32, .of = {.i32 = p}}); wasmParamsHlp(v, std::forward(args)...); } @@ -168,7 +186,7 @@ template inline void wasmParamsHlp(std::vector& v, std::int64_t p, Types&&... args) { - v.push_back({.type = WT_I64, .of = {.i64 = p}}); + v.push_back({.type = WtI64, .of = {.i64 = p}}); wasmParamsHlp(v, std::forward(args)...); } @@ -188,29 +206,29 @@ wasmParams(Types&&... args) return v; } -template -inline constexpr T +template +constexpr T adjustWasmEndianessHlp(T x) { - static_assert(std::is_integral::value, "Only integral types"); - if constexpr (size > 1) + static_assert(std::is_integral_v, "Only integral types"); + if constexpr (Size > 1) { - using U = std::make_unsigned::type; + using U = std::make_unsigned_t; U u = static_cast(x); - U const low = (u & 0xFF) << ((size - 1) << 3); - u = adjustWasmEndianessHlp(u >> 8); + U const low = (u & 0xFF) << ((Size - 1) << 3); + u = adjustWasmEndianessHlp(u >> 8); return static_cast(low | u); } return x; } -template -inline constexpr T +template +constexpr T adjustWasmEndianess(T x) { // LCOV_EXCL_START - static_assert(std::is_integral::value, "Only integral types"); + static_assert(std::is_integral_v, "Only integral types"); if constexpr (std::endian::native == std::endian::big) { return adjustWasmEndianessHlp(x); diff --git a/include/xrpl/tx/wasm/WasmVM.h b/include/xrpl/tx/wasm/WasmVM.h index e001ee6112..1e371a92b4 100644 --- a/include/xrpl/tx/wasm/WasmVM.h +++ b/include/xrpl/tx/wasm/WasmVM.h @@ -6,19 +6,19 @@ namespace xrpl { -std::string_view inline constexpr W_ENV = "env"; -std::string_view inline constexpr W_HOST_LIB = "host_lib"; -std::string_view inline constexpr W_MEM = "memory"; -std::string_view inline constexpr W_STORE = "store"; -std::string_view inline constexpr W_LOAD = "load"; -std::string_view inline constexpr W_SIZE = "size"; -std::string_view inline constexpr W_ALLOC = "allocate"; -std::string_view inline constexpr W_DEALLOC = "deallocate"; -std::string_view inline constexpr W_PROC_EXIT = "proc_exit"; +std::string_view inline constexpr wEnv = "env"; +std::string_view inline constexpr wHostLib = "host_lib"; +std::string_view inline constexpr wMem = "memory"; +std::string_view inline constexpr wStore = "store"; +std::string_view inline constexpr wLoad = "load"; +std::string_view inline constexpr wSize = "size"; +std::string_view inline constexpr wAlloc = "allocate"; +std::string_view inline constexpr wDealloc = "deallocate"; +std::string_view inline constexpr wProcExit = "proc_exit"; -std::string_view inline constexpr ESCROW_FUNCTION_NAME = "finish"; +std::string_view inline constexpr escrowFunctionName = "finish"; -uint32_t inline constexpr MAX_PAGES = 128; // 8MB = 64KB*128 +uint32_t inline constexpr maxPages = 128; // 8MB = 64KB*128 class WasmiEngine; @@ -61,7 +61,7 @@ public: void* newTrap(std::string const& txt = std::string()); - beast::Journal + [[nodiscard]] beast::Journal getJournal() const; }; @@ -75,14 +75,14 @@ runEscrowWasm( Bytes const& wasmCode, HostFunctions& hfs, int64_t gasLimit, - std::string_view funcName = ESCROW_FUNCTION_NAME, + std::string_view funcName = escrowFunctionName, std::vector const& params = {}); NotTEC preflightEscrowWasm( Bytes const& wasmCode, HostFunctions& hfs, - std::string_view funcName = ESCROW_FUNCTION_NAME, + std::string_view funcName = escrowFunctionName, std::vector const& params = {}); } // namespace xrpl diff --git a/include/xrpl/tx/wasm/WasmiVM.h b/include/xrpl/tx/wasm/WasmiVM.h index ce94b2ee29..ef3c33b164 100644 --- a/include/xrpl/tx/wasm/WasmiVM.h +++ b/include/xrpl/tx/wasm/WasmiVM.h @@ -67,7 +67,7 @@ public: return &vec_; } - T const* + [[nodiscard]] T const* get() const { return &vec_; @@ -89,13 +89,13 @@ public: return vec_.data[i]; } - size_t + [[nodiscard]] size_t size() const { return vec_.size; } - bool + [[nodiscard]] bool empty() const { return vec_.size == 0u; @@ -121,7 +121,7 @@ struct WasmiResult WasmValVec r; bool f{false}; // failure flag - WasmiResult(unsigned N = 0) : r(N) + WasmiResult(unsigned n = 0) : r(n) { } @@ -141,11 +141,11 @@ using FuncInfo = std::pair; struct InstanceWrapper { - wasm_store_t* store_ = nullptr; - WasmExternVec exports_; - mutable int memIdx_ = -1; - InstancePtr instance_; - beast::Journal j_ = beast::Journal(beast::Journal::getNullSink()); + wasm_store_t* store = nullptr; + WasmExternVec exports; + mutable int memIdx = -1; + InstancePtr instance; + beast::Journal j = beast::Journal(beast::Journal::getNullSink()); private: static InstancePtr @@ -176,7 +176,7 @@ public: FuncInfo getFunc(std::string_view funcName, WasmExporttypeVec const& exportTypes) const; - wmem + Wmem getMem() const; std::int64_t @@ -188,10 +188,10 @@ public: struct ModuleWrapper { - ModulePtr module_; - InstanceWrapper instanceWrap_; - WasmExporttypeVec exportTypes_; - beast::Journal j_ = beast::Journal(beast::Journal::getNullSink()); + ModulePtr module; + InstanceWrapper instanceWrap; + WasmExporttypeVec exportTypes; + beast::Journal j = beast::Journal(beast::Journal::getNullSink()); private: static ModulePtr @@ -218,7 +218,7 @@ public: wasm_functype_t* getFuncType(std::string_view funcName) const; - wmem + Wmem getMem() const; InstanceWrapper& @@ -269,21 +269,21 @@ public: ImportVec const& imports, beast::Journal j); - std::int64_t + [[nodiscard]] std::int64_t getGas() const; // Host functions helper functionality wasm_trap_t* newTrap(std::string const& msg); - beast::Journal + [[nodiscard]] beast::Journal getJournal() const; private: - InstanceWrapper& + [[nodiscard]] InstanceWrapper& getRT(int m = 0, int i = 0) const; - wmem + [[nodiscard]] Wmem getMem() const; Expected, TER> @@ -318,7 +318,7 @@ private: int32_t makeModule(Bytes const& wasmCode, WasmExternVec const& imports = {}); - FuncInfo + [[nodiscard]] FuncInfo getFunc(std::string_view funcName) const; static std::vector @@ -328,9 +328,9 @@ private: compareParamTypes(wasm_valtype_vec_t const* ftp, std::vector const& p); static void - add_param(std::vector& in, int32_t p); + addParam(std::vector& in, int32_t p); static void - add_param(std::vector& in, int64_t p); + addParam(std::vector& in, int64_t p); template inline WasmiResult diff --git a/src/libxrpl/tx/wasm/HostFuncImpl.cpp b/src/libxrpl/tx/wasm/HostFuncImpl.cpp index 7f6dd4255c..dbcd9d8e78 100644 --- a/src/libxrpl/tx/wasm/HostFuncImpl.cpp +++ b/src/libxrpl/tx/wasm/HostFuncImpl.cpp @@ -1,7 +1,15 @@ -#include -#include #include +#include +#include +#include +#include +#include +#include +#include + +#include + namespace xrpl { // ========================================================= @@ -13,7 +21,7 @@ WasmHostFunctionsImpl::updateData(Slice const& data) { if (data.size() > maxWasmDataLength) { - return Unexpected(HostFunctionError::DATA_FIELD_TOO_LARGE); + return Unexpected(HostFunctionError::DataFieldTooLarge); } data_ = Bytes(data.begin(), data.end()); return data_->size(); @@ -30,7 +38,7 @@ WasmHostFunctionsImpl::checkSignature( Slice const& pubkey) const { if (!publicKeyType(pubkey)) - return Unexpected(HostFunctionError::INVALID_PARAMS); + return Unexpected(HostFunctionError::InvalidParams); PublicKey const pk(pubkey); return verify(pk, message, signature); diff --git a/src/libxrpl/tx/wasm/HostFuncImplFloat.cpp b/src/libxrpl/tx/wasm/HostFuncImplFloat.cpp index 50e972a2da..f85a17a2d2 100644 --- a/src/libxrpl/tx/wasm/HostFuncImplFloat.cpp +++ b/src/libxrpl/tx/wasm/HostFuncImplFloat.cpp @@ -1,8 +1,19 @@ +#include +#include +#include #include -#include #include -#include +#include +#include #include +#include + +#include + +#include +#include +#include +#include #ifdef _DEBUG // #define DEBUG_OUTPUT 1 @@ -48,7 +59,7 @@ public: { try { - Number n; + Number const n; if constexpr (std::is_signed_v) { n = Number(static_cast(mantissa), exponent); @@ -102,25 +113,25 @@ public: struct FloatState { - Number::rounding_mode oldMode_; - bool good_ = false; + Number::RoundingMode oldMode; + bool good = false; - FloatState(int32_t mode) : oldMode_(Number::getround()) + FloatState(int32_t mode) : oldMode(Number::getround()) { - if (mode < Number::rounding_mode::to_nearest || mode > Number::rounding_mode::upward) + if (mode < Number::RoundingMode::ToNearest || mode > Number::RoundingMode::Upward) return; - Number::setround(static_cast(mode)); - good_ = true; + Number::setround(static_cast(mode)); + good = true; } ~FloatState() { - Number::setround(oldMode_); + Number::setround(oldMode); } operator bool() const { - return good_; + return good; } }; @@ -130,7 +141,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::rounding_mode::to_nearest); + detail::FloatState const rm(Number::RoundingMode::to_nearest); detail::WasmNumber const num(data); if (!num) { @@ -150,18 +161,18 @@ floatFromIntImpl(int64_t x, int32_t mode) { detail::FloatState const rm(mode); if (!rm) - return Unexpected(HostFunctionError::FLOAT_INPUT_MALFORMED); + return Unexpected(HostFunctionError::FloatInputMalformed); detail::WasmNumber const num(x); if (!num) - return Unexpected(HostFunctionError::FLOAT_INPUT_MALFORMED); // LCOV_EXCL_LINE + return Unexpected(HostFunctionError::FloatInputMalformed); // LCOV_EXCL_LINE auto const r = num.toBytes(); return r; } // LCOV_EXCL_START catch (...) { - return Unexpected(HostFunctionError::FLOAT_COMPUTATION_ERROR); + return Unexpected(HostFunctionError::FloatComputationError); } // LCOV_EXCL_STOP } @@ -173,18 +184,18 @@ floatFromUintImpl(uint64_t x, int32_t mode) { detail::FloatState const rm(mode); if (!rm) - return Unexpected(HostFunctionError::FLOAT_INPUT_MALFORMED); + return Unexpected(HostFunctionError::FloatInputMalformed); detail::WasmNumber const num(x); if (!num) - return Unexpected(HostFunctionError::FLOAT_INPUT_MALFORMED); // LCOV_EXCL_LINE + return Unexpected(HostFunctionError::FloatInputMalformed); // LCOV_EXCL_LINE auto const r = num.toBytes(); return r; } // LCOV_EXCL_START catch (...) { - return Unexpected(HostFunctionError::FLOAT_COMPUTATION_ERROR); + return Unexpected(HostFunctionError::FloatComputationError); } // LCOV_EXCL_STOP } @@ -196,18 +207,18 @@ floatFromSTAmountImpl(STAmount const& x, int32_t mode) { detail::FloatState const rm(mode); if (!rm) - return Unexpected(HostFunctionError::FLOAT_INPUT_MALFORMED); + return Unexpected(HostFunctionError::FloatInputMalformed); detail::WasmNumber const num(static_cast(x)); if (!num) - return Unexpected(HostFunctionError::FLOAT_INPUT_MALFORMED); // LCOV_EXCL_LINE + return Unexpected(HostFunctionError::FloatInputMalformed); // LCOV_EXCL_LINE auto const r = num.toBytes(); return r; } // LCOV_EXCL_START catch (...) { - return Unexpected(HostFunctionError::FLOAT_COMPUTATION_ERROR); + return Unexpected(HostFunctionError::FloatComputationError); } // LCOV_EXCL_STOP } @@ -219,18 +230,18 @@ floatFromSTNumberImpl(STNumber const& x, int32_t mode) { detail::FloatState const rm(mode); if (!rm) - return Unexpected(HostFunctionError::FLOAT_INPUT_MALFORMED); + return Unexpected(HostFunctionError::FloatInputMalformed); detail::WasmNumber const num(x.value()); if (!num) - return Unexpected(HostFunctionError::FLOAT_INPUT_MALFORMED); // LCOV_EXCL_LINE + return Unexpected(HostFunctionError::FloatInputMalformed); // LCOV_EXCL_LINE auto const r = num.toBytes(); return r; } // LCOV_EXCL_START catch (...) { - return Unexpected(HostFunctionError::FLOAT_COMPUTATION_ERROR); + return Unexpected(HostFunctionError::FloatComputationError); } // LCOV_EXCL_STOP } @@ -242,18 +253,18 @@ floatToIntImpl(Slice const& x, int32_t mode) { detail::FloatState const rm(mode); if (!rm) - return Unexpected(HostFunctionError::FLOAT_INPUT_MALFORMED); + return Unexpected(HostFunctionError::FloatInputMalformed); detail::WasmNumber const num(x); if (!num) - return Unexpected(HostFunctionError::FLOAT_INPUT_MALFORMED); // LCOV_EXCL_LINE + return Unexpected(HostFunctionError::FloatInputMalformed); // LCOV_EXCL_LINE int64_t const r(num); return r; } // LCOV_EXCL_START catch (...) { - return Unexpected(HostFunctionError::FLOAT_COMPUTATION_ERROR); + return Unexpected(HostFunctionError::FloatComputationError); } // LCOV_EXCL_STOP } @@ -263,20 +274,20 @@ floatToMantExpImpl(Slice const& x) { try { - detail::FloatState const rm(Number::rounding_mode::to_nearest); + detail::FloatState const rm(Number::RoundingMode::to_nearest); if (!rm) - return Unexpected(HostFunctionError::FLOAT_INPUT_MALFORMED); + return Unexpected(HostFunctionError::FloatInputMalformed); detail::WasmNumber const num(x); if (!num) - return Unexpected(HostFunctionError::FLOAT_INPUT_MALFORMED); // LCOV_EXCL_LINE + return Unexpected(HostFunctionError::FloatInputMalformed); // LCOV_EXCL_LINE return FloatPair(num.mantissa(), num.exponent()); } // LCOV_EXCL_START catch (...) { - return Unexpected(HostFunctionError::FLOAT_COMPUTATION_ERROR); + return Unexpected(HostFunctionError::FloatComputationError); } // LCOV_EXCL_STOP } @@ -288,15 +299,15 @@ floatFromMantExpImpl(int64_t mantissa, int32_t exponent, int32_t mode) { detail::FloatState const rm(mode); if (!rm) - return Unexpected(HostFunctionError::FLOAT_INPUT_MALFORMED); + return Unexpected(HostFunctionError::FloatInputMalformed); detail::WasmNumber const num(mantissa, exponent); if (!num) - return Unexpected(HostFunctionError::FLOAT_INPUT_MALFORMED); + return Unexpected(HostFunctionError::FloatInputMalformed); return num.toBytes(); } catch (...) { - return Unexpected(HostFunctionError::FLOAT_COMPUTATION_ERROR); + return Unexpected(HostFunctionError::FloatComputationError); } } @@ -306,14 +317,14 @@ 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::rounding_mode::to_nearest); + detail::FloatState const rm(Number::RoundingMode::to_nearest); detail::WasmNumber const xx(x); if (!xx) - return Unexpected(HostFunctionError::FLOAT_INPUT_MALFORMED); + return Unexpected(HostFunctionError::FloatInputMalformed); detail::WasmNumber const yy(y); if (!yy) - return Unexpected(HostFunctionError::FLOAT_INPUT_MALFORMED); + return Unexpected(HostFunctionError::FloatInputMalformed); if (xx < yy) return 2; if (xx == yy) @@ -323,7 +334,7 @@ floatCompareImpl(Slice const& x, Slice const& y) // LCOV_EXCL_START catch (...) { - return Unexpected(HostFunctionError::FLOAT_COMPUTATION_ERROR); + return Unexpected(HostFunctionError::FloatComputationError); } // LCOV_EXCL_STOP } @@ -335,14 +346,14 @@ floatAddImpl(Slice const& x, Slice const& y, int32_t mode) { detail::FloatState const rm(mode); if (!rm) - return Unexpected(HostFunctionError::FLOAT_INPUT_MALFORMED); + return Unexpected(HostFunctionError::FloatInputMalformed); detail::WasmNumber const xx(x); if (!xx) - return Unexpected(HostFunctionError::FLOAT_INPUT_MALFORMED); + return Unexpected(HostFunctionError::FloatInputMalformed); detail::WasmNumber const yy(y); if (!yy) - return Unexpected(HostFunctionError::FLOAT_INPUT_MALFORMED); + return Unexpected(HostFunctionError::FloatInputMalformed); detail::WasmNumber const res = xx + yy; return res.toBytes(); @@ -350,7 +361,7 @@ floatAddImpl(Slice const& x, Slice const& y, int32_t mode) // LCOV_EXCL_START catch (...) { - return Unexpected(HostFunctionError::FLOAT_COMPUTATION_ERROR); + return Unexpected(HostFunctionError::FloatComputationError); } // LCOV_EXCL_STOP } @@ -362,13 +373,13 @@ floatSubtractImpl(Slice const& x, Slice const& y, int32_t mode) { detail::FloatState const rm(mode); if (!rm) - return Unexpected(HostFunctionError::FLOAT_INPUT_MALFORMED); + return Unexpected(HostFunctionError::FloatInputMalformed); detail::WasmNumber const xx(x); if (!xx) - return Unexpected(HostFunctionError::FLOAT_INPUT_MALFORMED); + return Unexpected(HostFunctionError::FloatInputMalformed); detail::WasmNumber const yy(y); if (!yy) - return Unexpected(HostFunctionError::FLOAT_INPUT_MALFORMED); + return Unexpected(HostFunctionError::FloatInputMalformed); detail::WasmNumber const res = xx - yy; return res.toBytes(); @@ -376,7 +387,7 @@ floatSubtractImpl(Slice const& x, Slice const& y, int32_t mode) // LCOV_EXCL_START catch (...) { - return Unexpected(HostFunctionError::FLOAT_COMPUTATION_ERROR); + return Unexpected(HostFunctionError::FloatComputationError); } // LCOV_EXCL_STOP } @@ -388,13 +399,13 @@ floatMultiplyImpl(Slice const& x, Slice const& y, int32_t mode) { detail::FloatState const rm(mode); if (!rm) - return Unexpected(HostFunctionError::FLOAT_INPUT_MALFORMED); + return Unexpected(HostFunctionError::FloatInputMalformed); detail::WasmNumber const xx(x); if (!xx) - return Unexpected(HostFunctionError::FLOAT_INPUT_MALFORMED); + return Unexpected(HostFunctionError::FloatInputMalformed); detail::WasmNumber const yy(y); if (!yy) - return Unexpected(HostFunctionError::FLOAT_INPUT_MALFORMED); + return Unexpected(HostFunctionError::FloatInputMalformed); detail::WasmNumber const res = xx * yy; return res.toBytes(); @@ -402,7 +413,7 @@ floatMultiplyImpl(Slice const& x, Slice const& y, int32_t mode) // LCOV_EXCL_START catch (...) { - return Unexpected(HostFunctionError::FLOAT_COMPUTATION_ERROR); + return Unexpected(HostFunctionError::FloatComputationError); } // LCOV_EXCL_STOP } @@ -414,20 +425,20 @@ floatDivideImpl(Slice const& x, Slice const& y, int32_t mode) { detail::FloatState const rm(mode); if (!rm) - return Unexpected(HostFunctionError::FLOAT_INPUT_MALFORMED); + return Unexpected(HostFunctionError::FloatInputMalformed); detail::WasmNumber const xx(x); if (!xx) - return Unexpected(HostFunctionError::FLOAT_INPUT_MALFORMED); + return Unexpected(HostFunctionError::FloatInputMalformed); detail::WasmNumber const yy(y); if (!yy) - return Unexpected(HostFunctionError::FLOAT_INPUT_MALFORMED); + return Unexpected(HostFunctionError::FloatInputMalformed); detail::WasmNumber const res = xx / yy; return res.toBytes(); } catch (...) { - return Unexpected(HostFunctionError::FLOAT_COMPUTATION_ERROR); + return Unexpected(HostFunctionError::FloatComputationError); } } @@ -437,15 +448,15 @@ floatRootImpl(Slice const& x, int32_t n, int32_t mode) try { if (n < 1) - return Unexpected(HostFunctionError::FLOAT_INPUT_MALFORMED); + return Unexpected(HostFunctionError::FloatInputMalformed); detail::FloatState const rm(mode); if (!rm) - return Unexpected(HostFunctionError::FLOAT_INPUT_MALFORMED); + return Unexpected(HostFunctionError::FloatInputMalformed); detail::WasmNumber const xx(x); if (!xx) - return Unexpected(HostFunctionError::FLOAT_INPUT_MALFORMED); + return Unexpected(HostFunctionError::FloatInputMalformed); detail::WasmNumber const res(root(xx, n)); @@ -454,7 +465,7 @@ floatRootImpl(Slice const& x, int32_t n, int32_t mode) // LCOV_EXCL_START catch (...) { - return Unexpected(HostFunctionError::FLOAT_COMPUTATION_ERROR); + return Unexpected(HostFunctionError::FloatComputationError); } // LCOV_EXCL_STOP } @@ -464,18 +475,18 @@ floatPowerImpl(Slice const& x, int32_t n, int32_t mode) { try { - if ((n < 0) || (n > Number::maxExponent)) - return Unexpected(HostFunctionError::FLOAT_INPUT_MALFORMED); + if ((n < 0) || (n > Number::kMaxExponent)) + return Unexpected(HostFunctionError::FloatInputMalformed); detail::FloatState const rm(mode); if (!rm) - return Unexpected(HostFunctionError::FLOAT_INPUT_MALFORMED); + return Unexpected(HostFunctionError::FloatInputMalformed); detail::WasmNumber const xx(x); if (!xx) - return Unexpected(HostFunctionError::FLOAT_INPUT_MALFORMED); + return Unexpected(HostFunctionError::FloatInputMalformed); if (xx == Number() && (n == 0)) - return Unexpected(HostFunctionError::INVALID_PARAMS); + return Unexpected(HostFunctionError::InvalidParams); detail::WasmNumber const res(power(xx, n, 1)); @@ -484,7 +495,7 @@ floatPowerImpl(Slice const& x, int32_t n, int32_t mode) // LCOV_EXCL_START catch (...) { - return Unexpected(HostFunctionError::FLOAT_COMPUTATION_ERROR); + return Unexpected(HostFunctionError::FloatComputationError); } // LCOV_EXCL_STOP } diff --git a/src/libxrpl/tx/wasm/HostFuncImplGetter.cpp b/src/libxrpl/tx/wasm/HostFuncImplGetter.cpp index 0053af3400..a9aefd885e 100644 --- a/src/libxrpl/tx/wasm/HostFuncImplGetter.cpp +++ b/src/libxrpl/tx/wasm/HostFuncImplGetter.cpp @@ -1,10 +1,27 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include #include -#include +#include +#include +#include #include +#include + +#include +#include +#include +#include namespace xrpl { -typedef std::variant FieldValue; +using FieldValue = std::variant; template Bytes @@ -23,7 +40,7 @@ static Expected getAnyFieldData(STBase const* obj) { if (obj == nullptr) - return Unexpected(HostFunctionError::FIELD_NOT_FOUND); + return Unexpected(HostFunctionError::FieldNotFound); auto const stype = obj->getSType(); switch (stype) @@ -31,13 +48,13 @@ getAnyFieldData(STBase const* obj) // LCOV_EXCL_START case STI_UNKNOWN: case STI_NOTPRESENT: - return Unexpected(HostFunctionError::FIELD_NOT_FOUND); + return Unexpected(HostFunctionError::FieldNotFound); // LCOV_EXCL_STOP case STI_OBJECT: case STI_ARRAY: case STI_VECTOR256: - return Unexpected(HostFunctionError::NOT_LEAF_FIELD); + return Unexpected(HostFunctionError::NotLeafField); case STI_ACCOUNT: { auto const* account(static_cast(obj)); // NOLINT @@ -125,7 +142,7 @@ static Expected locateField(STObject const& obj, Slice const& locator) { if (locator.empty() || ((locator.size() & 3) != 0u)) // must be multiple of 4 - return Unexpected(HostFunctionError::LOCATOR_MALFORMED); + return Unexpected(HostFunctionError::LocatorMalformed); static_assert(maxWasmParamLength % sizeof(int32_t) == 0); int32_t locBuf[maxWasmParamLength / sizeof(int32_t)]; @@ -151,12 +168,12 @@ locateField(STObject const& obj, Slice const& locator) int32_t const sfieldCode = adjustWasmEndianess(locPtr[0]); auto const it = knownSFields.find(sfieldCode); if (it == knownSFields.end()) - return Unexpected(HostFunctionError::INVALID_FIELD); + return Unexpected(HostFunctionError::InvalidField); auto const& fname(*it->second); field = obj.peekAtPField(fname); if (noField(field)) - return Unexpected(HostFunctionError::FIELD_NOT_FOUND); + return Unexpected(HostFunctionError::FieldNotFound); } for (int i = 1; i < locSize; ++i) @@ -167,7 +184,7 @@ locateField(STObject const& obj, Slice const& locator) { auto const* arr = static_cast(field); // NOLINT if (sfieldCode < 0 || std::cmp_greater_equal(sfieldCode, arr->size())) - return Unexpected(HostFunctionError::INDEX_OUT_OF_BOUNDS); + return Unexpected(HostFunctionError::IndexOutOfBounds); field = &(arr->operator[](sfieldCode)); } else if (STI_OBJECT == field->getSType()) @@ -176,7 +193,7 @@ locateField(STObject const& obj, Slice const& locator) auto const it = knownSFields.find(sfieldCode); if (it == knownSFields.end()) - return Unexpected(HostFunctionError::INVALID_FIELD); + return Unexpected(HostFunctionError::InvalidField); auto const& fname(*it->second); field = o->peekAtPField(fname); @@ -185,16 +202,16 @@ locateField(STObject const& obj, Slice const& locator) { auto const* v = static_cast(field); // NOLINT if (sfieldCode < 0 || std::cmp_greater_equal(sfieldCode, v->size())) - return Unexpected(HostFunctionError::INDEX_OUT_OF_BOUNDS); + return Unexpected(HostFunctionError::IndexOutOfBounds); return FieldValue(&(v->operator[](sfieldCode))); } else // simple field must be the last one { - return Unexpected(HostFunctionError::LOCATOR_MALFORMED); + return Unexpected(HostFunctionError::LocatorMalformed); } if (noField(field)) - return Unexpected(HostFunctionError::FIELD_NOT_FOUND); + return Unexpected(HostFunctionError::FieldNotFound); } return FieldValue(field); @@ -212,19 +229,19 @@ getArrayLen(FieldValue const& variantField) } // uint256 is not an array so that variant should still return NO_ARRAY - return Unexpected(HostFunctionError::NO_ARRAY); // LCOV_EXCL_LINE + return Unexpected(HostFunctionError::NoArray); // LCOV_EXCL_LINE } Expected WasmHostFunctionsImpl::cacheLedgerObj(uint256 const& objId, int32_t cacheIdx) { auto const& keylet = keylet::unchecked(objId); - if (cacheIdx < 0 || cacheIdx > MAX_CACHE) - return Unexpected(HostFunctionError::SLOT_OUT_RANGE); + if (cacheIdx < 0 || cacheIdx > maxCache) + return Unexpected(HostFunctionError::SlotOutRange); if (cacheIdx == 0) { - for (cacheIdx = 0; cacheIdx < MAX_CACHE; ++cacheIdx) + for (cacheIdx = 0; cacheIdx < maxCache; ++cacheIdx) { if (!cache_[cacheIdx]) break; @@ -235,12 +252,12 @@ WasmHostFunctionsImpl::cacheLedgerObj(uint256 const& objId, int32_t cacheIdx) cacheIdx--; // convert to 0-based index } - if (cacheIdx >= MAX_CACHE) - return Unexpected(HostFunctionError::SLOTS_FULL); + if (cacheIdx >= maxCache) + return Unexpected(HostFunctionError::SlotsFull); cache_[cacheIdx] = ctx_.view().read(keylet); if (!cache_[cacheIdx]) - return Unexpected(HostFunctionError::LEDGER_OBJ_NOT_FOUND); + return Unexpected(HostFunctionError::LedgerObjNotFound); return cacheIdx + 1; // return 1-based index } @@ -316,11 +333,11 @@ Expected WasmHostFunctionsImpl::getTxArrayLen(SField const& fname) const { if (fname.fieldType != STI_ARRAY && fname.fieldType != STI_VECTOR256) - return Unexpected(HostFunctionError::NO_ARRAY); + return Unexpected(HostFunctionError::NoArray); auto const* field = ctx_.tx.peekAtPField(fname); if (noField(field)) - return Unexpected(HostFunctionError::FIELD_NOT_FOUND); + return Unexpected(HostFunctionError::FieldNotFound); return getArrayLen(field); } @@ -329,7 +346,7 @@ Expected WasmHostFunctionsImpl::getCurrentLedgerObjArrayLen(SField const& fname) const { if (fname.fieldType != STI_ARRAY && fname.fieldType != STI_VECTOR256) - return Unexpected(HostFunctionError::NO_ARRAY); + return Unexpected(HostFunctionError::NoArray); auto const sle = getCurrentLedgerObj(); if (!sle.has_value()) @@ -337,7 +354,7 @@ WasmHostFunctionsImpl::getCurrentLedgerObjArrayLen(SField const& fname) const auto const* field = sle.value()->peekAtPField(fname); if (noField(field)) - return Unexpected(HostFunctionError::FIELD_NOT_FOUND); + return Unexpected(HostFunctionError::FieldNotFound); return getArrayLen(field); } @@ -346,7 +363,7 @@ Expected WasmHostFunctionsImpl::getLedgerObjArrayLen(int32_t cacheIdx, SField const& fname) const { if (fname.fieldType != STI_ARRAY && fname.fieldType != STI_VECTOR256) - return Unexpected(HostFunctionError::NO_ARRAY); + return Unexpected(HostFunctionError::NoArray); auto const normalizedIdx = normalizeCacheIndex(cacheIdx); if (!normalizedIdx.has_value()) @@ -354,7 +371,7 @@ WasmHostFunctionsImpl::getLedgerObjArrayLen(int32_t cacheIdx, SField const& fnam auto const* field = cache_[normalizedIdx.value()]->peekAtPField(fname); if (noField(field)) - return Unexpected(HostFunctionError::FIELD_NOT_FOUND); + return Unexpected(HostFunctionError::FieldNotFound); return getArrayLen(field); } diff --git a/src/libxrpl/tx/wasm/HostFuncImplKeylet.cpp b/src/libxrpl/tx/wasm/HostFuncImplKeylet.cpp index 8953790464..e9d54d89fa 100644 --- a/src/libxrpl/tx/wasm/HostFuncImplKeylet.cpp +++ b/src/libxrpl/tx/wasm/HostFuncImplKeylet.cpp @@ -1,6 +1,17 @@ -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include +#include + +#include namespace xrpl { @@ -8,7 +19,7 @@ Expected WasmHostFunctionsImpl::accountKeylet(AccountID const& account) const { if (!account) - return Unexpected(HostFunctionError::INVALID_ACCOUNT); + return Unexpected(HostFunctionError::InvalidAccount); auto const keylet = keylet::account(account); return Bytes{keylet.key.begin(), keylet.key.end()}; } @@ -17,11 +28,11 @@ Expected WasmHostFunctionsImpl::ammKeylet(Asset const& issue1, Asset const& issue2) const { if (issue1 == issue2) - return Unexpected(HostFunctionError::INVALID_PARAMS); + return Unexpected(HostFunctionError::InvalidParams); // note: this should be removed with the MPT DEX amendment if (issue1.holds() || issue2.holds()) - return Unexpected(HostFunctionError::INVALID_PARAMS); + return Unexpected(HostFunctionError::InvalidParams); auto const keylet = keylet::amm(issue1, issue2); return Bytes{keylet.key.begin(), keylet.key.end()}; @@ -31,7 +42,7 @@ Expected WasmHostFunctionsImpl::checkKeylet(AccountID const& account, std::uint32_t seq) const { if (!account) - return Unexpected(HostFunctionError::INVALID_ACCOUNT); + return Unexpected(HostFunctionError::InvalidAccount); auto const keylet = keylet::check(account, seq); return Bytes{keylet.key.begin(), keylet.key.end()}; } @@ -43,10 +54,10 @@ WasmHostFunctionsImpl::credentialKeylet( Slice const& credentialType) const { if (!subject || !issuer) - return Unexpected(HostFunctionError::INVALID_ACCOUNT); + return Unexpected(HostFunctionError::InvalidAccount); - if (credentialType.empty() || credentialType.size() > maxCredentialTypeLength) - return Unexpected(HostFunctionError::INVALID_PARAMS); + if (credentialType.empty() || credentialType.size() > kMaxCredentialTypeLength) + return Unexpected(HostFunctionError::InvalidParams); auto const keylet = keylet::credential(subject, issuer, credentialType); @@ -57,7 +68,7 @@ Expected WasmHostFunctionsImpl::didKeylet(AccountID const& account) const { if (!account) - return Unexpected(HostFunctionError::INVALID_ACCOUNT); + return Unexpected(HostFunctionError::InvalidAccount); auto const keylet = keylet::did(account); return Bytes{keylet.key.begin(), keylet.key.end()}; } @@ -66,9 +77,9 @@ Expected WasmHostFunctionsImpl::delegateKeylet(AccountID const& account, AccountID const& authorize) const { if (!account || !authorize) - return Unexpected(HostFunctionError::INVALID_ACCOUNT); + return Unexpected(HostFunctionError::InvalidAccount); if (account == authorize) - return Unexpected(HostFunctionError::INVALID_PARAMS); + return Unexpected(HostFunctionError::InvalidParams); auto const keylet = keylet::delegate(account, authorize); return Bytes{keylet.key.begin(), keylet.key.end()}; } @@ -78,9 +89,9 @@ WasmHostFunctionsImpl::depositPreauthKeylet(AccountID const& account, AccountID const { if (!account || !authorize) - return Unexpected(HostFunctionError::INVALID_ACCOUNT); + return Unexpected(HostFunctionError::InvalidAccount); if (account == authorize) - return Unexpected(HostFunctionError::INVALID_PARAMS); + return Unexpected(HostFunctionError::InvalidParams); auto const keylet = keylet::depositPreauth(account, authorize); return Bytes{keylet.key.begin(), keylet.key.end()}; } @@ -89,7 +100,7 @@ Expected WasmHostFunctionsImpl::escrowKeylet(AccountID const& account, std::uint32_t seq) const { if (!account) - return Unexpected(HostFunctionError::INVALID_ACCOUNT); + return Unexpected(HostFunctionError::InvalidAccount); auto const keylet = keylet::escrow(account, seq); return Bytes{keylet.key.begin(), keylet.key.end()}; } @@ -101,11 +112,11 @@ WasmHostFunctionsImpl::lineKeylet( Currency const& currency) const { if (!account1 || !account2) - return Unexpected(HostFunctionError::INVALID_ACCOUNT); + return Unexpected(HostFunctionError::InvalidAccount); if (account1 == account2) - return Unexpected(HostFunctionError::INVALID_PARAMS); + return Unexpected(HostFunctionError::InvalidParams); if (currency.isZero()) - return Unexpected(HostFunctionError::INVALID_PARAMS); + return Unexpected(HostFunctionError::InvalidParams); auto const keylet = keylet::line(account1, account2, currency); return Bytes{keylet.key.begin(), keylet.key.end()}; @@ -115,7 +126,7 @@ Expected WasmHostFunctionsImpl::mptIssuanceKeylet(AccountID const& issuer, std::uint32_t seq) const { if (!issuer) - return Unexpected(HostFunctionError::INVALID_ACCOUNT); + return Unexpected(HostFunctionError::InvalidAccount); auto const keylet = keylet::mptIssuance(seq, issuer); return Bytes{keylet.key.begin(), keylet.key.end()}; @@ -125,9 +136,9 @@ Expected WasmHostFunctionsImpl::mptokenKeylet(MPTID const& mptid, AccountID const& holder) const { if (!mptid) - return Unexpected(HostFunctionError::INVALID_PARAMS); + return Unexpected(HostFunctionError::InvalidParams); if (!holder) - return Unexpected(HostFunctionError::INVALID_ACCOUNT); + return Unexpected(HostFunctionError::InvalidAccount); auto const keylet = keylet::mptoken(mptid, holder); return Bytes{keylet.key.begin(), keylet.key.end()}; @@ -137,7 +148,7 @@ Expected WasmHostFunctionsImpl::nftOfferKeylet(AccountID const& account, std::uint32_t seq) const { if (!account) - return Unexpected(HostFunctionError::INVALID_ACCOUNT); + return Unexpected(HostFunctionError::InvalidAccount); auto const keylet = keylet::nftoffer(account, seq); return Bytes{keylet.key.begin(), keylet.key.end()}; } @@ -146,7 +157,7 @@ Expected WasmHostFunctionsImpl::offerKeylet(AccountID const& account, std::uint32_t seq) const { if (!account) - return Unexpected(HostFunctionError::INVALID_ACCOUNT); + return Unexpected(HostFunctionError::InvalidAccount); auto const keylet = keylet::offer(account, seq); return Bytes{keylet.key.begin(), keylet.key.end()}; } @@ -155,7 +166,7 @@ Expected WasmHostFunctionsImpl::oracleKeylet(AccountID const& account, std::uint32_t documentId) const { if (!account) - return Unexpected(HostFunctionError::INVALID_ACCOUNT); + return Unexpected(HostFunctionError::InvalidAccount); auto const keylet = keylet::oracle(account, documentId); return Bytes{keylet.key.begin(), keylet.key.end()}; } @@ -167,9 +178,9 @@ WasmHostFunctionsImpl::paychanKeylet( std::uint32_t seq) const { if (!account || !destination) - return Unexpected(HostFunctionError::INVALID_ACCOUNT); + return Unexpected(HostFunctionError::InvalidAccount); if (account == destination) - return Unexpected(HostFunctionError::INVALID_PARAMS); + return Unexpected(HostFunctionError::InvalidParams); auto const keylet = keylet::payChan(account, destination, seq); return Bytes{keylet.key.begin(), keylet.key.end()}; } @@ -178,7 +189,7 @@ Expected WasmHostFunctionsImpl::permissionedDomainKeylet(AccountID const& account, std::uint32_t seq) const { if (!account) - return Unexpected(HostFunctionError::INVALID_ACCOUNT); + return Unexpected(HostFunctionError::InvalidAccount); auto const keylet = keylet::permissionedDomain(account, seq); return Bytes{keylet.key.begin(), keylet.key.end()}; } @@ -187,7 +198,7 @@ Expected WasmHostFunctionsImpl::signersKeylet(AccountID const& account) const { if (!account) - return Unexpected(HostFunctionError::INVALID_ACCOUNT); + return Unexpected(HostFunctionError::InvalidAccount); auto const keylet = keylet::signers(account); return Bytes{keylet.key.begin(), keylet.key.end()}; } @@ -196,8 +207,8 @@ Expected WasmHostFunctionsImpl::ticketKeylet(AccountID const& account, std::uint32_t seq) const { if (!account) - return Unexpected(HostFunctionError::INVALID_ACCOUNT); - auto const keylet = keylet::ticket(account, seq); + return Unexpected(HostFunctionError::InvalidAccount); + auto const keylet = jss::ticket(account, seq); return Bytes{keylet.key.begin(), keylet.key.end()}; } @@ -205,7 +216,7 @@ Expected WasmHostFunctionsImpl::vaultKeylet(AccountID const& account, std::uint32_t seq) const { if (!account) - return Unexpected(HostFunctionError::INVALID_ACCOUNT); + return Unexpected(HostFunctionError::InvalidAccount); auto const keylet = keylet::vault(account, seq); return Bytes{keylet.key.begin(), keylet.key.end()}; } diff --git a/src/libxrpl/tx/wasm/HostFuncImplLedgerHeader.cpp b/src/libxrpl/tx/wasm/HostFuncImplLedgerHeader.cpp index c8e38f6805..91092ba8d0 100644 --- a/src/libxrpl/tx/wasm/HostFuncImplLedgerHeader.cpp +++ b/src/libxrpl/tx/wasm/HostFuncImplLedgerHeader.cpp @@ -1,6 +1,13 @@ +#include +#include #include -#include +#include #include +#include + +#include +#include +#include namespace xrpl { diff --git a/src/libxrpl/tx/wasm/HostFuncImplNFT.cpp b/src/libxrpl/tx/wasm/HostFuncImplNFT.cpp index 510d6a886f..b312ab7098 100644 --- a/src/libxrpl/tx/wasm/HostFuncImplNFT.cpp +++ b/src/libxrpl/tx/wasm/HostFuncImplNFT.cpp @@ -1,7 +1,15 @@ +#include +#include +#include #include -#include -#include +#include +#include +#include +#include #include +#include + +#include namespace xrpl { @@ -13,18 +21,18 @@ Expected WasmHostFunctionsImpl::getNFT(AccountID const& account, uint256 const& nftId) const { if (!account) - return Unexpected(HostFunctionError::INVALID_ACCOUNT); + return Unexpected(HostFunctionError::InvalidAccount); if (!nftId) - return Unexpected(HostFunctionError::INVALID_PARAMS); + return Unexpected(HostFunctionError::InvalidParams); auto obj = nft::findToken(ctx_.view(), account, nftId); if (!obj) - return Unexpected(HostFunctionError::LEDGER_OBJ_NOT_FOUND); + return Unexpected(HostFunctionError::LedgerObjNotFound); auto objUri = obj->at(~sfURI); if (!objUri) - return Unexpected(HostFunctionError::FIELD_NOT_FOUND); + return Unexpected(HostFunctionError::FieldNotFound); Slice const s = objUri->value(); return Bytes(s.begin(), s.end()); @@ -35,7 +43,7 @@ WasmHostFunctionsImpl::getNFTIssuer(uint256 const& nftId) const { auto const issuer = nft::getIssuer(nftId); if (!issuer) - return Unexpected(HostFunctionError::INVALID_PARAMS); + return Unexpected(HostFunctionError::InvalidParams); return Bytes{issuer.begin(), issuer.end()}; } diff --git a/src/libxrpl/tx/wasm/HostFuncImplTrace.cpp b/src/libxrpl/tx/wasm/HostFuncImplTrace.cpp index 33f9dc8e2b..0f9ee2e64c 100644 --- a/src/libxrpl/tx/wasm/HostFuncImplTrace.cpp +++ b/src/libxrpl/tx/wasm/HostFuncImplTrace.cpp @@ -1,7 +1,17 @@ -#include -#include +#include +#include +#include +#include +#include #include +#include + +#include +#include +#include +#include + #ifdef _DEBUG // #define DEBUG_OUTPUT 1 #endif diff --git a/src/libxrpl/tx/wasm/HostFuncWrapper.cpp b/src/libxrpl/tx/wasm/HostFuncWrapper.cpp index a882204f51..b303fcc47e 100644 --- a/src/libxrpl/tx/wasm/HostFuncWrapper.cpp +++ b/src/libxrpl/tx/wasm/HostFuncWrapper.cpp @@ -1,15 +1,37 @@ +#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 +#include +#include +#include +#include +#include +#include +#include #include namespace xrpl { @@ -28,21 +50,21 @@ setData( return 0; // LCOV_EXCL_LINE if (dst < 0 || dstSize < 0 || (src == nullptr) || srcSize < 0) - return HfErrorToInt(HostFunctionError::INVALID_PARAMS); + return HfErrorToInt(HostFunctionError::InvalidParams); if (srcSize > maxWasmDataLength) - return HfErrorToInt(HostFunctionError::DATA_FIELD_TOO_LARGE); + return HfErrorToInt(HostFunctionError::DataFieldTooLarge); - auto const memory = (runtime != nullptr) ? runtime->getMem() : wmem(); + auto const memory = (runtime != nullptr) ? runtime->getMem() : Wmem(); // LCOV_EXCL_START if (memory.s == 0u) - return HfErrorToInt(HostFunctionError::NO_MEM_EXPORTED); + return HfErrorToInt(HostFunctionError::NoMemExported); // LCOV_EXCL_STOP if ((int64_t)dst + dstSize > memory.s) - return HfErrorToInt(HostFunctionError::POINTER_OUT_OF_BOUNDS); + return HfErrorToInt(HostFunctionError::PointerOutOfBounds); if (srcSize > dstSize) - return HfErrorToInt(HostFunctionError::BUFFER_TOO_SMALL); + return HfErrorToInt(HostFunctionError::BufferTooSmall); memcpy(memory.p + dst, src, srcSize); @@ -76,7 +98,7 @@ getDataUnsigned(IW* runtime, wasm_val_vec_t const* params, int32_t& i) if (!r) return Unexpected(r.error()); if (r->size() != sizeof(T)) - return Unexpected(HostFunctionError::INVALID_PARAMS); + return Unexpected(HostFunctionError::InvalidParams); T x; uintptr_t const p = reinterpret_cast(r->data()); @@ -116,7 +138,7 @@ getDataSField(IW* runtime, wasm_val_vec_t const* params, int32_t& i) i++; if (it == m.end()) { - return Unexpected(HostFunctionError::INVALID_FIELD); + return Unexpected(HostFunctionError::InvalidField); } return *it->second; } @@ -129,22 +151,22 @@ getDataSlice(IW* runtime, wasm_val_vec_t const* params, int32_t& i, bool isUpdat int64_t const size = params->data[i + 1].of.i32; i += 2; if (ptr < 0 || size < 0) - return Unexpected(HostFunctionError::INVALID_PARAMS); + return Unexpected(HostFunctionError::InvalidParams); if (!size) return Slice(); if (size > (isUpdate ? maxWasmDataLength : maxWasmParamLength)) - return Unexpected(HostFunctionError::DATA_FIELD_TOO_LARGE); + return Unexpected(HostFunctionError::DataFieldTooLarge); - auto const memory = runtime ? runtime->getMem() : wmem(); + auto const memory = runtime ? runtime->getMem() : Wmem(); // LCOV_EXCL_START if (!memory.s) - return Unexpected(HostFunctionError::NO_MEM_EXPORTED); + return Unexpected(HostFunctionError::NoMemExported); // LCOV_EXCL_STOP if (ptr + size > memory.s) - return Unexpected(HostFunctionError::POINTER_OUT_OF_BOUNDS); + return Unexpected(HostFunctionError::PointerOutOfBounds); Slice data(memory.p + ptr, size); return data; @@ -160,9 +182,9 @@ getDataUInt256(IW* runtime, wasm_val_vec_t const* params, int32_t& i) return Unexpected(slice.error()); } - if (slice->size() != uint256::bytes) + if (slice->size() != Bytes) { - return Unexpected(HostFunctionError::INVALID_PARAMS); + return Unexpected(HostFunctionError::InvalidParams); } return uint256::fromVoid(slice->data()); } @@ -177,9 +199,9 @@ getDataAccountID(IW* runtime, wasm_val_vec_t const* params, int32_t& i) return Unexpected(slice.error()); } - if (slice->size() != AccountID::bytes) + if (slice->size() != Bytes) { - return Unexpected(HostFunctionError::INVALID_PARAMS); + return Unexpected(HostFunctionError::InvalidParams); } return AccountID::fromVoid(slice->data()); @@ -195,9 +217,9 @@ getDataCurrency(IW* runtime, wasm_val_vec_t const* params, int32_t& i) return Unexpected(slice.error()); } - if (slice->size() != Currency::bytes) + if (slice->size() != Bytes) { - return Unexpected(HostFunctionError::INVALID_PARAMS); + return Unexpected(HostFunctionError::InvalidParams); } return Currency::fromVoid(slice->data()); @@ -213,33 +235,32 @@ getDataAsset(IW* runtime, wasm_val_vec_t const* params, int32_t& i) return Unexpected(slice.error()); } - if (slice->size() == MPTID::bytes) + if (slice->size() == Bytes) { auto const mptid = MPTID::fromVoid(slice->data()); return Asset{mptid}; } - if (slice->size() == Currency::bytes) + if (slice->size() == Bytes) { auto const currency = Currency::fromVoid(slice->data()); auto const issue = Issue{currency, xrpAccount()}; if (!issue.native()) - return Unexpected(HostFunctionError::INVALID_PARAMS); + return Unexpected(HostFunctionError::InvalidParams); return Asset{issue}; } - if (slice->size() == (AccountID::bytes + Currency::bytes)) + if (slice->size() == (Bytes + Bytes)) { - auto const issue = Issue( - Currency::fromVoid(slice->data()), - AccountID::fromVoid(slice->data() + Currency::bytes)); + auto const issue = + Issue(Currency::fromVoid(slice->data()), AccountID::fromVoid(slice->data() + Bytes)); if (issue.native()) - return Unexpected(HostFunctionError::INVALID_PARAMS); + return Unexpected(HostFunctionError::InvalidParams); return Asset{issue}; } - return Unexpected(HostFunctionError::INVALID_PARAMS); + return Unexpected(HostFunctionError::InvalidParams); } template @@ -486,7 +507,7 @@ isAmendmentEnabled_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* return hfResult(results, slice.error()); } - if (slice->size() == uint256::bytes) + if (slice->size() == Bytes) { if (auto const ret = hf->isAmendmentEnabled(uint256::fromVoid(slice->data())); ret && *ret == 1) @@ -496,7 +517,7 @@ isAmendmentEnabled_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* if (slice->size() > 64) { - return hfResult(results, HostFunctionError::DATA_FIELD_TOO_LARGE); + return hfResult(results, HostFunctionError::DataFieldTooLarge); } auto const str = std::string_view(reinterpret_cast(slice->data()), slice->size()); @@ -1104,9 +1125,9 @@ mptokenKeylet_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* resu return hfResult(results, slice.error()); } - if (slice->size() != MPTID::bytes) + if (slice->size() != Bytes) { - return hfResult(results, HostFunctionError::INVALID_PARAMS); + return hfResult(results, HostFunctionError::InvalidParams); } auto const mptid = MPTID::fromVoid(slice->data()); @@ -1440,12 +1461,12 @@ trace_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results) int64_t const len = (int64_t)params->data[1].of.i32 + params->data[3].of.i32; if (len < 0) { - return hfResult(results, HostFunctionError::INVALID_PARAMS); + return hfResult(results, HostFunctionError::InvalidParams); } if (std::cmp_greater(len, maxWasmParamLength)) { - return hfResult(results, HostFunctionError::DATA_FIELD_TOO_LARGE); + return hfResult(results, HostFunctionError::DataFieldTooLarge); } auto const msg = getDataString(runtime, params, index); @@ -1468,7 +1489,7 @@ trace_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results) if (*asHex != 0 && *asHex != 1) { - return hfResult(results, HostFunctionError::INVALID_PARAMS); + return hfResult(results, HostFunctionError::InvalidParams); } return returnResult(runtime, params, results, hf->trace(*msg, *data, *asHex != 0), index); @@ -1486,12 +1507,12 @@ traceNum_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results) int32_t const len = params->data[1].of.i32; if (len < 0) { - return hfResult(results, HostFunctionError::INVALID_PARAMS); + return hfResult(results, HostFunctionError::InvalidParams); } if (std::cmp_greater(len, maxWasmParamLength)) { - return hfResult(results, HostFunctionError::DATA_FIELD_TOO_LARGE); + return hfResult(results, HostFunctionError::DataFieldTooLarge); } auto const msg = getDataString(runtime, params, index); @@ -1520,12 +1541,12 @@ traceAccount_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* resul int32_t const len = params->data[1].of.i32; if (len < 0) { - return hfResult(results, HostFunctionError::INVALID_PARAMS); + return hfResult(results, HostFunctionError::InvalidParams); } if (std::cmp_greater(len, maxWasmParamLength)) { - return hfResult(results, HostFunctionError::DATA_FIELD_TOO_LARGE); + return hfResult(results, HostFunctionError::DataFieldTooLarge); } int i = 0; @@ -1555,12 +1576,12 @@ traceFloat_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results int32_t const len = params->data[1].of.i32; if (len < 0) { - return hfResult(results, HostFunctionError::INVALID_PARAMS); + return hfResult(results, HostFunctionError::InvalidParams); } if (std::cmp_greater(len, maxWasmParamLength)) { - return hfResult(results, HostFunctionError::DATA_FIELD_TOO_LARGE); + return hfResult(results, HostFunctionError::DataFieldTooLarge); } int i = 0; @@ -1590,12 +1611,12 @@ traceAmount_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* result int32_t const len = params->data[1].of.i32; if (len < 0) { - return hfResult(results, HostFunctionError::INVALID_PARAMS); + return hfResult(results, HostFunctionError::InvalidParams); } if (std::cmp_greater(len, maxWasmParamLength)) { - return hfResult(results, HostFunctionError::DATA_FIELD_TOO_LARGE); + return hfResult(results, HostFunctionError::DataFieldTooLarge); } int i = 0; @@ -1617,7 +1638,7 @@ traceAmount_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* result std::optional amount; try { - amount = STAmount(serialIter, sfGeneric); + amount = STAmount(serialIter, kSfGeneric); } catch (std::exception const&) { @@ -1626,7 +1647,7 @@ traceAmount_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* result if (!amount) { - return hfResult(results, HostFunctionError::INVALID_PARAMS); + return hfResult(results, HostFunctionError::InvalidParams); } return returnResult(runtime, params, results, hf->traceAmount(*msg, *amount), i); @@ -1693,14 +1714,14 @@ floatFromSTAmount_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* std::optional amount; try { - amount = STAmount(serialIter, sfGeneric); + amount = STAmount(serialIter, kSfGeneric); } catch (std::exception const&) { amount = std::nullopt; } if (!amount) - return hfResult(results, HostFunctionError::INVALID_PARAMS); + return hfResult(results, HostFunctionError::InvalidParams); i = 4; auto const rounding = getDataInt32(runtime, params, i); @@ -1728,14 +1749,14 @@ floatFromSTNumber_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* std::optional num; try { - num = STNumber(serialIter, sfGeneric); + num = STNumber(serialIter, kSfGeneric); } catch (std::exception const&) { num = std::nullopt; } if (!num) - return hfResult(results, HostFunctionError::INVALID_PARAMS); + return hfResult(results, HostFunctionError::InvalidParams); i = 4; auto const rounding = getDataInt32(runtime, params, i); @@ -1993,15 +2014,15 @@ namespace test { class MockWasmRuntimeWrapper { - wmem mem_; + Wmem mem_; public: - MockWasmRuntimeWrapper(wmem memory) : mem_(memory) + MockWasmRuntimeWrapper(Wmem memory) : mem_(memory) { } // Mock methods to simulate the behavior of WasmRuntimeWrapper - wmem + [[nodiscard]] Wmem getMem() const { return mem_; @@ -2014,7 +2035,7 @@ testGetDataIncrement() wasm_val_t values[4]; std::array buffer = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'}; - MockWasmRuntimeWrapper runtime(wmem{buffer.data(), buffer.size()}); + MockWasmRuntimeWrapper runtime(Wmem{.p = buffer.data(), .s = buffer.size()}); { // test int32_t @@ -2083,7 +2104,7 @@ testGetDataIncrement() { // test account AccountID const id( - calcAccountID(generateKeyPair(KeyType::secp256k1, generateSeed("alice")).first)); + calcAccountID(generateKeyPair(KeyType::Secp256k1, generateSeed("alice")).first)); wasm_val_vec_t const params = {2, &values[0]}; @@ -2123,7 +2144,7 @@ testGetDataIncrement() values[1] = WASM_I32_VAL(c.bytes); memcpy(&buffer[0], c.data(), c.bytes); - int index = 0; + int const 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 137b2c9f83..9dd0d2c736 100644 --- a/src/libxrpl/tx/wasm/WasmVM.cpp +++ b/src/libxrpl/tx/wasm/WasmVM.cpp @@ -1,13 +1,18 @@ +#include + +#include +#include +#include +#include + +#include +#include +#include #ifdef _DEBUG // #define DEBUG_OUTPUT 1 #endif -#include -#include -#include -#include #include -#include #include #include diff --git a/src/libxrpl/tx/wasm/WasmiVM.cpp b/src/libxrpl/tx/wasm/WasmiVM.cpp index 2ea7363fe3..a961f8bc16 100644 --- a/src/libxrpl/tx/wasm/WasmiVM.cpp +++ b/src/libxrpl/tx/wasm/WasmiVM.cpp @@ -1,7 +1,31 @@ -#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 #ifdef _DEBUG // #define DEBUG_OUTPUT 1 @@ -13,7 +37,7 @@ namespace xrpl { namespace { void -print_wasm_error(std::string_view msg, wasm_trap_t* trap, beast::Journal jlog) +printWasmError(std::string_view msg, wasm_trap_t* trap, beast::Journal jlog) { #ifdef DEBUG_OUTPUT auto& j = std::cerr; @@ -22,23 +46,23 @@ print_wasm_error(std::string_view msg, wasm_trap_t* trap, beast::Journal jlog) if (jlog.active(beast::severities::kWarning)) #endif { - wasm_byte_vec_t error_message WASM_EMPTY_VEC; + wasm_byte_vec_t errorMessage WASM_EMPTY_VEC; if (trap != nullptr) - wasm_trap_message(trap, &error_message); + wasm_trap_message(trap, &errorMessage); - if (error_message.size != 0u) + if (errorMessage.size != 0u) { j << "WASMI Error: " << msg << ", " - << std::string_view(error_message.data, error_message.size - 1); + << std::string_view(errorMessage.data, errorMessage.size - 1); } else { j << "WASMI Error: " << msg; } - if (error_message.size != 0u) - wasm_byte_vec_delete(&error_message); + if (errorMessage.size != 0u) + wasm_byte_vec_delete(&errorMessage); } if (trap != nullptr) @@ -54,28 +78,28 @@ print_wasm_error(std::string_view msg, wasm_trap_t* trap, beast::Journal jlog) struct WasmiRuntimeWrapper : public WasmRuntimeWrapper { - InstanceWrapper& iw_; + InstanceWrapper& iw; - WasmiRuntimeWrapper(InstanceWrapper& iw) : iw_(iw) + WasmiRuntimeWrapper(InstanceWrapper& iw) : iw(iw) { } - virtual wmem + Wmem getMem() override { - return iw_.getMem(); + return iw.getMem(); } - virtual std::int64_t + std::int64_t getGas() override { - return iw_.getGas(); + return iw.getGas(); } - virtual std::int64_t + std::int64_t setGas(std::int64_t gas) override { - return iw_.setGas(gas); + return iw.setGas(gas); } }; @@ -93,19 +117,19 @@ InstanceWrapper::init( if (!mi || (trap != nullptr)) { - print_wasm_error("can't create instance", trap, j); + printWasmError("can't create instance", trap, j); throw std::runtime_error("can't create instance"); } wasm_instance_exports(mi.get(), expt.get()); return mi; } -InstanceWrapper::InstanceWrapper() : instance_(nullptr, &wasm_instance_delete) +InstanceWrapper::InstanceWrapper() : instance(nullptr, &wasm_instance_delete) { } // LCOV_EXCL_START -InstanceWrapper::InstanceWrapper(InstanceWrapper&& o) : instance_(nullptr, &wasm_instance_delete) +InstanceWrapper::InstanceWrapper(InstanceWrapper&& o) : instance(nullptr, &wasm_instance_delete) { *this = std::move(o); } @@ -116,7 +140,7 @@ InstanceWrapper::InstanceWrapper( ModulePtr& m, WasmExternVec const& imports, beast::Journal j) - : store_(s.get()), instance_(init(s, m, exports_, imports, j)), j_(j) + : store(s.get()), instance(init(s, m, exports, imports, j)), j(j) { } @@ -126,14 +150,14 @@ InstanceWrapper::operator=(InstanceWrapper&& o) if (this == &o) return *this; // LCOV_EXCL_LINE - store_ = o.store_; - o.store_ = nullptr; - exports_ = std::move(o.exports_); - memIdx_ = o.memIdx_; - o.memIdx_ = -1; - instance_ = std::move(o.instance_); + store = o.store; + o.store = nullptr; + exports = std::move(o.exports); + memIdx = o.memIdx; + o.memIdx = -1; + instance = std::move(o.instance); - j_ = o.j_; + j = o.j; return *this; } @@ -141,7 +165,7 @@ InstanceWrapper::operator=(InstanceWrapper&& o) InstanceWrapper:: operator bool() const { - return static_cast(instance_); + return static_cast(instance); } FuncInfo @@ -150,12 +174,12 @@ InstanceWrapper::getFunc(std::string_view funcName, WasmExporttypeVec const& exp wasm_func_t const* f = nullptr; wasm_functype_t const* ft = nullptr; - if (!instance_) + if (!instance) throw std::runtime_error("no instance"); // LCOV_EXCL_LINE if (exportTypes.empty()) throw std::runtime_error("no export"); // LCOV_EXCL_LINE - if (exportTypes.size() != exports_.size()) + if (exportTypes.size() != exports.size()) throw std::runtime_error("invalid export"); // LCOV_EXCL_LINE for (unsigned i = 0; i < exportTypes.size(); ++i) @@ -169,7 +193,7 @@ InstanceWrapper::getFunc(std::string_view funcName, WasmExporttypeVec const& exp if (funcName != std::string_view(name->data, name->size)) continue; - auto const* exn(exports_[i]); + auto const* exn(exports[i]); if (wasm_extern_kind(exn) != WASM_EXTERN_FUNC) throw std::runtime_error("invalid export"); // LCOV_EXCL_LINE @@ -185,23 +209,25 @@ InstanceWrapper::getFunc(std::string_view funcName, WasmExporttypeVec const& exp return {f, ft}; } -wmem +Wmem InstanceWrapper::getMem() const { - if (memIdx_ >= 0) + if (memIdx >= 0) { - auto* e(exports_[memIdx_]); + auto* e(exports[memIdx]); wasm_memory_t* mem = wasm_extern_as_memory(e); - return {reinterpret_cast(wasm_memory_data(mem)), wasm_memory_data_size(mem)}; + return { + .p = reinterpret_cast(wasm_memory_data(mem)), + .s = wasm_memory_data_size(mem)}; } wasm_memory_t* mem = nullptr; - for (int i = 0; i < exports_.size(); ++i) + for (int i = 0; i < exports.size(); ++i) { - auto* e(exports_[i]); + auto* e(exports[i]); if (wasm_extern_kind(e) == WASM_EXTERN_MEMORY) { - memIdx_ = i; + memIdx = i; mem = wasm_extern_as_memory(e); break; } @@ -210,32 +236,34 @@ InstanceWrapper::getMem() const if (mem == nullptr) return {}; // LCOV_EXCL_LINE - return {reinterpret_cast(wasm_memory_data(mem)), wasm_memory_data_size(mem)}; + return { + .p = reinterpret_cast(wasm_memory_data(mem)), + .s = wasm_memory_data_size(mem)}; } std::int64_t InstanceWrapper::getGas() const { - if (store_ == nullptr) + if (store == nullptr) return -1; // LCOV_EXCL_LINE std::uint64_t gas = 0; - wasm_store_get_fuel(store_, &gas); + wasm_store_get_fuel(store, &gas); return static_cast(gas); } std::int64_t InstanceWrapper::setGas(std::int64_t gas) const { - if (store_ == nullptr) + if (store == nullptr) return -1; // LCOV_EXCL_LINE if (gas < 0) gas = std::numeric_limits::max(); - wasmi_error_t* err = wasm_store_set_fuel(store_, static_cast(gas)); + wasmi_error_t* err = wasm_store_set_fuel(store, static_cast(gas)); if (err != nullptr) { // LCOV_EXCL_START - print_wasm_error("Can't set instance gas", nullptr, j_); + printWasmError("Can't set instance gas", nullptr, j); wasmi_error_delete(err); return -1; // LCOV_EXCL_STOP @@ -258,11 +286,11 @@ ModuleWrapper::init(StorePtr& s, Bytes const& wasmBin, beast::Journal j) } // LCOV_EXCL_START -ModuleWrapper::ModuleWrapper() : module_(nullptr, &wasm_module_delete) +ModuleWrapper::ModuleWrapper() : module(nullptr, &wasm_module_delete) { } -ModuleWrapper::ModuleWrapper(ModuleWrapper&& o) : module_(nullptr, &wasm_module_delete) +ModuleWrapper::ModuleWrapper(ModuleWrapper&& o) : module(nullptr, &wasm_module_delete) { *this = std::move(o); } @@ -274,9 +302,9 @@ ModuleWrapper::ModuleWrapper( bool instantiate, ImportVec const& imports, beast::Journal j) - : module_(init(s, wasmBin, j)), j_(j) + : module(init(s, wasmBin, j)), j(j) { - wasm_module_exports(module_.get(), exportTypes_.get()); + wasm_module_exports(module.get(), exportTypes.get()); auto wimports = buildImports(s, imports); if (instantiate) { @@ -291,10 +319,10 @@ ModuleWrapper::operator=(ModuleWrapper&& o) if (this == &o) return *this; - module_ = std::move(o.module_); - instanceWrap_ = std::move(o.instanceWrap_); - exportTypes_ = std::move(o.exportTypes_); - j_ = o.j_; + module = std::move(o.module); + instanceWrap = std::move(o.instanceWrap); + exportTypes = std::move(o.exportTypes); + j = o.j; return *this; } @@ -302,7 +330,7 @@ ModuleWrapper::operator=(ModuleWrapper&& o) ModuleWrapper:: operator bool() const { - return instanceWrap_; + return instanceWrap; } // LCOV_EXCL_STOP @@ -321,10 +349,10 @@ makeImpParams(WasmImportFunc const& imp) auto const vt = imp.params[i]; switch (vt) { - case WT_I32: + case WtI32: v[i] = wasm_valtype_new_i32(); break; - case WT_I64: + case WtI64: v[i] = wasm_valtype_new_i64(); break; // LCOV_EXCL_START @@ -345,11 +373,11 @@ makeImpReturn(WasmImportFunc const& imp) WasmValtypeVec v(1); switch (*imp.result) { - case WT_I32: + case WtI32: v[0] = wasm_valtype_new_i32(); break; // LCOV_EXCL_START - case WT_I64: + case WtI64: v[0] = wasm_valtype_new_i64(); break; default: @@ -363,7 +391,7 @@ WasmExternVec ModuleWrapper::buildImports(StorePtr& s, ImportVec const& imports) const { WasmImporttypeVec importTypes; - wasm_module_imports(module_.get(), importTypes.get()); + wasm_module_imports(module.get(), importTypes.get()); if (importTypes.empty()) return {}; @@ -396,7 +424,7 @@ ModuleWrapper::buildImports(StorePtr& s, ImportVec const& imports) const auto const it = imports.find(fieldName); if (it == imports.end()) { - print_wasm_error("Import not found: " + std::string(fieldName), nullptr, j_); + printWasmError("Import not found: " + std::string(fieldName), nullptr, j); continue; // print all missed import } @@ -430,11 +458,11 @@ ModuleWrapper::buildImports(StorePtr& s, ImportVec const& imports) const if (impCnt != importTypes.size()) { - print_wasm_error( + printWasmError( std::string("Imports not finished: ") + std::to_string(impCnt) + "/" + std::to_string(importTypes.size()), nullptr, - j_); + j); Throw("Missing imports"); } @@ -444,43 +472,43 @@ ModuleWrapper::buildImports(StorePtr& s, ImportVec const& imports) const FuncInfo ModuleWrapper::getFunc(std::string_view funcName) const { - return instanceWrap_.getFunc(funcName, exportTypes_); + return instanceWrap.getFunc(funcName, exportTypes); } wasm_functype_t* ModuleWrapper::getFuncType(std::string_view funcName) const { - for (size_t i = 0; i < exportTypes_.size(); i++) + for (size_t i = 0; i < exportTypes.size(); i++) { - auto const* exp_type(exportTypes_[i]); - wasm_name_t const* name = wasm_exporttype_name(exp_type); - wasm_externtype_t const* exn_type = wasm_exporttype_type(exp_type); - if (wasm_externtype_kind(exn_type) == WASM_EXTERN_FUNC && + auto const* expType(exportTypes[i]); + wasm_name_t const* name = wasm_exporttype_name(expType); + wasm_externtype_t const* exnType = wasm_exporttype_type(expType); + if (wasm_externtype_kind(exnType) == WASM_EXTERN_FUNC && funcName == std::string_view(name->data, name->size)) { - return wasm_externtype_as_functype(const_cast(exn_type)); + return wasm_externtype_as_functype(const_cast(exnType)); } } throw std::runtime_error("can't find function <" + std::string(funcName) + ">"); } -wmem +Wmem ModuleWrapper::getMem() const { - return instanceWrap_.getMem(); + return instanceWrap.getMem(); } InstanceWrapper& ModuleWrapper::getInstance(int) { - return instanceWrap_; + return instanceWrap; } int ModuleWrapper::addInstance(StorePtr& s, WasmExternVec const& imports) { - instanceWrap_ = {s, module_, imports, j_}; + instanceWrap = {s, module, imports, j}; return 0; } @@ -497,7 +525,7 @@ ModuleWrapper::addInstance(StorePtr& s, WasmExternVec const& imports) std::int64_t ModuleWrapper::getGas() const { - return instanceWrap_ ? instanceWrap_.getGas() : -1; + return instanceWrap ? instanceWrap.getGas() : -1; } ////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -552,7 +580,7 @@ WasmiEngine::addModule( { moduleWrap_.reset(); store_.reset(); // to free the memory before creating new store - store_ = {wasm_store_new_with_memory_max_pages(engine_.get(), MAX_PAGES), &wasm_store_delete}; + store_ = {wasm_store_new_with_memory_max_pages(engine_.get(), maxPages), &wasm_store_delete}; if (gas < 0) gas = std::numeric_limits::max(); @@ -560,7 +588,7 @@ WasmiEngine::addModule( if (err != nullptr) { // LCOV_EXCL_START - print_wasm_error("Error setting gas", nullptr, j_); + printWasmError("Error setting gas", nullptr, j_); wasmi_error_delete(err); throw std::runtime_error("can't set gas"); // LCOV_EXCL_STOP @@ -595,11 +623,11 @@ WasmiEngine::convertParams(std::vector const& params) { switch (p.type) { - case WT_I32: + case WtI32: v.push_back(WASM_I32_VAL(p.of.i32)); break; // LCOV_EXCL_START - case WT_I64: + case WtI64: v.push_back(WASM_I64_VAL(p.of.i64)); break; default: @@ -631,7 +659,7 @@ WasmiEngine::compareParamTypes(wasm_valtype_vec_t const* ftp, std::vector& in, int32_t p) +WasmiEngine::addParam(std::vector& in, int32_t p) { in.emplace_back(); auto& el(in.back()); @@ -642,7 +670,7 @@ WasmiEngine::add_param(std::vector& in, int32_t p) // LCOV_EXCL_STOP void -WasmiEngine::add_param(std::vector& in, int64_t p) +WasmiEngine::addParam(std::vector& in, int64_t p) { in.emplace_back(); auto& el(in.back()); @@ -700,7 +728,7 @@ WasmiEngine::call(FuncInfo const& f, std::vector& in) if (trap) { ret.f = true; - print_wasm_error("failure to call func", trap, j_); + printWasmError("failure to call func", trap, j_); } return ret; @@ -710,7 +738,7 @@ template WasmiResult WasmiEngine::call(FuncInfo const& f, std::vector& in, std::int32_t p, Types&&... args) { - add_param(in, p); + addParam(in, p); return call(f, in, std::forward(args)...); } @@ -718,7 +746,7 @@ template WasmiResult WasmiEngine::call(FuncInfo const& f, std::vector& in, std::int64_t p, Types&&... args) { - add_param(in, p); + addParam(in, p); return call(f, in, std::forward(args)...); } @@ -759,12 +787,12 @@ WasmiEngine::run( } catch (std::exception const& e) { - print_wasm_error(std::string("exception: ") + e.what(), nullptr, j); + printWasmError(std::string("exception: ") + e.what(), nullptr, j); } // LCOV_EXCL_START catch (...) { - print_wasm_error(std::string("exception: unknown"), nullptr, j); + printWasmError(std::string("exception: unknown"), nullptr, j); } // LCOV_EXCL_STOP return Unexpected(tecFAILED_PROCESSING); @@ -781,7 +809,7 @@ WasmiEngine::runHlp( beast::Journal j) { // currently only 1 module support, possible parallel UT run - std::lock_guard const lg(m_); + std::scoped_lock const lg(m_); j_ = j; if (wasmCode.empty()) @@ -792,7 +820,7 @@ WasmiEngine::runHlp( // Create and instantiate the module. [[maybe_unused]] int const m = addModule(wasmCode, true, imports, gas); - if (!moduleWrap_ || !moduleWrap_->instanceWrap_) + if (!moduleWrap_ || !moduleWrap_->instanceWrap) throw std::runtime_error("no instance"); // LCOV_EXCL_LINE auto clear = [](HostFunctions* p) { p->setRT(nullptr); }; @@ -833,7 +861,7 @@ WasmiEngine::runHlp( if (gas == -1) gas = std::numeric_limits::max(); - WasmResult const ret{res.r[0].of.i32, gas - moduleWrap_->getGas()}; + WasmResult const ret{.result = res.r[0].of.i32, .cost = gas - moduleWrap_->getGas()}; // #ifdef DEBUG_OUTPUT // auto& j = std::cerr; @@ -861,12 +889,12 @@ WasmiEngine::check( } catch (std::exception const& e) { - print_wasm_error(std::string("exception: ") + e.what(), nullptr, j); + printWasmError(std::string("exception: ") + e.what(), nullptr, j); } // LCOV_EXCL_START catch (...) { - print_wasm_error(std::string("exception: unknown"), nullptr, j); + printWasmError(std::string("exception: unknown"), nullptr, j); } // LCOV_EXCL_STOP @@ -883,7 +911,7 @@ WasmiEngine::checkHlp( beast::Journal j) { // currently only 1 module support, possible parallel UT run - std::lock_guard const lg(m_); + std::scoped_lock const lg(m_); j_ = j; // Create and instantiate the module. @@ -913,10 +941,10 @@ WasmiEngine::getGas() const } // LCOV_EXCL_STOP -wmem +Wmem WasmiEngine::getMem() const { - return moduleWrap_ ? moduleWrap_->getMem() : wmem(); + return moduleWrap_ ? moduleWrap_->getMem() : Wmem(); } InstanceWrapper& diff --git a/src/test/app/HostFuncImpl_test.cpp b/src/test/app/HostFuncImpl_test.cpp index 60ba559b76..01355237ae 100644 --- a/src/test/app/HostFuncImpl_test.cpp +++ b/src/test/app/HostFuncImpl_test.cpp @@ -1,12 +1,64 @@ -#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 +#include +#include +#include +#include +#include +#include +#include +#include +#include #include +#include +#include #include #include +#include +#include #include -namespace xrpl { -namespace test { +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace xrpl::test { static Bytes toBytes(std::uint8_t value) @@ -108,10 +160,10 @@ public: { } - wmem + Wmem getMem() override { - return {buffer_.data(), buffer_.size()}; + return {.p = buffer_.data(), .s = buffer_.size()}; } std::int64_t @@ -153,7 +205,7 @@ public: Throw("Out of bounds"); } - Slice + [[nodiscard]] Slice getBuffer(WasmValVec const& params, size_t i) const { checkIdx(params, i); @@ -162,7 +214,7 @@ public: return {&buffer_[ptr], static_cast(size)}; } - Bytes + [[nodiscard]] Bytes getBytes(WasmValVec const& params, size_t i) const { checkIdx(params, i); @@ -180,7 +232,7 @@ public: } template - T + [[nodiscard]] [[nodiscard]] [[nodiscard]] [[nodiscard]] T getInt(WasmValVec const& params, size_t i) const { checkIdx(params, i); @@ -191,25 +243,25 @@ public: return *reinterpret_cast(&buffer_[ptr]); } - std::int32_t + [[nodiscard]] std::int32_t getInt32(WasmValVec const& params, size_t i) const { return getInt(params, i); } - std::uint32_t + [[nodiscard]] std::uint32_t getUint32(WasmValVec const& params, size_t i) const { return getInt(params, i); } - std::int64_t + [[nodiscard]] std::int64_t getInt64(WasmValVec const& params, size_t i) const { return getInt(params, i); } - std::uint64_t + [[nodiscard]] std::uint64_t getUint64(WasmValVec const& params, size_t i) const { return getInt(params, i); @@ -265,9 +317,9 @@ ww(F&& f, E&& e, P&& params, P&& result, Args... args) constexpr int64_t min64 = std::numeric_limits::min(); constexpr int64_t max64 = std::numeric_limits::max(); -constexpr int32_t FLOAT_SIZE = 12; +constexpr int32_t floatSize = 12; -struct HostFuncImpl_test : public beast::unit_test::suite +struct HostFuncImpl_test : public beast::unit_test::Suite { void testGetLedgerSqn() @@ -362,15 +414,15 @@ struct HostFuncImpl_test : public beast::unit_test::suite params, result, 0, - uint256::bytes); + Bytes); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && - BEAST_EXPECT(result[0].of.i32 == uint256::bytes); + BEAST_EXPECT(result[0].of.i32 == Bytes); auto const resultBytes = vrt.getBytes(params, 0); auto const expectedHash = env.current()->header().parentHash; BEAST_EXPECT( - resultBytes.size() == uint256::bytes && - std::memcmp(resultBytes.data(), expectedHash.data(), uint256::bytes) == 0); + resultBytes.size() == Bytes && + std::memcmp(resultBytes.data(), expectedHash.data(), Bytes) == 0); } } @@ -429,14 +481,9 @@ struct HostFuncImpl_test : public beast::unit_test::suite // hfs.isAmendmentEnabled(amendmentId); { WasmValVec params(2), result(1); - vrt.setBytes(0, amendmentId.data(), uint256::bytes); - auto* trap = - ww(isAmendmentEnabled_wrap, - &import.at("amendment_enabled"), - params, - result, - 0, - uint256::bytes); + vrt.setBytes(0, amendmentId.data(), Bytes); + auto* trap = ww( + isAmendmentEnabled_wrap, &import.at("amendment_enabled"), params, result, 0, Bytes); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && BEAST_EXPECT(result[0].of.i32 == 1); @@ -463,14 +510,9 @@ struct HostFuncImpl_test : public beast::unit_test::suite // hfs.isAmendmentEnabled(fakeId); { WasmValVec params(2), result(1); - vrt.setBytes(0, fakeId.data(), uint256::bytes); - auto* trap = - ww(isAmendmentEnabled_wrap, - &import.at("amendment_enabled"), - params, - result, - 0, - uint256::bytes); + vrt.setBytes(0, fakeId.data(), Bytes); + auto* trap = ww( + isAmendmentEnabled_wrap, &import.at("amendment_enabled"), params, result, 0, Bytes); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && BEAST_EXPECT(result[0].of.i32 == 0); @@ -515,64 +557,62 @@ 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(), Bytes); auto* trap = ww(cacheLedgerObj_wrap, &import.at("cache_ledger_obj"), params, result, 0, - uint256::bytes, + Bytes, -1); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && BEAST_EXPECT( - result[0].of.i32 == - static_cast(HostFunctionError::SLOT_OUT_RANGE)); + result[0].of.i32 == static_cast(HostFunctionError::SlotOutRange)); } // hfs.cacheLedgerObj(accountKeylet.key, 257); { WasmValVec params(3), result(1); - vrt.setBytes(0, accountKeylet.key.data(), uint256::bytes); + vrt.setBytes(0, accountKeylet.key.data(), Bytes); auto* trap = ww(cacheLedgerObj_wrap, &import.at("cache_ledger_obj"), params, result, 0, - uint256::bytes, + Bytes, 257); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && BEAST_EXPECT( - result[0].of.i32 == - static_cast(HostFunctionError::SLOT_OUT_RANGE)); + result[0].of.i32 == static_cast(HostFunctionError::SlotOutRange)); } // hfs.cacheLedgerObj(dummyEscrow.key, 0); { WasmValVec params(3), result(1); - vrt.setBytes(0, dummyEscrow.key.data(), uint256::bytes); + vrt.setBytes(0, dummyEscrow.key.data(), Bytes); auto* trap = ww(cacheLedgerObj_wrap, &import.at("cache_ledger_obj"), params, result, 0, - uint256::bytes, + Bytes, 0); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && BEAST_EXPECT( result[0].of.i32 == - static_cast(HostFunctionError::LEDGER_OBJ_NOT_FOUND)); + static_cast(HostFunctionError::LedgerObjNotFound)); } // hfs.cacheLedgerObj(accountKeylet.key, 0); { WasmValVec params(3), result(1); - vrt.setBytes(0, accountKeylet.key.data(), uint256::bytes); + vrt.setBytes(0, accountKeylet.key.data(), Bytes); auto* trap = ww(cacheLedgerObj_wrap, &import.at("cache_ledger_obj"), @@ -624,7 +664,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && BEAST_EXPECT( - result[0].of.i32 == static_cast(HostFunctionError::SLOTS_FULL)); + result[0].of.i32 == static_cast(HostFunctionError::SlotsFull)); } } @@ -673,7 +713,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && BEAST_EXPECT( - result[0].of.i32 == static_cast(HostFunctionError::SLOTS_FULL)); + result[0].of.i32 == static_cast(HostFunctionError::SlotsFull)); } } } @@ -798,8 +838,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && BEAST_EXPECT( - result[0].of.i32 == - static_cast(HostFunctionError::FIELD_NOT_FOUND)); + result[0].of.i32 == static_cast(HostFunctionError::FieldNotFound)); } // hfs.getTxField(sfMemos); @@ -816,8 +855,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && BEAST_EXPECT( - result[0].of.i32 == - static_cast(HostFunctionError::NOT_LEAF_FIELD)); + result[0].of.i32 == static_cast(HostFunctionError::NotLeafField)); } // hfs.getTxField(sfCredentialIDs); @@ -834,7 +872,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32); BEAST_EXPECTS( - result[0].of.i32 == static_cast(HostFunctionError::NOT_LEAF_FIELD), + result[0].of.i32 == static_cast(HostFunctionError::NotLeafField), std::to_string(result[0].of.i32)); } @@ -852,8 +890,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && BEAST_EXPECT( - result[0].of.i32 == - static_cast(HostFunctionError::FIELD_NOT_FOUND)); + result[0].of.i32 == static_cast(HostFunctionError::FieldNotFound)); } // hfs.getTxField(sfGeneric); @@ -870,8 +907,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && BEAST_EXPECT( - result[0].of.i32 == - static_cast(HostFunctionError::FIELD_NOT_FOUND)); + result[0].of.i32 == static_cast(HostFunctionError::FieldNotFound)); } } @@ -1126,7 +1162,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && BEAST_EXPECT( - result[0].of.i32 == static_cast(HostFunctionError::FIELD_NOT_FOUND)); + result[0].of.i32 == static_cast(HostFunctionError::FieldNotFound)); } { @@ -1152,7 +1188,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && BEAST_EXPECT( result[0].of.i32 == - static_cast(HostFunctionError::LEDGER_OBJ_NOT_FOUND)); + static_cast(HostFunctionError::LedgerObjNotFound)); } } } @@ -1256,7 +1292,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && BEAST_EXPECT( - result[0].of.i32 == static_cast(HostFunctionError::SLOT_OUT_RANGE)); + result[0].of.i32 == static_cast(HostFunctionError::SlotOutRange)); } // hfs.getLedgerObjField(257, sfAccount); @@ -1274,7 +1310,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && BEAST_EXPECT( - result[0].of.i32 == static_cast(HostFunctionError::SLOT_OUT_RANGE)); + result[0].of.i32 == static_cast(HostFunctionError::SlotOutRange)); } // hfs.getLedgerObjField(2, sfAccount); @@ -1292,7 +1328,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && BEAST_EXPECT( - result[0].of.i32 == static_cast(HostFunctionError::EMPTY_SLOT)); + result[0].of.i32 == static_cast(HostFunctionError::EmptySlot)); } // hfs.getLedgerObjField(1, sfOwner); @@ -1310,7 +1346,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && BEAST_EXPECT( - result[0].of.i32 == static_cast(HostFunctionError::FIELD_NOT_FOUND)); + result[0].of.i32 == static_cast(HostFunctionError::FieldNotFound)); } } @@ -1489,7 +1525,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite {sfSigners.fieldCode, // sfSigners does not exist 0, sfAccount.fieldCode}, - HostFunctionError::FIELD_NOT_FOUND); + HostFunctionError::FieldNotFound); // hfs.getTxNestedField(locator); // Locator for non-existent index @@ -1497,13 +1533,13 @@ struct HostFuncImpl_test : public beast::unit_test::suite {sfMemos.fieldCode, 1, // index 1 does not exist sfMemoData.fieldCode}, - HostFunctionError::INDEX_OUT_OF_BOUNDS); + HostFunctionError::IndexOutOfBounds); // hfs.getTxNestedField(locator); // Locator for non-existent index expectError( {sfCredentialIDs.fieldCode, 1}, // index 1 does not exist - HostFunctionError::INDEX_OUT_OF_BOUNDS); + HostFunctionError::IndexOutOfBounds); // hfs.getTxNestedField(locator); // Locator for negative index (STArray) @@ -1511,19 +1547,19 @@ struct HostFuncImpl_test : public beast::unit_test::suite {sfMemos.fieldCode, -1, // negative index sfMemoData.fieldCode}, - HostFunctionError::INDEX_OUT_OF_BOUNDS); + HostFunctionError::IndexOutOfBounds); // hfs.getTxNestedField(locator); // Locator for negative index (STVector256) expectError( {sfCredentialIDs.fieldCode, -1}, // negative index - HostFunctionError::INDEX_OUT_OF_BOUNDS); + HostFunctionError::IndexOutOfBounds); // hfs.getTxNestedField(locator); // Locator for non-existent nested field expectError( {sfMemos.fieldCode, 0, sfURI.fieldCode}, // sfURI does not exist in the memo - HostFunctionError::FIELD_NOT_FOUND); + HostFunctionError::FieldNotFound); // hfs.getTxNestedField(locator); // Locator for non-existent base sfield @@ -1531,7 +1567,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite {field_code(20000, 20000), // nonexistent SField code 0, sfAccount.fieldCode}, - HostFunctionError::INVALID_FIELD); + HostFunctionError::InvalidField); // hfs.getTxNestedField(locator); // Locator for non-existent nested sfield @@ -1539,7 +1575,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite {sfMemos.fieldCode, // nonexistent SField code 0, field_code(20000, 20000)}, - HostFunctionError::INVALID_FIELD); + HostFunctionError::InvalidField); // hfs.getTxNestedField(locator); // Locator for negative base sfield code (-1 = sfInvalid, exists in map but not in tx) @@ -1547,7 +1583,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite {-1, // sfInvalid's field code 0, sfAccount.fieldCode}, - HostFunctionError::FIELD_NOT_FOUND); + HostFunctionError::FieldNotFound); // hfs.getTxNestedField(locator); // Locator for zero base sfield code (0 = sfGeneric, exists in map but not in tx) @@ -1555,28 +1591,28 @@ struct HostFuncImpl_test : public beast::unit_test::suite {0, // sfGeneric's field code 0, sfAccount.fieldCode}, - HostFunctionError::FIELD_NOT_FOUND); + HostFunctionError::FieldNotFound); // hfs.getTxNestedField(locator); // Locator for very negative base sfield code (not in knownCodeToField map) expectError( {std::numeric_limits::min(), 0, sfAccount.fieldCode}, - HostFunctionError::INVALID_FIELD); + 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 - HostFunctionError::FIELD_NOT_FOUND); + HostFunctionError::FieldNotFound); // hfs.getTxNestedField(locator); // Locator for STArray - expectError({sfMemos.fieldCode}, HostFunctionError::NOT_LEAF_FIELD); + expectError({sfMemos.fieldCode}, HostFunctionError::NotLeafField); // hfs.getTxNestedField(locator); // Locator for STVector256 - expectError({sfCredentialIDs.fieldCode}, HostFunctionError::NOT_LEAF_FIELD); + expectError({sfCredentialIDs.fieldCode}, HostFunctionError::NotLeafField); // hfs.getTxNestedField(locator); // Locator for nesting into non-array/object field @@ -1584,11 +1620,11 @@ struct HostFuncImpl_test : public beast::unit_test::suite {sfAccount.fieldCode, // sfAccount is not an array or object 0, sfAccount.fieldCode}, - HostFunctionError::LOCATOR_MALFORMED); + HostFunctionError::LocatorMalformed); // hfs.getTxNestedField(locator); // Locator for empty locator - expectError({}, HostFunctionError::LOCATOR_MALFORMED); + expectError({}, HostFunctionError::LocatorMalformed); // hfs.getTxNestedField(locator); // Locator for malformed locator (not multiple of 4) @@ -1609,7 +1645,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && BEAST_EXPECT( - result[0].of.i32 == static_cast(HostFunctionError::LOCATOR_MALFORMED)); + result[0].of.i32 == static_cast(HostFunctionError::LocatorMalformed)); } } @@ -1691,7 +1727,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite {sfSigners.fieldCode, // sfSigners does not exist 0, sfAccount.fieldCode}, - HostFunctionError::FIELD_NOT_FOUND); + HostFunctionError::FieldNotFound); // hfs.getCurrentLedgerObjNestedField(locator); // Locator for nesting into non-array/object field @@ -1699,7 +1735,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite {sfSignerQuorum.fieldCode, // sfSignerQuorum is not an array or object 0, sfAccount.fieldCode}, - HostFunctionError::LOCATOR_MALFORMED); + HostFunctionError::LocatorMalformed); // hfs.getCurrentLedgerObjNestedField(emptyLocator); // Locator for empty locator @@ -1717,7 +1753,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && BEAST_EXPECT( - result[0].of.i32 == static_cast(HostFunctionError::LOCATOR_MALFORMED)); + result[0].of.i32 == static_cast(HostFunctionError::LocatorMalformed)); } // hfs.getCurrentLedgerObjNestedField(malformedLocator); @@ -1739,7 +1775,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && BEAST_EXPECT( - result[0].of.i32 == static_cast(HostFunctionError::LOCATOR_MALFORMED)); + result[0].of.i32 == static_cast(HostFunctionError::LocatorMalformed)); } // hfs.getCurrentLedgerObjNestedField(locator); @@ -1767,7 +1803,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32); BEAST_EXPECTS( - result[0].of.i32 == static_cast(HostFunctionError::LEDGER_OBJ_NOT_FOUND), + result[0].of.i32 == static_cast(HostFunctionError::LedgerObjNotFound), std::to_string(result[0].of.i32)); } } @@ -1951,14 +1987,14 @@ struct HostFuncImpl_test : public beast::unit_test::suite {sfSigners.fieldCode, // sfSigners does not exist 0, sfAccount.fieldCode}, - HostFunctionError::FIELD_NOT_FOUND); + HostFunctionError::FieldNotFound); // Error: index out of bounds expectError( {sfSignerEntries.fieldCode, 2, // index 2 does not exist sfAccount.fieldCode}, - HostFunctionError::INDEX_OUT_OF_BOUNDS); + HostFunctionError::IndexOutOfBounds); // Error: nested field not found expectError( @@ -1967,34 +2003,34 @@ struct HostFuncImpl_test : public beast::unit_test::suite 0, sfDestination.fieldCode // sfDestination does not exist }, - HostFunctionError::FIELD_NOT_FOUND); + HostFunctionError::FieldNotFound); // Error: invalid field code expectError( - {field_code(99999, 99999), 0, sfAccount.fieldCode}, HostFunctionError::INVALID_FIELD); + {field_code(99999, 99999), 0, sfAccount.fieldCode}, HostFunctionError::InvalidField); // Error: invalid nested field code expectError( {sfSignerEntries.fieldCode, 0, field_code(99999, 99999)}, - HostFunctionError::INVALID_FIELD); + HostFunctionError::InvalidField); // Error: slot out of range - expectError({sfSignerQuorum.fieldCode}, HostFunctionError::SLOT_OUT_RANGE, 0); - expectError({sfSignerQuorum.fieldCode}, HostFunctionError::SLOT_OUT_RANGE, 257); + expectError({sfSignerQuorum.fieldCode}, HostFunctionError::SlotOutRange, 0); + expectError({sfSignerQuorum.fieldCode}, HostFunctionError::SlotOutRange, 257); // Error: empty slot - expectError({sfSignerQuorum.fieldCode}, HostFunctionError::EMPTY_SLOT, 2); + expectError({sfSignerQuorum.fieldCode}, HostFunctionError::EmptySlot, 2); // Error: locator for STArray (not leaf field) - expectError({sfSignerEntries.fieldCode}, HostFunctionError::NOT_LEAF_FIELD); + expectError({sfSignerEntries.fieldCode}, HostFunctionError::NotLeafField); // Error: nesting into non-array/object field expectError( {sfSignerQuorum.fieldCode, 0, sfAccount.fieldCode}, - HostFunctionError::LOCATOR_MALFORMED); + HostFunctionError::LocatorMalformed); // Error: empty locator - expectError({}, HostFunctionError::LOCATOR_MALFORMED); + expectError({}, HostFunctionError::LocatorMalformed); // Error: locator malformed (not multiple of 4) { @@ -2015,7 +2051,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && BEAST_EXPECT( - result[0].of.i32 == static_cast(HostFunctionError::LOCATOR_MALFORMED)); + result[0].of.i32 == static_cast(HostFunctionError::LocatorMalformed)); } } @@ -2089,7 +2125,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite sfAccount.fieldCode); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32); - BEAST_EXPECT(result[0].of.i32 == static_cast(HostFunctionError::NO_ARRAY)); + BEAST_EXPECT(result[0].of.i32 == static_cast(HostFunctionError::NoArray)); } // Should return error for missing array field @@ -2105,7 +2141,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32); BEAST_EXPECT( - result[0].of.i32 == static_cast(HostFunctionError::FIELD_NOT_FOUND)); + result[0].of.i32 == static_cast(HostFunctionError::FieldNotFound)); } // Should return 1 for sfCredentialIDs @@ -2175,7 +2211,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32); BEAST_EXPECT( - result[0].of.i32 == static_cast(HostFunctionError::FIELD_NOT_FOUND)); + result[0].of.i32 == static_cast(HostFunctionError::FieldNotFound)); } // Should return NO_ARRAY for non-array field @@ -2190,7 +2226,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite sfAccount.fieldCode); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32); - BEAST_EXPECT(result[0].of.i32 == static_cast(HostFunctionError::NO_ARRAY)); + BEAST_EXPECT(result[0].of.i32 == static_cast(HostFunctionError::NoArray)); } { @@ -2212,7 +2248,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32); BEAST_EXPECT( - result[0].of.i32 == static_cast(HostFunctionError::LEDGER_OBJ_NOT_FOUND)); + result[0].of.i32 == static_cast(HostFunctionError::LedgerObjNotFound)); } } @@ -2286,8 +2322,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite sfSignerEntries.fieldCode); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32); - BEAST_EXPECT( - result[0].of.i32 == static_cast(HostFunctionError::SLOT_OUT_RANGE)); + BEAST_EXPECT(result[0].of.i32 == static_cast(HostFunctionError::SlotOutRange)); } { @@ -2303,7 +2338,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite sfAccount.fieldCode); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32); - BEAST_EXPECT(result[0].of.i32 == static_cast(HostFunctionError::NO_ARRAY)); + BEAST_EXPECT(result[0].of.i32 == static_cast(HostFunctionError::NoArray)); } { @@ -2319,7 +2354,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite sfSignerEntries.fieldCode); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32); - BEAST_EXPECT(result[0].of.i32 == static_cast(HostFunctionError::EMPTY_SLOT)); + BEAST_EXPECT(result[0].of.i32 == static_cast(HostFunctionError::EmptySlot)); } { @@ -2336,7 +2371,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32); BEAST_EXPECT( - result[0].of.i32 == static_cast(HostFunctionError::FIELD_NOT_FOUND)); + result[0].of.i32 == static_cast(HostFunctionError::FieldNotFound)); } } @@ -2404,10 +2439,10 @@ struct HostFuncImpl_test : public beast::unit_test::suite } // Error: non-array field - expectError({sfAccount.fieldCode}, HostFunctionError::NO_ARRAY); + expectError({sfAccount.fieldCode}, HostFunctionError::NoArray); // Error: missing field - expectError({sfSigners.fieldCode}, HostFunctionError::FIELD_NOT_FOUND); + expectError({sfSigners.fieldCode}, HostFunctionError::FieldNotFound); } void @@ -2472,10 +2507,10 @@ struct HostFuncImpl_test : public beast::unit_test::suite } // Error: non-array field - expectError({sfSignerQuorum.fieldCode}, HostFunctionError::NO_ARRAY); + expectError({sfSignerQuorum.fieldCode}, HostFunctionError::NoArray); // Error: missing field - expectError({sfSigners.fieldCode}, HostFunctionError::FIELD_NOT_FOUND); + expectError({sfSigners.fieldCode}, HostFunctionError::FieldNotFound); { auto const dummyEscrow = keylet::escrow(env.master, env.seq(env.master) + 5); @@ -2499,7 +2534,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32); BEAST_EXPECTS( - result[0].of.i32 == static_cast(HostFunctionError::LEDGER_OBJ_NOT_FOUND), + result[0].of.i32 == static_cast(HostFunctionError::LedgerObjNotFound), std::to_string(result[0].of.i32)); } } @@ -2586,20 +2621,20 @@ struct HostFuncImpl_test : public beast::unit_test::suite }; // Error: non-array field - expectError({sfSignerQuorum.fieldCode}, HostFunctionError::NO_ARRAY); + expectError({sfSignerQuorum.fieldCode}, HostFunctionError::NoArray); // Error: missing field - expectError({sfSigners.fieldCode}, HostFunctionError::FIELD_NOT_FOUND); + expectError({sfSigners.fieldCode}, HostFunctionError::FieldNotFound); // Slot out of range - expectError(locatorVec, HostFunctionError::SLOT_OUT_RANGE, 0); - expectError(locatorVec, HostFunctionError::SLOT_OUT_RANGE, 257); + expectError(locatorVec, HostFunctionError::SlotOutRange, 0); + expectError(locatorVec, HostFunctionError::SlotOutRange, 257); // Empty slot - expectError(locatorVec, HostFunctionError::EMPTY_SLOT, 2); + expectError(locatorVec, HostFunctionError::EmptySlot, 2); // Error: empty locator - expectError({}, HostFunctionError::LOCATOR_MALFORMED); + expectError({}, HostFunctionError::LocatorMalformed); // Error: locator malformed (not multiple of 4) { @@ -2617,13 +2652,13 @@ struct HostFuncImpl_test : public beast::unit_test::suite BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && BEAST_EXPECT( - result[0].of.i32 == static_cast(HostFunctionError::LOCATOR_MALFORMED)); + result[0].of.i32 == static_cast(HostFunctionError::LocatorMalformed)); } // Error: locator for non-STArray field expectError( {sfSignerQuorum.fieldCode, 0, sfAccount.fieldCode}, - HostFunctionError::LOCATOR_MALFORMED); + HostFunctionError::LocatorMalformed); } void @@ -2672,7 +2707,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && BEAST_EXPECT( - result[0].of.i32 == HfErrorToInt(HostFunctionError::DATA_FIELD_TOO_LARGE)); + result[0].of.i32 == HfErrorToInt(HostFunctionError::DataFieldTooLarge)); } } @@ -2777,7 +2812,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite badPk.size()); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && - BEAST_EXPECT(result[0].of.i32 == HfErrorToInt(HostFunctionError::INVALID_PARAMS)); + BEAST_EXPECT(result[0].of.i32 == HfErrorToInt(HostFunctionError::InvalidParams)); } // Should fail for empty public key @@ -2802,7 +2837,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite 0); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && - BEAST_EXPECT(result[0].of.i32 == HfErrorToInt(HostFunctionError::INVALID_PARAMS)); + BEAST_EXPECT(result[0].of.i32 == HfErrorToInt(HostFunctionError::InvalidParams)); } // Should fail for empty signature @@ -2943,7 +2978,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite 32); BEAST_EXPECT( !trap2 && result[0].kind == WASM_I32 && - result[0].of.i32 == static_cast(HostFunctionError::INVALID_ACCOUNT)); + result[0].of.i32 == static_cast(HostFunctionError::InvalidAccount)); } { @@ -2976,7 +3011,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite 32); BEAST_EXPECT( !trap2 && result[0].kind == WASM_I32 && - result[0].of.i32 == static_cast(HostFunctionError::INVALID_PARAMS)); + result[0].of.i32 == static_cast(HostFunctionError::InvalidParams)); auto* trap3 = ww(ammKeylet_wrap, @@ -2989,7 +3024,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite 32); BEAST_EXPECT( !trap3 && result[0].kind == WASM_I32 && - result[0].of.i32 == static_cast(HostFunctionError::INVALID_PARAMS)); + result[0].of.i32 == static_cast(HostFunctionError::InvalidParams)); } { @@ -3021,7 +3056,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite 32); BEAST_EXPECT( !trap2 && result[0].kind == WASM_I32 && - result[0].of.i32 == static_cast(HostFunctionError::INVALID_ACCOUNT)); + result[0].of.i32 == static_cast(HostFunctionError::InvalidAccount)); } std::string const credTypeStr = "test"; @@ -3063,7 +3098,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite 32); BEAST_EXPECT( !trap2 && result[0].kind == WASM_I32 && - result[0].of.i32 == static_cast(HostFunctionError::INVALID_PARAMS)); + result[0].of.i32 == static_cast(HostFunctionError::InvalidParams)); auto* trap3 = ww(credentialKeylet_wrap, @@ -3077,7 +3112,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite 32); BEAST_EXPECT( !trap3 && result[0].kind == WASM_I32 && - result[0].of.i32 == static_cast(HostFunctionError::INVALID_ACCOUNT)); + result[0].of.i32 == static_cast(HostFunctionError::InvalidAccount)); auto* trap4 = ww(credentialKeylet_wrap, @@ -3091,7 +3126,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite 32); BEAST_EXPECT( !trap4 && result[0].kind == WASM_I32 && - result[0].of.i32 == static_cast(HostFunctionError::INVALID_ACCOUNT)); + result[0].of.i32 == static_cast(HostFunctionError::InvalidAccount)); } { @@ -3109,7 +3144,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite ww(didKeylet_wrap, &imp.at("did_keylet"), params, result, xrpAccount(), 1024, 32); BEAST_EXPECT( !trap2 && result[0].kind == WASM_I32 && - result[0].of.i32 == static_cast(HostFunctionError::INVALID_ACCOUNT)); + result[0].of.i32 == static_cast(HostFunctionError::InvalidAccount)); } { @@ -3141,7 +3176,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite 32); BEAST_EXPECT( !trap2 && result[0].kind == WASM_I32 && - result[0].of.i32 == static_cast(HostFunctionError::INVALID_PARAMS)); + result[0].of.i32 == static_cast(HostFunctionError::InvalidParams)); auto* trap3 = ww(delegateKeylet_wrap, @@ -3154,7 +3189,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite 32); BEAST_EXPECT( !trap3 && result[0].kind == WASM_I32 && - result[0].of.i32 == static_cast(HostFunctionError::INVALID_ACCOUNT)); + result[0].of.i32 == static_cast(HostFunctionError::InvalidAccount)); auto* trap4 = ww(delegateKeylet_wrap, @@ -3167,7 +3202,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite 32); BEAST_EXPECT( !trap4 && result[0].kind == WASM_I32 && - result[0].of.i32 == static_cast(HostFunctionError::INVALID_ACCOUNT)); + result[0].of.i32 == static_cast(HostFunctionError::InvalidAccount)); } { @@ -3199,7 +3234,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite 32); BEAST_EXPECT( !trap2 && result[0].kind == WASM_I32 && - result[0].of.i32 == static_cast(HostFunctionError::INVALID_PARAMS)); + result[0].of.i32 == static_cast(HostFunctionError::InvalidParams)); auto* trap3 = ww(depositPreauthKeylet_wrap, @@ -3212,7 +3247,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite 32); BEAST_EXPECT( !trap3 && result[0].kind == WASM_I32 && - result[0].of.i32 == static_cast(HostFunctionError::INVALID_ACCOUNT)); + result[0].of.i32 == static_cast(HostFunctionError::InvalidAccount)); auto* trap4 = ww(depositPreauthKeylet_wrap, @@ -3225,7 +3260,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite 32); BEAST_EXPECT( !trap4 && result[0].kind == WASM_I32 && - result[0].of.i32 == static_cast(HostFunctionError::INVALID_ACCOUNT)); + result[0].of.i32 == static_cast(HostFunctionError::InvalidAccount)); } { @@ -3257,7 +3292,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite 32); BEAST_EXPECT( !trap2 && result[0].kind == WASM_I32 && - result[0].of.i32 == static_cast(HostFunctionError::INVALID_ACCOUNT)); + result[0].of.i32 == static_cast(HostFunctionError::InvalidAccount)); } Currency const usd = to_currency("USD"); @@ -3292,7 +3327,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite 32); BEAST_EXPECT( !trap2 && result[0].kind == WASM_I32 && - result[0].of.i32 == static_cast(HostFunctionError::INVALID_PARAMS)); + result[0].of.i32 == static_cast(HostFunctionError::InvalidParams)); auto* trap3 = ww(lineKeylet_wrap, @@ -3306,7 +3341,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite 32); BEAST_EXPECT( !trap3 && result[0].kind == WASM_I32 && - result[0].of.i32 == static_cast(HostFunctionError::INVALID_ACCOUNT)); + result[0].of.i32 == static_cast(HostFunctionError::InvalidAccount)); auto* trap4 = ww(lineKeylet_wrap, @@ -3320,7 +3355,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite 32); BEAST_EXPECT( !trap4 && result[0].kind == WASM_I32 && - result[0].of.i32 == static_cast(HostFunctionError::INVALID_ACCOUNT)); + result[0].of.i32 == static_cast(HostFunctionError::InvalidAccount)); auto* trap5 = ww(lineKeylet_wrap, @@ -3334,7 +3369,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite 32); BEAST_EXPECT( !trap5 && result[0].kind == WASM_I32 && - result[0].of.i32 == static_cast(HostFunctionError::INVALID_PARAMS)); + result[0].of.i32 == static_cast(HostFunctionError::InvalidParams)); } { @@ -3366,7 +3401,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite 32); BEAST_EXPECT( !trap2 && result[0].kind == WASM_I32 && - result[0].of.i32 == static_cast(HostFunctionError::INVALID_ACCOUNT)); + result[0].of.i32 == static_cast(HostFunctionError::InvalidAccount)); } { @@ -3398,7 +3433,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite 32); BEAST_EXPECT( !trap2 && result[0].kind == WASM_I32 && - result[0].of.i32 == static_cast(HostFunctionError::INVALID_PARAMS)); + result[0].of.i32 == static_cast(HostFunctionError::InvalidParams)); auto* trap3 = ww(mptokenKeylet_wrap, @@ -3411,7 +3446,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite 32); BEAST_EXPECT( !trap3 && result[0].kind == WASM_I32 && - result[0].of.i32 == static_cast(HostFunctionError::INVALID_ACCOUNT)); + result[0].of.i32 == static_cast(HostFunctionError::InvalidAccount)); } { @@ -3443,7 +3478,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite 32); BEAST_EXPECT( !trap2 && result[0].kind == WASM_I32 && - result[0].of.i32 == static_cast(HostFunctionError::INVALID_ACCOUNT)); + result[0].of.i32 == static_cast(HostFunctionError::InvalidAccount)); } { @@ -3475,7 +3510,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite 32); BEAST_EXPECT( !trap2 && result[0].kind == WASM_I32 && - result[0].of.i32 == static_cast(HostFunctionError::INVALID_ACCOUNT)); + result[0].of.i32 == static_cast(HostFunctionError::InvalidAccount)); } { @@ -3507,7 +3542,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite 32); BEAST_EXPECT( !trap2 && result[0].kind == WASM_I32 && - result[0].of.i32 == static_cast(HostFunctionError::INVALID_ACCOUNT)); + result[0].of.i32 == static_cast(HostFunctionError::InvalidAccount)); } { @@ -3541,7 +3576,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite 32); BEAST_EXPECT( !trap2 && result[0].kind == WASM_I32 && - result[0].of.i32 == static_cast(HostFunctionError::INVALID_PARAMS)); + result[0].of.i32 == static_cast(HostFunctionError::InvalidParams)); auto* trap3 = ww(paychanKeylet_wrap, @@ -3555,7 +3590,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite 32); BEAST_EXPECT( !trap3 && result[0].kind == WASM_I32 && - result[0].of.i32 == static_cast(HostFunctionError::INVALID_ACCOUNT)); + result[0].of.i32 == static_cast(HostFunctionError::InvalidAccount)); auto* trap4 = ww(paychanKeylet_wrap, @@ -3569,7 +3604,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite 32); BEAST_EXPECT( !trap4 && result[0].kind == WASM_I32 && - result[0].of.i32 == static_cast(HostFunctionError::INVALID_ACCOUNT)); + result[0].of.i32 == static_cast(HostFunctionError::InvalidAccount)); } { @@ -3601,7 +3636,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite 32); BEAST_EXPECT( !trap2 && result[0].kind == WASM_I32 && - result[0].of.i32 == static_cast(HostFunctionError::INVALID_ACCOUNT)); + result[0].of.i32 == static_cast(HostFunctionError::InvalidAccount)); } { @@ -3625,7 +3660,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite 32); BEAST_EXPECT( !trap2 && result[0].kind == WASM_I32 && - result[0].of.i32 == static_cast(HostFunctionError::INVALID_ACCOUNT)); + result[0].of.i32 == static_cast(HostFunctionError::InvalidAccount)); } { @@ -3657,7 +3692,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite 32); BEAST_EXPECT( !trap2 && result[0].kind == WASM_I32 && - result[0].of.i32 == static_cast(HostFunctionError::INVALID_ACCOUNT)); + result[0].of.i32 == static_cast(HostFunctionError::InvalidAccount)); } { @@ -3689,7 +3724,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite 32); BEAST_EXPECT( !trap2 && result[0].kind == WASM_I32 && - result[0].of.i32 == static_cast(HostFunctionError::INVALID_ACCOUNT)); + result[0].of.i32 == static_cast(HostFunctionError::InvalidAccount)); } } @@ -3769,7 +3804,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite 256); if (BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32)) - BEAST_EXPECT(result[0].of.i32 == HfErrorToInt(HostFunctionError::INVALID_ACCOUNT)); + BEAST_EXPECT(result[0].of.i32 == HfErrorToInt(HostFunctionError::InvalidAccount)); } // Should fail for invalid nftId @@ -3792,7 +3827,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite 256); if (BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32)) - BEAST_EXPECT(result[0].of.i32 == HfErrorToInt(HostFunctionError::INVALID_PARAMS)); + BEAST_EXPECT(result[0].of.i32 == HfErrorToInt(HostFunctionError::InvalidParams)); } // Should fail for invalid nftId @@ -3816,7 +3851,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && BEAST_EXPECT( - result[0].of.i32 == HfErrorToInt(HostFunctionError::LEDGER_OBJ_NOT_FOUND)); + result[0].of.i32 == HfErrorToInt(HostFunctionError::LedgerObjNotFound)); } { @@ -3837,7 +3872,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite 256); if (BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32)) - BEAST_EXPECT(result[0].of.i32 == HfErrorToInt(HostFunctionError::FIELD_NOT_FOUND)); + BEAST_EXPECT(result[0].of.i32 == HfErrorToInt(HostFunctionError::FieldNotFound)); } } @@ -3904,7 +3939,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite AccountID::bytes); if (BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32)) - BEAST_EXPECT(result[0].of.i32 == HfErrorToInt(HostFunctionError::INVALID_PARAMS)); + BEAST_EXPECT(result[0].of.i32 == HfErrorToInt(HostFunctionError::InvalidParams)); } } @@ -4593,7 +4628,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite std::cout << std::dec << std::setfill(' ') << std::endl; } - void + static void printNumbersBin() { printFloats("int64.min", std::numeric_limits::min(), 0); @@ -4745,13 +4780,13 @@ struct HostFuncImpl_test : public beast::unit_test::suite result, min64, 0, - FLOAT_SIZE, + floatSize, -1); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && BEAST_EXPECT( result[0].of.i32 == - static_cast(HostFunctionError::FLOAT_INPUT_MALFORMED)); + static_cast(HostFunctionError::FloatInputMalformed)); } { @@ -4764,13 +4799,13 @@ struct HostFuncImpl_test : public beast::unit_test::suite result, min64, 0, - FLOAT_SIZE, + floatSize, 4); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && BEAST_EXPECT( result[0].of.i32 == - static_cast(HostFunctionError::FLOAT_INPUT_MALFORMED)); + static_cast(HostFunctionError::FloatInputMalformed)); } { @@ -4783,11 +4818,11 @@ struct HostFuncImpl_test : public beast::unit_test::suite result, min64, 0, - FLOAT_SIZE, + floatSize, 0); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && - BEAST_EXPECT(result[0].of.i32 == FLOAT_SIZE); + BEAST_EXPECT(result[0].of.i32 == floatSize); auto const resultBytes = vrt.getBytes(params, 1); BEAST_EXPECT(resultBytes == floatIntMin); } @@ -4802,11 +4837,11 @@ struct HostFuncImpl_test : public beast::unit_test::suite result, 0ll, 0, - FLOAT_SIZE, + floatSize, 0); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && - BEAST_EXPECT(result[0].of.i32 == FLOAT_SIZE); + BEAST_EXPECT(result[0].of.i32 == floatSize); auto const resultBytes = vrt.getBytes(params, 1); BEAST_EXPECT(resultBytes == floatIntZero); } @@ -4821,11 +4856,11 @@ struct HostFuncImpl_test : public beast::unit_test::suite result, max64, 0, - FLOAT_SIZE, + floatSize, 0); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && - BEAST_EXPECT(result[0].of.i32 == FLOAT_SIZE); + BEAST_EXPECT(result[0].of.i32 == floatSize); auto const resultBytes = vrt.getBytes(params, 1); BEAST_EXPECT(resultBytes == floatIntMax); } @@ -4860,13 +4895,13 @@ struct HostFuncImpl_test : public beast::unit_test::suite 0, 8, 16, - FLOAT_SIZE, + floatSize, -1); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && BEAST_EXPECT( result[0].of.i32 == - static_cast(HostFunctionError::FLOAT_INPUT_MALFORMED)); + static_cast(HostFunctionError::FloatInputMalformed)); } { @@ -4882,13 +4917,13 @@ struct HostFuncImpl_test : public beast::unit_test::suite 0, 8, 16, - FLOAT_SIZE, + floatSize, 4); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && BEAST_EXPECT( result[0].of.i32 == - static_cast(HostFunctionError::FLOAT_INPUT_MALFORMED)); + static_cast(HostFunctionError::FloatInputMalformed)); } { @@ -4904,11 +4939,11 @@ struct HostFuncImpl_test : public beast::unit_test::suite 0, 8, 16, - FLOAT_SIZE, + floatSize, 0); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && - BEAST_EXPECT(result[0].of.i32 == FLOAT_SIZE); + BEAST_EXPECT(result[0].of.i32 == floatSize); auto const resultBytes = vrt.getBytes(params, 2); BEAST_EXPECT(resultBytes == floatIntZero); } @@ -4926,11 +4961,11 @@ struct HostFuncImpl_test : public beast::unit_test::suite 0, 8, 16, - FLOAT_SIZE, + floatSize, 0); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && - BEAST_EXPECT(result[0].of.i32 == FLOAT_SIZE); + BEAST_EXPECT(result[0].of.i32 == floatSize); auto const resultBytes = vrt.getBytes(params, 2); BEAST_EXPECT(resultBytes == floatUIntMax); } @@ -4964,13 +4999,13 @@ struct HostFuncImpl_test : public beast::unit_test::suite 1ll, 0, 0, - FLOAT_SIZE, + floatSize, -1); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && BEAST_EXPECT( result[0].of.i32 == - static_cast(HostFunctionError::FLOAT_INPUT_MALFORMED)); + static_cast(HostFunctionError::FloatInputMalformed)); } { @@ -4984,13 +5019,13 @@ struct HostFuncImpl_test : public beast::unit_test::suite 1ll, 0, 0, - FLOAT_SIZE, + floatSize, 4); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && BEAST_EXPECT( result[0].of.i32 == - static_cast(HostFunctionError::FLOAT_INPUT_MALFORMED)); + static_cast(HostFunctionError::FloatInputMalformed)); } { @@ -5004,13 +5039,13 @@ struct HostFuncImpl_test : public beast::unit_test::suite 1ll, Number::maxExponent + normalExp + 1, 0, - FLOAT_SIZE, + floatSize, 0); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && BEAST_EXPECT( result[0].of.i32 == - static_cast(HostFunctionError::FLOAT_INPUT_MALFORMED)); + static_cast(HostFunctionError::FloatInputMalformed)); } { @@ -5024,11 +5059,11 @@ struct HostFuncImpl_test : public beast::unit_test::suite 1ll, Number::minExponent + normalExp - 1, 0, - FLOAT_SIZE, + floatSize, 0); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && - BEAST_EXPECT(result[0].of.i32 == FLOAT_SIZE); + BEAST_EXPECT(result[0].of.i32 == floatSize); auto const resultBytes = vrt.getBytes(params, 2); BEAST_EXPECT(resultBytes == floatIntZero); } @@ -5044,11 +5079,11 @@ struct HostFuncImpl_test : public beast::unit_test::suite 1ll, Number::maxExponent + normalExp, 0, - FLOAT_SIZE, + floatSize, 0); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && - BEAST_EXPECT(result[0].of.i32 == FLOAT_SIZE); + BEAST_EXPECT(result[0].of.i32 == floatSize); auto const resultBytes = vrt.getBytes(params, 2); BEAST_EXPECT(resultBytes == floatMaxExp); } @@ -5064,11 +5099,11 @@ struct HostFuncImpl_test : public beast::unit_test::suite -1ll, Number::maxExponent + normalExp, 0, - FLOAT_SIZE, + floatSize, 0); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && - BEAST_EXPECT(result[0].of.i32 == FLOAT_SIZE); + BEAST_EXPECT(result[0].of.i32 == floatSize); auto const resultBytes = vrt.getBytes(params, 2); BEAST_EXPECT(resultBytes == floatMinusMaxExp); } @@ -5084,11 +5119,11 @@ struct HostFuncImpl_test : public beast::unit_test::suite 1ll, Number::maxExponent + normalExp - 1, 0, - FLOAT_SIZE, + floatSize, 0); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && - BEAST_EXPECT(result[0].of.i32 == FLOAT_SIZE); + BEAST_EXPECT(result[0].of.i32 == floatSize); auto const resultBytes = vrt.getBytes(params, 2); BEAST_EXPECT(resultBytes == floatPreMaxExp); } @@ -5104,11 +5139,11 @@ struct HostFuncImpl_test : public beast::unit_test::suite static_cast(STAmount::cMaxValue), STAmount::cMaxOffset, 0, - FLOAT_SIZE, + floatSize, 0); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && - BEAST_EXPECT(result[0].of.i32 == FLOAT_SIZE); + BEAST_EXPECT(result[0].of.i32 == floatSize); auto const resultBytes = vrt.getBytes(params, 2); BEAST_EXPECT(resultBytes == floatMaxIOU); } @@ -5124,11 +5159,11 @@ struct HostFuncImpl_test : public beast::unit_test::suite 1ll, Number::minExponent - normalExp, 0, - FLOAT_SIZE, + floatSize, 0); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && - BEAST_EXPECT(result[0].of.i32 == FLOAT_SIZE); + BEAST_EXPECT(result[0].of.i32 == floatSize); auto const resultBytes = vrt.getBytes(params, 2); BEAST_EXPECT(resultBytes == floatMinExp); } @@ -5144,11 +5179,11 @@ struct HostFuncImpl_test : public beast::unit_test::suite 10ll, -1, 0, - FLOAT_SIZE, + floatSize, 0); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && - BEAST_EXPECT(result[0].of.i32 == FLOAT_SIZE); + BEAST_EXPECT(result[0].of.i32 == floatSize); auto const resultBytes = vrt.getBytes(params, 2); BEAST_EXPECT(resultBytes == float1); } @@ -5164,13 +5199,13 @@ struct HostFuncImpl_test : public beast::unit_test::suite 1ll, Number::maxExponent + normalExp + 1, 0, - FLOAT_SIZE, + floatSize, 0); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && BEAST_EXPECT( result[0].of.i32 == - static_cast(HostFunctionError::FLOAT_INPUT_MALFORMED)); + static_cast(HostFunctionError::FloatInputMalformed)); } } @@ -5198,7 +5233,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && BEAST_EXPECT( result[0].of.i32 == - static_cast(HostFunctionError::FLOAT_INPUT_MALFORMED)); + static_cast(HostFunctionError::FloatInputMalformed)); } { @@ -5206,49 +5241,49 @@ struct HostFuncImpl_test : public beast::unit_test::suite WasmValVec params(4), result(1); vrt.setBytes(0, floatInvalidZero.data(), floatInvalidZero.size()); auto* trap = - ww(floatCompare_wrap, &import.at("float_add"), params, result, 0, FLOAT_SIZE, 0, 0); + ww(floatCompare_wrap, &import.at("float_add"), params, result, 0, floatSize, 0, 0); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && BEAST_EXPECT( result[0].of.i32 == - static_cast(HostFunctionError::FLOAT_INPUT_MALFORMED)); + static_cast(HostFunctionError::FloatInputMalformed)); } { // hfs.floatCompare(makeSlice(float1), makeSlice(invalid)); WasmValVec params(4), result(1); vrt.setBytes(0, float1.data(), float1.size()); - vrt.setBytes(FLOAT_SIZE, invalid.data(), invalid.size()); + vrt.setBytes(floatSize, invalid.data(), invalid.size()); auto* trap = ww(floatCompare_wrap, &import.at("float_add"), params, result, 0, - FLOAT_SIZE, - FLOAT_SIZE, + floatSize, + floatSize, invalid.size()); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && BEAST_EXPECT( result[0].of.i32 == - static_cast(HostFunctionError::FLOAT_INPUT_MALFORMED)); + static_cast(HostFunctionError::FloatInputMalformed)); } { // hfs.floatCompare(makeSlice(floatIntMin), makeSlice(floatIntZero)); WasmValVec params(4), result(1); vrt.setBytes(0, floatIntMin.data(), floatIntMin.size()); - vrt.setBytes(FLOAT_SIZE, floatIntZero.data(), floatIntZero.size()); + vrt.setBytes(floatSize, floatIntZero.data(), floatIntZero.size()); auto* trap = ww(floatCompare_wrap, &import.at("float_add"), params, result, 0, - FLOAT_SIZE, - FLOAT_SIZE, - FLOAT_SIZE); + floatSize, + floatSize, + floatSize); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && BEAST_EXPECT(result[0].of.i32 == 2); @@ -5258,16 +5293,16 @@ struct HostFuncImpl_test : public beast::unit_test::suite // hfs.floatCompare(makeSlice(floatIntMax), makeSlice(floatIntZero)); WasmValVec params(4), result(1); vrt.setBytes(0, floatIntMax.data(), floatIntMax.size()); - vrt.setBytes(FLOAT_SIZE, floatIntZero.data(), floatIntZero.size()); + vrt.setBytes(floatSize, floatIntZero.data(), floatIntZero.size()); auto* trap = ww(floatCompare_wrap, &import.at("float_add"), params, result, 0, - FLOAT_SIZE, - FLOAT_SIZE, - FLOAT_SIZE); + floatSize, + floatSize, + floatSize); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && BEAST_EXPECT(result[0].of.i32 == 1); @@ -5277,16 +5312,16 @@ struct HostFuncImpl_test : public beast::unit_test::suite // hfs.floatCompare(makeSlice(float1), makeSlice(float1)); WasmValVec params(4), result(1); vrt.setBytes(0, float1.data(), float1.size()); - vrt.setBytes(FLOAT_SIZE, float1.data(), float1.size()); + vrt.setBytes(floatSize, float1.data(), float1.size()); auto* trap = ww(floatCompare_wrap, &import.at("float_add"), params, result, 0, - FLOAT_SIZE, - FLOAT_SIZE, - FLOAT_SIZE); + floatSize, + floatSize, + floatSize); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && BEAST_EXPECT(result[0].of.i32 == 0); @@ -5322,13 +5357,13 @@ struct HostFuncImpl_test : public beast::unit_test::suite 0, 0, 0, - FLOAT_SIZE, + floatSize, -1); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && BEAST_EXPECT( result[0].of.i32 == - static_cast(HostFunctionError::FLOAT_INPUT_MALFORMED)); + static_cast(HostFunctionError::FloatInputMalformed)); } { @@ -5344,37 +5379,37 @@ struct HostFuncImpl_test : public beast::unit_test::suite 0, 0, 0, - FLOAT_SIZE, + floatSize, 0); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && BEAST_EXPECT( result[0].of.i32 == - static_cast(HostFunctionError::FLOAT_INPUT_MALFORMED)); + static_cast(HostFunctionError::FloatInputMalformed)); } { // hfs.floatAdd(makeSlice(float1), makeSlice(invalid), 0); WasmValVec params(7), result(1); vrt.setBytes(0, float1.data(), float1.size()); - vrt.setBytes(FLOAT_SIZE, invalid.data(), invalid.size()); + vrt.setBytes(floatSize, invalid.data(), invalid.size()); auto* trap = ww(floatAdd_wrap, &import.at("float_subtract"), params, result, 0, - FLOAT_SIZE, - FLOAT_SIZE, + floatSize, + floatSize, invalid.size(), - 2 * FLOAT_SIZE, - FLOAT_SIZE, + 2 * floatSize, + floatSize, 0); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && BEAST_EXPECT( result[0].of.i32 == - static_cast(HostFunctionError::FLOAT_INPUT_MALFORMED)); + static_cast(HostFunctionError::FloatInputMalformed)); } { @@ -5382,22 +5417,22 @@ struct HostFuncImpl_test : public beast::unit_test::suite // max IOU is too small to make any change WasmValVec params(7), result(1); vrt.setBytes(0, floatMaxIOU.data(), floatMaxIOU.size()); - vrt.setBytes(FLOAT_SIZE, floatMaxExp.data(), floatMaxExp.size()); + vrt.setBytes(floatSize, floatMaxExp.data(), floatMaxExp.size()); auto* trap = ww(floatAdd_wrap, &import.at("float_subtract"), params, result, 0, - FLOAT_SIZE, - FLOAT_SIZE, - FLOAT_SIZE, - 2 * FLOAT_SIZE, - FLOAT_SIZE, + floatSize, + floatSize, + floatSize, + 2 * floatSize, + floatSize, 0); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && - BEAST_EXPECT(result[0].of.i32 == FLOAT_SIZE); + BEAST_EXPECT(result[0].of.i32 == floatSize); auto const resultBytes = vrt.getBytes(params, 4); BEAST_EXPECT(resultBytes == floatMaxExp); } @@ -5406,22 +5441,22 @@ struct HostFuncImpl_test : public beast::unit_test::suite // hfs.floatAdd(makeSlice(floatIntMin), makeSlice(floatIntZero), 0); WasmValVec params(7), result(1); vrt.setBytes(0, floatIntMin.data(), floatIntMin.size()); - vrt.setBytes(FLOAT_SIZE, floatIntZero.data(), floatIntZero.size()); + vrt.setBytes(floatSize, floatIntZero.data(), floatIntZero.size()); auto* trap = ww(floatAdd_wrap, &import.at("float_subtract"), params, result, 0, - FLOAT_SIZE, - FLOAT_SIZE, - FLOAT_SIZE, - 2 * FLOAT_SIZE, - FLOAT_SIZE, + floatSize, + floatSize, + floatSize, + 2 * floatSize, + floatSize, 0); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && - BEAST_EXPECT(result[0].of.i32 == FLOAT_SIZE); + BEAST_EXPECT(result[0].of.i32 == floatSize); auto const resultBytes = vrt.getBytes(params, 4); BEAST_EXPECT(resultBytes == floatIntMin); } @@ -5431,22 +5466,22 @@ struct HostFuncImpl_test : public beast::unit_test::suite // Number can't hold int64.min, it is rounded and we get -3, not -1 WasmValVec params(7), result(1); vrt.setBytes(0, floatIntMax.data(), floatIntMax.size()); - vrt.setBytes(FLOAT_SIZE, floatIntMin.data(), floatIntMin.size()); + vrt.setBytes(floatSize, floatIntMin.data(), floatIntMin.size()); auto* trap = ww(floatAdd_wrap, &import.at("float_subtract"), params, result, 0, - FLOAT_SIZE, - FLOAT_SIZE, - FLOAT_SIZE, - 2 * FLOAT_SIZE, - FLOAT_SIZE, + floatSize, + floatSize, + floatSize, + 2 * floatSize, + floatSize, 0); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && - BEAST_EXPECT(result[0].of.i32 == FLOAT_SIZE); + BEAST_EXPECT(result[0].of.i32 == floatSize); auto const resultBytes = vrt.getBytes(params, 4); BEAST_EXPECT(resultBytes == floatMinus3); } @@ -5481,13 +5516,13 @@ struct HostFuncImpl_test : public beast::unit_test::suite 0, 0, 0, - FLOAT_SIZE, + floatSize, -1); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && BEAST_EXPECT( result[0].of.i32 == - static_cast(HostFunctionError::FLOAT_INPUT_MALFORMED)); + static_cast(HostFunctionError::FloatInputMalformed)); } { @@ -5503,59 +5538,59 @@ struct HostFuncImpl_test : public beast::unit_test::suite 0, 0, 0, - FLOAT_SIZE, + floatSize, 0); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && BEAST_EXPECT( result[0].of.i32 == - static_cast(HostFunctionError::FLOAT_INPUT_MALFORMED)); + static_cast(HostFunctionError::FloatInputMalformed)); } { // hfs.floatSubtract(makeSlice(float1), makeSlice(invalid), 0); WasmValVec params(7), result(1); vrt.setBytes(0, float1.data(), float1.size()); - vrt.setBytes(FLOAT_SIZE, invalid.data(), invalid.size()); + vrt.setBytes(floatSize, invalid.data(), invalid.size()); auto* trap = ww(floatSubtract_wrap, &import.at("float_from_mant_exp"), params, result, 0, - FLOAT_SIZE, - FLOAT_SIZE, + floatSize, + floatSize, invalid.size(), - FLOAT_SIZE * 2, - FLOAT_SIZE, + floatSize * 2, + floatSize, 0); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && BEAST_EXPECT( result[0].of.i32 == - static_cast(HostFunctionError::FLOAT_INPUT_MALFORMED)); + static_cast(HostFunctionError::FloatInputMalformed)); } { // hfs.floatSubtract(makeSlice(floatMinusMaxExp), makeSlice(floatMaxIOU), 0); WasmValVec params(7), result(1); vrt.setBytes(0, floatMinusMaxExp.data(), floatMinusMaxExp.size()); - vrt.setBytes(FLOAT_SIZE, floatMaxIOU.data(), floatMaxIOU.size()); + vrt.setBytes(floatSize, floatMaxIOU.data(), floatMaxIOU.size()); auto* trap = ww(floatSubtract_wrap, &import.at("float_from_mant_exp"), params, result, 0, - FLOAT_SIZE, - FLOAT_SIZE, - FLOAT_SIZE, - 2 * FLOAT_SIZE, - FLOAT_SIZE, + floatSize, + floatSize, + floatSize, + 2 * floatSize, + floatSize, 0); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && - BEAST_EXPECT(result[0].of.i32 == FLOAT_SIZE); + BEAST_EXPECT(result[0].of.i32 == floatSize); auto const resultBytes = vrt.getBytes(params, 4); BEAST_EXPECT(resultBytes == floatMinusMaxExp); } @@ -5564,22 +5599,22 @@ struct HostFuncImpl_test : public beast::unit_test::suite // hfs.floatSubtract(makeSlice(floatIntMin), makeSlice(floatIntZero), 0); WasmValVec params(7), result(1); vrt.setBytes(0, floatIntMin.data(), floatIntMin.size()); - vrt.setBytes(FLOAT_SIZE, floatIntZero.data(), floatIntZero.size()); + vrt.setBytes(floatSize, floatIntZero.data(), floatIntZero.size()); auto* trap = ww(floatSubtract_wrap, &import.at("float_from_mant_exp"), params, result, 0, - FLOAT_SIZE, - FLOAT_SIZE, - FLOAT_SIZE, - 2 * FLOAT_SIZE, - FLOAT_SIZE, + floatSize, + floatSize, + floatSize, + 2 * floatSize, + floatSize, 0); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && - BEAST_EXPECT(result[0].of.i32 == FLOAT_SIZE); + BEAST_EXPECT(result[0].of.i32 == floatSize); auto const resultBytes = vrt.getBytes(params, 4); BEAST_EXPECT(resultBytes == floatIntMin); } @@ -5588,22 +5623,22 @@ struct HostFuncImpl_test : public beast::unit_test::suite // hfs.floatSubtract(makeSlice(floatIntZero), makeSlice(float1), 0); WasmValVec params(7), result(1); vrt.setBytes(0, floatIntZero.data(), floatIntZero.size()); - vrt.setBytes(FLOAT_SIZE, float1.data(), float1.size()); + vrt.setBytes(floatSize, float1.data(), float1.size()); auto* trap = ww(floatSubtract_wrap, &import.at("float_from_mant_exp"), params, result, 0, - FLOAT_SIZE, - FLOAT_SIZE, - FLOAT_SIZE, - 2 * FLOAT_SIZE, - FLOAT_SIZE, + floatSize, + floatSize, + floatSize, + 2 * floatSize, + floatSize, 0); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && - BEAST_EXPECT(result[0].of.i32 == FLOAT_SIZE); + BEAST_EXPECT(result[0].of.i32 == floatSize); auto const resultBytes = vrt.getBytes(params, 4); BEAST_EXPECT(resultBytes == floatMinus1); } @@ -5638,13 +5673,13 @@ struct HostFuncImpl_test : public beast::unit_test::suite 0, 0, 0, - FLOAT_SIZE, + floatSize, -1); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && BEAST_EXPECT( result[0].of.i32 == - static_cast(HostFunctionError::FLOAT_INPUT_MALFORMED)); + static_cast(HostFunctionError::FloatInputMalformed)); } { @@ -5660,83 +5695,83 @@ struct HostFuncImpl_test : public beast::unit_test::suite 0, 0, 0, - FLOAT_SIZE, + floatSize, 0); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && BEAST_EXPECT( result[0].of.i32 == - static_cast(HostFunctionError::FLOAT_INPUT_MALFORMED)); + static_cast(HostFunctionError::FloatInputMalformed)); } { // hfs.floatMultiply(makeSlice(float1), makeSlice(invalid), 0); WasmValVec params(7), result(1); vrt.setBytes(0, float1.data(), float1.size()); - vrt.setBytes(FLOAT_SIZE, invalid.data(), invalid.size()); + vrt.setBytes(floatSize, invalid.data(), invalid.size()); auto* trap = ww(floatMultiply_wrap, &import.at("float_multiply"), params, result, 0, - FLOAT_SIZE, - FLOAT_SIZE, + floatSize, + floatSize, invalid.size(), - 2 * FLOAT_SIZE, - FLOAT_SIZE, + 2 * floatSize, + floatSize, 0); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && BEAST_EXPECT( result[0].of.i32 == - static_cast(HostFunctionError::FLOAT_INPUT_MALFORMED)); + static_cast(HostFunctionError::FloatInputMalformed)); } { // hfs.floatMultiply(makeSlice(floatMax), makeSlice(float1More), 0); WasmValVec params(7), result(1); vrt.setBytes(0, floatMax.data(), floatMax.size()); - vrt.setBytes(FLOAT_SIZE, float1More.data(), float1More.size()); + vrt.setBytes(floatSize, float1More.data(), float1More.size()); auto* trap = ww(floatMultiply_wrap, &import.at("float_multiply"), params, result, 0, - FLOAT_SIZE, - FLOAT_SIZE, - FLOAT_SIZE, - 2 * FLOAT_SIZE, - FLOAT_SIZE, + floatSize, + floatSize, + floatSize, + 2 * floatSize, + floatSize, 0); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && BEAST_EXPECT( result[0].of.i32 == - static_cast(HostFunctionError::FLOAT_COMPUTATION_ERROR)); + static_cast(HostFunctionError::FloatComputationError)); } { // hfs.floatMultiply(makeSlice(float1), makeSlice(float1), 0); WasmValVec params(7), result(1); vrt.setBytes(0, float1.data(), float1.size()); - vrt.setBytes(FLOAT_SIZE, float1.data(), float1.size()); + vrt.setBytes(floatSize, float1.data(), float1.size()); auto* trap = ww(floatMultiply_wrap, &import.at("float_multiply"), params, result, 0, - FLOAT_SIZE, - FLOAT_SIZE, - FLOAT_SIZE, - 2 * FLOAT_SIZE, - FLOAT_SIZE, + floatSize, + floatSize, + floatSize, + 2 * floatSize, + floatSize, 0); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && - BEAST_EXPECT(result[0].of.i32 == FLOAT_SIZE); + BEAST_EXPECT(result[0].of.i32 == floatSize); auto const resultBytes = vrt.getBytes(params, 4); BEAST_EXPECT(resultBytes == float1); } @@ -5745,22 +5780,22 @@ struct HostFuncImpl_test : public beast::unit_test::suite // hfs.floatMultiply(makeSlice(floatIntZero), makeSlice(floatMaxIOU), 0); WasmValVec params(7), result(1); vrt.setBytes(0, floatIntZero.data(), floatIntZero.size()); - vrt.setBytes(FLOAT_SIZE, floatMaxIOU.data(), floatMaxIOU.size()); + vrt.setBytes(floatSize, floatMaxIOU.data(), floatMaxIOU.size()); auto* trap = ww(floatMultiply_wrap, &import.at("float_multiply"), params, result, 0, - FLOAT_SIZE, - FLOAT_SIZE, - FLOAT_SIZE, - 2 * FLOAT_SIZE, - FLOAT_SIZE, + floatSize, + floatSize, + floatSize, + 2 * floatSize, + floatSize, 0); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && - BEAST_EXPECT(result[0].of.i32 == FLOAT_SIZE); + BEAST_EXPECT(result[0].of.i32 == floatSize); auto const resultBytes = vrt.getBytes(params, 4); BEAST_EXPECT(resultBytes == floatIntZero); } @@ -5769,22 +5804,22 @@ struct HostFuncImpl_test : public beast::unit_test::suite // hfs.floatMultiply(makeSlice(float10), makeSlice(floatPreMaxExp), 0); WasmValVec params(7), result(1); vrt.setBytes(0, float10.data(), float10.size()); - vrt.setBytes(FLOAT_SIZE, floatPreMaxExp.data(), floatPreMaxExp.size()); + vrt.setBytes(floatSize, floatPreMaxExp.data(), floatPreMaxExp.size()); auto* trap = ww(floatMultiply_wrap, &import.at("float_multiply"), params, result, 0, - FLOAT_SIZE, - FLOAT_SIZE, - FLOAT_SIZE, - 2 * FLOAT_SIZE, - FLOAT_SIZE, + floatSize, + floatSize, + floatSize, + 2 * floatSize, + floatSize, 0); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && - BEAST_EXPECT(result[0].of.i32 == FLOAT_SIZE); + BEAST_EXPECT(result[0].of.i32 == floatSize); auto const resultBytes = vrt.getBytes(params, 4); BEAST_EXPECT(resultBytes == floatMaxExp); } @@ -5819,13 +5854,13 @@ struct HostFuncImpl_test : public beast::unit_test::suite 0, 0, 0, - FLOAT_SIZE, + floatSize, -1); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && BEAST_EXPECT( result[0].of.i32 == - static_cast(HostFunctionError::FLOAT_INPUT_MALFORMED)); + static_cast(HostFunctionError::FloatInputMalformed)); } { @@ -5841,59 +5876,59 @@ struct HostFuncImpl_test : public beast::unit_test::suite 0, 0, 0, - FLOAT_SIZE, + floatSize, 0); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && BEAST_EXPECT( result[0].of.i32 == - static_cast(HostFunctionError::FLOAT_INPUT_MALFORMED)); + static_cast(HostFunctionError::FloatInputMalformed)); } { // hfs.floatDivide(makeSlice(float1), makeSlice(invalid), 0); WasmValVec params(7), result(1); vrt.setBytes(0, float1.data(), float1.size()); - vrt.setBytes(FLOAT_SIZE, invalid.data(), invalid.size()); + vrt.setBytes(floatSize, invalid.data(), invalid.size()); auto* trap = ww(floatDivide_wrap, &import.at("float_divide"), params, result, 0, - FLOAT_SIZE, - FLOAT_SIZE, + floatSize, + floatSize, invalid.size(), - 2 * FLOAT_SIZE, - FLOAT_SIZE, + 2 * floatSize, + floatSize, 0); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && BEAST_EXPECT( result[0].of.i32 == - static_cast(HostFunctionError::FLOAT_INPUT_MALFORMED)); + static_cast(HostFunctionError::FloatInputMalformed)); } { // hfs.floatDivide(makeSlice(float1), makeSlice(floatIntZero), 0); WasmValVec params(7), result(1); vrt.setBytes(0, float1.data(), float1.size()); - vrt.setBytes(FLOAT_SIZE, floatIntZero.data(), floatIntZero.size()); + vrt.setBytes(floatSize, floatIntZero.data(), floatIntZero.size()); auto* trap = ww(floatDivide_wrap, &import.at("float_divide"), params, result, 0, - FLOAT_SIZE, - FLOAT_SIZE, - FLOAT_SIZE, - 2 * FLOAT_SIZE, - FLOAT_SIZE, + floatSize, + floatSize, + floatSize, + 2 * floatSize, + floatSize, 0); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && BEAST_EXPECT( result[0].of.i32 == - static_cast(HostFunctionError::FLOAT_COMPUTATION_ERROR)); + static_cast(HostFunctionError::FloatComputationError)); } { // hfs.floatDivide(makeSlice(floatMax), makeSlice(*y), 0); @@ -5903,46 +5938,46 @@ struct HostFuncImpl_test : public beast::unit_test::suite { WasmValVec params(7), result(1); vrt.setBytes(0, floatMax.data(), floatMax.size()); - vrt.setBytes(FLOAT_SIZE, y->data(), y->size()); + vrt.setBytes(floatSize, y->data(), y->size()); auto* trap = ww(floatDivide_wrap, &import.at("float_divide"), params, result, 0, - FLOAT_SIZE, - FLOAT_SIZE, - FLOAT_SIZE, - 2 * FLOAT_SIZE, - FLOAT_SIZE, + floatSize, + floatSize, + floatSize, + 2 * floatSize, + floatSize, 0); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && BEAST_EXPECT( result[0].of.i32 == - static_cast(HostFunctionError::FLOAT_COMPUTATION_ERROR)); + static_cast(HostFunctionError::FloatComputationError)); } } { // hfs.floatDivide(makeSlice(floatIntZero), makeSlice(float1), 0); WasmValVec params(7), result(1); vrt.setBytes(0, floatIntZero.data(), floatIntZero.size()); - vrt.setBytes(FLOAT_SIZE, float1.data(), float1.size()); + vrt.setBytes(floatSize, float1.data(), float1.size()); auto* trap = ww(floatDivide_wrap, &import.at("float_divide"), params, result, 0, - FLOAT_SIZE, - FLOAT_SIZE, - FLOAT_SIZE, - 2 * FLOAT_SIZE, - FLOAT_SIZE, + floatSize, + floatSize, + floatSize, + 2 * floatSize, + floatSize, 0); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && - BEAST_EXPECT(result[0].of.i32 == FLOAT_SIZE); + BEAST_EXPECT(result[0].of.i32 == floatSize); auto const resultBytes = vrt.getBytes(params, 4); BEAST_EXPECT(resultBytes == floatIntZero); } @@ -5950,22 +5985,22 @@ struct HostFuncImpl_test : public beast::unit_test::suite { // hfs.floatDivide(makeSlice(floatMaxExp), makeSlice(float10), 0); WasmValVec params(7), result(1); vrt.setBytes(0, floatMaxExp.data(), floatMaxExp.size()); - vrt.setBytes(FLOAT_SIZE, float10.data(), float10.size()); + vrt.setBytes(floatSize, float10.data(), float10.size()); auto* trap = ww(floatDivide_wrap, &import.at("float_divide"), params, result, 0, - FLOAT_SIZE, - FLOAT_SIZE, - FLOAT_SIZE, - 2 * FLOAT_SIZE, - FLOAT_SIZE, + floatSize, + floatSize, + floatSize, + 2 * floatSize, + floatSize, 0); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && - BEAST_EXPECT(result[0].of.i32 == FLOAT_SIZE); + BEAST_EXPECT(result[0].of.i32 == floatSize); auto const resultBytes = vrt.getBytes(params, 4); BEAST_EXPECT(resultBytes == floatPreMaxExp); } @@ -5998,13 +6033,13 @@ struct HostFuncImpl_test : public beast::unit_test::suite 0, 2, 0, - FLOAT_SIZE, + floatSize, -1); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && BEAST_EXPECT( result[0].of.i32 == - static_cast(HostFunctionError::FLOAT_INPUT_MALFORMED)); + static_cast(HostFunctionError::FloatInputMalformed)); } { // hfs.floatRoot(makeSlice(invalid), 3, 0); @@ -6018,14 +6053,14 @@ struct HostFuncImpl_test : public beast::unit_test::suite 0, invalid.size(), 3, - 2 * FLOAT_SIZE, - FLOAT_SIZE, + 2 * floatSize, + floatSize, 0); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && BEAST_EXPECT( result[0].of.i32 == - static_cast(HostFunctionError::FLOAT_INPUT_MALFORMED)); + static_cast(HostFunctionError::FloatInputMalformed)); } { // hfs.floatRoot(makeSlice(float1), -2, 0); @@ -6037,16 +6072,16 @@ struct HostFuncImpl_test : public beast::unit_test::suite params, result, 0, - FLOAT_SIZE, + floatSize, -2, - 2 * FLOAT_SIZE, - FLOAT_SIZE, + 2 * floatSize, + floatSize, 0); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && BEAST_EXPECT( result[0].of.i32 == - static_cast(HostFunctionError::FLOAT_INPUT_MALFORMED)); + static_cast(HostFunctionError::FloatInputMalformed)); } { // hfs.floatRoot(makeSlice(floatIntZero), 2, 0); @@ -6058,14 +6093,14 @@ struct HostFuncImpl_test : public beast::unit_test::suite params, result, 0, - FLOAT_SIZE, + floatSize, 2, - 2 * FLOAT_SIZE, - FLOAT_SIZE, + 2 * floatSize, + floatSize, 0); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && - BEAST_EXPECT(result[0].of.i32 == FLOAT_SIZE); + BEAST_EXPECT(result[0].of.i32 == floatSize); auto const resultBytes = vrt.getBytes(params, 3); BEAST_EXPECT(resultBytes == floatIntZero); } @@ -6079,14 +6114,14 @@ struct HostFuncImpl_test : public beast::unit_test::suite params, result, 0, - FLOAT_SIZE, + floatSize, 1, - 2 * FLOAT_SIZE, - FLOAT_SIZE, + 2 * floatSize, + floatSize, 0); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && - BEAST_EXPECT(result[0].of.i32 == FLOAT_SIZE); + BEAST_EXPECT(result[0].of.i32 == floatSize); auto const resultBytes = vrt.getBytes(params, 3); BEAST_EXPECT(resultBytes == floatMaxIOU); } @@ -6104,14 +6139,14 @@ struct HostFuncImpl_test : public beast::unit_test::suite params, result, 0, - FLOAT_SIZE, + floatSize, 2, - 2 * FLOAT_SIZE, - FLOAT_SIZE, + 2 * floatSize, + floatSize, 0); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && - BEAST_EXPECT(result[0].of.i32 == FLOAT_SIZE); + BEAST_EXPECT(result[0].of.i32 == floatSize); auto const resultBytes = vrt.getBytes(params, 3); BEAST_EXPECT(resultBytes == float10); } @@ -6130,14 +6165,14 @@ struct HostFuncImpl_test : public beast::unit_test::suite params, result, 0, - FLOAT_SIZE, + floatSize, 3, - 2 * FLOAT_SIZE, - FLOAT_SIZE, + 2 * floatSize, + floatSize, 0); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && - BEAST_EXPECT(result[0].of.i32 == FLOAT_SIZE); + BEAST_EXPECT(result[0].of.i32 == floatSize); auto const resultBytes = vrt.getBytes(params, 3); BEAST_EXPECT(resultBytes == float10); } @@ -6157,14 +6192,14 @@ struct HostFuncImpl_test : public beast::unit_test::suite params, result, 0, - FLOAT_SIZE, + floatSize, 2, - 2 * FLOAT_SIZE, - FLOAT_SIZE, + 2 * floatSize, + floatSize, 0); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && - BEAST_EXPECT(result[0].of.i32 == FLOAT_SIZE); + BEAST_EXPECT(result[0].of.i32 == floatSize); auto const resultBytes = vrt.getBytes(params, 3); BEAST_EXPECT(resultBytes == *y); } @@ -6198,13 +6233,13 @@ struct HostFuncImpl_test : public beast::unit_test::suite 0, 2, 0, - FLOAT_SIZE, + floatSize, -1); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && BEAST_EXPECT( result[0].of.i32 == - static_cast(HostFunctionError::FLOAT_INPUT_MALFORMED)); + static_cast(HostFunctionError::FloatInputMalformed)); } { // hfs.floatPower(makeSlice(invalid), 3, 0); @@ -6218,14 +6253,14 @@ struct HostFuncImpl_test : public beast::unit_test::suite 0, invalid.size(), 3, - 2 * FLOAT_SIZE, - FLOAT_SIZE, + 2 * floatSize, + floatSize, 0); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && BEAST_EXPECT( result[0].of.i32 == - static_cast(HostFunctionError::FLOAT_INPUT_MALFORMED)); + static_cast(HostFunctionError::FloatInputMalformed)); } { // hfs.floatPower(makeSlice(float1), -2, 0); @@ -6237,16 +6272,16 @@ struct HostFuncImpl_test : public beast::unit_test::suite params, result, 0, - FLOAT_SIZE, + floatSize, -2, - 2 * FLOAT_SIZE, - FLOAT_SIZE, + 2 * floatSize, + floatSize, 0); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && BEAST_EXPECT( result[0].of.i32 == - static_cast(HostFunctionError::FLOAT_INPUT_MALFORMED)); + static_cast(HostFunctionError::FloatInputMalformed)); } { @@ -6259,16 +6294,16 @@ struct HostFuncImpl_test : public beast::unit_test::suite params, result, 0, - FLOAT_SIZE, + floatSize, 2, - FLOAT_SIZE, - FLOAT_SIZE, + floatSize, + floatSize, 0); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && BEAST_EXPECT( result[0].of.i32 == - static_cast(HostFunctionError::FLOAT_COMPUTATION_ERROR)); + static_cast(HostFunctionError::FloatComputationError)); } { @@ -6281,16 +6316,16 @@ struct HostFuncImpl_test : public beast::unit_test::suite params, result, 0, - FLOAT_SIZE, + floatSize, Number::maxExponent + 1, - FLOAT_SIZE, - FLOAT_SIZE, + floatSize, + floatSize, 0); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && BEAST_EXPECT( result[0].of.i32 == - static_cast(HostFunctionError::FLOAT_INPUT_MALFORMED)); + static_cast(HostFunctionError::FloatInputMalformed)); } { @@ -6303,14 +6338,14 @@ struct HostFuncImpl_test : public beast::unit_test::suite params, result, 0, - FLOAT_SIZE, + floatSize, 0, - FLOAT_SIZE, - FLOAT_SIZE, + floatSize, + floatSize, 0); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && - BEAST_EXPECT(result[0].of.i32 == FLOAT_SIZE); + BEAST_EXPECT(result[0].of.i32 == floatSize); auto const resultBytes = vrt.getBytes(params, 3); BEAST_EXPECT(resultBytes == float1); } @@ -6324,14 +6359,14 @@ struct HostFuncImpl_test : public beast::unit_test::suite params, result, 0, - FLOAT_SIZE, + floatSize, 1, - FLOAT_SIZE, - FLOAT_SIZE, + floatSize, + floatSize, 0); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && - BEAST_EXPECT(result[0].of.i32 == FLOAT_SIZE); + BEAST_EXPECT(result[0].of.i32 == floatSize); auto const resultBytes = vrt.getBytes(params, 3); BEAST_EXPECT(resultBytes == floatMaxIOU); } @@ -6349,14 +6384,14 @@ struct HostFuncImpl_test : public beast::unit_test::suite params, result, 0, - FLOAT_SIZE, + floatSize, 2, - 2 * FLOAT_SIZE, - FLOAT_SIZE, + 2 * floatSize, + floatSize, 0); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && - BEAST_EXPECT(result[0].of.i32 == FLOAT_SIZE); + BEAST_EXPECT(result[0].of.i32 == floatSize); auto const resultBytes = vrt.getBytes(params, 3); BEAST_EXPECT(resultBytes == *x); } @@ -6376,14 +6411,14 @@ struct HostFuncImpl_test : public beast::unit_test::suite params, result, 0, - FLOAT_SIZE, + floatSize, 2, - 2 * FLOAT_SIZE, - FLOAT_SIZE, + 2 * floatSize, + floatSize, 0); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && - BEAST_EXPECT(result[0].of.i32 == FLOAT_SIZE); + BEAST_EXPECT(result[0].of.i32 == floatSize); auto const resultBytes = vrt.getBytes(params, 3); BEAST_EXPECT(resultBytes == *y); } @@ -6441,13 +6476,13 @@ struct HostFuncImpl_test : public beast::unit_test::suite 0, amountBytes.size(), 256, - FLOAT_SIZE, + floatSize, -1); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && BEAST_EXPECT( result[0].of.i32 == - static_cast(HostFunctionError::FLOAT_INPUT_MALFORMED)); + static_cast(HostFunctionError::FloatInputMalformed)); } { @@ -6464,13 +6499,13 @@ struct HostFuncImpl_test : public beast::unit_test::suite 0, amountBytes.size(), 256, - FLOAT_SIZE, + floatSize, 4); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && BEAST_EXPECT( result[0].of.i32 == - static_cast(HostFunctionError::FLOAT_INPUT_MALFORMED)); + static_cast(HostFunctionError::FloatInputMalformed)); } { @@ -6487,11 +6522,11 @@ struct HostFuncImpl_test : public beast::unit_test::suite 0, amountBytes.size(), 256, - FLOAT_SIZE, + floatSize, 0); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && - BEAST_EXPECT(result[0].of.i32 == FLOAT_SIZE); + BEAST_EXPECT(result[0].of.i32 == floatSize); auto const resultBytes = vrt.getBytes(params, 2); BEAST_EXPECT(resultBytes == floatIntZero); } @@ -6513,11 +6548,11 @@ struct HostFuncImpl_test : public beast::unit_test::suite 0, amountBytes.size(), 256, - FLOAT_SIZE, + floatSize, 0); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && - BEAST_EXPECT(result[0].of.i32 == FLOAT_SIZE); + BEAST_EXPECT(result[0].of.i32 == floatSize); auto const resultBytes = vrt.getBytes(params, 2); BEAST_EXPECT(resultBytes == *y); } @@ -6538,11 +6573,11 @@ struct HostFuncImpl_test : public beast::unit_test::suite 0, amountBytes.size(), 256, - FLOAT_SIZE, + floatSize, 0); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && - BEAST_EXPECT(result[0].of.i32 == FLOAT_SIZE); + BEAST_EXPECT(result[0].of.i32 == floatSize); auto const resultBytes = vrt.getBytes(params, 2); BEAST_EXPECT(resultBytes == *y); } @@ -6562,7 +6597,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite BEAST_EXPECT(ex); } - auto const USD = env.master["USD"]; + auto const usd = env.master["USD"]; { // hfs.floatFromSTAmount(amount, 0); STAmount const amount( @@ -6578,11 +6613,11 @@ struct HostFuncImpl_test : public beast::unit_test::suite 0, amountBytes.size(), 256, - FLOAT_SIZE, + floatSize, 0); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && - BEAST_EXPECT(result[0].of.i32 == FLOAT_SIZE); + BEAST_EXPECT(result[0].of.i32 == floatSize); auto const resultBytes = vrt.getBytes(params, 2); BEAST_EXPECT(resultBytes == floatMinIOU); } @@ -6602,11 +6637,11 @@ struct HostFuncImpl_test : public beast::unit_test::suite 0, amountBytes.size(), 256, - FLOAT_SIZE, + floatSize, 0); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && - BEAST_EXPECT(result[0].of.i32 == FLOAT_SIZE); + BEAST_EXPECT(result[0].of.i32 == floatSize); auto const resultBytes = vrt.getBytes(params, 2); BEAST_EXPECT(resultBytes == floatMaxIOU); } @@ -6643,13 +6678,13 @@ struct HostFuncImpl_test : public beast::unit_test::suite 0, numBytes.size(), 256, - FLOAT_SIZE, + floatSize, -1); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && BEAST_EXPECT( result[0].of.i32 == - static_cast(HostFunctionError::FLOAT_INPUT_MALFORMED)); + static_cast(HostFunctionError::FloatInputMalformed)); } { @@ -6666,13 +6701,13 @@ struct HostFuncImpl_test : public beast::unit_test::suite 0, numBytes.size(), 256, - FLOAT_SIZE, + floatSize, 4); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && BEAST_EXPECT( result[0].of.i32 == - static_cast(HostFunctionError::FLOAT_INPUT_MALFORMED)); + static_cast(HostFunctionError::FloatInputMalformed)); } { @@ -6690,11 +6725,11 @@ struct HostFuncImpl_test : public beast::unit_test::suite 0, numBytes.size(), 256, - FLOAT_SIZE, + floatSize, 0); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && - BEAST_EXPECT(result[0].of.i32 == FLOAT_SIZE); + BEAST_EXPECT(result[0].of.i32 == floatSize); auto const resultBytes = vrt.getBytes(params, 2); BEAST_EXPECT(resultBytes == floatUIntMax); } @@ -6713,11 +6748,11 @@ struct HostFuncImpl_test : public beast::unit_test::suite 0, numBytes.size(), 256, - FLOAT_SIZE, + floatSize, 0); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && - BEAST_EXPECT(result[0].of.i32 == FLOAT_SIZE); + BEAST_EXPECT(result[0].of.i32 == floatSize); auto const resultBytes = vrt.getBytes(params, 2); BEAST_EXPECT(resultBytes == floatMinusMaxExp); } @@ -6749,7 +6784,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite params, result, 0, - FLOAT_SIZE, + floatSize, 256, 8, -1); @@ -6757,7 +6792,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && BEAST_EXPECT( result[0].of.i32 == - static_cast(HostFunctionError::FLOAT_INPUT_MALFORMED)); + static_cast(HostFunctionError::FloatInputMalformed)); } { @@ -6770,7 +6805,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite params, result, 0, - FLOAT_SIZE, + floatSize, 256, 8, 4); @@ -6778,7 +6813,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && BEAST_EXPECT( result[0].of.i32 == - static_cast(HostFunctionError::FLOAT_INPUT_MALFORMED)); + static_cast(HostFunctionError::FloatInputMalformed)); } { @@ -6790,7 +6825,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && BEAST_EXPECT( result[0].of.i32 == - static_cast(HostFunctionError::FLOAT_INPUT_MALFORMED)); + static_cast(HostFunctionError::FloatInputMalformed)); } { @@ -6803,7 +6838,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite params, result, 0, - FLOAT_SIZE, + floatSize, 256, 8, 0); @@ -6811,7 +6846,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && BEAST_EXPECT( result[0].of.i32 == - static_cast(HostFunctionError::FLOAT_INPUT_MALFORMED)); + static_cast(HostFunctionError::FloatInputMalformed)); } { @@ -6824,7 +6859,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite params, result, 0, - FLOAT_SIZE, + floatSize, 256, 8, 0); @@ -6849,7 +6884,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite params, result, 0, - FLOAT_SIZE, + floatSize, 256, 8, 0); @@ -6874,7 +6909,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite params, result, 0, - FLOAT_SIZE, + floatSize, 256, 8, 0); @@ -6899,7 +6934,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite params, result, 0, - FLOAT_SIZE, + floatSize, 256, 8, 0); @@ -6926,7 +6961,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite params, result, 0, - FLOAT_SIZE, + floatSize, 256, 8, 0); @@ -6934,7 +6969,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && BEAST_EXPECT( result[0].of.i32 == - static_cast(HostFunctionError::FLOAT_COMPUTATION_ERROR)); + static_cast(HostFunctionError::FloatComputationError)); } { @@ -6947,7 +6982,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite params, result, 0, - FLOAT_SIZE, + floatSize, 256, 8, 0); @@ -6955,7 +6990,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && BEAST_EXPECT( result[0].of.i32 == - static_cast(HostFunctionError::FLOAT_COMPUTATION_ERROR)); + static_cast(HostFunctionError::FloatComputationError)); } // Test rounding modes with pi (3.141592653589793) @@ -6970,7 +7005,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite params, result, 0, - FLOAT_SIZE, + floatSize, 256, 8, 0); @@ -6992,7 +7027,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite params, result, 0, - FLOAT_SIZE, + floatSize, 256, 8, 1); @@ -7014,7 +7049,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite params, result, 0, - FLOAT_SIZE, + floatSize, 256, 8, 2); @@ -7036,7 +7071,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite params, result, 0, - FLOAT_SIZE, + floatSize, 256, 8, 3); @@ -7074,7 +7109,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite params, result, 0, - FLOAT_SIZE, + floatSize, 256, 8, 512, @@ -7083,7 +7118,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && BEAST_EXPECT( result[0].of.i32 == - static_cast(HostFunctionError::FLOAT_INPUT_MALFORMED)); + static_cast(HostFunctionError::FloatInputMalformed)); } { @@ -7096,14 +7131,14 @@ struct HostFuncImpl_test : public beast::unit_test::suite params, result, 0, - FLOAT_SIZE, + floatSize, 256, 8, 512, 4); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && - BEAST_EXPECT(result[0].of.i32 == FLOAT_SIZE); + BEAST_EXPECT(result[0].of.i32 == floatSize); auto const mantissa = vrt.getInt64(params, 2); auto const exponent = vrt.getInt32(params, 4); BEAST_EXPECT(mantissa == 0) && @@ -7124,14 +7159,14 @@ struct HostFuncImpl_test : public beast::unit_test::suite params, result, 0, - FLOAT_SIZE, + floatSize, 256, 8, 512, 4); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && - BEAST_EXPECT(result[0].of.i32 == FLOAT_SIZE); + BEAST_EXPECT(result[0].of.i32 == floatSize); auto const mantissa = vrt.getInt64(params, 2); auto const exponent = vrt.getInt32(params, 4); BEAST_EXPECT(mantissa == 1000000000000000000) && BEAST_EXPECT(exponent == -normalExp); @@ -7151,14 +7186,14 @@ struct HostFuncImpl_test : public beast::unit_test::suite params, result, 0, - FLOAT_SIZE, + floatSize, 256, 8, 512, 4); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && - BEAST_EXPECT(result[0].of.i32 == FLOAT_SIZE); + BEAST_EXPECT(result[0].of.i32 == floatSize); auto const mantissa = vrt.getInt64(params, 2); auto const exponent = vrt.getInt32(params, 4); BEAST_EXPECT(mantissa == -1000000000000000000) && BEAST_EXPECT(exponent == -normalExp); @@ -7178,14 +7213,14 @@ struct HostFuncImpl_test : public beast::unit_test::suite params, result, 0, - FLOAT_SIZE, + floatSize, 256, 8, 512, 4); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && - BEAST_EXPECT(result[0].of.i32 == FLOAT_SIZE); + BEAST_EXPECT(result[0].of.i32 == floatSize); auto const mantissa = vrt.getInt64(params, 2); auto const exponent = vrt.getInt32(params, 4); BEAST_EXPECT(mantissa == 1000000000000000000) && @@ -7206,14 +7241,14 @@ struct HostFuncImpl_test : public beast::unit_test::suite params, result, 0, - FLOAT_SIZE, + floatSize, 256, 8, 512, 4); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && - BEAST_EXPECT(result[0].of.i32 == FLOAT_SIZE); + BEAST_EXPECT(result[0].of.i32 == floatSize); auto const mantissa = vrt.getInt64(params, 2); auto const exponent = vrt.getInt32(params, 4); BEAST_EXPECT(mantissa == 3141592653589793000) && BEAST_EXPECT(exponent == -normalExp); @@ -7233,14 +7268,14 @@ struct HostFuncImpl_test : public beast::unit_test::suite params, result, 0, - FLOAT_SIZE, + floatSize, 256, 8, 512, 4); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && - BEAST_EXPECT(result[0].of.i32 == FLOAT_SIZE); + BEAST_EXPECT(result[0].of.i32 == floatSize); auto const mantissa = vrt.getInt64(params, 2); auto const exponent = vrt.getInt32(params, 4); BEAST_EXPECT(mantissa == std::numeric_limits::max()) && @@ -7261,14 +7296,14 @@ struct HostFuncImpl_test : public beast::unit_test::suite params, result, 0, - FLOAT_SIZE, + floatSize, 256, 8, 512, 4); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && - BEAST_EXPECT(result[0].of.i32 == FLOAT_SIZE); + BEAST_EXPECT(result[0].of.i32 == floatSize); auto const mantissa = vrt.getInt64(params, 2); auto const exponent = vrt.getInt32(params, 4); BEAST_EXPECT(mantissa == (std::numeric_limits::min() / 10) - 1) && @@ -7289,14 +7324,14 @@ struct HostFuncImpl_test : public beast::unit_test::suite params, result, 0, - FLOAT_SIZE, + floatSize, 256, 8, 512, 4); BEAST_EXPECT(!trap) && BEAST_EXPECT(result[0].kind == WASM_I32) && - BEAST_EXPECT(result[0].of.i32 == FLOAT_SIZE); + 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) && @@ -7432,5 +7467,4 @@ struct HostFuncImpl_test : public beast::unit_test::suite BEAST_DEFINE_TESTSUITE(HostFuncImpl, app, xrpl); -} // namespace test -} // namespace xrpl +} // namespace xrpl::test diff --git a/src/test/app/TestHostFunctions.h b/src/test/app/TestHostFunctions.h index 1a0d640522..524a3e3379 100644 --- a/src/test/app/TestHostFunctions.h +++ b/src/test/app/TestHostFunctions.h @@ -8,36 +8,34 @@ #include #include -namespace xrpl { - -namespace test { +namespace xrpl::test { struct TestLedgerDataProvider : public HostFunctions { - jtx::Env& env_; - void* rt_ = nullptr; + jtx::Env& env; + void* rt = nullptr; public: - TestLedgerDataProvider(jtx::Env& env) : HostFunctions(env.journal), env_(env) + TestLedgerDataProvider(jtx::Env& env) : HostFunctions(env.journal), env(env) { } - virtual void + void setRT(void* rt) override { - rt_ = rt; + rt = rt; } - virtual void* + [[nodiscard]] void* getRT() const override { - return rt_; + return rt; } Expected getLedgerSqn() const override { - return env_.current()->seq(); + return env.current()->seq(); } }; @@ -46,28 +44,28 @@ struct TestHostFunctions : public HostFunctions test::jtx::Env& env_; AccountID accountID_; Bytes data_; - int clock_drift_ = 0; - void* rt_ = nullptr; + 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(); std::string t = "10000"; data_ = Bytes{t.begin(), t.end()}; } - virtual void + void setRT(void* rt) override { - rt_ = rt; + rt = rt; } - virtual void* + [[nodiscard]] void* getRT() const override { - return rt_; + return rt; } Expected @@ -106,7 +104,7 @@ public: return 1; } - virtual Expected + Expected cacheLedgerObj(uint256 const& objId, int32_t cacheIdx) override { return 1; @@ -116,8 +114,10 @@ public: getTxField(SField const& fname) const override { if (fname == sfAccount) + { return Bytes(accountID_.begin(), accountID_.end()); - else if (fname == sfFee) + } + if (fname == sfFee) { int64_t x = 235; uint8_t const* p = reinterpret_cast(&x); @@ -141,8 +141,10 @@ public: { auto const& sn = fname.getName(); if (sn == "Destination" || sn == "Account") + { return Bytes(accountID_.begin(), accountID_.end()); - else if (sn == "Data") + } + if (sn == "Data") return data_; else if (sn == "FinishAfter") { @@ -163,7 +165,7 @@ public: uint8_t const* p = reinterpret_cast(&x); return Bytes{p, p + sizeof(x)}; } - else if (fname == sfAccount) + if (fname == sfAccount) { return Bytes(accountID_.begin(), accountID_.end()); } @@ -282,7 +284,7 @@ public: accountKeylet(AccountID const& account) const override { if (!account) - return Unexpected(HostFunctionError::INVALID_ACCOUNT); + return Unexpected(HostFunctionError::InvalidAccount); auto const keylet = keylet::account(account); return Bytes{keylet.key.begin(), keylet.key.end()}; } @@ -291,9 +293,9 @@ public: ammKeylet(Asset const& issue1, Asset const& issue2) const override { if (issue1 == issue2) - return Unexpected(HostFunctionError::INVALID_PARAMS); + return Unexpected(HostFunctionError::InvalidParams); if (issue1.holds() || issue2.holds()) - return Unexpected(HostFunctionError::INVALID_PARAMS); + return Unexpected(HostFunctionError::InvalidParams); auto const keylet = keylet::amm(issue1, issue2); return Bytes{keylet.key.begin(), keylet.key.end()}; } @@ -302,7 +304,7 @@ public: checkKeylet(AccountID const& account, std::uint32_t seq) const override { if (!account) - return Unexpected(HostFunctionError::INVALID_ACCOUNT); + return Unexpected(HostFunctionError::InvalidAccount); auto const keylet = keylet::check(account, seq); return Bytes{keylet.key.begin(), keylet.key.end()}; } @@ -312,8 +314,8 @@ public: const override { if (!subject || !issuer || credentialType.empty() || - credentialType.size() > maxCredentialTypeLength) - return Unexpected(HostFunctionError::INVALID_ACCOUNT); + credentialType.size() > kMaxCredentialTypeLength) + return Unexpected(HostFunctionError::InvalidAccount); auto const keylet = keylet::credential(subject, issuer, credentialType); return Bytes{keylet.key.begin(), keylet.key.end()}; } @@ -322,7 +324,7 @@ public: escrowKeylet(AccountID const& account, std::uint32_t seq) const override { if (!account) - return Unexpected(HostFunctionError::INVALID_ACCOUNT); + return Unexpected(HostFunctionError::InvalidAccount); auto const keylet = keylet::escrow(account, seq); return Bytes{keylet.key.begin(), keylet.key.end()}; } @@ -331,7 +333,7 @@ public: oracleKeylet(AccountID const& account, std::uint32_t documentId) const override { if (!account) - return Unexpected(HostFunctionError::INVALID_ACCOUNT); + return Unexpected(HostFunctionError::InvalidAccount); auto const keylet = keylet::oracle(account, documentId); return Bytes{keylet.key.begin(), keylet.key.end()}; } @@ -341,7 +343,7 @@ public: { if (!account || !nftId) { - return Unexpected(HostFunctionError::INVALID_PARAMS); + return Unexpected(HostFunctionError::InvalidParams); } std::string s = "https://ripple.com"; @@ -476,7 +478,7 @@ public: return wasm_float::floatToIntImpl(x, mode); } - virtual Expected + Expected floatToMantExp(Slice const& x) const override { return wasm_float::floatToMantExpImpl(x); @@ -533,22 +535,21 @@ public: struct TestHostFunctionsSink : public TestHostFunctions { - test::StreamSink sink_; - void const* rt_ = nullptr; + test::StreamSink sink; + void const* rt = nullptr; public: explicit TestHostFunctionsSink(test::jtx::Env& env, int cd = 0) : TestHostFunctions(env, cd), sink_(beast::severities::kDebug) { - j_ = beast::Journal(sink_); + j = beast::Journal(sink); } test::StreamSink& getSink() { - return sink_; + return sink; } }; -} // namespace test -} // namespace xrpl +} // namespace xrpl::test diff --git a/src/test/app/Wasm_test.cpp b/src/test/app/Wasm_test.cpp index 1140de9293..37a91c6778 100644 --- a/src/test/app/Wasm_test.cpp +++ b/src/test/app/Wasm_test.cpp @@ -1,27 +1,49 @@ +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #ifdef _DEBUG // #define DEBUG_OUTPUT 1 #endif #include -#include - #include -namespace xrpl { -namespace test { +namespace xrpl::test { bool testGetDataIncrement(); using Add_proto = int32_t(int32_t, int32_t); static wasm_trap_t* -Add(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results) +add(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results) { - int32_t const Val1 = params->data[0].of.i32; - int32_t const Val2 = params->data[1].of.i32; + int32_t const val1 = params->data[0].of.i32; + int32_t const val2 = params->data[1].of.i32; // printf("Host function \"Add\": %d + %d\n", Val1, Val2); - results->data[0] = WASM_I32_VAL(Val1 + Val2); + results->data[0] = WASM_I32_VAL(val1 + val2); return nullptr; } @@ -76,27 +98,27 @@ uleb128(IT&& it) std::pair getSection(Bytes const& module, std::uint8_t n) { - static std::uint8_t const hdr[] = {0x00, 0x61, 0x73, 0x6D}; - static std::uint8_t const ver[] = {0x01, 0x00, 0x00, 0x00}; - static std::uint8_t const lastSec = 12; + static std::uint8_t const kHdr[] = {0x00, 0x61, 0x73, 0x6D}; + static std::uint8_t const kVer[] = {0x01, 0x00, 0x00, 0x00}; + static std::uint8_t const kLastSec = 12; // sections: // 0: "Custom", 1: "Type", 2: "Import", 3: "Function", 4: "Table", 5: "Memory", 6: "Global", // 7: "Export", 8: "Start", 9: "Element", 10: "Code", 11: "Data", 12: "DataCount" - if (module.size() < sizeof(hdr) + sizeof(ver) + 2) + if (module.size() < sizeof(kHdr) + sizeof(kVer) + 2) return {0, 0}; - if (memcmp(module.data(), hdr, sizeof(hdr)) != 0) + if (memcmp(module.data(), kHdr, sizeof(kHdr)) != 0) return {0, 0}; - if (memcmp(module.data() + sizeof(hdr), ver, sizeof(ver)) != 0) + if (memcmp(module.data() + sizeof(kHdr), kVer, sizeof(kVer)) != 0) return {0, 0}; - unsigned pos = sizeof(hdr) + sizeof(ver); // sections start + unsigned pos = sizeof(kHdr) + sizeof(kVer); // sections start for (; pos < module.size();) { auto const start = pos; std::uint8_t const byte = module[pos++]; - if (byte > lastSec) + if (byte > kLastSec) return {0, 0}; auto [sz, cnt] = uleb128(module.cbegin() + pos); @@ -127,7 +149,7 @@ runFinishFunction(std::string const& code) return std::nullopt; } -struct Wasm_test : public beast::unit_test::suite +struct Wasm_test : public beast::unit_test::Suite { void checkResult( @@ -188,7 +210,7 @@ struct Wasm_test : public beast::unit_test::suite HostFunctions hfs; ImportVec imports; - WasmImpFunc(imports, "func-add", reinterpret_cast(&Add), &hfs); + WasmImpFunc(imports, "func-add", reinterpret_cast(&add), &hfs); auto re = vm.run(wasm, hfs, 10'000'000, "addTwo", wasmParams(1234, 5678), imports); @@ -240,7 +262,7 @@ struct Wasm_test : public beast::unit_test::suite "732b087369676e2d6578742b0f7265666572656e63652d74797065732b0a" "6d756c746976616c7565"); - auto const re = preflightEscrowWasm(badWasm, hfs, ESCROW_FUNCTION_NAME); + auto const re = preflightEscrowWasm(badWasm, hfs, escrowFunctionName); BEAST_EXPECT(!isTesSuccess(re)); } } @@ -250,7 +272,7 @@ struct Wasm_test : public beast::unit_test::suite { testcase("Wasm get ledger sequence"); - auto ledgerSqnWasm = hexToBytes(ledgerSqnWasmHex); + auto ledgerSqnWasm = hexToBytes(kLedgerSqnWasmHex); using namespace test::jtx; @@ -260,8 +282,8 @@ struct Wasm_test : public beast::unit_test::suite WASM_IMPORT_FUNC2(imports, getLedgerSqn, "get_ledger_sqn", &hfs, 33); auto& engine = WasmEngine::instance(); - auto re = engine.run( - ledgerSqnWasm, hfs, 1'000'000, ESCROW_FUNCTION_NAME, {}, imports, env.journal); + auto re = + engine.run(ledgerSqnWasm, hfs, 1'000'000, escrowFunctionName, {}, imports, env.journal); checkResult(re, 0, 440); @@ -269,7 +291,7 @@ struct Wasm_test : public beast::unit_test::suite env.close(); // empty module, throwing exception - re = engine.run({}, hfs, 1'000'000, ESCROW_FUNCTION_NAME, {}, imports, env.journal); + re = engine.run({}, hfs, 1'000'000, escrowFunctionName, {}, imports, env.journal); BEAST_EXPECT(!re); env.close(); } @@ -279,7 +301,7 @@ struct Wasm_test : public beast::unit_test::suite { testcase("Wasm import/export functions"); - auto impExpWasm = hexToBytes(impExpHex); + auto impExpWasm = hexToBytes(kImpExpHex); using namespace test::jtx; @@ -344,7 +366,7 @@ struct Wasm_test : public beast::unit_test::suite { testcase("Wasm fibo"); - auto const fibWasm = hexToBytes(fibWasmHex); + auto const fibWasm = hexToBytes(kFibWasmHex); auto& engine = WasmEngine::instance(); HostFunctions hfs; @@ -362,7 +384,7 @@ struct Wasm_test : public beast::unit_test::suite Env env(*this); { - auto const allHostFuncWasm = hexToBytes(allHostFunctionsWasmHex); + auto const allHostFuncWasm = hexToBytes(kAllHostFunctionsWasmHex); auto& engine = WasmEngine::instance(); @@ -372,7 +394,7 @@ struct Wasm_test : public beast::unit_test::suite i.second.second.gas = 0; auto re = engine.run( - allHostFuncWasm, hfs, 1'000'000, ESCROW_FUNCTION_NAME, {}, imp, env.journal); + allHostFuncWasm, hfs, 1'000'000, escrowFunctionName, {}, imp, env.journal); checkResult(re, 1, 27'080); @@ -386,7 +408,7 @@ struct Wasm_test : public beast::unit_test::suite env.close(); { - auto const allHostFuncWasm = hexToBytes(allHostFunctionsWasmHex); + auto const allHostFuncWasm = hexToBytes(kAllHostFunctionsWasmHex); auto& engine = WasmEngine::instance(); @@ -394,7 +416,7 @@ struct Wasm_test : public beast::unit_test::suite auto const imp = createWasmImport(hfs); auto re = engine.run( - allHostFuncWasm, hfs, 1'000'000, ESCROW_FUNCTION_NAME, {}, imp, env.journal); + allHostFuncWasm, hfs, 1'000'000, escrowFunctionName, {}, imp, env.journal); checkResult(re, 1, 70'340); @@ -403,7 +425,7 @@ struct Wasm_test : public beast::unit_test::suite // not enough gas { - auto const allHostFuncWasm = hexToBytes(allHostFunctionsWasmHex); + auto const allHostFuncWasm = hexToBytes(kAllHostFunctionsWasmHex); auto& engine = WasmEngine::instance(); @@ -411,7 +433,7 @@ struct Wasm_test : public beast::unit_test::suite auto const imp = createWasmImport(hfs); auto re = - engine.run(allHostFuncWasm, hfs, 200, ESCROW_FUNCTION_NAME, {}, imp, env.journal); + engine.run(allHostFuncWasm, hfs, 200, escrowFunctionName, {}, imp, env.journal); if (BEAST_EXPECT(!re)) { @@ -428,20 +450,20 @@ struct Wasm_test : public beast::unit_test::suite { testcase("escrow wasm devnet test"); - auto const allHFWasm = hexToBytes(allHostFunctionsWasmHex); + auto const allHFWasm = hexToBytes(kAllHostFunctionsWasmHex); using namespace test::jtx; Env env{*this}; { TestHostFunctions hfs(env, 0); - auto re = runEscrowWasm(allHFWasm, hfs, 100'000, ESCROW_FUNCTION_NAME, {}); + auto re = runEscrowWasm(allHFWasm, hfs, 100'000, escrowFunctionName, {}); checkResult(re, 1, 70'340); } { // Invalid gas limit (0) should be rejected (boundary condition) TestHostFunctions hfs(env, 0); - auto re = runEscrowWasm(allHFWasm, hfs, -1, ESCROW_FUNCTION_NAME, {}); + auto re = runEscrowWasm(allHFWasm, hfs, -1, escrowFunctionName, {}); BEAST_EXPECT(!re.has_value()); BEAST_EXPECT(re.error() == temBAD_AMOUNT); } @@ -449,7 +471,7 @@ struct Wasm_test : public beast::unit_test::suite { // Invalid gas limit (-1) should be rejected TestHostFunctions hfs(env, 0); - auto re = runEscrowWasm(allHFWasm, hfs, 0, ESCROW_FUNCTION_NAME, {}); + auto re = runEscrowWasm(allHFWasm, hfs, 0, escrowFunctionName, {}); BEAST_EXPECT(!re.has_value()); BEAST_EXPECT(re.error() == temBAD_AMOUNT); } @@ -458,7 +480,7 @@ struct Wasm_test : public beast::unit_test::suite // max() gas TestHostFunctions hfs(env, 0); auto re = runEscrowWasm( - allHFWasm, hfs, std::numeric_limits::max(), ESCROW_FUNCTION_NAME, {}); + allHFWasm, hfs, std::numeric_limits::max(), escrowFunctionName, {}); checkResult(re, 1, 70'340); } @@ -471,12 +493,12 @@ struct Wasm_test : public beast::unit_test::suite Expected getTxField(SField const& fname) const override { - return Unexpected(HostFunctionError::FIELD_NOT_FOUND); + return Unexpected(HostFunctionError::FieldNotFound); } }; FieldNotFoundHostFunctions hfs(env); - auto re = runEscrowWasm(allHFWasm, hfs, 100'000, ESCROW_FUNCTION_NAME, {}); + auto re = runEscrowWasm(allHFWasm, hfs, 100'000, escrowFunctionName, {}); checkResult(re, -201, 28'965); } @@ -494,7 +516,7 @@ struct Wasm_test : public beast::unit_test::suite }; OversizedFieldHostFunctions hfs(env); - auto re = runEscrowWasm(allHFWasm, hfs, 100'000, ESCROW_FUNCTION_NAME, {}); + auto re = runEscrowWasm(allHFWasm, hfs, 100'000, escrowFunctionName, {}); checkResult(re, -201, 28'965); } @@ -502,7 +524,7 @@ struct Wasm_test : public beast::unit_test::suite #ifndef DEBUG_OUTPUT { // fail because recursion too deep - auto const deepWasm = hexToBytes(deepRecursionHex); + auto const deepWasm = hexToBytes(kDeepRecursionHex); TestHostFunctionsSink hfs(env); std::string const funcName("finish"); @@ -530,7 +552,7 @@ struct Wasm_test : public beast::unit_test::suite #endif { // infinite loop - auto const infiniteLoopWasm = hexToBytes(infiniteLoopWasmHex); + auto const infiniteLoopWasm = hexToBytes(kInfiniteLoopWasmHex); std::string const funcName("loop"); TestHostFunctions hfs(env, 0); @@ -544,7 +566,7 @@ struct Wasm_test : public beast::unit_test::suite { // expected import not provided - auto const lgrSqnWasm = hexToBytes(ledgerSqnWasmHex); + auto const lgrSqnWasm = hexToBytes(kLedgerSqnWasmHex); TestLedgerDataProvider hfs(env); ImportVec imports; WASM_IMPORT_FUNC2(imports, getLedgerSqn, "get_ledger_sqn2", &hfs); @@ -552,14 +574,14 @@ struct Wasm_test : public beast::unit_test::suite auto& engine = WasmEngine::instance(); auto re = engine.run( - lgrSqnWasm, hfs, 1'000'000, ESCROW_FUNCTION_NAME, {}, imports, env.journal); + lgrSqnWasm, hfs, 1'000'000, escrowFunctionName, {}, imports, env.journal); BEAST_EXPECT(!re); } { // bad import format - auto const lgrSqnWasm = hexToBytes(ledgerSqnWasmHex); + auto const lgrSqnWasm = hexToBytes(kLedgerSqnWasmHex); TestLedgerDataProvider hfs(env); ImportVec imports; WASM_IMPORT_FUNC2(imports, getLedgerSqn, "get_ledger_sqn", &hfs); @@ -568,14 +590,14 @@ struct Wasm_test : public beast::unit_test::suite auto& engine = WasmEngine::instance(); auto re = engine.run( - lgrSqnWasm, hfs, 1'000'000, ESCROW_FUNCTION_NAME, {}, imports, env.journal); + lgrSqnWasm, hfs, 1'000'000, escrowFunctionName, {}, imports, env.journal); BEAST_EXPECT(!re); } { // bad function name - auto const lgrSqnWasm = hexToBytes(ledgerSqnWasmHex); + auto const lgrSqnWasm = hexToBytes(kLedgerSqnWasmHex); TestLedgerDataProvider hfs(env); ImportVec imports; WASM_IMPORT_FUNC2(imports, getLedgerSqn, "get_ledger_sqn", &hfs); @@ -598,7 +620,7 @@ struct Wasm_test : public beast::unit_test::suite Env env(*this); { - auto const floatTestWasm = hexToBytes(floatTestsWasmHex); + auto const floatTestWasm = hexToBytes(kFloatTestsWasmHex); TestHostFunctions hfs(env, 0); auto re = runEscrowWasm(floatTestWasm, hfs, 200'000, funcName, {}); @@ -607,7 +629,7 @@ struct Wasm_test : public beast::unit_test::suite } { - auto const float0Wasm = hexToBytes(float0Hex); + auto const float0Wasm = hexToBytes(kFloat0Hex); TestHostFunctions hfs(env, 0); auto re = runEscrowWasm(float0Wasm, hfs, 100'000, funcName, {}); @@ -625,11 +647,11 @@ struct Wasm_test : public beast::unit_test::suite Env env{*this}; - auto const codecovWasm = hexToBytes(codecovTestsWasmHex); + auto const codecovWasm = hexToBytes(kCodecovTestsWasmHex); TestHostFunctions hfs(env, 0); auto const allowance = 220'169; - auto re = runEscrowWasm(codecovWasm, hfs, allowance, ESCROW_FUNCTION_NAME, {}); + auto re = runEscrowWasm(codecovWasm, hfs, allowance, escrowFunctionName, {}); checkResult(re, 1, allowance); } @@ -642,7 +664,7 @@ struct Wasm_test : public beast::unit_test::suite using namespace test::jtx; Env env{*this}; - auto disabledFloatWasm = hexToBytes(disabledFloatHex); + auto disabledFloatWasm = hexToBytes(kDisabledFloatHex); std::string const funcName("finish"); TestHostFunctions hfs(env, 0); @@ -670,82 +692,82 @@ struct Wasm_test : public beast::unit_test::suite testWasmMemory() { testcase("Wasm additional memory limit tests"); - BEAST_EXPECT(runFinishFunction(memoryPointerAtLimitHex).value() == 1); - BEAST_EXPECT(runFinishFunction(memoryPointerOverLimitHex).has_value() == false); - BEAST_EXPECT(runFinishFunction(memoryOffsetOverLimitHex).has_value() == false); - BEAST_EXPECT(runFinishFunction(memoryEndOfWordOverLimitHex).has_value() == false); - BEAST_EXPECT(runFinishFunction(memoryGrow0To1PageHex).value() == 1); - BEAST_EXPECT(runFinishFunction(memoryGrow1To0PageHex).value() == -1); - BEAST_EXPECT(runFinishFunction(memoryLastByteOf8MBHex).value() == 1); - BEAST_EXPECT(runFinishFunction(memoryGrow1MoreThan8MBHex).value() == -1); - BEAST_EXPECT(runFinishFunction(memoryGrow0MoreThan8MBHex).value() == 1); - BEAST_EXPECT(runFinishFunction(memoryInit1MoreThan8MBHex).has_value() == false); - BEAST_EXPECT(runFinishFunction(memoryNegativeAddressHex).has_value() == false); + 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); } void testWasmTable() { testcase("Wasm table limit tests"); - BEAST_EXPECT(runFinishFunction(table64ElementsHex).value() == 1); - BEAST_EXPECT(runFinishFunction(table65ElementsHex).has_value() == false); - BEAST_EXPECT(runFinishFunction(table2TablesHex).has_value() == false); - BEAST_EXPECT(runFinishFunction(table0ElementsHex).value() == 1); - BEAST_EXPECT(runFinishFunction(tableUintMaxHex).has_value() == false); + 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); } void testWasmProposal() { testcase("Wasm disabled proposal tests"); - BEAST_EXPECT(runFinishFunction(proposalMutableGlobalHex).has_value() == false); - BEAST_EXPECT(runFinishFunction(proposalGcStructNewHex).has_value() == false); - BEAST_EXPECT(runFinishFunction(proposalMultiValueHex).has_value() == false); - BEAST_EXPECT(runFinishFunction(proposalSignExtHex).has_value() == false); - BEAST_EXPECT(runFinishFunction(proposalFloatToIntHex).has_value() == false); - BEAST_EXPECT(runFinishFunction(proposalBulkMemoryHex).has_value() == false); - BEAST_EXPECT(runFinishFunction(proposalRefTypesHex).has_value() == false); - BEAST_EXPECT(runFinishFunction(proposalTailCallHex).has_value() == false); - BEAST_EXPECT(runFinishFunction(proposalExtendedConstHex).has_value() == false); - BEAST_EXPECT(runFinishFunction(proposalMultiMemoryHex).has_value() == false); - BEAST_EXPECT(runFinishFunction(proposalCustomPageSizesHex).has_value() == false); - BEAST_EXPECT(runFinishFunction(proposalMemory64Hex).has_value() == false); - BEAST_EXPECT(runFinishFunction(proposalWideArithmeticHex).has_value() == false); + 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); } void testWasmTrap() { testcase("Wasm trap tests"); - BEAST_EXPECT(runFinishFunction(trapDivideBy0Hex).has_value() == false); - BEAST_EXPECT(runFinishFunction(trapIntOverflowHex).has_value() == false); - BEAST_EXPECT(runFinishFunction(trapUnreachableHex).has_value() == false); - BEAST_EXPECT(runFinishFunction(trapNullCallHex).has_value() == false); - BEAST_EXPECT(runFinishFunction(trapFuncSigMismatchHex).has_value() == false); + 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); } void testWasmWasi() { testcase("Wasm Wasi tests"); - BEAST_EXPECT(runFinishFunction(wasiGetTimeHex).has_value() == false); - BEAST_EXPECT(runFinishFunction(wasiPrintHex).has_value() == false); + BEAST_EXPECT(runFinishFunction(kWasiGetTimeHex).has_value() == false); + BEAST_EXPECT(runFinishFunction(kWasiPrintHex).has_value() == false); } void testWasmSectionCorruption() { testcase("Wasm Section Corruption tests"); - BEAST_EXPECT(runFinishFunction(badMagicNumberHex).has_value() == false); - BEAST_EXPECT(runFinishFunction(badVersionNumberHex).has_value() == false); - BEAST_EXPECT(runFinishFunction(lyingHeaderHex).has_value() == false); - BEAST_EXPECT(runFinishFunction(neverEndingNumberHex).has_value() == false); - BEAST_EXPECT(runFinishFunction(vectorLieHex).has_value() == false); - BEAST_EXPECT(runFinishFunction(sectionOrderingHex).has_value() == false); - BEAST_EXPECT(runFinishFunction(ghostPayloadHex).has_value() == false); - BEAST_EXPECT(runFinishFunction(junkAfterSectionHex).has_value() == false); - BEAST_EXPECT(runFinishFunction(invalidSectionIdHex).has_value() == false); - BEAST_EXPECT(runFinishFunction(localVariableBombHex).has_value() == false); + 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); } void @@ -756,7 +778,7 @@ struct Wasm_test : public beast::unit_test::suite using namespace test::jtx; Env env(*this); - auto const startLoopWasm = hexToBytes(startLoopHex); + auto const startLoopWasm = hexToBytes(kStartLoopHex); TestLedgerDataProvider hfs(env); ImportVec const imports; @@ -764,8 +786,8 @@ struct Wasm_test : public beast::unit_test::suite auto checkRes = engine.check(startLoopWasm, hfs, "finish", {}, imports, env.journal); BEAST_EXPECTS(checkRes == tesSUCCESS, std::to_string(TERtoInt(checkRes))); - auto re = engine.run( - startLoopWasm, hfs, 1'000'000, ESCROW_FUNCTION_NAME, {}, imports, env.journal); + auto re = + engine.run(startLoopWasm, hfs, 1'000'000, escrowFunctionName, {}, imports, env.journal); BEAST_EXPECTS(re.error() == tecFAILED_PROCESSING, std::to_string(TERtoInt(re.error()))); } @@ -775,7 +797,7 @@ struct Wasm_test : public beast::unit_test::suite testcase("Wasm Bad Align"); // bad_align.c - auto const badAlignWasm = hexToBytes(badAlignWasmHex); + auto const badAlignWasm = hexToBytes(kBadAlignWasmHex); using namespace test::jtx; @@ -816,7 +838,7 @@ struct Wasm_test : public beast::unit_test::suite "071302066d656d6f727902000666696e69736800000a0a01" "08004280808080100b"; auto const wasm = hexToBytes(wasmHex); - auto const re = runEscrowWasm(wasm, hfs, 100'000, ESCROW_FUNCTION_NAME, {}); + auto const re = runEscrowWasm(wasm, hfs, 100'000, escrowFunctionName, {}); BEAST_EXPECT(!re); } @@ -832,7 +854,7 @@ struct Wasm_test : public beast::unit_test::suite "0061736d01000000010401600000030201000503010001071302066d656d6f" "727902000666696e69736800000a050103000f0b"; auto const wasm = hexToBytes(wasmHex); - auto const re = runEscrowWasm(wasm, hfs, 100'000, ESCROW_FUNCTION_NAME, {}); + auto const re = runEscrowWasm(wasm, hfs, 100'000, escrowFunctionName, {}); BEAST_EXPECT(!re); } @@ -847,7 +869,7 @@ struct Wasm_test : public beast::unit_test::suite "6d6f727902000666696e69736800000a10010e0041808080800141ff818080" "010b"; auto const wasm = hexToBytes(wasmHex); - auto const re = runEscrowWasm(wasm, hfs, 100'000, ESCROW_FUNCTION_NAME, {}); + auto const re = runEscrowWasm(wasm, hfs, 100'000, escrowFunctionName, {}); BEAST_EXPECT(!re); } } @@ -909,53 +931,53 @@ struct Wasm_test : public beast::unit_test::suite { testcase("Wasm swap bytes"); - uint64_t const SWAP_DATAU64 = 0x123456789abcdeffull; - uint64_t const REVERSE_SWAP_DATAU64 = 0xffdebc9a78563412ull; - int64_t const SWAP_DATAI64 = 0x123456789abcdeffll; - int64_t const REVERSE_SWAP_DATAI64 = 0xffdebc9a78563412ll; + uint64_t const swapDataU64 = 0x123456789abcdeffull; + uint64_t const reverseSwapDataU64 = 0xffdebc9a78563412ull; + int64_t const swapDataI64 = 0x123456789abcdeffll; + int64_t const reverseSwapDataI64 = 0xffdebc9a78563412ll; - uint32_t const SWAP_DATAU32 = 0x12789aff; - uint32_t const REVERSE_SWAP_DATAU32 = 0xff9a7812; - int32_t const SWAP_DATAI32 = 0x12789aff; - int32_t const REVERSE_SWAP_DATAI32 = 0xff9a7812; + uint32_t const swapDataU32 = 0x12789aff; + uint32_t const reverseSwapDataU32 = 0xff9a7812; + int32_t const swapDataI32 = 0x12789aff; + int32_t const reverseSwapDataI32 = 0xff9a7812; - uint16_t const SWAP_DATAU16 = 0x12ff; - uint16_t const REVERSE_SWAP_DATAU16 = 0xff12; - int16_t const SWAP_DATAI16 = 0x12ff; - int16_t const REVERSE_SWAP_DATAI16 = 0xff12; + uint16_t const swapDataU16 = 0x12ff; + uint16_t const reverseSwapDataU16 = 0xff12; + int16_t const swapDataI16 = 0x12ff; + int16_t const reverseSwapDataI16 = 0xff12; - uint64_t b1 = SWAP_DATAU64; - int64_t b2 = SWAP_DATAI64; + uint64_t b1 = swapDataU64; + int64_t b2 = swapDataI64; b1 = adjustWasmEndianessHlp(b1); b2 = adjustWasmEndianessHlp(b2); - BEAST_EXPECT(b1 == REVERSE_SWAP_DATAU64); - BEAST_EXPECT(b2 == REVERSE_SWAP_DATAI64); + BEAST_EXPECT(b1 == reverseSwapDataU64); + BEAST_EXPECT(b2 == reverseSwapDataI64); b1 = adjustWasmEndianessHlp(b1); b2 = adjustWasmEndianessHlp(b2); - BEAST_EXPECT(b1 == SWAP_DATAU64); - BEAST_EXPECT(b2 == SWAP_DATAI64); + BEAST_EXPECT(b1 == swapDataU64); + BEAST_EXPECT(b2 == swapDataI64); - uint32_t b3 = SWAP_DATAU32; - int32_t b4 = SWAP_DATAI32; + uint32_t b3 = swapDataU32; + int32_t b4 = swapDataI32; b3 = adjustWasmEndianessHlp(b3); b4 = adjustWasmEndianessHlp(b4); - BEAST_EXPECT(b3 == REVERSE_SWAP_DATAU32); - BEAST_EXPECT(b4 == REVERSE_SWAP_DATAI32); + BEAST_EXPECT(b3 == reverseSwapDataU32); + BEAST_EXPECT(b4 == reverseSwapDataI32); b3 = adjustWasmEndianessHlp(b3); b4 = adjustWasmEndianessHlp(b4); - BEAST_EXPECT(b3 == SWAP_DATAU32); - BEAST_EXPECT(b4 == SWAP_DATAI32); + BEAST_EXPECT(b3 == swapDataU32); + BEAST_EXPECT(b4 == swapDataI32); - uint16_t b5 = SWAP_DATAU16; - int16_t b6 = SWAP_DATAI16; + uint16_t b5 = swapDataU16; + int16_t b6 = swapDataI16; b5 = adjustWasmEndianessHlp(b5); b6 = adjustWasmEndianessHlp(b6); - BEAST_EXPECT(b5 == REVERSE_SWAP_DATAU16); - BEAST_EXPECT(b6 == REVERSE_SWAP_DATAI16); + BEAST_EXPECT(b5 == reverseSwapDataU16); + BEAST_EXPECT(b6 == reverseSwapDataI16); b5 = adjustWasmEndianessHlp(b5); b6 = adjustWasmEndianessHlp(b6); - BEAST_EXPECT(b5 == SWAP_DATAU16); - BEAST_EXPECT(b6 == SWAP_DATAI16); + BEAST_EXPECT(b5 == swapDataU16); + BEAST_EXPECT(b6 == swapDataI16); } void @@ -963,8 +985,8 @@ struct Wasm_test : public beast::unit_test::suite { testcase("Wasm Many params"); - auto const params1k = hexToBytes(thousandParamsHex); - auto const params1k1 = hexToBytes(thousand1ParamsHex); + auto const params1k = hexToBytes(kThousandParamsHex); + auto const params1k1 = hexToBytes(kThousand1ParamsHex); using namespace test::jtx; @@ -976,7 +998,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 = WT_I32, .of = {.i32 = 2 * i}}); + params.push_back({.type = WtI32, .of = {.i32 = 2 * i}}); auto& engine = WasmEngine::instance(); { @@ -985,14 +1007,14 @@ struct Wasm_test : public beast::unit_test::suite } // add 1 more parameter, module can't be created now - params.push_back({.type = WT_I32, .of = {.i32 = 2 * 1000}}); + params.push_back({.type = WtI32, .of = {.i32 = 2 * 1000}}); { auto re = engine.run(params1k1, hfs, 1'000'000, "test", params, imports, env.journal); BEAST_EXPECT(!re); } // function that create 10k local variables - auto const locals10k = hexToBytes(locals10kHex); + auto const locals10k = hexToBytes(kLocals10kHex); { auto re = engine.run( locals10k, hfs, 1'000'000, "test", wasmParams(0, 1), imports, env.journal); @@ -1000,7 +1022,7 @@ struct Wasm_test : public beast::unit_test::suite } // module has 5k functions - auto const functions5k = hexToBytes(functions5kHex); + auto const functions5k = hexToBytes(kFunctions5kHex); { auto re = engine.run( functions5k, hfs, 1'000'000, "test0001", wasmParams(2, 3), imports, env.journal); @@ -1015,11 +1037,11 @@ struct Wasm_test : public beast::unit_test::suite { using namespace test::jtx; - unsigned const RESERVED = 64; + unsigned const reserved = 64; std::uint8_t const nop = 0x01; std::array const codeMarker = { nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop}; - auto const opcReserved = hexToBytes(opcReservedHex); + auto const opcReserved = hexToBytes(kOpcReservedHex); Env env{*this}; auto& engine = WasmEngine::instance(); @@ -1096,7 +1118,7 @@ struct Wasm_test : public beast::unit_test::suite if (!BEAST_EXPECTS(!codeRange.empty(), lineStr)) return; - if (!BEAST_EXPECTS(codeSnap.size() < RESERVED, lineStr)) + if (!BEAST_EXPECTS(codeSnap.size() < reserved, lineStr)) return; auto it = codeRange.begin(); for (auto x : codeSnap) @@ -1554,5 +1576,4 @@ struct Wasm_test : public beast::unit_test::suite BEAST_DEFINE_TESTSUITE(Wasm, app, xrpl); -} // namespace test -} // namespace xrpl +} // namespace xrpl::test diff --git a/src/test/app/wasm_fixtures/fixture_functions_5k.cpp b/src/test/app/wasm_fixtures/fixture_functions_5k.cpp index 6ade5fea14..d65f602eec 100644 --- a/src/test/app/wasm_fixtures/fixture_functions_5k.cpp +++ b/src/test/app/wasm_fixtures/fixture_functions_5k.cpp @@ -2,7 +2,9 @@ #include -extern std::string const functions5kHex = +#include + +extern std::string const kFunctions5kHex = "0061736d0100000001070160027f7f017f038a27882700000000000000000000000000000000000000000000000000" "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" diff --git a/src/test/app/wasm_fixtures/fixture_locals_10k.cpp b/src/test/app/wasm_fixtures/fixture_locals_10k.cpp index fe3b11a7a8..75a799243d 100644 --- a/src/test/app/wasm_fixtures/fixture_locals_10k.cpp +++ b/src/test/app/wasm_fixtures/fixture_locals_10k.cpp @@ -2,7 +2,9 @@ #include -extern std::string const locals10kHex = +#include + +extern std::string const kLocals10kHex = "0061736d0100000001070160027f7f017f03020100070801047465737400000a9b8a0601978a06018e4e7f20002001" "6a2102200120026a2103200220036a2104200320046a2105200420056a2106200520066a2107200620076a21082007" "20086a2109200820096a210a2009200a6a210b200a200b6a210c200b200c6a210d200c200d6a210e200d200e6a210f" diff --git a/src/test/app/wasm_fixtures/fixtures.cpp b/src/test/app/wasm_fixtures/fixtures.cpp index 95656161b9..cf8e3fe2c0 100644 --- a/src/test/app/wasm_fixtures/fixtures.cpp +++ b/src/test/app/wasm_fixtures/fixtures.cpp @@ -2,12 +2,14 @@ #include -extern std::string const fibWasmHex = +#include + +extern std::string const kFibWasmHex = "0061736d0100000001090260000060017f017f0303020001071b02115f5f7761736d5f63616c6c5f63746f72730000" "0366696200010a440202000b3f01017f200045044041000f0b2000410348044041010f0b200041026a210003402000" "41036b100120016a2101200041026b220041044a0d000b200141016a0b"; -extern std::string const ledgerSqnWasmHex = +extern std::string const kLedgerSqnWasmHex = "0061736d01000000010e0360027f7f017f6000006000017f02160103656e760e6765745f6c65646765725f73716e00" "0003030201020503010002063f0a7f01418088040b7f004180080b7f004180080b7f004180080b7f00418088040b7f" "004180080b7f00418088040b7f00418080080b7f0041000b7f0041010b07aa010c066d656d6f72790200115f5f7761" @@ -21,7 +23,7 @@ extern std::string const ledgerSqnWasmHex = "61373930636664623432626432343732302900490f7461726765745f6665617475726573042b0f6d757461626c652d" "676c6f62616c732b087369676e2d6578742b0f7265666572656e63652d74797065732b0a6d756c746976616c7565"; -extern std::string const allHostFunctionsWasmHex = +extern std::string const kAllHostFunctionsWasmHex = "0061736d0100000001540c60027f7f017f60037f7f7f017f60047f7f7f7f017f60017f017f60067f7f7f7f7f7f017f" "60037f7f7f0060057f7f7f7f7f017f60037f7f7e017f60087f7f7f7f7f7f7f7f017f60017f0060027f7f006000017f" "02ae061a08686f73745f6c69620c6765745f74785f6669656c64000108686f73745f6c69620974726163655f6e756d" @@ -197,11 +199,11 @@ extern std::string const allHostFunctionsWasmHex = "65737365642d6279010572757374631d312e38372e30202831373036376539616320323032352d30352d303929002c" "0f7461726765745f6665617475726573022b0f6d757461626c652d676c6f62616c732b087369676e2d657874"; -extern std::string const deepRecursionHex = +extern std::string const kDeepRecursionHex = "0061736d010000000105016000017f030201000608017f0141c0843d0b070a010666696e69736800000a1601140023" "0045044041010f0b230041016b240010000b"; -extern std::string const allKeyletsWasmHex = +extern std::string const kAllKeyletsWasmHex = "0061736d0100000001480960067f7f7f7f7f7f017f60047f7f7f7f017f60087f7f7f7f7f7f7f7f017f60037f7f7f01" "7f60037f7f7e017f60057f7f7f7f7f017f60057f7f7f7f7f006000017f60037f7f7f000284051808686f73745f6c69" "620974726163655f6e756d000408686f73745f6c6962057472616365000508686f73745f6c69621063616368655f6c" @@ -395,7 +397,7 @@ extern std::string const allKeyletsWasmHex = "20323032352d30352d303929002c0f7461726765745f6665617475726573022b0f6d757461626c652d676c6f62616c" "732b087369676e2d657874"; -extern std::string const codecovTestsWasmHex = +extern std::string const kCodecovTestsWasmHex = "0061736d01000000015a0c60057f7f7f7f7f017f60037f7f7e017f60027f7f017f60037f7f7f017f60047f7f7f7f01" "7f60017f017f60067f7f7f7f7f7f017f60087f7f7f7f7f7f7f7f017f60077f7f7f7f7f7f7f017f60047f7f7f7f0060" "00006000017f02840d3b08686f73745f6c6962057472616365000008686f73745f6c69620974726163655f6e756d00" @@ -822,7 +824,7 @@ extern std::string const codecovTestsWasmHex = "6976616c75652b0f6d757461626c652d676c6f62616c732b136e6f6e7472617070696e672d6670746f696e742b0f72" "65666572656e63652d74797065732b087369676e2d657874"; -extern std::string const floatTestsWasmHex = +extern std::string const kFloatTestsWasmHex = "0061736d0100000001490960057f7f7f7f7f017f60077f7f7f7f7f7f7f017f60067f7f7f7f7f7f017f60047e7f7f7f" "017f60057e7f7f7f7f017f60047f7f7f7f017f60037f7f7e017f60037f7f7f006000017f02fa021008686f73745f6c" "6962057472616365000008686f73745f6c69620e666c6f61745f66726f6d5f696e74000308686f73745f6c69620f66" @@ -1002,7 +1004,7 @@ extern std::string const floatTestsWasmHex = "1d312e38392e30202832393438333838336520323032352d30382d303429002c0f7461726765745f66656174757265" "73022b0f6d757461626c652d676c6f62616c732b087369676e2d657874"; -extern std::string const float0Hex = +extern std::string const kFloat0Hex = "0061736d0100000001290560057f7f7f7f7f017f60047e7f7f7f017f60077f7f7f7f7f7f7f017f60047f7f7f7f017f" "6000017f025f0408686f73745f6c6962057472616365000008686f73745f6c69620e666c6f61745f66726f6d5f696e" "74000108686f73745f6c69620e666c6f61745f7375627472616374000208686f73745f6c69620d666c6f61745f636f" @@ -1034,7 +1036,7 @@ extern std::string const float0Hex = "626c652d676c6f62616c732b136e6f6e7472617070696e672d6670746f696e742b0f7265666572656e63652d747970" "65732b087369676e2d657874"; -extern std::string const disabledFloatHex = +extern std::string const kDisabledFloatHex = "0061736d010000000108026000006000017f03030200010503010002063e0a7f004180080b7f004180080b7f004180" "100b7f004180100b7f00418090040b7f004180080b7f00418090040b7f00418080080b7f0041000b7f0041010b07b0" "010d066d656d6f72790200115f5f7761736d5f63616c6c5f63746f727300000666696e69736800010362756603000c" @@ -1043,143 +1045,143 @@ extern std::string const disabledFloatHex = "656e6403070d5f5f6d656d6f72795f6261736503080c5f5f7461626c655f6261736503090a150202000b1000430000" "00c54300200045921a41010b"; -extern std::string const memoryPointerAtLimitHex = +extern std::string const kMemoryPointerAtLimitHex = "0061736d010000000105016000017f030201000503010001070a010666696e69736800000a0e010c0041ffff032d00" "001a41010b"; -extern std::string const memoryPointerOverLimitHex = +extern std::string const kMemoryPointerOverLimitHex = "0061736d010000000105016000017f030201000503010001070a010666696e69736800000a0e010c00418080042d00" "001a41010b"; -extern std::string const memoryOffsetOverLimitHex = +extern std::string const kMemoryOffsetOverLimitHex = "0061736d010000000105016000017f030201000503010001071302066d656d6f727902000666696e69736800000a0e" "010c00410028028080041a41010b"; -extern std::string const memoryEndOfWordOverLimitHex = +extern std::string const kMemoryEndOfWordOverLimitHex = "0061736d010000000105016000017f030201000503010001071302066d656d6f727902000666696e69736800000a0e" "010c0041feff032802001a41010b"; -extern std::string const memoryGrow0To1PageHex = +extern std::string const kMemoryGrow0To1PageHex = "0061736d010000000105016000017f030201000503010000071302066d656d6f727902000666696e69736800000a0b" "010900410140001a41010b"; -extern std::string const memoryGrow1To0PageHex = +extern std::string const kMemoryGrow1To0PageHex = "0061736d010000000105016000017f030201000503010001071302066d656d6f727902000666696e69736800000a13" "011100417f4000417f460440417f0f0b41010b"; -extern std::string const memoryLastByteOf8MBHex = +extern std::string const kMemoryLastByteOf8MbHex = "0061736d010000000105016000017f030201000506010180018001071302066d656d6f727902000666696e69736800" "000a0f010d0041ffffff032d00001a41010b"; -extern std::string const memoryGrow1MoreThan8MBHex = +extern std::string const kMemoryGrow1MoreThan8MbHex = "0061736d010000000105016000017f03020100050401008001071302066d656d6f727902000666696e69736800000a" "1301110041014000417f460440417f0f0b41010b"; -extern std::string const memoryGrow0MoreThan8MBHex = +extern std::string const kMemoryGrow0MoreThan8MbHex = "0061736d010000000105016000017f03020100050401008001071302066d656d6f727902000666696e69736800000a" "1301110041004000417f460440417f0f0b41010b"; -extern std::string const memoryInit1MoreThan8MBHex = +extern std::string const kMemoryInit1MoreThan8MbHex = "0061736d010000000105016000017f030201000506010181018101071302066d656d6f727902000666696e69736800" "000a0f010d0041ffffff032d00001a41010b"; -extern std::string const memoryNegativeAddressHex = +extern std::string const kMemoryNegativeAddressHex = "0061736d010000000105016000017f030201000506010180018001071302066d656d6f727902000666696e69736800" "000a0c010a00417f2d00001a41010b"; -extern std::string const table64ElementsHex = +extern std::string const kTable64ElementsHex = "0061736d010000000108026000006000017f0303020001040401700040070a010666696e6973680001094601004100" "0b40000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" "000000000000000000000000000000000000000a090202000b040041010b"; -extern std::string const table65ElementsHex = +extern std::string const kTable65ElementsHex = "0061736d010000000108026000006000017f0303020001040401700041070a010666696e6973680001094701004100" "0b41000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" "00000000000000000000000000000000000000000a090202000b040041010b"; -extern std::string const table2TablesHex = +extern std::string const kTable2TablesHex = "0061736d010000000108026000006000017f03030200010409027001010170010101070a010666696e697368000109" "0f020041000b0100020141000b0001000a090202000b040041010b"; -extern std::string const table0ElementsHex = +extern std::string const kTable0ElementsHex = "0061736d010000000105016000017f03020100040401700000070a010666696e69736800000a0601040041010b"; -extern std::string const tableUintMaxHex = +extern std::string const kTableUintMaxHex = "0061736d010000000105016000017f030201000408017000ffffffff0f070a010666696e69736800000a0601040041" "010b"; -extern std::string const proposalMutableGlobalHex = +extern std::string const kProposalMutableGlobalHex = "0061736d010000000105016000017f030201000606017f0141000b07140207636f756e74657203000666696e697368" "00000a0d010b00230041016a240041010b"; -extern std::string const proposalGcStructNewHex = +extern std::string const kProposalGcStructNewHex = "0061736d01000000010b026000017f5f027f017f0103020100070a010666696e69736800000a0a010800fb01011a41" "010b"; -extern std::string const proposalMultiValueHex = +extern std::string const kProposalMultiValueHex = "0061736d010000000110036000027f7f6000017f60027f7f017f0303020001070a010666696e69736800010a140206" "00410a41140b0b00100002026a411e460b0b"; -extern std::string const proposalSignExtHex = +extern std::string const kProposalSignExtHex = "0061736d010000000105016000017f03020100070a010666696e69736800000a0b01090041ff01c0417f460b"; -extern std::string const proposalFloatToIntHex = +extern std::string const kProposalFloatToIntHex = "0061736d010000000105016000017f03020100070a010666696e69736800000a1201100043f9021550fc0041ffffff" "ff07460b"; -extern std::string const proposalBulkMemoryHex = +extern std::string const kProposalBulkMemoryHex = "0061736d010000000105016000017f030201000503010001071302066d656d6f727902000666696e69736800000a1f" "011d004100412a3a000041e40041004101fc0a000041e4002d0000412a460b"; -extern std::string const proposalRefTypesHex = +extern std::string const kProposalRefTypesHex = "0061736d010000000105016000017f020f0103656e76057461626c65016f000103020100070a010666696e69736800" "000a0c010a004100d06f260041010b"; -extern std::string const proposalTailCallHex = +extern std::string const kProposalTailCallHex = "0061736d010000000105016000017f0303020000070a010666696e69736800010a0b02040041010b040012000b"; -extern std::string const proposalExtendedConstHex = +extern std::string const kProposalExtendedConstHex = "0061736d010000000105016000017f030201000609017f00410a41206a0b070a010666696e69736800000a09010700" "2300412a460b"; -extern std::string const proposalMultiMemoryHex = +extern std::string const kProposalMultiMemoryHex = "0061736d010000000105016000017f0302010005050200000001070a010666696e69736800000a060104003f010b"; -extern std::string const proposalCustomPageSizesHex = +extern std::string const kProposalCustomPageSizesHex = "0061736d010000000105016000017f0302010005040108010a070a010666696e69736800000a0601040041010b0010" "046e616d65010901000666696e697368"; -extern std::string const proposalMemory64Hex = +extern std::string const kProposalMemory64Hex = "0061736d010000000105016000017f030201000503010401070a010666696e69736800000a10010e004200412a3a00" "003f004201510b0010046e616d65010901000666696e697368"; -extern std::string const proposalWideArithmeticHex = +extern std::string const kProposalWideArithmeticHex = "0061736d010000000105016000017f03020100070a010666696e69736800000a0e010c0042014202fc161a1a41010b" "0010046e616d65010901000666696e697368"; -extern std::string const trapDivideBy0Hex = +extern std::string const kTrapDivideBy0Hex = "0061736d010000000105016000017f03020100070a010666696e69736800000a0c010a00412a41006d1a41010b"; -extern std::string const trapIntOverflowHex = +extern std::string const kTrapIntOverflowHex = "0061736d010000000105016000017f03020100070a010666696e69736800000a0d010b00418080808078417f6d0b"; -extern std::string const trapUnreachableHex = +extern std::string const kTrapUnreachableHex = "0061736d010000000105016000017f03020100070a010666696e69736800000a070105000041010b"; -extern std::string const trapNullCallHex = +extern std::string const kTrapNullCallHex = "0061736d010000000105016000017f03020100040401700001070a010666696e69736800000a090107004100110000" "0b"; -extern std::string const trapFuncSigMismatchHex = +extern std::string const kTrapFuncSigMismatchHex = "0061736d010000000108026000006000017f0303020001040401700001070a010666696e6973680001090701004100" "0b01000a0d020300010b070041001101000b"; -extern std::string const wasiGetTimeHex = +extern std::string const kWasiGetTimeHex = "0061736d01000000010c0260037f7e7f017f6000017f02290116776173695f736e617073686f745f70726576696577" "310e636c6f636b5f74696d655f6765740000030201010503010001071302066d656d6f727902000666696e69736800" "010a16011400410042e8074100100045047f410105417f0b0b"; -extern std::string const wasiPrintHex = +extern std::string const kWasiPrintHex = "0061736d01000000010d0260047f7f7f7f017f6000017f02230116776173695f736e617073686f745f707265766965" "77310866645f77726974650000030201010503010001071302066d656d6f727902000666696e69736800010a1d011b" "01017f411821004101410041012000100045047f410105417f0b0b0b1e030041100b0648656c6c6f0a0041000b0410" @@ -1190,8 +1192,8 @@ extern std::string const wasiPrintHex = // rust or wat sources. // Wasm code magic number is "0061736d", and the only valid version is 1. -extern std::string const badMagicNumberHex = "1061736d01000000"; -extern std::string const badVersionNumberHex = "0061736d02000000"; +extern std::string const kBadMagicNumberHex = "1061736d01000000"; +extern std::string const kBadVersionNumberHex = "0061736d02000000"; // Corruption Test: lyingHeader // Scenario: A section declares it is 2GB long, but the file ends immediately. @@ -1201,7 +1203,7 @@ extern std::string const badVersionNumberHex = "0061736d02000000"; // # Type Section (ID 1) // # Size: LEB128 encoded 2GB (0x80 0x80 0x80 0x80 0x08) // data += b'\x01\x80\x80\x80\x80\x08' -extern std::string const lyingHeaderHex = "0061736d01000000018080808008"; +extern std::string const kLyingHeaderHex = "0061736d01000000018080808008"; // Corruption Test: neverEndingNumber // Scenario: An LEB128 integer that never has a stop bit (byte < 0x80). @@ -1211,7 +1213,7 @@ extern std::string const lyingHeaderHex = "0061736d01000000018080808008"; // data += b'\x01\x05' // # Vector count: Infinite stream of 0x80 (100 bytes) // data += b'\x80' * 100 -extern std::string const neverEndingNumberHex = +extern std::string const kNeverEndingNumberHex = "0061736d01000000010580808080808080808080808080808080808080808080808080808080808080808080808080" "8080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080" "80808080808080808080808080808080"; @@ -1226,7 +1228,7 @@ extern std::string const neverEndingNumberHex = // # Vector Count: 0xFF 0xFF 0xFF 0xFF 0x0F (4,294,967,295 items) // data += b'\xff\xff\xff\xff\x0f' // # No actual items follow... -extern std::string const vectorLieHex = "0061736d010000000105ffffffff0f"; +extern std::string const kVectorLieHex = "0061736d010000000105ffffffff0f"; // Corruption Test: sectionOrdering // Scenario: Sections appear out of order @@ -1238,7 +1240,7 @@ extern std::string const vectorLieHex = "0061736d010000000105ffffffff0f"; // data += b'\x0a\x02\x00\x0b' // # Function Section (ID 3) - usually 3rd // data += b'\x03\x02\x00\x00' -extern std::string const sectionOrderingHex = "0061736d010000000a02000b03020000"; +extern std::string const kSectionOrderingHex = "0061736d010000000a02000b03020000"; // Corruption Test: ghostPayload // Scenario: Valid headers, but file is truncated in the middle of a payload. @@ -1251,7 +1253,7 @@ extern std::string const sectionOrderingHex = "0061736d010000000a02000b03020000" // # Start of a type definition (0x60 = func) // data += b'\x60' // # File ends abruptly here (missing params/results) -extern std::string const ghostPayloadHex = "0061736d01000000010a0160"; +extern std::string const kGhostPayloadHex = "0061736d01000000010a0160"; // Corruption Test: junkAfterSection // Scenario: Section declares size X, but logical content finishes at X-5. @@ -1265,7 +1267,7 @@ extern std::string const ghostPayloadHex = "0061736d01000000010a0160"; // data += b'\x01\x60\x00\x00' // # Remaining 6 bytes are junk padding within the section size // data += b'\x00' * 6 -extern std::string const junkAfterSectionHex = "0061736d01000000010a01600000000000000000"; +extern std::string const kJunkAfterSectionHex = "0061736d01000000010a01600000000000000000"; // Corruption Test: invalidSectionId // Scenario: A section ID that doesn't exist (0xFF). @@ -1273,7 +1275,7 @@ extern std::string const junkAfterSectionHex = "0061736d01000000010a016000000000 // data = b'\x00\x61\x73\x6d\x01\x00\x00\x00' // # Section ID 0xFF, Size 1 // data += b'\xff\x01\x00' -extern std::string const invalidSectionIdHex = "0061736d01000000ff0100"; +extern std::string const kInvalidSectionIdHex = "0061736d01000000ff0100"; // Corruption Test: localVariableBomb // Scenario: A function declares 4 billion local variables. @@ -1296,10 +1298,10 @@ extern std::string const invalidSectionIdHex = "0061736d01000000ff0100"; // data += b'\xff\xff\xff\xff\x0f\x7f' // # Instruction: end (0x0b) // data += b'\x0b' -extern std::string const localVariableBombHex = +extern std::string const kLocalVariableBombHex = "0061736d01000000010401600000030201000a0f010d01ffffffff0f7f0b"; -extern std::string const infiniteLoopWasmHex = +extern std::string const kInfiniteLoopWasmHex = "0061736d010000000108026000006000017f030302000105030100020638097f004180080b7f004180080b7f004180" "080b7f00418088040b7f004180080b7f00418088040b7f00418080080b7f0041000b7f0041010b07a8010c066d656d" "6f72790200115f5f7761736d5f63616c6c5f63746f72730000046c6f6f7000010c5f5f64736f5f68616e646c650300" @@ -1312,11 +1314,11 @@ extern std::string const infiniteLoopWasmHex = "3732302900490f7461726765745f6665617475726573042b0f6d757461626c652d676c6f62616c732b087369676e2d" "6578742b0f7265666572656e63652d74797065732b0a6d756c746976616c7565"; -extern std::string const startLoopHex = +extern std::string const kStartLoopHex = "0061736d010000000108026000006000017f030302000107120205737461727400000666696e69736800010801000a" "0e02070003400c000b0b040041010b"; -extern std::string const badAlignWasmHex = +extern std::string const kBadAlignWasmHex = "0061736d01000000011b046000017f60057f7f7f7f7f017f60067f7f7f7f7f7f017f600000022a0203656e760f666c" "6f61745f66726f6d5f75696e74000103656e760c636865636b5f6b65796c6574000203050403000000050301000306" "470b7f004180080b7f00418088020b7f004180080b7f00418088040b7f00418088040b7f00418088080b7f00418008" @@ -1337,7 +1339,7 @@ extern std::string const badAlignWasmHex = "7475726573042b0f6d757461626c652d676c6f62616c732b087369676e2d6578742b0f7265666572656e63652d7479" "7065732b0a6d756c746976616c7565"; -extern std::string const thousandParamsHex = +extern std::string const kThousandParamsHex = "0061736d0100000001f1070260000060e8077f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f" "7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f" "7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f" @@ -1453,7 +1455,7 @@ extern std::string const thousandParamsHex = "32343732302900490f7461726765745f6665617475726573042b0f6d757461626c652d676c6f62616c732b08736967" "6e2d6578742b0f7265666572656e63652d74797065732b0a6d756c746976616c7565"; -extern std::string const thousand1ParamsHex = +extern std::string const kThousand1ParamsHex = "0061736d0100000001f2070260000060e9077f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f" "7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f" "7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f" @@ -1569,13 +1571,13 @@ extern std::string const thousand1ParamsHex = "623432626432343732302900490f7461726765745f6665617475726573042b0f6d757461626c652d676c6f62616c73" "2b087369676e2d6578742b0f7265666572656e63652d74797065732b0a6d756c746976616c7565"; -extern std::string const opcReservedHex = +extern std::string const kOpcReservedHex = "0061736d010000000105016000017f03030200000404017000010503010001060b027f0141000b7e0142000b071401" "10616c6c5f696e737472756374696f6e7300010907010041000b01000a53020400412a0b4c02017f017e0101010101" "0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101" "01010101010101010101010101010101410b0b0b0a010041000b0474657374"; -extern std::string const impExpHex = +extern std::string const kImpExpHex = "0061736d0100000001100360027f7f017f6000017f60017f017f02330203656e760e6765745f6c65646765725f7371" "6e000003656e76166765745f706172656e745f6c65646765725f686173680000030403010201050301000107310406" "6d656d6f72790200096578705f66756e63310002096578705f66756e633200030c746573745f696d706f7274730004" diff --git a/src/test/app/wasm_fixtures/fixtures.h b/src/test/app/wasm_fixtures/fixtures.h index b3b20a8f37..2f0a1072f6 100644 --- a/src/test/app/wasm_fixtures/fixtures.h +++ b/src/test/app/wasm_fixtures/fixtures.h @@ -4,80 +4,80 @@ #include -extern std::string const ledgerSqnWasmHex; -extern std::string const allHostFunctionsWasmHex; -extern std::string const allKeyletsWasmHex; -extern std::string const codecovTestsWasmHex; +extern std::string const kLedgerSqnWasmHex; +extern std::string const kAllHostFunctionsWasmHex; +extern std::string const kAllKeyletsWasmHex; +extern std::string const kCodecovTestsWasmHex; -extern std::string const fibWasmHex; +extern std::string const kFibWasmHex; -extern std::string const floatTestsWasmHex; -extern std::string const float0Hex; -extern std::string const disabledFloatHex; +extern std::string const kFloatTestsWasmHex; +extern std::string const kFloat0Hex; +extern std::string const kDisabledFloatHex; -extern std::string const memoryPointerAtLimitHex; -extern std::string const memoryPointerOverLimitHex; -extern std::string const memoryOffsetOverLimitHex; -extern std::string const memoryEndOfWordOverLimitHex; -extern std::string const memoryGrow0To1PageHex; -extern std::string const memoryGrow1To0PageHex; -extern std::string const memoryLastByteOf8MBHex; -extern std::string const memoryGrow1MoreThan8MBHex; -extern std::string const memoryGrow0MoreThan8MBHex; -extern std::string const memoryInit1MoreThan8MBHex; -extern std::string const memoryNegativeAddressHex; +extern std::string const kMemoryPointerAtLimitHex; +extern std::string const kMemoryPointerOverLimitHex; +extern std::string const kMemoryOffsetOverLimitHex; +extern std::string const kMemoryEndOfWordOverLimitHex; +extern std::string const kMemoryGrow0To1PageHex; +extern std::string const kMemoryGrow1To0PageHex; +extern std::string const kMemoryLastByteOf8MbHex; +extern std::string const kMemoryGrow1MoreThan8MbHex; +extern std::string const kMemoryGrow0MoreThan8MbHex; +extern std::string const kMemoryInit1MoreThan8MbHex; +extern std::string const kMemoryNegativeAddressHex; -extern std::string const table64ElementsHex; -extern std::string const table65ElementsHex; -extern std::string const table2TablesHex; -extern std::string const table0ElementsHex; -extern std::string const tableUintMaxHex; +extern std::string const kTable64ElementsHex; +extern std::string const kTable65ElementsHex; +extern std::string const kTable2TablesHex; +extern std::string const kTable0ElementsHex; +extern std::string const kTableUintMaxHex; -extern std::string const proposalMutableGlobalHex; -extern std::string const proposalGcStructNewHex; -extern std::string const proposalMultiValueHex; -extern std::string const proposalSignExtHex; -extern std::string const proposalFloatToIntHex; -extern std::string const proposalBulkMemoryHex; -extern std::string const proposalRefTypesHex; -extern std::string const proposalTailCallHex; -extern std::string const proposalExtendedConstHex; -extern std::string const proposalMultiMemoryHex; -extern std::string const proposalCustomPageSizesHex; -extern std::string const proposalMemory64Hex; -extern std::string const proposalWideArithmeticHex; +extern std::string const kProposalMutableGlobalHex; +extern std::string const kProposalGcStructNewHex; +extern std::string const kProposalMultiValueHex; +extern std::string const kProposalSignExtHex; +extern std::string const kProposalFloatToIntHex; +extern std::string const kProposalBulkMemoryHex; +extern std::string const kProposalRefTypesHex; +extern std::string const kProposalTailCallHex; +extern std::string const kProposalExtendedConstHex; +extern std::string const kProposalMultiMemoryHex; +extern std::string const kProposalCustomPageSizesHex; +extern std::string const kProposalMemory64Hex; +extern std::string const kProposalWideArithmeticHex; -extern std::string const trapDivideBy0Hex; -extern std::string const trapIntOverflowHex; -extern std::string const trapUnreachableHex; -extern std::string const trapNullCallHex; -extern std::string const trapFuncSigMismatchHex; +extern std::string const kTrapDivideBy0Hex; +extern std::string const kTrapIntOverflowHex; +extern std::string const kTrapUnreachableHex; +extern std::string const kTrapNullCallHex; +extern std::string const kTrapFuncSigMismatchHex; -extern std::string const wasiGetTimeHex; -extern std::string const wasiPrintHex; +extern std::string const kWasiGetTimeHex; +extern std::string const kWasiPrintHex; -extern std::string const badMagicNumberHex; -extern std::string const badVersionNumberHex; -extern std::string const lyingHeaderHex; -extern std::string const neverEndingNumberHex; -extern std::string const vectorLieHex; -extern std::string const sectionOrderingHex; -extern std::string const ghostPayloadHex; -extern std::string const junkAfterSectionHex; -extern std::string const invalidSectionIdHex; -extern std::string const localVariableBombHex; +extern std::string const kBadMagicNumberHex; +extern std::string const kBadVersionNumberHex; +extern std::string const kLyingHeaderHex; +extern std::string const kNeverEndingNumberHex; +extern std::string const kVectorLieHex; +extern std::string const kSectionOrderingHex; +extern std::string const kGhostPayloadHex; +extern std::string const kJunkAfterSectionHex; +extern std::string const kInvalidSectionIdHex; +extern std::string const kLocalVariableBombHex; -extern std::string const deepRecursionHex; -extern std::string const infiniteLoopWasmHex; -extern std::string const startLoopHex; +extern std::string const kDeepRecursionHex; +extern std::string const kInfiniteLoopWasmHex; +extern std::string const kStartLoopHex; -extern std::string const badAlignWasmHex; +extern std::string const kBadAlignWasmHex; -extern std::string const thousandParamsHex; -extern std::string const thousand1ParamsHex; -extern std::string const locals10kHex; -extern std::string const functions5kHex; +extern std::string const kThousandParamsHex; +extern std::string const kThousand1ParamsHex; +extern std::string const kLocals10kHex; +extern std::string const kFunctions5kHex; -extern std::string const opcReservedHex; +extern std::string const kOpcReservedHex; -extern std::string const impExpHex; +extern std::string const kImpExpHex;