From 803a344c65361607c18badede43b36eac9c4f43f Mon Sep 17 00:00:00 2001 From: Mayukha Vadari Date: Wed, 28 Jan 2026 16:35:02 -0500 Subject: [PATCH] fix clang-format --- src/test/app/HostFuncImpl_test.cpp | 1132 +++++------------ src/test/app/TestHostFunctions.h | 106 +- src/test/app/Wasm_test.cpp | 321 ++--- src/test/app/wasm_fixtures/b58.c | 3 +- src/test/app/wasm_fixtures/fixtures.cpp | 9 +- src/test/app/wasm_fixtures/sha512Pure.c | 48 +- src/test/basics/Number_test.cpp | 22 +- src/xrpld/app/wasm/HostFunc.h | 24 +- src/xrpld/app/wasm/HostFuncImpl.h | 38 +- src/xrpld/app/wasm/HostFuncWrapper.h | 467 ++----- src/xrpld/app/wasm/ParamsHelper.h | 46 +- src/xrpld/app/wasm/WasmiVM.h | 86 +- src/xrpld/app/wasm/detail/HostFuncImpl.cpp | 5 +- .../app/wasm/detail/HostFuncImplFloat.cpp | 50 +- .../app/wasm/detail/HostFuncImplGetter.cpp | 18 +- .../app/wasm/detail/HostFuncImplKeylet.cpp | 46 +- .../app/wasm/detail/HostFuncImplTrace.cpp | 25 +- src/xrpld/app/wasm/detail/HostFuncWrapper.cpp | 592 ++------- src/xrpld/app/wasm/detail/WasmVM.cpp | 20 +- src/xrpld/app/wasm/detail/WasmiVM.cpp | 192 +-- 20 files changed, 831 insertions(+), 2419 deletions(-) diff --git a/src/test/app/HostFuncImpl_test.cpp b/src/test/app/HostFuncImpl_test.cpp index 5c9aa54dc8..811166c013 100644 --- a/src/test/app/HostFuncImpl_test.cpp +++ b/src/test/app/HostFuncImpl_test.cpp @@ -71,16 +71,12 @@ createApplyContext( beast::Journal j, STTx const& tx = STTx(ttESCROW_FINISH, [](STObject&) {})) { - ApplyContext ac{ - env.app(), ov, tx, tesSUCCESS, env.current()->fees().base, tapNONE, j}; + ApplyContext ac{env.app(), ov, tx, tesSUCCESS, env.current()->fees().base, tapNONE, j}; return ac; } static ApplyContext -createApplyContext( - test::jtx::Env& env, - OpenView& ov, - STTx const& tx = STTx(ttESCROW_FINISH, [](STObject&) {})) +createApplyContext(test::jtx::Env& env, OpenView& ov, STTx const& tx = STTx(ttESCROW_FINISH, [](STObject&) {})) { return createApplyContext(env, ov, env.journal, tx); } @@ -96,8 +92,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite Env env{*this}; OpenView ov{*env.current()}; ApplyContext ac = createApplyContext(env, ov); - auto const dummyEscrow = - keylet::escrow(env.master, env.seq(env.master)); + auto const dummyEscrow = keylet::escrow(env.master, env.seq(env.master)); WasmHostFunctionsImpl hfs(ac, dummyEscrow); auto const result = hfs.getLedgerSqn(); @@ -112,8 +107,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite using namespace test::jtx; Env env{*this}; - auto const dummyEscrow = - keylet::escrow(env.master, env.seq(env.master)); + auto const dummyEscrow = keylet::escrow(env.master, env.seq(env.master)); { OpenView ov{*env.current()}; @@ -121,24 +115,16 @@ struct HostFuncImpl_test : public beast::unit_test::suite WasmHostFunctionsImpl hfs(ac, dummyEscrow); auto const result = hfs.getParentLedgerTime(); if (BEAST_EXPECT(result.has_value())) - BEAST_EXPECT( - result.value() == - env.current() - ->parentCloseTime() - .time_since_epoch() - .count()); + BEAST_EXPECT(result.value() == env.current()->parentCloseTime().time_since_epoch().count()); } - env.close( - env.now() + - std::chrono::seconds(std::numeric_limits::max() - 1)); + env.close(env.now() + std::chrono::seconds(std::numeric_limits::max() - 1)); { OpenView ov{*env.current()}; ApplyContext ac = createApplyContext(env, ov); WasmHostFunctionsImpl hfs(ac, dummyEscrow); auto const result = hfs.getParentLedgerTime(); - if (BEAST_EXPECTS( - !result.has_value(), std::to_string(result.value()))) + if (BEAST_EXPECTS(!result.has_value(), std::to_string(result.value()))) BEAST_EXPECT(result.error() == HostFunctionError::INTERNAL); } } @@ -152,8 +138,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite Env env{*this}; OpenView ov{*env.current()}; ApplyContext ac = createApplyContext(env, ov); - auto const dummyEscrow = - keylet::escrow(env.master, env.seq(env.master)); + auto const dummyEscrow = keylet::escrow(env.master, env.seq(env.master)); WasmHostFunctionsImpl hfs(ac, dummyEscrow); @@ -171,8 +156,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite Env env{*this}; OpenView ov{*env.current()}; ApplyContext ac = createApplyContext(env, ov); - auto const dummyEscrow = - keylet::escrow(env.master, env.seq(env.master)); + auto const dummyEscrow = keylet::escrow(env.master, env.seq(env.master)); WasmHostFunctionsImpl hfs(ac, dummyEscrow); @@ -184,10 +168,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite Env env2( *this, envconfig([](std::unique_ptr cfg) { - cfg->FEES.reference_fee = - static_cast( - std::numeric_limits::max()) + - 1; + cfg->FEES.reference_fee = static_cast(std::numeric_limits::max()) + 1; return cfg; }), testable_amendments()); @@ -215,8 +196,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite Env env{*this}; OpenView ov{*env.current()}; ApplyContext ac = createApplyContext(env, ov); - auto const dummyEscrow = - keylet::escrow(env.master, env.seq(env.master)); + auto const dummyEscrow = keylet::escrow(env.master, env.seq(env.master)); WasmHostFunctionsImpl hfs(ac, dummyEscrow); // Use featureTokenEscrow for testing @@ -268,15 +248,9 @@ struct HostFuncImpl_test : public beast::unit_test::suite { WasmHostFunctionsImpl hfs(ac, dummyEscrow); - BEAST_EXPECT( - hfs.cacheLedgerObj(accountKeylet.key, -1).error() == - HostFunctionError::SLOT_OUT_RANGE); - BEAST_EXPECT( - hfs.cacheLedgerObj(accountKeylet.key, 257).error() == - HostFunctionError::SLOT_OUT_RANGE); - BEAST_EXPECT( - hfs.cacheLedgerObj(dummyEscrow.key, 0).error() == - HostFunctionError::LEDGER_OBJ_NOT_FOUND); + BEAST_EXPECT(hfs.cacheLedgerObj(accountKeylet.key, -1).error() == HostFunctionError::SLOT_OUT_RANGE); + BEAST_EXPECT(hfs.cacheLedgerObj(accountKeylet.key, 257).error() == HostFunctionError::SLOT_OUT_RANGE); + BEAST_EXPECT(hfs.cacheLedgerObj(dummyEscrow.key, 0).error() == HostFunctionError::LEDGER_OBJ_NOT_FOUND); BEAST_EXPECT(hfs.cacheLedgerObj(accountKeylet.key, 0).value() == 1); for (int i = 1; i <= 256; ++i) @@ -284,9 +258,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite auto const result = hfs.cacheLedgerObj(accountKeylet.key, i); BEAST_EXPECT(result.has_value() && result.value() == i); } - BEAST_EXPECT( - hfs.cacheLedgerObj(accountKeylet.key, 0).error() == - HostFunctionError::SLOTS_FULL); + BEAST_EXPECT(hfs.cacheLedgerObj(accountKeylet.key, 0).error() == HostFunctionError::SLOTS_FULL); } { @@ -297,9 +269,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite auto const result = hfs.cacheLedgerObj(accountKeylet.key, 0); BEAST_EXPECT(result.has_value() && result.value() == i); } - BEAST_EXPECT( - hfs.cacheLedgerObj(accountKeylet.key, 0).error() == - HostFunctionError::SLOTS_FULL); + BEAST_EXPECT(hfs.cacheLedgerObj(accountKeylet.key, 0).error() == HostFunctionError::SLOTS_FULL); } } @@ -309,8 +279,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite testcase("getTxField"); using namespace test::jtx; - std::string const credIdHex = - "0011223344556677889900112233445566778899001122334455667788990011"; + std::string const credIdHex = "0011223344556677889900112233445566778899001122334455667788990011"; uint256 credId; BEAST_EXPECT(credId.parseHex(credIdHex)); @@ -326,14 +295,12 @@ struct HostFuncImpl_test : public beast::unit_test::suite obj.setFieldV256(sfCredentialIDs, credIds); }); ApplyContext ac = createApplyContext(env, ov, stx); - auto const dummyEscrow = - keylet::escrow(env.master, env.seq(env.master)); + auto const dummyEscrow = keylet::escrow(env.master, env.seq(env.master)); { WasmHostFunctionsImpl hfs(ac, dummyEscrow); auto const account = hfs.getTxField(sfAccount); - BEAST_EXPECT( - account && std::ranges::equal(*account, env.master.id())); + BEAST_EXPECT(account && std::ranges::equal(*account, env.master.id())); auto const owner = hfs.getTxField(sfOwner); BEAST_EXPECT(owner && std::ranges::equal(*owner, env.master.id())); @@ -346,13 +313,11 @@ struct HostFuncImpl_test : public beast::unit_test::suite auto const notPresent = hfs.getTxField(sfDestination); if (BEAST_EXPECT(!notPresent.has_value())) - BEAST_EXPECT( - notPresent.error() == HostFunctionError::FIELD_NOT_FOUND); + BEAST_EXPECT(notPresent.error() == HostFunctionError::FIELD_NOT_FOUND); auto const memos = hfs.getTxField(sfMemos); if (BEAST_EXPECT(!memos.has_value())) - BEAST_EXPECT( - memos.error() == HostFunctionError::NOT_LEAF_FIELD); + BEAST_EXPECT(memos.error() == HostFunctionError::NOT_LEAF_FIELD); auto const credentialIds = hfs.getTxField(sfCredentialIDs); if (BEAST_EXPECT(!credentialIds.has_value())) @@ -362,13 +327,11 @@ struct HostFuncImpl_test : public beast::unit_test::suite auto const nonField = hfs.getTxField(sfInvalid); if (BEAST_EXPECT(!nonField.has_value())) - BEAST_EXPECT( - nonField.error() == HostFunctionError::FIELD_NOT_FOUND); + BEAST_EXPECT(nonField.error() == HostFunctionError::FIELD_NOT_FOUND); auto const nonField2 = hfs.getTxField(sfGeneric); if (BEAST_EXPECT(!nonField2.has_value())) - BEAST_EXPECT( - nonField2.error() == HostFunctionError::FIELD_NOT_FOUND); + BEAST_EXPECT(nonField2.error() == HostFunctionError::FIELD_NOT_FOUND); } { @@ -376,8 +339,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite STTx const stx2 = STTx(ttAMM_DEPOSIT, [&](auto& obj) { obj.setAccountID(sfAccount, env.master.id()); obj.setFieldIssue(sfAsset, STIssue{sfAsset, xrpIssue()}); - obj.setFieldIssue( - sfAsset2, STIssue{sfAsset2, iouAsset.issue()}); + obj.setFieldIssue(sfAsset2, STIssue{sfAsset2, iouAsset.issue()}); }); ApplyContext ac2 = createApplyContext(env, ov, stx2); WasmHostFunctionsImpl hfs(ac2, dummyEscrow); @@ -426,8 +388,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite auto const actualScale = hfs.getTxField(sfAssetScale); if (BEAST_EXPECT(actualScale.has_value())) { - BEAST_EXPECT( - std::ranges::equal(*actualScale, toBytes(expectedScale))); + BEAST_EXPECT(std::ranges::equal(*actualScale, toBytes(expectedScale))); } } } @@ -442,25 +403,21 @@ struct HostFuncImpl_test : public beast::unit_test::suite Env env{*this}; // Fund the account and create an escrow so the ledger object exists - env(escrow::create(env.master, env.master, XRP(100)), - escrow::finish_time(env.now() + 1s)); + env(escrow::create(env.master, env.master, XRP(100)), escrow::finish_time(env.now() + 1s)); env.close(); OpenView ov{*env.current()}; ApplyContext ac = createApplyContext(env, ov); // Find the escrow ledger object - auto const escrowKeylet = - keylet::escrow(env.master, env.seq(env.master) - 1); + auto const escrowKeylet = keylet::escrow(env.master, env.seq(env.master) - 1); BEAST_EXPECT(env.le(escrowKeylet)); WasmHostFunctionsImpl hfs(ac, escrowKeylet); // Should return the Account field from the escrow ledger object auto const account = hfs.getCurrentLedgerObjField(sfAccount); - if (BEAST_EXPECTS( - account.has_value(), - std::to_string(static_cast(account.error())))) + if (BEAST_EXPECTS(account.has_value(), std::to_string(static_cast(account.error())))) BEAST_EXPECT(std::ranges::equal(*account, env.master.id())); // Should return the Amount field from the escrow ledger object @@ -471,29 +428,23 @@ struct HostFuncImpl_test : public beast::unit_test::suite } // Should return the PreviousTxnID field from the escrow ledger object - auto const previousTxnId = - hfs.getCurrentLedgerObjField(sfPreviousTxnID); + auto const previousTxnId = hfs.getCurrentLedgerObjField(sfPreviousTxnID); if (BEAST_EXPECT(previousTxnId.has_value())) { - BEAST_EXPECT( - *previousTxnId == toBytes(env.tx()->getTransactionID())); + BEAST_EXPECT(*previousTxnId == toBytes(env.tx()->getTransactionID())); } // Should return nullopt for a field not present auto const notPresent = hfs.getCurrentLedgerObjField(sfOwner); - BEAST_EXPECT( - !notPresent.has_value() && - notPresent.error() == HostFunctionError::FIELD_NOT_FOUND); + BEAST_EXPECT(!notPresent.has_value() && notPresent.error() == HostFunctionError::FIELD_NOT_FOUND); { - auto const dummyEscrow = - keylet::escrow(env.master, env.seq(env.master) + 5); + auto const dummyEscrow = keylet::escrow(env.master, env.seq(env.master) + 5); WasmHostFunctionsImpl hfs2(ac, dummyEscrow); auto const account = hfs2.getCurrentLedgerObjField(sfAccount); if (BEAST_EXPECT(!account.has_value())) { - BEAST_EXPECT( - account.error() == HostFunctionError::LEDGER_OBJ_NOT_FOUND); + BEAST_EXPECT(account.error() == HostFunctionError::LEDGER_OBJ_NOT_FOUND); } } } @@ -507,16 +458,14 @@ struct HostFuncImpl_test : public beast::unit_test::suite Env env{*this}; // Fund the account and create an escrow so the ledger object exists - env(escrow::create(env.master, env.master, XRP(100)), - escrow::finish_time(env.now() + 1s)); + env(escrow::create(env.master, env.master, XRP(100)), escrow::finish_time(env.now() + 1s)); env.close(); OpenView ov{*env.current()}; ApplyContext ac = createApplyContext(env, ov); auto const accountKeylet = keylet::account(env.master.id()); - auto const escrowKeylet = - keylet::escrow(env.master.id(), env.seq(env.master) - 1); + auto const escrowKeylet = keylet::escrow(env.master.id(), env.seq(env.master) - 1); WasmHostFunctionsImpl hfs(ac, escrowKeylet); // Cache the escrow ledger object in slot 1 @@ -525,9 +474,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite // Should return the Account field from the cached ledger object auto const account = hfs.getLedgerObjField(1, sfAccount); - if (BEAST_EXPECTS( - account.has_value(), - std::to_string(static_cast(account.error())))) + if (BEAST_EXPECTS(account.has_value(), std::to_string(static_cast(account.error())))) BEAST_EXPECT(std::ranges::equal(*account, env.master.id())); // Should return the Balance field from the cached ledger object @@ -539,26 +486,18 @@ struct HostFuncImpl_test : public beast::unit_test::suite // Should return error for slot out of range auto const outOfRange = hfs.getLedgerObjField(0, sfAccount); - BEAST_EXPECT( - !outOfRange.has_value() && - outOfRange.error() == HostFunctionError::SLOT_OUT_RANGE); + BEAST_EXPECT(!outOfRange.has_value() && outOfRange.error() == HostFunctionError::SLOT_OUT_RANGE); auto const tooHigh = hfs.getLedgerObjField(257, sfAccount); - BEAST_EXPECT( - !tooHigh.has_value() && - tooHigh.error() == HostFunctionError::SLOT_OUT_RANGE); + BEAST_EXPECT(!tooHigh.has_value() && tooHigh.error() == HostFunctionError::SLOT_OUT_RANGE); // Should return error for empty slot auto const emptySlot = hfs.getLedgerObjField(2, sfAccount); - BEAST_EXPECT( - !emptySlot.has_value() && - emptySlot.error() == HostFunctionError::EMPTY_SLOT); + BEAST_EXPECT(!emptySlot.has_value() && emptySlot.error() == HostFunctionError::EMPTY_SLOT); // Should return error for field not present auto const notPresent = hfs.getLedgerObjField(1, sfOwner); - BEAST_EXPECT( - !notPresent.has_value() && - notPresent.error() == HostFunctionError::FIELD_NOT_FOUND); + BEAST_EXPECT(!notPresent.has_value() && notPresent.error() == HostFunctionError::FIELD_NOT_FOUND); } void @@ -570,8 +509,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite Env env{*this}; OpenView ov{*env.current()}; - std::string const credIdHex = - "0011223344556677889900112233445566778899001122334455667788990011"; + std::string const credIdHex = "0011223344556677889900112233445566778899001122334455667788990011"; uint256 credId; BEAST_EXPECT(credId.parseHex(credIdHex)); @@ -589,8 +527,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite }); ApplyContext ac = createApplyContext(env, ov, stx); - auto const dummyEscrow = - keylet::escrow(env.master, env.seq(env.master)); + auto const dummyEscrow = keylet::escrow(env.master, env.seq(env.master)); WasmHostFunctionsImpl hfs(ac, dummyEscrow); @@ -598,19 +535,13 @@ struct HostFuncImpl_test : public beast::unit_test::suite // Locator for sfMemos[0].sfMemo.sfMemoData // Locator is a sequence of int32_t codes: // [sfMemos.fieldCode, 0, sfMemoData.fieldCode] - std::vector locatorVec = { - sfMemos.fieldCode, 0, sfMemoData.fieldCode}; - Slice locator( - reinterpret_cast(locatorVec.data()), - locatorVec.size() * sizeof(int32_t)); + std::vector locatorVec = {sfMemos.fieldCode, 0, sfMemoData.fieldCode}; + Slice locator(reinterpret_cast(locatorVec.data()), locatorVec.size() * sizeof(int32_t)); auto const result = hfs.getTxNestedField(locator); - if (BEAST_EXPECTS( - result.has_value(), - std::to_string(static_cast(result.error())))) + if (BEAST_EXPECTS(result.has_value(), std::to_string(static_cast(result.error())))) { - std::string memoData( - result.value().begin(), result.value().end()); + std::string memoData(result.value().begin(), result.value().end()); BEAST_EXPECT(memoData == "hello"); } } @@ -618,17 +549,12 @@ struct HostFuncImpl_test : public beast::unit_test::suite { // Locator for sfCredentialIDs[0] std::vector locatorVec = {sfCredentialIDs.fieldCode, 0}; - Slice locator( - reinterpret_cast(locatorVec.data()), - locatorVec.size() * sizeof(int32_t)); + Slice locator(reinterpret_cast(locatorVec.data()), locatorVec.size() * sizeof(int32_t)); auto const result = hfs.getTxNestedField(locator); - if (BEAST_EXPECTS( - result.has_value(), - std::to_string(static_cast(result.error())))) + if (BEAST_EXPECTS(result.has_value(), std::to_string(static_cast(result.error())))) { - std::string credIdResult( - result.value().begin(), result.value().end()); + std::string credIdResult(result.value().begin(), result.value().end()); BEAST_EXPECT(strHex(credIdResult) == credIdHex); } } @@ -636,14 +562,10 @@ struct HostFuncImpl_test : public beast::unit_test::suite { // can use the nested locator for base fields too std::vector locatorVec = {sfAccount.fieldCode}; - Slice locator( - reinterpret_cast(locatorVec.data()), - locatorVec.size() * sizeof(int32_t)); + Slice locator(reinterpret_cast(locatorVec.data()), locatorVec.size() * sizeof(int32_t)); auto const account = hfs.getTxNestedField(locator); - if (BEAST_EXPECTS( - account.has_value(), - std::to_string(static_cast(account.error())))) + if (BEAST_EXPECTS(account.has_value(), std::to_string(static_cast(account.error())))) { BEAST_EXPECT(std::ranges::equal(*account, env.master.id())); } @@ -652,31 +574,21 @@ struct HostFuncImpl_test : public beast::unit_test::suite { // unaligned locator std::vector locatorVec(sizeof(int32_t) + 1); - memcpy( - locatorVec.data() + 1, &sfAccount.fieldCode, sizeof(int32_t)); - Slice locator( - reinterpret_cast(locatorVec.data() + 1), - sizeof(int32_t)); + memcpy(locatorVec.data() + 1, &sfAccount.fieldCode, sizeof(int32_t)); + Slice locator(reinterpret_cast(locatorVec.data() + 1), sizeof(int32_t)); auto const account = hfs.getTxNestedField(locator); - if (BEAST_EXPECTS( - account.has_value(), - std::to_string(static_cast(account.error())))) + if (BEAST_EXPECTS(account.has_value(), std::to_string(static_cast(account.error())))) { BEAST_EXPECT(std::ranges::equal(*account, env.master.id())); } } - auto expectError = [&](std::vector const& locatorVec, - HostFunctionError expectedError) { - Slice locator( - reinterpret_cast(locatorVec.data()), - locatorVec.size() * sizeof(int32_t)); + auto expectError = [&](std::vector const& locatorVec, HostFunctionError expectedError) { + Slice locator(reinterpret_cast(locatorVec.data()), locatorVec.size() * sizeof(int32_t)); auto const result = hfs.getTxNestedField(locator); if (BEAST_EXPECT(!result.has_value())) - BEAST_EXPECTS( - result.error() == expectedError, - std::to_string(static_cast(result.error()))); + BEAST_EXPECTS(result.error() == expectedError, std::to_string(static_cast(result.error()))); }; // Locator for non-existent base field expectError( @@ -699,9 +611,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite // Locator for non-existent nested field expectError( - {sfMemos.fieldCode, - 0, - sfURI.fieldCode}, // sfURI does not exist in the memo + {sfMemos.fieldCode, 0, sfURI.fieldCode}, // sfURI does not exist in the memo HostFunctionError::FIELD_NOT_FOUND); // Locator for non-existent base sfield @@ -722,8 +632,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite expectError({sfMemos.fieldCode}, HostFunctionError::NOT_LEAF_FIELD); // Locator for STVector256 - expectError( - {sfCredentialIDs.fieldCode}, HostFunctionError::NOT_LEAF_FIELD); + expectError({sfCredentialIDs.fieldCode}, HostFunctionError::NOT_LEAF_FIELD); // Locator for nesting into non-array/object field expectError( @@ -738,13 +647,10 @@ struct HostFuncImpl_test : public beast::unit_test::suite // Locator for malformed locator (not multiple of 4) { std::vector locatorVec = {sfMemos.fieldCode}; - Slice malformedLocator( - reinterpret_cast(locatorVec.data()), 3); + Slice malformedLocator(reinterpret_cast(locatorVec.data()), 3); auto const malformedResult = hfs.getTxNestedField(malformedLocator); BEAST_EXPECT( - !malformedResult.has_value() && - malformedResult.error() == - HostFunctionError::LOCATOR_MALFORMED); + !malformedResult.has_value() && malformedResult.error() == HostFunctionError::LOCATOR_MALFORMED); } } @@ -772,27 +678,18 @@ struct HostFuncImpl_test : public beast::unit_test::suite // Locator for base field std::vector baseLocator = {sfSignerQuorum.fieldCode}; Slice baseLocatorSlice( - reinterpret_cast(baseLocator.data()), - baseLocator.size() * sizeof(int32_t)); - auto const signerQuorum = - hfs.getCurrentLedgerObjNestedField(baseLocatorSlice); - if (BEAST_EXPECTS( - signerQuorum.has_value(), - std::to_string(static_cast(signerQuorum.error())))) + reinterpret_cast(baseLocator.data()), baseLocator.size() * sizeof(int32_t)); + auto const signerQuorum = hfs.getCurrentLedgerObjNestedField(baseLocatorSlice); + if (BEAST_EXPECTS(signerQuorum.has_value(), std::to_string(static_cast(signerQuorum.error())))) { BEAST_EXPECT(*signerQuorum == toBytes(static_cast(2))); } - auto expectError = [&](std::vector const& locatorVec, - HostFunctionError expectedError) { - Slice locator( - reinterpret_cast(locatorVec.data()), - locatorVec.size() * sizeof(int32_t)); + auto expectError = [&](std::vector const& locatorVec, HostFunctionError expectedError) { + Slice locator(reinterpret_cast(locatorVec.data()), locatorVec.size() * sizeof(int32_t)); auto const result = hfs.getCurrentLedgerObjNestedField(locator); if (BEAST_EXPECT(!result.has_value())) - BEAST_EXPECTS( - result.error() == expectedError, - std::to_string(static_cast(result.error()))); + BEAST_EXPECTS(result.error() == expectedError, std::to_string(static_cast(result.error()))); }; // Locator for non-existent base field expectError( @@ -802,40 +699,28 @@ struct HostFuncImpl_test : public beast::unit_test::suite HostFunctionError::FIELD_NOT_FOUND); // Locator for nesting into non-array/object field expectError( - {sfSignerQuorum - .fieldCode, // sfSignerQuorum is not an array or object + {sfSignerQuorum.fieldCode, // sfSignerQuorum is not an array or object 0, sfAccount.fieldCode}, HostFunctionError::LOCATOR_MALFORMED); // Locator for empty locator Slice emptyLocator(nullptr, 0); - auto const emptyResult = - hfs.getCurrentLedgerObjNestedField(emptyLocator); - BEAST_EXPECT( - !emptyResult.has_value() && - emptyResult.error() == HostFunctionError::LOCATOR_MALFORMED); + auto const emptyResult = hfs.getCurrentLedgerObjNestedField(emptyLocator); + BEAST_EXPECT(!emptyResult.has_value() && emptyResult.error() == HostFunctionError::LOCATOR_MALFORMED); // Locator for malformed locator (not multiple of 4) std::vector malformedLocatorVec = {sfMemos.fieldCode}; - Slice malformedLocator( - reinterpret_cast(malformedLocatorVec.data()), 3); - auto const malformedResult = - hfs.getCurrentLedgerObjNestedField(malformedLocator); - BEAST_EXPECT( - !malformedResult.has_value() && - malformedResult.error() == HostFunctionError::LOCATOR_MALFORMED); + Slice malformedLocator(reinterpret_cast(malformedLocatorVec.data()), 3); + auto const malformedResult = hfs.getCurrentLedgerObjNestedField(malformedLocator); + BEAST_EXPECT(!malformedResult.has_value() && malformedResult.error() == HostFunctionError::LOCATOR_MALFORMED); { - auto const dummyEscrow = - keylet::escrow(env.master, env.seq(env.master) + 5); + auto const dummyEscrow = keylet::escrow(env.master, env.seq(env.master) + 5); WasmHostFunctionsImpl dummyHfs(ac, dummyEscrow); std::vector const locatorVec = {sfAccount.fieldCode}; - Slice locator( - reinterpret_cast(locatorVec.data()), - locatorVec.size() * sizeof(int32_t)); - auto const result = - dummyHfs.getCurrentLedgerObjNestedField(locator); + Slice locator(reinterpret_cast(locatorVec.data()), locatorVec.size() * sizeof(int32_t)); + auto const result = dummyHfs.getCurrentLedgerObjNestedField(locator); if (BEAST_EXPECT(!result.has_value())) BEAST_EXPECTS( result.error() == HostFunctionError::LEDGER_OBJ_NOT_FOUND, @@ -859,8 +744,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite OpenView ov{*env.current()}; ApplyContext ac = createApplyContext(env, ov); - auto const dummyEscrow = - keylet::escrow(env.master, env.seq(env.master)); + auto const dummyEscrow = keylet::escrow(env.master, env.seq(env.master)); WasmHostFunctionsImpl hfs(ac, dummyEscrow); // Cache the SignerList ledger object in slot 1 @@ -870,16 +754,11 @@ struct HostFuncImpl_test : public beast::unit_test::suite // Locator for sfSignerEntries[0].sfAccount { - std::vector const locatorVec = { - sfSignerEntries.fieldCode, 0, sfAccount.fieldCode}; - Slice locator( - reinterpret_cast(locatorVec.data()), - locatorVec.size() * sizeof(int32_t)); + std::vector const locatorVec = {sfSignerEntries.fieldCode, 0, sfAccount.fieldCode}; + Slice locator(reinterpret_cast(locatorVec.data()), locatorVec.size() * sizeof(int32_t)); auto const result = hfs.getLedgerObjNestedField(1, locator); - if (BEAST_EXPECTS( - result.has_value(), - std::to_string(static_cast(result.error())))) + if (BEAST_EXPECTS(result.has_value(), std::to_string(static_cast(result.error())))) { BEAST_EXPECT(std::ranges::equal(*result, alice.id())); } @@ -887,15 +766,11 @@ struct HostFuncImpl_test : public beast::unit_test::suite // Locator for sfSignerEntries[1].sfAccount { - std::vector const locatorVec = { - sfSignerEntries.fieldCode, 1, sfAccount.fieldCode}; - Slice const locator = Slice( - reinterpret_cast(locatorVec.data()), - locatorVec.size() * sizeof(int32_t)); + std::vector const locatorVec = {sfSignerEntries.fieldCode, 1, sfAccount.fieldCode}; + Slice const locator = + Slice(reinterpret_cast(locatorVec.data()), locatorVec.size() * sizeof(int32_t)); auto const result2 = hfs.getLedgerObjNestedField(1, locator); - if (BEAST_EXPECTS( - result2.has_value(), - std::to_string(static_cast(result2.error())))) + if (BEAST_EXPECTS(result2.has_value(), std::to_string(static_cast(result2.error())))) { BEAST_EXPECT(std::ranges::equal(*result2, becky.id())); } @@ -903,15 +778,11 @@ struct HostFuncImpl_test : public beast::unit_test::suite // Locator for sfSignerEntries[0].sfSignerWeight { - std::vector const locatorVec = { - sfSignerEntries.fieldCode, 0, sfSignerWeight.fieldCode}; - Slice const locator = Slice( - reinterpret_cast(locatorVec.data()), - locatorVec.size() * sizeof(int32_t)); + std::vector const locatorVec = {sfSignerEntries.fieldCode, 0, sfSignerWeight.fieldCode}; + Slice const locator = + Slice(reinterpret_cast(locatorVec.data()), locatorVec.size() * sizeof(int32_t)); auto const weightResult = hfs.getLedgerObjNestedField(1, locator); - if (BEAST_EXPECTS( - weightResult.has_value(), - std::to_string(static_cast(weightResult.error())))) + if (BEAST_EXPECTS(weightResult.has_value(), std::to_string(static_cast(weightResult.error())))) { // Should be 1 auto const expected = toBytes(static_cast(1)); @@ -922,13 +793,10 @@ struct HostFuncImpl_test : public beast::unit_test::suite // Locator for base field sfSignerQuorum { std::vector const locatorVec = {sfSignerQuorum.fieldCode}; - Slice const locator = Slice( - reinterpret_cast(locatorVec.data()), - locatorVec.size() * sizeof(int32_t)); + Slice const locator = + Slice(reinterpret_cast(locatorVec.data()), locatorVec.size() * sizeof(int32_t)); auto const quorumResult = hfs.getLedgerObjNestedField(1, locator); - if (BEAST_EXPECTS( - quorumResult.has_value(), - std::to_string(static_cast(quorumResult.error())))) + if (BEAST_EXPECTS(quorumResult.has_value(), std::to_string(static_cast(quorumResult.error())))) { auto const expected = toBytes(static_cast(2)); BEAST_EXPECT(*quorumResult == expected); @@ -936,17 +804,12 @@ struct HostFuncImpl_test : public beast::unit_test::suite } // Helper for error checks - auto expectError = [&](std::vector const& locatorVec, - HostFunctionError expectedError, - int slot = 1) { + auto expectError = [&](std::vector const& locatorVec, HostFunctionError expectedError, int slot = 1) { Slice const locator( - reinterpret_cast(locatorVec.data()), - locatorVec.size() * sizeof(int32_t)); + reinterpret_cast(locatorVec.data()), locatorVec.size() * sizeof(int32_t)); auto const result = hfs.getLedgerObjNestedField(slot, locator); if (BEAST_EXPECT(!result.has_value())) - BEAST_EXPECTS( - result.error() == expectedError, - std::to_string(static_cast(result.error()))); + BEAST_EXPECTS(result.error() == expectedError, std::to_string(static_cast(result.error()))); }; // Error: base field not found @@ -973,45 +836,32 @@ struct HostFuncImpl_test : public beast::unit_test::suite HostFunctionError::FIELD_NOT_FOUND); // Error: invalid field code - expectError( - {field_code(99999, 99999), 0, sfAccount.fieldCode}, - HostFunctionError::INVALID_FIELD); + expectError({field_code(99999, 99999), 0, sfAccount.fieldCode}, HostFunctionError::INVALID_FIELD); // Error: invalid nested field code - expectError( - {sfSignerEntries.fieldCode, 0, field_code(99999, 99999)}, - HostFunctionError::INVALID_FIELD); + expectError({sfSignerEntries.fieldCode, 0, field_code(99999, 99999)}, HostFunctionError::INVALID_FIELD); // 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::SLOT_OUT_RANGE, 0); + expectError({sfSignerQuorum.fieldCode}, HostFunctionError::SLOT_OUT_RANGE, 257); // Error: empty slot - expectError( - {sfSignerQuorum.fieldCode}, HostFunctionError::EMPTY_SLOT, 2); + expectError({sfSignerQuorum.fieldCode}, HostFunctionError::EMPTY_SLOT, 2); // Error: locator for STArray (not leaf field) - expectError( - {sfSignerEntries.fieldCode}, HostFunctionError::NOT_LEAF_FIELD); + expectError({sfSignerEntries.fieldCode}, HostFunctionError::NOT_LEAF_FIELD); // Error: nesting into non-array/object field - expectError( - {sfSignerQuorum.fieldCode, 0, sfAccount.fieldCode}, - HostFunctionError::LOCATOR_MALFORMED); + expectError({sfSignerQuorum.fieldCode, 0, sfAccount.fieldCode}, HostFunctionError::LOCATOR_MALFORMED); // Error: empty locator expectError({}, HostFunctionError::LOCATOR_MALFORMED); // Error: locator malformed (not multiple of 4) std::vector const locatorVec = {sfSignerEntries.fieldCode}; - Slice const locator = - Slice(reinterpret_cast(locatorVec.data()), 3); + Slice const locator = Slice(reinterpret_cast(locatorVec.data()), 3); auto const malformed = hfs.getLedgerObjNestedField(1, locator); - BEAST_EXPECT( - !malformed.has_value() && - malformed.error() == HostFunctionError::LOCATOR_MALFORMED); + BEAST_EXPECT(!malformed.has_value() && malformed.error() == HostFunctionError::LOCATOR_MALFORMED); } void @@ -1020,8 +870,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite testcase("getTxArrayLen"); using namespace test::jtx; - std::string const credIdHex = - "0011223344556677889900112233445566778899001122334455667788990011"; + std::string const credIdHex = "0011223344556677889900112233445566778899001122334455667788990011"; uint256 credId; BEAST_EXPECT(credId.parseHex(credIdHex)); @@ -1049,8 +898,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite }); ApplyContext ac = createApplyContext(env, ov, stx); - auto const dummyEscrow = - keylet::escrow(env.master, env.seq(env.master)); + auto const dummyEscrow = keylet::escrow(env.master, env.seq(env.master)); WasmHostFunctionsImpl hfs(ac, dummyEscrow); // Should return 1 for sfMemos @@ -1066,8 +914,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite // Should return error for missing array field auto const missingArray = hfs.getTxArrayLen(sfSigners); if (BEAST_EXPECT(!missingArray.has_value())) - BEAST_EXPECT( - missingArray.error() == HostFunctionError::FIELD_NOT_FOUND); + BEAST_EXPECT(missingArray.error() == HostFunctionError::FIELD_NOT_FOUND); // Should return 1 for sfCredentialIDs auto const credIdsLen = hfs.getTxArrayLen(sfCredentialIDs); @@ -1094,8 +941,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite auto const signerKeylet = keylet::signers(env.master.id()); WasmHostFunctionsImpl hfs(ac, signerKeylet); - auto const entriesLen = - hfs.getCurrentLedgerObjArrayLen(sfSignerEntries); + auto const entriesLen = hfs.getCurrentLedgerObjArrayLen(sfSignerEntries); if (BEAST_EXPECT(entriesLen.has_value())) BEAST_EXPECT(entriesLen.value() == 2); @@ -1109,13 +955,11 @@ struct HostFuncImpl_test : public beast::unit_test::suite BEAST_EXPECT(notArray.error() == HostFunctionError::NO_ARRAY); { - auto const dummyEscrow = - keylet::escrow(env.master, env.seq(env.master) + 5); + auto const dummyEscrow = keylet::escrow(env.master, env.seq(env.master) + 5); WasmHostFunctionsImpl dummyHfs(ac, dummyEscrow); auto const len = dummyHfs.getCurrentLedgerObjArrayLen(sfMemos); if (BEAST_EXPECT(!len.has_value())) - BEAST_EXPECT( - len.error() == HostFunctionError::LEDGER_OBJ_NOT_FOUND); + BEAST_EXPECT(len.error() == HostFunctionError::LEDGER_OBJ_NOT_FOUND); } } @@ -1135,8 +979,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite OpenView ov{*env.current()}; ApplyContext ac = createApplyContext(env, ov); - auto const dummyEscrow = - keylet::escrow(env.master, env.seq(env.master)); + auto const dummyEscrow = keylet::escrow(env.master, env.seq(env.master)); WasmHostFunctionsImpl hfs(ac, dummyEscrow); auto const signerListKeylet = keylet::signers(env.master.id()); @@ -1152,8 +995,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite { auto const arrLen = hfs.getLedgerObjArrayLen(0, sfSignerEntries); if (BEAST_EXPECT(!arrLen.has_value())) - BEAST_EXPECT( - arrLen.error() == HostFunctionError::SLOT_OUT_RANGE); + BEAST_EXPECT(arrLen.error() == HostFunctionError::SLOT_OUT_RANGE); } { @@ -1167,16 +1009,14 @@ struct HostFuncImpl_test : public beast::unit_test::suite // Should return error for empty slot auto const emptySlot = hfs.getLedgerObjArrayLen(2, sfSignerEntries); if (BEAST_EXPECT(!emptySlot.has_value())) - BEAST_EXPECT( - emptySlot.error() == HostFunctionError::EMPTY_SLOT); + BEAST_EXPECT(emptySlot.error() == HostFunctionError::EMPTY_SLOT); } { // Should return error for missing array field auto const missingArray = hfs.getLedgerObjArrayLen(1, sfMemos); if (BEAST_EXPECT(!missingArray.has_value())) - BEAST_EXPECT( - missingArray.error() == HostFunctionError::FIELD_NOT_FOUND); + BEAST_EXPECT(missingArray.error() == HostFunctionError::FIELD_NOT_FOUND); } } @@ -1198,30 +1038,22 @@ struct HostFuncImpl_test : public beast::unit_test::suite }); ApplyContext ac = createApplyContext(env, ov, stx); - auto const dummyEscrow = - keylet::escrow(env.master, env.seq(env.master)); + auto const dummyEscrow = keylet::escrow(env.master, env.seq(env.master)); WasmHostFunctionsImpl hfs(ac, dummyEscrow); // Helper for error checks - auto expectError = [&](std::vector const& locatorVec, - HostFunctionError expectedError, - int slot = 1) { + auto expectError = [&](std::vector const& locatorVec, HostFunctionError expectedError, int slot = 1) { Slice const locator( - reinterpret_cast(locatorVec.data()), - locatorVec.size() * sizeof(int32_t)); + reinterpret_cast(locatorVec.data()), locatorVec.size() * sizeof(int32_t)); auto const result = hfs.getTxNestedArrayLen(locator); if (BEAST_EXPECT(!result.has_value())) - BEAST_EXPECTS( - result.error() == expectedError, - std::to_string(static_cast(result.error()))); + BEAST_EXPECTS(result.error() == expectedError, std::to_string(static_cast(result.error()))); }; // Locator for sfMemos { std::vector locatorVec = {sfMemos.fieldCode}; - Slice locator( - reinterpret_cast(locatorVec.data()), - locatorVec.size() * sizeof(int32_t)); + Slice locator(reinterpret_cast(locatorVec.data()), locatorVec.size() * sizeof(int32_t)); auto const arrLen = hfs.getTxNestedArrayLen(locator); BEAST_EXPECT(arrLen.has_value() && arrLen.value() == 1); } @@ -1253,25 +1085,18 @@ struct HostFuncImpl_test : public beast::unit_test::suite WasmHostFunctionsImpl hfs(ac, signerKeylet); // Helper for error checks - auto expectError = [&](std::vector const& locatorVec, - HostFunctionError expectedError, - int slot = 1) { + auto expectError = [&](std::vector const& locatorVec, HostFunctionError expectedError, int slot = 1) { Slice const locator( - reinterpret_cast(locatorVec.data()), - locatorVec.size() * sizeof(int32_t)); + reinterpret_cast(locatorVec.data()), locatorVec.size() * sizeof(int32_t)); auto const result = hfs.getCurrentLedgerObjNestedArrayLen(locator); if (BEAST_EXPECT(!result.has_value())) - BEAST_EXPECTS( - result.error() == expectedError, - std::to_string(static_cast(result.error()))); + BEAST_EXPECTS(result.error() == expectedError, std::to_string(static_cast(result.error()))); }; // Locator for sfSignerEntries { std::vector locatorVec = {sfSignerEntries.fieldCode}; - Slice locator( - reinterpret_cast(locatorVec.data()), - locatorVec.size() * sizeof(int32_t)); + Slice locator(reinterpret_cast(locatorVec.data()), locatorVec.size() * sizeof(int32_t)); auto const arrLen = hfs.getCurrentLedgerObjNestedArrayLen(locator); BEAST_EXPECT(arrLen.has_value() && arrLen.value() == 2); } @@ -1283,15 +1108,12 @@ struct HostFuncImpl_test : public beast::unit_test::suite expectError({sfSigners.fieldCode}, HostFunctionError::FIELD_NOT_FOUND); { - auto const dummyEscrow = - keylet::escrow(env.master, env.seq(env.master) + 5); + auto const dummyEscrow = keylet::escrow(env.master, env.seq(env.master) + 5); WasmHostFunctionsImpl dummyHfs(ac, dummyEscrow); std::vector locatorVec = {sfAccount.fieldCode}; Slice const locator( - reinterpret_cast(locatorVec.data()), - locatorVec.size() * sizeof(int32_t)); - auto const result = - dummyHfs.getCurrentLedgerObjNestedArrayLen(locator); + reinterpret_cast(locatorVec.data()), locatorVec.size() * sizeof(int32_t)); + auto const result = dummyHfs.getCurrentLedgerObjNestedArrayLen(locator); if (BEAST_EXPECT(!result.has_value())) BEAST_EXPECTS( result.error() == HostFunctionError::LEDGER_OBJ_NOT_FOUND, @@ -1314,8 +1136,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite OpenView ov{*env.current()}; ApplyContext ac = createApplyContext(env, ov); - auto const dummyEscrow = - keylet::escrow(env.master, env.seq(env.master)); + auto const dummyEscrow = keylet::escrow(env.master, env.seq(env.master)); WasmHostFunctionsImpl hfs(ac, dummyEscrow); auto const signerListKeylet = keylet::signers(env.master.id()); @@ -1324,25 +1145,18 @@ struct HostFuncImpl_test : public beast::unit_test::suite // Locator for sfSignerEntries std::vector locatorVec = {sfSignerEntries.fieldCode}; - Slice locator( - reinterpret_cast(locatorVec.data()), - locatorVec.size() * sizeof(int32_t)); + Slice locator(reinterpret_cast(locatorVec.data()), locatorVec.size() * sizeof(int32_t)); auto const arrLen = hfs.getLedgerObjNestedArrayLen(1, locator); if (BEAST_EXPECT(arrLen.has_value())) BEAST_EXPECT(arrLen.value() == 2); // Helper for error checks - auto expectError = [&](std::vector const& locatorVec, - HostFunctionError expectedError, - int slot = 1) { + auto expectError = [&](std::vector const& locatorVec, HostFunctionError expectedError, int slot = 1) { Slice const locator( - reinterpret_cast(locatorVec.data()), - locatorVec.size() * sizeof(int32_t)); + reinterpret_cast(locatorVec.data()), locatorVec.size() * sizeof(int32_t)); auto const result = hfs.getLedgerObjNestedArrayLen(slot, locator); if (BEAST_EXPECT(!result.has_value())) - BEAST_EXPECTS( - result.error() == expectedError, - std::to_string(static_cast(result.error()))); + BEAST_EXPECTS(result.error() == expectedError, std::to_string(static_cast(result.error()))); }; // Error: non-array field @@ -1362,18 +1176,12 @@ struct HostFuncImpl_test : public beast::unit_test::suite expectError({}, HostFunctionError::LOCATOR_MALFORMED); // Error: locator malformed (not multiple of 4) - Slice malformedLocator( - reinterpret_cast(locator.data()), 3); - auto const malformed = - hfs.getLedgerObjNestedArrayLen(1, malformedLocator); - BEAST_EXPECT( - !malformed.has_value() && - malformed.error() == HostFunctionError::LOCATOR_MALFORMED); + Slice malformedLocator(reinterpret_cast(locator.data()), 3); + auto const malformed = hfs.getLedgerObjNestedArrayLen(1, malformedLocator); + BEAST_EXPECT(!malformed.has_value() && malformed.error() == HostFunctionError::LOCATOR_MALFORMED); // Error: locator for non-STArray field - expectError( - {sfSignerQuorum.fieldCode, 0, sfAccount.fieldCode}, - HostFunctionError::LOCATOR_MALFORMED); + expectError({sfSignerQuorum.fieldCode, 0, sfAccount.fieldCode}, HostFunctionError::LOCATOR_MALFORMED); } void @@ -1383,15 +1191,13 @@ struct HostFuncImpl_test : public beast::unit_test::suite using namespace test::jtx; Env env{*this}; - env(escrow::create(env.master, env.master, XRP(100)), - escrow::finish_time(env.now() + std::chrono::seconds(1))); + env(escrow::create(env.master, env.master, XRP(100)), escrow::finish_time(env.now() + std::chrono::seconds(1))); env.close(); OpenView ov{*env.current()}; ApplyContext ac = createApplyContext(env, ov); - auto const escrowKeylet = - keylet::escrow(env.master, env.seq(env.master) - 1); + auto const escrowKeylet = keylet::escrow(env.master, env.seq(env.master) - 1); WasmHostFunctionsImpl hfs(ac, escrowKeylet); // Should succeed for small data @@ -1401,11 +1207,9 @@ struct HostFuncImpl_test : public beast::unit_test::suite // Should fail for too large data std::vector bigData(maxWasmDataLength + 1, 0x42); - auto const tooBig = - hfs.updateData(Slice(bigData.data(), bigData.size())); + auto const tooBig = hfs.updateData(Slice(bigData.data(), bigData.size())); if (BEAST_EXPECT(!tooBig.has_value())) - BEAST_EXPECT( - tooBig.error() == HostFunctionError::DATA_FIELD_TOO_LARGE); + BEAST_EXPECT(tooBig.error() == HostFunctionError::DATA_FIELD_TOO_LARGE); } void @@ -1418,8 +1222,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite OpenView ov{*env.current()}; ApplyContext ac = createApplyContext(env, ov); - auto const dummyEscrow = - keylet::escrow(env.master, env.seq(env.master)); + auto const dummyEscrow = keylet::escrow(env.master, env.seq(env.master)); WasmHostFunctionsImpl hfs(ac, dummyEscrow); // Generate a keypair and sign a message @@ -1432,9 +1235,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite // Should succeed for valid signature { auto const result = hfs.checkSignature( - Slice(message.data(), message.size()), - Slice(sig.data(), sig.size()), - Slice(pk.data(), pk.size())); + Slice(message.data(), message.size()), Slice(sig.data(), sig.size()), Slice(pk.data(), pk.size())); BEAST_EXPECT(result.has_value()); BEAST_EXPECT(result.value() == 1); } @@ -1464,9 +1265,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite // Should fail for empty public key { auto const result = hfs.checkSignature( - Slice(message.data(), message.size()), - Slice(sig.data(), sig.size()), - Slice(nullptr, 0)); + Slice(message.data(), message.size()), Slice(sig.data(), sig.size()), Slice(nullptr, 0)); BEAST_EXPECT(!result.has_value()); BEAST_EXPECT(result.error() == HostFunctionError::INVALID_PARAMS); } @@ -1474,19 +1273,15 @@ struct HostFuncImpl_test : public beast::unit_test::suite // Should fail for empty signature { auto const result = hfs.checkSignature( - Slice(message.data(), message.size()), - Slice(nullptr, 0), - Slice(pk.data(), pk.size())); + Slice(message.data(), message.size()), Slice(nullptr, 0), Slice(pk.data(), pk.size())); BEAST_EXPECT(result.has_value()); BEAST_EXPECT(result.value() == 0); } // Should fail for empty message { - auto const result = hfs.checkSignature( - Slice(nullptr, 0), - Slice(sig.data(), sig.size()), - Slice(pk.data(), pk.size())); + auto const result = + hfs.checkSignature(Slice(nullptr, 0), Slice(sig.data(), sig.size()), Slice(pk.data(), pk.size())); BEAST_EXPECT(result.has_value()); BEAST_EXPECT(result.value() == 0); } @@ -1502,13 +1297,11 @@ struct HostFuncImpl_test : public beast::unit_test::suite OpenView ov{*env.current()}; ApplyContext ac = createApplyContext(env, ov); - auto const dummyEscrow = - keylet::escrow(env.master, env.seq(env.master)); + auto const dummyEscrow = keylet::escrow(env.master, env.seq(env.master)); WasmHostFunctionsImpl hfs(ac, dummyEscrow); std::string data = "hello world"; - auto const result = - hfs.computeSha512HalfHash(Slice(data.data(), data.size())); + auto const result = hfs.computeSha512HalfHash(Slice(data.data(), data.size())); BEAST_EXPECT(result.has_value()); // Should match direct call to sha512Half @@ -1526,12 +1319,10 @@ struct HostFuncImpl_test : public beast::unit_test::suite OpenView ov{*env.current()}; ApplyContext ac = createApplyContext(env, ov); - auto const dummyEscrow = - keylet::escrow(env.master, env.seq(env.master)); + auto const dummyEscrow = keylet::escrow(env.master, env.seq(env.master)); WasmHostFunctionsImpl hfs(ac, dummyEscrow); - auto compareKeylet = [](std::vector const& bytes, - Keylet const& kl) { + auto compareKeylet = [](std::vector const& bytes, Keylet const& kl) { return std::ranges::equal(bytes, kl.key); }; // Lambda to compare a Bytes (std::vector) to a keylet @@ -1544,37 +1335,24 @@ struct HostFuncImpl_test : public beast::unit_test::suite BEAST_EXPECT(compareKeylet(actual.value(), expected)); \ } \ } -#define COMPARE_KEYLET_FAIL(hfsFunc, expected, ...) \ - { \ - auto actual = hfs.hfsFunc(__VA_ARGS__); \ - if (BEAST_EXPECT(!actual.has_value())) \ - { \ - BEAST_EXPECTS( \ - actual.error() == expected, \ - std::to_string(HfErrorToInt(actual.error()))); \ - } \ +#define COMPARE_KEYLET_FAIL(hfsFunc, expected, ...) \ + { \ + auto actual = hfs.hfsFunc(__VA_ARGS__); \ + if (BEAST_EXPECT(!actual.has_value())) \ + { \ + BEAST_EXPECTS(actual.error() == expected, std::to_string(HfErrorToInt(actual.error()))); \ + } \ } COMPARE_KEYLET(accountKeylet, keylet::account, env.master.id()); - COMPARE_KEYLET_FAIL( - accountKeylet, HostFunctionError::INVALID_ACCOUNT, xrpAccount()); + COMPARE_KEYLET_FAIL(accountKeylet, HostFunctionError::INVALID_ACCOUNT, xrpAccount()); - COMPARE_KEYLET( - ammKeylet, keylet::amm, xrpIssue(), env.master["USD"].issue()); - COMPARE_KEYLET_FAIL( - ammKeylet, - HostFunctionError::INVALID_PARAMS, - xrpIssue(), - xrpIssue()); - COMPARE_KEYLET_FAIL( - ammKeylet, - HostFunctionError::INVALID_PARAMS, - makeMptID(1, env.master.id()), - xrpIssue()); + COMPARE_KEYLET(ammKeylet, keylet::amm, xrpIssue(), env.master["USD"].issue()); + COMPARE_KEYLET_FAIL(ammKeylet, HostFunctionError::INVALID_PARAMS, xrpIssue(), xrpIssue()); + COMPARE_KEYLET_FAIL(ammKeylet, HostFunctionError::INVALID_PARAMS, makeMptID(1, env.master.id()), xrpIssue()); COMPARE_KEYLET(checkKeylet, keylet::check, env.master.id(), 1); - COMPARE_KEYLET_FAIL( - checkKeylet, HostFunctionError::INVALID_ACCOUNT, xrpAccount(), 1); + COMPARE_KEYLET_FAIL(checkKeylet, HostFunctionError::INVALID_ACCOUNT, xrpAccount(), 1); std::string const credType = "test"; COMPARE_KEYLET( @@ -1609,79 +1387,28 @@ struct HostFuncImpl_test : public beast::unit_test::suite Slice(credType.data(), credType.size())); COMPARE_KEYLET(didKeylet, keylet::did, env.master.id()); - COMPARE_KEYLET_FAIL( - didKeylet, HostFunctionError::INVALID_ACCOUNT, xrpAccount()); + COMPARE_KEYLET_FAIL(didKeylet, HostFunctionError::INVALID_ACCOUNT, xrpAccount()); - COMPARE_KEYLET( - delegateKeylet, keylet::delegate, env.master.id(), alice.id()); - COMPARE_KEYLET_FAIL( - delegateKeylet, - HostFunctionError::INVALID_PARAMS, - env.master.id(), - env.master.id()); - COMPARE_KEYLET_FAIL( - delegateKeylet, - HostFunctionError::INVALID_ACCOUNT, - env.master.id(), - xrpAccount()); - COMPARE_KEYLET_FAIL( - delegateKeylet, - HostFunctionError::INVALID_ACCOUNT, - xrpAccount(), - env.master.id()); + COMPARE_KEYLET(delegateKeylet, keylet::delegate, env.master.id(), alice.id()); + COMPARE_KEYLET_FAIL(delegateKeylet, HostFunctionError::INVALID_PARAMS, env.master.id(), env.master.id()); + COMPARE_KEYLET_FAIL(delegateKeylet, HostFunctionError::INVALID_ACCOUNT, env.master.id(), xrpAccount()); + COMPARE_KEYLET_FAIL(delegateKeylet, HostFunctionError::INVALID_ACCOUNT, xrpAccount(), env.master.id()); - COMPARE_KEYLET( - depositPreauthKeylet, - keylet::depositPreauth, - env.master.id(), - alice.id()); - COMPARE_KEYLET_FAIL( - depositPreauthKeylet, - HostFunctionError::INVALID_PARAMS, - env.master.id(), - env.master.id()); - COMPARE_KEYLET_FAIL( - depositPreauthKeylet, - HostFunctionError::INVALID_ACCOUNT, - env.master.id(), - xrpAccount()); - COMPARE_KEYLET_FAIL( - depositPreauthKeylet, - HostFunctionError::INVALID_ACCOUNT, - xrpAccount(), - env.master.id()); + COMPARE_KEYLET(depositPreauthKeylet, keylet::depositPreauth, env.master.id(), alice.id()); + COMPARE_KEYLET_FAIL(depositPreauthKeylet, HostFunctionError::INVALID_PARAMS, env.master.id(), env.master.id()); + COMPARE_KEYLET_FAIL(depositPreauthKeylet, HostFunctionError::INVALID_ACCOUNT, env.master.id(), xrpAccount()); + COMPARE_KEYLET_FAIL(depositPreauthKeylet, HostFunctionError::INVALID_ACCOUNT, xrpAccount(), env.master.id()); COMPARE_KEYLET(escrowKeylet, keylet::escrow, env.master.id(), 1); - COMPARE_KEYLET_FAIL( - escrowKeylet, HostFunctionError::INVALID_ACCOUNT, xrpAccount(), 1); + COMPARE_KEYLET_FAIL(escrowKeylet, HostFunctionError::INVALID_ACCOUNT, xrpAccount(), 1); Currency usd = to_currency("USD"); - COMPARE_KEYLET( - lineKeylet, keylet::line, env.master.id(), alice.id(), usd); + COMPARE_KEYLET(lineKeylet, keylet::line, env.master.id(), alice.id(), usd); + COMPARE_KEYLET_FAIL(lineKeylet, HostFunctionError::INVALID_PARAMS, env.master.id(), env.master.id(), usd); + COMPARE_KEYLET_FAIL(lineKeylet, HostFunctionError::INVALID_ACCOUNT, env.master.id(), xrpAccount(), usd); + COMPARE_KEYLET_FAIL(lineKeylet, HostFunctionError::INVALID_ACCOUNT, xrpAccount(), env.master.id(), usd); COMPARE_KEYLET_FAIL( - lineKeylet, - HostFunctionError::INVALID_PARAMS, - env.master.id(), - env.master.id(), - usd); - COMPARE_KEYLET_FAIL( - lineKeylet, - HostFunctionError::INVALID_ACCOUNT, - env.master.id(), - xrpAccount(), - usd); - COMPARE_KEYLET_FAIL( - lineKeylet, - HostFunctionError::INVALID_ACCOUNT, - xrpAccount(), - env.master.id(), - usd); - COMPARE_KEYLET_FAIL( - lineKeylet, - HostFunctionError::INVALID_PARAMS, - env.master.id(), - alice.id(), - to_currency("")); + lineKeylet, HostFunctionError::INVALID_PARAMS, env.master.id(), alice.id(), to_currency("")); { auto actual = hfs.mptIssuanceKeylet(env.master.id(), 1); @@ -1694,81 +1421,39 @@ struct HostFuncImpl_test : public beast::unit_test::suite { auto actual = hfs.mptIssuanceKeylet(xrpAccount(), 1); if (BEAST_EXPECT(!actual.has_value())) - BEAST_EXPECT( - actual.error() == HostFunctionError::INVALID_ACCOUNT); + BEAST_EXPECT(actual.error() == HostFunctionError::INVALID_ACCOUNT); } auto const sampleMPTID = makeMptID(1, env.master.id()); COMPARE_KEYLET(mptokenKeylet, keylet::mptoken, sampleMPTID, alice.id()); - COMPARE_KEYLET_FAIL( - mptokenKeylet, - HostFunctionError::INVALID_PARAMS, - MPTID{}, - alice.id()); - COMPARE_KEYLET_FAIL( - mptokenKeylet, - HostFunctionError::INVALID_ACCOUNT, - sampleMPTID, - xrpAccount()); + COMPARE_KEYLET_FAIL(mptokenKeylet, HostFunctionError::INVALID_PARAMS, MPTID{}, alice.id()); + COMPARE_KEYLET_FAIL(mptokenKeylet, HostFunctionError::INVALID_ACCOUNT, sampleMPTID, xrpAccount()); COMPARE_KEYLET(nftOfferKeylet, keylet::nftoffer, env.master.id(), 1); - COMPARE_KEYLET_FAIL( - nftOfferKeylet, - HostFunctionError::INVALID_ACCOUNT, - xrpAccount(), - 1); + COMPARE_KEYLET_FAIL(nftOfferKeylet, HostFunctionError::INVALID_ACCOUNT, xrpAccount(), 1); COMPARE_KEYLET(offerKeylet, keylet::offer, env.master.id(), 1); - COMPARE_KEYLET_FAIL( - offerKeylet, HostFunctionError::INVALID_ACCOUNT, xrpAccount(), 1); + COMPARE_KEYLET_FAIL(offerKeylet, HostFunctionError::INVALID_ACCOUNT, xrpAccount(), 1); COMPARE_KEYLET(oracleKeylet, keylet::oracle, env.master.id(), 1); - COMPARE_KEYLET_FAIL( - oracleKeylet, HostFunctionError::INVALID_ACCOUNT, xrpAccount(), 1); + COMPARE_KEYLET_FAIL(oracleKeylet, HostFunctionError::INVALID_ACCOUNT, xrpAccount(), 1); - COMPARE_KEYLET( - paychanKeylet, keylet::payChan, env.master.id(), alice.id(), 1); - COMPARE_KEYLET_FAIL( - paychanKeylet, - HostFunctionError::INVALID_PARAMS, - env.master.id(), - env.master.id(), - 1); - COMPARE_KEYLET_FAIL( - paychanKeylet, - HostFunctionError::INVALID_ACCOUNT, - env.master.id(), - xrpAccount(), - 1); - COMPARE_KEYLET_FAIL( - paychanKeylet, - HostFunctionError::INVALID_ACCOUNT, - xrpAccount(), - env.master.id(), - 1); + COMPARE_KEYLET(paychanKeylet, keylet::payChan, env.master.id(), alice.id(), 1); + COMPARE_KEYLET_FAIL(paychanKeylet, HostFunctionError::INVALID_PARAMS, env.master.id(), env.master.id(), 1); + COMPARE_KEYLET_FAIL(paychanKeylet, HostFunctionError::INVALID_ACCOUNT, env.master.id(), xrpAccount(), 1); + COMPARE_KEYLET_FAIL(paychanKeylet, HostFunctionError::INVALID_ACCOUNT, xrpAccount(), env.master.id(), 1); - COMPARE_KEYLET( - permissionedDomainKeylet, - keylet::permissionedDomain, - env.master.id(), - 1); - COMPARE_KEYLET_FAIL( - permissionedDomainKeylet, - HostFunctionError::INVALID_ACCOUNT, - xrpAccount(), - 1); + COMPARE_KEYLET(permissionedDomainKeylet, keylet::permissionedDomain, env.master.id(), 1); + COMPARE_KEYLET_FAIL(permissionedDomainKeylet, HostFunctionError::INVALID_ACCOUNT, xrpAccount(), 1); COMPARE_KEYLET(signersKeylet, keylet::signers, env.master.id()); - COMPARE_KEYLET_FAIL( - signersKeylet, HostFunctionError::INVALID_ACCOUNT, xrpAccount()); + COMPARE_KEYLET_FAIL(signersKeylet, HostFunctionError::INVALID_ACCOUNT, xrpAccount()); COMPARE_KEYLET(ticketKeylet, keylet::ticket, env.master.id(), 1); - COMPARE_KEYLET_FAIL( - ticketKeylet, HostFunctionError::INVALID_ACCOUNT, xrpAccount(), 1); + COMPARE_KEYLET_FAIL(ticketKeylet, HostFunctionError::INVALID_ACCOUNT, xrpAccount(), 1); COMPARE_KEYLET(vaultKeylet, keylet::vault, env.master.id(), 1); - COMPARE_KEYLET_FAIL( - vaultKeylet, HostFunctionError::INVALID_ACCOUNT, xrpAccount(), 1); + COMPARE_KEYLET_FAIL(vaultKeylet, HostFunctionError::INVALID_ACCOUNT, xrpAccount(), 1); } void @@ -1808,16 +1493,14 @@ struct HostFuncImpl_test : public beast::unit_test::suite { auto const result = hfs.getNFT(xrpAccount(), nftId); if (BEAST_EXPECT(!result.has_value())) - BEAST_EXPECT( - result.error() == HostFunctionError::INVALID_ACCOUNT); + BEAST_EXPECT(result.error() == HostFunctionError::INVALID_ACCOUNT); } // Should fail for invalid nftId { auto const result = hfs.getNFT(alice.id(), uint256()); if (BEAST_EXPECT(!result.has_value())) - BEAST_EXPECT( - result.error() == HostFunctionError::INVALID_PARAMS); + BEAST_EXPECT(result.error() == HostFunctionError::INVALID_PARAMS); } // Should fail for invalid nftId @@ -1825,15 +1508,13 @@ struct HostFuncImpl_test : public beast::unit_test::suite auto const badId = token::getNextID(env, alice, 0u, 1u); auto const result = hfs.getNFT(alice.id(), badId); if (BEAST_EXPECT(!result.has_value())) - BEAST_EXPECT( - result.error() == HostFunctionError::LEDGER_OBJ_NOT_FOUND); + BEAST_EXPECT(result.error() == HostFunctionError::LEDGER_OBJ_NOT_FOUND); } { auto const result = hfs.getNFT(alice.id(), nftId2); if (BEAST_EXPECT(!result.has_value())) - BEAST_EXPECT( - result.error() == HostFunctionError::FIELD_NOT_FOUND); + BEAST_EXPECT(result.error() == HostFunctionError::FIELD_NOT_FOUND); } } @@ -1853,8 +1534,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite OpenView ov{*env.current()}; ApplyContext ac = createApplyContext(env, ov); - auto const dummyEscrow = - keylet::escrow(env.master, env.seq(env.master)); + auto const dummyEscrow = keylet::escrow(env.master, env.seq(env.master)); WasmHostFunctionsImpl hfs(ac, dummyEscrow); // Should succeed for valid NFT id @@ -1868,8 +1548,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite { auto const result = hfs.getNFTIssuer(uint256()); if (BEAST_EXPECT(!result.has_value())) - BEAST_EXPECT( - result.error() == HostFunctionError::INVALID_PARAMS); + BEAST_EXPECT(result.error() == HostFunctionError::INVALID_PARAMS); } } @@ -1889,8 +1568,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite OpenView ov{*env.current()}; ApplyContext ac = createApplyContext(env, ov); - auto const dummyEscrow = - keylet::escrow(env.master, env.seq(env.master)); + auto const dummyEscrow = keylet::escrow(env.master, env.seq(env.master)); WasmHostFunctionsImpl hfs(ac, dummyEscrow); auto const result = hfs.getNFTTaxon(nftId); @@ -1907,16 +1585,14 @@ struct HostFuncImpl_test : public beast::unit_test::suite Env env{*this}; // Mint NFT with default flags - uint256 const nftId = - token::getNextID(env, env.master, 0u, tfTransferable); + uint256 const nftId = token::getNextID(env, env.master, 0u, tfTransferable); env(token::mint(env.master, 0), txflags(tfTransferable)); env.close(); OpenView ov{*env.current()}; ApplyContext ac = createApplyContext(env, ov); - auto const dummyEscrow = - keylet::escrow(env.master, env.seq(env.master)); + auto const dummyEscrow = keylet::escrow(env.master, env.seq(env.master)); WasmHostFunctionsImpl hfs(ac, dummyEscrow); { @@ -1942,18 +1618,14 @@ struct HostFuncImpl_test : public beast::unit_test::suite Env env{*this}; uint16_t const transferFee = 250; - uint256 const nftId = - token::getNextID(env, env.master, 0u, tfTransferable, transferFee); - env(token::mint(env.master, 0), - token::xferFee(transferFee), - txflags(tfTransferable)); + uint256 const nftId = token::getNextID(env, env.master, 0u, tfTransferable, transferFee); + env(token::mint(env.master, 0), token::xferFee(transferFee), txflags(tfTransferable)); env.close(); OpenView ov{*env.current()}; ApplyContext ac = createApplyContext(env, ov); - auto const dummyEscrow = - keylet::escrow(env.master, env.seq(env.master)); + auto const dummyEscrow = keylet::escrow(env.master, env.seq(env.master)); WasmHostFunctionsImpl hfs(ac, dummyEscrow); { @@ -1987,8 +1659,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite OpenView ov{*env.current()}; ApplyContext ac = createApplyContext(env, ov); - auto const dummyEscrow = - keylet::escrow(env.master, env.seq(env.master)); + auto const dummyEscrow = keylet::escrow(env.master, env.seq(env.master)); WasmHostFunctionsImpl hfs(ac, dummyEscrow); { @@ -2018,8 +1689,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite beast::Journal jlog{sink}; ApplyContext ac = createApplyContext(env, ov, jlog); - auto const dummyEscrow = - keylet::escrow(env.master, env.seq(env.master)); + auto const dummyEscrow = keylet::escrow(env.master, env.seq(env.master)); WasmHostFunctionsImpl hfs(ac, dummyEscrow); std::string msg = "test trace"; @@ -2041,8 +1711,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite auto const messages = sink.messages().str(); std::string hex; hex.reserve(data.size() * 2); - boost::algorithm::hex( - data.begin(), data.end(), std::back_inserter(hex)); + boost::algorithm::hex(data.begin(), data.end(), std::back_inserter(hex)); BEAST_EXPECT(messages.find(msg) != std::string::npos); BEAST_EXPECT(messages.find(hex) != std::string::npos); } @@ -2056,8 +1725,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite beast::Journal jlog{sink}; ApplyContext ac = createApplyContext(env, ov, jlog); - auto const dummyEscrow = - keylet::escrow(env.master, env.seq(env.master)); + auto const dummyEscrow = keylet::escrow(env.master, env.seq(env.master)); WasmHostFunctionsImpl hfs(ac, dummyEscrow); std::string msg = "test trace"; @@ -2083,8 +1751,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite beast::Journal jlog{sink}; ApplyContext ac = createApplyContext(env, ov, jlog); - auto const dummyEscrow = - keylet::escrow(env.master, env.seq(env.master)); + auto const dummyEscrow = keylet::escrow(env.master, env.seq(env.master)); WasmHostFunctionsImpl hfs(ac, dummyEscrow); std::string msg = "trace number"; @@ -2095,8 +1762,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite BEAST_EXPECT(result.value() == 0); auto const messages = sink.messages().str(); BEAST_EXPECT(messages.find(msg) != std::string::npos); - BEAST_EXPECT( - messages.find(std::to_string(num)) != std::string::npos); + BEAST_EXPECT(messages.find(std::to_string(num)) != std::string::npos); } } @@ -2108,8 +1774,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite beast::Journal jlog{sink}; ApplyContext ac = createApplyContext(env, ov, jlog); - auto const dummyEscrow = - keylet::escrow(env.master, env.seq(env.master)); + auto const dummyEscrow = keylet::escrow(env.master, env.seq(env.master)); WasmHostFunctionsImpl hfs(ac, dummyEscrow); std::string msg = "trace number"; @@ -2134,8 +1799,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite beast::Journal jlog{sink}; ApplyContext ac = createApplyContext(env, ov, jlog); - auto const dummyEscrow = - keylet::escrow(env.master, env.seq(env.master)); + auto const dummyEscrow = keylet::escrow(env.master, env.seq(env.master)); WasmHostFunctionsImpl hfs(ac, dummyEscrow); std::string msg = "trace account"; @@ -2145,8 +1809,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite BEAST_EXPECT(result.value() == 0); auto const messages = sink.messages().str(); BEAST_EXPECT(messages.find(msg) != std::string::npos); - BEAST_EXPECT( - messages.find(env.master.human()) != std::string::npos); + BEAST_EXPECT(messages.find(env.master.human()) != std::string::npos); } } @@ -2158,8 +1821,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite beast::Journal jlog{sink}; ApplyContext ac = createApplyContext(env, ov, jlog); - auto const dummyEscrow = - keylet::escrow(env.master, env.seq(env.master)); + auto const dummyEscrow = keylet::escrow(env.master, env.seq(env.master)); WasmHostFunctionsImpl hfs(ac, dummyEscrow); std::string msg = "trace account"; auto const result = hfs.traceAccount(msg, env.master.id()); @@ -2182,8 +1844,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite beast::Journal jlog{sink}; ApplyContext ac = createApplyContext(env, ov, jlog); - auto const dummyEscrow = - keylet::escrow(env.master, env.seq(env.master)); + auto const dummyEscrow = keylet::escrow(env.master, env.seq(env.master)); WasmHostFunctionsImpl hfs(ac, dummyEscrow); std::string msg = "trace amount"; @@ -2195,9 +1856,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite BEAST_EXPECT(*result == 0); auto const messages = sink.messages().str(); BEAST_EXPECT(messages.find(msg) != std::string::npos); - BEAST_EXPECT( - messages.find(amount.getFullText()) != - std::string::npos); + BEAST_EXPECT(messages.find(amount.getFullText()) != std::string::npos); } } @@ -2231,8 +1890,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite beast::Journal jlog{sink}; ApplyContext ac = createApplyContext(env, ov, jlog); - auto const dummyEscrow = - keylet::escrow(env.master, env.seq(env.master)); + auto const dummyEscrow = keylet::escrow(env.master, env.seq(env.master)); WasmHostFunctionsImpl hfs(ac, dummyEscrow); std::string msg = "trace amount"; @@ -2280,8 +1938,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite OpenView ov{*env.current()}; ApplyContext ac = createApplyContext(env, ov); - auto const dummyEscrow = - keylet::escrow(env.master, env.seq(env.master)); + auto const dummyEscrow = keylet::escrow(env.master, env.seq(env.master)); WasmHostFunctionsImpl hfs(ac, dummyEscrow); std::string msg = "trace float"; @@ -2305,8 +1962,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite beast::Journal jlog{sink}; ApplyContext ac = createApplyContext(env, ov, jlog); - auto const dummyEscrow = - keylet::escrow(env.master, env.seq(env.master)); + auto const dummyEscrow = keylet::escrow(env.master, env.seq(env.master)); WasmHostFunctionsImpl hfs(ac, dummyEscrow); std::string msg = "trace float"; @@ -2327,29 +1983,21 @@ struct HostFuncImpl_test : public beast::unit_test::suite Env env{*this}; OpenView ov{*env.current()}; ApplyContext ac = createApplyContext(env, ov); - auto const dummyEscrow = - keylet::escrow(env.master, env.seq(env.master)); + auto const dummyEscrow = keylet::escrow(env.master, env.seq(env.master)); WasmHostFunctionsImpl hfs(ac, dummyEscrow); { - auto const result = - hfs.floatFromInt(std::numeric_limits::min(), -1); - BEAST_EXPECT(!result) && - BEAST_EXPECT( - result.error() == HostFunctionError::FLOAT_INPUT_MALFORMED); + auto const result = hfs.floatFromInt(std::numeric_limits::min(), -1); + BEAST_EXPECT(!result) && BEAST_EXPECT(result.error() == HostFunctionError::FLOAT_INPUT_MALFORMED); } { - auto const result = - hfs.floatFromInt(std::numeric_limits::min(), 4); - BEAST_EXPECT(!result) && - BEAST_EXPECT( - result.error() == HostFunctionError::FLOAT_INPUT_MALFORMED); + auto const result = hfs.floatFromInt(std::numeric_limits::min(), 4); + BEAST_EXPECT(!result) && BEAST_EXPECT(result.error() == HostFunctionError::FLOAT_INPUT_MALFORMED); } { - auto const result = - hfs.floatFromInt(std::numeric_limits::min(), 0); + auto const result = hfs.floatFromInt(std::numeric_limits::min(), 0); BEAST_EXPECT(result) && BEAST_EXPECT(*result == floatIntMin); } @@ -2359,8 +2007,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite } { - auto const result = - hfs.floatFromInt(std::numeric_limits::max(), 0); + auto const result = hfs.floatFromInt(std::numeric_limits::max(), 0); BEAST_EXPECT(result) && BEAST_EXPECT(*result == floatIntMax); } } @@ -2374,24 +2021,17 @@ struct HostFuncImpl_test : public beast::unit_test::suite Env env{*this}; OpenView ov{*env.current()}; ApplyContext ac = createApplyContext(env, ov); - auto const dummyEscrow = - keylet::escrow(env.master, env.seq(env.master)); + auto const dummyEscrow = keylet::escrow(env.master, env.seq(env.master)); WasmHostFunctionsImpl hfs(ac, dummyEscrow); { - auto const result = - hfs.floatFromUint(std::numeric_limits::min(), -1); - BEAST_EXPECT(!result) && - BEAST_EXPECT( - result.error() == HostFunctionError::FLOAT_INPUT_MALFORMED); + auto const result = hfs.floatFromUint(std::numeric_limits::min(), -1); + BEAST_EXPECT(!result) && BEAST_EXPECT(result.error() == HostFunctionError::FLOAT_INPUT_MALFORMED); } { - auto const result = - hfs.floatFromUint(std::numeric_limits::min(), 4); - BEAST_EXPECT(!result) && - BEAST_EXPECT( - result.error() == HostFunctionError::FLOAT_INPUT_MALFORMED); + auto const result = hfs.floatFromUint(std::numeric_limits::min(), 4); + BEAST_EXPECT(!result) && BEAST_EXPECT(result.error() == HostFunctionError::FLOAT_INPUT_MALFORMED); } { @@ -2400,8 +2040,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite } { - auto const result = - hfs.floatFromUint(std::numeric_limits::max(), 0); + auto const result = hfs.floatFromUint(std::numeric_limits::max(), 0); BEAST_EXPECT(result) && BEAST_EXPECT(*result == floatUIntMax); } } @@ -2416,36 +2055,26 @@ struct HostFuncImpl_test : public beast::unit_test::suite Env env{*this}; OpenView ov{*env.current()}; ApplyContext ac = createApplyContext(env, ov); - auto const dummyEscrow = - keylet::escrow(env.master, env.seq(env.master)); + auto const dummyEscrow = keylet::escrow(env.master, env.seq(env.master)); WasmHostFunctionsImpl hfs(ac, dummyEscrow); { auto const result = hfs.floatSet(1, 0, -1); - BEAST_EXPECT(!result) && - BEAST_EXPECT( - result.error() == HostFunctionError::FLOAT_INPUT_MALFORMED); + BEAST_EXPECT(!result) && BEAST_EXPECT(result.error() == HostFunctionError::FLOAT_INPUT_MALFORMED); } { auto const result = hfs.floatSet(1, 0, 4); - BEAST_EXPECT(!result) && - BEAST_EXPECT( - result.error() == HostFunctionError::FLOAT_INPUT_MALFORMED); + BEAST_EXPECT(!result) && BEAST_EXPECT(result.error() == HostFunctionError::FLOAT_INPUT_MALFORMED); } { - auto const result = - hfs.floatSet(1, wasmMaxExponent + normalExp + 1, 0); - BEAST_EXPECT(!result) && - BEAST_EXPECT( - result.error() == - HostFunctionError::FLOAT_COMPUTATION_ERROR); + auto const result = hfs.floatSet(1, wasmMaxExponent + normalExp + 1, 0); + BEAST_EXPECT(!result) && BEAST_EXPECT(result.error() == HostFunctionError::FLOAT_COMPUTATION_ERROR); } { - auto const result = - hfs.floatSet(1, wasmMinExponent + normalExp - 1, 0); + auto const result = hfs.floatSet(1, wasmMinExponent + normalExp - 1, 0); BEAST_EXPECT(result) && BEAST_EXPECT(*result == floatIntZero); } @@ -2455,20 +2084,17 @@ struct HostFuncImpl_test : public beast::unit_test::suite } { - auto const result = - hfs.floatSet(-1, wasmMaxExponent + normalExp, 0); + auto const result = hfs.floatSet(-1, wasmMaxExponent + normalExp, 0); BEAST_EXPECT(result) && BEAST_EXPECT(*result == floatMinusMaxExp); } { - auto const result = - hfs.floatSet(1, wasmMaxExponent + normalExp - 1, 0); + auto const result = hfs.floatSet(1, wasmMaxExponent + normalExp - 1, 0); BEAST_EXPECT(result) && BEAST_EXPECT(*result == floatPreMaxExp); } { - auto const result = - hfs.floatSet(STAmount::cMaxValue, wasmMaxExponent, 0); + auto const result = hfs.floatSet(STAmount::cMaxValue, wasmMaxExponent, 0); BEAST_EXPECT(result) && BEAST_EXPECT(*result == floatMaxIOU); } @@ -2492,31 +2118,22 @@ struct HostFuncImpl_test : public beast::unit_test::suite Env env{*this}; OpenView ov{*env.current()}; ApplyContext ac = createApplyContext(env, ov); - auto const dummyEscrow = - keylet::escrow(env.master, env.seq(env.master)); + auto const dummyEscrow = keylet::escrow(env.master, env.seq(env.master)); WasmHostFunctionsImpl hfs(ac, dummyEscrow); { auto const result = hfs.floatCompare(Slice(), Slice()); - BEAST_EXPECT(!result) && - BEAST_EXPECT( - result.error() == HostFunctionError::FLOAT_INPUT_MALFORMED); + BEAST_EXPECT(!result) && BEAST_EXPECT(result.error() == HostFunctionError::FLOAT_INPUT_MALFORMED); } { - auto const result = - hfs.floatCompare(makeSlice(floatInvalidZero), Slice()); - BEAST_EXPECT(!result) && - BEAST_EXPECT( - result.error() == HostFunctionError::FLOAT_INPUT_MALFORMED); + auto const result = hfs.floatCompare(makeSlice(floatInvalidZero), Slice()); + BEAST_EXPECT(!result) && BEAST_EXPECT(result.error() == HostFunctionError::FLOAT_INPUT_MALFORMED); } { - auto const result = - hfs.floatCompare(makeSlice(float1), makeSlice(invalid)); - BEAST_EXPECT( - !result && - result.error() == HostFunctionError::FLOAT_INPUT_MALFORMED); + auto const result = hfs.floatCompare(makeSlice(float1), makeSlice(invalid)); + BEAST_EXPECT(!result && result.error() == HostFunctionError::FLOAT_INPUT_MALFORMED); } { @@ -2524,28 +2141,22 @@ struct HostFuncImpl_test : public beast::unit_test::suite // exp = 81 + 97 = 178 x[1] |= 0x80; x[1] &= 0xBF; - auto const result = - hfs.floatCompare(makeSlice(x), makeSlice(floatMaxExp)); - BEAST_EXPECT( - !result && - result.error() == HostFunctionError::FLOAT_INPUT_MALFORMED); + auto const result = hfs.floatCompare(makeSlice(x), makeSlice(floatMaxExp)); + BEAST_EXPECT(!result && result.error() == HostFunctionError::FLOAT_INPUT_MALFORMED); } { - auto const result = hfs.floatCompare( - makeSlice(floatIntMin), makeSlice(floatIntZero)); + auto const result = hfs.floatCompare(makeSlice(floatIntMin), makeSlice(floatIntZero)); BEAST_EXPECT(result) && BEAST_EXPECT(*result == 2); } { - auto const result = hfs.floatCompare( - makeSlice(floatIntMax), makeSlice(floatIntZero)); + auto const result = hfs.floatCompare(makeSlice(floatIntMax), makeSlice(floatIntZero)); BEAST_EXPECT(result) && BEAST_EXPECT(*result == 1); } { - auto const result = - hfs.floatCompare(makeSlice(float1), makeSlice(float1)); + auto const result = hfs.floatCompare(makeSlice(float1), makeSlice(float1)); BEAST_EXPECT(result) && BEAST_EXPECT(*result == 0); } } @@ -2559,50 +2170,36 @@ struct HostFuncImpl_test : public beast::unit_test::suite Env env{*this}; OpenView ov{*env.current()}; ApplyContext ac = createApplyContext(env, ov); - auto const dummyEscrow = - keylet::escrow(env.master, env.seq(env.master)); + auto const dummyEscrow = keylet::escrow(env.master, env.seq(env.master)); WasmHostFunctionsImpl hfs(ac, dummyEscrow); { auto const result = hfs.floatAdd(Slice(), Slice(), -1); - BEAST_EXPECT(!result) && - BEAST_EXPECT( - result.error() == HostFunctionError::FLOAT_INPUT_MALFORMED); + BEAST_EXPECT(!result) && BEAST_EXPECT(result.error() == HostFunctionError::FLOAT_INPUT_MALFORMED); } { auto const result = hfs.floatAdd(Slice(), Slice(), 0); - BEAST_EXPECT(!result) && - BEAST_EXPECT( - result.error() == HostFunctionError::FLOAT_INPUT_MALFORMED); + BEAST_EXPECT(!result) && BEAST_EXPECT(result.error() == HostFunctionError::FLOAT_INPUT_MALFORMED); } { - auto const result = - hfs.floatAdd(makeSlice(float1), makeSlice(invalid), 0); - BEAST_EXPECT(!result) && - BEAST_EXPECT( - result.error() == HostFunctionError::FLOAT_INPUT_MALFORMED); + auto const result = hfs.floatAdd(makeSlice(float1), makeSlice(invalid), 0); + BEAST_EXPECT(!result) && BEAST_EXPECT(result.error() == HostFunctionError::FLOAT_INPUT_MALFORMED); } { - auto const result = - hfs.floatAdd(makeSlice(floatMaxIOU), makeSlice(floatMaxExp), 0); - BEAST_EXPECT(!result) && - BEAST_EXPECT( - result.error() == - HostFunctionError::FLOAT_COMPUTATION_ERROR); + auto const result = hfs.floatAdd(makeSlice(floatMaxIOU), makeSlice(floatMaxExp), 0); + BEAST_EXPECT(!result) && BEAST_EXPECT(result.error() == HostFunctionError::FLOAT_COMPUTATION_ERROR); } { - auto const result = hfs.floatAdd( - makeSlice(floatIntMin), makeSlice(floatIntZero), 0); + auto const result = hfs.floatAdd(makeSlice(floatIntMin), makeSlice(floatIntZero), 0); BEAST_EXPECT(result) && BEAST_EXPECT(*result == floatIntMin); } { - auto const result = - hfs.floatAdd(makeSlice(floatIntMax), makeSlice(floatIntMin), 0); + auto const result = hfs.floatAdd(makeSlice(floatIntMax), makeSlice(floatIntMin), 0); BEAST_EXPECT(result) && BEAST_EXPECT(*result == floatIntZero); } } @@ -2616,50 +2213,36 @@ struct HostFuncImpl_test : public beast::unit_test::suite Env env{*this}; OpenView ov{*env.current()}; ApplyContext ac = createApplyContext(env, ov); - auto const dummyEscrow = - keylet::escrow(env.master, env.seq(env.master)); + auto const dummyEscrow = keylet::escrow(env.master, env.seq(env.master)); WasmHostFunctionsImpl hfs(ac, dummyEscrow); { auto const result = hfs.floatSubtract(Slice(), Slice(), -1); - BEAST_EXPECT(!result) && - BEAST_EXPECT( - result.error() == HostFunctionError::FLOAT_INPUT_MALFORMED); + BEAST_EXPECT(!result) && BEAST_EXPECT(result.error() == HostFunctionError::FLOAT_INPUT_MALFORMED); } { auto const result = hfs.floatSubtract(Slice(), Slice(), 0); - BEAST_EXPECT(!result) && - BEAST_EXPECT( - result.error() == HostFunctionError::FLOAT_INPUT_MALFORMED); + BEAST_EXPECT(!result) && BEAST_EXPECT(result.error() == HostFunctionError::FLOAT_INPUT_MALFORMED); } { - auto const result = - hfs.floatSubtract(makeSlice(float1), makeSlice(invalid), 0); - BEAST_EXPECT(!result) && - BEAST_EXPECT( - result.error() == HostFunctionError::FLOAT_INPUT_MALFORMED); + auto const result = hfs.floatSubtract(makeSlice(float1), makeSlice(invalid), 0); + BEAST_EXPECT(!result) && BEAST_EXPECT(result.error() == HostFunctionError::FLOAT_INPUT_MALFORMED); } { - auto const result = hfs.floatSubtract( - makeSlice(floatMaxIOU), makeSlice(floatMinusMaxExp), 0); - BEAST_EXPECT(!result) && - BEAST_EXPECT( - result.error() == - HostFunctionError::FLOAT_COMPUTATION_ERROR); + auto const result = hfs.floatSubtract(makeSlice(floatMaxIOU), makeSlice(floatMinusMaxExp), 0); + BEAST_EXPECT(!result) && BEAST_EXPECT(result.error() == HostFunctionError::FLOAT_COMPUTATION_ERROR); } { - auto const result = hfs.floatSubtract( - makeSlice(floatIntMin), makeSlice(floatIntZero), 0); + auto const result = hfs.floatSubtract(makeSlice(floatIntMin), makeSlice(floatIntZero), 0); BEAST_EXPECT(result) && BEAST_EXPECT(*result == floatIntMin); } { - auto const result = hfs.floatSubtract( - makeSlice(floatIntZero), makeSlice(float1), 0); + auto const result = hfs.floatSubtract(makeSlice(floatIntZero), makeSlice(float1), 0); BEAST_EXPECT(result) && BEAST_EXPECT(*result == floatMinus1); } } @@ -2673,56 +2256,41 @@ struct HostFuncImpl_test : public beast::unit_test::suite Env env{*this}; OpenView ov{*env.current()}; ApplyContext ac = createApplyContext(env, ov); - auto const dummyEscrow = - keylet::escrow(env.master, env.seq(env.master)); + auto const dummyEscrow = keylet::escrow(env.master, env.seq(env.master)); WasmHostFunctionsImpl hfs(ac, dummyEscrow); { auto const result = hfs.floatMultiply(Slice(), Slice(), -1); - BEAST_EXPECT(!result) && - BEAST_EXPECT( - result.error() == HostFunctionError::FLOAT_INPUT_MALFORMED); + BEAST_EXPECT(!result) && BEAST_EXPECT(result.error() == HostFunctionError::FLOAT_INPUT_MALFORMED); } { auto const result = hfs.floatMultiply(Slice(), Slice(), 0); - BEAST_EXPECT(!result) && - BEAST_EXPECT( - result.error() == HostFunctionError::FLOAT_INPUT_MALFORMED); + BEAST_EXPECT(!result) && BEAST_EXPECT(result.error() == HostFunctionError::FLOAT_INPUT_MALFORMED); } { - auto const result = - hfs.floatMultiply(makeSlice(float1), makeSlice(invalid), 0); - BEAST_EXPECT(!result) && - BEAST_EXPECT( - result.error() == HostFunctionError::FLOAT_INPUT_MALFORMED); + auto const result = hfs.floatMultiply(makeSlice(float1), makeSlice(invalid), 0); + BEAST_EXPECT(!result) && BEAST_EXPECT(result.error() == HostFunctionError::FLOAT_INPUT_MALFORMED); } { - auto const result = hfs.floatMultiply( - makeSlice(floatMaxIOU), makeSlice(float1More), 0); - BEAST_EXPECT(!result) && - BEAST_EXPECT( - result.error() == - HostFunctionError::FLOAT_COMPUTATION_ERROR); + auto const result = hfs.floatMultiply(makeSlice(floatMaxIOU), makeSlice(float1More), 0); + BEAST_EXPECT(!result) && BEAST_EXPECT(result.error() == HostFunctionError::FLOAT_COMPUTATION_ERROR); } { - auto const result = - hfs.floatMultiply(makeSlice(float1), makeSlice(float1), 0); + auto const result = hfs.floatMultiply(makeSlice(float1), makeSlice(float1), 0); BEAST_EXPECT(result) && BEAST_EXPECT(*result == float1); } { - auto const result = hfs.floatMultiply( - makeSlice(floatIntZero), makeSlice(floatMaxIOU), 0); + auto const result = hfs.floatMultiply(makeSlice(floatIntZero), makeSlice(floatMaxIOU), 0); BEAST_EXPECT(result) && BEAST_EXPECT(*result == floatIntZero); } { - auto const result = hfs.floatMultiply( - makeSlice(float10), makeSlice(floatPreMaxExp), 0); + auto const result = hfs.floatMultiply(makeSlice(float10), makeSlice(floatPreMaxExp), 0); BEAST_EXPECT(result) && BEAST_EXPECT(*result == floatMaxExp); } } @@ -2736,64 +2304,45 @@ struct HostFuncImpl_test : public beast::unit_test::suite Env env{*this}; OpenView ov{*env.current()}; ApplyContext ac = createApplyContext(env, ov); - auto const dummyEscrow = - keylet::escrow(env.master, env.seq(env.master)); + auto const dummyEscrow = keylet::escrow(env.master, env.seq(env.master)); WasmHostFunctionsImpl hfs(ac, dummyEscrow); { auto const result = hfs.floatDivide(Slice(), Slice(), -1); - BEAST_EXPECT(!result) && - BEAST_EXPECT( - result.error() == HostFunctionError::FLOAT_INPUT_MALFORMED); + BEAST_EXPECT(!result) && BEAST_EXPECT(result.error() == HostFunctionError::FLOAT_INPUT_MALFORMED); } { auto const result = hfs.floatDivide(Slice(), Slice(), 0); - BEAST_EXPECT(!result) && - BEAST_EXPECT( - result.error() == HostFunctionError::FLOAT_INPUT_MALFORMED); + BEAST_EXPECT(!result) && BEAST_EXPECT(result.error() == HostFunctionError::FLOAT_INPUT_MALFORMED); } { - auto const result = - hfs.floatDivide(makeSlice(float1), makeSlice(invalid), 0); - BEAST_EXPECT(!result) && - BEAST_EXPECT( - result.error() == HostFunctionError::FLOAT_INPUT_MALFORMED); + auto const result = hfs.floatDivide(makeSlice(float1), makeSlice(invalid), 0); + BEAST_EXPECT(!result) && BEAST_EXPECT(result.error() == HostFunctionError::FLOAT_INPUT_MALFORMED); } { - auto const result = - hfs.floatDivide(makeSlice(float1), makeSlice(floatIntZero), 0); - BEAST_EXPECT(!result) && - BEAST_EXPECT( - result.error() == - HostFunctionError::FLOAT_COMPUTATION_ERROR); + auto const result = hfs.floatDivide(makeSlice(float1), makeSlice(floatIntZero), 0); + BEAST_EXPECT(!result) && BEAST_EXPECT(result.error() == HostFunctionError::FLOAT_COMPUTATION_ERROR); } { - auto const y = hfs.floatSet( - STAmount::cMaxValue, -normalExp - 1, 0); // 0.9999999... + auto const y = hfs.floatSet(STAmount::cMaxValue, -normalExp - 1, 0); // 0.9999999... if (BEAST_EXPECT(y)) { - auto const result = - hfs.floatDivide(makeSlice(floatMaxIOU), makeSlice(*y), 0); - BEAST_EXPECT(!result) && - BEAST_EXPECT( - result.error() == - HostFunctionError::FLOAT_COMPUTATION_ERROR); + auto const result = hfs.floatDivide(makeSlice(floatMaxIOU), makeSlice(*y), 0); + BEAST_EXPECT(!result) && BEAST_EXPECT(result.error() == HostFunctionError::FLOAT_COMPUTATION_ERROR); } } { - auto const result = - hfs.floatDivide(makeSlice(floatIntZero), makeSlice(float1), 0); + auto const result = hfs.floatDivide(makeSlice(floatIntZero), makeSlice(float1), 0); BEAST_EXPECT(result) && BEAST_EXPECT(*result == floatIntZero); } { - auto const result = - hfs.floatDivide(makeSlice(floatMaxExp), makeSlice(float10), 0); + auto const result = hfs.floatDivide(makeSlice(floatMaxExp), makeSlice(float10), 0); BEAST_EXPECT(result) && BEAST_EXPECT(*result == floatPreMaxExp); } } @@ -2807,29 +2356,22 @@ struct HostFuncImpl_test : public beast::unit_test::suite Env env{*this}; OpenView ov{*env.current()}; ApplyContext ac = createApplyContext(env, ov); - auto const dummyEscrow = - keylet::escrow(env.master, env.seq(env.master)); + auto const dummyEscrow = keylet::escrow(env.master, env.seq(env.master)); WasmHostFunctionsImpl hfs(ac, dummyEscrow); { auto const result = hfs.floatRoot(Slice(), 2, -1); - BEAST_EXPECT(!result) && - BEAST_EXPECT( - result.error() == HostFunctionError::FLOAT_INPUT_MALFORMED); + BEAST_EXPECT(!result) && BEAST_EXPECT(result.error() == HostFunctionError::FLOAT_INPUT_MALFORMED); } { auto const result = hfs.floatRoot(makeSlice(invalid), 3, 0); - BEAST_EXPECT(!result) && - BEAST_EXPECT( - result.error() == HostFunctionError::FLOAT_INPUT_MALFORMED); + BEAST_EXPECT(!result) && BEAST_EXPECT(result.error() == HostFunctionError::FLOAT_INPUT_MALFORMED); } { auto const result = hfs.floatRoot(makeSlice(float1), -2, 0); - BEAST_EXPECT(!result) && - BEAST_EXPECT( - result.error() == HostFunctionError::FLOAT_INPUT_MALFORMED); + BEAST_EXPECT(!result) && BEAST_EXPECT(result.error() == HostFunctionError::FLOAT_INPUT_MALFORMED); } { @@ -2880,52 +2422,37 @@ struct HostFuncImpl_test : public beast::unit_test::suite Env env{*this}; OpenView ov{*env.current()}; ApplyContext ac = createApplyContext(env, ov); - auto const dummyEscrow = - keylet::escrow(env.master, env.seq(env.master)); + auto const dummyEscrow = keylet::escrow(env.master, env.seq(env.master)); WasmHostFunctionsImpl hfs(ac, dummyEscrow); { auto const result = hfs.floatPower(Slice(), 2, -1); - BEAST_EXPECT(!result) && - BEAST_EXPECT( - result.error() == HostFunctionError::FLOAT_INPUT_MALFORMED); + BEAST_EXPECT(!result) && BEAST_EXPECT(result.error() == HostFunctionError::FLOAT_INPUT_MALFORMED); } { auto const result = hfs.floatPower(makeSlice(invalid), 3, 0); - BEAST_EXPECT(!result) && - BEAST_EXPECT( - result.error() == HostFunctionError::FLOAT_INPUT_MALFORMED); + BEAST_EXPECT(!result) && BEAST_EXPECT(result.error() == HostFunctionError::FLOAT_INPUT_MALFORMED); } { auto const result = hfs.floatPower(makeSlice(float1), -2, 0); - BEAST_EXPECT(!result) && - BEAST_EXPECT( - result.error() == HostFunctionError::FLOAT_INPUT_MALFORMED); + BEAST_EXPECT(!result) && BEAST_EXPECT(result.error() == HostFunctionError::FLOAT_INPUT_MALFORMED); } { auto const result = hfs.floatPower(makeSlice(floatMaxIOU), 2, 0); - BEAST_EXPECT(!result) && - BEAST_EXPECT( - result.error() == - HostFunctionError::FLOAT_COMPUTATION_ERROR); + BEAST_EXPECT(!result) && BEAST_EXPECT(result.error() == HostFunctionError::FLOAT_COMPUTATION_ERROR); } { auto const result = hfs.floatPower(makeSlice(floatMaxIOU), 81, 0); - BEAST_EXPECT(!result) && - BEAST_EXPECT( - result.error() == HostFunctionError::FLOAT_INPUT_MALFORMED); + BEAST_EXPECT(!result) && BEAST_EXPECT(result.error() == HostFunctionError::FLOAT_INPUT_MALFORMED); } { auto const result = hfs.floatPower(makeSlice(floatMaxIOU), 2, 0); - BEAST_EXPECT(!result) && - BEAST_EXPECT( - result.error() == - HostFunctionError::FLOAT_COMPUTATION_ERROR); + BEAST_EXPECT(!result) && BEAST_EXPECT(result.error() == HostFunctionError::FLOAT_COMPUTATION_ERROR); } { @@ -2967,22 +2494,17 @@ struct HostFuncImpl_test : public beast::unit_test::suite Env env{*this}; OpenView ov{*env.current()}; ApplyContext ac = createApplyContext(env, ov); - auto const dummyEscrow = - keylet::escrow(env.master, env.seq(env.master)); + auto const dummyEscrow = keylet::escrow(env.master, env.seq(env.master)); WasmHostFunctionsImpl hfs(ac, dummyEscrow); { auto const result = hfs.floatLog(Slice(), -1); - BEAST_EXPECT(!result) && - BEAST_EXPECT( - result.error() == HostFunctionError::FLOAT_INPUT_MALFORMED); + BEAST_EXPECT(!result) && BEAST_EXPECT(result.error() == HostFunctionError::FLOAT_INPUT_MALFORMED); } { auto const result = hfs.floatLog(makeSlice(invalid), 0); - BEAST_EXPECT(!result) && - BEAST_EXPECT( - result.error() == HostFunctionError::FLOAT_INPUT_MALFORMED); + BEAST_EXPECT(!result) && BEAST_EXPECT(result.error() == HostFunctionError::FLOAT_INPUT_MALFORMED); } // perf test logs @@ -3026,8 +2548,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite // } { - auto const x = - hfs.floatSet(9'500'000'000'000'001, -14, 0); // almost 80+15 + auto const x = hfs.floatSet(9'500'000'000'000'001, -14, 0); // almost 80+15 if (BEAST_EXPECT(x)) { auto const result = hfs.floatLog(makeSlice(floatMaxExp), 0); @@ -3055,9 +2576,8 @@ struct HostFuncImpl_test : public beast::unit_test::suite } { - auto const x = hfs.floatSet(1, -2, 0); // 0.01 - auto const y = - hfs.floatSet(-2'000'000'000'000'000ll, -15, 0); // -2 + auto const x = hfs.floatSet(1, -2, 0); // 0.01 + auto const y = hfs.floatSet(-2'000'000'000'000'000ll, -15, 0); // -2 if (BEAST_EXPECT(x && y)) { auto const result = hfs.floatLog(makeSlice(*x), 0); @@ -3075,8 +2595,7 @@ struct HostFuncImpl_test : public beast::unit_test::suite Env env{*this}; OpenView ov{*env.current()}; ApplyContext ac = createApplyContext(env, ov); - auto const dummyEscrow = - keylet::escrow(env.master, env.seq(env.master)); + auto const dummyEscrow = keylet::escrow(env.master, env.seq(env.master)); WasmHostFunctionsImpl hfs(ac, dummyEscrow); auto const y = hfs.floatSet(20, 0, 0); @@ -3091,19 +2610,13 @@ struct HostFuncImpl_test : public beast::unit_test::suite x[7] = 10; { - auto const result = - hfs.floatCompare(makeSlice(x), makeSlice(float10)); - BEAST_EXPECT( - !result && - result.error() == HostFunctionError::FLOAT_INPUT_MALFORMED); + auto const result = hfs.floatCompare(makeSlice(x), makeSlice(float10)); + BEAST_EXPECT(!result && result.error() == HostFunctionError::FLOAT_INPUT_MALFORMED); } { - auto const result = - hfs.floatAdd(makeSlice(float10), makeSlice(x), 0); - BEAST_EXPECT( - !result && - result.error() == HostFunctionError::FLOAT_INPUT_MALFORMED); + auto const result = hfs.floatAdd(makeSlice(float10), makeSlice(x), 0); + BEAST_EXPECT(!result && result.error() == HostFunctionError::FLOAT_INPUT_MALFORMED); } // MPT @@ -3112,19 +2625,13 @@ struct HostFuncImpl_test : public beast::unit_test::suite x[7] = 10; { - auto const result = - hfs.floatCompare(makeSlice(x), makeSlice(float10)); - BEAST_EXPECT( - !result && - result.error() == HostFunctionError::FLOAT_INPUT_MALFORMED); + auto const result = hfs.floatCompare(makeSlice(x), makeSlice(float10)); + BEAST_EXPECT(!result && result.error() == HostFunctionError::FLOAT_INPUT_MALFORMED); } { - auto const result = - hfs.floatAdd(makeSlice(float10), makeSlice(x), 0); - BEAST_EXPECT( - !result && - result.error() == HostFunctionError::FLOAT_INPUT_MALFORMED); + auto const result = hfs.floatAdd(makeSlice(float10), makeSlice(x), 0); + BEAST_EXPECT(!result && result.error() == HostFunctionError::FLOAT_INPUT_MALFORMED); } testcase("float non-canonical"); @@ -3133,11 +2640,8 @@ struct HostFuncImpl_test : public beast::unit_test::suite Bytes x = float1; *reinterpret_cast(x.data()) = 0x0000C16FF286A3D4ull; { - auto const result = - hfs.floatCompare(makeSlice(x), makeSlice(float1)); - BEAST_EXPECT( - !result && - result.error() == HostFunctionError::FLOAT_INPUT_MALFORMED); + auto const result = hfs.floatCompare(makeSlice(x), makeSlice(float1)); + BEAST_EXPECT(!result && result.error() == HostFunctionError::FLOAT_INPUT_MALFORMED); } } } diff --git a/src/test/app/TestHostFunctions.h b/src/test/app/TestHostFunctions.h index 0938243cff..85f8049e94 100644 --- a/src/test/app/TestHostFunctions.h +++ b/src/test/app/TestHostFunctions.h @@ -19,8 +19,7 @@ struct TestLedgerDataProvider : public HostFunctions void const* rt_ = nullptr; public: - TestLedgerDataProvider(jtx::Env& env) - : HostFunctions(env.journal), env_(env) + TestLedgerDataProvider(jtx::Env& env) : HostFunctions(env.journal), env_(env) { } @@ -52,8 +51,7 @@ struct TestHostFunctions : public HostFunctions void const* rt_ = nullptr; public: - TestHostFunctions(test::jtx::Env& env, int cd = 0) - : HostFunctions(env.journal), env_(env), clock_drift_(cd) + TestHostFunctions(test::jtx::Env& env, int cd = 0) : HostFunctions(env.journal), env_(env), clock_drift_(cd) { accountID_ = env_.master.id(); std::string t = "10000"; @@ -148,8 +146,7 @@ public: return data_; else if (sn == "FinishAfter") { - auto t = - env_.current()->parentCloseTime().time_since_epoch().count(); + auto t = env_.current()->parentCloseTime().time_since_epoch().count(); std::string s = std::to_string(t); return Bytes{s.begin(), s.end()}; } @@ -185,10 +182,9 @@ public: return Bytes(accountID_.begin(), accountID_.end()); } } - uint8_t const a[] = {0x2b, 0x6a, 0x23, 0x2a, 0xa4, 0xc4, 0xbe, 0x41, - 0xbf, 0x49, 0xd2, 0x45, 0x9f, 0xa4, 0xa0, 0x34, - 0x7e, 0x1b, 0x54, 0x3a, 0x4c, 0x92, 0xfc, 0xee, - 0x08, 0x21, 0xc0, 0x20, 0x1e, 0x2e, 0x9a, 0x00}; + uint8_t const a[] = {0x2b, 0x6a, 0x23, 0x2a, 0xa4, 0xc4, 0xbe, 0x41, 0xbf, 0x49, 0xd2, + 0x45, 0x9f, 0xa4, 0xa0, 0x34, 0x7e, 0x1b, 0x54, 0x3a, 0x4c, 0x92, + 0xfc, 0xee, 0x08, 0x21, 0xc0, 0x20, 0x1e, 0x2e, 0x9a, 0x00}; return Bytes(&a[0], &a[sizeof(a)]); } @@ -204,10 +200,9 @@ public: return Bytes(accountID_.begin(), accountID_.end()); } } - uint8_t const a[] = {0x2b, 0x6a, 0x23, 0x2a, 0xa4, 0xc4, 0xbe, 0x41, - 0xbf, 0x49, 0xd2, 0x45, 0x9f, 0xa4, 0xa0, 0x34, - 0x7e, 0x1b, 0x54, 0x3a, 0x4c, 0x92, 0xfc, 0xee, - 0x08, 0x21, 0xc0, 0x20, 0x1e, 0x2e, 0x9a, 0x00}; + uint8_t const a[] = {0x2b, 0x6a, 0x23, 0x2a, 0xa4, 0xc4, 0xbe, 0x41, 0xbf, 0x49, 0xd2, + 0x45, 0x9f, 0xa4, 0xa0, 0x34, 0x7e, 0x1b, 0x54, 0x3a, 0x4c, 0x92, + 0xfc, 0xee, 0x08, 0x21, 0xc0, 0x20, 0x1e, 0x2e, 0x9a, 0x00}; return Bytes(&a[0], &a[sizeof(a)]); } @@ -223,10 +218,9 @@ public: return Bytes(accountID_.begin(), accountID_.end()); } } - uint8_t const a[] = {0x2b, 0x6a, 0x23, 0x2a, 0xa4, 0xc4, 0xbe, 0x41, - 0xbf, 0x49, 0xd2, 0x45, 0x9f, 0xa4, 0xa0, 0x34, - 0x7e, 0x1b, 0x54, 0x3a, 0x4c, 0x92, 0xfc, 0xee, - 0x08, 0x21, 0xc0, 0x20, 0x1e, 0x2e, 0x9a, 0x00}; + uint8_t const a[] = {0x2b, 0x6a, 0x23, 0x2a, 0xa4, 0xc4, 0xbe, 0x41, 0xbf, 0x49, 0xd2, + 0x45, 0x9f, 0xa4, 0xa0, 0x34, 0x7e, 0x1b, 0x54, 0x3a, 0x4c, 0x92, + 0xfc, 0xee, 0x08, 0x21, 0xc0, 0x20, 0x1e, 0x2e, 0x9a, 0x00}; return Bytes(&a[0], &a[sizeof(a)]); } @@ -273,10 +267,7 @@ public: } Expected - checkSignature( - Slice const& message, - Slice const& signature, - Slice const& pubkey) override + checkSignature(Slice const& message, Slice const& signature, Slice const& pubkey) override { return 1; } @@ -308,13 +299,9 @@ public: } Expected - credentialKeylet( - AccountID const& subject, - AccountID const& issuer, - Slice const& credentialType) override + credentialKeylet(AccountID const& subject, AccountID const& issuer, Slice const& credentialType) override { - if (!subject || !issuer || credentialType.empty() || - credentialType.size() > maxCredentialTypeLength) + if (!subject || !issuer || credentialType.empty() || credentialType.size() > maxCredentialTypeLength) return Unexpected(HostFunctionError::INVALID_ACCOUNT); auto const keylet = keylet::credential(subject, issuer, credentialType); return Bytes{keylet.key.begin(), keylet.key.end()}; @@ -403,18 +390,14 @@ public: { if (!asHex) { - log(msg, [&data] { - return std::string_view( - reinterpret_cast(data.data()), data.size()); - }); + log(msg, [&data] { return std::string_view(reinterpret_cast(data.data()), data.size()); }); } else { log(msg, [&data] { std::string hex; hex.reserve(data.size() * 2); - boost::algorithm::hex( - data.begin(), data.end(), std::back_inserter(hex)); + boost::algorithm::hex(data.begin(), data.end(), std::back_inserter(hex)); return hex; }); } @@ -550,10 +533,7 @@ struct PerfHostFunctions : public TestHostFunctions void const* rt_ = nullptr; - PerfHostFunctions( - test::jtx::Env& env, - Keylet const& k, - std::shared_ptr&& tx) + PerfHostFunctions(test::jtx::Env& env, Keylet const& k, std::shared_ptr&& tx) : TestHostFunctions(env), leKey(k), tx_(std::move(tx)) { } @@ -570,8 +550,7 @@ struct PerfHostFunctions : public TestHostFunctions Expected getParentLedgerTime() override { - auto time = - env_.current()->parentCloseTime().time_since_epoch().count(); + auto time = env_.current()->parentCloseTime().time_since_epoch().count(); if (time > std::numeric_limits::max()) return Unexpected(HostFunctionError::INTERNAL); return static_cast(time); @@ -727,16 +706,14 @@ struct PerfHostFunctions : public TestHostFunctions } break; case STI_UINT16: { - auto const& num( - static_cast const*>(obj)); + auto const& num(static_cast const*>(obj)); std::uint16_t const data = num->value(); auto const* b = reinterpret_cast(&data); auto const* e = reinterpret_cast(&data + 1); return Bytes{b, e}; } case STI_UINT32: { - auto const* num( - static_cast const*>(obj)); + auto const* num(static_cast const*>(obj)); std::uint32_t const data = num->value(); auto const* b = reinterpret_cast(&data); auto const* e = reinterpret_cast(&data + 1); @@ -781,8 +758,7 @@ struct PerfHostFunctions : public TestHostFunctions static inline bool noField(STBase const* field) { - return !field || (STI_NOTPRESENT == field->getSType()) || - (STI_UNKNOWN == field->getSType()); + return !field || (STI_NOTPRESENT == field->getSType()) || (STI_UNKNOWN == field->getSType()); } static Expected @@ -791,8 +767,7 @@ struct PerfHostFunctions : public TestHostFunctions if (locator.empty() || (locator.size() & 3)) // must be multiple of 4 return Unexpected(HostFunctionError::LOCATOR_MALFORMED); - int32_t const* locPtr = - reinterpret_cast(locator.data()); + int32_t const* locPtr = reinterpret_cast(locator.data()); int32_t const locSize = locator.size() / 4; STBase const* field = nullptr; auto const& knownSFields = SField::getKnownCodeToField(); @@ -1001,8 +976,7 @@ struct PerfHostFunctions : public TestHostFunctions if (data.size() > maxWasmDataLength) return Unexpected(HostFunctionError::DATA_FIELD_TOO_LARGE); - xrpl::detail::ApplyViewBase v( - env_.app().openLedger().current().get(), tapNONE); + xrpl::detail::ApplyViewBase v(env_.app().openLedger().current().get(), tapNONE); auto sle = v.peek(leKey); if (!sle) @@ -1015,10 +989,7 @@ struct PerfHostFunctions : public TestHostFunctions } Expected - checkSignature( - Slice const& message, - Slice const& signature, - Slice const& pubkey) override + checkSignature(Slice const& message, Slice const& signature, Slice const& pubkey) override { if (!publicKeyType(pubkey)) return Unexpected(HostFunctionError::INVALID_PARAMS); @@ -1067,16 +1038,12 @@ struct PerfHostFunctions : public TestHostFunctions } Expected - credentialKeylet( - AccountID const& subject, - AccountID const& issuer, - Slice const& credentialType) override + credentialKeylet(AccountID const& subject, AccountID const& issuer, Slice const& credentialType) override { if (!subject || !issuer) return Unexpected(HostFunctionError::INVALID_ACCOUNT); - if (credentialType.empty() || - credentialType.size() > maxCredentialTypeLength) + if (credentialType.empty() || credentialType.size() > maxCredentialTypeLength) return Unexpected(HostFunctionError::INVALID_PARAMS); auto const keylet = keylet::credential(subject, issuer, credentialType); @@ -1094,8 +1061,7 @@ struct PerfHostFunctions : public TestHostFunctions } Expected - delegateKeylet(AccountID const& account, AccountID const& authorize) - override + delegateKeylet(AccountID const& account, AccountID const& authorize) override { if (!account || !authorize) return Unexpected(HostFunctionError::INVALID_ACCOUNT); @@ -1106,8 +1072,7 @@ struct PerfHostFunctions : public TestHostFunctions } Expected - depositPreauthKeylet(AccountID const& account, AccountID const& authorize) - override + depositPreauthKeylet(AccountID const& account, AccountID const& authorize) override { if (!account || !authorize) return Unexpected(HostFunctionError::INVALID_ACCOUNT); @@ -1127,10 +1092,7 @@ struct PerfHostFunctions : public TestHostFunctions } Expected - lineKeylet( - AccountID const& account1, - AccountID const& account2, - Currency const& currency) override + lineKeylet(AccountID const& account1, AccountID const& account2, Currency const& currency) override { if (!account1 || !account2) return Unexpected(HostFunctionError::INVALID_ACCOUNT); @@ -1193,10 +1155,7 @@ struct PerfHostFunctions : public TestHostFunctions } Expected - paychanKeylet( - AccountID const& account, - AccountID const& destination, - std::uint32_t seq) override + paychanKeylet(AccountID const& account, AccountID const& destination, std::uint32_t seq) override { if (!account || !destination) return Unexpected(HostFunctionError::INVALID_ACCOUNT); @@ -1207,8 +1166,7 @@ struct PerfHostFunctions : public TestHostFunctions } Expected - permissionedDomainKeylet(AccountID const& account, std::uint32_t seq) - override + permissionedDomainKeylet(AccountID const& account, std::uint32_t seq) override { if (!account) return Unexpected(HostFunctionError::INVALID_ACCOUNT); diff --git a/src/test/app/Wasm_test.cpp b/src/test/app/Wasm_test.cpp index a26328039b..3305ca03b8 100644 --- a/src/test/app/Wasm_test.cpp +++ b/src/test/app/Wasm_test.cpp @@ -60,11 +60,8 @@ struct Wasm_test : public beast::unit_test::suite auto const lineStr = " (" + std::to_string(location.line()) + ")"; if (BEAST_EXPECTS(re.has_value(), transToken(re.error()) + lineStr)) { - BEAST_EXPECTS( - re->result == expectedResult, - std::to_string(re->result) + lineStr); - BEAST_EXPECTS( - re->cost == expectedCost, std::to_string(re->cost) + lineStr); + BEAST_EXPECTS(re->result == expectedResult, std::to_string(re->result) + lineStr); + BEAST_EXPECTS(re->cost == expectedCost, std::to_string(re->cost) + lineStr); } } @@ -111,8 +108,7 @@ struct Wasm_test : public beast::unit_test::suite auto& vm = WasmEngine::instance(); std::shared_ptr imports(std::make_shared()); - WasmImpFunc( - *imports, "func-add", reinterpret_cast(&Add)); + WasmImpFunc(*imports, "func-add", reinterpret_cast(&Add)); auto re = vm.run(wasm, "addTwo", wasmParams(1234, 5678), imports); @@ -164,8 +160,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, ESCROW_FUNCTION_NAME); BEAST_EXPECT(!isTesSuccess(re)); } } @@ -182,18 +177,10 @@ struct Wasm_test : public beast::unit_test::suite Env env{*this}; std::shared_ptr hfs(new TestLedgerDataProvider(env)); auto imports = std::make_shared(); - WASM_IMPORT_FUNC2( - *imports, getLedgerSqn, "get_ledger_sqn", hfs.get(), 33); + WASM_IMPORT_FUNC2(*imports, getLedgerSqn, "get_ledger_sqn", hfs.get(), 33); auto& engine = WasmEngine::instance(); - auto re = engine.run( - ledgerSqnWasm, - ESCROW_FUNCTION_NAME, - {}, - imports, - hfs, - 1'000'000, - env.journal); + auto re = engine.run(ledgerSqnWasm, ESCROW_FUNCTION_NAME, {}, imports, hfs, 1'000'000, env.journal); checkResult(re, 0, 151); @@ -201,8 +188,7 @@ struct Wasm_test : public beast::unit_test::suite env.close(); // empty module - run the same instance - re = engine.run( - {}, ESCROW_FUNCTION_NAME, {}, imports, hfs, 1'000'000, env.journal); + re = engine.run({}, ESCROW_FUNCTION_NAME, {}, imports, hfs, 1'000'000, env.journal); checkResult(re, 5, 190); } @@ -228,8 +214,7 @@ struct Wasm_test : public beast::unit_test::suite auto const sha512Wasm = hexToBytes(sha512PureWasmHex); auto& engine = WasmEngine::instance(); - auto const re = engine.run( - sha512Wasm, "sha512_process", wasmParams(sha512PureWasmHex)); + auto const re = engine.run(sha512Wasm, "sha512_process", wasmParams(sha512PureWasmHex)); checkResult(re, 34'432, 151'155); } @@ -244,9 +229,7 @@ struct Wasm_test : public beast::unit_test::suite Bytes outb; outb.resize(1024); - auto const minsz = std::min( - static_cast(512), - static_cast(b58WasmHex.size())); + auto const minsz = std::min(static_cast(512), static_cast(b58WasmHex.size())); auto const s = std::string_view(b58WasmHex.c_str(), minsz); auto const re = engine.run(b58Wasm, "b58enco", wasmParams(outb, s)); @@ -272,14 +255,7 @@ struct Wasm_test : public beast::unit_test::suite for (auto& i : *imp) i.second.gas = 0; - auto re = engine.run( - allHostFuncWasm, - ESCROW_FUNCTION_NAME, - {}, - imp, - hfs, - 1'000'000, - env.journal); + auto re = engine.run(allHostFuncWasm, ESCROW_FUNCTION_NAME, {}, imp, hfs, 1'000'000, env.journal); checkResult(re, 1, 25'503); @@ -300,14 +276,7 @@ struct Wasm_test : public beast::unit_test::suite std::shared_ptr hfs(new TestHostFunctions(env, 0)); auto const imp = createWasmImport(*hfs); - auto re = engine.run( - allHostFuncWasm, - ESCROW_FUNCTION_NAME, - {}, - imp, - hfs, - 1'000'000, - env.journal); + auto re = engine.run(allHostFuncWasm, ESCROW_FUNCTION_NAME, {}, imp, hfs, 1'000'000, env.journal); checkResult(re, 1, 64'763); @@ -323,20 +292,11 @@ struct Wasm_test : public beast::unit_test::suite std::shared_ptr hfs(new TestHostFunctions(env, 0)); auto const imp = createWasmImport(*hfs); - auto re = engine.run( - allHostFuncWasm, - ESCROW_FUNCTION_NAME, - {}, - imp, - hfs, - 200, - env.journal); + auto re = engine.run(allHostFuncWasm, ESCROW_FUNCTION_NAME, {}, imp, hfs, 200, env.journal); if (BEAST_EXPECT(!re)) { - BEAST_EXPECTS( - re.error() == tecFAILED_PROCESSING, - std::to_string(TERtoInt(re.error()))); + BEAST_EXPECTS(re.error() == tecFAILED_PROCESSING, std::to_string(TERtoInt(re.error()))); } env.close(); @@ -354,16 +314,14 @@ struct Wasm_test : public beast::unit_test::suite Env env{*this}; { std::shared_ptr hfs(new TestHostFunctions(env, 0)); - auto re = runEscrowWasm( - allHFWasm, hfs, ESCROW_FUNCTION_NAME, {}, 100'000); + auto re = runEscrowWasm(allHFWasm, hfs, ESCROW_FUNCTION_NAME, {}, 100'000); checkResult(re, 1, 64'763); } { // max() gas std::shared_ptr hfs(new TestHostFunctions(env, 0)); - auto re = - runEscrowWasm(allHFWasm, hfs, ESCROW_FUNCTION_NAME, {}, -1); + auto re = runEscrowWasm(allHFWasm, hfs, ESCROW_FUNCTION_NAME, {}, -1); checkResult(re, 1, 64'763); } @@ -381,8 +339,7 @@ struct Wasm_test : public beast::unit_test::suite }; std::shared_ptr hfs(new BadTestHostFunctions(env)); - auto re = runEscrowWasm( - allHFWasm, hfs, ESCROW_FUNCTION_NAME, {}, 100'000); + auto re = runEscrowWasm(allHFWasm, hfs, ESCROW_FUNCTION_NAME, {}, 100'000); checkResult(re, -201, 28'148); } @@ -400,8 +357,7 @@ struct Wasm_test : public beast::unit_test::suite }; std::shared_ptr hfs(new BadTestHostFunctions(env)); - auto re = runEscrowWasm( - allHFWasm, hfs, ESCROW_FUNCTION_NAME, {}, 100'000); + auto re = runEscrowWasm(allHFWasm, hfs, ESCROW_FUNCTION_NAME, {}, 100'000); checkResult(re, -201, 28'148); } @@ -409,8 +365,7 @@ struct Wasm_test : public beast::unit_test::suite auto const deepWasm = hexToBytes(deepRecursionHex); - std::shared_ptr hfs( - new TestHostFunctionsSink(env)); + std::shared_ptr hfs(new TestHostFunctionsSink(env)); std::string funcName("finish"); auto re = runEscrowWasm(deepWasm, hfs, funcName, {}, 1'000'000'000); BEAST_EXPECT(!re && re.error()); @@ -418,8 +373,7 @@ struct Wasm_test : public beast::unit_test::suite // << std::endl; auto const& sink = hfs->getSink(); - auto countSubstr = [](std::string const& str, - std::string const& substr) { + auto countSubstr = [](std::string const& str, std::string const& substr) { std::size_t pos = 0; int occurrences = 0; while ((pos = str.find(substr, pos)) != std::string::npos) @@ -431,8 +385,7 @@ struct Wasm_test : public beast::unit_test::suite }; auto const s = sink.messages().str(); - BEAST_EXPECT( - countSubstr(s, "WASMI Error: failure to call func") == 1); + BEAST_EXPECT(countSubstr(s, "WASMI Error: failure to call func") == 1); BEAST_EXPECT(countSubstr(s, "exception: failure") > 0); } @@ -442,8 +395,7 @@ struct Wasm_test : public beast::unit_test::suite std::shared_ptr hfs(new TestHostFunctions(env, 0)); // infinite loop should be caught and fail - auto const re = - runEscrowWasm(infiniteLoopWasm, hfs, funcName, {}, 1'000'000); + auto const re = runEscrowWasm(infiniteLoopWasm, hfs, funcName, {}, 1'000'000); if (BEAST_EXPECT(!re.has_value())) { BEAST_EXPECT(re.error() == tecFAILED_PROCESSING); @@ -455,19 +407,11 @@ struct Wasm_test : public beast::unit_test::suite auto const lgrSqnWasm = hexToBytes(ledgerSqnWasmHex); std::shared_ptr hfs(new TestLedgerDataProvider(env)); std::shared_ptr imports(std::make_shared()); - WASM_IMPORT_FUNC2( - *imports, getLedgerSqn, "get_ledger_sqn2", hfs.get()); + WASM_IMPORT_FUNC2(*imports, getLedgerSqn, "get_ledger_sqn2", hfs.get()); auto& engine = WasmEngine::instance(); - auto re = engine.run( - lgrSqnWasm, - ESCROW_FUNCTION_NAME, - {}, - imports, - hfs, - 1'000'000, - env.journal); + auto re = engine.run(lgrSqnWasm, ESCROW_FUNCTION_NAME, {}, imports, hfs, 1'000'000, env.journal); BEAST_EXPECT(!re); } @@ -477,20 +421,12 @@ struct Wasm_test : public beast::unit_test::suite auto const lgrSqnWasm = hexToBytes(ledgerSqnWasmHex); std::shared_ptr hfs(new TestLedgerDataProvider(env)); std::shared_ptr imports(std::make_shared()); - WASM_IMPORT_FUNC2( - *imports, getLedgerSqn, "get_ledger_sqn", hfs.get()); + WASM_IMPORT_FUNC2(*imports, getLedgerSqn, "get_ledger_sqn", hfs.get()); (*imports)[0].first = nullptr; auto& engine = WasmEngine::instance(); - auto re = engine.run( - lgrSqnWasm, - ESCROW_FUNCTION_NAME, - {}, - imports, - hfs, - 1'000'000, - env.journal); + auto re = engine.run(lgrSqnWasm, ESCROW_FUNCTION_NAME, {}, imports, hfs, 1'000'000, env.journal); BEAST_EXPECT(!re); } @@ -500,12 +436,10 @@ struct Wasm_test : public beast::unit_test::suite auto const lgrSqnWasm = hexToBytes(ledgerSqnWasmHex); std::shared_ptr hfs(new TestLedgerDataProvider(env)); std::shared_ptr imports(std::make_shared()); - WASM_IMPORT_FUNC2( - *imports, getLedgerSqn, "get_ledger_sqn", hfs.get()); + WASM_IMPORT_FUNC2(*imports, getLedgerSqn, "get_ledger_sqn", hfs.get()); auto& engine = WasmEngine::instance(); - auto re = engine.run( - lgrSqnWasm, "func1", {}, imports, hfs, 1'000'000, env.journal); + auto re = engine.run(lgrSqnWasm, "func1", {}, imports, hfs, 1'000'000, env.journal); BEAST_EXPECT(!re); } @@ -595,34 +529,28 @@ struct Wasm_test : public beast::unit_test::suite // {issuer, credType3}})); // create nft - [[maybe_unused]] uint256 const nft0{ - token::getNextID(env, alan, 0u)}; + [[maybe_unused]] uint256 const nft0{token::getNextID(env, alan, 0u)}; env(token::mint(alan, 0u)); auto const k = keylet::nftoffer(alan, 0); - [[maybe_unused]] uint256 const nft1{ - token::getNextID(env, alan, 0u)}; + [[maybe_unused]] uint256 const nft1{token::getNextID(env, alan, 0u)}; env(token::mint(alan, 0u), - token::uri( - "https://github.com/XRPLF/XRPL-Standards/discussions/" - "279?id=github.com/XRPLF/XRPL-Standards/discussions/" - "279&ut=github.com/XRPLF/XRPL-Standards/discussions/" - "279&sid=github.com/XRPLF/XRPL-Standards/discussions/" - "279&aot=github.com/XRPLF/XRPL-Standards/disc")); - [[maybe_unused]] uint256 const nft2{ - token::getNextID(env, alan, 0u)}; + token::uri("https://github.com/XRPLF/XRPL-Standards/discussions/" + "279?id=github.com/XRPLF/XRPL-Standards/discussions/" + "279&ut=github.com/XRPLF/XRPL-Standards/discussions/" + "279&sid=github.com/XRPLF/XRPL-Standards/discussions/" + "279&aot=github.com/XRPLF/XRPL-Standards/disc")); + [[maybe_unused]] uint256 const nft2{token::getNextID(env, alan, 0u)}; env(token::mint(alan, 0u)); env.close(); - std::shared_ptr hfs( - new PerfHostFunctions(env, k, env.tx())); + std::shared_ptr hfs(new PerfHostFunctions(env, k, env.tx())); auto re = runEscrowWasm(perfWasm, hfs, ESCROW_FUNCTION_NAME); if (BEAST_EXPECT(re.has_value())) { BEAST_EXPECT(re->result); - std::cout << "Res: " << re->result << " cost: " << re->cost - << std::endl; + std::cout << "Res: " << re->result << " cost: " << re->cost << std::endl; } // env(escrow::finish(alan, alan, seq), @@ -647,8 +575,7 @@ struct Wasm_test : public beast::unit_test::suite std::shared_ptr hfs(new TestHostFunctions(env, 0)); auto const allowance = 187'131; - auto re = runEscrowWasm( - codecovWasm, hfs, ESCROW_FUNCTION_NAME, {}, allowance); + auto re = runEscrowWasm(codecovWasm, hfs, ESCROW_FUNCTION_NAME, {}, allowance); checkResult(re, 1, allowance); } @@ -667,8 +594,7 @@ struct Wasm_test : public beast::unit_test::suite { // f32 set constant, opcode disabled exception - auto const re = - runEscrowWasm(disabledFloatWasm, hfs, funcName, {}, 1'000'000); + auto const re = runEscrowWasm(disabledFloatWasm, hfs, funcName, {}, 1'000'000); if (BEAST_EXPECT(!re.has_value())) { BEAST_EXPECT(re.error() == tecFAILED_PROCESSING); @@ -678,8 +604,7 @@ struct Wasm_test : public beast::unit_test::suite { // f32 add, can't create module exception disabledFloatWasm[0x117] = 0x92; - auto const re = - runEscrowWasm(disabledFloatWasm, hfs, funcName, {}, 1'000'000); + auto const re = runEscrowWasm(disabledFloatWasm, hfs, funcName, {}, 1'000'000); if (BEAST_EXPECT(!re.has_value())) { BEAST_EXPECT(re.error() == tecFAILED_PROCESSING); @@ -692,23 +617,16 @@ struct Wasm_test : public beast::unit_test::suite { 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(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(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(memoryInit1MoreThan8MBHex).has_value() == false); + BEAST_EXPECT(runFinishFunction(memoryNegativeAddressHex).has_value() == false); } void @@ -716,8 +634,7 @@ struct Wasm_test : public beast::unit_test::suite { testcase("Wasm table limit tests"); BEAST_EXPECT(runFinishFunction(table64ElementsHex).value() == 1); - BEAST_EXPECT( - runFinishFunction(table65ElementsHex).has_value() == false); + 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); @@ -727,32 +644,19 @@ struct Wasm_test : public beast::unit_test::suite 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(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); } void @@ -760,13 +664,10 @@ struct Wasm_test : public beast::unit_test::suite { 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(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(trapFuncSigMismatchHex).has_value() == false); } void @@ -782,21 +683,15 @@ struct Wasm_test : public beast::unit_test::suite { testcase("Wasm Section Corruption tests"); BEAST_EXPECT(runFinishFunction(badMagicNumberHex).has_value() == false); - BEAST_EXPECT( - runFinishFunction(badVersionNumberHex).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(neverEndingNumberHex).has_value() == false); BEAST_EXPECT(runFinishFunction(vectorLieHex).has_value() == false); - BEAST_EXPECT( - runFinishFunction(sectionOrderingHex).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(junkAfterSectionHex).has_value() == false); + BEAST_EXPECT(runFinishFunction(invalidSectionIdHex).has_value() == false); + BEAST_EXPECT(runFinishFunction(localVariableBombHex).has_value() == false); } void @@ -812,22 +707,11 @@ struct Wasm_test : public beast::unit_test::suite std::shared_ptr imports(std::make_shared()); auto& engine = WasmEngine::instance(); - auto checkRes = engine.check( - startLoopWasm, "finish", {}, imports, hfs, env.journal); - BEAST_EXPECTS( - checkRes == tesSUCCESS, std::to_string(TERtoInt(checkRes))); + auto checkRes = engine.check(startLoopWasm, "finish", {}, imports, hfs, env.journal); + BEAST_EXPECTS(checkRes == tesSUCCESS, std::to_string(TERtoInt(checkRes))); - auto re = engine.run( - startLoopWasm, - ESCROW_FUNCTION_NAME, - {}, - imports, - hfs, - 1'000'000, - env.journal); - BEAST_EXPECTS( - re.error() == tecFAILED_PROCESSING, - std::to_string(TERtoInt(re.error()))); + auto re = engine.run(startLoopWasm, ESCROW_FUNCTION_NAME, {}, imports, hfs, 1'000'000, env.journal); + BEAST_EXPECTS(re.error() == tecFAILED_PROCESSING, std::to_string(TERtoInt(re.error()))); } void @@ -846,13 +730,10 @@ struct Wasm_test : public beast::unit_test::suite // std::shared_ptr imports(std::make_shared()); uint8_t buf1[8] = {7, 8, 9, 10, 11, 12, 13, 14}; { // forged "allocate" return valid address - std::vector params = { - {.type = WT_U8V, - .of = {.u8v = {.d = buf1, .sz = sizeof(buf1)}}}}; + std::vector params = {{.type = WT_U8V, .of = {.u8v = {.d = buf1, .sz = sizeof(buf1)}}}}; auto& engine = WasmEngine::instance(); - auto re = engine.run( - badAllocWasm, "test", params, {}, hfs, 1'000'000, env.journal); + auto re = engine.run(badAllocWasm, "test", params, {}, hfs, 1'000'000, env.journal); if (BEAST_EXPECT(re)) { BEAST_EXPECTS(re->result == 7, std::to_string(re->result)); @@ -861,44 +742,32 @@ struct Wasm_test : public beast::unit_test::suite } { // return 0 whithout calling wasm - std::vector params = { - {.type = WT_U8V, .of = {.u8v = {.d = buf1, .sz = 0}}}}; + std::vector params = {{.type = WT_U8V, .of = {.u8v = {.d = buf1, .sz = 0}}}}; auto& engine = WasmEngine::instance(); - auto re = engine.run( - badAllocWasm, "test", params, {}, hfs, 1'000'000, env.journal); - BEAST_EXPECT(!re) && - BEAST_EXPECT(re.error() == tecFAILED_PROCESSING); + auto re = engine.run(badAllocWasm, "test", params, {}, hfs, 1'000'000, env.journal); + BEAST_EXPECT(!re) && BEAST_EXPECT(re.error() == tecFAILED_PROCESSING); } { // forged "allocate" return 8Mb (which is more than memory limit) - std::vector params = { - {.type = WT_U8V, .of = {.u8v = {.d = buf1, .sz = 1}}}}; + std::vector params = {{.type = WT_U8V, .of = {.u8v = {.d = buf1, .sz = 1}}}}; auto& engine = WasmEngine::instance(); - auto re = engine.run( - badAllocWasm, "test", params, {}, hfs, 1'000'000, env.journal); - BEAST_EXPECT(!re) && - BEAST_EXPECT(re.error() == tecFAILED_PROCESSING); + auto re = engine.run(badAllocWasm, "test", params, {}, hfs, 1'000'000, env.journal); + BEAST_EXPECT(!re) && BEAST_EXPECT(re.error() == tecFAILED_PROCESSING); } { // forged "allocate" return 0 - std::vector params = { - {.type = WT_U8V, .of = {.u8v = {.d = buf1, .sz = 2}}}}; + std::vector params = {{.type = WT_U8V, .of = {.u8v = {.d = buf1, .sz = 2}}}}; auto& engine = WasmEngine::instance(); - auto re = engine.run( - badAllocWasm, "test", params, {}, hfs, 1'000'000, env.journal); - BEAST_EXPECT(!re) && - BEAST_EXPECT(re.error() == tecFAILED_PROCESSING); + auto re = engine.run(badAllocWasm, "test", params, {}, hfs, 1'000'000, env.journal); + BEAST_EXPECT(!re) && BEAST_EXPECT(re.error() == tecFAILED_PROCESSING); } { // forged "allocate" return -1 - std::vector params = { - {.type = WT_U8V, .of = {.u8v = {.d = buf1, .sz = 3}}}}; + std::vector params = {{.type = WT_U8V, .of = {.u8v = {.d = buf1, .sz = 3}}}}; auto& engine = WasmEngine::instance(); - auto re = engine.run( - badAllocWasm, "test", params, {}, hfs, 1'000'000, env.journal); + auto re = engine.run(badAllocWasm, "test", params, {}, hfs, 1'000'000, env.journal); - BEAST_EXPECT(!re) && - BEAST_EXPECT(re.error() == tecFAILED_PROCESSING); + BEAST_EXPECT(!re) && BEAST_EXPECT(re.error() == tecFAILED_PROCESSING); } { @@ -913,9 +782,7 @@ struct Wasm_test : public beast::unit_test::suite { what = e.what(); } - BEAST_EXPECT( - what.find("can't allocate memory, size: 2147483648") != - std::string::npos); + BEAST_EXPECT(what.find("can't allocate memory, size: 2147483648") != std::string::npos); } env.close(); @@ -939,8 +806,7 @@ struct Wasm_test : public beast::unit_test::suite // Can be checked through codecov auto& engine = WasmEngine::instance(); - auto re = engine.run( - badAlignWasm, "test", {}, imports, hfs, 1'000'000, env.journal); + auto re = engine.run(badAlignWasm, "test", {}, imports, hfs, 1'000'000, env.journal); BEAST_EXPECT(re && re->result == 0xbab88d46); } @@ -964,8 +830,7 @@ struct Wasm_test : public beast::unit_test::suite "071302066d656d6f727902000666696e69736800000a0a01" "08004280808080100b"; auto const wasm = hexToBytes(wasmHex); - auto const re = - runEscrowWasm(wasm, hfs, ESCROW_FUNCTION_NAME, {}, 100'000); + auto const re = runEscrowWasm(wasm, hfs, ESCROW_FUNCTION_NAME, {}, 100'000); BEAST_EXPECT(!re); } @@ -981,8 +846,7 @@ struct Wasm_test : public beast::unit_test::suite "0061736d01000000010401600000030201000503010001071302066d656d6f" "727902000666696e69736800000a050103000f0b"; auto const wasm = hexToBytes(wasmHex); - auto const re = - runEscrowWasm(wasm, hfs, ESCROW_FUNCTION_NAME, {}, 100'000); + auto const re = runEscrowWasm(wasm, hfs, ESCROW_FUNCTION_NAME, {}, 100'000); BEAST_EXPECT(!re); } @@ -997,8 +861,7 @@ struct Wasm_test : public beast::unit_test::suite "6d6f727902000666696e69736800000a10010e0041808080800141ff818080" "010b"; auto const wasm = hexToBytes(wasmHex); - auto const re = - runEscrowWasm(wasm, hfs, ESCROW_FUNCTION_NAME, {}, 100'000); + auto const re = runEscrowWasm(wasm, hfs, ESCROW_FUNCTION_NAME, {}, 100'000); BEAST_EXPECT(!re); } } diff --git a/src/test/app/wasm_fixtures/b58.c b/src/test/app/wasm_fixtures/b58.c index 00b6178ec0..56defdbb32 100644 --- a/src/test/app/wasm_fixtures/b58.c +++ b/src/test/app/wasm_fixtures/b58.c @@ -1,7 +1,6 @@ #include -static char const b58digits_ordered[] = - "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"; +static char const b58digits_ordered[] = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"; uint8_t e_data[32 * 1024]; diff --git a/src/test/app/wasm_fixtures/fixtures.cpp b/src/test/app/wasm_fixtures/fixtures.cpp index e826f621c3..6bff452705 100644 --- a/src/test/app/wasm_fixtures/fixtures.cpp +++ b/src/test/app/wasm_fixtures/fixtures.cpp @@ -1277,8 +1277,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 sectionOrderingHex = "0061736d010000000a02000b03020000"; // Corruption Test: ghostPayload // Scenario: Valid headers, but file is truncated in the middle of a payload. @@ -1305,8 +1304,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 junkAfterSectionHex = "0061736d01000000010a01600000000000000000"; // Corruption Test: invalidSectionId // Scenario: A section ID that doesn't exist (0xFF). @@ -1337,8 +1335,7 @@ 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 = - "0061736d01000000010401600000030201000a0f010d01ffffffff0f7f0b"; +extern std::string const localVariableBombHex = "0061736d01000000010401600000030201000a0f010d01ffffffff0f7f0b"; extern std::string const infiniteLoopWasmHex = "0061736d010000000108026000006000017f030302000105030100020638097f004180080b" diff --git a/src/test/app/wasm_fixtures/sha512Pure.c b/src/test/app/wasm_fixtures/sha512Pure.c index fe82aa2a65..2c736bb218 100644 --- a/src/test/app/wasm_fixtures/sha512Pure.c +++ b/src/test/app/wasm_fixtures/sha512Pure.c @@ -2,33 +2,22 @@ #include static uint64_t const K512[] = { - 0x428a2f98d728ae22, 0x7137449123ef65cd, 0xb5c0fbcfec4d3b2f, - 0xe9b5dba58189dbbc, 0x3956c25bf348b538, 0x59f111f1b605d019, - 0x923f82a4af194f9b, 0xab1c5ed5da6d8118, 0xd807aa98a3030242, - 0x12835b0145706fbe, 0x243185be4ee4b28c, 0x550c7dc3d5ffb4e2, - 0x72be5d74f27b896f, 0x80deb1fe3b1696b1, 0x9bdc06a725c71235, - 0xc19bf174cf692694, 0xe49b69c19ef14ad2, 0xefbe4786384f25e3, - 0x0fc19dc68b8cd5b5, 0x240ca1cc77ac9c65, 0x2de92c6f592b0275, - 0x4a7484aa6ea6e483, 0x5cb0a9dcbd41fbd4, 0x76f988da831153b5, - 0x983e5152ee66dfab, 0xa831c66d2db43210, 0xb00327c898fb213f, - 0xbf597fc7beef0ee4, 0xc6e00bf33da88fc2, 0xd5a79147930aa725, - 0x06ca6351e003826f, 0x142929670a0e6e70, 0x27b70a8546d22ffc, - 0x2e1b21385c26c926, 0x4d2c6dfc5ac42aed, 0x53380d139d95b3df, - 0x650a73548baf63de, 0x766a0abb3c77b2a8, 0x81c2c92e47edaee6, - 0x92722c851482353b, 0xa2bfe8a14cf10364, 0xa81a664bbc423001, - 0xc24b8b70d0f89791, 0xc76c51a30654be30, 0xd192e819d6ef5218, - 0xd69906245565a910, 0xf40e35855771202a, 0x106aa07032bbd1b8, - 0x19a4c116b8d2d0c8, 0x1e376c085141ab53, 0x2748774cdf8eeb99, - 0x34b0bcb5e19b48a8, 0x391c0cb3c5c95a63, 0x4ed8aa4ae3418acb, - 0x5b9cca4f7763e373, 0x682e6ff3d6b2b8a3, 0x748f82ee5defb2fc, - 0x78a5636f43172f60, 0x84c87814a1f0ab72, 0x8cc702081a6439ec, - 0x90befffa23631e28, 0xa4506cebde82bde9, 0xbef9a3f7b2c67915, - 0xc67178f2e372532b, 0xca273eceea26619c, 0xd186b8c721c0c207, - 0xeada7dd6cde0eb1e, 0xf57d4f7fee6ed178, 0x06f067aa72176fba, - 0x0a637dc5a2c898a6, 0x113f9804bef90dae, 0x1b710b35131c471b, - 0x28db77f523047d84, 0x32caab7b40c72493, 0x3c9ebe0a15c9bebc, - 0x431d67c49c100d4c, 0x4cc5d4becb3e42b6, 0x597f299cfc657e2a, - 0x5fcb6fab3ad6faec, 0x6c44198c4a475817}; + 0x428a2f98d728ae22, 0x7137449123ef65cd, 0xb5c0fbcfec4d3b2f, 0xe9b5dba58189dbbc, 0x3956c25bf348b538, + 0x59f111f1b605d019, 0x923f82a4af194f9b, 0xab1c5ed5da6d8118, 0xd807aa98a3030242, 0x12835b0145706fbe, + 0x243185be4ee4b28c, 0x550c7dc3d5ffb4e2, 0x72be5d74f27b896f, 0x80deb1fe3b1696b1, 0x9bdc06a725c71235, + 0xc19bf174cf692694, 0xe49b69c19ef14ad2, 0xefbe4786384f25e3, 0x0fc19dc68b8cd5b5, 0x240ca1cc77ac9c65, + 0x2de92c6f592b0275, 0x4a7484aa6ea6e483, 0x5cb0a9dcbd41fbd4, 0x76f988da831153b5, 0x983e5152ee66dfab, + 0xa831c66d2db43210, 0xb00327c898fb213f, 0xbf597fc7beef0ee4, 0xc6e00bf33da88fc2, 0xd5a79147930aa725, + 0x06ca6351e003826f, 0x142929670a0e6e70, 0x27b70a8546d22ffc, 0x2e1b21385c26c926, 0x4d2c6dfc5ac42aed, + 0x53380d139d95b3df, 0x650a73548baf63de, 0x766a0abb3c77b2a8, 0x81c2c92e47edaee6, 0x92722c851482353b, + 0xa2bfe8a14cf10364, 0xa81a664bbc423001, 0xc24b8b70d0f89791, 0xc76c51a30654be30, 0xd192e819d6ef5218, + 0xd69906245565a910, 0xf40e35855771202a, 0x106aa07032bbd1b8, 0x19a4c116b8d2d0c8, 0x1e376c085141ab53, + 0x2748774cdf8eeb99, 0x34b0bcb5e19b48a8, 0x391c0cb3c5c95a63, 0x4ed8aa4ae3418acb, 0x5b9cca4f7763e373, + 0x682e6ff3d6b2b8a3, 0x748f82ee5defb2fc, 0x78a5636f43172f60, 0x84c87814a1f0ab72, 0x8cc702081a6439ec, + 0x90befffa23631e28, 0xa4506cebde82bde9, 0xbef9a3f7b2c67915, 0xc67178f2e372532b, 0xca273eceea26619c, + 0xd186b8c721c0c207, 0xeada7dd6cde0eb1e, 0xf57d4f7fee6ed178, 0x06f067aa72176fba, 0x0a637dc5a2c898a6, + 0x113f9804bef90dae, 0x1b710b35131c471b, 0x28db77f523047d84, 0x32caab7b40c72493, 0x3c9ebe0a15c9bebc, + 0x431d67c49c100d4c, 0x4cc5d4becb3e42b6, 0x597f299cfc657e2a, 0x5fcb6fab3ad6faec, 0x6c44198c4a475817}; #define ROTATE(x, y) (((x) >> (y)) | ((x) << (64 - (y)))) #define Sigma0(x) (ROTATE((x), 28) ^ ROTATE((x), 34) ^ ROTATE((x), 39)) @@ -81,9 +70,8 @@ sha512_process(uint8_t const* data, int32_t length) unsigned i; for (i = 0; i < 16; i++) { - X[i] = B2U64(data[0], 56) | B2U64(data[1], 48) | - B2U64(data[2], 40) | B2U64(data[3], 32) | B2U64(data[4], 24) | - B2U64(data[5], 16) | B2U64(data[6], 8) | B2U64(data[7], 0); + X[i] = B2U64(data[0], 56) | B2U64(data[1], 48) | B2U64(data[2], 40) | B2U64(data[3], 32) | + B2U64(data[4], 24) | B2U64(data[5], 16) | B2U64(data[6], 8) | B2U64(data[7], 0); data += 8; T1 = h; diff --git a/src/test/basics/Number_test.cpp b/src/test/basics/Number_test.cpp index b7170b9e00..5838a98a15 100644 --- a/src/test/basics/Number_test.cpp +++ b/src/test/basics/Number_test.cpp @@ -1361,25 +1361,11 @@ public: {Number{5625, -4}, Number{-2'498'774'732'165'998, -16}}}); auto const cLarge = std::to_array( - {{Number{ - false, Number::maxMantissa() - 9, -1, Number::normalized{}}, - Number{ - false, - 1'746'901'684'478'673'451ll, - -17, - Number::normalized{}}}, + {{Number{false, Number::maxMantissa() - 9, -1, Number::normalized{}}, + Number{false, 1'746'901'684'478'673'451ll, -17, Number::normalized{}}}, {Number{false, Number::maxMantissa() - 9, 0, Number::normalized{}}, - Number{ - false, - 1'846'901'684'478'673'451ll, - -17, - Number::normalized{}}}, - {Number{Number::maxRep}, - Number{ - false, - 1'861'728'612'932'620'011ll, - -17, - Number::normalized{}}}}); + Number{false, 1'846'901'684'478'673'451ll, -17, Number::normalized{}}}, + {Number{Number::maxRep}, Number{false, 1'861'728'612'932'620'011ll, -17, Number::normalized{}}}}); if (Number::getMantissaScale() == MantissaRange::small) { diff --git a/src/xrpld/app/wasm/HostFunc.h b/src/xrpld/app/wasm/HostFunc.h index 0ee4a615ce..c49e58eb38 100644 --- a/src/xrpld/app/wasm/HostFunc.h +++ b/src/xrpld/app/wasm/HostFunc.h @@ -88,9 +88,7 @@ struct HostFunctions { 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) { } @@ -245,10 +243,7 @@ struct HostFunctions } virtual Expected - checkSignature( - Slice const& message, - Slice const& signature, - Slice const& pubkey) + checkSignature(Slice const& message, Slice const& signature, Slice const& pubkey) { return Unexpected(HostFunctionError::INTERNAL); } @@ -278,10 +273,7 @@ struct HostFunctions } virtual Expected - credentialKeylet( - AccountID const& subject, - AccountID const& issuer, - Slice const& credentialType) + credentialKeylet(AccountID const& subject, AccountID const& issuer, Slice const& credentialType) { return Unexpected(HostFunctionError::INTERNAL); } @@ -311,10 +303,7 @@ struct HostFunctions } virtual Expected - lineKeylet( - AccountID const& account1, - AccountID const& account2, - Currency const& currency) + lineKeylet(AccountID const& account1, AccountID const& account2, Currency const& currency) { return Unexpected(HostFunctionError::INTERNAL); } @@ -350,10 +339,7 @@ struct HostFunctions } virtual Expected - paychanKeylet( - AccountID const& account, - AccountID const& destination, - std::uint32_t seq) + paychanKeylet(AccountID const& account, AccountID const& destination, std::uint32_t seq) { return Unexpected(HostFunctionError::INTERNAL); } diff --git a/src/xrpld/app/wasm/HostFuncImpl.h b/src/xrpld/app/wasm/HostFuncImpl.h index 4acdc85dfb..b5ce367004 100644 --- a/src/xrpld/app/wasm/HostFuncImpl.h +++ b/src/xrpld/app/wasm/HostFuncImpl.h @@ -52,8 +52,7 @@ class WasmHostFunctionsImpl : public HostFunctions return; auto j = getJournal().trace(); #endif - j << "WasmTrace[" << to_short_string(leKey.key) << "]: " << msg << " " - << dataFn(); + j << "WasmTrace[" << to_short_string(leKey.key) << "]: " << msg << " " << dataFn(); #ifdef DEBUG_OUTPUT j << std::endl; @@ -61,8 +60,7 @@ class WasmHostFunctionsImpl : public HostFunctions } public: - WasmHostFunctionsImpl(ApplyContext& ct, Keylet const& leKey) - : HostFunctions(ct.journal), ctx(ct), leKey(leKey) + WasmHostFunctionsImpl(ApplyContext& ct, Keylet const& leKey) : HostFunctions(ct.journal), ctx(ct), leKey(leKey) { } @@ -145,10 +143,7 @@ public: updateData(Slice const& data) override; Expected - checkSignature( - Slice const& message, - Slice const& signature, - Slice const& pubkey) override; + checkSignature(Slice const& message, Slice const& signature, Slice const& pubkey) override; Expected computeSha512HalfHash(Slice const& data) override; @@ -163,30 +158,22 @@ public: checkKeylet(AccountID const& account, std::uint32_t seq) override; Expected - credentialKeylet( - AccountID const& subject, - AccountID const& issuer, - Slice const& credentialType) override; + credentialKeylet(AccountID const& subject, AccountID const& issuer, Slice const& credentialType) override; Expected didKeylet(AccountID const& account) override; Expected - delegateKeylet(AccountID const& account, AccountID const& authorize) - override; + delegateKeylet(AccountID const& account, AccountID const& authorize) override; Expected - depositPreauthKeylet(AccountID const& account, AccountID const& authorize) - override; + depositPreauthKeylet(AccountID const& account, AccountID const& authorize) override; Expected escrowKeylet(AccountID const& account, std::uint32_t seq) override; Expected - lineKeylet( - AccountID const& account1, - AccountID const& account2, - Currency const& currency) override; + lineKeylet(AccountID const& account1, AccountID const& account2, Currency const& currency) override; Expected mptIssuanceKeylet(AccountID const& issuer, std::uint32_t seq) override; @@ -204,14 +191,10 @@ public: oracleKeylet(AccountID const& account, std::uint32_t docId) override; Expected - paychanKeylet( - AccountID const& account, - AccountID const& destination, - std::uint32_t seq) override; + paychanKeylet(AccountID const& account, AccountID const& destination, std::uint32_t seq) override; Expected - permissionedDomainKeylet(AccountID const& account, std::uint32_t seq) - override; + permissionedDomainKeylet(AccountID const& account, std::uint32_t seq) override; Expected signersKeylet(AccountID const& account) override; @@ -247,8 +230,7 @@ public: traceNum(std::string_view const& msg, int64_t data) override; Expected - traceAccount(std::string_view const& msg, AccountID const& account) - override; + traceAccount(std::string_view const& msg, AccountID const& account) override; Expected traceFloat(std::string_view const& msg, Slice const& data) override; diff --git a/src/xrpld/app/wasm/HostFuncWrapper.h b/src/xrpld/app/wasm/HostFuncWrapper.h index 745bbe9a2c..8555fd69a1 100644 --- a/src/xrpld/app/wasm/HostFuncWrapper.h +++ b/src/xrpld/app/wasm/HostFuncWrapper.h @@ -6,399 +6,191 @@ namespace xrpl { using getLedgerSqn_proto = int32_t(); wasm_trap_t* -getLedgerSqn_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results); +getLedgerSqn_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results); using getParentLedgerTime_proto = int32_t(); wasm_trap_t* -getParentLedgerTime_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results); +getParentLedgerTime_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results); using getParentLedgerHash_proto = int32_t(uint8_t*, int32_t); wasm_trap_t* -getParentLedgerHash_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results); +getParentLedgerHash_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results); using getBaseFee_proto = int32_t(); wasm_trap_t* -getBaseFee_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results); +getBaseFee_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results); using isAmendmentEnabled_proto = int32_t(uint8_t const*, int32_t); wasm_trap_t* -isAmendmentEnabled_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results); +isAmendmentEnabled_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results); using cacheLedgerObj_proto = int32_t(uint8_t const*, int32_t, int32_t); wasm_trap_t* -cacheLedgerObj_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results); +cacheLedgerObj_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results); using getTxField_proto = int32_t(int32_t, uint8_t*, int32_t); wasm_trap_t* -getTxField_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results); +getTxField_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results); using getCurrentLedgerObjField_proto = int32_t(int32_t, uint8_t*, int32_t); wasm_trap_t* -getCurrentLedgerObjField_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results); +getCurrentLedgerObjField_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results); using getLedgerObjField_proto = int32_t(int32_t, int32_t, uint8_t*, int32_t); wasm_trap_t* -getLedgerObjField_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results); +getLedgerObjField_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results); -using getTxNestedField_proto = - int32_t(uint8_t const*, int32_t, uint8_t*, int32_t); +using getTxNestedField_proto = int32_t(uint8_t const*, int32_t, uint8_t*, int32_t); wasm_trap_t* -getTxNestedField_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results); +getTxNestedField_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results); -using getCurrentLedgerObjNestedField_proto = - int32_t(uint8_t const*, int32_t, uint8_t*, int32_t); +using getCurrentLedgerObjNestedField_proto = int32_t(uint8_t const*, int32_t, uint8_t*, int32_t); wasm_trap_t* -getCurrentLedgerObjNestedField_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results); +getCurrentLedgerObjNestedField_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results); -using getLedgerObjNestedField_proto = - int32_t(int32_t, uint8_t const*, int32_t, uint8_t*, int32_t); +using getLedgerObjNestedField_proto = int32_t(int32_t, uint8_t const*, int32_t, uint8_t*, int32_t); wasm_trap_t* -getLedgerObjNestedField_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results); +getLedgerObjNestedField_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results); using getTxArrayLen_proto = int32_t(int32_t); wasm_trap_t* -getTxArrayLen_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results); +getTxArrayLen_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results); using getCurrentLedgerObjArrayLen_proto = int32_t(int32_t); wasm_trap_t* -getCurrentLedgerObjArrayLen_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results); +getCurrentLedgerObjArrayLen_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results); using getLedgerObjArrayLen_proto = int32_t(int32_t, int32_t); wasm_trap_t* -getLedgerObjArrayLen_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results); +getLedgerObjArrayLen_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results); using getTxNestedArrayLen_proto = int32_t(uint8_t const*, int32_t); wasm_trap_t* -getTxNestedArrayLen_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results); +getTxNestedArrayLen_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results); -using getCurrentLedgerObjNestedArrayLen_proto = - int32_t(uint8_t const*, int32_t); +using getCurrentLedgerObjNestedArrayLen_proto = int32_t(uint8_t const*, int32_t); wasm_trap_t* -getCurrentLedgerObjNestedArrayLen_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results); +getCurrentLedgerObjNestedArrayLen_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results); -using getLedgerObjNestedArrayLen_proto = - int32_t(int32_t, uint8_t const*, int32_t); +using getLedgerObjNestedArrayLen_proto = int32_t(int32_t, uint8_t const*, int32_t); wasm_trap_t* -getLedgerObjNestedArrayLen_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results); +getLedgerObjNestedArrayLen_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results); using updateData_proto = int32_t(uint8_t const*, int32_t); wasm_trap_t* -updateData_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results); +updateData_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results); -using checkSignature_proto = int32_t( - uint8_t const*, - int32_t, - uint8_t const*, - int32_t, - uint8_t const*, - int32_t); +using checkSignature_proto = int32_t(uint8_t const*, int32_t, uint8_t const*, int32_t, uint8_t const*, int32_t); wasm_trap_t* -checkSignature_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results); +checkSignature_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results); -using computeSha512HalfHash_proto = - int32_t(uint8_t const*, int32_t, uint8_t*, int32_t); +using computeSha512HalfHash_proto = int32_t(uint8_t const*, int32_t, uint8_t*, int32_t); wasm_trap_t* -computeSha512HalfHash_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results); +computeSha512HalfHash_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results); using accountKeylet_proto = int32_t(uint8_t const*, int32_t, uint8_t*, int32_t); wasm_trap_t* -accountKeylet_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results); +accountKeylet_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results); -using ammKeylet_proto = int32_t( - uint8_t const*, - int32_t, - uint8_t const*, - int32_t, - uint8_t*, - int32_t); +using ammKeylet_proto = int32_t(uint8_t const*, int32_t, uint8_t const*, int32_t, uint8_t*, int32_t); wasm_trap_t* -ammKeylet_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results); +ammKeylet_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results); -using checkKeylet_proto = - int32_t(uint8_t const*, int32_t, int32_t, uint8_t*, int32_t); +using checkKeylet_proto = int32_t(uint8_t const*, int32_t, int32_t, uint8_t*, int32_t); wasm_trap_t* -checkKeylet_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results); +checkKeylet_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results); -using credentialKeylet_proto = int32_t( - uint8_t const*, - int32_t, - uint8_t const*, - int32_t, - uint8_t const*, - int32_t, - uint8_t*, - int32_t); +using credentialKeylet_proto = + int32_t(uint8_t const*, int32_t, uint8_t const*, int32_t, uint8_t const*, int32_t, uint8_t*, int32_t); wasm_trap_t* -credentialKeylet_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results); +credentialKeylet_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results); -using delegateKeylet_proto = int32_t( - uint8_t const*, - int32_t, - uint8_t const*, - int32_t, - uint8_t*, - int32_t); +using delegateKeylet_proto = int32_t(uint8_t const*, int32_t, uint8_t const*, int32_t, uint8_t*, int32_t); wasm_trap_t* -delegateKeylet_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results); +delegateKeylet_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results); -using depositPreauthKeylet_proto = int32_t( - uint8_t const*, - int32_t, - uint8_t const*, - int32_t, - uint8_t*, - int32_t); +using depositPreauthKeylet_proto = int32_t(uint8_t const*, int32_t, uint8_t const*, int32_t, uint8_t*, int32_t); wasm_trap_t* -depositPreauthKeylet_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results); +depositPreauthKeylet_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results); using didKeylet_proto = int32_t(uint8_t const*, int32_t, uint8_t*, int32_t); wasm_trap_t* -didKeylet_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results); +didKeylet_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results); -using escrowKeylet_proto = - int32_t(uint8_t const*, int32_t, int32_t, uint8_t*, int32_t); +using escrowKeylet_proto = int32_t(uint8_t const*, int32_t, int32_t, uint8_t*, int32_t); wasm_trap_t* -escrowKeylet_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results); +escrowKeylet_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results); -using lineKeylet_proto = int32_t( - uint8_t const*, - int32_t, - uint8_t const*, - int32_t, - uint8_t const*, - int32_t, - uint8_t*, - int32_t); +using lineKeylet_proto = + int32_t(uint8_t const*, int32_t, uint8_t const*, int32_t, uint8_t const*, int32_t, uint8_t*, int32_t); wasm_trap_t* -lineKeylet_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results); +lineKeylet_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results); -using mptIssuanceKeylet_proto = - int32_t(uint8_t const*, int32_t, int32_t, uint8_t*, int32_t); +using mptIssuanceKeylet_proto = int32_t(uint8_t const*, int32_t, int32_t, uint8_t*, int32_t); wasm_trap_t* -mptIssuanceKeylet_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results); +mptIssuanceKeylet_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results); -using mptokenKeylet_proto = int32_t( - uint8_t const*, - int32_t, - uint8_t const*, - int32_t, - uint8_t*, - int32_t); +using mptokenKeylet_proto = int32_t(uint8_t const*, int32_t, uint8_t const*, int32_t, uint8_t*, int32_t); wasm_trap_t* -mptokenKeylet_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results); +mptokenKeylet_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results); -using nftOfferKeylet_proto = - int32_t(uint8_t const*, int32_t, int32_t, uint8_t*, int32_t); +using nftOfferKeylet_proto = int32_t(uint8_t const*, int32_t, int32_t, uint8_t*, int32_t); wasm_trap_t* -nftOfferKeylet_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results); +nftOfferKeylet_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results); -using offerKeylet_proto = - int32_t(uint8_t const*, int32_t, int32_t, uint8_t*, int32_t); +using offerKeylet_proto = int32_t(uint8_t const*, int32_t, int32_t, uint8_t*, int32_t); wasm_trap_t* -offerKeylet_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results); +offerKeylet_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results); -using oracleKeylet_proto = - int32_t(uint8_t const*, int32_t, int32_t, uint8_t*, int32_t); +using oracleKeylet_proto = int32_t(uint8_t const*, int32_t, int32_t, uint8_t*, int32_t); wasm_trap_t* -oracleKeylet_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results); +oracleKeylet_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results); -using paychanKeylet_proto = int32_t( - uint8_t const*, - int32_t, - uint8_t const*, - int32_t, - int32_t, - uint8_t*, - int32_t); +using paychanKeylet_proto = int32_t(uint8_t const*, int32_t, uint8_t const*, int32_t, int32_t, uint8_t*, int32_t); wasm_trap_t* -paychanKeylet_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results); +paychanKeylet_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results); -using permissionedDomainKeylet_proto = - int32_t(uint8_t const*, int32_t, int32_t, uint8_t*, int32_t); +using permissionedDomainKeylet_proto = int32_t(uint8_t const*, int32_t, int32_t, uint8_t*, int32_t); wasm_trap_t* -permissionedDomainKeylet_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results); +permissionedDomainKeylet_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results); using signersKeylet_proto = int32_t(uint8_t const*, int32_t, uint8_t*, int32_t); wasm_trap_t* -signersKeylet_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results); +signersKeylet_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results); -using ticketKeylet_proto = - int32_t(uint8_t const*, int32_t, int32_t, uint8_t*, int32_t); +using ticketKeylet_proto = int32_t(uint8_t const*, int32_t, int32_t, uint8_t*, int32_t); wasm_trap_t* -ticketKeylet_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results); +ticketKeylet_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results); -using vaultKeylet_proto = - int32_t(uint8_t const*, int32_t, int32_t, uint8_t*, int32_t); +using vaultKeylet_proto = int32_t(uint8_t const*, int32_t, int32_t, uint8_t*, int32_t); wasm_trap_t* -vaultKeylet_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results); +vaultKeylet_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results); -using getNFT_proto = int32_t( - uint8_t const*, - int32_t, - uint8_t const*, - int32_t, - uint8_t*, - int32_t); +using getNFT_proto = int32_t(uint8_t const*, int32_t, uint8_t const*, int32_t, uint8_t*, int32_t); wasm_trap_t* getNFT_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results); using getNFTIssuer_proto = int32_t(uint8_t const*, int32_t, uint8_t*, int32_t); wasm_trap_t* -getNFTIssuer_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results); +getNFTIssuer_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results); using getNFTTaxon_proto = int32_t(uint8_t const*, int32_t, uint8_t*, int32_t); wasm_trap_t* -getNFTTaxon_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results); +getNFTTaxon_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results); using getNFTFlags_proto = int32_t(uint8_t const*, int32_t); wasm_trap_t* -getNFTFlags_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results); +getNFTFlags_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results); using getNFTTransferFee_proto = int32_t(uint8_t const*, int32_t); wasm_trap_t* -getNFTTransferFee_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results); +getNFTTransferFee_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results); using getNFTSerial_proto = int32_t(uint8_t const*, int32_t, uint8_t*, int32_t); wasm_trap_t* -getNFTSerial_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results); +getNFTSerial_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results); -using trace_proto = - int32_t(uint8_t const*, int32_t, uint8_t const*, int32_t, int32_t); +using trace_proto = int32_t(uint8_t const*, int32_t, uint8_t const*, int32_t, int32_t); wasm_trap_t* trace_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results); @@ -406,128 +198,59 @@ using traceNum_proto = int32_t(uint8_t const*, int32_t, int64_t); wasm_trap_t* traceNum_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results); -using traceAccount_proto = - int32_t(uint8_t const*, int32_t, uint8_t const*, int32_t); +using traceAccount_proto = int32_t(uint8_t const*, int32_t, uint8_t const*, int32_t); wasm_trap_t* -traceAccount_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results); +traceAccount_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results); -using traceFloat_proto = - int32_t(uint8_t const*, int32_t, uint8_t const*, int32_t); +using traceFloat_proto = int32_t(uint8_t const*, int32_t, uint8_t const*, int32_t); wasm_trap_t* -traceFloat_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results); +traceFloat_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results); -using traceAmount_proto = - int32_t(uint8_t const*, int32_t, uint8_t const*, int32_t); +using traceAmount_proto = int32_t(uint8_t const*, int32_t, uint8_t const*, int32_t); wasm_trap_t* -traceAmount_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results); +traceAmount_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results); using floatFromInt_proto = int32_t(int64_t, uint8_t*, int32_t, int32_t); wasm_trap_t* -floatFromInt_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results); +floatFromInt_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results); -using floatFromUint_proto = - int32_t(uint8_t const*, int32_t, uint8_t*, int32_t, int32_t); +using floatFromUint_proto = int32_t(uint8_t const*, int32_t, uint8_t*, int32_t, int32_t); wasm_trap_t* -floatFromUint_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results); +floatFromUint_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results); using floatSet_proto = int32_t(int32_t, int64_t, uint8_t*, int32_t, int32_t); wasm_trap_t* floatSet_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results); -using floatCompare_proto = - int32_t(uint8_t const*, int32_t, uint8_t const*, int32_t); +using floatCompare_proto = int32_t(uint8_t const*, int32_t, uint8_t const*, int32_t); wasm_trap_t* -floatCompare_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results); +floatCompare_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results); -using floatAdd_proto = int32_t( - uint8_t const*, - int32_t, - uint8_t const*, - int32_t, - uint8_t*, - int32_t, - int32_t); +using floatAdd_proto = int32_t(uint8_t const*, int32_t, uint8_t const*, int32_t, uint8_t*, int32_t, int32_t); wasm_trap_t* floatAdd_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results); -using floatSubtract_proto = int32_t( - uint8_t const*, - int32_t, - uint8_t const*, - int32_t, - uint8_t*, - int32_t, - int32_t); +using floatSubtract_proto = int32_t(uint8_t const*, int32_t, uint8_t const*, int32_t, uint8_t*, int32_t, int32_t); wasm_trap_t* -floatSubtract_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results); +floatSubtract_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results); -using floatMultiply_proto = int32_t( - uint8_t const*, - int32_t, - uint8_t const*, - int32_t, - uint8_t*, - int32_t, - int32_t); +using floatMultiply_proto = int32_t(uint8_t const*, int32_t, uint8_t const*, int32_t, uint8_t*, int32_t, int32_t); wasm_trap_t* -floatMultiply_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results); +floatMultiply_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results); -using floatDivide_proto = int32_t( - uint8_t const*, - int32_t, - uint8_t const*, - int32_t, - uint8_t*, - int32_t, - int32_t); +using floatDivide_proto = int32_t(uint8_t const*, int32_t, uint8_t const*, int32_t, uint8_t*, int32_t, int32_t); wasm_trap_t* -floatDivide_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results); +floatDivide_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results); -using floatRoot_proto = - int32_t(uint8_t const*, int32_t, int32_t, uint8_t*, int32_t, int32_t); +using floatRoot_proto = int32_t(uint8_t const*, int32_t, int32_t, uint8_t*, int32_t, int32_t); wasm_trap_t* -floatRoot_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results); +floatRoot_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results); -using floatPower_proto = - int32_t(uint8_t const*, int32_t, int32_t, uint8_t*, int32_t, int32_t); +using floatPower_proto = int32_t(uint8_t const*, int32_t, int32_t, uint8_t*, int32_t, int32_t); wasm_trap_t* -floatPower_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results); +floatPower_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results); -using floatLog_proto = - int32_t(uint8_t const*, int32_t, uint8_t*, int32_t, int32_t); +using floatLog_proto = int32_t(uint8_t const*, int32_t, uint8_t*, int32_t, int32_t); wasm_trap_t* floatLog_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results); diff --git a/src/xrpld/app/wasm/ParamsHelper.h b/src/xrpld/app/wasm/ParamsHelper.h index a7546ce092..90ecb4caa5 100644 --- a/src/xrpld/app/wasm/ParamsHelper.h +++ b/src/xrpld/app/wasm/ParamsHelper.h @@ -50,13 +50,9 @@ struct WasmImportFunc typedef std::pair WasmUserData; typedef std::vector ImportVec; -#define WASM_IMPORT_FUNC(v, f, ...) \ - WasmImpFunc( \ - v, #f, reinterpret_cast(&f##_wrap), ##__VA_ARGS__) +#define WASM_IMPORT_FUNC(v, f, ...) WasmImpFunc(v, #f, reinterpret_cast(&f##_wrap), ##__VA_ARGS__) -#define WASM_IMPORT_FUNC2(v, f, n, ...) \ - WasmImpFunc( \ - v, n, reinterpret_cast(&f##_wrap), ##__VA_ARGS__) +#define WASM_IMPORT_FUNC2(v, f, n, ...) WasmImpFunc(v, n, reinterpret_cast(&f##_wrap), ##__VA_ARGS__) template void @@ -91,8 +87,7 @@ WasmImpRet(WasmImportFunc& e) e.result = WT_I64; else if constexpr (std::is_void_v) e.result.reset(); -#if (defined(__GNUC__) && (__GNUC__ >= 14)) || \ - ((defined(__clang_major__)) && (__clang_major__ >= 18)) +#if (defined(__GNUC__) && (__GNUC__ >= 14)) || ((defined(__clang_major__)) && (__clang_major__ >= 18)) else static_assert(false, "Unsupported return type"); #endif @@ -113,12 +108,7 @@ WasmImpFuncHelper(WasmImportFunc& e) template void -WasmImpFunc( - ImportVec& v, - std::string_view imp_name, - void* f_wrap, - void* data = nullptr, - uint32_t gas = 0) +WasmImpFunc(ImportVec& v, std::string_view imp_name, void* f_wrap, void* data = nullptr, uint32_t gas = 0) { WasmImportFunc e; e.name = imp_name; @@ -185,11 +175,7 @@ wasmParamsHlp(std::vector& v, std::int64_t p, Types&&... args) template inline void -wasmParamsHlp( - std::vector& v, - std::uint8_t const* dt, - std::int32_t sz, - Types&&... args) +wasmParamsHlp(std::vector& v, std::uint8_t const* dt, std::int32_t sz, Types&&... args) { v.push_back({.type = WT_U8V, .of = {.u8v = {.d = dt, .sz = sz}}}); wasmParamsHlp(v, std::forward(args)...); @@ -200,27 +186,17 @@ inline void wasmParamsHlp(std::vector& v, Bytes const& p, Types&&... args) { if (p.size() > std::numeric_limits::max()) - throw std::runtime_error( - "can't allocate memory, size: " + - std::to_string(p.size())); // LCOV_EXCL_LINE + throw std::runtime_error("can't allocate memory, size: " + std::to_string(p.size())); // LCOV_EXCL_LINE - wasmParamsHlp( - v, - p.data(), - static_cast(p.size()), - std::forward(args)...); + wasmParamsHlp(v, p.data(), static_cast(p.size()), std::forward(args)...); } template inline void -wasmParamsHlp( - std::vector& v, - std::string_view const& p, - Types&&... args) +wasmParamsHlp(std::vector& v, std::string_view const& p, Types&&... args) { if (p.size() > std::numeric_limits::max()) - throw std::runtime_error( - "can't allocate memory, size: " + std::to_string(p.size())); + throw std::runtime_error("can't allocate memory, size: " + std::to_string(p.size())); wasmParamsHlp( v, @@ -234,9 +210,7 @@ inline void wasmParamsHlp(std::vector& v, std::string const& p, Types&&... args) { if (p.size() > std::numeric_limits::max()) - throw std::runtime_error( - "can't allocate memory, size: " + - std::to_string(p.size())); // LCOV_EXCL_LINE + throw std::runtime_error("can't allocate memory, size: " + std::to_string(p.size())); // LCOV_EXCL_LINE wasmParamsHlp( v, diff --git a/src/xrpld/app/wasm/WasmiVM.h b/src/xrpld/app/wasm/WasmiVM.h index c64e7951c0..d4ea0bfaa9 100644 --- a/src/xrpld/app/wasm/WasmiVM.h +++ b/src/xrpld/app/wasm/WasmiVM.h @@ -60,26 +60,13 @@ struct WasmVec } }; -using WasmValtypeVec = WasmVec< - wasm_valtype_vec_t, - &wasm_valtype_vec_new_uninitialized, - &wasm_valtype_vec_delete>; -using WasmValVec = WasmVec< - wasm_val_vec_t, - &wasm_val_vec_new_uninitialized, - &wasm_val_vec_delete>; -using WasmExternVec = WasmVec< - wasm_extern_vec_t, - &wasm_extern_vec_new_uninitialized, - &wasm_extern_vec_delete>; -using WasmExporttypeVec = WasmVec< - wasm_exporttype_vec_t, - &wasm_exporttype_vec_new_uninitialized, - &wasm_exporttype_vec_delete>; -using WasmImporttypeVec = WasmVec< - wasm_importtype_vec_t, - &wasm_importtype_vec_new_uninitialized, - &wasm_importtype_vec_delete>; +using WasmValtypeVec = WasmVec; +using WasmValVec = WasmVec; +using WasmExternVec = WasmVec; +using WasmExporttypeVec = + WasmVec; +using WasmImporttypeVec = + WasmVec; struct WasmiResult { @@ -97,8 +84,7 @@ struct WasmiResult }; using ModulePtr = std::unique_ptr; -using InstancePtr = - std::unique_ptr; +using InstancePtr = std::unique_ptr; using EnginePtr = std::unique_ptr; using StorePtr = std::unique_ptr; @@ -114,12 +100,7 @@ struct InstanceWrapper private: static InstancePtr - init( - StorePtr& s, - ModulePtr& m, - WasmExternVec& expt, - WasmExternVec const& imports, - beast::Journal j); + init(StorePtr& s, ModulePtr& m, WasmExternVec& expt, WasmExternVec const& imports, beast::Journal j); public: InstanceWrapper(); @@ -129,19 +110,14 @@ public: InstanceWrapper& operator=(InstanceWrapper&& o); - InstanceWrapper( - StorePtr& s, - ModulePtr& m, - WasmExternVec const& imports, - beast::Journal j); + InstanceWrapper(StorePtr& s, ModulePtr& m, WasmExternVec const& imports, beast::Journal j); ~InstanceWrapper() = default; operator bool() const; FuncInfo - getFunc(std::string_view funcName, WasmExporttypeVec const& exportTypes) - const; + getFunc(std::string_view funcName, WasmExporttypeVec const& exportTypes) const; wmem getMem() const; @@ -260,17 +236,10 @@ private: allocate(int32_t size); Expected, TER> - runHlp( - Bytes const& wasmCode, - std::string_view funcName, - std::vector const& params, - int64_t gas); + runHlp(Bytes const& wasmCode, std::string_view funcName, std::vector const& params, int64_t gas); NotTEC - checkHlp( - Bytes const& wasmCode, - std::string_view funcName, - std::vector const& params); + checkHlp(Bytes const& wasmCode, std::string_view funcName, std::vector const& params); int addModule(Bytes const& wasmCode, bool instantiate, int64_t gas); @@ -292,9 +261,7 @@ private: convertParams(std::vector const& params); static int - compareParamTypes( - wasm_valtype_vec_t const* ftp, - std::vector const& p); + compareParamTypes(wasm_valtype_vec_t const* ftp, std::vector const& p); static void add_param(std::vector& in, int32_t p); @@ -315,36 +282,19 @@ private: template inline WasmiResult - call( - FuncInfo const& f, - std::vector& in, - std::int32_t p, - Types&&... args); + call(FuncInfo const& f, std::vector& in, std::int32_t p, Types&&... args); template inline WasmiResult - call( - FuncInfo const& f, - std::vector& in, - std::int64_t p, - Types&&... args); + call(FuncInfo const& f, std::vector& in, std::int64_t p, Types&&... args); template inline WasmiResult - call( - FuncInfo const& f, - std::vector& in, - uint8_t const* d, - int32_t sz, - Types&&... args); + call(FuncInfo const& f, std::vector& in, uint8_t const* d, int32_t sz, Types&&... args); template inline WasmiResult - call( - FuncInfo const& f, - std::vector& in, - Bytes const& p, - Types&&... args); + call(FuncInfo const& f, std::vector& in, Bytes const& p, Types&&... args); }; } // namespace xrpl diff --git a/src/xrpld/app/wasm/detail/HostFuncImpl.cpp b/src/xrpld/app/wasm/detail/HostFuncImpl.cpp index c0c514129f..dfff35727f 100644 --- a/src/xrpld/app/wasm/detail/HostFuncImpl.cpp +++ b/src/xrpld/app/wasm/detail/HostFuncImpl.cpp @@ -25,10 +25,7 @@ WasmHostFunctionsImpl::updateData(Slice const& data) // ========================================================= Expected -WasmHostFunctionsImpl::checkSignature( - Slice const& message, - Slice const& signature, - Slice const& pubkey) +WasmHostFunctionsImpl::checkSignature(Slice const& message, Slice const& signature, Slice const& pubkey) { if (!publicKeyType(pubkey)) return Unexpected(HostFunctionError::INVALID_PARAMS); diff --git a/src/xrpld/app/wasm/detail/HostFuncImplFloat.cpp b/src/xrpld/app/wasm/detail/HostFuncImplFloat.cpp index 29a0dd545f..36231ec37d 100644 --- a/src/xrpld/app/wasm/detail/HostFuncImplFloat.cpp +++ b/src/xrpld/app/wasm/detail/HostFuncImplFloat.cpp @@ -23,8 +23,7 @@ protected: static_assert(wasmMinExponent < 0); - static uint64_t constexpr maxEncodedMantissa = - (1ull << (encodedMantissaBits + 1)) - 1; + static uint64_t constexpr maxEncodedMantissa = (1ull << (encodedMantissaBits + 1)) - 1; bool good_; @@ -44,16 +43,13 @@ public: if (!(v & STAmount::cIssuedCurrency)) return; - int32_t const e = - static_cast((v >> encodedMantissaBits) & 0xFFull); + int32_t const e = static_cast((v >> encodedMantissaBits) & 0xFFull); int32_t const decodedExponent = e + wasmMinExponent - 1; // e - 97 - if (decodedExponent < wasmMinExponent || - decodedExponent > wasmMaxExponent) + if (decodedExponent < wasmMinExponent || decodedExponent > wasmMaxExponent) return; int64_t const neg = (v & STAmount::cPositive) ? 1 : -1; - int64_t const m = - neg * static_cast(v & ((1ull << encodedMantissaBits) - 1)); + int64_t const m = neg * static_cast(v & ((1ull << encodedMantissaBits) - 1)); if (!m) return; @@ -89,8 +85,7 @@ public: good_ = true; } - Number2(Number const& n) - : Number2(n.mantissa(), n.exponent()) // ensure Number canonized + Number2(Number const& n) : Number2(n.mantissa(), n.exponent()) // ensure Number canonized { } @@ -132,8 +127,7 @@ public: } else if (absM > maxEncodedMantissa) { - return Unexpected( - HostFunctionError::FLOAT_COMPUTATION_ERROR); // LCOV_EXCL_LINE + return Unexpected(HostFunctionError::FLOAT_COMPUTATION_ERROR); // LCOV_EXCL_LINE } v |= absM; @@ -149,8 +143,7 @@ public: auto const data = msg.getData(); #ifdef DEBUG_OUTPUT - std::cout << "m: " << std::setw(20) << mantissa() - << ", e: " << std::setw(12) << exponent() << ", hex: "; + std::cout << "m: " << std::setw(20) << mantissa() << ", e: " << std::setw(12) << exponent() << ", hex: "; std::cout << std::hex << std::uppercase << std::setfill('0'); for (auto const& c : data) std::cout << std::setw(2) << (unsigned)c << " "; @@ -161,8 +154,7 @@ public: } }; -Bytes const Number2::floatNull = - {0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; +Bytes const Number2::floatNull = {0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; struct FloatState { @@ -170,13 +162,9 @@ struct FloatState MantissaRange::mantissa_scale oldScale_; bool good_; - FloatState(int32_t mode) - : oldMode_(Number::getround()) - , oldScale_(Number::getMantissaScale()) - , good_(false) + FloatState(int32_t mode) : oldMode_(Number::getround()), oldScale_(Number::getMantissaScale()), good_(false) { - if (mode < Number::rounding_mode::to_nearest || - mode > Number::rounding_mode::upward) + if (mode < Number::rounding_mode::to_nearest || mode > Number::rounding_mode::upward) return; Number::setround(static_cast(mode)); @@ -208,8 +196,7 @@ floatToString(Slice const& data) { std::string hex; hex.reserve(data.size() * 2); - boost::algorithm::hex( - data.begin(), data.end(), std::back_inserter(hex)); + boost::algorithm::hex(data.begin(), data.end(), std::back_inserter(hex)); return "Invalid data: " + hex; } @@ -505,10 +492,7 @@ WasmHostFunctionsImpl::floatFromUint(uint64_t x, int32_t mode) } Expected -WasmHostFunctionsImpl::floatSet( - int64_t mantissa, - int32_t exponent, - int32_t mode) +WasmHostFunctionsImpl::floatSet(int64_t mantissa, int32_t exponent, int32_t mode) { return wasm_float::floatSetImpl(mantissa, exponent, mode); } @@ -526,19 +510,13 @@ WasmHostFunctionsImpl::floatAdd(Slice const& x, Slice const& y, int32_t mode) } Expected -WasmHostFunctionsImpl::floatSubtract( - Slice const& x, - Slice const& y, - int32_t mode) +WasmHostFunctionsImpl::floatSubtract(Slice const& x, Slice const& y, int32_t mode) { return wasm_float::floatSubtractImpl(x, y, mode); } Expected -WasmHostFunctionsImpl::floatMultiply( - Slice const& x, - Slice const& y, - int32_t mode) +WasmHostFunctionsImpl::floatMultiply(Slice const& x, Slice const& y, int32_t mode) { return wasm_float::floatMultiplyImpl(x, y, mode); } diff --git a/src/xrpld/app/wasm/detail/HostFuncImplGetter.cpp b/src/xrpld/app/wasm/detail/HostFuncImplGetter.cpp index 70fb1b5304..0a3247604a 100644 --- a/src/xrpld/app/wasm/detail/HostFuncImplGetter.cpp +++ b/src/xrpld/app/wasm/detail/HostFuncImplGetter.cpp @@ -126,8 +126,7 @@ getAnyFieldData(FieldValue const& variantObj) static inline bool noField(STBase const* field) { - return !field || (STI_NOTPRESENT == field->getSType()) || - (STI_UNKNOWN == field->getSType()); + return !field || (STI_NOTPRESENT == field->getSType()) || (STI_UNKNOWN == field->getSType()); } static Expected @@ -272,8 +271,7 @@ WasmHostFunctionsImpl::getLedgerObjField(int32_t cacheIdx, SField const& fname) auto const normalizedIdx = normalizeCacheIndex(cacheIdx); if (!normalizedIdx.has_value()) return Unexpected(normalizedIdx.error()); - return detail::getAnyFieldData( - cache[normalizedIdx.value()]->peekAtPField(fname)); + return detail::getAnyFieldData(cache[normalizedIdx.value()]->peekAtPField(fname)); } // Subsection: nested getters @@ -303,9 +301,7 @@ WasmHostFunctionsImpl::getCurrentLedgerObjNestedField(Slice const& locator) } Expected -WasmHostFunctionsImpl::getLedgerObjNestedField( - int32_t cacheIdx, - Slice const& locator) +WasmHostFunctionsImpl::getLedgerObjNestedField(int32_t cacheIdx, Slice const& locator) { auto const normalizedIdx = normalizeCacheIndex(cacheIdx); if (!normalizedIdx.has_value()) @@ -351,9 +347,7 @@ WasmHostFunctionsImpl::getCurrentLedgerObjArrayLen(SField const& fname) } Expected -WasmHostFunctionsImpl::getLedgerObjArrayLen( - int32_t cacheIdx, - SField const& fname) +WasmHostFunctionsImpl::getLedgerObjArrayLen(int32_t cacheIdx, SField const& fname) { if (fname.fieldType != STI_ARRAY && fname.fieldType != STI_VECTOR256) return Unexpected(HostFunctionError::NO_ARRAY); @@ -397,9 +391,7 @@ WasmHostFunctionsImpl::getCurrentLedgerObjNestedArrayLen(Slice const& locator) } Expected -WasmHostFunctionsImpl::getLedgerObjNestedArrayLen( - int32_t cacheIdx, - Slice const& locator) +WasmHostFunctionsImpl::getLedgerObjNestedArrayLen(int32_t cacheIdx, Slice const& locator) { auto const normalizedIdx = normalizeCacheIndex(cacheIdx); if (!normalizedIdx.has_value()) diff --git a/src/xrpld/app/wasm/detail/HostFuncImplKeylet.cpp b/src/xrpld/app/wasm/detail/HostFuncImplKeylet.cpp index 89ec35cd3b..a006b584e4 100644 --- a/src/xrpld/app/wasm/detail/HostFuncImplKeylet.cpp +++ b/src/xrpld/app/wasm/detail/HostFuncImplKeylet.cpp @@ -38,16 +38,12 @@ WasmHostFunctionsImpl::checkKeylet(AccountID const& account, std::uint32_t seq) } Expected -WasmHostFunctionsImpl::credentialKeylet( - AccountID const& subject, - AccountID const& issuer, - Slice const& credentialType) +WasmHostFunctionsImpl::credentialKeylet(AccountID const& subject, AccountID const& issuer, Slice const& credentialType) { if (!subject || !issuer) return Unexpected(HostFunctionError::INVALID_ACCOUNT); - if (credentialType.empty() || - credentialType.size() > maxCredentialTypeLength) + if (credentialType.empty() || credentialType.size() > maxCredentialTypeLength) return Unexpected(HostFunctionError::INVALID_PARAMS); auto const keylet = keylet::credential(subject, issuer, credentialType); @@ -65,9 +61,7 @@ WasmHostFunctionsImpl::didKeylet(AccountID const& account) } Expected -WasmHostFunctionsImpl::delegateKeylet( - AccountID const& account, - AccountID const& authorize) +WasmHostFunctionsImpl::delegateKeylet(AccountID const& account, AccountID const& authorize) { if (!account || !authorize) return Unexpected(HostFunctionError::INVALID_ACCOUNT); @@ -78,9 +72,7 @@ WasmHostFunctionsImpl::delegateKeylet( } Expected -WasmHostFunctionsImpl::depositPreauthKeylet( - AccountID const& account, - AccountID const& authorize) +WasmHostFunctionsImpl::depositPreauthKeylet(AccountID const& account, AccountID const& authorize) { if (!account || !authorize) return Unexpected(HostFunctionError::INVALID_ACCOUNT); @@ -100,10 +92,7 @@ WasmHostFunctionsImpl::escrowKeylet(AccountID const& account, std::uint32_t seq) } Expected -WasmHostFunctionsImpl::lineKeylet( - AccountID const& account1, - AccountID const& account2, - Currency const& currency) +WasmHostFunctionsImpl::lineKeylet(AccountID const& account1, AccountID const& account2, Currency const& currency) { if (!account1 || !account2) return Unexpected(HostFunctionError::INVALID_ACCOUNT); @@ -117,9 +106,7 @@ WasmHostFunctionsImpl::lineKeylet( } Expected -WasmHostFunctionsImpl::mptIssuanceKeylet( - AccountID const& issuer, - std::uint32_t seq) +WasmHostFunctionsImpl::mptIssuanceKeylet(AccountID const& issuer, std::uint32_t seq) { if (!issuer) return Unexpected(HostFunctionError::INVALID_ACCOUNT); @@ -129,9 +116,7 @@ WasmHostFunctionsImpl::mptIssuanceKeylet( } Expected -WasmHostFunctionsImpl::mptokenKeylet( - MPTID const& mptid, - AccountID const& holder) +WasmHostFunctionsImpl::mptokenKeylet(MPTID const& mptid, AccountID const& holder) { if (!mptid) return Unexpected(HostFunctionError::INVALID_PARAMS); @@ -143,9 +128,7 @@ WasmHostFunctionsImpl::mptokenKeylet( } Expected -WasmHostFunctionsImpl::nftOfferKeylet( - AccountID const& account, - std::uint32_t seq) +WasmHostFunctionsImpl::nftOfferKeylet(AccountID const& account, std::uint32_t seq) { if (!account) return Unexpected(HostFunctionError::INVALID_ACCOUNT); @@ -163,9 +146,7 @@ WasmHostFunctionsImpl::offerKeylet(AccountID const& account, std::uint32_t seq) } Expected -WasmHostFunctionsImpl::oracleKeylet( - AccountID const& account, - std::uint32_t documentId) +WasmHostFunctionsImpl::oracleKeylet(AccountID const& account, std::uint32_t documentId) { if (!account) return Unexpected(HostFunctionError::INVALID_ACCOUNT); @@ -174,10 +155,7 @@ WasmHostFunctionsImpl::oracleKeylet( } Expected -WasmHostFunctionsImpl::paychanKeylet( - AccountID const& account, - AccountID const& destination, - std::uint32_t seq) +WasmHostFunctionsImpl::paychanKeylet(AccountID const& account, AccountID const& destination, std::uint32_t seq) { if (!account || !destination) return Unexpected(HostFunctionError::INVALID_ACCOUNT); @@ -188,9 +166,7 @@ WasmHostFunctionsImpl::paychanKeylet( } Expected -WasmHostFunctionsImpl::permissionedDomainKeylet( - AccountID const& account, - std::uint32_t seq) +WasmHostFunctionsImpl::permissionedDomainKeylet(AccountID const& account, std::uint32_t seq) { if (!account) return Unexpected(HostFunctionError::INVALID_ACCOUNT); diff --git a/src/xrpld/app/wasm/detail/HostFuncImplTrace.cpp b/src/xrpld/app/wasm/detail/HostFuncImplTrace.cpp index 31e90df7ab..c3b0b95529 100644 --- a/src/xrpld/app/wasm/detail/HostFuncImplTrace.cpp +++ b/src/xrpld/app/wasm/detail/HostFuncImplTrace.cpp @@ -10,25 +10,18 @@ namespace xrpl { Expected -WasmHostFunctionsImpl::trace( - std::string_view const& msg, - Slice const& data, - bool asHex) +WasmHostFunctionsImpl::trace(std::string_view const& msg, Slice const& data, bool asHex) { if (!asHex) { - log(msg, [&data] { - return std::string_view( - reinterpret_cast(data.data()), data.size()); - }); + log(msg, [&data] { return std::string_view(reinterpret_cast(data.data()), data.size()); }); } else { log(msg, [&data] { std::string hex; hex.reserve(data.size() * 2); - boost::algorithm::hex( - data.begin(), data.end(), std::back_inserter(hex)); + boost::algorithm::hex(data.begin(), data.end(), std::back_inserter(hex)); return hex; }); } @@ -44,27 +37,21 @@ WasmHostFunctionsImpl::traceNum(std::string_view const& msg, int64_t data) } Expected -WasmHostFunctionsImpl::traceAccount( - std::string_view const& msg, - AccountID const& account) +WasmHostFunctionsImpl::traceAccount(std::string_view const& msg, AccountID const& account) { log(msg, [&account] { return toBase58(account); }); return 0; } Expected -WasmHostFunctionsImpl::traceFloat( - std::string_view const& msg, - Slice const& data) +WasmHostFunctionsImpl::traceFloat(std::string_view const& msg, Slice const& data) { log(msg, [&data] { return wasm_float::floatToString(data); }); return 0; } Expected -WasmHostFunctionsImpl::traceAmount( - std::string_view const& msg, - STAmount const& amount) +WasmHostFunctionsImpl::traceAmount(std::string_view const& msg, STAmount const& amount) { log(msg, [&amount] { return amount.getFullText(); }); return 0; diff --git a/src/xrpld/app/wasm/detail/HostFuncWrapper.cpp b/src/xrpld/app/wasm/detail/HostFuncWrapper.cpp index da768ff6eb..ffae4de7ed 100644 --- a/src/xrpld/app/wasm/detail/HostFuncWrapper.cpp +++ b/src/xrpld/app/wasm/detail/HostFuncWrapper.cpp @@ -11,12 +11,7 @@ namespace xrpl { using SFieldCRef = std::reference_wrapper; static int32_t -setData( - InstanceWrapper const* runtime, - int32_t dst, - int32_t dstSize, - uint8_t const* src, - int32_t srcSize) +setData(InstanceWrapper const* runtime, int32_t dst, int32_t dstSize, uint8_t const* src, int32_t srcSize) { if (!srcSize) return 0; // LCOV_EXCL_LINE @@ -98,11 +93,7 @@ getDataSField(IW const* _runtime, wasm_val_vec_t const* params, int32_t& i) template Expected -getDataSlice( - IW const* runtime, - wasm_val_vec_t const* params, - int32_t& i, - bool isUpdate = false) +getDataSlice(IW const* runtime, wasm_val_vec_t const* params, int32_t& i, bool isUpdate = false) { int64_t const ptr = params->data[i].of.i32; int64_t const size = params->data[i + 1].of.i32; @@ -209,9 +200,8 @@ getDataAsset(IW const* runtime, wasm_val_vec_t const* params, int32_t& i) if (slice->size() == (AccountID::bytes + Currency::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() + Currency::bytes)); if (issue.native()) return Unexpected(HostFunctionError::INVALID_PARAMS); @@ -228,8 +218,7 @@ getDataString(IW const* runtime, wasm_val_vec_t const* params, int32_t& i) auto const slice = getDataSlice(runtime, params, i); if (!slice) return Unexpected(slice.error()); - return std::string_view( - reinterpret_cast(slice->data()), slice->size()); + return std::string_view(reinterpret_cast(slice->data()), slice->size()); } std::nullptr_t @@ -267,23 +256,13 @@ returnResult( { return hfResult( results, - setData( - runtime, - params->data[index].of.i32, - params->data[index + 1].of.i32, - res->data(), - res->size())); + setData(runtime, params->data[index].of.i32, params->data[index + 1].of.i32, res->data(), res->size())); } else if constexpr (std::is_same_v) { return hfResult( results, - setData( - runtime, - params->data[index].of.i32, - params->data[index + 1].of.i32, - res->data(), - res->size())); + setData(runtime, params->data[index].of.i32, params->data[index + 1].of.i32, res->data(), res->size())); } else if constexpr (std::is_same_v) { @@ -303,8 +282,7 @@ returnResult( } else { - static_assert( - [] { return false; }(), "Unhandled return type in returnResult"); + static_assert([] { return false; }(), "Unhandled return type in returnResult"); } } @@ -325,9 +303,9 @@ checkGas(void* env) auto const* runtime = reinterpret_cast(hf->getRT()); if (!runtime) { - wasm_trap_t* trap = reinterpret_cast( - WasmEngine::instance().newTrap("hf no runtime")); // LCOV_EXCL_LINE - return Unexpected(trap); // LCOV_EXCL_LINE + wasm_trap_t* trap = + reinterpret_cast(WasmEngine::instance().newTrap("hf no runtime")); // LCOV_EXCL_LINE + return Unexpected(trap); // LCOV_EXCL_LINE } int64_t const gas = runtime->getGas(); @@ -336,15 +314,14 @@ checkGas(void* env) if (runtime->setGas(x) < 0) { - wasm_trap_t* trap = reinterpret_cast( - WasmEngine::instance().newTrap("can't set gas")); // LCOV_EXCL_LINE - return Unexpected(trap); // LCOV_EXCL_LINE + wasm_trap_t* trap = + reinterpret_cast(WasmEngine::instance().newTrap("can't set gas")); // LCOV_EXCL_LINE + return Unexpected(trap); // LCOV_EXCL_LINE } if (gas < impFunc.gas) { - wasm_trap_t* trap = reinterpret_cast( - WasmEngine::instance().newTrap("hf out of gas")); + wasm_trap_t* trap = reinterpret_cast(WasmEngine::instance().newTrap("hf out of gas")); return Unexpected(trap); } @@ -353,10 +330,7 @@ checkGas(void* env) //---------------------------------------------------------------------------------------------------------------------- wasm_trap_t* -getLedgerSqn_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results) +getLedgerSqn_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results) { if (auto g = checkGas(env); !g) return g.error(); // LCOV_EXCL_LINE @@ -368,10 +342,7 @@ getLedgerSqn_wrap( } wasm_trap_t* -getParentLedgerTime_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results) +getParentLedgerTime_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results) { if (auto g = checkGas(env); !g) return g.error(); // LCOV_EXCL_LINE @@ -379,15 +350,11 @@ getParentLedgerTime_wrap( auto const* runtime = reinterpret_cast(hf->getRT()); int index = 0; - return returnResult( - runtime, params, results, hf->getParentLedgerTime(), index); + return returnResult(runtime, params, results, hf->getParentLedgerTime(), index); } wasm_trap_t* -getParentLedgerHash_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results) +getParentLedgerHash_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results) { if (auto g = checkGas(env); !g) return g.error(); // LCOV_EXCL_LINE @@ -395,15 +362,11 @@ getParentLedgerHash_wrap( auto const* runtime = reinterpret_cast(hf->getRT()); int index = 0; - return returnResult( - runtime, params, results, hf->getParentLedgerHash(), index); + return returnResult(runtime, params, results, hf->getParentLedgerHash(), index); } wasm_trap_t* -getBaseFee_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results) +getBaseFee_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results) { if (auto g = checkGas(env); !g) return g.error(); // LCOV_EXCL_LINE @@ -415,10 +378,7 @@ getBaseFee_wrap( } wasm_trap_t* -isAmendmentEnabled_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results) +isAmendmentEnabled_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results) { if (auto g = checkGas(env); !g) return g.error(); // LCOV_EXCL_LINE @@ -434,8 +394,7 @@ isAmendmentEnabled_wrap( if (slice->size() == uint256::bytes) { - if (auto ret = hf->isAmendmentEnabled(uint256::fromVoid(slice->data())); - *ret == 1) + if (auto ret = hf->isAmendmentEnabled(uint256::fromVoid(slice->data())); *ret == 1) { return returnResult(runtime, params, results, ret, index); } @@ -446,17 +405,12 @@ isAmendmentEnabled_wrap( return hfResult(results, HostFunctionError::DATA_FIELD_TOO_LARGE); } - auto const str = std::string_view( - reinterpret_cast(slice->data()), slice->size()); - return returnResult( - runtime, params, results, hf->isAmendmentEnabled(str), index); + auto const str = std::string_view(reinterpret_cast(slice->data()), slice->size()); + return returnResult(runtime, params, results, hf->isAmendmentEnabled(str), index); } wasm_trap_t* -cacheLedgerObj_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results) +cacheLedgerObj_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results) { if (auto g = checkGas(env); !g) return g.error(); // LCOV_EXCL_LINE @@ -476,15 +430,11 @@ cacheLedgerObj_wrap( return hfResult(results, cache.error()); // LCOV_EXCL_LINE } - return returnResult( - runtime, params, results, hf->cacheLedgerObj(*id, *cache), index); + return returnResult(runtime, params, results, hf->cacheLedgerObj(*id, *cache), index); } wasm_trap_t* -getTxField_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results) +getTxField_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results) { if (auto g = checkGas(env); !g) return g.error(); // LCOV_EXCL_LINE @@ -497,15 +447,11 @@ getTxField_wrap( { return hfResult(results, fname.error()); } - return returnResult( - runtime, params, results, hf->getTxField(*fname), index); + return returnResult(runtime, params, results, hf->getTxField(*fname), index); } wasm_trap_t* -getCurrentLedgerObjField_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results) +getCurrentLedgerObjField_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results) { if (auto g = checkGas(env); !g) return g.error(); // LCOV_EXCL_LINE @@ -519,15 +465,11 @@ getCurrentLedgerObjField_wrap( return hfResult(results, fname.error()); } - return returnResult( - runtime, params, results, hf->getCurrentLedgerObjField(*fname), index); + return returnResult(runtime, params, results, hf->getCurrentLedgerObjField(*fname), index); } wasm_trap_t* -getLedgerObjField_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results) +getLedgerObjField_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results) { if (auto g = checkGas(env); !g) return g.error(); // LCOV_EXCL_LINE @@ -547,15 +489,11 @@ getLedgerObjField_wrap( return hfResult(results, fname.error()); } - return returnResult( - runtime, params, results, hf->getLedgerObjField(*cache, *fname), index); + return returnResult(runtime, params, results, hf->getLedgerObjField(*cache, *fname), index); } wasm_trap_t* -getTxNestedField_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results) +getTxNestedField_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results) { if (auto g = checkGas(env); !g) return g.error(); // LCOV_EXCL_LINE @@ -569,15 +507,11 @@ getTxNestedField_wrap( return hfResult(results, bytes.error()); } - return returnResult( - runtime, params, results, hf->getTxNestedField(*bytes), index); + return returnResult(runtime, params, results, hf->getTxNestedField(*bytes), index); } wasm_trap_t* -getCurrentLedgerObjNestedField_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results) +getCurrentLedgerObjNestedField_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results) { if (auto g = checkGas(env); !g) return g.error(); // LCOV_EXCL_LINE @@ -590,19 +524,11 @@ getCurrentLedgerObjNestedField_wrap( { return hfResult(results, bytes.error()); } - return returnResult( - runtime, - params, - results, - hf->getCurrentLedgerObjNestedField(*bytes), - index); + return returnResult(runtime, params, results, hf->getCurrentLedgerObjNestedField(*bytes), index); } wasm_trap_t* -getLedgerObjNestedField_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results) +getLedgerObjNestedField_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results) { if (auto g = checkGas(env); !g) return g.error(); // LCOV_EXCL_LINE @@ -622,19 +548,11 @@ getLedgerObjNestedField_wrap( return hfResult(results, bytes.error()); } - return returnResult( - runtime, - params, - results, - hf->getLedgerObjNestedField(*cache, *bytes), - index); + return returnResult(runtime, params, results, hf->getLedgerObjNestedField(*cache, *bytes), index); } wasm_trap_t* -getTxArrayLen_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results) +getTxArrayLen_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results) { if (auto g = checkGas(env); !g) return g.error(); // LCOV_EXCL_LINE @@ -648,15 +566,11 @@ getTxArrayLen_wrap( return hfResult(results, fname.error()); } - return returnResult( - runtime, params, results, hf->getTxArrayLen(*fname), index); + return returnResult(runtime, params, results, hf->getTxArrayLen(*fname), index); } wasm_trap_t* -getCurrentLedgerObjArrayLen_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results) +getCurrentLedgerObjArrayLen_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results) { if (auto g = checkGas(env); !g) return g.error(); // LCOV_EXCL_LINE @@ -670,19 +584,11 @@ getCurrentLedgerObjArrayLen_wrap( return hfResult(results, fname.error()); } - return returnResult( - runtime, - params, - results, - hf->getCurrentLedgerObjArrayLen(*fname), - index); + return returnResult(runtime, params, results, hf->getCurrentLedgerObjArrayLen(*fname), index); } wasm_trap_t* -getLedgerObjArrayLen_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results) +getLedgerObjArrayLen_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results) { if (auto g = checkGas(env); !g) return g.error(); // LCOV_EXCL_LINE @@ -702,19 +608,11 @@ getLedgerObjArrayLen_wrap( return hfResult(results, fname.error()); } - return returnResult( - runtime, - params, - results, - hf->getLedgerObjArrayLen(*cache, *fname), - index); + return returnResult(runtime, params, results, hf->getLedgerObjArrayLen(*cache, *fname), index); } wasm_trap_t* -getTxNestedArrayLen_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results) +getTxNestedArrayLen_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results) { if (auto g = checkGas(env); !g) return g.error(); // LCOV_EXCL_LINE @@ -728,15 +626,11 @@ getTxNestedArrayLen_wrap( return hfResult(results, bytes.error()); } - return returnResult( - runtime, params, results, hf->getTxNestedArrayLen(*bytes), index); + return returnResult(runtime, params, results, hf->getTxNestedArrayLen(*bytes), index); } wasm_trap_t* -getCurrentLedgerObjNestedArrayLen_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results) +getCurrentLedgerObjNestedArrayLen_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results) { if (auto g = checkGas(env); !g) return g.error(); // LCOV_EXCL_LINE @@ -750,18 +644,10 @@ getCurrentLedgerObjNestedArrayLen_wrap( return hfResult(results, bytes.error()); } - return returnResult( - runtime, - params, - results, - hf->getCurrentLedgerObjNestedArrayLen(*bytes), - index); + return returnResult(runtime, params, results, hf->getCurrentLedgerObjNestedArrayLen(*bytes), index); } wasm_trap_t* -getLedgerObjNestedArrayLen_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results) +getLedgerObjNestedArrayLen_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results) { if (auto g = checkGas(env); !g) return g.error(); // LCOV_EXCL_LINE @@ -780,19 +666,11 @@ getLedgerObjNestedArrayLen_wrap( { return hfResult(results, bytes.error()); } - return returnResult( - runtime, - params, - results, - hf->getLedgerObjNestedArrayLen(*cache, *bytes), - index); + return returnResult(runtime, params, results, hf->getLedgerObjNestedArrayLen(*cache, *bytes), index); } wasm_trap_t* -updateData_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results) +updateData_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results) { if (auto g = checkGas(env); !g) return g.error(); // LCOV_EXCL_LINE @@ -806,15 +684,11 @@ updateData_wrap( return hfResult(results, bytes.error()); } - return returnResult( - runtime, params, results, hf->updateData(*bytes), index); + return returnResult(runtime, params, results, hf->updateData(*bytes), index); } wasm_trap_t* -checkSignature_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results) +checkSignature_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results) { if (auto g = checkGas(env); !g) return g.error(); // LCOV_EXCL_LINE @@ -840,19 +714,11 @@ checkSignature_wrap( return hfResult(results, pubkey.error()); } - return returnResult( - runtime, - params, - results, - hf->checkSignature(*message, *signature, *pubkey), - index); + return returnResult(runtime, params, results, hf->checkSignature(*message, *signature, *pubkey), index); } wasm_trap_t* -computeSha512HalfHash_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results) +computeSha512HalfHash_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results) { if (auto g = checkGas(env); !g) return g.error(); // LCOV_EXCL_LINE @@ -865,15 +731,11 @@ computeSha512HalfHash_wrap( { return hfResult(results, bytes.error()); } - return returnResult( - runtime, params, results, hf->computeSha512HalfHash(*bytes), index); + return returnResult(runtime, params, results, hf->computeSha512HalfHash(*bytes), index); } wasm_trap_t* -accountKeylet_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results) +accountKeylet_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results) { if (auto g = checkGas(env); !g) return g.error(); // LCOV_EXCL_LINE @@ -887,8 +749,7 @@ accountKeylet_wrap( return hfResult(results, acc.error()); } - return returnResult( - runtime, params, results, hf->accountKeylet(*acc), index); + return returnResult(runtime, params, results, hf->accountKeylet(*acc), index); } wasm_trap_t* @@ -912,19 +773,11 @@ ammKeylet_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results) return hfResult(results, issue2.error()); } - return returnResult( - runtime, - params, - results, - hf->ammKeylet(issue1.value(), issue2.value()), - index); + return returnResult(runtime, params, results, hf->ammKeylet(issue1.value(), issue2.value()), index); } wasm_trap_t* -checkKeylet_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results) +checkKeylet_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results) { if (auto g = checkGas(env); !g) return g.error(); // LCOV_EXCL_LINE @@ -944,15 +797,11 @@ checkKeylet_wrap( return hfResult(results, seq.error()); // LCOV_EXCL_LINE } - return returnResult( - runtime, params, results, hf->checkKeylet(acc.value(), *seq), index); + return returnResult(runtime, params, results, hf->checkKeylet(acc.value(), *seq), index); } wasm_trap_t* -credentialKeylet_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results) +credentialKeylet_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results) { if (auto g = checkGas(env); !g) return g.error(); // LCOV_EXCL_LINE @@ -978,19 +827,11 @@ credentialKeylet_wrap( return hfResult(results, credType.error()); } - return returnResult( - runtime, - params, - results, - hf->credentialKeylet(*subj, *iss, *credType), - index); + return returnResult(runtime, params, results, hf->credentialKeylet(*subj, *iss, *credType), index); } wasm_trap_t* -delegateKeylet_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results) +delegateKeylet_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results) { if (auto g = checkGas(env); !g) return g.error(); // LCOV_EXCL_LINE @@ -1010,19 +851,11 @@ delegateKeylet_wrap( return hfResult(results, authorize.error()); } - return returnResult( - runtime, - params, - results, - hf->delegateKeylet(acc.value(), authorize.value()), - index); + return returnResult(runtime, params, results, hf->delegateKeylet(acc.value(), authorize.value()), index); } wasm_trap_t* -depositPreauthKeylet_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results) +depositPreauthKeylet_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results) { if (auto g = checkGas(env); !g) return g.error(); // LCOV_EXCL_LINE @@ -1042,12 +875,7 @@ depositPreauthKeylet_wrap( return hfResult(results, authorize.error()); } - return returnResult( - runtime, - params, - results, - hf->depositPreauthKeylet(acc.value(), authorize.value()), - index); + return returnResult(runtime, params, results, hf->depositPreauthKeylet(acc.value(), authorize.value()), index); } wasm_trap_t* @@ -1065,15 +893,11 @@ didKeylet_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results) return hfResult(results, acc.error()); } - return returnResult( - runtime, params, results, hf->didKeylet(acc.value()), index); + return returnResult(runtime, params, results, hf->didKeylet(acc.value()), index); } wasm_trap_t* -escrowKeylet_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results) +escrowKeylet_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results) { if (auto g = checkGas(env); !g) return g.error(); // LCOV_EXCL_LINE @@ -1093,15 +917,11 @@ escrowKeylet_wrap( return hfResult(results, seq.error()); // LCOV_EXCL_LINE } - return returnResult( - runtime, params, results, hf->escrowKeylet(*acc, *seq), index); + return returnResult(runtime, params, results, hf->escrowKeylet(*acc, *seq), index); } wasm_trap_t* -lineKeylet_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results) +lineKeylet_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results) { if (auto g = checkGas(env); !g) return g.error(); // LCOV_EXCL_LINE @@ -1127,19 +947,11 @@ lineKeylet_wrap( return hfResult(results, currency.error()); } - return returnResult( - runtime, - params, - results, - hf->lineKeylet(acc1.value(), acc2.value(), currency.value()), - index); + return returnResult(runtime, params, results, hf->lineKeylet(acc1.value(), acc2.value(), currency.value()), index); } wasm_trap_t* -mptIssuanceKeylet_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results) +mptIssuanceKeylet_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results) { if (auto g = checkGas(env); !g) return g.error(); // LCOV_EXCL_LINE @@ -1159,19 +971,11 @@ mptIssuanceKeylet_wrap( return hfResult(results, seq.error()); // LCOV_EXCL_LINE } - return returnResult( - runtime, - params, - results, - hf->mptIssuanceKeylet(acc.value(), seq.value()), - index); + return returnResult(runtime, params, results, hf->mptIssuanceKeylet(acc.value(), seq.value()), index); } wasm_trap_t* -mptokenKeylet_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results) +mptokenKeylet_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results) { if (auto g = checkGas(env); !g) return g.error(); // LCOV_EXCL_LINE @@ -1197,19 +1001,11 @@ mptokenKeylet_wrap( return hfResult(results, holder.error()); } - return returnResult( - runtime, - params, - results, - hf->mptokenKeylet(mptid, holder.value()), - index); + return returnResult(runtime, params, results, hf->mptokenKeylet(mptid, holder.value()), index); } wasm_trap_t* -nftOfferKeylet_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results) +nftOfferKeylet_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results) { if (auto g = checkGas(env); !g) return g.error(); // LCOV_EXCL_LINE @@ -1229,19 +1025,11 @@ nftOfferKeylet_wrap( return hfResult(results, seq.error()); // LCOV_EXCL_LINE } - return returnResult( - runtime, - params, - results, - hf->nftOfferKeylet(acc.value(), seq.value()), - index); + return returnResult(runtime, params, results, hf->nftOfferKeylet(acc.value(), seq.value()), index); } wasm_trap_t* -offerKeylet_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results) +offerKeylet_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results) { if (auto g = checkGas(env); !g) return g.error(); // LCOV_EXCL_LINE @@ -1261,19 +1049,11 @@ offerKeylet_wrap( return hfResult(results, seq.error()); // LCOV_EXCL_LINE } - return returnResult( - runtime, - params, - results, - hf->offerKeylet(acc.value(), seq.value()), - index); + return returnResult(runtime, params, results, hf->offerKeylet(acc.value(), seq.value()), index); } wasm_trap_t* -oracleKeylet_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results) +oracleKeylet_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results) { if (auto g = checkGas(env); !g) return g.error(); // LCOV_EXCL_LINE @@ -1292,15 +1072,11 @@ oracleKeylet_wrap( { return hfResult(results, documentId.error()); // LCOV_EXCL_LINE } - return returnResult( - runtime, params, results, hf->oracleKeylet(*acc, *documentId), index); + return returnResult(runtime, params, results, hf->oracleKeylet(*acc, *documentId), index); } wasm_trap_t* -paychanKeylet_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results) +paychanKeylet_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results) { if (auto g = checkGas(env); !g) return g.error(); // LCOV_EXCL_LINE @@ -1326,19 +1102,11 @@ paychanKeylet_wrap( return hfResult(results, seq.error()); // LCOV_EXCL_LINE } - return returnResult( - runtime, - params, - results, - hf->paychanKeylet(acc.value(), dest.value(), seq.value()), - index); + return returnResult(runtime, params, results, hf->paychanKeylet(acc.value(), dest.value(), seq.value()), index); } wasm_trap_t* -permissionedDomainKeylet_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results) +permissionedDomainKeylet_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results) { if (auto g = checkGas(env); !g) return g.error(); // LCOV_EXCL_LINE @@ -1358,19 +1126,11 @@ permissionedDomainKeylet_wrap( return hfResult(results, seq.error()); // LCOV_EXCL_LINE } - return returnResult( - runtime, - params, - results, - hf->permissionedDomainKeylet(acc.value(), seq.value()), - index); + return returnResult(runtime, params, results, hf->permissionedDomainKeylet(acc.value(), seq.value()), index); } wasm_trap_t* -signersKeylet_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results) +signersKeylet_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results) { if (auto g = checkGas(env); !g) return g.error(); // LCOV_EXCL_LINE @@ -1384,15 +1144,11 @@ signersKeylet_wrap( return hfResult(results, acc.error()); } - return returnResult( - runtime, params, results, hf->signersKeylet(acc.value()), index); + return returnResult(runtime, params, results, hf->signersKeylet(acc.value()), index); } wasm_trap_t* -ticketKeylet_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results) +ticketKeylet_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results) { if (auto g = checkGas(env); !g) return g.error(); // LCOV_EXCL_LINE @@ -1412,19 +1168,11 @@ ticketKeylet_wrap( return hfResult(results, seq.error()); // LCOV_EXCL_LINE } - return returnResult( - runtime, - params, - results, - hf->ticketKeylet(acc.value(), seq.value()), - index); + return returnResult(runtime, params, results, hf->ticketKeylet(acc.value(), seq.value()), index); } wasm_trap_t* -vaultKeylet_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results) +vaultKeylet_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results) { if (auto g = checkGas(env); !g) return g.error(); // LCOV_EXCL_LINE @@ -1444,12 +1192,7 @@ vaultKeylet_wrap( return hfResult(results, seq.error()); // LCOV_EXCL_LINE } - return returnResult( - runtime, - params, - results, - hf->vaultKeylet(acc.value(), seq.value()), - index); + return returnResult(runtime, params, results, hf->vaultKeylet(acc.value(), seq.value()), index); } wasm_trap_t* @@ -1473,15 +1216,11 @@ getNFT_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results) return hfResult(results, nftId.error()); } - return returnResult( - runtime, params, results, hf->getNFT(*acc, *nftId), index); + return returnResult(runtime, params, results, hf->getNFT(*acc, *nftId), index); } wasm_trap_t* -getNFTIssuer_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results) +getNFTIssuer_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results) { if (auto g = checkGas(env); !g) return g.error(); // LCOV_EXCL_LINE @@ -1495,15 +1234,11 @@ getNFTIssuer_wrap( return hfResult(results, nftId.error()); } - return returnResult( - runtime, params, results, hf->getNFTIssuer(*nftId), index); + return returnResult(runtime, params, results, hf->getNFTIssuer(*nftId), index); } wasm_trap_t* -getNFTTaxon_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results) +getNFTTaxon_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results) { if (auto g = checkGas(env); !g) return g.error(); // LCOV_EXCL_LINE @@ -1517,15 +1252,11 @@ getNFTTaxon_wrap( return hfResult(results, nftId.error()); } - return returnResult( - runtime, params, results, hf->getNFTTaxon(*nftId), index); + return returnResult(runtime, params, results, hf->getNFTTaxon(*nftId), index); } wasm_trap_t* -getNFTFlags_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results) +getNFTFlags_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results) { if (auto g = checkGas(env); !g) return g.error(); // LCOV_EXCL_LINE @@ -1539,15 +1270,11 @@ getNFTFlags_wrap( return hfResult(results, nftId.error()); } - return returnResult( - runtime, params, results, hf->getNFTFlags(*nftId), index); + return returnResult(runtime, params, results, hf->getNFTFlags(*nftId), index); } wasm_trap_t* -getNFTTransferFee_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results) +getNFTTransferFee_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results) { if (auto g = checkGas(env); !g) return g.error(); // LCOV_EXCL_LINE @@ -1561,15 +1288,11 @@ getNFTTransferFee_wrap( return hfResult(results, nftId.error()); } - return returnResult( - runtime, params, results, hf->getNFTTransferFee(*nftId), index); + return returnResult(runtime, params, results, hf->getNFTTransferFee(*nftId), index); } wasm_trap_t* -getNFTSerial_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results) +getNFTSerial_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results) { if (auto g = checkGas(env); !g) return g.error(); // LCOV_EXCL_LINE @@ -1583,8 +1306,7 @@ getNFTSerial_wrap( return hfResult(results, nftId.error()); } - return returnResult( - runtime, params, results, hf->getNFTSerial(*nftId), index); + return returnResult(runtime, params, results, hf->getNFTSerial(*nftId), index); } wasm_trap_t* @@ -1619,8 +1341,7 @@ trace_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results) return hfResult(results, asHex.error()); // LCOV_EXCL_LINE } - return returnResult( - runtime, params, results, hf->trace(*msg, *data, *asHex), index); + return returnResult(runtime, params, results, hf->trace(*msg, *data, *asHex), index); } wasm_trap_t* @@ -1648,15 +1369,11 @@ traceNum_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results) return hfResult(results, number.error()); // LCOV_EXCL_LINE } - return returnResult( - runtime, params, results, hf->traceNum(*msg, *number), index); + return returnResult(runtime, params, results, hf->traceNum(*msg, *number), index); } wasm_trap_t* -traceAccount_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results) +traceAccount_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results) { if (auto g = checkGas(env); !g) return g.error(); // LCOV_EXCL_LINE @@ -1675,15 +1392,11 @@ traceAccount_wrap( if (!account) return hfResult(results, account.error()); - return returnResult( - runtime, params, results, hf->traceAccount(*msg, *account), i); + return returnResult(runtime, params, results, hf->traceAccount(*msg, *account), i); } wasm_trap_t* -traceFloat_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results) +traceFloat_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results) { if (auto g = checkGas(env); !g) return g.error(); // LCOV_EXCL_LINE @@ -1702,15 +1415,11 @@ traceFloat_wrap( if (!number) return hfResult(results, number.error()); - return returnResult( - runtime, params, results, hf->traceFloat(*msg, *number), i); + return returnResult(runtime, params, results, hf->traceFloat(*msg, *number), i); } wasm_trap_t* -traceAmount_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results) +traceAmount_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results) { if (auto g = checkGas(env); !g) return g.error(); // LCOV_EXCL_LINE @@ -1744,15 +1453,11 @@ traceAmount_wrap( if (!amount) return hfResult(results, HostFunctionError::INVALID_PARAMS); - return returnResult( - runtime, params, results, hf->traceAmount(*msg, *amount), i); + return returnResult(runtime, params, results, hf->traceAmount(*msg, *amount), i); } wasm_trap_t* -floatFromInt_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results) +floatFromInt_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results) { if (auto g = checkGas(env); !g) return g.error(); // LCOV_EXCL_LINE @@ -1770,15 +1475,11 @@ floatFromInt_wrap( return hfResult(results, rounding.error()); // LCOV_EXCL_LINE i = 1; - return returnResult( - runtime, params, results, hf->floatFromInt(*x, *rounding), i); + return returnResult(runtime, params, results, hf->floatFromInt(*x, *rounding), i); } wasm_trap_t* -floatFromUint_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results) +floatFromUint_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results) { if (auto g = checkGas(env); !g) return g.error(); // LCOV_EXCL_LINE @@ -1796,8 +1497,7 @@ floatFromUint_wrap( return hfResult(results, rounding.error()); // LCOV_EXCL_LINE i = 2; - return returnResult( - runtime, params, results, hf->floatFromUint(*x, *rounding), i); + return returnResult(runtime, params, results, hf->floatFromUint(*x, *rounding), i); } wasm_trap_t* @@ -1823,15 +1523,11 @@ floatSet_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results) return hfResult(results, rounding.error()); // LCOV_EXCL_LINE i = 2; - return returnResult( - runtime, params, results, hf->floatSet(*mant, *exp, *rounding), i); + return returnResult(runtime, params, results, hf->floatSet(*mant, *exp, *rounding), i); } wasm_trap_t* -floatCompare_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results) +floatCompare_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results) { if (auto g = checkGas(env); !g) return g.error(); // LCOV_EXCL_LINE @@ -1873,15 +1569,11 @@ floatAdd_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results) return hfResult(results, rounding.error()); // LCOV_EXCL_LINE i = 4; - return returnResult( - runtime, params, results, hf->floatAdd(*x, *y, *rounding), i); + return returnResult(runtime, params, results, hf->floatAdd(*x, *y, *rounding), i); } wasm_trap_t* -floatSubtract_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results) +floatSubtract_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results) { if (auto g = checkGas(env); !g) return g.error(); // LCOV_EXCL_LINE @@ -1903,15 +1595,11 @@ floatSubtract_wrap( return hfResult(results, rounding.error()); // LCOV_EXCL_LINE i = 4; - return returnResult( - runtime, params, results, hf->floatSubtract(*x, *y, *rounding), i); + return returnResult(runtime, params, results, hf->floatSubtract(*x, *y, *rounding), i); } wasm_trap_t* -floatMultiply_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results) +floatMultiply_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results) { if (auto g = checkGas(env); !g) return g.error(); // LCOV_EXCL_LINE @@ -1933,15 +1621,11 @@ floatMultiply_wrap( return hfResult(results, rounding.error()); // LCOV_EXCL_LINE i = 4; - return returnResult( - runtime, params, results, hf->floatMultiply(*x, *y, *rounding), i); + return returnResult(runtime, params, results, hf->floatMultiply(*x, *y, *rounding), i); } wasm_trap_t* -floatDivide_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results) +floatDivide_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results) { if (auto g = checkGas(env); !g) return g.error(); // LCOV_EXCL_LINE @@ -1963,8 +1647,7 @@ floatDivide_wrap( return hfResult(results, rounding.error()); // LCOV_EXCL_LINE i = 4; - return returnResult( - runtime, params, results, hf->floatDivide(*x, *y, *rounding), i); + return returnResult(runtime, params, results, hf->floatDivide(*x, *y, *rounding), i); } wasm_trap_t* @@ -1990,15 +1673,11 @@ floatRoot_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results) return hfResult(results, rounding.error()); // LCOV_EXCL_LINE i = 3; - return returnResult( - runtime, params, results, hf->floatRoot(*x, *n, *rounding), i); + return returnResult(runtime, params, results, hf->floatRoot(*x, *n, *rounding), i); } wasm_trap_t* -floatPower_wrap( - void* env, - wasm_val_vec_t const* params, - wasm_val_vec_t* results) +floatPower_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results) { if (auto g = checkGas(env); !g) return g.error(); // LCOV_EXCL_LINE @@ -2020,8 +1699,7 @@ floatPower_wrap( return hfResult(results, rounding.error()); // LCOV_EXCL_LINE i = 3; - return returnResult( - runtime, params, results, hf->floatPower(*x, *n, *rounding), i); + return returnResult(runtime, params, results, hf->floatPower(*x, *n, *rounding), i); } wasm_trap_t* @@ -2043,8 +1721,7 @@ floatLog_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results) return hfResult(results, rounding.error()); // LCOV_EXCL_LINE i = 2; - return returnResult( - runtime, params, results, hf->floatLog(*x, *rounding), i); + return returnResult(runtime, params, results, hf->floatLog(*x, *rounding), i); } // LCOV_EXCL_START @@ -2072,8 +1749,7 @@ testGetDataIncrement() { wasm_val_t values[4]; - std::array buffer = { - 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'}; + std::array buffer = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'}; MockInstanceWrapper runtime(wmem{buffer.data(), buffer.size()}); { @@ -2134,18 +1810,14 @@ testGetDataIncrement() int index = 0; auto const result = getDataString(&runtime, ¶ms, index); - if (!result || - result.value() != - std::string_view( - reinterpret_cast(buffer.data()), 5) || + if (!result || result.value() != std::string_view(reinterpret_cast(buffer.data()), 5) || index != 2) return false; } { // test account - AccountID const id(calcAccountID( - generateKeyPair(KeyType::secp256k1, generateSeed("alice")).first)); + AccountID const id(calcAccountID(generateKeyPair(KeyType::secp256k1, generateSeed("alice")).first)); wasm_val_vec_t params = {2, &values[0]}; diff --git a/src/xrpld/app/wasm/detail/WasmVM.cpp b/src/xrpld/app/wasm/detail/WasmVM.cpp index c7fa3bbb5b..23edbd2370 100644 --- a/src/xrpld/app/wasm/detail/WasmVM.cpp +++ b/src/xrpld/app/wasm/detail/WasmVM.cpp @@ -112,14 +112,7 @@ runEscrowWasm( auto& vm = WasmEngine::instance(); // vm.initMaxPages(MAX_PAGES); - auto const ret = vm.run( - wasmCode, - funcName, - params, - createWasmImport(*hfs), - hfs, - gasLimit, - hfs->getJournal()); + auto const ret = vm.run(wasmCode, funcName, params, createWasmImport(*hfs), hfs, gasLimit, hfs->getJournal()); // std::cout << "runEscrowWasm, mod size: " << wasmCode.size() // << ", gasLimit: " << gasLimit << ", funcName: " << funcName; @@ -133,8 +126,7 @@ runEscrowWasm( } #ifdef DEBUG_OUTPUT - std::cout << ", ret: " << ret->result << ", gas spent: " << ret->cost - << std::endl; + std::cout << ", ret: " << ret->result << ", gas spent: " << ret->cost << std::endl; #endif return EscrowResult{ret->result, ret->cost}; } @@ -150,13 +142,7 @@ preflightEscrowWasm( auto& vm = WasmEngine::instance(); // vm.initMaxPages(MAX_PAGES); - auto const ret = vm.check( - wasmCode, - funcName, - params, - createWasmImport(*hfs), - hfs, - hfs->getJournal()); + auto const ret = vm.check(wasmCode, funcName, params, createWasmImport(*hfs), hfs, hfs->getJournal()); return ret; } diff --git a/src/xrpld/app/wasm/detail/WasmiVM.cpp b/src/xrpld/app/wasm/detail/WasmiVM.cpp index a0f8b612da..6ef0315b97 100644 --- a/src/xrpld/app/wasm/detail/WasmiVM.cpp +++ b/src/xrpld/app/wasm/detail/WasmiVM.cpp @@ -30,8 +30,7 @@ print_wasm_error(std::string_view msg, wasm_trap_t* trap, beast::Journal jlog) if (error_message.size) { - j << "WASMI Error: " << msg << ", " - << std::string_view(error_message.data, error_message.size - 1); + j << "WASMI Error: " << msg << ", " << std::string_view(error_message.data, error_message.size - 1); } else j << "WASMI Error: " << msg; @@ -52,17 +51,10 @@ print_wasm_error(std::string_view msg, wasm_trap_t* trap, beast::Journal jlog) } // namespace InstancePtr -InstanceWrapper::init( - StorePtr& s, - ModulePtr& m, - WasmExternVec& expt, - WasmExternVec const& imports, - beast::Journal j) +InstanceWrapper::init(StorePtr& s, ModulePtr& m, WasmExternVec& expt, WasmExternVec const& imports, beast::Journal j) { wasm_trap_t* trap = nullptr; - InstancePtr mi = InstancePtr( - wasm_instance_new(s.get(), m.get(), &imports.vec_, &trap), - &wasm_instance_delete); + InstancePtr mi = InstancePtr(wasm_instance_new(s.get(), m.get(), &imports.vec_, &trap), &wasm_instance_delete); if (!mi || trap) { @@ -78,18 +70,13 @@ 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); } // LCOV_EXCL_STOP -InstanceWrapper::InstanceWrapper( - StorePtr& s, - ModulePtr& m, - WasmExternVec const& imports, - beast::Journal j) +InstanceWrapper::InstanceWrapper(StorePtr& s, ModulePtr& m, WasmExternVec const& imports, beast::Journal j) : store_(s.get()), instance_(init(s, m, exports_, imports, j)), j_(j) { } @@ -118,9 +105,7 @@ InstanceWrapper::operator bool() const } FuncInfo -InstanceWrapper::getFunc( - std::string_view funcName, - WasmExporttypeVec const& exportTypes) const +InstanceWrapper::getFunc(std::string_view funcName, WasmExporttypeVec const& exportTypes) const { wasm_func_t const* f = nullptr; wasm_functype_t const* ft = nullptr; @@ -155,8 +140,7 @@ InstanceWrapper::getFunc( } if (!f || !ft) - throw std::runtime_error( - "can't find function <" + std::string(funcName) + ">"); + throw std::runtime_error("can't find function <" + std::string(funcName) + ">"); return {f, ft}; } @@ -168,9 +152,7 @@ InstanceWrapper::getMem() const { auto* e(exports_.vec_.data[memIdx_]); wasm_memory_t* mem = wasm_extern_as_memory(e); - return { - reinterpret_cast(wasm_memory_data(mem)), - wasm_memory_data_size(mem)}; + return {reinterpret_cast(wasm_memory_data(mem)), wasm_memory_data_size(mem)}; } wasm_memory_t* mem = nullptr; @@ -188,9 +170,7 @@ InstanceWrapper::getMem() const if (!mem) return {}; // LCOV_EXCL_LINE - return { - reinterpret_cast(wasm_memory_data(mem)), - wasm_memory_data_size(mem)}; + return {reinterpret_cast(wasm_memory_data(mem)), wasm_memory_data_size(mem)}; } std::int64_t @@ -211,8 +191,7 @@ InstanceWrapper::setGas(std::int64_t gas) const 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) { // LCOV_EXCL_START @@ -231,8 +210,7 @@ ModulePtr ModuleWrapper::init(StorePtr& s, Bytes const& wasmBin, beast::Journal j) { wasm_byte_vec_t const code{wasmBin.size(), (char*)(wasmBin.data())}; - ModulePtr m = - ModulePtr(wasm_module_new(s.get(), &code), &wasm_module_delete); + ModulePtr m = ModulePtr(wasm_module_new(s.get(), &code), &wasm_module_delete); if (!m) throw std::runtime_error("can't create module"); @@ -244,8 +222,7 @@ 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); } @@ -342,9 +319,7 @@ makeImpReturn(WasmImportFunc const& imp) } WasmExternVec -ModuleWrapper::buildImports( - StorePtr& s, - std::shared_ptr const& imports) +ModuleWrapper::buildImports(StorePtr& s, std::shared_ptr const& imports) { WasmImporttypeVec importTypes; wasm_module_imports(module_.get(), &importTypes.vec_); @@ -366,12 +341,9 @@ ModuleWrapper::buildImports( wasm_name_t const* fn = wasm_importtype_name(importType); auto fieldName = std::string_view(fn->data, fn->size); - wasm_externkind_t const itype = - wasm_externtype_kind(wasm_importtype_type(importType)); + wasm_externkind_t const itype = wasm_externtype_kind(wasm_importtype_type(importType)); if ((itype) != WASM_EXTERN_FUNC) - throw std::runtime_error( - "Invalid import type " + - std::to_string(itype)); // LCOV_EXCL_LINE + throw std::runtime_error("Invalid import type " + std::to_string(itype)); // LCOV_EXCL_LINE // for multi-module support // if ((W_ENV != modName) && (W_HOST_LIB != modName)) @@ -387,25 +359,18 @@ ModuleWrapper::buildImports( WasmValtypeVec params(makeImpParams(imp)); WasmValtypeVec results(makeImpReturn(imp)); - std::unique_ptr - ftype( - wasm_functype_new(¶ms.vec_, &results.vec_), - &wasm_functype_delete); + std::unique_ptr ftype( + wasm_functype_new(¶ms.vec_, &results.vec_), &wasm_functype_delete); params.release(); results.release(); wasm_func_t* func = wasm_func_new_with_env( - s.get(), - ftype.get(), - reinterpret_cast(imp.wrap), - (void*)&obj, - nullptr); + s.get(), ftype.get(), reinterpret_cast(imp.wrap), (void*)&obj, nullptr); if (!func) { // LCOV_EXCL_START - throw std::runtime_error( - "can't create import function " + imp.name); + throw std::runtime_error("can't create import function " + imp.name); // LCOV_EXCL_STOP } @@ -418,16 +383,15 @@ ModuleWrapper::buildImports( if (!impSet) { - print_wasm_error( - "Import not found: " + std::string(fieldName), nullptr, j_); + print_wasm_error("Import not found: " + std::string(fieldName), nullptr, j_); } } if (impCnt != importTypes.vec_.size) { print_wasm_error( - std::string("Imports not finished: ") + std::to_string(impCnt) + - "/" + std::to_string(importTypes.vec_.size), + std::string("Imports not finished: ") + std::to_string(impCnt) + "/" + + std::to_string(importTypes.vec_.size), nullptr, j_); throw std::runtime_error("Missing imports"); @@ -450,16 +414,13 @@ ModuleWrapper::getFuncType(std::string_view funcName) const auto const* exp_type(exportTypes_.vec_.data[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 && - funcName == std::string_view(name->data, name->size)) + if (wasm_externtype_kind(exn_type) == 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(exn_type)); } } - throw std::runtime_error( - "can't find function <" + std::string(funcName) + ">"); + throw std::runtime_error("can't find function <" + std::string(funcName) + ">"); } wmem @@ -534,8 +495,7 @@ WasmiEngine::init() wasm_engine_new_with_config(config), &wasm_engine_delete); } -WasmiEngine::WasmiEngine() - : engine_(init()), store_(nullptr, &wasm_store_delete) +WasmiEngine::WasmiEngine() : engine_(init()), store_(nullptr, &wasm_store_delete) { } @@ -544,14 +504,11 @@ WasmiEngine::addModule(Bytes const& wasmCode, bool instantiate, int64_t gas) { 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(), MAX_PAGES), &wasm_store_delete}; if (gas < 0) gas = std::numeric_limits::max(); - wasmi_error_t* err = - wasm_store_set_fuel(store_.get(), static_cast(gas)); + wasmi_error_t* err = wasm_store_set_fuel(store_.get(), static_cast(gas)); if (err) { // LCOV_EXCL_START @@ -561,12 +518,10 @@ WasmiEngine::addModule(Bytes const& wasmCode, bool instantiate, int64_t gas) // LCOV_EXCL_STOP } - moduleWrap_ = std::make_unique( - store_, wasmCode, instantiate, imports_, j_); + moduleWrap_ = std::make_unique(store_, wasmCode, instantiate, imports_, j_); if (!moduleWrap_) - throw std::runtime_error( - "can't create module wrapper"); // LCOV_EXCL_LINE + throw std::runtime_error("can't create module wrapper"); // LCOV_EXCL_LINE return moduleWrap_ ? 0 : -1; } @@ -603,8 +558,7 @@ WasmiEngine::convertParams(std::vector const& params) case WT_U8V: { auto mem = getMem(); if (!mem.s) - throw std::runtime_error( - "no memory exported"); // LCOV_EXCL_LINE + throw std::runtime_error("no memory exported"); // LCOV_EXCL_LINE auto const sz = p.of.u8v.sz; auto const ptr = allocate(sz); memcpy(mem.p + ptr, p.of.u8v.d, sz); @@ -614,8 +568,7 @@ WasmiEngine::convertParams(std::vector const& params) break; // LCOV_EXCL_START default: - throw std::runtime_error( - "unknown parameter type: " + std::to_string(p.type)); + throw std::runtime_error("unknown parameter type: " + std::to_string(p.type)); break; // LCOV_EXCL_STOP } @@ -625,9 +578,7 @@ WasmiEngine::convertParams(std::vector const& params) } int -WasmiEngine::compareParamTypes( - wasm_valtype_vec_t const* ftp, - std::vector const& p) +WasmiEngine::compareParamTypes(wasm_valtype_vec_t const* ftp, std::vector const& p) { if (ftp->size != p.size()) return std::min(ftp->size, p.size()); @@ -684,10 +635,9 @@ WasmiEngine::call(FuncInfo const& f, Types&&... args) static inline uint64_t usecs() { - uint64_t x = - std::chrono::duration_cast( - std::chrono::high_resolution_clock::now().time_since_epoch()) - .count(); + uint64_t x = std::chrono::duration_cast( + std::chrono::high_resolution_clock::now().time_since_epoch()) + .count(); return x; } #endif @@ -701,9 +651,7 @@ WasmiEngine::call(FuncInfo const& f, std::vector& in) // if (NR) { wasm_val_vec_new_uninitialized(&ret, NR); // // wasm_val_vec_new(&ret, NR, &rs[0]); // ret = WASM_ARRAY_VEC(rs); } - wasm_val_vec_t const inv = in.empty() - ? wasm_val_vec_t WASM_EMPTY_VEC - : wasm_val_vec_t{in.size(), in.data()}; + wasm_val_vec_t const inv = in.empty() ? wasm_val_vec_t WASM_EMPTY_VEC : wasm_val_vec_t{in.size(), in.data()}; #ifdef SHOW_CALL_TIME auto const start = usecs(); @@ -731,11 +679,7 @@ WasmiEngine::call(FuncInfo const& f, std::vector& in) template WasmiResult -WasmiEngine::call( - FuncInfo const& f, - std::vector& in, - std::int32_t p, - Types&&... args) +WasmiEngine::call(FuncInfo const& f, std::vector& in, std::int32_t p, Types&&... args) { add_param(in, p); return call(f, in, std::forward(args)...); @@ -743,11 +687,7 @@ WasmiEngine::call( template WasmiResult -WasmiEngine::call( - FuncInfo const& f, - std::vector& in, - std::int64_t p, - Types&&... args) +WasmiEngine::call(FuncInfo const& f, std::vector& in, std::int64_t p, Types&&... args) { add_param(in, p); return call(f, in, std::forward(args)...); @@ -755,12 +695,7 @@ WasmiEngine::call( template WasmiResult -WasmiEngine::call( - FuncInfo const& f, - std::vector& in, - uint8_t const* d, - int32_t sz, - Types&&... args) +WasmiEngine::call(FuncInfo const& f, std::vector& in, uint8_t const* d, int32_t sz, Types&&... args) { auto mem = getMem(); if (!mem.s) @@ -776,11 +711,7 @@ WasmiEngine::call( template WasmiResult -WasmiEngine::call( - FuncInfo const& f, - std::vector& in, - Bytes const& p, - Types&&... args) +WasmiEngine::call(FuncInfo const& f, std::vector& in, Bytes const& p, Types&&... args) { return call(f, in, p.data(), p.size(), std::forward(args)...); } @@ -833,11 +764,7 @@ WasmiEngine::run( } Expected, TER> -WasmiEngine::runHlp( - Bytes const& wasmCode, - std::string_view funcName, - std::vector const& params, - int64_t gas) +WasmiEngine::runHlp(Bytes const& wasmCode, std::string_view funcName, std::vector const& params, int64_t gas) { // currently only 1 module support, possible parallel UT run std::lock_guard lg(m_); @@ -863,26 +790,22 @@ WasmiEngine::runHlp( auto p = convertParams(params); if (int const comp = compareParamTypes(ftp, p); comp >= 0) - throw std::runtime_error( - "invalid parameter type #" + std::to_string(comp)); + throw std::runtime_error("invalid parameter type #" + std::to_string(comp)); auto const res = call<1>(f, p); if (res.f) throw std::runtime_error("<" + std::string(funcName) + "> failure"); else if (!res.r.vec_.size) - throw std::runtime_error( - "<" + std::string(funcName) + - "> return nothing"); // LCOV_EXCL_LINE + throw std::runtime_error("<" + std::string(funcName) + "> return nothing"); // LCOV_EXCL_LINE else if (res.r.vec_.data[0].kind != WASM_I32) throw std::runtime_error( - "<" + std::string(funcName) + "> return type mismatch, ret: " + - std::to_string(static_cast(res.r.vec_.data[0].kind))); + "<" + std::string(funcName) + + "> return type mismatch, ret: " + std::to_string(static_cast(res.r.vec_.data[0].kind))); if (gas == -1) gas = std::numeric_limits::max(); - WasmResult const ret{ - res.r.vec_.data[0].of.i32, gas - moduleWrap_->getGas()}; + WasmResult const ret{res.r.vec_.data[0].of.i32, gas - moduleWrap_->getGas()}; // #ifdef DEBUG_OUTPUT // auto& j = std::cerr; @@ -932,10 +855,7 @@ WasmiEngine::check( } NotTEC -WasmiEngine::checkHlp( - Bytes const& wasmCode, - std::string_view funcName, - std::vector const& params) +WasmiEngine::checkHlp(Bytes const& wasmCode, std::string_view funcName, std::vector const& params) { // currently only 1 module support, possible parallel UT run std::lock_guard lg(m_); @@ -949,14 +869,12 @@ WasmiEngine::checkHlp( throw std::runtime_error("no module"); // LCOV_EXCL_LINE // Looking for a func and compare parameter types - auto const f = - moduleWrap_->getFuncType(!funcName.empty() ? funcName : "_start"); + auto const f = moduleWrap_->getFuncType(!funcName.empty() ? funcName : "_start"); auto const* ftp = wasm_functype_params(f); auto const p = convertParams(params); if (int const comp = compareParamTypes(ftp, p); comp >= 0) - throw std::runtime_error( - "invalid parameter type #" + std::to_string(comp)); + throw std::runtime_error("invalid parameter type #" + std::to_string(comp)); return tesSUCCESS; } @@ -987,21 +905,17 @@ int32_t WasmiEngine::allocate(int32_t sz) { if (sz <= 0) - throw std::runtime_error( - "can't allocate memory, " + std::to_string(sz) + " bytes"); + throw std::runtime_error("can't allocate memory, " + std::to_string(sz) + " bytes"); auto res = call<1>(W_ALLOC, sz); if (res.f || !res.r.vec_.size || (res.r.vec_.data[0].kind != WASM_I32)) - throw std::runtime_error( - "can't allocate memory, " + std::to_string(sz) + - " bytes"); // LCOV_EXCL_LINE + throw std::runtime_error("can't allocate memory, " + std::to_string(sz) + " bytes"); // LCOV_EXCL_LINE int32_t const p = res.r.vec_.data[0].of.i32; auto const mem = getMem(); if (p <= 0 || p + sz > mem.s) - throw std::runtime_error( - "invalid memory allocation, " + std::to_string(sz) + " bytes"); + throw std::runtime_error("invalid memory allocation, " + std::to_string(sz) + " bytes"); return p; }