mirror of
https://github.com/Xahau/xahaud.git
synced 2026-07-24 23:50:10 +00:00
fix(protocol): own validated bitset storage
This commit is contained in:
@@ -32,7 +32,7 @@ namespace ripple {
|
||||
|
||||
class ValidatedValidatorBitset
|
||||
{
|
||||
Slice bitset_;
|
||||
Blob bitset_;
|
||||
std::size_t memberCount_ = 0;
|
||||
std::size_t selected_ = 0;
|
||||
|
||||
@@ -40,15 +40,14 @@ class ValidatedValidatorBitset
|
||||
Slice bitset,
|
||||
std::size_t memberCount,
|
||||
std::size_t selected)
|
||||
: bitset_(bitset), memberCount_(memberCount), selected_(selected)
|
||||
: bitset_(bitset.begin(), bitset.end())
|
||||
, memberCount_(memberCount)
|
||||
, selected_(selected)
|
||||
{
|
||||
}
|
||||
|
||||
public:
|
||||
/** Construct a validated, non-owning view over a validator bitset.
|
||||
|
||||
The caller must keep the bitset storage alive while using the view.
|
||||
*/
|
||||
/** Construct an owning, validated validator bitset. */
|
||||
static std::optional<ValidatedValidatorBitset>
|
||||
make(Slice bitset, std::size_t memberCount);
|
||||
|
||||
|
||||
@@ -87,12 +87,43 @@ public:
|
||||
BEAST_EXPECT(full->selected() == 8);
|
||||
}
|
||||
|
||||
void
|
||||
testValidatedOwnership()
|
||||
{
|
||||
testcase("validated ownership");
|
||||
|
||||
auto const temporary = validateValidatorBitset(
|
||||
makeSlice(makeValidatorBitset(
|
||||
10, [](std::size_t i) { return i == 1 || i == 9; })),
|
||||
10);
|
||||
BEAST_EXPECT(temporary);
|
||||
if (temporary)
|
||||
{
|
||||
BEAST_EXPECT(temporary->selected() == 2);
|
||||
BEAST_EXPECT(temporary->contains(1));
|
||||
BEAST_EXPECT(temporary->contains(9));
|
||||
}
|
||||
|
||||
Blob mutableBacking{0x01, 0x00};
|
||||
auto const copied =
|
||||
validateValidatorBitset(makeSlice(mutableBacking), 10);
|
||||
BEAST_EXPECT(copied);
|
||||
mutableBacking = Blob{0x00, 0x02};
|
||||
if (copied)
|
||||
{
|
||||
BEAST_EXPECT(copied->selected() == 1);
|
||||
BEAST_EXPECT(copied->contains(0));
|
||||
BEAST_EXPECT(!copied->contains(9));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
run() override
|
||||
{
|
||||
testByteCount();
|
||||
testConstructionAndPopulation();
|
||||
testCanonicalShape();
|
||||
testValidatedOwnership();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user