diff --git a/src/protocols/electrum/protocol_electrum_addresses.cpp b/src/protocols/electrum/protocol_electrum_addresses.cpp index 3de0f7a9..3301d96a 100644 --- a/src/protocols/electrum/protocol_electrum_addresses.cpp +++ b/src/protocols/electrum/protocol_electrum_addresses.cpp @@ -121,19 +121,27 @@ void protocol_electrum::handle_blockchain_address_subscribe(const code& ec, // utilities // ---------------------------------------------------------------------------- // A p2pk output does not produce a bitcoin payment address, as there is no -// form of a p2pk bitcoin payment address. However a +// form of a p2pk bitcoin payment address. +// A failed parse or default initialized script returns null_hash. hash_digest protocol_electrum::extract_scripthash( const std::string& address) const NOEXCEPT { - // A failed parse or default initialized script hashes to null_hash. - return payment_address(address).output_script(p2kh_, p2sh_).hash(); + const auto payment = payment_address(address); + if (!payment) + return {}; + + const auto script = payment.output_script(p2kh_, p2sh_); + if (!script.is_valid()) + return {}; + + return script.hash(); } +// A failure to parse as p2sh or p2kh returns invalid object. payment_address protocol_electrum::extract_address( const chain::script& script) const NOEXCEPT { - // A failure to parse as p2sh or p2kh returns invalid object. return payment_address::extract_output(script, p2kh_, p2sh_); } diff --git a/test/protocols/bitcoind/bitcoind.cpp b/test/protocols/bitcoind/bitcoind.cpp index 2da16a28..fe475260 100644 --- a/test/protocols/bitcoind/bitcoind.cpp +++ b/test/protocols/bitcoind/bitcoind.cpp @@ -21,8 +21,13 @@ #include "bitcoind.hpp" #include -bitcoind_setup_fixture::bitcoind_setup_fixture() - : config_{ system::chain::selection::mainnet, web_pages, web_pages }, +bitcoind_setup_fixture::bitcoind_setup_fixture(const initializer& setup) + : config_ + { + system::chain::selection::mainnet, + test::web_pages, + test::web_pages + }, store_ { [&]() NOEXCEPT -> const database::settings& @@ -49,11 +54,11 @@ bitcoind_setup_fixture::bitcoind_setup_fixture() node_settings.minimum_fee_rate = 99.0; network_settings.inbound.connections = 0; network_settings.outbound.connections = 0; - auto ec = store_.create([](auto, auto) {}); // Create and populate the store. + auto ec = store_.create([](auto, auto) {}); BOOST_REQUIRE_MESSAGE(!ec, ec.message()); - BOOST_REQUIRE_MESSAGE(setup_ten_block_store(query_), "bitcoind initialize"); + BOOST_REQUIRE_MESSAGE(setup(query_), "bitcoind initialize"); // Run the server. std::promise running{}; diff --git a/test/protocols/bitcoind/bitcoind.hpp b/test/protocols/bitcoind/bitcoind.hpp index f1a0f1cd..e9b348d7 100644 --- a/test/protocols/bitcoind/bitcoind.hpp +++ b/test/protocols/bitcoind/bitcoind.hpp @@ -30,7 +30,8 @@ struct bitcoind_setup_fixture { DELETE_COPY_MOVE(bitcoind_setup_fixture); - bitcoind_setup_fixture(); + using initializer = std::function; + explicit bitcoind_setup_fixture(const initializer& setup); ~bitcoind_setup_fixture(); // bitcoind does not implement any protocol version control or negotiation. @@ -38,8 +39,8 @@ struct bitcoind_setup_fixture protected: configuration config_; - store_t store_; - query_t query_; + test::store_t store_; + test::query_t query_; private: network::logger log_; @@ -48,4 +49,16 @@ struct bitcoind_setup_fixture boost::asio::ip::tcp::socket socket_{ io }; }; +struct bitcoind_ten_block_setup_fixture + : bitcoind_setup_fixture +{ + inline bitcoind_ten_block_setup_fixture() + : bitcoind_setup_fixture([](test::query_t& query) + { + return test::setup_ten_block_store(query); + }) + { + } +}; + #endif diff --git a/test/protocols/bitcoind/bitcoind_rest.cpp b/test/protocols/bitcoind/bitcoind_rest.cpp index 0a479744..ae16ebe2 100644 --- a/test/protocols/bitcoind/bitcoind_rest.cpp +++ b/test/protocols/bitcoind/bitcoind_rest.cpp @@ -19,6 +19,6 @@ #include "../../test.hpp" #include "bitcoind.hpp" -BOOST_FIXTURE_TEST_SUITE(bitcoind_tests, bitcoind_setup_fixture) +BOOST_FIXTURE_TEST_SUITE(bitcoind_tests, bitcoind_ten_block_setup_fixture) BOOST_AUTO_TEST_SUITE_END() diff --git a/test/protocols/bitcoind/bitcoind_rpc.cpp b/test/protocols/bitcoind/bitcoind_rpc.cpp index 0a479744..ae16ebe2 100644 --- a/test/protocols/bitcoind/bitcoind_rpc.cpp +++ b/test/protocols/bitcoind/bitcoind_rpc.cpp @@ -19,6 +19,6 @@ #include "../../test.hpp" #include "bitcoind.hpp" -BOOST_FIXTURE_TEST_SUITE(bitcoind_tests, bitcoind_setup_fixture) +BOOST_FIXTURE_TEST_SUITE(bitcoind_tests, bitcoind_ten_block_setup_fixture) BOOST_AUTO_TEST_SUITE_END() diff --git a/test/protocols/blocks.cpp b/test/protocols/blocks.cpp index ef70cae8..fb95ca40 100644 --- a/test/protocols/blocks.cpp +++ b/test/protocols/blocks.cpp @@ -21,6 +21,8 @@ // blockchain.info/rawblock/[hash]?format=hex +namespace test { + using namespace system; constexpr hash_digest block0_hash = base16_hash("000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f"); constexpr hash_digest block1_hash = base16_hash("00000000839a8e6886ab5951d76f411475428afc90947ee320161bbf18eb6048"); @@ -66,16 +68,17 @@ constexpr block_data block7_data = base16_array("010000008d778fdc15a2d3fb76b7122 constexpr block_data block8_data = base16_array("010000004494c8cf4154bdcc0720cd4a59d9c9b285e4b146d45f061d2b6c967100000000e3855ed886605b6d4a99d5fa2ef2e9b0b164e63df3c4136bebf2d0dac0f1f7a667c86649ffff001d1c4b56660101000000010000000000000000000000000000000000000000000000000000000000000000ffffffff0704ffff001d012cffffffff0100f2052a01000000434104cc8d85f5e7933cb18f13b97d165e1189c1fb3e9c98b0dd5446b2a1989883ff9e740a8a75da99cc59a21016caf7a7afd3e4e9e7952983e18d1ff70529d62e0ba1ac00000000"); constexpr block_data block9_data = base16_array("01000000c60ddef1b7618ca2348a46e868afc26e3efc68226c78aa47f8488c4000000000c997a5e56e104102fa209c6a852dd90660a20b2d9c352423edce25857fcd37047fca6649ffff001d28404f530101000000010000000000000000000000000000000000000000000000000000000000000000ffffffff0704ffff001d0134ffffffff0100f2052a0100000043410411db93e1dcdb8a016b49840f8c53bc1eb68a382e97b1482ecad7b148a6909a5cb2e0eaddfb84ccf9744464f82e160bfa9b8b64f9d4c03f999b8643f656b412a3ac00000000"); -const chain::block genesis = system::settings{ chain::selection::mainnet }.genesis_block; -const chain::block block1{ block1_data, true }; -const chain::block block2{ block2_data, true }; -const chain::block block3{ block3_data, true }; -const chain::block block4{ block4_data, true }; -const chain::block block5{ block5_data, true }; -const chain::block block6{ block6_data, true }; -const chain::block block7{ block7_data, true }; -const chain::block block8{ block8_data, true }; -const chain::block block9{ block9_data, true }; +using namespace chain; +const block genesis = system::settings{ chain::selection::mainnet }.genesis_block; +const block block1{ block1_data, true }; +const block block2{ block2_data, true }; +const block block3{ block3_data, true }; +const block block4{ block4_data, true }; +const block block5{ block5_data, true }; +const block block6{ block6_data, true }; +const block block7{ block7_data, true }; +const block block8{ block8_data, true }; +const block block9{ block9_data, true }; const server::settings::embedded_pages web_pages{}; @@ -102,8 +105,50 @@ bool setup_ten_block_store(query_t& query) NOEXCEPT query.push_confirmed(query.to_header(block9_hash), false); } -using namespace chain; -const chain::block bogus_block10 +bool setup_three_block_store(query_t& query) NOEXCEPT +{ + return query.initialize(genesis) && + query.set(block1, database::context{ 0, 1, 0 }, false, false) && + query.set(block2, database::context{ 0, 2, 0 }, false, false) && + query.push_confirmed(query.to_header(block1_hash), false) && + query.push_confirmed(query.to_header(block2_hash), false); +} + +bool setup_three_block_witness_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.push_confirmed(query.to_header(block1a.hash()), false) && + 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.set(block1b, database::context{ 0, 1, 0 }, false, false) && + query.set(block2b, database::context{ 0, 2, 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(block3a.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); +} + +const block bogus_block10 { header { @@ -212,4 +257,465 @@ const chain::block bogus_block10 0x0f } } -}; \ No newline at end of file +}; +const block bogus_block +{ + header + { + 0x31323334, + null_hash, + hash_digest{ 0xbb }, + 0x41424344, + 0x51525354, + 0x61626364 + }, + transactions + { + transaction + { + 0x01, + inputs + { + input + { + point{}, + script{}, + witness{}, + 0x02 + }, + input + { + point{}, + script{}, + witness{}, + 0x03 + } + }, + outputs + { + output + { + 0x04, + script{} + } + }, + 0x05 + }, + transaction + { + 0x06, + inputs + { + input + { + point{}, + script{}, + witness{}, + 0x07 + }, + input + { + point{}, + script{}, + witness{}, + 0x08 + } + }, + outputs + { + output + { + 0x09, + script{} + } + }, + 0x0a + }, + transaction + { + 0x0b, + inputs + { + input + { + point{}, + script{}, + witness{}, + 0x0c + }, + input + { + point{}, + script{}, + witness{}, + 0x0d + } + }, + outputs + { + output + { + 0x0e, + script{} + } + }, + 0x0f + } + } +}; +const block block1a +{ + header + { + 0x31323334, // version + block0_hash, // previous_block_hash + hash_digest{ 0x1a },// merkle_root + 0x41424344, // timestamp + 0x51525354, // bits + 0x61626364 // nonce + }, + transactions + { + // This first transaction is *not* a coinbase. + transaction // tx#1 + { + 0x2a, // version + inputs + { + input + { + point{ one_hash, 0x18 }, // missing prevout + script{ { { opcode::op_return }, { opcode::pick } } }, + witness{ "[242424]" }, + 0x2a // sequence + }, + input + { + point{ one_hash, 0x2a }, // missing prevout + script{ { { opcode::op_return }, { opcode::roll } } }, + witness{ "[313131]" }, + 0x18 // sequence + }, + input + { + point{ hash_digest{ 0x02 }, 0x2b }, // missing prevout + script{ { { opcode::op_return }, { opcode::roll } } }, + witness{ "[424242]" }, + 0x19 // sequence + } + }, + outputs + { + output + { + 0x18, // value + script{ { { opcode::pick } } } + }, + output + { + 0x2a, // value + script{ { { opcode::roll } } } + } + }, + 0x18 // locktime + } + } +}; +const block block2a +{ + header + { + 0x31323334, // version + block1a.hash(), // previous_block_hash + hash_digest{ 0x2a },// merkle_root + 0x41424344, // timestamp + 0x51525354, // bits + 0x61626364 // nonce + }, + transactions + { + // This first transaction is *not* a coinbase. + transaction // tx#2 + { + 0xa2, // version + inputs + { + input + { + // existing prevout + point{ block1a.transactions_ptr()->front()->hash(false), 0x00 }, + script{ { { opcode::checkmultisig }, { opcode::pick } } }, + witness{ "[242424]" }, + 0xa2 // sequence + }, + input + { + // existing prevout + point{ block1a.transactions_ptr()->front()->hash(false), 0x01 }, + script{ { { opcode::checkmultisig }, { opcode::roll } } }, + witness{ "[313131]" }, + 0x81 // sequence + } + }, + outputs + { + output + { + 0x81, // value + script{ { { opcode::pick } } } + } + }, + 0x81 // locktime + }, + transaction // tx#3 + { + 0xa2, // version + inputs + { + input + { + point{ one_hash, 0x20 }, // missing prevout + script{ { { opcode::checkmultisig }, { opcode::pick } } }, + witness{ "[242424]" }, + 0xa2 // sequence + }, + input + { + point{ one_hash, 0x21 }, // missing prevout + script{ { { opcode::checkmultisig }, { opcode::roll } } }, + witness{ "[313131]" }, + 0x81 // sequence + } + }, + outputs + { + output + { + 0x81, // value + script{ { { opcode::pick } } } + } + }, + 0x81 // locktime + } + } +}; +const block block3a +{ + header + { + 0x31323334, // version + block2a.hash(), // previous_block_hash + hash_digest{ 0x3a },// merkle_root + 0x41424344, // timestamp + 0x51525354, // bits + 0x61626364 // nonce + }, + transactions + { + // This first transaction is *not* a coinbase. + transaction + { + 0xa3, // version + inputs + { + input + { + // existing prevout + point{ block1a.transactions_ptr()->front()->hash(false), 0x01 }, + script{ { { opcode::checkmultisig }, { opcode::size } } }, + witness{ "[949494]" }, + 0xa3 // sequence + }, + input + { + // existing prevout + point{ block1a.transactions_ptr()->front()->hash(false), 0x00 }, + script{ { { opcode::checkmultisig }, { opcode::size } } }, + witness{ "[919191]" }, + 0x83 // sequence + } + }, + outputs + { + output + { + 0x83, // value + script{ { { opcode::pick } } } + } + }, + 0x83 // locktime + } + } +}; +const transaction tx4 +{ + 0xa5, // version + inputs + { + input + { + point{ block1a.transactions_ptr()->front()->hash(false), 0x00 }, + script{ { { opcode::checkmultisig }, { opcode::pick } } }, + witness{ "[252525]" }, + 0xa5 // sequence + }, + input + { + point{ block1a.transactions_ptr()->front()->hash(false), 0x01 }, + script{ { { opcode::checkmultisig }, { opcode::roll } } }, + witness{ "[353535]" }, + 0x85 // sequence + } + }, + outputs + { + output + { + 0x08, // value + script{ { { opcode::pick } } } + } + }, + 0x85 // locktime +}; +const transaction tx5 +{ + 0xa5, // version + inputs + { + input + { + point{ block1a.transactions_ptr()->front()->hash(false), 0x00 }, + script{ { { opcode::checkmultisig }, { opcode::pick } } }, + witness{ "[252525]" }, + 0xa5 // sequence + } + }, + outputs + { + output + { + 0x85, // value + script{ { { opcode::pick } } } + } + }, + 0x85 // locktime +}; +const block block1b +{ + header + { + 0x31323334, // version + block0_hash, // previous_block_hash + hash_digest{ 0x1b },// merkle_root + 0x41424344, // timestamp + 0x51525354, // bits + 0x61626364 // nonce + }, + transactions + { + // This first transaction is a coinbase. + transaction // tx#1 + { + 0xb1, + inputs + { + input + { + point{}, + script{ { { opcode::checkmultisig }, { opcode::size } } }, + witness{}, + 0xb1 + } + }, + outputs + { + output + { + 0xb1, + script{ { { opcode::pick } } } + }, + output + { + 0xb1, + script{ { { opcode::pick } } } + } + }, + 0xb1 + } + } +}; +const block block2b +{ + header + { + 0x31323334, // version + block1b.hash(), // previous_block_hash + hash_digest{ 0x2b },// merkle_root + 0x41424344, // timestamp + 0x51525354, // bits + 0x61626364 // nonce + }, + transactions + { + // This first transaction is a coinbase. + transaction // tx#2 + { + 0xb2, + inputs + { + input + { + point{ block1b.transactions_ptr()->front()->hash(false), 0x00 }, + script{ { { opcode::checkmultisig }, { opcode::size } } }, + witness{}, + 0xb2 + }, + input + { + point{ block1b.transactions_ptr()->front()->hash(false), 0x01 }, + script{ { { opcode::checkmultisig }, { opcode::size } } }, + witness{}, + 0xb2 + } + }, + outputs + { + output + { + 0xb2, + script{ { { opcode::pick } } } + } + }, + 0xb2 + } + } +}; +const transaction tx2b +{ + transaction + { + 0xb1, + inputs + { + input + { + // Spends block1b coinbase. + point{ block1b.transactions_ptr()->front()->hash(false), 0x00 }, + script{ { { opcode::checkmultisig }, { opcode::size } } }, + witness{}, + 0xb1 + } + }, + outputs + { + output + { + 0xb1, + script{ { { opcode::pick } } } + } + }, + 0xb1 + } +}; + +} // namespace test diff --git a/test/protocols/blocks.hpp b/test/protocols/blocks.hpp index 4ca2747c..d59639d1 100644 --- a/test/protocols/blocks.hpp +++ b/test/protocols/blocks.hpp @@ -21,6 +21,8 @@ #include "../test.hpp" +namespace test { + using block_data = system::data_array<215>; using header_data = system::data_array<80>; using store_t = database::store; @@ -84,6 +86,22 @@ extern const system::chain::block block8; extern const system::chain::block block9; extern const system::chain::block bogus_block10; +extern const system::chain::block bogus_block; +extern const system::chain::block block1a; +extern const system::chain::block block2a; +extern const system::chain::block block3a; +extern const system::chain::transaction tx4; +extern const system::chain::transaction tx5; +extern const system::chain::block block1b; +extern const system::chain::block block2b; +extern const system::chain::transaction tx2b; + bool setup_ten_block_store(query_t& query) NOEXCEPT; +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 #endif diff --git a/test/protocols/electrum/electrum.cpp b/test/protocols/electrum/electrum.cpp index e9a1eb57..4bec6033 100644 --- a/test/protocols/electrum/electrum.cpp +++ b/test/protocols/electrum/electrum.cpp @@ -22,8 +22,13 @@ #include #include -electrum_setup_fixture::electrum_setup_fixture() - : config_{ system::chain::selection::mainnet, web_pages, web_pages }, +electrum_setup_fixture::electrum_setup_fixture(const initializer& setup) + : config_ + { + system::chain::selection::mainnet, + test::web_pages, + test::web_pages + }, store_ { [&]() NOEXCEPT -> const database::settings& @@ -55,11 +60,11 @@ electrum_setup_fixture::electrum_setup_fixture() node_settings.minimum_fee_rate = 99.0; network_settings.inbound.connections = 0; network_settings.outbound.connections = 0; - auto ec = store_.create([](auto, auto) {}); // Create and populate the store. + auto ec = store_.create([](auto, auto) {}); BOOST_REQUIRE_MESSAGE(!ec, ec.message()); - BOOST_REQUIRE_MESSAGE(setup_ten_block_store(query_), "electrum initialize"); + BOOST_REQUIRE_MESSAGE(setup(query_), "electrum initialize"); // Run the server. std::promise running{}; diff --git a/test/protocols/electrum/electrum.hpp b/test/protocols/electrum/electrum.hpp index f984f21d..a5b31282 100644 --- a/test/protocols/electrum/electrum.hpp +++ b/test/protocols/electrum/electrum.hpp @@ -28,7 +28,8 @@ struct electrum_setup_fixture { DELETE_COPY_MOVE(electrum_setup_fixture); - electrum_setup_fixture(); + using initializer = std::function; + explicit electrum_setup_fixture(const initializer& setup); ~electrum_setup_fixture(); boost::json::value get(const std::string& request); @@ -37,8 +38,8 @@ struct electrum_setup_fixture protected: configuration config_; - store_t store_; - query_t query_; + test::store_t store_; + test::query_t query_; private: network::logger log_; @@ -47,4 +48,28 @@ struct electrum_setup_fixture boost::asio::ip::tcp::socket socket_{ io }; }; +struct electrum_ten_block_setup_fixture + : electrum_setup_fixture +{ + inline electrum_ten_block_setup_fixture() + : electrum_setup_fixture([](test::query_t& query) + { + return test::setup_ten_block_store(query); + }) + { + } +}; + +struct electrum_three_block_confirmed_address_setup_fixture + : electrum_setup_fixture +{ + inline electrum_three_block_confirmed_address_setup_fixture() + : electrum_setup_fixture([](test::query_t& query) + { + return test::setup_three_block_confirmed_address_store(query); + }) + { + } +}; + #endif diff --git a/test/protocols/electrum/electrum_addresses.cpp b/test/protocols/electrum/electrum_addresses.cpp index a1fed756..c4e67092 100644 --- a/test/protocols/electrum/electrum_addresses.cpp +++ b/test/protocols/electrum/electrum_addresses.cpp @@ -19,7 +19,7 @@ #include "../../test.hpp" #include "electrum.hpp" -BOOST_FIXTURE_TEST_SUITE(electrum_tests, electrum_setup_fixture) +BOOST_FIXTURE_TEST_SUITE(electrum_tests, electrum_three_block_confirmed_address_setup_fixture) // blockchain.address.get_balance // blockchain.address.get_history diff --git a/test/protocols/electrum/electrum_fees.cpp b/test/protocols/electrum/electrum_fees.cpp index 3b154995..690275b4 100644 --- a/test/protocols/electrum/electrum_fees.cpp +++ b/test/protocols/electrum/electrum_fees.cpp @@ -19,7 +19,7 @@ #include "../../test.hpp" #include "electrum.hpp" -BOOST_FIXTURE_TEST_SUITE(electrum_tests, electrum_setup_fixture) +BOOST_FIXTURE_TEST_SUITE(electrum_tests, electrum_ten_block_setup_fixture) using namespace system; static const code wrong_version{ server::error::wrong_version }; diff --git a/test/protocols/electrum/electrum_headers.cpp b/test/protocols/electrum/electrum_headers.cpp index 566215a9..e8f5cb12 100644 --- a/test/protocols/electrum/electrum_headers.cpp +++ b/test/protocols/electrum/electrum_headers.cpp @@ -19,7 +19,7 @@ #include "../../test.hpp" #include "electrum.hpp" -BOOST_FIXTURE_TEST_SUITE(electrum_tests, electrum_setup_fixture) +BOOST_FIXTURE_TEST_SUITE(electrum_tests, electrum_ten_block_setup_fixture) using namespace system; static const code not_found{ server::error::not_found }; @@ -79,6 +79,7 @@ BOOST_AUTO_TEST_CASE(electrum__blockchain_block_get_chunk__above_top__empty) BOOST_AUTO_TEST_CASE(electrum__blockchain_block_get_chunk__zero__first_ten_headers_in_order) { BOOST_REQUIRE(handshake(electrum::version::v1_1)); + using namespace test; const auto expected = encode_base16(header0_data) + encode_base16(header1_data) + encode_base16(header2_data) + encode_base16(header3_data) + encode_base16(header4_data) + encode_base16(header5_data) + encode_base16(header6_data) + @@ -127,7 +128,7 @@ BOOST_AUTO_TEST_CASE(electrum__blockchain_block_get_header__five__expected_heade REQUIRE_NO_THROW_TRUE(response.at("result").is_string()); const auto& result = response.at("result").as_string(); - BOOST_REQUIRE_EQUAL(result, encode_base16(header5_data)); + BOOST_REQUIRE_EQUAL(result, encode_base16(test::header5_data)); } // blockchain.block.header @@ -151,7 +152,7 @@ BOOST_AUTO_TEST_CASE(electrum__blockchain_block_header__genesis_no_checkpoint__e // "hex" prior to v1.6 const auto& result = response.at("result").as_object(); REQUIRE_NO_THROW_TRUE(result.at("hex").is_string()); - BOOST_REQUIRE_EQUAL(result.at("hex").as_string(), encode_base16(header0_data)); + BOOST_REQUIRE_EQUAL(result.at("hex").as_string(), encode_base16(test::header0_data)); } BOOST_AUTO_TEST_CASE(electrum__blockchain_block_header__block1_no_checkpoint__expected_no_proof) @@ -160,7 +161,7 @@ BOOST_AUTO_TEST_CASE(electrum__blockchain_block_header__block1_no_checkpoint__ex const auto response = get(R"({"id":44,"method":"blockchain.block.header","params":[1]})" "\n"); REQUIRE_NO_THROW_TRUE(response.at("result").as_object().at("header").is_string()); - BOOST_REQUIRE_EQUAL(response.at("result").as_object().at("header").as_string(), encode_base16(header1_data)); + BOOST_REQUIRE_EQUAL(response.at("result").as_object().at("header").as_string(), encode_base16(test::header1_data)); } BOOST_AUTO_TEST_CASE(electrum__blockchain_block_header__genesis_zero_checkpoint__expected_no_proof) @@ -169,17 +170,17 @@ BOOST_AUTO_TEST_CASE(electrum__blockchain_block_header__genesis_zero_checkpoint_ const auto response = get(R"({"id":45,"method":"blockchain.block.header","params":[0,0]})" "\n"); REQUIRE_NO_THROW_TRUE(response.at("result").as_object().at("header").is_string()); - BOOST_REQUIRE_EQUAL(response.at("result").as_object().at("header").as_string(), encode_base16(header0_data)); + BOOST_REQUIRE_EQUAL(response.at("result").as_object().at("header").as_string(), encode_base16(test::header0_data)); } BOOST_AUTO_TEST_CASE(electrum__blockchain_block_header__proof_self_block1__expected) { BOOST_REQUIRE(handshake(electrum::version::v1_6)); - const auto expected_header = encode_base16(header1_data); + const auto expected_header = encode_base16(test::header1_data); const auto expected_root = encode_hash(merkle_root( { - block0_hash, - block1_hash + test::block0_hash, + test::block1_hash })); const auto response = get(R"({"id":46,"method":"blockchain.block.header","params":[1,1]})" "\n"); @@ -195,13 +196,14 @@ BOOST_AUTO_TEST_CASE(electrum__blockchain_block_header__proof_self_block1__expec const auto& branch = result.at("branch").as_array(); BOOST_REQUIRE(branch.at(0).is_string()); BOOST_REQUIRE_EQUAL(branch.size(), 1u); - BOOST_REQUIRE_EQUAL(branch.at(0).as_string(), encode_hash(block0_hash)); + BOOST_REQUIRE_EQUAL(branch.at(0).as_string(), encode_hash(test::block0_hash)); } BOOST_AUTO_TEST_CASE(electrum__blockchain_block_header__proof_example__expected) { BOOST_REQUIRE(handshake(electrum::version::v1_6)); - + + using namespace test; const auto expected_root = encode_hash(merkle_root( { block0_hash, @@ -322,7 +324,7 @@ BOOST_AUTO_TEST_CASE(electrum__blockchain_block_headers__genesis_count1_no_check // "hex" prior to 1.6 REQUIRE_NO_THROW_TRUE(result.at("hex").is_string()); - BOOST_REQUIRE_EQUAL(result.at("hex").as_string(), encode_base16(header0_data)); + BOOST_REQUIRE_EQUAL(result.at("hex").as_string(), encode_base16(test::header0_data)); } BOOST_AUTO_TEST_CASE(electrum__blockchain_block_headers__genesis_count1_no_checkpoint_v1_6__expected) @@ -340,7 +342,7 @@ BOOST_AUTO_TEST_CASE(electrum__blockchain_block_headers__genesis_count1_no_check REQUIRE_NO_THROW_TRUE(result.at("headers").is_array()); BOOST_REQUIRE(result.at("headers").as_array().at(0).is_string()); BOOST_REQUIRE_EQUAL(result.at("headers").as_array().size(), 1u); - BOOST_REQUIRE_EQUAL(result.at("headers").as_array().at(0).as_string(), encode_base16(header0_data)); + BOOST_REQUIRE_EQUAL(result.at("headers").as_array().at(0).as_string(), encode_base16(test::header0_data)); } BOOST_AUTO_TEST_CASE(electrum__blockchain_block_headers__block1to3_no_checkpoint_v1_6__expected) @@ -358,9 +360,9 @@ BOOST_AUTO_TEST_CASE(electrum__blockchain_block_headers__block1to3_no_checkpoint const auto& headers = result.at("headers").as_array(); BOOST_REQUIRE(result.at("headers").as_array().at(0).is_string()); BOOST_REQUIRE_EQUAL(headers.size(), 3u); - BOOST_REQUIRE_EQUAL(headers.at(0).as_string(), encode_base16(header1_data)); - BOOST_REQUIRE_EQUAL(headers.at(1).as_string(), encode_base16(header2_data)); - BOOST_REQUIRE_EQUAL(headers.at(2).as_string(), encode_base16(header3_data)); + BOOST_REQUIRE_EQUAL(headers.at(0).as_string(), encode_base16(test::header1_data)); + BOOST_REQUIRE_EQUAL(headers.at(1).as_string(), encode_base16(test::header2_data)); + BOOST_REQUIRE_EQUAL(headers.at(2).as_string(), encode_base16(test::header3_data)); } BOOST_AUTO_TEST_CASE(electrum__blockchain_block_headers__block1to3_no_checkpoint_v1_4__expected) @@ -376,6 +378,7 @@ BOOST_AUTO_TEST_CASE(electrum__blockchain_block_headers__block1to3_no_checkpoint BOOST_REQUIRE_EQUAL(result.at("count").as_int64(), 3); // "hex" prior to v1.6 + using namespace test; const auto expected = encode_base16(header1_data) + encode_base16(header2_data) + encode_base16(header3_data); BOOST_REQUIRE_EQUAL(result.at("hex").as_string(), expected); } @@ -410,6 +413,7 @@ BOOST_AUTO_TEST_CASE(electrum__blockchain_block_headers__proof_no_offset__expect { BOOST_REQUIRE(handshake(electrum::version::v1_6)); + using namespace test; const auto expected_root = encode_hash(merkle_root( { block0_hash, @@ -456,6 +460,7 @@ BOOST_AUTO_TEST_CASE(electrum__blockchain_block_headers__proof_offset__expected) { BOOST_REQUIRE(handshake(electrum::version::v1_6)); + using namespace test; const auto expected_root = encode_hash(merkle_root( { block0_hash, @@ -570,7 +575,7 @@ BOOST_AUTO_TEST_CASE(electrum__blockchain_headers_subscribe__default__expected) REQUIRE_NO_THROW_TRUE(result.at("height").is_int64()); REQUIRE_NO_THROW_TRUE(result.at("hex").is_string()); BOOST_REQUIRE_EQUAL(result.at("height").as_int64(), 9); - BOOST_REQUIRE_EQUAL(result.at("hex").as_string(), system::encode_base16(header9_data)); + BOOST_REQUIRE_EQUAL(result.at("hex").as_string(), system::encode_base16(test::header9_data)); } BOOST_AUTO_TEST_CASE(electrum__blockchain_headers_subscribe__jsonrpc_2__expected) @@ -582,7 +587,7 @@ BOOST_AUTO_TEST_CASE(electrum__blockchain_headers_subscribe__jsonrpc_2__expected REQUIRE_NO_THROW_TRUE(result.at("height").is_int64()); REQUIRE_NO_THROW_TRUE(result.at("hex").is_string()); BOOST_REQUIRE_EQUAL(result.at("height").as_int64(), 9); - BOOST_REQUIRE_EQUAL(result.at("hex").as_string(), system::encode_base16(header9_data)); + BOOST_REQUIRE_EQUAL(result.at("hex").as_string(), system::encode_base16(test::header9_data)); } BOOST_AUTO_TEST_CASE(electrum__blockchain_headers_subscribe__id_preserved__expected) @@ -604,7 +609,7 @@ BOOST_AUTO_TEST_CASE(electrum__blockchain_headers_subscribe__empty_params__expec const auto& result = response.at("result").as_object(); BOOST_REQUIRE_EQUAL(result.at("height").as_int64(), 9); - BOOST_REQUIRE_EQUAL(result.at("hex").as_string(), system::encode_base16(header9_data)); + BOOST_REQUIRE_EQUAL(result.at("hex").as_string(), system::encode_base16(test::header9_data)); } BOOST_AUTO_TEST_SUITE_END() diff --git a/test/protocols/electrum/electrum_mempool.cpp b/test/protocols/electrum/electrum_mempool.cpp index 48d9ebe2..13589731 100644 --- a/test/protocols/electrum/electrum_mempool.cpp +++ b/test/protocols/electrum/electrum_mempool.cpp @@ -19,7 +19,7 @@ #include "../../test.hpp" #include "electrum.hpp" -BOOST_FIXTURE_TEST_SUITE(electrum_tests, electrum_setup_fixture) +BOOST_FIXTURE_TEST_SUITE(electrum_tests, electrum_ten_block_setup_fixture) using namespace system; static const code wrong_version{ server::error::wrong_version }; diff --git a/test/protocols/electrum/electrum_outputs.cpp b/test/protocols/electrum/electrum_outputs.cpp index b9dcbd4e..eb55cb33 100644 --- a/test/protocols/electrum/electrum_outputs.cpp +++ b/test/protocols/electrum/electrum_outputs.cpp @@ -19,7 +19,7 @@ #include "../../test.hpp" #include "electrum.hpp" -BOOST_FIXTURE_TEST_SUITE(electrum_tests, electrum_setup_fixture) +BOOST_FIXTURE_TEST_SUITE(electrum_tests, electrum_ten_block_setup_fixture) using namespace system; static const code not_found{ server::error::not_found }; @@ -92,10 +92,10 @@ BOOST_AUTO_TEST_CASE(electrum__blockchain_utxo_get_address__p2kh__expected) BOOST_REQUIRE(handshake(electrum::version::v1_0)); // Add a confirmed p2sh/p2kh block. - query_.set(bogus_block10, database::context{ 0, 10, 0 }, false, false); - query_.push_confirmed(query_.to_header(bogus_block10.hash()), false); + query_.set(test::bogus_block10, database::context{ 0, 10, 0 }, false, false); + query_.push_confirmed(query_.to_header(test::bogus_block10.hash()), false); - const auto hash = bogus_block10.transactions_ptr()->at(1)->hash(false); + const auto hash = test::bogus_block10.transactions_ptr()->at(1)->hash(false); const auto request = R"({"id":901,"method":"blockchain.utxo.get_address","params":["%1%",0]})" "\n"; const auto response = get((boost::format(request) % encode_hash(hash)).str()); REQUIRE_NO_THROW_TRUE(response.at("result").is_string()); @@ -109,10 +109,10 @@ BOOST_AUTO_TEST_CASE(electrum__blockchain_utxo_get_address__p2sh__expected) BOOST_REQUIRE(handshake(electrum::version::v1_0)); // Add a confirmed p2sh/p2kh block. - query_.set(bogus_block10, database::context{ 0, 10, 0 }, false, false); - query_.push_confirmed(query_.to_header(bogus_block10.hash()), false); + query_.set(test::bogus_block10, database::context{ 0, 10, 0 }, false, false); + query_.push_confirmed(query_.to_header(test::bogus_block10.hash()), false); - const auto hash = bogus_block10.transactions_ptr()->at(1)->hash(false); + const auto hash = test::bogus_block10.transactions_ptr()->at(1)->hash(false); const auto request = R"({"id":901,"method":"blockchain.utxo.get_address","params":["%1%",1]})" "\n"; const auto response = get((boost::format(request) % encode_hash(hash)).str()); REQUIRE_NO_THROW_TRUE(response.at("result").is_string()); diff --git a/test/protocols/electrum/electrum_scripthash.cpp b/test/protocols/electrum/electrum_scripthash.cpp index 2c58efd8..e9298eb6 100644 --- a/test/protocols/electrum/electrum_scripthash.cpp +++ b/test/protocols/electrum/electrum_scripthash.cpp @@ -19,7 +19,7 @@ #include "../../test.hpp" #include "electrum.hpp" -BOOST_FIXTURE_TEST_SUITE(electrum_tests, electrum_setup_fixture) +BOOST_FIXTURE_TEST_SUITE(electrum_tests, electrum_three_block_confirmed_address_setup_fixture) // blockchain.scripthash.get_balance // blockchain.scripthash.get_history diff --git a/test/protocols/electrum/electrum_scripts.cpp b/test/protocols/electrum/electrum_scripts.cpp index 02c1574a..b887070e 100644 --- a/test/protocols/electrum/electrum_scripts.cpp +++ b/test/protocols/electrum/electrum_scripts.cpp @@ -19,7 +19,7 @@ #include "../../test.hpp" #include "electrum.hpp" -BOOST_FIXTURE_TEST_SUITE(electrum_tests, electrum_setup_fixture) +BOOST_FIXTURE_TEST_SUITE(electrum_tests, electrum_three_block_confirmed_address_setup_fixture) // blockchain.scriptpubkey.get_balance // blockchain.scriptpubkey.get_history diff --git a/test/protocols/electrum/electrum_server.cpp b/test/protocols/electrum/electrum_server.cpp index 008cee2b..08d58ac6 100644 --- a/test/protocols/electrum/electrum_server.cpp +++ b/test/protocols/electrum/electrum_server.cpp @@ -19,7 +19,7 @@ #include "../../test.hpp" #include "electrum.hpp" -BOOST_FIXTURE_TEST_SUITE(electrum_tests, electrum_setup_fixture) +BOOST_FIXTURE_TEST_SUITE(electrum_tests, electrum_ten_block_setup_fixture) using namespace system; static const code wrong_version{ server::error::wrong_version }; @@ -150,7 +150,7 @@ BOOST_AUTO_TEST_CASE(electrum__server_features__default_hosts__expected) const auto min = version_to_string(protocol_electrum_version::minimum); const auto max = version_to_string(protocol_electrum_version::maximum); const auto server_name = config_.server.electrum.server_name; - const auto genesis_hash = encode_hash(genesis.hash()); + const auto genesis_hash = encode_hash(test::genesis.hash()); BOOST_REQUIRE_EQUAL(result.at("genesis_hash").as_string(), genesis_hash); BOOST_REQUIRE_EQUAL(result.at("hash_function").as_string(), "sha256"); BOOST_REQUIRE_EQUAL(result.at("server_version").as_string(), server_name); diff --git a/test/protocols/electrum/electrum_transactions.cpp b/test/protocols/electrum/electrum_transactions.cpp index 73e99fa2..d86064a3 100644 --- a/test/protocols/electrum/electrum_transactions.cpp +++ b/test/protocols/electrum/electrum_transactions.cpp @@ -21,7 +21,7 @@ #include "electrum.hpp" #include -BOOST_FIXTURE_TEST_SUITE(electrum_tests, electrum_setup_fixture) +BOOST_FIXTURE_TEST_SUITE(electrum_tests, electrum_ten_block_setup_fixture) // blockchain.transaction.broadcast @@ -65,7 +65,7 @@ BOOST_AUTO_TEST_CASE(electrum__blockchain_transaction_broadcast__genesis_coinbas { BOOST_REQUIRE(handshake(electrum::version::v1_0)); - const auto tx0_text = encode_base16(genesis.transactions_ptr()->front()->to_data(true)); + const auto tx0_text = encode_base16(test::genesis.transactions_ptr()->front()->to_data(true)); constexpr auto request = R"({"id":73,"method":"blockchain.transaction.broadcast","params":["%1%"]})" "\n"; const auto response = get((boost::format(request) % tx0_text).str()); REQUIRE_NO_THROW_TRUE(response.at("result").is_string()); @@ -76,7 +76,7 @@ BOOST_AUTO_TEST_CASE(electrum__blockchain_transaction_broadcast__genesis_coinbas { BOOST_REQUIRE(handshake(electrum::version::v1_6)); - const auto tx0_text = encode_base16(genesis.transactions_ptr()->front()->to_data(true)); + const auto tx0_text = encode_base16(test::genesis.transactions_ptr()->front()->to_data(true)); constexpr auto request = R"({"id":74,"method":"blockchain.transaction.broadcast","params":["%1%"]})" "\n"; const auto response = get((boost::format(request) % tx0_text).str()); REQUIRE_NO_THROW_TRUE(response.at("error").as_object().at("code").is_int64()); @@ -152,10 +152,10 @@ BOOST_AUTO_TEST_CASE(electrum__blockchain_transaction_broadcast_package__two_tra { BOOST_REQUIRE(handshake(electrum::version::v1_6)); - const auto tx0_text = encode_base16(genesis.transactions_ptr()->front()->to_data(true)); - const auto tx1_text = encode_base16(block1.transactions_ptr()->front()->to_data(true)); - const auto tx0_hash = encode_hash(genesis.transactions_ptr()->front()->hash(false)); - const auto tx1_hash = encode_hash(block1.transactions_ptr()->front()->hash(false)); + const auto tx0_text = encode_base16(test::genesis.transactions_ptr()->front()->to_data(true)); + const auto tx1_text = encode_base16(test::block1.transactions_ptr()->front()->to_data(true)); + const auto tx0_hash = encode_hash(test::genesis.transactions_ptr()->front()->hash(false)); + const auto tx1_hash = encode_hash(test::block1.transactions_ptr()->front()->hash(false)); constexpr auto request = R"({"id":73,"method":"blockchain.transaction.broadcast_package","params":[["%1%","%2%"]]})" "\n"; const auto response = get((boost::format(request) % tx0_text % tx1_text).str()); REQUIRE_NO_THROW_TRUE(response.at("result").is_object()); @@ -218,7 +218,7 @@ BOOST_AUTO_TEST_CASE(electrum__blockchain_transaction_get__missing_param__droppe { BOOST_REQUIRE(handshake(electrum::version::v1_0)); - const auto& coinbase = *genesis.transactions_ptr()->front(); + const auto& coinbase = *test::genesis.transactions_ptr()->front(); const auto tx0_hash = encode_hash(coinbase.hash(false)); const auto request = R"({"id":80,"method":"blockchain.transaction.get","params":["%1%"]})" "\n"; const auto response = get((boost::format(request) % tx0_hash).str()); @@ -229,7 +229,7 @@ BOOST_AUTO_TEST_CASE(electrum__blockchain_transaction_get__extra_param__dropped) { BOOST_REQUIRE(handshake(electrum::version::v1_0)); - const auto& coinbase = *genesis.transactions_ptr()->front(); + const auto& coinbase = *test::genesis.transactions_ptr()->front(); const auto tx0_hash = encode_hash(coinbase.hash(false)); const auto request = R"({"id":81,"method":"blockchain.transaction.get","params":["%1%",false,"extra"]})" "\n"; const auto response = get((boost::format(request) % tx0_hash).str()); @@ -240,7 +240,7 @@ BOOST_AUTO_TEST_CASE(electrum__blockchain_transaction_get__genesis_coinbase_verb { BOOST_REQUIRE(handshake(electrum::version::v1_0)); - const auto& coinbase = *genesis.transactions_ptr()->front(); + const auto& coinbase = *test::genesis.transactions_ptr()->front(); const auto tx0_hash = encode_hash(coinbase.hash(false)); const auto request = R"({"id":82,"method":"blockchain.transaction.get","params":["%1%",false]})" "\n"; const auto response = get((boost::format(request) % tx0_hash).str()); @@ -252,7 +252,7 @@ BOOST_AUTO_TEST_CASE(electrum__blockchain_transaction_get__version_1_1_verbose__ { BOOST_REQUIRE(handshake(electrum::version::v1_1)); - const auto& coinbase = *genesis.transactions_ptr()->front(); + const auto& coinbase = *test::genesis.transactions_ptr()->front(); const auto tx0_hash = encode_hash(coinbase.hash(false)); const auto request = R"({"id":83,"method":"blockchain.transaction.get","params":["%1%",true]})" "\n"; const auto response = get((boost::format(request) % tx0_hash).str()); @@ -264,7 +264,7 @@ BOOST_AUTO_TEST_CASE(electrum__blockchain_transaction_get__version_1_2_verbose__ { BOOST_REQUIRE(handshake(electrum::version::v1_2)); - const auto& coinbase = *genesis.transactions_ptr()->front(); + const auto& coinbase = *test::genesis.transactions_ptr()->front(); const auto tx0_hash = encode_hash(coinbase.hash(false)); const auto request = R"({"id":83,"method":"blockchain.transaction.get","params":["%1%",true]})" "\n"; const auto response = get((boost::format(request) % tx0_hash).str()); @@ -277,10 +277,10 @@ BOOST_AUTO_TEST_CASE(electrum__blockchain_transaction_get__version_1_2_verbose__ constexpr auto top = 9u; auto& tx = expected.as_object(); tx["in_active_chain"] = true; - tx["blockhash"] = encode_hash(genesis.hash()); + tx["blockhash"] = encode_hash(test::genesis.hash()); tx["confirmations"] = add1(top); - tx["blocktime"] = genesis.header().timestamp(); - tx["time"] = genesis.header().timestamp(); + tx["blocktime"] = test::genesis.header().timestamp(); + tx["time"] = test::genesis.header().timestamp(); BOOST_REQUIRE_EQUAL(response.at("result").as_object(), expected); } @@ -339,7 +339,7 @@ BOOST_AUTO_TEST_CASE(electrum__blockchain_transaction_get_merkle__genesis_coinba { BOOST_REQUIRE(handshake(electrum::version::v1_4)); - const auto& coinbase = *genesis.transactions_ptr()->front(); + const auto& coinbase = *test::genesis.transactions_ptr()->front(); const auto tx_hash = encode_hash(coinbase.hash(false)); const auto request = R"({"id":104,"method":"blockchain.transaction.get_merkle","params":["%1%",0]})" "\n"; const auto response = get((boost::format(request) % tx_hash).str()); @@ -358,7 +358,7 @@ BOOST_AUTO_TEST_CASE(electrum__blockchain_transaction_get_merkle__mutiple_txs_bl { BOOST_REQUIRE(handshake(electrum::version::v1_4)); - const auto& txs = *bogus_block10.transactions_ptr(); + const auto& txs = *test::bogus_block10.transactions_ptr(); const auto& tx0 = *txs.at(0); const auto& tx1 = *txs.at(1); const auto& tx2 = *txs.at(2); @@ -367,8 +367,8 @@ BOOST_AUTO_TEST_CASE(electrum__blockchain_transaction_get_merkle__mutiple_txs_bl const auto tx2_hash = tx2.hash(false); // Add a confirmed multi-tx block. - query_.set(bogus_block10, database::context{ 0, 10, 0 }, false, false); - query_.push_confirmed(query_.to_header(bogus_block10.hash()), false); + query_.set(test::bogus_block10, database::context{ 0, 10, 0 }, false, false); + query_.push_confirmed(query_.to_header(test::bogus_block10.hash()), false); const auto request = R"({"id":104,"method":"blockchain.transaction.get_merkle","params":["%1%",10]})" "\n"; const auto response = get((boost::format(request) % encode_hash(tx1_hash)).str()); @@ -392,7 +392,7 @@ BOOST_AUTO_TEST_CASE(electrum__blockchain_transaction_get_merkle__missing_param_ { BOOST_REQUIRE(handshake(electrum::version::v1_4)); - const auto& coinbase = *genesis.transactions_ptr()->front(); + const auto& coinbase = *test::genesis.transactions_ptr()->front(); const auto tx_hash = encode_hash(coinbase.hash(false)); const auto request = R"({"id":105,"method":"blockchain.transaction.get_merkle","params":["%1%"]})" "\n"; const auto response = get((boost::format(request) % tx_hash).str()); @@ -403,7 +403,7 @@ BOOST_AUTO_TEST_CASE(electrum__blockchain_transaction_get_merkle__extra_param__d { BOOST_REQUIRE(handshake(electrum::version::v1_4)); - const auto& coinbase = *genesis.transactions_ptr()->front(); + const auto& coinbase = *test::genesis.transactions_ptr()->front(); const auto tx_hash = encode_hash(coinbase.hash(false)); const auto request = R"({"id":106,"method":"blockchain.transaction.get_merkle","params":["%1%",0,"extra"]})" "\n"; const auto response = get((boost::format(request) % tx_hash).str()); @@ -425,7 +425,7 @@ BOOST_AUTO_TEST_CASE(electrum__blockchain_transaction_id_from_pos__genesis_coinb { BOOST_REQUIRE(handshake(electrum::version::v1_4)); - const auto& coinbase = *genesis.transactions_ptr()->front(); + const auto& coinbase = *test::genesis.transactions_ptr()->front(); const auto tx0_hash = encode_hash(coinbase.hash(false)); const auto response = get(R"({"id":90,"method":"blockchain.transaction.id_from_pos","params":[0,0]})" "\n"); REQUIRE_NO_THROW_TRUE(response.at("result").is_string()); @@ -436,7 +436,7 @@ BOOST_AUTO_TEST_CASE(electrum__blockchain_transaction_id_from_pos__coinbase_fals { BOOST_REQUIRE(handshake(electrum::version::v1_4)); - const auto& coinbase = *block2.transactions_ptr()->front(); + const auto& coinbase = *test::block2.transactions_ptr()->front(); const auto tx0_hash = encode_hash(coinbase.hash(false)); const auto response = get(R"({"id":91,"method":"blockchain.transaction.id_from_pos","params":[2,0,false]})" "\n"); REQUIRE_NO_THROW_TRUE(response.at("result").is_string()); @@ -447,7 +447,7 @@ BOOST_AUTO_TEST_CASE(electrum__blockchain_transaction_id_from_pos__merkle_proof_ { BOOST_REQUIRE(handshake(electrum::version::v1_4)); - const auto& coinbase = *block9.transactions_ptr()->front(); + const auto& coinbase = *test::block9.transactions_ptr()->front(); const auto tx0_hash = encode_hash(coinbase.hash(false)); const auto response = get(R"({"id":92,"method":"blockchain.transaction.id_from_pos","params":[9,0,true]})" "\n"); REQUIRE_NO_THROW_TRUE(response.at("result").is_object()); diff --git a/test/protocols/electrum/electrum_version.cpp b/test/protocols/electrum/electrum_version.cpp index 4ce993c2..87e9d9b1 100644 --- a/test/protocols/electrum/electrum_version.cpp +++ b/test/protocols/electrum/electrum_version.cpp @@ -19,7 +19,7 @@ #include "../../test.hpp" #include "electrum.hpp" -BOOST_FIXTURE_TEST_SUITE(electrum_tests, electrum_setup_fixture) +BOOST_FIXTURE_TEST_SUITE(electrum_tests, electrum_ten_block_setup_fixture) // server.version diff --git a/test/protocols/native/native.cpp b/test/protocols/native/native.cpp index e1447309..f80aeea2 100644 --- a/test/protocols/native/native.cpp +++ b/test/protocols/native/native.cpp @@ -21,8 +21,13 @@ #include "native.hpp" #include -native_setup_fixture::native_setup_fixture() - : config_{ system::chain::selection::mainnet, web_pages, web_pages }, +native_setup_fixture::native_setup_fixture(const initializer& setup) + : config_ + { + system::chain::selection::mainnet, + test::web_pages, + test::web_pages + }, store_ { [&]() NOEXCEPT -> const database::settings& @@ -48,11 +53,11 @@ native_setup_fixture::native_setup_fixture() node_settings.minimum_fee_rate = 99.0; network_settings.inbound.connections = 0; network_settings.outbound.connections = 0; - auto ec = store_.create([](auto, auto) {}); // Create and populate the store. + auto ec = store_.create([](auto, auto) {}); BOOST_REQUIRE_MESSAGE(!ec, ec.message()); - BOOST_REQUIRE_MESSAGE(setup_ten_block_store(query_), "native initialize"); + BOOST_REQUIRE_MESSAGE(setup(query_), "native initialize"); // Run the server. std::promise running{}; diff --git a/test/protocols/native/native.hpp b/test/protocols/native/native.hpp index 2c4bebcc..5ee83f7d 100644 --- a/test/protocols/native/native.hpp +++ b/test/protocols/native/native.hpp @@ -30,7 +30,8 @@ struct native_setup_fixture { DELETE_COPY_MOVE(native_setup_fixture); - native_setup_fixture(); + using initializer = std::function; + explicit native_setup_fixture(const initializer& setup); ~native_setup_fixture(); // native does not implement a handshake (url versioning). @@ -38,8 +39,8 @@ struct native_setup_fixture protected: configuration config_; - store_t store_; - query_t query_; + test::store_t store_; + test::query_t query_; private: network::logger log_; @@ -48,4 +49,16 @@ struct native_setup_fixture boost::asio::ip::tcp::socket socket_{ io }; }; +struct native_ten_block_setup_fixture + : native_setup_fixture +{ + inline native_ten_block_setup_fixture() + : native_setup_fixture([](test::query_t& query) + { + return test::setup_ten_block_store(query); + }) + { + } +}; + #endif diff --git a/test/protocols/native/native_address.cpp b/test/protocols/native/native_address.cpp index 514c7a3b..2ca17f9e 100644 --- a/test/protocols/native/native_address.cpp +++ b/test/protocols/native/native_address.cpp @@ -19,6 +19,6 @@ #include "../../test.hpp" #include "native.hpp" -BOOST_FIXTURE_TEST_SUITE(native_tests, native_setup_fixture) +BOOST_FIXTURE_TEST_SUITE(native_tests, native_ten_block_setup_fixture) BOOST_AUTO_TEST_SUITE_END() diff --git a/test/protocols/native/native_block.cpp b/test/protocols/native/native_block.cpp index 514c7a3b..2ca17f9e 100644 --- a/test/protocols/native/native_block.cpp +++ b/test/protocols/native/native_block.cpp @@ -19,6 +19,6 @@ #include "../../test.hpp" #include "native.hpp" -BOOST_FIXTURE_TEST_SUITE(native_tests, native_setup_fixture) +BOOST_FIXTURE_TEST_SUITE(native_tests, native_ten_block_setup_fixture) BOOST_AUTO_TEST_SUITE_END() diff --git a/test/protocols/native/native_configuration.cpp b/test/protocols/native/native_configuration.cpp index 514c7a3b..2ca17f9e 100644 --- a/test/protocols/native/native_configuration.cpp +++ b/test/protocols/native/native_configuration.cpp @@ -19,6 +19,6 @@ #include "../../test.hpp" #include "native.hpp" -BOOST_FIXTURE_TEST_SUITE(native_tests, native_setup_fixture) +BOOST_FIXTURE_TEST_SUITE(native_tests, native_ten_block_setup_fixture) BOOST_AUTO_TEST_SUITE_END() diff --git a/test/protocols/native/native_input.cpp b/test/protocols/native/native_input.cpp index 514c7a3b..2ca17f9e 100644 --- a/test/protocols/native/native_input.cpp +++ b/test/protocols/native/native_input.cpp @@ -19,6 +19,6 @@ #include "../../test.hpp" #include "native.hpp" -BOOST_FIXTURE_TEST_SUITE(native_tests, native_setup_fixture) +BOOST_FIXTURE_TEST_SUITE(native_tests, native_ten_block_setup_fixture) BOOST_AUTO_TEST_SUITE_END() diff --git a/test/protocols/native/native_output.cpp b/test/protocols/native/native_output.cpp index 514c7a3b..2ca17f9e 100644 --- a/test/protocols/native/native_output.cpp +++ b/test/protocols/native/native_output.cpp @@ -19,6 +19,6 @@ #include "../../test.hpp" #include "native.hpp" -BOOST_FIXTURE_TEST_SUITE(native_tests, native_setup_fixture) +BOOST_FIXTURE_TEST_SUITE(native_tests, native_ten_block_setup_fixture) BOOST_AUTO_TEST_SUITE_END() diff --git a/test/protocols/native/native_tx.cpp b/test/protocols/native/native_tx.cpp index 514c7a3b..2ca17f9e 100644 --- a/test/protocols/native/native_tx.cpp +++ b/test/protocols/native/native_tx.cpp @@ -19,6 +19,6 @@ #include "../../test.hpp" #include "native.hpp" -BOOST_FIXTURE_TEST_SUITE(native_tests, native_setup_fixture) +BOOST_FIXTURE_TEST_SUITE(native_tests, native_ten_block_setup_fixture) BOOST_AUTO_TEST_SUITE_END()