Skip to content

Instantly share code, notes, and snippets.

@kulpreet
Created November 9, 2018 18:14
Show Gist options
  • Save kulpreet/1c09e864ee52a2c247dc88119f5c4aac to your computer and use it in GitHub Desktop.
Save kulpreet/1c09e864ee52a2c247dc88119f5c4aac to your computer and use it in GitHub Desktop.
/**
* Copyright (c) 2011-2018 libbitcoin developers (see AUTHORS)
*
* This file is part of libbitcoin.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <boost/test/unit_test.hpp>
#include <boost/filesystem.hpp>
#include <bitcoin/bitcoin.hpp>
#include <bitcoin/database.hpp>
#include "../utility/utility.hpp"
using namespace boost::system;
using namespace boost::filesystem;
using namespace bc;
using namespace bc::chain;
using namespace bc::database;
transaction random_tx(size_t fudge)
{
const chain::block genesis = libbitcoin::settings(bc::config::settings::mainnet).genesis_block;
auto tx = genesis.transactions()[0];
tx.inputs()[0].previous_output().set_index(fudge);
tx.metadata.link = fudge;
return tx;
}
#define DIRECTORY "block_database"
auto constexpr block_table = DIRECTORY "/block_table";
auto constexpr candidate_index = DIRECTORY "/candidate_index";
auto constexpr confirmed_index = DIRECTORY "/confirmed_index";
auto constexpr tx_index = DIRECTORY "/tx_index";
struct block_database_directory_setup_fixture
{
block_database_directory_setup_fixture()
{
test::clear_path(DIRECTORY);
}
~block_database_directory_setup_fixture()
{
test::clear_path(DIRECTORY);
}
};
BOOST_FIXTURE_TEST_SUITE(block_database_tests, block_database_directory_setup_fixture)
BOOST_AUTO_TEST_CASE(block_database__store__only_genesis_no_index__height_not_available) {
const chain::block& block0 = libbitcoin::settings(bc::config::settings::mainnet).genesis_block;
test::create(block_table);
test::create(candidate_index);
test::create(confirmed_index);
test::create(tx_index);
block_database instance(block_table, candidate_index, confirmed_index, tx_index, 1000, 50);
BOOST_REQUIRE(instance.create());
// setup end
instance.store(block0.header(), 0, 0);
size_t height;
BOOST_REQUIRE(!instance.top(height, false));
}
BOOST_AUTO_TEST_SUITE_END()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment