|
| 1 | +/** |
| 2 | + * Copyright (c) 2011-2026 libbitcoin developers (see AUTHORS) |
| 3 | + * |
| 4 | + * This file is part of libbitcoin. |
| 5 | + * |
| 6 | + * This program is free software: you can redistribute it and/or modify |
| 7 | + * it under the terms of the GNU Affero General Public License as published by |
| 8 | + * the Free Software Foundation, either version 3 of the License, or |
| 9 | + * (at your option) any later version. |
| 10 | + * |
| 11 | + * This program is distributed in the hope that it will be useful, |
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | + * GNU Affero General Public License for more details. |
| 15 | + * |
| 16 | + * You should have received a copy of the GNU Affero General Public License |
| 17 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 | + */ |
| 19 | +#include "../test.hpp" |
| 20 | + |
| 21 | +BOOST_AUTO_TEST_SUITE(block_tests) |
| 22 | + |
| 23 | +using namespace network::messages; |
| 24 | + |
| 25 | +// The message holds a block_view and serializes in the requested form. Genesis |
| 26 | +// is non-witness (witnessed and stripped forms are identical); the witnessed |
| 27 | +// strip is covered by the libbitcoin-system block_view to_data tests. |
| 28 | + |
| 29 | +BOOST_AUTO_TEST_CASE(block__serialize__witness__expected) |
| 30 | +{ |
| 31 | + const system::settings settings{ system::chain::selection::mainnet }; |
| 32 | + const node::messages::block instance |
| 33 | + { |
| 34 | + { settings.genesis_block.to_data(true), true } |
| 35 | + }; |
| 36 | + system::data_chunk buffer(instance.size(peer::level::canonical, true)); |
| 37 | + BOOST_REQUIRE(instance.serialize(peer::level::canonical, { buffer }, true)); |
| 38 | + BOOST_REQUIRE_EQUAL(buffer, settings.genesis_block.to_data(true)); |
| 39 | +} |
| 40 | + |
| 41 | +BOOST_AUTO_TEST_CASE(block__serialize__non_witness__expected) |
| 42 | +{ |
| 43 | + const system::settings settings{ system::chain::selection::mainnet }; |
| 44 | + const node::messages::block instance |
| 45 | + { |
| 46 | + { settings.genesis_block.to_data(true), false } |
| 47 | + }; |
| 48 | + system::data_chunk buffer(instance.size(peer::level::canonical, false)); |
| 49 | + BOOST_REQUIRE(instance.serialize(peer::level::canonical, { buffer }, false)); |
| 50 | + BOOST_REQUIRE_EQUAL(buffer, settings.genesis_block.to_data(false)); |
| 51 | +} |
| 52 | + |
| 53 | +BOOST_AUTO_TEST_CASE(block__serialize__short_buffer__false) |
| 54 | +{ |
| 55 | + const system::settings settings{ system::chain::selection::mainnet }; |
| 56 | + const node::messages::block instance |
| 57 | + { |
| 58 | + { settings.genesis_block.to_data(true), true } |
| 59 | + }; |
| 60 | + system::data_chunk buffer(sub1(instance.size(peer::level::canonical, true))); |
| 61 | + BOOST_REQUIRE(!instance.serialize(peer::level::canonical, { buffer }, true)); |
| 62 | +} |
| 63 | + |
| 64 | +BOOST_AUTO_TEST_SUITE_END() |
0 commit comments