xrpld
Loading...
Searching...
No Matches
Basics_test.cpp
1#include <test/nodestore/TestBase.h>
2
3#include <xrpl/beast/unit_test/suite.h>
4#include <xrpl/nodestore/NodeObject.h>
5#include <xrpl/nodestore/detail/DecodedBlob.h>
6#include <xrpl/nodestore/detail/EncodedBlob.h>
7
8#include <cstdint>
9#include <memory>
10
11namespace xrpl::NodeStore {
12
13// Tests predictable batches, and NodeObject blob encoding
14//
16{
17public:
18 // Make sure predictable object generation works!
19 void
20 testBatches(std::uint64_t const seedValue)
21 {
22 testcase("batch");
23
24 auto batch1 = createPredictableBatch(kNumObjectsToTest, seedValue);
25
26 auto batch2 = createPredictableBatch(kNumObjectsToTest, seedValue);
27
28 BEAST_EXPECT(areBatchesEqual(batch1, batch2));
29
30 auto batch3 = createPredictableBatch(kNumObjectsToTest, seedValue + 1);
31
32 BEAST_EXPECT(!areBatchesEqual(batch1, batch3));
33 }
34
35 // Checks encoding/decoding blobs
36 void
37 testBlobs(std::uint64_t const seedValue)
38 {
39 testcase("encoding");
40
41 auto batch = createPredictableBatch(kNumObjectsToTest, seedValue);
42
43 for (int i = 0; i < batch.size(); ++i)
44 {
45 EncodedBlob const encoded(batch[i]);
46
47 DecodedBlob decoded(encoded.getKey(), encoded.getData(), encoded.getSize());
48
49 BEAST_EXPECT(decoded.wasOk());
50
51 if (decoded.wasOk())
52 {
53 std::shared_ptr<NodeObject> const object(decoded.createObject());
54
55 BEAST_EXPECT(isSame(batch[i], object));
56 }
57 }
58 }
59
60 void
61 run() override
62 {
63 std::uint64_t const seedValue = 50;
64
65 testBatches(seedValue);
66
67 testBlobs(seedValue);
68 }
69};
70
71BEAST_DEFINE_TESTSUITE(NodeStoreBasic, nodestore, xrpl);
72
73} // namespace xrpl::NodeStore
TestcaseT testcase
Memberspace for declaring test cases.
Definition suite.h:149
Parsed key/value blob into NodeObject components.
Definition DecodedBlob.h:18
std::shared_ptr< NodeObject > createObject()
Create a NodeObject from this data.
bool wasOk() const noexcept
Determine if the decoding was successful.
Definition DecodedBlob.h:25
Convert a NodeObject from in-memory to database format.
Definition EncodedBlob.h:35
void const * getKey() const noexcept
Definition EncodedBlob.h:89
std::size_t getSize() const noexcept
Definition EncodedBlob.h:95
void const * getData() const noexcept
void testBlobs(std::uint64_t const seedValue)
void testBatches(std::uint64_t const seedValue)
void run() override
Runs the suite.
static bool areBatchesEqual(Batch const &lhs, Batch const &rhs)
Definition TestBase.h:95
static Batch createPredictableBatch(int numObjects, std::uint64_t seed)
Definition TestBase.h:57
static int const kNumObjectsToTest
Definition TestBase.h:52
bool isSame(std::shared_ptr< NodeObject > const &lhs, std::shared_ptr< NodeObject > const &rhs)
Returns true if objects are identical.
Definition TestBase.h:37
BEAST_DEFINE_TESTSUITE(Backend, nodestore, xrpl)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5