mirror of
https://github.com/XRPLF/rippled.git
synced 2026-06-05 01:37:00 +00:00
fix: Fix build issues post-clang-tidy changes (#7298)
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,6 @@
|
||||
#include <test/app/wasm_fixtures/fixtures.h>
|
||||
#include <test/jtx.h>
|
||||
#include <test/jtx/Env.h>
|
||||
#include <test/unit_test/SuiteJournal.h>
|
||||
|
||||
#include <xrpl/ledger/AmendmentTable.h>
|
||||
#include <xrpl/ledger/detail/ApplyViewBase.h>
|
||||
@@ -8,6 +9,13 @@
|
||||
#include <xrpl/tx/wasm/HostFunc.h>
|
||||
#include <xrpl/tx/wasm/WasmVM.h>
|
||||
|
||||
#include <boost/algorithm/hex.hpp>
|
||||
|
||||
#include <cstdint>
|
||||
#include <iterator>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
namespace xrpl::test {
|
||||
|
||||
struct TestLedgerDataProvider : public HostFunctions
|
||||
@@ -23,7 +31,7 @@ public:
|
||||
void
|
||||
setRT(void* rt) override
|
||||
{
|
||||
rt = rt;
|
||||
this->rt = rt;
|
||||
}
|
||||
|
||||
[[nodiscard]] void*
|
||||
@@ -41,25 +49,25 @@ public:
|
||||
|
||||
struct TestHostFunctions : public HostFunctions
|
||||
{
|
||||
test::jtx::Env& env_;
|
||||
AccountID accountID_;
|
||||
Bytes data_;
|
||||
test::jtx::Env& env;
|
||||
AccountID accountID;
|
||||
Bytes data;
|
||||
int clock_drift = 0;
|
||||
void* rt = nullptr;
|
||||
|
||||
public:
|
||||
TestHostFunctions(test::jtx::Env& env, int cd = 0)
|
||||
: HostFunctions(env.journal), env_(env), clock_drift(cd)
|
||||
: HostFunctions(env.journal), env(env), clock_drift(cd)
|
||||
{
|
||||
accountID_ = env_.master.id();
|
||||
accountID = env.master.id();
|
||||
std::string t = "10000";
|
||||
data_ = Bytes{t.begin(), t.end()};
|
||||
data = Bytes{t.begin(), t.end()};
|
||||
}
|
||||
|
||||
void
|
||||
setRT(void* rt) override
|
||||
{
|
||||
rt = rt;
|
||||
this->rt = rt;
|
||||
}
|
||||
|
||||
[[nodiscard]] void*
|
||||
@@ -83,7 +91,7 @@ public:
|
||||
Expected<Hash, HostFunctionError>
|
||||
getParentLedgerHash() const override
|
||||
{
|
||||
return env_.current()->header().parentHash;
|
||||
return env.current()->header().parentHash;
|
||||
}
|
||||
|
||||
Expected<std::uint32_t, HostFunctionError>
|
||||
@@ -115,7 +123,7 @@ public:
|
||||
{
|
||||
if (fname == sfAccount)
|
||||
{
|
||||
return Bytes(accountID_.begin(), accountID_.end());
|
||||
return Bytes(accountID.begin(), accountID.end());
|
||||
}
|
||||
if (fname == sfFee)
|
||||
{
|
||||
@@ -123,7 +131,7 @@ public:
|
||||
uint8_t const* p = reinterpret_cast<uint8_t const*>(&x);
|
||||
return Bytes{p, p + sizeof(x)};
|
||||
}
|
||||
else if (fname == sfSequence)
|
||||
if (fname == sfSequence)
|
||||
{
|
||||
auto const x = getLedgerSqn();
|
||||
if (!x)
|
||||
@@ -142,13 +150,15 @@ public:
|
||||
auto const& sn = fname.getName();
|
||||
if (sn == "Destination" || sn == "Account")
|
||||
{
|
||||
return Bytes(accountID_.begin(), accountID_.end());
|
||||
return Bytes(accountID.begin(), accountID.end());
|
||||
}
|
||||
if (sn == "Data")
|
||||
return data_;
|
||||
else if (sn == "FinishAfter")
|
||||
{
|
||||
auto t = env_.current()->parentCloseTime().time_since_epoch().count();
|
||||
return data;
|
||||
}
|
||||
if (sn == "FinishAfter")
|
||||
{
|
||||
auto t = env.current()->parentCloseTime().time_since_epoch().count();
|
||||
std::string s = std::to_string(t);
|
||||
return Bytes{s.begin(), s.end()};
|
||||
}
|
||||
@@ -167,9 +177,9 @@ public:
|
||||
}
|
||||
if (fname == sfAccount)
|
||||
{
|
||||
return Bytes(accountID_.begin(), accountID_.end());
|
||||
return Bytes(accountID.begin(), accountID.end());
|
||||
}
|
||||
return data_;
|
||||
return data;
|
||||
}
|
||||
|
||||
Expected<Bytes, HostFunctionError>
|
||||
@@ -179,9 +189,9 @@ public:
|
||||
{
|
||||
int32_t const* l = reinterpret_cast<int32_t const*>(locator.data());
|
||||
int32_t const sfield = l[0];
|
||||
if (sfield == sfAccount.fieldCode)
|
||||
if (sfield == sfAccount.getCode())
|
||||
{
|
||||
return Bytes(accountID_.begin(), accountID_.end());
|
||||
return Bytes(accountID.begin(), accountID.end());
|
||||
}
|
||||
}
|
||||
uint8_t const a[] = {0x2b, 0x6a, 0x23, 0x2a, 0xa4, 0xc4, 0xbe, 0x41, 0xbf, 0x49, 0xd2,
|
||||
@@ -197,9 +207,9 @@ public:
|
||||
{
|
||||
int32_t const* l = reinterpret_cast<int32_t const*>(locator.data());
|
||||
int32_t const sfield = l[0];
|
||||
if (sfield == sfAccount.fieldCode)
|
||||
if (sfield == sfAccount.getCode())
|
||||
{
|
||||
return Bytes(accountID_.begin(), accountID_.end());
|
||||
return Bytes(accountID.begin(), accountID.end());
|
||||
}
|
||||
}
|
||||
uint8_t const a[] = {0x2b, 0x6a, 0x23, 0x2a, 0xa4, 0xc4, 0xbe, 0x41, 0xbf, 0x49, 0xd2,
|
||||
@@ -215,9 +225,9 @@ public:
|
||||
{
|
||||
int32_t const* l = reinterpret_cast<int32_t const*>(locator.data());
|
||||
int32_t const sfield = l[0];
|
||||
if (sfield == sfAccount.fieldCode)
|
||||
if (sfield == sfAccount.getCode())
|
||||
{
|
||||
return Bytes(accountID_.begin(), accountID_.end());
|
||||
return Bytes(accountID.begin(), accountID.end());
|
||||
}
|
||||
}
|
||||
uint8_t const a[] = {0x2b, 0x6a, 0x23, 0x2a, 0xa4, 0xc4, 0xbe, 0x41, 0xbf, 0x49, 0xd2,
|
||||
@@ -277,7 +287,7 @@ public:
|
||||
Expected<Hash, HostFunctionError>
|
||||
computeSha512HalfHash(Slice const& data) const override
|
||||
{
|
||||
return env_.current()->header().parentHash;
|
||||
return env.current()->header().parentHash;
|
||||
}
|
||||
|
||||
Expected<Bytes, HostFunctionError>
|
||||
@@ -353,7 +363,7 @@ public:
|
||||
Expected<Bytes, HostFunctionError>
|
||||
getNFTIssuer(uint256 const& nftId) const override
|
||||
{
|
||||
return Bytes(accountID_.begin(), accountID_.end());
|
||||
return Bytes(accountID.begin(), accountID.end());
|
||||
}
|
||||
|
||||
Expected<std::uint32_t, HostFunctionError>
|
||||
@@ -387,7 +397,7 @@ public:
|
||||
#ifdef DEBUG_OUTPUT
|
||||
auto& j = std::cerr;
|
||||
#else
|
||||
if (!getJournal().active(beast::severities::kTrace))
|
||||
if (!getJournal().active(beast::Severity::Trace))
|
||||
return;
|
||||
auto j = getJournal().trace();
|
||||
#endif
|
||||
@@ -540,7 +550,7 @@ struct TestHostFunctionsSink : public TestHostFunctions
|
||||
|
||||
public:
|
||||
explicit TestHostFunctionsSink(test::jtx::Env& env, int cd = 0)
|
||||
: TestHostFunctions(env, cd), sink_(beast::severities::kDebug)
|
||||
: TestHostFunctions(env, cd), sink(beast::Severity::Debug)
|
||||
{
|
||||
j = beast::Journal(sink);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <xrpl/protocol/SField.h>
|
||||
#include <xrpl/protocol/TER.h>
|
||||
#include <xrpl/tx/wasm/HostFunc.h>
|
||||
#include <xrpl/tx/wasm/HostFuncWrapper.h> // IWYU pragma: keep
|
||||
#include <xrpl/tx/wasm/ParamsHelper.h>
|
||||
#include <xrpl/tx/wasm/WasmVM.h>
|
||||
|
||||
@@ -95,7 +96,7 @@ uleb128(IT&& it)
|
||||
return {val, count};
|
||||
}
|
||||
|
||||
std::pair<unsigned, unsigned>
|
||||
static std::pair<unsigned, unsigned>
|
||||
getSection(Bytes const& module, std::uint8_t n)
|
||||
{
|
||||
static std::uint8_t const kHdr[] = {0x00, 0x61, 0x73, 0x6D};
|
||||
@@ -134,7 +135,7 @@ getSection(Bytes const& module, std::uint8_t n)
|
||||
return {0, 0};
|
||||
}
|
||||
|
||||
std::optional<int32_t>
|
||||
static std::optional<int32_t>
|
||||
runFinishFunction(std::string const& code)
|
||||
{
|
||||
auto& engine = WasmEngine::instance();
|
||||
@@ -149,6 +150,13 @@ runFinishFunction(std::string const& code)
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
static bool
|
||||
finishFunctionReturns(std::string const& code, int32_t expected)
|
||||
{
|
||||
auto const result = runFinishFunction(code);
|
||||
return result.has_value() && *result == expected;
|
||||
}
|
||||
|
||||
struct Wasm_test : public beast::unit_test::Suite
|
||||
{
|
||||
void
|
||||
@@ -692,82 +700,82 @@ struct Wasm_test : public beast::unit_test::Suite
|
||||
testWasmMemory()
|
||||
{
|
||||
testcase("Wasm additional memory limit tests");
|
||||
BEAST_EXPECT(runFinishFunction(kMemoryPointerAtLimitHex).value() == 1);
|
||||
BEAST_EXPECT(runFinishFunction(kMemoryPointerOverLimitHex).has_value() == false);
|
||||
BEAST_EXPECT(runFinishFunction(kMemoryOffsetOverLimitHex).has_value() == false);
|
||||
BEAST_EXPECT(runFinishFunction(kMemoryEndOfWordOverLimitHex).has_value() == false);
|
||||
BEAST_EXPECT(runFinishFunction(kMemoryGrow0To1PageHex).value() == 1);
|
||||
BEAST_EXPECT(runFinishFunction(kMemoryGrow1To0PageHex).value() == -1);
|
||||
BEAST_EXPECT(runFinishFunction(kMemoryLastByteOf8MbHex).value() == 1);
|
||||
BEAST_EXPECT(runFinishFunction(kMemoryGrow1MoreThan8MbHex).value() == -1);
|
||||
BEAST_EXPECT(runFinishFunction(kMemoryGrow0MoreThan8MbHex).value() == 1);
|
||||
BEAST_EXPECT(runFinishFunction(kMemoryInit1MoreThan8MbHex).has_value() == false);
|
||||
BEAST_EXPECT(runFinishFunction(kMemoryNegativeAddressHex).has_value() == false);
|
||||
BEAST_EXPECT(finishFunctionReturns(kMemoryPointerAtLimitHex, 1));
|
||||
BEAST_EXPECT(!runFinishFunction(kMemoryPointerOverLimitHex).has_value());
|
||||
BEAST_EXPECT(!runFinishFunction(kMemoryOffsetOverLimitHex).has_value());
|
||||
BEAST_EXPECT(!runFinishFunction(kMemoryEndOfWordOverLimitHex).has_value());
|
||||
BEAST_EXPECT(finishFunctionReturns(kMemoryGrow0To1PageHex, 1));
|
||||
BEAST_EXPECT(finishFunctionReturns(kMemoryGrow1To0PageHex, -1));
|
||||
BEAST_EXPECT(finishFunctionReturns(kMemoryLastByteOf8MbHex, 1));
|
||||
BEAST_EXPECT(finishFunctionReturns(kMemoryGrow1MoreThan8MbHex, -1));
|
||||
BEAST_EXPECT(finishFunctionReturns(kMemoryGrow0MoreThan8MbHex, 1));
|
||||
BEAST_EXPECT(!runFinishFunction(kMemoryInit1MoreThan8MbHex).has_value());
|
||||
BEAST_EXPECT(!runFinishFunction(kMemoryNegativeAddressHex).has_value());
|
||||
}
|
||||
|
||||
void
|
||||
testWasmTable()
|
||||
{
|
||||
testcase("Wasm table limit tests");
|
||||
BEAST_EXPECT(runFinishFunction(kTable64ElementsHex).value() == 1);
|
||||
BEAST_EXPECT(runFinishFunction(kTable65ElementsHex).has_value() == false);
|
||||
BEAST_EXPECT(runFinishFunction(kTable2TablesHex).has_value() == false);
|
||||
BEAST_EXPECT(runFinishFunction(kTable0ElementsHex).value() == 1);
|
||||
BEAST_EXPECT(runFinishFunction(kTableUintMaxHex).has_value() == false);
|
||||
BEAST_EXPECT(finishFunctionReturns(kTable64ElementsHex, 1));
|
||||
BEAST_EXPECT(!runFinishFunction(kTable65ElementsHex).has_value());
|
||||
BEAST_EXPECT(!runFinishFunction(kTable2TablesHex).has_value());
|
||||
BEAST_EXPECT(finishFunctionReturns(kTable0ElementsHex, 1));
|
||||
BEAST_EXPECT(!runFinishFunction(kTableUintMaxHex).has_value());
|
||||
}
|
||||
|
||||
void
|
||||
testWasmProposal()
|
||||
{
|
||||
testcase("Wasm disabled proposal tests");
|
||||
BEAST_EXPECT(runFinishFunction(kProposalMutableGlobalHex).has_value() == false);
|
||||
BEAST_EXPECT(runFinishFunction(kProposalGcStructNewHex).has_value() == false);
|
||||
BEAST_EXPECT(runFinishFunction(kProposalMultiValueHex).has_value() == false);
|
||||
BEAST_EXPECT(runFinishFunction(kProposalSignExtHex).has_value() == false);
|
||||
BEAST_EXPECT(runFinishFunction(kProposalFloatToIntHex).has_value() == false);
|
||||
BEAST_EXPECT(runFinishFunction(kProposalBulkMemoryHex).has_value() == false);
|
||||
BEAST_EXPECT(runFinishFunction(kProposalRefTypesHex).has_value() == false);
|
||||
BEAST_EXPECT(runFinishFunction(kProposalTailCallHex).has_value() == false);
|
||||
BEAST_EXPECT(runFinishFunction(kProposalExtendedConstHex).has_value() == false);
|
||||
BEAST_EXPECT(runFinishFunction(kProposalMultiMemoryHex).has_value() == false);
|
||||
BEAST_EXPECT(runFinishFunction(kProposalCustomPageSizesHex).has_value() == false);
|
||||
BEAST_EXPECT(runFinishFunction(kProposalMemory64Hex).has_value() == false);
|
||||
BEAST_EXPECT(runFinishFunction(kProposalWideArithmeticHex).has_value() == false);
|
||||
BEAST_EXPECT(!runFinishFunction(kProposalMutableGlobalHex).has_value());
|
||||
BEAST_EXPECT(!runFinishFunction(kProposalGcStructNewHex).has_value());
|
||||
BEAST_EXPECT(!runFinishFunction(kProposalMultiValueHex).has_value());
|
||||
BEAST_EXPECT(!runFinishFunction(kProposalSignExtHex).has_value());
|
||||
BEAST_EXPECT(!runFinishFunction(kProposalFloatToIntHex).has_value());
|
||||
BEAST_EXPECT(!runFinishFunction(kProposalBulkMemoryHex).has_value());
|
||||
BEAST_EXPECT(!runFinishFunction(kProposalRefTypesHex).has_value());
|
||||
BEAST_EXPECT(!runFinishFunction(kProposalTailCallHex).has_value());
|
||||
BEAST_EXPECT(!runFinishFunction(kProposalExtendedConstHex).has_value());
|
||||
BEAST_EXPECT(!runFinishFunction(kProposalMultiMemoryHex).has_value());
|
||||
BEAST_EXPECT(!runFinishFunction(kProposalCustomPageSizesHex).has_value());
|
||||
BEAST_EXPECT(!runFinishFunction(kProposalMemory64Hex).has_value());
|
||||
BEAST_EXPECT(!runFinishFunction(kProposalWideArithmeticHex).has_value());
|
||||
}
|
||||
|
||||
void
|
||||
testWasmTrap()
|
||||
{
|
||||
testcase("Wasm trap tests");
|
||||
BEAST_EXPECT(runFinishFunction(kTrapDivideBy0Hex).has_value() == false);
|
||||
BEAST_EXPECT(runFinishFunction(kTrapIntOverflowHex).has_value() == false);
|
||||
BEAST_EXPECT(runFinishFunction(kTrapUnreachableHex).has_value() == false);
|
||||
BEAST_EXPECT(runFinishFunction(kTrapNullCallHex).has_value() == false);
|
||||
BEAST_EXPECT(runFinishFunction(kTrapFuncSigMismatchHex).has_value() == false);
|
||||
BEAST_EXPECT(!runFinishFunction(kTrapDivideBy0Hex).has_value());
|
||||
BEAST_EXPECT(!runFinishFunction(kTrapIntOverflowHex).has_value());
|
||||
BEAST_EXPECT(!runFinishFunction(kTrapUnreachableHex).has_value());
|
||||
BEAST_EXPECT(!runFinishFunction(kTrapNullCallHex).has_value());
|
||||
BEAST_EXPECT(!runFinishFunction(kTrapFuncSigMismatchHex).has_value());
|
||||
}
|
||||
|
||||
void
|
||||
testWasmWasi()
|
||||
{
|
||||
testcase("Wasm Wasi tests");
|
||||
BEAST_EXPECT(runFinishFunction(kWasiGetTimeHex).has_value() == false);
|
||||
BEAST_EXPECT(runFinishFunction(kWasiPrintHex).has_value() == false);
|
||||
BEAST_EXPECT(!runFinishFunction(kWasiGetTimeHex).has_value());
|
||||
BEAST_EXPECT(!runFinishFunction(kWasiPrintHex).has_value());
|
||||
}
|
||||
|
||||
void
|
||||
testWasmSectionCorruption()
|
||||
{
|
||||
testcase("Wasm Section Corruption tests");
|
||||
BEAST_EXPECT(runFinishFunction(kBadMagicNumberHex).has_value() == false);
|
||||
BEAST_EXPECT(runFinishFunction(kBadVersionNumberHex).has_value() == false);
|
||||
BEAST_EXPECT(runFinishFunction(kLyingHeaderHex).has_value() == false);
|
||||
BEAST_EXPECT(runFinishFunction(kNeverEndingNumberHex).has_value() == false);
|
||||
BEAST_EXPECT(runFinishFunction(kVectorLieHex).has_value() == false);
|
||||
BEAST_EXPECT(runFinishFunction(kSectionOrderingHex).has_value() == false);
|
||||
BEAST_EXPECT(runFinishFunction(kGhostPayloadHex).has_value() == false);
|
||||
BEAST_EXPECT(runFinishFunction(kJunkAfterSectionHex).has_value() == false);
|
||||
BEAST_EXPECT(runFinishFunction(kInvalidSectionIdHex).has_value() == false);
|
||||
BEAST_EXPECT(runFinishFunction(kLocalVariableBombHex).has_value() == false);
|
||||
BEAST_EXPECT(!runFinishFunction(kBadMagicNumberHex).has_value());
|
||||
BEAST_EXPECT(!runFinishFunction(kBadVersionNumberHex).has_value());
|
||||
BEAST_EXPECT(!runFinishFunction(kLyingHeaderHex).has_value());
|
||||
BEAST_EXPECT(!runFinishFunction(kNeverEndingNumberHex).has_value());
|
||||
BEAST_EXPECT(!runFinishFunction(kVectorLieHex).has_value());
|
||||
BEAST_EXPECT(!runFinishFunction(kSectionOrderingHex).has_value());
|
||||
BEAST_EXPECT(!runFinishFunction(kGhostPayloadHex).has_value());
|
||||
BEAST_EXPECT(!runFinishFunction(kJunkAfterSectionHex).has_value());
|
||||
BEAST_EXPECT(!runFinishFunction(kInvalidSectionIdHex).has_value());
|
||||
BEAST_EXPECT(!runFinishFunction(kLocalVariableBombHex).has_value());
|
||||
}
|
||||
|
||||
void
|
||||
@@ -998,7 +1006,7 @@ struct Wasm_test : public beast::unit_test::Suite
|
||||
std::vector<WasmParam> params;
|
||||
params.reserve(1000);
|
||||
for (int i = 0; i < 1000; ++i)
|
||||
params.push_back({.type = WtI32, .of = {.i32 = 2 * i}});
|
||||
params.push_back({.type = WasmTypes::WtI32, .of = {.i32 = 2 * i}});
|
||||
|
||||
auto& engine = WasmEngine::instance();
|
||||
{
|
||||
@@ -1007,7 +1015,7 @@ struct Wasm_test : public beast::unit_test::Suite
|
||||
}
|
||||
|
||||
// add 1 more parameter, module can't be created now
|
||||
params.push_back({.type = WtI32, .of = {.i32 = 2 * 1000}});
|
||||
params.push_back({.type = WasmTypes::WtI32, .of = {.i32 = 2 * 1000}});
|
||||
{
|
||||
auto re = engine.run(params1k1, hfs, 1'000'000, "test", params, imports, env.journal);
|
||||
BEAST_EXPECT(!re);
|
||||
|
||||
Reference in New Issue
Block a user