diff options
Diffstat (limited to 'src/wallet/test/util.cpp')
-rw-r--r-- | src/wallet/test/util.cpp | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/wallet/test/util.cpp b/src/wallet/test/util.cpp index 4fa7adc37d..069ab25f26 100644 --- a/src/wallet/test/util.cpp +++ b/src/wallet/test/util.cpp @@ -92,6 +92,17 @@ CTxDestination getNewDestination(CWallet& w, OutputType output_type) return *Assert(w.GetNewDestination(output_type, "")); } +// BytePrefix compares equality with other byte spans that begin with the same prefix. +struct BytePrefix { Span<const std::byte> prefix; }; +bool operator<(BytePrefix a, Span<const std::byte> b) { return a.prefix < b.subspan(0, std::min(a.prefix.size(), b.size())); } +bool operator<(Span<const std::byte> a, BytePrefix b) { return a.subspan(0, std::min(a.size(), b.prefix.size())) < b.prefix; } + +MockableCursor::MockableCursor(const MockableData& records, bool pass, Span<const std::byte> prefix) +{ + m_pass = pass; + std::tie(m_cursor, m_cursor_end) = records.equal_range(BytePrefix{prefix}); +} + DatabaseCursor::Status MockableCursor::Next(DataStream& key, DataStream& value) { if (!m_pass) { @@ -175,7 +186,7 @@ bool MockableBatch::ErasePrefix(Span<const std::byte> prefix) return true; } -std::unique_ptr<WalletDatabase> CreateMockableWalletDatabase(std::map<SerializeData, SerializeData> records) +std::unique_ptr<WalletDatabase> CreateMockableWalletDatabase(MockableData records) { return std::make_unique<MockableDatabase>(records); } |