Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions include/bitcoin/database/impl/query/address/address_balance.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,16 @@ namespace database {

// unused
TEMPLATE
code CLASS::get_unconfirmed_balance(const stopper& cancel, uint64_t& out,
const hash_digest& key, bool turbo) const NOEXCEPT
code CLASS::get_unconfirmed_balance(const stopper& , uint64_t& out,
const hash_digest& , bool ) const NOEXCEPT
{
// While duplicates are easily filtered out, conflict resolution is murky.
// An output may have multiple directly or indirectly conflicting spends,
// and other spends and receives may not be visible. An unconfirmed balance
// is therefore inherehtly ambiguous. Given the lack of tx pooling,
// presently we just return combined = confirmed (net zero unconfirmed).
return get_confirmed_balance(cancel, out, key, turbo);
// presently we just return zero unconfirmed.
out = zero;
return error::success;
}

// server/native
Expand Down Expand Up @@ -69,11 +70,11 @@ code CLASS::get_confirmed_balance(const stopper& cancel, uint64_t& out,
// server/electrum
TEMPLATE
code CLASS::get_balance(const stopper& cancel, uint64_t& confirmed,
uint64_t& combined, const hash_digest& key, bool turbo) const NOEXCEPT
uint64_t& unconfirmed, const hash_digest& key, bool turbo) const NOEXCEPT
{
// See notes on get_unconfirmed_balance().
const auto ec = get_confirmed_balance(cancel, confirmed, key, turbo);
combined = confirmed;
unconfirmed = zero;
return ec;
}

Expand Down
5 changes: 3 additions & 2 deletions include/bitcoin/database/query.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -648,8 +648,9 @@ class query
const hash_digest& key, bool turbo=false) const NOEXCEPT;
code get_confirmed_balance(const stopper& cancel, uint64_t& out,
const hash_digest& key, bool turbo=false) const NOEXCEPT;
code get_balance(const stopper& cancel, uint64_t& confirmed, uint64_t& combined,
const hash_digest& key, bool turbo=false) const NOEXCEPT;
code get_balance(const stopper& cancel, uint64_t& confirmed,
uint64_t& unconfirmed, const hash_digest& key,
bool turbo=false) const NOEXCEPT;

/// Filters.
/// -----------------------------------------------------------------------
Expand Down
23 changes: 23 additions & 0 deletions test/mocks/blocks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,29 @@ bool setup_three_block_witness_store(query_t& query) NOEXCEPT
query.push_confirmed(query.to_header(block2a.hash()), false);
}

bool setup_three_block_confirmed_address_store(query_t& query) NOEXCEPT
{
return query.initialize(genesis) &&
query.set(block1a, database::context{ 0, 1, 0 }, false, false) &&
query.set(block2a, database::context{ 0, 2, 0 }, false, false) &&
query.set(test::tx4) &&
query.set(test::tx5) &&
query.set(block3a, database::context{ 0, 3, 0 }, false, false) &&
query.push_confirmed(query.to_header(block1a.hash()), true) &&
query.push_confirmed(query.to_header(block2a.hash()), true) &&
query.push_confirmed(query.to_header(block2a.hash()), true);
}

bool setup_three_block_unconfirmed_address_store(query_t& query) NOEXCEPT
{
return query.initialize(genesis) &&
query.set(block1a, database::context{ 0, 1, 0 }, false, false) &&
query.set(block2a, database::context{ 0, 2, 0 }, false, false) &&
query.set(test::tx4) &&
query.set(test::tx5) &&
query.set(block3a, database::context{ 0, 3, 0 }, false, false);
}

// Setting block metadata on a shared instance creates test side effects.
// Chain objects such as blocks cannot be copied for side-effect-free metadata
// tests, since block copy takes shared pointer references. So create new test
Expand Down
9 changes: 6 additions & 3 deletions test/mocks/blocks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@
#define LIBBITCOIN_DATABASE_TEST_MOCKS_BLOCKS_HPP

#include "../test.hpp"
#include "../mocks/chunk_store.hpp"

namespace test {


using store_t = test::chunk_store;
using query_t = test::query_accessor;
using block_data = system::data_array<215>;
using header_data = system::data_array<80>;
using store_t = database::store<database::map>;
using query_t = database::query<database::store<database::map>>;
const auto events_handler = [](auto, auto) {};
extern const database::context context;

Expand Down Expand Up @@ -107,6 +108,8 @@ extern const system::chain::block block_valid_spend_internal_2b;

bool setup_three_block_store(query_t& query) NOEXCEPT;
bool setup_three_block_witness_store(query_t& query) NOEXCEPT;
bool setup_three_block_confirmed_address_store(query_t& query) NOEXCEPT;
bool setup_three_block_unconfirmed_address_store(query_t& query) NOEXCEPT;

} // namespace test

Expand Down
12 changes: 6 additions & 6 deletions test/primitives/arrayhead.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class nullptr_storage

BOOST_AUTO_TEST_CASE(arrayhead__create__size__expected)
{
data_chunk data;
data_chunk data{};
test::chunk_storage store{ data };
test_header head{ store, buckets };
BOOST_REQUIRE(head.create());
Expand All @@ -60,7 +60,7 @@ BOOST_AUTO_TEST_CASE(arrayhead__create__size__expected)

BOOST_AUTO_TEST_CASE(arrayhead__verify__uncreated__false)
{
data_chunk data;
data_chunk data{};
test::chunk_storage store{ data };
test_header head{ store, buckets };
////BOOST_REQUIRE(head.create());
Expand All @@ -69,7 +69,7 @@ BOOST_AUTO_TEST_CASE(arrayhead__verify__uncreated__false)

BOOST_AUTO_TEST_CASE(arrayhead__verify__created__false)
{
data_chunk data;
data_chunk data{};
test::chunk_storage store{ data };
test_header head{ store, buckets };
BOOST_REQUIRE(head.create());
Expand All @@ -78,7 +78,7 @@ BOOST_AUTO_TEST_CASE(arrayhead__verify__created__false)

BOOST_AUTO_TEST_CASE(arrayhead__get_body_count__created__zero)
{
data_chunk data;
data_chunk data{};
test::chunk_storage store{ data };
test_header head{ store, buckets };
BOOST_REQUIRE(head.create());
Expand All @@ -90,7 +90,7 @@ BOOST_AUTO_TEST_CASE(arrayhead__get_body_count__created__zero)

BOOST_AUTO_TEST_CASE(arrayhead__set_body_count__get_body_count__expected)
{
data_chunk data;
data_chunk data{};
test::chunk_storage store{ data };
test_header head{ store, buckets };
BOOST_REQUIRE(head.create());
Expand All @@ -105,7 +105,7 @@ BOOST_AUTO_TEST_CASE(arrayhead__set_body_count__get_body_count__expected)

BOOST_AUTO_TEST_CASE(arrayhead__clear__get_body_count__zero)
{
data_chunk data;
data_chunk data{};
test::chunk_storage store{ data };
test_header head{ store, buckets };
BOOST_REQUIRE(head.create());
Expand Down
10 changes: 5 additions & 5 deletions test/primitives/hashhead.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class nullptr_storage

BOOST_AUTO_TEST_CASE(hashhead__create__size__expected)
{
data_chunk data;
data_chunk data{};
test::chunk_storage store{ data };
hashhead_ head{ store, buckets };
BOOST_REQUIRE(head.create());
Expand All @@ -65,7 +65,7 @@ BOOST_AUTO_TEST_CASE(hashhead__create__size__expected)

BOOST_AUTO_TEST_CASE(hashhead__verify__uncreated__false)
{
data_chunk data;
data_chunk data{};;
test::chunk_storage store{ data };
hashhead_ head{ store, buckets };
////BOOST_REQUIRE(head.create());
Expand All @@ -74,7 +74,7 @@ BOOST_AUTO_TEST_CASE(hashhead__verify__uncreated__false)

BOOST_AUTO_TEST_CASE(hashhead__verify__created__false)
{
data_chunk data;
data_chunk data{};
test::chunk_storage store{ data };
hashhead_ head{ store, buckets };
BOOST_REQUIRE(head.create());
Expand All @@ -83,7 +83,7 @@ BOOST_AUTO_TEST_CASE(hashhead__verify__created__false)

BOOST_AUTO_TEST_CASE(hashhead__get_body_count__created__zero)
{
data_chunk data;
data_chunk data{};
test::chunk_storage store{ data };
hashhead_ head{ store, buckets };
BOOST_REQUIRE(head.create());
Expand All @@ -95,7 +95,7 @@ BOOST_AUTO_TEST_CASE(hashhead__get_body_count__created__zero)

BOOST_AUTO_TEST_CASE(hashhead__set_body_count__get__expected)
{
data_chunk data;
data_chunk data{};
test::chunk_storage store{ data };
hashhead_ head{ store, buckets };
BOOST_REQUIRE(head.create());
Expand Down
14 changes: 7 additions & 7 deletions test/primitives/manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ BOOST_AUTO_TEST_CASE(manager__capacity__reserved__expected)

BOOST_AUTO_TEST_CASE(manager__truncate__terminal_slab__false_unchanged)
{
data_chunk buffer;
data_chunk buffer{};
test::chunk_storage file(buffer);
manager<linkage<4>, key1, max_size_t> instance(file);
BOOST_REQUIRE(!instance.truncate(linkage<4>::terminal));
Expand Down Expand Up @@ -118,7 +118,7 @@ BOOST_AUTO_TEST_CASE(manager__truncate__half_full_slab__true_changed)

BOOST_AUTO_TEST_CASE(manager__allocate__eof_slab__terminal_unchanged)
{
data_chunk buffer;
data_chunk buffer{};
test::chunk_storage file(buffer);
manager<linkage<7>, key1, max_size_t> instance(file);
BOOST_REQUIRE_EQUAL(instance.allocate(storage::eof), linkage<7>::terminal);
Expand All @@ -128,7 +128,7 @@ BOOST_AUTO_TEST_CASE(manager__allocate__eof_slab__terminal_unchanged)

BOOST_AUTO_TEST_CASE(manager__allocate__terminal_slab__terminal_unchanged)
{
data_chunk buffer;
data_chunk buffer{};
test::chunk_storage file(buffer);
manager<linkage<4>, key1, max_size_t> instance(file);
BOOST_REQUIRE_EQUAL(instance.allocate(linkage<4>::terminal), linkage<4>::terminal);
Expand All @@ -139,7 +139,7 @@ BOOST_AUTO_TEST_CASE(manager__allocate__terminal_slab__terminal_unchanged)
BOOST_AUTO_TEST_CASE(manager__allocate__empty_slab__expected)
{
constexpr auto expected = 42u;
data_chunk buffer;
data_chunk buffer{};
test::chunk_storage file(buffer);
manager<linkage<4>, key1, max_size_t> instance(file);
BOOST_REQUIRE_EQUAL(instance.allocate(expected), zero);
Expand Down Expand Up @@ -226,7 +226,7 @@ BOOST_AUTO_TEST_CASE(manager__count__33_record__expected)

BOOST_AUTO_TEST_CASE(manager__truncate__terminal_record__false_unchanged)
{
data_chunk buffer;
data_chunk buffer{};
test::chunk_storage file(buffer);
manager<linkage<2>, key0, 5u> instance(file);
BOOST_REQUIRE(!instance.truncate(linkage<2>::terminal));
Expand Down Expand Up @@ -269,7 +269,7 @@ BOOST_AUTO_TEST_CASE(manager__truncate__half_full_record__true_logical_size_chan

BOOST_AUTO_TEST_CASE(manager__allocate__terminal_empty_record__terminal_unchanged)
{
data_chunk buffer;
data_chunk buffer{};
test::chunk_storage file(buffer);
manager<linkage<2>, key0, 5u> instance(file);
BOOST_REQUIRE_EQUAL(instance.allocate(linkage<2>::terminal), linkage<2>::terminal);
Expand All @@ -291,7 +291,7 @@ BOOST_AUTO_TEST_CASE(manager__allocate__terminal_non_empty_record__expected)

BOOST_AUTO_TEST_CASE(manager__allocate__empty_record__expected)
{
data_chunk buffer;
data_chunk buffer{};
test::chunk_storage file(buffer);
manager<linkage<2>, key0, 5u> instance(file);
BOOST_REQUIRE_EQUAL(instance.allocate(1), 0u);
Expand Down
Loading