forked from bitcoin/bitcoin
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Add interfaces::FoundBlock class to selectively return bloc…
…k data FoundBlock class allows interfaces::Chain::findBlock to return more block information without having lots of optional output parameters. FoundBlock class is also used by other chain methods in upcoming commits. There is mostly no change in behavior. Only exception is CWallet::RescanFromTime now throwing NonFatalCheckError instead of std::logic_error.
- Loading branch information
Showing
7 changed files
with
99 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright (c) 2020 The Bitcoin Core developers | ||
// Distributed under the MIT software license, see the accompanying | ||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
#include <interfaces/chain.h> | ||
#include <test/util/setup_common.h> | ||
#include <validation.h> | ||
|
||
#include <boost/test/unit_test.hpp> | ||
|
||
using interfaces::FoundBlock; | ||
|
||
BOOST_FIXTURE_TEST_SUITE(interfaces_tests, TestChain100Setup) | ||
|
||
BOOST_AUTO_TEST_CASE(findBlock) | ||
{ | ||
auto chain = interfaces::MakeChain(m_node); | ||
auto& active = ChainActive(); | ||
|
||
uint256 hash; | ||
BOOST_CHECK(chain->findBlock(active[10]->GetBlockHash(), FoundBlock().hash(hash))); | ||
BOOST_CHECK_EQUAL(hash, active[10]->GetBlockHash()); | ||
|
||
int height = -1; | ||
BOOST_CHECK(chain->findBlock(active[20]->GetBlockHash(), FoundBlock().height(height))); | ||
BOOST_CHECK_EQUAL(height, active[20]->nHeight); | ||
|
||
CBlock data; | ||
BOOST_CHECK(chain->findBlock(active[30]->GetBlockHash(), FoundBlock().data(data))); | ||
BOOST_CHECK_EQUAL(data.GetHash(), active[30]->GetBlockHash()); | ||
|
||
int64_t time = -1; | ||
BOOST_CHECK(chain->findBlock(active[40]->GetBlockHash(), FoundBlock().time(time))); | ||
BOOST_CHECK_EQUAL(time, active[40]->GetBlockTime()); | ||
|
||
int64_t max_time = -1; | ||
BOOST_CHECK(chain->findBlock(active[50]->GetBlockHash(), FoundBlock().maxTime(max_time))); | ||
BOOST_CHECK_EQUAL(max_time, active[50]->GetBlockTimeMax()); | ||
|
||
int64_t mtp_time = -1; | ||
BOOST_CHECK(chain->findBlock(active[60]->GetBlockHash(), FoundBlock().mtpTime(mtp_time))); | ||
BOOST_CHECK_EQUAL(mtp_time, active[60]->GetMedianTimePast()); | ||
|
||
BOOST_CHECK(!chain->findBlock({}, FoundBlock())); | ||
} | ||
|
||
BOOST_AUTO_TEST_SUITE_END() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters