diff --git a/src/ipc/libmultiprocess/src/mp/proxy.cpp b/src/ipc/libmultiprocess/src/mp/proxy.cpp index d24208dbfd89..a5224919adbd 100644 --- a/src/ipc/libmultiprocess/src/mp/proxy.cpp +++ b/src/ipc/libmultiprocess/src/mp/proxy.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -203,6 +204,9 @@ EventLoop::EventLoop(const char* exe_name, LogOptions log_opts, void* context) m_log_opts(std::move(log_opts)), m_context(context) { + // Ignore SIGPIPE so writes to a closed pipe/socket return EPIPE instead of + // terminating the process when the remote end disconnects unexpectedly. + std::signal(SIGPIPE, SIG_IGN); int fds[2]; KJ_SYSCALL(socketpair(AF_UNIX, SOCK_STREAM, 0, fds)); m_wait_fd = fds[0]; diff --git a/src/ipc/test/ipc_test.cpp b/src/ipc/test/ipc_test.cpp index 4ff854e9a21c..37f7cbff811b 100644 --- a/src/ipc/test/ipc_test.cpp +++ b/src/ipc/test/ipc_test.cpp @@ -23,7 +23,7 @@ #include #include -#include +#include static_assert(ipc::capnp::messages::MAX_MONEY == MAX_MONEY); static_assert(ipc::capnp::messages::MAX_DOUBLE == std::numeric_limits::max()); @@ -47,8 +47,8 @@ static std::string TempPath(std::string_view pattern) std::string temp{fs::PathToString(fs::path{fs::temp_directory_path()} / fs::PathFromString(std::string{pattern}))}; temp.push_back('\0'); int fd{mkstemp(temp.data())}; - BOOST_CHECK_GE(fd, 0); - BOOST_CHECK_EQUAL(close(fd), 0); + CHECK(fd >= 0); + CHECK(close(fd) == 0); temp.resize(temp.size() - 1); fs::remove(fs::PathFromString(temp)); return temp; @@ -87,17 +87,17 @@ void IpcPipeTest() std::unique_ptr> foo{foo_promise.get_future().get()}; // Test: make sure arguments were sent and return value is received - BOOST_CHECK_EQUAL(foo->add(1, 2), 3); + CHECK(foo->add(1, 2) == 3); COutPoint txout1{Txid::FromUint256(uint256{100}), 200}; COutPoint txout2{foo->passOutPoint(txout1)}; - BOOST_CHECK(txout1 == txout2); + CHECK(txout1 == txout2); UniValue uni1{UniValue::VOBJ}; uni1.pushKV("i", 1); uni1.pushKV("s", "two"); UniValue uni2{foo->passUniValue(uni1)}; - BOOST_CHECK_EQUAL(uni1.write(), uni2.write()); + CHECK(uni1.write() == uni2.write()); CMutableTransaction mtx; mtx.version = 2; @@ -106,15 +106,15 @@ void IpcPipeTest() mtx.vout.emplace_back(COIN, CScript()); CTransactionRef tx1{MakeTransactionRef(mtx)}; CTransactionRef tx2{foo->passTransaction(tx1)}; - BOOST_CHECK(*Assert(tx1) == *Assert(tx2)); + CHECK(*Assert(tx1) == *Assert(tx2)); std::vector vec1{'H', 'e', 'l', 'l', 'o'}; std::vector vec2{foo->passVectorChar(vec1)}; - BOOST_CHECK_EQUAL(std::string_view(vec1.begin(), vec1.end()), std::string_view(vec2.begin(), vec2.end())); + CHECK(std::string_view(vec1.begin(), vec1.end()) == std::string_view(vec2.begin(), vec2.end())); auto script1{CScript() << OP_11}; auto script2{foo->passScript(script1)}; - BOOST_CHECK_EQUAL(HexStr(script1), HexStr(script2)); + CHECK(HexStr(script1) == HexStr(script2)); // Test cleanup: disconnect and join thread foo.reset(); @@ -125,7 +125,7 @@ void IpcPipeTest() void IpcSocketPairTest() { int fds[2]; - BOOST_CHECK_EQUAL(socketpair(AF_UNIX, SOCK_STREAM, 0, fds), 0); + CHECK(socketpair(AF_UNIX, SOCK_STREAM, 0, fds) == 0); std::unique_ptr init{std::make_unique()}; std::unique_ptr protocol{ipc::capnp::MakeCapnpProtocol()}; std::promise promise; @@ -135,10 +135,10 @@ void IpcSocketPairTest() promise.get_future().wait(); std::unique_ptr remote_init{protocol->connect(fds[1], "test-connect")}; std::unique_ptr remote_echo{remote_init->makeEcho()}; - BOOST_CHECK_EQUAL(remote_echo->echo("echo test"), "echo test"); + CHECK(remote_echo->echo("echo test") == "echo test"); remote_echo.reset(); remote_init->stop(); - BOOST_CHECK(static_cast(init.get())->stop_called.load()); + CHECK(static_cast(init.get())->stop_called.load()); remote_init.reset(); thread.join(); } @@ -151,24 +151,24 @@ void IpcSocketTest(const fs::path& datadir) std::unique_ptr process{ipc::MakeProcess()}; std::string invalid_bind{"invalid:"}; - BOOST_CHECK_THROW(process->bind(datadir, "test_bitcoin", invalid_bind), std::invalid_argument); - BOOST_CHECK_THROW(process->connect(datadir, "test_bitcoin", invalid_bind), std::invalid_argument); + CHECK_THROWS_AS(process->bind(datadir, "test_bitcoin", invalid_bind), std::invalid_argument); + CHECK_THROWS_AS(process->connect(datadir, "test_bitcoin", invalid_bind), std::invalid_argument); auto bind_and_listen{[&](const std::string& bind_address) { std::string address{bind_address}; int serve_fd = process->bind(datadir, "test_bitcoin", address); - BOOST_CHECK_GE(serve_fd, 0); - BOOST_CHECK_EQUAL(address, bind_address); + CHECK(serve_fd >= 0); + CHECK(address == bind_address); protocol->listen(serve_fd, "test-serve", *init); }}; auto connect_and_test{[&](const std::string& connect_address) { std::string address{connect_address}; int connect_fd{process->connect(datadir, "test_bitcoin", address)}; - BOOST_CHECK_EQUAL(address, connect_address); + CHECK(address == connect_address); std::unique_ptr remote_init{protocol->connect(connect_fd, "test-connect")}; std::unique_ptr remote_echo{remote_init->makeEcho()}; - BOOST_CHECK_EQUAL(remote_echo->echo("echo test"), "echo test"); + CHECK(remote_echo->echo("echo test") == "echo test"); }}; // Need to specify explicit socket addresses outside the data directory, because the data diff --git a/src/ipc/test/ipc_tests.cpp b/src/ipc/test/ipc_tests.cpp index ebe4b397afa1..3f361cf461d1 100644 --- a/src/ipc/test/ipc_tests.cpp +++ b/src/ipc/test/ipc_tests.cpp @@ -7,10 +7,10 @@ #include #include -#include +#include -BOOST_FIXTURE_TEST_SUITE(ipc_tests, BasicTestingSetup) -BOOST_AUTO_TEST_CASE(ipc_tests) +TEST_SUITE_BEGIN("ipc_tests") +FIXTURE_TEST_CASE("ipc_tests", BasicTestingSetup) { IpcPipeTest(); IpcSocketPairTest(); @@ -18,18 +18,18 @@ BOOST_AUTO_TEST_CASE(ipc_tests) } // Test address parsing. -BOOST_AUTO_TEST_CASE(parse_address_test) +FIXTURE_TEST_CASE("parse_address_test", BasicTestingSetup) { std::unique_ptr process{ipc::MakeProcess()}; fs::path datadir{"/var/empty/notexist"}; auto check_notexist{[](const std::system_error& e) { return e.code() == std::errc::no_such_file_or_directory; }}; auto check_address{[&](std::string address, std::string expect_address, std::string expect_error) { if (expect_error.empty()) { - BOOST_CHECK_EXCEPTION(process->connect(datadir, "test_bitcoin", address), std::system_error, check_notexist); + CHECK_EXCEPTION(process->connect(datadir, "test_bitcoin", address), std::system_error, check_notexist); } else { - BOOST_CHECK_EXCEPTION(process->connect(datadir, "test_bitcoin", address), std::invalid_argument, HasReason(expect_error)); + CHECK_EXCEPTION(process->connect(datadir, "test_bitcoin", address), std::invalid_argument, HasReason(expect_error)); } - BOOST_CHECK_EQUAL(address, expect_address); + CHECK(address == expect_address); }}; check_address("unix", "unix:/var/empty/notexist/test_bitcoin.sock", ""); check_address("unix:", "unix:/var/empty/notexist/test_bitcoin.sock", ""); @@ -40,4 +40,4 @@ BOOST_AUTO_TEST_CASE(parse_address_test) check_address("invalid", "invalid", "Unrecognized address 'invalid'"); } -BOOST_AUTO_TEST_SUITE_END() +TEST_SUITE_END() diff --git a/src/test/CMakeLists.txt b/src/test/CMakeLists.txt index 666487b5fb3c..19e7e6aa8c50 100644 --- a/src/test/CMakeLists.txt +++ b/src/test/CMakeLists.txt @@ -160,22 +160,21 @@ target_link_libraries(test_bitcoin add_subdirectory(${PROJECT_SOURCE_DIR}/src/ipc/test ipc) -function(add_boost_test source_file) +function(register_test_suite source_file) if(NOT EXISTS ${source_file}) return() endif() file(READ "${source_file}" source_file_content) string(REGEX - MATCHALL "(BOOST_FIXTURE_TEST_SUITE|BOOST_AUTO_TEST_SUITE)\\(([A-Za-z0-9_]+)" + MATCHALL "TEST_SUITE_BEGIN\\(\"[A-Za-z0-9_]+\"" test_suite_macro "${source_file_content}" ) - list(TRANSFORM test_suite_macro - REPLACE "(BOOST_FIXTURE_TEST_SUITE|BOOST_AUTO_TEST_SUITE)\\(" "" - ) + list(TRANSFORM test_suite_macro REPLACE "^TEST_SUITE_BEGIN\\(\"" "") + list(TRANSFORM test_suite_macro REPLACE "\"$" "") foreach(test_suite_name IN LISTS test_suite_macro) add_test(NAME ${test_suite_name} - COMMAND test_bitcoin --run_test=${test_suite_name} --catch_system_error=no --log_level=test_suite -- -printtoconsole=1 + COMMAND test_bitcoin --run_test=${test_suite_name} -- -printtoconsole=1 ) set_property(TEST ${test_suite_name} PROPERTY SKIP_REGULAR_EXPRESSION @@ -194,7 +193,7 @@ function(add_all_test_targets) if(result) cmake_path(APPEND test_source_dir ${test_source} OUTPUT_VARIABLE test_source) endif() - add_boost_test(${test_source}) + register_test_suite(${test_source}) endforeach() endfunction() diff --git a/src/test/addrman_tests.cpp b/src/test/addrman_tests.cpp index cd1c651a08c2..aa964cc0d35e 100644 --- a/src/test/addrman_tests.cpp +++ b/src/test/addrman_tests.cpp @@ -16,7 +16,7 @@ #include #include -#include +#include #include #include @@ -37,42 +37,42 @@ static int32_t GetCheckRatio(const NodeContext& node_ctx) static CNetAddr ResolveIP(const std::string& ip) { const std::optional addr{LookupHost(ip, false)}; - BOOST_CHECK_MESSAGE(addr.has_value(), strprintf("failed to resolve: %s", ip)); + CHECK(addr.has_value(), strprintf("failed to resolve: %s", ip)); return addr.value_or(CNetAddr{}); } static CService ResolveService(const std::string& ip, uint16_t port = 0) { const std::optional serv{Lookup(ip, port, false)}; - BOOST_CHECK_MESSAGE(serv.has_value(), strprintf("failed to resolve: %s:%i", ip, port)); + CHECK(serv.has_value(), strprintf("failed to resolve: %s:%i", ip, port)); return serv.value_or(CService{}); } -BOOST_FIXTURE_TEST_SUITE(addrman_tests, BasicTestingSetup) +TEST_SUITE_BEGIN("addrman_tests") -BOOST_AUTO_TEST_CASE(addrman_simple) +FIXTURE_TEST_CASE("addrman_simple", BasicTestingSetup) { auto addrman = std::make_unique(EMPTY_NETGROUPMAN, DETERMINISTIC, GetCheckRatio(m_node)); CNetAddr source = ResolveIP("252.2.2.2"); // Test: Does Addrman respond correctly when empty. - BOOST_CHECK_EQUAL(addrman->Size(), 0U); + CHECK(addrman->Size() == 0U); auto addr_null = addrman->Select().first; - BOOST_CHECK_EQUAL(addr_null.ToStringAddrPort(), "[::]:0"); + CHECK(addr_null.ToStringAddrPort() == "[::]:0"); // Test: Does Addrman::Add work as expected. CService addr1 = ResolveService("250.1.1.1", 8333); - BOOST_CHECK(addrman->Add({CAddress(addr1, NODE_NONE)}, source)); - BOOST_CHECK_EQUAL(addrman->Size(), 1U); + CHECK(addrman->Add({CAddress(addr1, NODE_NONE)}, source)); + CHECK(addrman->Size() == 1U); auto addr_ret1 = addrman->Select().first; - BOOST_CHECK_EQUAL(addr_ret1.ToStringAddrPort(), "250.1.1.1:8333"); + CHECK(addr_ret1.ToStringAddrPort() == "250.1.1.1:8333"); // Test: Does IP address deduplication work correctly. // Expected dup IP should not be added. CService addr1_dup = ResolveService("250.1.1.1", 8333); - BOOST_CHECK(!addrman->Add({CAddress(addr1_dup, NODE_NONE)}, source)); - BOOST_CHECK_EQUAL(addrman->Size(), 1U); + CHECK(!addrman->Add({CAddress(addr1_dup, NODE_NONE)}, source)); + CHECK(addrman->Size() == 1U); // Test: New table has one addr and we add a diff addr we should @@ -82,20 +82,20 @@ BOOST_AUTO_TEST_CASE(addrman_simple) // success. CService addr2 = ResolveService("250.1.1.2", 8333); - BOOST_CHECK(addrman->Add({CAddress(addr2, NODE_NONE)}, source)); - BOOST_CHECK(addrman->Size() >= 1); + CHECK(addrman->Add({CAddress(addr2, NODE_NONE)}, source)); + CHECK(addrman->Size() >= 1U); // Test: reset addrman and test AddrMan::Add multiple addresses works as expected addrman = std::make_unique(EMPTY_NETGROUPMAN, DETERMINISTIC, GetCheckRatio(m_node)); std::vector vAddr; vAddr.emplace_back(ResolveService("250.1.1.3", 8333), NODE_NONE); vAddr.emplace_back(ResolveService("250.1.1.4", 8333), NODE_NONE); - BOOST_CHECK(addrman->Add(vAddr, source)); - BOOST_CHECK(addrman->Size() >= 1); + CHECK(addrman->Add(vAddr, source)); + CHECK(addrman->Size() >= 1U); } -BOOST_AUTO_TEST_CASE(addrman_terrible_many_failures) +FIXTURE_TEST_CASE("addrman_terrible_many_failures", BasicTestingSetup) { auto now = Now(); SetMockTime(now - (ADDRMAN_MIN_FAIL + 24h)); @@ -106,15 +106,15 @@ BOOST_AUTO_TEST_CASE(addrman_terrible_many_failures) CAddress addr{CAddress(ResolveService("250.250.2.1", 8333), NODE_NONE)}; addr.nTime = Now(); - BOOST_CHECK(addrman->Add({addr}, source)); - BOOST_CHECK(addrman->Good(addr)); + CHECK(addrman->Add({addr}, source)); + CHECK(addrman->Good(addr)); SetMockTime(now); CAddress addr_helper{CAddress(ResolveService("251.252.2.3", 8333), NODE_NONE)}; addr_helper.nTime = Now(); - BOOST_CHECK(addrman->Add({addr_helper}, source)); - BOOST_CHECK(addrman->Good(addr_helper)); + CHECK(addrman->Add({addr_helper}, source)); + CHECK(addrman->Good(addr_helper)); for (int i = 0; i < ADDRMAN_MAX_FAILURES; ++i) { // Use a time > 60s ago so IsTerrible doesn't bail out at the "tried in the last minute" check @@ -122,15 +122,15 @@ BOOST_AUTO_TEST_CASE(addrman_terrible_many_failures) } std::vector filtered{addrman->GetAddr(/*max_addresses=*/0, /*max_pct=*/0, /*network=*/std::nullopt)}; - BOOST_CHECK_EQUAL(filtered.size(), 1U); - BOOST_CHECK_EQUAL(filtered[0].ToStringAddrPort(), "251.252.2.3:8333"); + CHECK(filtered.size() == 1U); + CHECK(filtered[0].ToStringAddrPort() == "251.252.2.3:8333"); std::vector unfiltered{addrman->GetAddr(/*max_addresses=*/0, /*max_pct=*/0, /*network=*/std::nullopt, /*filtered=*/false)}; - BOOST_CHECK_EQUAL(unfiltered.size(), 2U); + CHECK(unfiltered.size() == 2U); } -BOOST_AUTO_TEST_CASE(addrman_penalty_self_announcement) +FIXTURE_TEST_CASE("addrman_penalty_self_announcement", BasicTestingSetup) { SetMockTime(Now()); auto addrman = std::make_unique(EMPTY_NETGROUPMAN, DETERMINISTIC, GetCheckRatio(m_node)); @@ -144,15 +144,15 @@ BOOST_AUTO_TEST_CASE(addrman_penalty_self_announcement) const auto time_penalty{3600s}; - BOOST_CHECK(addrman->Add({caddr1}, source1, time_penalty)); + CHECK(addrman->Add({caddr1}, source1, time_penalty)); auto addr_pos1{addrman->FindAddressEntry(caddr1)}; - BOOST_REQUIRE(addr_pos1.has_value()); + REQUIRE(addr_pos1.has_value()); std::vector addresses{addrman->GetAddr(/*max_addresses=*/0, /*max_pct=*/0, /*network=*/std::nullopt)}; - BOOST_REQUIRE_EQUAL(addresses.size(), 1U); + REQUIRE(addresses.size() == 1U); - BOOST_CHECK(addresses[0].nTime == base_time); + CHECK(addresses[0].nTime == base_time); CService addr2{ResolveService("250.1.1.2", 8333)}; CNetAddr source2{ResolveIP("250.1.1.3")}; // Different from addr2 - not self announcement @@ -160,150 +160,150 @@ BOOST_AUTO_TEST_CASE(addrman_penalty_self_announcement) CAddress caddr2(addr2, NODE_NONE); caddr2.nTime = base_time; - BOOST_CHECK(addrman->Add({caddr2}, source2, time_penalty)); + CHECK(addrman->Add({caddr2}, source2, time_penalty)); addresses = addrman->GetAddr(/*max_addresses=*/0, /*max_pct=*/0, /*network=*/std::nullopt); - BOOST_REQUIRE_EQUAL(addresses.size(), 2U); + REQUIRE(addresses.size() == 2U); CAddress retrieved_addr2{addresses[0]}; - BOOST_CHECK(retrieved_addr2.nTime == base_time - time_penalty); + CHECK(retrieved_addr2.nTime == base_time - time_penalty); } -BOOST_AUTO_TEST_CASE(addrman_ports) +FIXTURE_TEST_CASE("addrman_ports", BasicTestingSetup) { auto addrman = std::make_unique(EMPTY_NETGROUPMAN, DETERMINISTIC, GetCheckRatio(m_node)); CNetAddr source = ResolveIP("252.2.2.2"); - BOOST_CHECK_EQUAL(addrman->Size(), 0U); + CHECK(addrman->Size() == 0U); // Test 7; Addr with same IP but diff port does not replace existing addr. CService addr1 = ResolveService("250.1.1.1", 8333); - BOOST_CHECK(addrman->Add({CAddress(addr1, NODE_NONE)}, source)); - BOOST_CHECK_EQUAL(addrman->Size(), 1U); + CHECK(addrman->Add({CAddress(addr1, NODE_NONE)}, source)); + CHECK(addrman->Size() == 1U); CService addr1_port = ResolveService("250.1.1.1", 8334); - BOOST_CHECK(addrman->Add({CAddress(addr1_port, NODE_NONE)}, source)); - BOOST_CHECK_EQUAL(addrman->Size(), 2U); + CHECK(addrman->Add({CAddress(addr1_port, NODE_NONE)}, source)); + CHECK(addrman->Size() == 2U); auto addr_ret2 = addrman->Select().first; - BOOST_CHECK(addr_ret2.ToStringAddrPort() == "250.1.1.1:8333" || addr_ret2.ToStringAddrPort() == "250.1.1.1:8334"); + CHECK((addr_ret2.ToStringAddrPort() == "250.1.1.1:8333" || addr_ret2.ToStringAddrPort() == "250.1.1.1:8334")); // Test: Add same IP but diff port to tried table; this converts the entry with // the specified port to tried, but not the other. addrman->Good(CAddress(addr1_port, NODE_NONE)); - BOOST_CHECK_EQUAL(addrman->Size(), 2U); + CHECK(addrman->Size() == 2U); bool new_only = true; auto addr_ret3 = addrman->Select(new_only).first; - BOOST_CHECK_EQUAL(addr_ret3.ToStringAddrPort(), "250.1.1.1:8333"); + CHECK(addr_ret3.ToStringAddrPort() == "250.1.1.1:8333"); } -BOOST_AUTO_TEST_CASE(addrman_select) +FIXTURE_TEST_CASE("addrman_select", BasicTestingSetup) { auto addrman = std::make_unique(EMPTY_NETGROUPMAN, DETERMINISTIC, GetCheckRatio(m_node)); - BOOST_CHECK(!addrman->Select(false).first.IsValid()); - BOOST_CHECK(!addrman->Select(true).first.IsValid()); + CHECK(!addrman->Select(false).first.IsValid()); + CHECK(!addrman->Select(true).first.IsValid()); CNetAddr source = ResolveIP("252.2.2.2"); // Add 1 address to the new table CService addr1 = ResolveService("250.1.1.1", 8333); - BOOST_CHECK(addrman->Add({CAddress(addr1, NODE_NONE)}, source)); - BOOST_CHECK_EQUAL(addrman->Size(), 1U); + CHECK(addrman->Add({CAddress(addr1, NODE_NONE)}, source)); + CHECK(addrman->Size() == 1U); - BOOST_CHECK(addrman->Select(/*new_only=*/true).first == addr1); - BOOST_CHECK(addrman->Select(/*new_only=*/false).first == addr1); + CHECK(addrman->Select(/*new_only=*/true).first == addr1); + CHECK(addrman->Select(/*new_only=*/false).first == addr1); // Move address to the tried table - BOOST_CHECK(addrman->Good(CAddress(addr1, NODE_NONE))); + CHECK(addrman->Good(CAddress(addr1, NODE_NONE))); - BOOST_CHECK_EQUAL(addrman->Size(), 1U); - BOOST_CHECK(!addrman->Select(/*new_only=*/true).first.IsValid()); - BOOST_CHECK(addrman->Select().first == addr1); - BOOST_CHECK_EQUAL(addrman->Size(), 1U); + CHECK(addrman->Size() == 1U); + CHECK(!addrman->Select(/*new_only=*/true).first.IsValid()); + CHECK(addrman->Select().first == addr1); + CHECK(addrman->Size() == 1U); // Add one address to the new table CService addr2 = ResolveService("250.3.1.1", 8333); - BOOST_CHECK(addrman->Add({CAddress(addr2, NODE_NONE)}, addr2)); - BOOST_CHECK(addrman->Select(/*new_only=*/true).first == addr2); + CHECK(addrman->Add({CAddress(addr2, NODE_NONE)}, addr2)); + CHECK(addrman->Select(/*new_only=*/true).first == addr2); // Add two more addresses to the new table CService addr3 = ResolveService("250.3.2.2", 9999); CService addr4 = ResolveService("250.3.3.3", 9999); - BOOST_CHECK(addrman->Add({CAddress(addr3, NODE_NONE)}, addr2)); - BOOST_CHECK(addrman->Add({CAddress(addr4, NODE_NONE)}, ResolveService("250.4.1.1", 8333))); + CHECK(addrman->Add({CAddress(addr3, NODE_NONE)}, addr2)); + CHECK(addrman->Add({CAddress(addr4, NODE_NONE)}, ResolveService("250.4.1.1", 8333))); // Add three addresses to tried table. CService addr5 = ResolveService("250.4.4.4", 8333); CService addr6 = ResolveService("250.4.5.5", 7777); CService addr7 = ResolveService("250.4.6.6", 8333); - BOOST_CHECK(addrman->Add({CAddress(addr5, NODE_NONE)}, addr3)); - BOOST_CHECK(addrman->Good(CAddress(addr5, NODE_NONE))); - BOOST_CHECK(addrman->Add({CAddress(addr6, NODE_NONE)}, addr3)); - BOOST_CHECK(addrman->Good(CAddress(addr6, NODE_NONE))); - BOOST_CHECK(addrman->Add({CAddress(addr7, NODE_NONE)}, ResolveService("250.1.1.3", 8333))); - BOOST_CHECK(addrman->Good(CAddress(addr7, NODE_NONE))); + CHECK(addrman->Add({CAddress(addr5, NODE_NONE)}, addr3)); + CHECK(addrman->Good(CAddress(addr5, NODE_NONE))); + CHECK(addrman->Add({CAddress(addr6, NODE_NONE)}, addr3)); + CHECK(addrman->Good(CAddress(addr6, NODE_NONE))); + CHECK(addrman->Add({CAddress(addr7, NODE_NONE)}, ResolveService("250.1.1.3", 8333))); + CHECK(addrman->Good(CAddress(addr7, NODE_NONE))); // 6 addrs + 1 addr from last test = 7. - BOOST_CHECK_EQUAL(addrman->Size(), 7U); + CHECK(addrman->Size() == 7U); // Select pulls from new and tried regardless of port number. std::set ports; for (int i = 0; i < 20; ++i) { ports.insert(addrman->Select().first.GetPort()); } - BOOST_CHECK_EQUAL(ports.size(), 3U); + CHECK(ports.size() == 3U); } -BOOST_AUTO_TEST_CASE(addrman_select_by_network) +FIXTURE_TEST_CASE("addrman_select_by_network", BasicTestingSetup) { auto addrman = std::make_unique(EMPTY_NETGROUPMAN, DETERMINISTIC, GetCheckRatio(m_node)); - BOOST_CHECK(!addrman->Select(/*new_only=*/true, {NET_IPV4}).first.IsValid()); - BOOST_CHECK(!addrman->Select(/*new_only=*/false, {NET_IPV4}).first.IsValid()); + CHECK(!addrman->Select(/*new_only=*/true, {NET_IPV4}).first.IsValid()); + CHECK(!addrman->Select(/*new_only=*/false, {NET_IPV4}).first.IsValid()); // add ipv4 address to the new table CNetAddr source = ResolveIP("252.2.2.2"); CService addr1 = ResolveService("250.1.1.1", 8333); - BOOST_CHECK(addrman->Add({CAddress(addr1, NODE_NONE)}, source)); + CHECK(addrman->Add({CAddress(addr1, NODE_NONE)}, source)); - BOOST_CHECK(addrman->Select(/*new_only=*/true, {NET_IPV4}).first == addr1); - BOOST_CHECK(addrman->Select(/*new_only=*/false, {NET_IPV4}).first == addr1); - BOOST_CHECK(!addrman->Select(/*new_only=*/false, {NET_IPV6}).first.IsValid()); - BOOST_CHECK(!addrman->Select(/*new_only=*/false, {NET_ONION}).first.IsValid()); - BOOST_CHECK(!addrman->Select(/*new_only=*/false, {NET_I2P}).first.IsValid()); - BOOST_CHECK(!addrman->Select(/*new_only=*/false, {NET_CJDNS}).first.IsValid()); - BOOST_CHECK(!addrman->Select(/*new_only=*/true, {NET_CJDNS}).first.IsValid()); - BOOST_CHECK(addrman->Select(/*new_only=*/false).first == addr1); + CHECK(addrman->Select(/*new_only=*/true, {NET_IPV4}).first == addr1); + CHECK(addrman->Select(/*new_only=*/false, {NET_IPV4}).first == addr1); + CHECK(!addrman->Select(/*new_only=*/false, {NET_IPV6}).first.IsValid()); + CHECK(!addrman->Select(/*new_only=*/false, {NET_ONION}).first.IsValid()); + CHECK(!addrman->Select(/*new_only=*/false, {NET_I2P}).first.IsValid()); + CHECK(!addrman->Select(/*new_only=*/false, {NET_CJDNS}).first.IsValid()); + CHECK(!addrman->Select(/*new_only=*/true, {NET_CJDNS}).first.IsValid()); + CHECK(addrman->Select(/*new_only=*/false).first == addr1); // add I2P address to the new table CAddress i2p_addr; i2p_addr.SetSpecial("udhdrtrcetjm5sxzskjyr5ztpeszydbh4dpl3pl4utgqqw2v4jna.b32.i2p"); - BOOST_CHECK(addrman->Add({i2p_addr}, source)); + CHECK(addrman->Add({i2p_addr}, source)); - BOOST_CHECK(addrman->Select(/*new_only=*/true, {NET_I2P}).first == i2p_addr); - BOOST_CHECK(addrman->Select(/*new_only=*/false, {NET_I2P}).first == i2p_addr); - BOOST_CHECK(addrman->Select(/*new_only=*/false, {NET_IPV4}).first == addr1); + CHECK(addrman->Select(/*new_only=*/true, {NET_I2P}).first == i2p_addr); + CHECK(addrman->Select(/*new_only=*/false, {NET_I2P}).first == i2p_addr); + CHECK(addrman->Select(/*new_only=*/false, {NET_IPV4}).first == addr1); std::unordered_set nets_with_entries = {NET_IPV4, NET_I2P}; - BOOST_CHECK(addrman->Select(/*new_only=*/false, nets_with_entries).first.IsValid()); - BOOST_CHECK(!addrman->Select(/*new_only=*/false, {NET_IPV6}).first.IsValid()); - BOOST_CHECK(!addrman->Select(/*new_only=*/false, {NET_ONION}).first.IsValid()); - BOOST_CHECK(!addrman->Select(/*new_only=*/false, {NET_CJDNS}).first.IsValid()); + CHECK(addrman->Select(/*new_only=*/false, nets_with_entries).first.IsValid()); + CHECK(!addrman->Select(/*new_only=*/false, {NET_IPV6}).first.IsValid()); + CHECK(!addrman->Select(/*new_only=*/false, {NET_ONION}).first.IsValid()); + CHECK(!addrman->Select(/*new_only=*/false, {NET_CJDNS}).first.IsValid()); std::unordered_set nets_without_entries = {NET_IPV6, NET_ONION, NET_CJDNS}; - BOOST_CHECK(!addrman->Select(/*new_only=*/false, nets_without_entries).first.IsValid()); + CHECK(!addrman->Select(/*new_only=*/false, nets_without_entries).first.IsValid()); // bump I2P address to tried table - BOOST_CHECK(addrman->Good(i2p_addr)); + CHECK(addrman->Good(i2p_addr)); - BOOST_CHECK(!addrman->Select(/*new_only=*/true, {NET_I2P}).first.IsValid()); - BOOST_CHECK(addrman->Select(/*new_only=*/false, {NET_I2P}).first == i2p_addr); + CHECK(!addrman->Select(/*new_only=*/true, {NET_I2P}).first.IsValid()); + CHECK(addrman->Select(/*new_only=*/false, {NET_I2P}).first == i2p_addr); // add another I2P address to the new table CAddress i2p_addr2; i2p_addr2.SetSpecial("c4gfnttsuwqomiygupdqqqyy5y5emnk5c73hrfvatri67prd7vyq.b32.i2p"); - BOOST_CHECK(addrman->Add({i2p_addr2}, source)); + CHECK(addrman->Add({i2p_addr2}, source)); - BOOST_CHECK(addrman->Select(/*new_only=*/true, {NET_I2P}).first == i2p_addr2); + CHECK(addrman->Select(/*new_only=*/true, {NET_I2P}).first == i2p_addr2); // ensure that both new and tried table are selected from bool new_selected{false}; @@ -312,7 +312,7 @@ BOOST_AUTO_TEST_CASE(addrman_select_by_network) while (--counter > 0 && (!new_selected || !tried_selected)) { const CAddress selected{addrman->Select(/*new_only=*/false, {NET_I2P}).first}; - BOOST_REQUIRE(selected == i2p_addr || selected == i2p_addr2); + REQUIRE((selected == i2p_addr || selected == i2p_addr2)); if (selected == i2p_addr) { tried_selected = true; } else { @@ -320,11 +320,11 @@ BOOST_AUTO_TEST_CASE(addrman_select_by_network) } } - BOOST_CHECK(new_selected); - BOOST_CHECK(tried_selected); + CHECK(new_selected); + CHECK(tried_selected); } -BOOST_AUTO_TEST_CASE(addrman_select_special) +FIXTURE_TEST_CASE("addrman_select_special", BasicTestingSetup) { // use a non-deterministic addrman to ensure a passing test isn't due to setup auto addrman = std::make_unique(EMPTY_NETGROUPMAN, /*deterministic=*/false, GetCheckRatio(m_node)); @@ -334,20 +334,20 @@ BOOST_AUTO_TEST_CASE(addrman_select_special) // add I2P address to the tried table CAddress i2p_addr; i2p_addr.SetSpecial("udhdrtrcetjm5sxzskjyr5ztpeszydbh4dpl3pl4utgqqw2v4jna.b32.i2p"); - BOOST_CHECK(addrman->Add({i2p_addr}, source)); - BOOST_CHECK(addrman->Good(i2p_addr)); + CHECK(addrman->Add({i2p_addr}, source)); + CHECK(addrman->Good(i2p_addr)); // add ipv4 address to the new table CService addr1 = ResolveService("250.1.1.3", 8333); - BOOST_CHECK(addrman->Add({CAddress(addr1, NODE_NONE)}, source)); + CHECK(addrman->Add({CAddress(addr1, NODE_NONE)}, source)); // since the only ipv4 address is on the new table, ensure that the new // table gets selected even if new_only is false. if the table was being // selected at random, this test will sporadically fail - BOOST_CHECK(addrman->Select(/*new_only=*/false, {NET_IPV4}).first == addr1); + CHECK(addrman->Select(/*new_only=*/false, {NET_IPV4}).first == addr1); } -BOOST_AUTO_TEST_CASE(addrman_new_collisions) +FIXTURE_TEST_CASE("addrman_new_collisions", BasicTestingSetup) { auto addrman = std::make_unique(EMPTY_NETGROUPMAN, DETERMINISTIC, GetCheckRatio(m_node)); @@ -355,28 +355,28 @@ BOOST_AUTO_TEST_CASE(addrman_new_collisions) uint32_t num_addrs{0}; - BOOST_CHECK_EQUAL(addrman->Size(), num_addrs); + CHECK(addrman->Size() == num_addrs); while (num_addrs < 22) { // Magic number! 250.1.1.1 - 250.1.1.22 do not collide with deterministic key = 1 CService addr = ResolveService("250.1.1." + ToString(++num_addrs)); - BOOST_CHECK(addrman->Add({CAddress(addr, NODE_NONE)}, source)); + CHECK(addrman->Add({CAddress(addr, NODE_NONE)}, source)); // Test: No collision in new table yet. - BOOST_CHECK_EQUAL(addrman->Size(), num_addrs); + CHECK(addrman->Size() == num_addrs); } // Test: new table collision! CService addr1 = ResolveService("250.1.1." + ToString(++num_addrs)); uint32_t collisions{1}; - BOOST_CHECK(addrman->Add({CAddress(addr1, NODE_NONE)}, source)); - BOOST_CHECK_EQUAL(addrman->Size(), num_addrs - collisions); + CHECK(addrman->Add({CAddress(addr1, NODE_NONE)}, source)); + CHECK(addrman->Size() == num_addrs - collisions); CService addr2 = ResolveService("250.1.1." + ToString(++num_addrs)); - BOOST_CHECK(addrman->Add({CAddress(addr2, NODE_NONE)}, source)); - BOOST_CHECK_EQUAL(addrman->Size(), num_addrs - collisions); + CHECK(addrman->Add({CAddress(addr2, NODE_NONE)}, source)); + CHECK(addrman->Size() == num_addrs - collisions); } -BOOST_AUTO_TEST_CASE(addrman_new_multiplicity) +FIXTURE_TEST_CASE("addrman_new_multiplicity", BasicTestingSetup) { auto addrman = std::make_unique(EMPTY_NETGROUPMAN, DETERMINISTIC, GetCheckRatio(m_node)); CAddress addr{CAddress(ResolveService("253.3.3.3", 8333), NODE_NONE)}; @@ -390,8 +390,8 @@ BOOST_AUTO_TEST_CASE(addrman_new_multiplicity) addrman->Add({addr}, source); } AddressPosition addr_pos = addrman->FindAddressEntry(addr).value(); - BOOST_CHECK_EQUAL(addr_pos.multiplicity, 1U); - BOOST_CHECK_EQUAL(addrman->Size(), 1U); + CHECK(addr_pos.multiplicity == 1); + CHECK(addrman->Size() == 1U); // if nTime increases, an addr can occur in up to 8 buckets // The acceptance probability decreases exponentially with existing multiplicity - @@ -403,12 +403,12 @@ BOOST_AUTO_TEST_CASE(addrman_new_multiplicity) addrman->Add({addr}, source); } AddressPosition addr_pos_multi = addrman->FindAddressEntry(addr).value(); - BOOST_CHECK_EQUAL(addr_pos_multi.multiplicity, 8U); + CHECK(addr_pos_multi.multiplicity == 8); // multiplicity doesn't affect size - BOOST_CHECK_EQUAL(addrman->Size(), 1U); + CHECK(addrman->Size() == 1U); } -BOOST_AUTO_TEST_CASE(addrman_tried_collisions) +FIXTURE_TEST_CASE("addrman_tried_collisions", BasicTestingSetup) { auto addrman = std::make_unique(EMPTY_NETGROUPMAN, DETERMINISTIC, GetCheckRatio(m_node)); @@ -416,38 +416,38 @@ BOOST_AUTO_TEST_CASE(addrman_tried_collisions) uint32_t num_addrs{0}; - BOOST_CHECK_EQUAL(addrman->Size(), num_addrs); + CHECK(addrman->Size() == num_addrs); while (num_addrs < 35) { // Magic number! 250.1.1.1 - 250.1.1.35 do not collide in tried with deterministic key = 1 CService addr = ResolveService("250.1.1." + ToString(++num_addrs)); - BOOST_CHECK(addrman->Add({CAddress(addr, NODE_NONE)}, source)); + CHECK(addrman->Add({CAddress(addr, NODE_NONE)}, source)); // Test: Add to tried without collision - BOOST_CHECK(addrman->Good(CAddress(addr, NODE_NONE))); + CHECK(addrman->Good(CAddress(addr, NODE_NONE))); } // Test: Unable to add to tried table due to collision! CService addr1 = ResolveService("250.1.1." + ToString(++num_addrs)); - BOOST_CHECK(addrman->Add({CAddress(addr1, NODE_NONE)}, source)); - BOOST_CHECK(!addrman->Good(CAddress(addr1, NODE_NONE))); + CHECK(addrman->Add({CAddress(addr1, NODE_NONE)}, source)); + CHECK(!addrman->Good(CAddress(addr1, NODE_NONE))); // Test: Add the next address to tried without collision CService addr2 = ResolveService("250.1.1." + ToString(++num_addrs)); - BOOST_CHECK(addrman->Add({CAddress(addr2, NODE_NONE)}, source)); - BOOST_CHECK(addrman->Good(CAddress(addr2, NODE_NONE))); + CHECK(addrman->Add({CAddress(addr2, NODE_NONE)}, source)); + CHECK(addrman->Good(CAddress(addr2, NODE_NONE))); } -BOOST_AUTO_TEST_CASE(addrman_getaddr) +FIXTURE_TEST_CASE("addrman_getaddr", BasicTestingSetup) { auto addrman = std::make_unique(EMPTY_NETGROUPMAN, DETERMINISTIC, GetCheckRatio(m_node)); // Test: Sanity check, GetAddr should never return anything if addrman // is empty. - BOOST_CHECK_EQUAL(addrman->Size(), 0U); + CHECK(addrman->Size() == 0U); std::vector vAddr1 = addrman->GetAddr(/*max_addresses=*/0, /*max_pct=*/0, /*network=*/std::nullopt); - BOOST_CHECK_EQUAL(vAddr1.size(), 0U); + CHECK(vAddr1.size() == 0U); CAddress addr1 = CAddress(ResolveService("250.250.2.1", 8333), NODE_NONE); addr1.nTime = Now(); // Set time so isTerrible = false @@ -463,18 +463,18 @@ BOOST_AUTO_TEST_CASE(addrman_getaddr) CNetAddr source2 = ResolveIP("250.2.3.3"); // Test: Ensure GetAddr works with new addresses. - BOOST_CHECK(addrman->Add({addr1, addr3, addr5}, source1)); - BOOST_CHECK(addrman->Add({addr2, addr4}, source2)); + CHECK(addrman->Add({addr1, addr3, addr5}, source1)); + CHECK(addrman->Add({addr2, addr4}, source2)); - BOOST_CHECK_EQUAL(addrman->GetAddr(/*max_addresses=*/0, /*max_pct=*/0, /*network=*/std::nullopt).size(), 5U); + CHECK(addrman->GetAddr(/*max_addresses=*/0, /*max_pct=*/0, /*network=*/std::nullopt).size() == 5U); // Net processing asks for 23% of addresses. 23% of 5 is 1 rounded down. - BOOST_CHECK_EQUAL(addrman->GetAddr(/*max_addresses=*/2500, /*max_pct=*/23, /*network=*/std::nullopt).size(), 1U); + CHECK(addrman->GetAddr(/*max_addresses=*/2500, /*max_pct=*/23, /*network=*/std::nullopt).size() == 1U); // Test: Ensure GetAddr works with new and tried addresses. - BOOST_CHECK(addrman->Good(CAddress(addr1, NODE_NONE))); - BOOST_CHECK(addrman->Good(CAddress(addr2, NODE_NONE))); - BOOST_CHECK_EQUAL(addrman->GetAddr(/*max_addresses=*/0, /*max_pct=*/0, /*network=*/std::nullopt).size(), 5U); - BOOST_CHECK_EQUAL(addrman->GetAddr(/*max_addresses=*/2500, /*max_pct=*/23, /*network=*/std::nullopt).size(), 1U); + CHECK(addrman->Good(CAddress(addr1, NODE_NONE))); + CHECK(addrman->Good(CAddress(addr2, NODE_NONE))); + CHECK(addrman->GetAddr(/*max_addresses=*/0, /*max_pct=*/0, /*network=*/std::nullopt).size() == 5U); + CHECK(addrman->GetAddr(/*max_addresses=*/2500, /*max_pct=*/23, /*network=*/std::nullopt).size() == 1U); // Test: Ensure GetAddr still returns 23% when addrman has many addrs. for (unsigned int i = 1; i < (8 * 256); i++) { @@ -492,13 +492,13 @@ BOOST_AUTO_TEST_CASE(addrman_getaddr) std::vector vAddr = addrman->GetAddr(/*max_addresses=*/2500, /*max_pct=*/23, /*network=*/std::nullopt); size_t percent23 = (addrman->Size() * 23) / 100; - BOOST_CHECK_EQUAL(vAddr.size(), percent23); - BOOST_CHECK_EQUAL(vAddr.size(), 461U); + CHECK(vAddr.size() == percent23); + CHECK(vAddr.size() == 461U); // (addrman.Size() < number of addresses added) due to address collisions. - BOOST_CHECK_EQUAL(addrman->Size(), 2006U); + CHECK(addrman->Size() == 2006U); } -BOOST_AUTO_TEST_CASE(getaddr_unfiltered) +FIXTURE_TEST_CASE("getaddr_unfiltered", BasicTestingSetup) { auto addrman = std::make_unique(EMPTY_NETGROUPMAN, DETERMINISTIC, GetCheckRatio(m_node)); @@ -509,13 +509,13 @@ BOOST_AUTO_TEST_CASE(getaddr_unfiltered) CAddress addr2 = CAddress(ResolveService("250.251.2.2", 9999), NODE_NONE); CNetAddr source = ResolveIP("250.1.2.1"); - BOOST_CHECK(addrman->Add({addr1, addr2}, source)); + CHECK(addrman->Add({addr1, addr2}, source)); // Set time on this addr so isTerrible = false CAddress addr3 = CAddress(ResolveService("250.251.2.3", 9998), NODE_NONE); addr3.nTime = Now(); addrman->Good(addr3, /*time=*/Now()); - BOOST_CHECK(addrman->Add({addr3}, source)); + CHECK(addrman->Add({addr3}, source)); // The time is set, but after ADDRMAN_RETRIES unsuccessful attempts not // retried in the last minute, this addr should be isTerrible = true for (size_t i = 0; i < 3; ++i) { @@ -526,15 +526,15 @@ BOOST_AUTO_TEST_CASE(getaddr_unfiltered) // addr should be isTerrible = true CAddress addr4 = CAddress(ResolveService("250.252.2.4", 9997), NODE_NONE); addr4.nTime = Now() + 11min; - BOOST_CHECK(addrman->Add({addr4}, source)); + CHECK(addrman->Add({addr4}, source)); // GetAddr filtered by quality (i.e. not IsTerrible) should only return addr1 - BOOST_CHECK_EQUAL(addrman->GetAddr(/*max_addresses=*/0, /*max_pct=*/0, /*network=*/std::nullopt).size(), 1U); + CHECK(addrman->GetAddr(/*max_addresses=*/0, /*max_pct=*/0, /*network=*/std::nullopt).size() == 1U); // Unfiltered GetAddr should return all addrs - BOOST_CHECK_EQUAL(addrman->GetAddr(/*max_addresses=*/0, /*max_pct=*/0, /*network=*/std::nullopt, /*filtered=*/false).size(), 4U); + CHECK(addrman->GetAddr(/*max_addresses=*/0, /*max_pct=*/0, /*network=*/std::nullopt, /*filtered=*/false).size() == 4U); } -BOOST_AUTO_TEST_CASE(caddrinfo_get_tried_bucket_legacy) +FIXTURE_TEST_CASE("caddrinfo_get_tried_bucket_legacy", BasicTestingSetup) { CAddress addr1 = CAddress(ResolveService("250.1.1.1", 8333), NODE_NONE); CAddress addr2 = CAddress(ResolveService("250.1.1.1", 9999), NODE_NONE); @@ -547,18 +547,18 @@ BOOST_AUTO_TEST_CASE(caddrinfo_get_tried_bucket_legacy) uint256 nKey1 = (HashWriter{} << 1).GetHash(); uint256 nKey2 = (HashWriter{} << 2).GetHash(); - BOOST_CHECK_EQUAL(info1.GetTriedBucket(nKey1, EMPTY_NETGROUPMAN), 40); + CHECK(info1.GetTriedBucket(nKey1, EMPTY_NETGROUPMAN) == 40); // Test: Make sure key actually randomizes bucket placement. A fail on // this test could be a security issue. - BOOST_CHECK(info1.GetTriedBucket(nKey1, EMPTY_NETGROUPMAN) != info1.GetTriedBucket(nKey2, EMPTY_NETGROUPMAN)); + CHECK(info1.GetTriedBucket(nKey1, EMPTY_NETGROUPMAN) != info1.GetTriedBucket(nKey2, EMPTY_NETGROUPMAN)); // Test: Two addresses with same IP but different ports can map to // different buckets because they have different keys. AddrInfo info2 = AddrInfo(addr2, source1); - BOOST_CHECK(info1.GetKey() != info2.GetKey()); - BOOST_CHECK(info1.GetTriedBucket(nKey1, EMPTY_NETGROUPMAN) != info2.GetTriedBucket(nKey1, EMPTY_NETGROUPMAN)); + CHECK(info1.GetKey() != info2.GetKey()); + CHECK(info1.GetTriedBucket(nKey1, EMPTY_NETGROUPMAN) != info2.GetTriedBucket(nKey1, EMPTY_NETGROUPMAN)); std::set buckets; for (int i = 0; i < 255; i++) { @@ -570,7 +570,7 @@ BOOST_AUTO_TEST_CASE(caddrinfo_get_tried_bucket_legacy) } // Test: IP addresses in the same /16 prefix should // never get more than 8 buckets with legacy grouping - BOOST_CHECK_EQUAL(buckets.size(), 8U); + CHECK(buckets.size() == 8U); buckets.clear(); for (int j = 0; j < 255; j++) { @@ -582,10 +582,10 @@ BOOST_AUTO_TEST_CASE(caddrinfo_get_tried_bucket_legacy) } // Test: IP addresses in the different /16 prefix should map to more than // 8 buckets with legacy grouping - BOOST_CHECK_EQUAL(buckets.size(), 160U); + CHECK(buckets.size() == 160U); } -BOOST_AUTO_TEST_CASE(caddrinfo_get_new_bucket_legacy) +FIXTURE_TEST_CASE("caddrinfo_get_new_bucket_legacy", BasicTestingSetup) { CAddress addr1 = CAddress(ResolveService("250.1.2.1", 8333), NODE_NONE); CAddress addr2 = CAddress(ResolveService("250.1.2.1", 9999), NODE_NONE); @@ -598,17 +598,17 @@ BOOST_AUTO_TEST_CASE(caddrinfo_get_new_bucket_legacy) uint256 nKey2 = (HashWriter{} << 2).GetHash(); // Test: Make sure the buckets are what we expect - BOOST_CHECK_EQUAL(info1.GetNewBucket(nKey1, EMPTY_NETGROUPMAN), 786); - BOOST_CHECK_EQUAL(info1.GetNewBucket(nKey1, source1, EMPTY_NETGROUPMAN), 786); + CHECK(info1.GetNewBucket(nKey1, EMPTY_NETGROUPMAN) == 786); + CHECK(info1.GetNewBucket(nKey1, source1, EMPTY_NETGROUPMAN) == 786); // Test: Make sure key actually randomizes bucket placement. A fail on // this test could be a security issue. - BOOST_CHECK(info1.GetNewBucket(nKey1, EMPTY_NETGROUPMAN) != info1.GetNewBucket(nKey2, EMPTY_NETGROUPMAN)); + CHECK(info1.GetNewBucket(nKey1, EMPTY_NETGROUPMAN) != info1.GetNewBucket(nKey2, EMPTY_NETGROUPMAN)); // Test: Ports should not affect bucket placement in the addr AddrInfo info2 = AddrInfo(addr2, source1); - BOOST_CHECK(info1.GetKey() != info2.GetKey()); - BOOST_CHECK_EQUAL(info1.GetNewBucket(nKey1, EMPTY_NETGROUPMAN), info2.GetNewBucket(nKey1, EMPTY_NETGROUPMAN)); + CHECK(info1.GetKey() != info2.GetKey()); + CHECK(info1.GetNewBucket(nKey1, EMPTY_NETGROUPMAN) == info2.GetNewBucket(nKey1, EMPTY_NETGROUPMAN)); std::set buckets; for (int i = 0; i < 255; i++) { @@ -620,7 +620,7 @@ BOOST_AUTO_TEST_CASE(caddrinfo_get_new_bucket_legacy) } // Test: IP addresses in the same group (\16 prefix for IPv4) should // always map to the same bucket. - BOOST_CHECK_EQUAL(buckets.size(), 1U); + CHECK(buckets.size() == 1U); buckets.clear(); for (int j = 0; j < 4 * 255; j++) { @@ -633,7 +633,7 @@ BOOST_AUTO_TEST_CASE(caddrinfo_get_new_bucket_legacy) } // Test: IP addresses in the same source groups should map to NO MORE // than 64 buckets. - BOOST_CHECK(buckets.size() <= 64); + CHECK(buckets.size() <= 64U); buckets.clear(); for (int p = 0; p < 255; p++) { @@ -645,7 +645,7 @@ BOOST_AUTO_TEST_CASE(caddrinfo_get_new_bucket_legacy) } // Test: IP addresses in the different source groups should map to MORE // than 64 buckets. - BOOST_CHECK(buckets.size() > 64); + CHECK(buckets.size() > 64U); } // The following three test cases use asmap.raw @@ -659,7 +659,7 @@ BOOST_AUTO_TEST_CASE(caddrinfo_get_new_bucket_legacy) // 101.6.0.0/16 AS6 // 101.7.0.0/16 AS7 // 101.8.0.0/16 AS8 -BOOST_AUTO_TEST_CASE(caddrinfo_get_tried_bucket) +FIXTURE_TEST_CASE("caddrinfo_get_tried_bucket", BasicTestingSetup) { auto ngm_asmap{NetGroupManager::WithEmbeddedAsmap(test::data::asmap)}; @@ -674,18 +674,18 @@ BOOST_AUTO_TEST_CASE(caddrinfo_get_tried_bucket) uint256 nKey1 = (HashWriter{} << 1).GetHash(); uint256 nKey2 = (HashWriter{} << 2).GetHash(); - BOOST_CHECK_EQUAL(info1.GetTriedBucket(nKey1, ngm_asmap), 236); + CHECK(info1.GetTriedBucket(nKey1, ngm_asmap) == 236); // Test: Make sure key actually randomizes bucket placement. A fail on // this test could be a security issue. - BOOST_CHECK(info1.GetTriedBucket(nKey1, ngm_asmap) != info1.GetTriedBucket(nKey2, ngm_asmap)); + CHECK(info1.GetTriedBucket(nKey1, ngm_asmap) != info1.GetTriedBucket(nKey2, ngm_asmap)); // Test: Two addresses with same IP but different ports can map to // different buckets because they have different keys. AddrInfo info2 = AddrInfo(addr2, source1); - BOOST_CHECK(info1.GetKey() != info2.GetKey()); - BOOST_CHECK(info1.GetTriedBucket(nKey1, ngm_asmap) != info2.GetTriedBucket(nKey1, ngm_asmap)); + CHECK(info1.GetKey() != info2.GetKey()); + CHECK(info1.GetTriedBucket(nKey1, ngm_asmap) != info2.GetTriedBucket(nKey1, ngm_asmap)); std::set buckets; for (int j = 0; j < 255; j++) { @@ -697,7 +697,7 @@ BOOST_AUTO_TEST_CASE(caddrinfo_get_tried_bucket) } // Test: IP addresses in the different /16 prefix MAY map to more than // 8 buckets. - BOOST_CHECK(buckets.size() > 8); + CHECK(buckets.size() > 8U); buckets.clear(); for (int j = 0; j < 255; j++) { @@ -709,10 +709,10 @@ BOOST_AUTO_TEST_CASE(caddrinfo_get_tried_bucket) } // Test: IP addresses in the different /16 prefix MAY NOT map to more than // 8 buckets. - BOOST_CHECK(buckets.size() == 8); + CHECK(buckets.size() == 8U); } -BOOST_AUTO_TEST_CASE(caddrinfo_get_new_bucket) +FIXTURE_TEST_CASE("caddrinfo_get_new_bucket", BasicTestingSetup) { auto ngm_asmap{NetGroupManager::WithEmbeddedAsmap(test::data::asmap)}; @@ -727,17 +727,17 @@ BOOST_AUTO_TEST_CASE(caddrinfo_get_new_bucket) uint256 nKey2 = (HashWriter{} << 2).GetHash(); // Test: Make sure the buckets are what we expect - BOOST_CHECK_EQUAL(info1.GetNewBucket(nKey1, ngm_asmap), 795); - BOOST_CHECK_EQUAL(info1.GetNewBucket(nKey1, source1, ngm_asmap), 795); + CHECK(info1.GetNewBucket(nKey1, ngm_asmap) == 795); + CHECK(info1.GetNewBucket(nKey1, source1, ngm_asmap) == 795); // Test: Make sure key actually randomizes bucket placement. A fail on // this test could be a security issue. - BOOST_CHECK(info1.GetNewBucket(nKey1, ngm_asmap) != info1.GetNewBucket(nKey2, ngm_asmap)); + CHECK(info1.GetNewBucket(nKey1, ngm_asmap) != info1.GetNewBucket(nKey2, ngm_asmap)); // Test: Ports should not affect bucket placement in the addr AddrInfo info2 = AddrInfo(addr2, source1); - BOOST_CHECK(info1.GetKey() != info2.GetKey()); - BOOST_CHECK_EQUAL(info1.GetNewBucket(nKey1, ngm_asmap), info2.GetNewBucket(nKey1, ngm_asmap)); + CHECK(info1.GetKey() != info2.GetKey()); + CHECK(info1.GetNewBucket(nKey1, ngm_asmap) == info2.GetNewBucket(nKey1, ngm_asmap)); std::set buckets; for (int i = 0; i < 255; i++) { @@ -749,7 +749,7 @@ BOOST_AUTO_TEST_CASE(caddrinfo_get_new_bucket) } // Test: IP addresses in the same /16 prefix // usually map to the same bucket. - BOOST_CHECK_EQUAL(buckets.size(), 1U); + CHECK(buckets.size() == 1U); buckets.clear(); for (int j = 0; j < 4 * 255; j++) { @@ -762,7 +762,7 @@ BOOST_AUTO_TEST_CASE(caddrinfo_get_new_bucket) } // Test: IP addresses in the same source /16 prefix should not map to more // than 64 buckets. - BOOST_CHECK(buckets.size() <= 64); + CHECK(buckets.size() <= 64U); buckets.clear(); for (int p = 0; p < 255; p++) { @@ -774,7 +774,7 @@ BOOST_AUTO_TEST_CASE(caddrinfo_get_new_bucket) } // Test: IP addresses in the different source /16 prefixes usually map to MORE // than 1 bucket. - BOOST_CHECK(buckets.size() > 1); + CHECK(buckets.size() > 1U); buckets.clear(); for (int p = 0; p < 255; p++) { @@ -786,10 +786,10 @@ BOOST_AUTO_TEST_CASE(caddrinfo_get_new_bucket) } // Test: IP addresses in the different source /16 prefixes sometimes map to NO MORE // than 1 bucket. - BOOST_CHECK(buckets.size() == 1); + CHECK(buckets.size() == 1U); } -BOOST_AUTO_TEST_CASE(addrman_serialization) +FIXTURE_TEST_CASE("addrman_serialization", BasicTestingSetup) { auto netgroupman{NetGroupManager::WithEmbeddedAsmap(test::data::asmap)}; @@ -811,18 +811,18 @@ BOOST_AUTO_TEST_CASE(addrman_serialization) AddressPosition addr_pos1 = addrman_asmap1->FindAddressEntry(addr).value(); AddressPosition addr_pos2 = addrman_asmap1_dup->FindAddressEntry(addr).value(); - BOOST_CHECK(addr_pos1.multiplicity != 0); - BOOST_CHECK(addr_pos2.multiplicity != 0); + CHECK(addr_pos1.multiplicity != 0); + CHECK(addr_pos2.multiplicity != 0); - BOOST_CHECK(addr_pos1 == addr_pos2); + CHECK(addr_pos1 == addr_pos2); // deserializing asmaped peers.dat to non-asmaped addrman stream << *addrman_asmap1; stream >> *addrman_noasmap; AddressPosition addr_pos3 = addrman_noasmap->FindAddressEntry(addr).value(); - BOOST_CHECK(addr_pos3.multiplicity != 0); - BOOST_CHECK(addr_pos1.bucket != addr_pos3.bucket); - BOOST_CHECK(addr_pos1.position != addr_pos3.position); + CHECK(addr_pos3.multiplicity != 0); + CHECK(addr_pos1.bucket != addr_pos3.bucket); + CHECK(addr_pos1.position != addr_pos3.position); // deserializing non-asmaped peers.dat to asmaped addrman addrman_asmap1 = std::make_unique(netgroupman, DETERMINISTIC, ratio); @@ -832,9 +832,9 @@ BOOST_AUTO_TEST_CASE(addrman_serialization) stream >> *addrman_asmap1; AddressPosition addr_pos4 = addrman_asmap1->FindAddressEntry(addr).value(); - BOOST_CHECK(addr_pos4.multiplicity != 0); - BOOST_CHECK(addr_pos4.bucket != addr_pos3.bucket); - BOOST_CHECK(addr_pos4 == addr_pos2); + CHECK(addr_pos4.multiplicity != 0); + CHECK(addr_pos4.bucket != addr_pos3.bucket); + CHECK(addr_pos4 == addr_pos2); // used to map to different buckets, now maps to the same bucket. addrman_asmap1 = std::make_unique(netgroupman, DETERMINISTIC, ratio); @@ -844,16 +844,16 @@ BOOST_AUTO_TEST_CASE(addrman_serialization) addrman_noasmap->Add({addr, addr2}, default_source); AddressPosition addr_pos5 = addrman_noasmap->FindAddressEntry(addr1).value(); AddressPosition addr_pos6 = addrman_noasmap->FindAddressEntry(addr2).value(); - BOOST_CHECK(addr_pos5.bucket != addr_pos6.bucket); + CHECK(addr_pos5.bucket != addr_pos6.bucket); stream << *addrman_noasmap; stream >> *addrman_asmap1; AddressPosition addr_pos7 = addrman_asmap1->FindAddressEntry(addr1).value(); AddressPosition addr_pos8 = addrman_asmap1->FindAddressEntry(addr2).value(); - BOOST_CHECK(addr_pos7.bucket == addr_pos8.bucket); - BOOST_CHECK(addr_pos7.position != addr_pos8.position); + CHECK(addr_pos7.bucket == addr_pos8.bucket); + CHECK(addr_pos7.position != addr_pos8.position); } -BOOST_AUTO_TEST_CASE(remove_invalid) +FIXTURE_TEST_CASE("remove_invalid", BasicTestingSetup) { // Confirm that invalid addresses are ignored in unserialization. @@ -868,7 +868,7 @@ BOOST_AUTO_TEST_CASE(remove_invalid) addrman->Add({new1, tried1, new2, tried2}, CNetAddr{}); addrman->Good(tried1); addrman->Good(tried2); - BOOST_REQUIRE_EQUAL(addrman->Size(), 4); + REQUIRE(addrman->Size() == 4U); stream << *addrman; @@ -878,40 +878,40 @@ BOOST_AUTO_TEST_CASE(remove_invalid) const char new2_raw[]{6, 6, 6, 6}; const uint8_t new2_raw_replacement[]{0, 0, 0, 0}; // 0.0.0.0 is !IsValid() pos = str.find(new2_raw, 0, sizeof(new2_raw)); - BOOST_REQUIRE(pos != std::string::npos); - BOOST_REQUIRE(pos + sizeof(new2_raw_replacement) <= stream.size()); + REQUIRE(pos != std::string::npos); + REQUIRE(pos + sizeof(new2_raw_replacement) <= stream.size()); memcpy(stream.data() + pos, new2_raw_replacement, sizeof(new2_raw_replacement)); const char tried2_raw[]{8, 8, 8, 8}; const uint8_t tried2_raw_replacement[]{255, 255, 255, 255}; // 255.255.255.255 is !IsValid() pos = str.find(tried2_raw, 0, sizeof(tried2_raw)); - BOOST_REQUIRE(pos != std::string::npos); - BOOST_REQUIRE(pos + sizeof(tried2_raw_replacement) <= stream.size()); + REQUIRE(pos != std::string::npos); + REQUIRE(pos + sizeof(tried2_raw_replacement) <= stream.size()); memcpy(stream.data() + pos, tried2_raw_replacement, sizeof(tried2_raw_replacement)); addrman = std::make_unique(EMPTY_NETGROUPMAN, DETERMINISTIC, GetCheckRatio(m_node)); stream >> *addrman; - BOOST_CHECK_EQUAL(addrman->Size(), 2); + CHECK(addrman->Size() == 2U); } -BOOST_AUTO_TEST_CASE(addrman_selecttriedcollision) +FIXTURE_TEST_CASE("addrman_selecttriedcollision", BasicTestingSetup) { auto addrman = std::make_unique(EMPTY_NETGROUPMAN, DETERMINISTIC, GetCheckRatio(m_node)); - BOOST_CHECK(addrman->Size() == 0); + CHECK(addrman->Size() == 0U); // Empty addrman should return blank addrman info. - BOOST_CHECK(addrman->SelectTriedCollision().first.ToStringAddrPort() == "[::]:0"); + CHECK(addrman->SelectTriedCollision().first.ToStringAddrPort() == "[::]:0"); // Add twenty two addresses. CNetAddr source = ResolveIP("252.2.2.2"); for (unsigned int i = 1; i < 23; i++) { CService addr = ResolveService("250.1.1." + ToString(i)); - BOOST_CHECK(addrman->Add({CAddress(addr, NODE_NONE)}, source)); + CHECK(addrman->Add({CAddress(addr, NODE_NONE)}, source)); // No collisions in tried. - BOOST_CHECK(addrman->Good(addr)); - BOOST_CHECK(addrman->SelectTriedCollision().first.ToStringAddrPort() == "[::]:0"); + CHECK(addrman->Good(addr)); + CHECK(addrman->SelectTriedCollision().first.ToStringAddrPort() == "[::]:0"); } // Ensure Good handles duplicates well. @@ -920,14 +920,14 @@ BOOST_AUTO_TEST_CASE(addrman_selecttriedcollision) CService addr = ResolveService("250.1.1." + ToString(i)); // Unable to add duplicate address to tried table. - BOOST_CHECK(!addrman->Good(addr)); + CHECK(!addrman->Good(addr)); // Verify duplicate address not marked as a collision. - BOOST_CHECK(addrman->SelectTriedCollision().first.ToStringAddrPort() == "[::]:0"); + CHECK(addrman->SelectTriedCollision().first.ToStringAddrPort() == "[::]:0"); } } -BOOST_AUTO_TEST_CASE(addrman_noevict) +FIXTURE_TEST_CASE("addrman_noevict", BasicTestingSetup) { auto addrman = std::make_unique(EMPTY_NETGROUPMAN, DETERMINISTIC, GetCheckRatio(m_node)); @@ -935,111 +935,111 @@ BOOST_AUTO_TEST_CASE(addrman_noevict) CNetAddr source = ResolveIP("252.2.2.2"); for (unsigned int i = 1; i < 36; i++) { CService addr = ResolveService("250.1.1." + ToString(i)); - BOOST_CHECK(addrman->Add({CAddress(addr, NODE_NONE)}, source)); + CHECK(addrman->Add({CAddress(addr, NODE_NONE)}, source)); // No collision yet. - BOOST_CHECK(addrman->Good(addr)); + CHECK(addrman->Good(addr)); } // Collision in tried table between 36 and 19. CService addr36 = ResolveService("250.1.1.36"); - BOOST_CHECK(addrman->Add({CAddress(addr36, NODE_NONE)}, source)); - BOOST_CHECK(!addrman->Good(addr36)); - BOOST_CHECK_EQUAL(addrman->SelectTriedCollision().first.ToStringAddrPort(), "250.1.1.19:0"); + CHECK(addrman->Add({CAddress(addr36, NODE_NONE)}, source)); + CHECK(!addrman->Good(addr36)); + CHECK(addrman->SelectTriedCollision().first.ToStringAddrPort() == "250.1.1.19:0"); // 36 should be discarded and 19 not evicted. // This means we keep 19 in the tried table and // 36 stays in the new table. addrman->ResolveCollisions(); - BOOST_CHECK(addrman->SelectTriedCollision().first.ToStringAddrPort() == "[::]:0"); + CHECK(addrman->SelectTriedCollision().first.ToStringAddrPort() == "[::]:0"); // Lets create two collisions. for (unsigned int i = 37; i < 59; i++) { CService addr = ResolveService("250.1.1." + ToString(i)); - BOOST_CHECK(addrman->Add({CAddress(addr, NODE_NONE)}, source)); - BOOST_CHECK(addrman->Good(addr)); + CHECK(addrman->Add({CAddress(addr, NODE_NONE)}, source)); + CHECK(addrman->Good(addr)); } // Cause a collision in the tried table. CService addr59 = ResolveService("250.1.1.59"); - BOOST_CHECK(addrman->Add({CAddress(addr59, NODE_NONE)}, source)); - BOOST_CHECK(!addrman->Good(addr59)); + CHECK(addrman->Add({CAddress(addr59, NODE_NONE)}, source)); + CHECK(!addrman->Good(addr59)); - BOOST_CHECK_EQUAL(addrman->SelectTriedCollision().first.ToStringAddrPort(), "250.1.1.10:0"); + CHECK(addrman->SelectTriedCollision().first.ToStringAddrPort() == "250.1.1.10:0"); // Cause a second collision in the new table. - BOOST_CHECK(!addrman->Add({CAddress(addr36, NODE_NONE)}, source)); + CHECK(!addrman->Add({CAddress(addr36, NODE_NONE)}, source)); // 36 still cannot be moved from new to tried due to colliding with 19 - BOOST_CHECK(!addrman->Good(addr36)); - BOOST_CHECK(addrman->SelectTriedCollision().first.ToStringAddrPort() != "[::]:0"); + CHECK(!addrman->Good(addr36)); + CHECK(addrman->SelectTriedCollision().first.ToStringAddrPort() != "[::]:0"); // Resolve all collisions. addrman->ResolveCollisions(); - BOOST_CHECK(addrman->SelectTriedCollision().first.ToStringAddrPort() == "[::]:0"); + CHECK(addrman->SelectTriedCollision().first.ToStringAddrPort() == "[::]:0"); } -BOOST_AUTO_TEST_CASE(addrman_evictionworks) +FIXTURE_TEST_CASE("addrman_evictionworks", BasicTestingSetup) { auto addrman = std::make_unique(EMPTY_NETGROUPMAN, DETERMINISTIC, GetCheckRatio(m_node)); - BOOST_CHECK(addrman->Size() == 0); + CHECK(addrman->Size() == 0U); // Empty addrman should return blank addrman info. - BOOST_CHECK(addrman->SelectTriedCollision().first.ToStringAddrPort() == "[::]:0"); + CHECK(addrman->SelectTriedCollision().first.ToStringAddrPort() == "[::]:0"); // Add 35 addresses CNetAddr source = ResolveIP("252.2.2.2"); for (unsigned int i = 1; i < 36; i++) { CService addr = ResolveService("250.1.1." + ToString(i)); - BOOST_CHECK(addrman->Add({CAddress(addr, NODE_NONE)}, source)); + CHECK(addrman->Add({CAddress(addr, NODE_NONE)}, source)); // No collision yet. - BOOST_CHECK(addrman->Good(addr)); + CHECK(addrman->Good(addr)); } // Collision between 36 and 19. CService addr = ResolveService("250.1.1.36"); - BOOST_CHECK(addrman->Add({CAddress(addr, NODE_NONE)}, source)); - BOOST_CHECK(!addrman->Good(addr)); + CHECK(addrman->Add({CAddress(addr, NODE_NONE)}, source)); + CHECK(!addrman->Good(addr)); auto info = addrman->SelectTriedCollision().first; - BOOST_CHECK_EQUAL(info.ToStringAddrPort(), "250.1.1.19:0"); + CHECK(info.ToStringAddrPort() == "250.1.1.19:0"); // Ensure test of address fails, so that it is evicted. // Update entry in tried by setting last good connection in the deep past. - BOOST_CHECK(!addrman->Good(info, NodeSeconds{1s})); + CHECK(!addrman->Good(info, NodeSeconds{1s})); addrman->Attempt(info, /*fCountFailure=*/false, Now() - 61s); // Should swap 36 for 19. addrman->ResolveCollisions(); - BOOST_CHECK(addrman->SelectTriedCollision().first.ToStringAddrPort() == "[::]:0"); + CHECK(addrman->SelectTriedCollision().first.ToStringAddrPort() == "[::]:0"); AddressPosition addr_pos{addrman->FindAddressEntry(CAddress(addr, NODE_NONE)).value()}; - BOOST_CHECK(addr_pos.tried); + CHECK(addr_pos.tried); // If 36 was swapped for 19, then adding 36 to tried should fail because we // are attempting to add a duplicate. // We check this by verifying Good() returns false and also verifying that // we have no collisions. - BOOST_CHECK(!addrman->Good(addr)); - BOOST_CHECK(addrman->SelectTriedCollision().first.ToStringAddrPort() == "[::]:0"); + CHECK(!addrman->Good(addr)); + CHECK(addrman->SelectTriedCollision().first.ToStringAddrPort() == "[::]:0"); // 19 should fail as a collision (not a duplicate) if we now attempt to move // it to the tried table. CService addr19 = ResolveService("250.1.1.19"); - BOOST_CHECK(!addrman->Good(addr19)); - BOOST_CHECK_EQUAL(addrman->SelectTriedCollision().first.ToStringAddrPort(), "250.1.1.36:0"); + CHECK(!addrman->Good(addr19)); + CHECK(addrman->SelectTriedCollision().first.ToStringAddrPort() == "250.1.1.36:0"); // Eviction is also successful if too much time has passed since last try NodeClockContext clock_ctx{}; clock_ctx += 4h; addrman->ResolveCollisions(); - BOOST_CHECK(addrman->SelectTriedCollision().first.ToStringAddrPort() == "[::]:0"); + CHECK(addrman->SelectTriedCollision().first.ToStringAddrPort() == "[::]:0"); //Now 19 is in tried again, and 36 back to new AddressPosition addr_pos19{addrman->FindAddressEntry(CAddress(addr19, NODE_NONE)).value()}; - BOOST_CHECK(addr_pos19.tried); + CHECK(addr_pos19.tried); AddressPosition addr_pos36{addrman->FindAddressEntry(CAddress(addr, NODE_NONE)).value()}; - BOOST_CHECK(!addr_pos36.tried); + CHECK(!addr_pos36.tried); } static auto AddrmanToStream(const AddrMan& addrman) @@ -1050,35 +1050,35 @@ static auto AddrmanToStream(const AddrMan& addrman) return ssPeersIn; } -BOOST_AUTO_TEST_CASE(load_addrman) +FIXTURE_TEST_CASE("load_addrman", BasicTestingSetup) { AddrMan addrman{EMPTY_NETGROUPMAN, DETERMINISTIC, GetCheckRatio(m_node)}; std::optional addr1, addr2, addr3, addr4; addr1 = Lookup("250.7.1.1", 8333, false); - BOOST_CHECK(addr1.has_value()); + CHECK(addr1.has_value()); addr2 = Lookup("250.7.2.2", 9999, false); - BOOST_CHECK(addr2.has_value()); + CHECK(addr2.has_value()); addr3 = Lookup("250.7.3.3", 9999, false); - BOOST_CHECK(addr3.has_value()); + CHECK(addr3.has_value()); addr3 = Lookup("250.7.3.3"s, 9999, false); - BOOST_CHECK(addr3.has_value()); + CHECK(addr3.has_value()); addr4 = Lookup("250.7.3.3\0example.com"s, 9999, false); - BOOST_CHECK(!addr4.has_value()); + CHECK(!addr4.has_value()); // Add three addresses to new table. const std::optional source{Lookup("252.5.1.1", 8333, false)}; - BOOST_CHECK(source.has_value()); + CHECK(source.has_value()); std::vector addresses{CAddress(addr1.value(), NODE_NONE), CAddress(addr2.value(), NODE_NONE), CAddress(addr3.value(), NODE_NONE)}; - BOOST_CHECK(addrman.Add(addresses, source.value())); - BOOST_CHECK(addrman.Size() == 3); + CHECK(addrman.Add(addresses, source.value())); + CHECK(addrman.Size() == 3U); // Test that the de-serialization does not throw an exception. auto ssPeers1{AddrmanToStream(addrman)}; bool exceptionThrown = false; AddrMan addrman1{EMPTY_NETGROUPMAN, !DETERMINISTIC, GetCheckRatio(m_node)}; - BOOST_CHECK(addrman1.Size() == 0); + CHECK(addrman1.Size() == 0U); try { unsigned char pchMsgTmp[4]; ssPeers1 >> pchMsgTmp; @@ -1087,16 +1087,16 @@ BOOST_AUTO_TEST_CASE(load_addrman) exceptionThrown = true; } - BOOST_CHECK(addrman1.Size() == 3); - BOOST_CHECK(exceptionThrown == false); + CHECK(addrman1.Size() == 3U); + CHECK(exceptionThrown == false); // Test that ReadFromStream creates an addrman with the correct number of addrs. DataStream ssPeers2 = AddrmanToStream(addrman); AddrMan addrman2{EMPTY_NETGROUPMAN, !DETERMINISTIC, GetCheckRatio(m_node)}; - BOOST_CHECK(addrman2.Size() == 0); + CHECK(addrman2.Size() == 0U); ReadFromStream(addrman2, ssPeers2); - BOOST_CHECK(addrman2.Size() == 3); + CHECK(addrman2.Size() == 3U); } // Produce a corrupt peers.dat that claims 20 addrs when it only has one addr. @@ -1116,23 +1116,23 @@ static auto MakeCorruptPeersDat() s << nUBuckets; const std::optional serv{Lookup("252.1.1.1", 7777, false)}; - BOOST_REQUIRE(serv.has_value()); + REQUIRE(serv.has_value()); CAddress addr = CAddress(serv.value(), NODE_NONE); std::optional resolved{LookupHost("252.2.2.2", false)}; - BOOST_REQUIRE(resolved.has_value()); + REQUIRE(resolved.has_value()); AddrInfo info = AddrInfo(addr, resolved.value()); s << CAddress::V1_DISK(info); return s; } -BOOST_AUTO_TEST_CASE(load_addrman_corrupted) +FIXTURE_TEST_CASE("load_addrman_corrupted", BasicTestingSetup) { // Test that the de-serialization of corrupted peers.dat throws an exception. auto ssPeers1{MakeCorruptPeersDat()}; bool exceptionThrown = false; AddrMan addrman1{EMPTY_NETGROUPMAN, !DETERMINISTIC, GetCheckRatio(m_node)}; - BOOST_CHECK(addrman1.Size() == 0); + CHECK(addrman1.Size() == 0); try { unsigned char pchMsgTmp[4]; ssPeers1 >> pchMsgTmp; @@ -1140,17 +1140,17 @@ BOOST_AUTO_TEST_CASE(load_addrman_corrupted) } catch (const std::exception&) { exceptionThrown = true; } - BOOST_CHECK(exceptionThrown); + CHECK(exceptionThrown); // Test that ReadFromStream fails if peers.dat is corrupt auto ssPeers2{MakeCorruptPeersDat()}; AddrMan addrman2{EMPTY_NETGROUPMAN, !DETERMINISTIC, GetCheckRatio(m_node)}; - BOOST_CHECK(addrman2.Size() == 0); - BOOST_CHECK_THROW(ReadFromStream(addrman2, ssPeers2), std::ios_base::failure); + CHECK(addrman2.Size() == 0); + CHECK_THROWS_AS(ReadFromStream(addrman2, ssPeers2), std::ios_base::failure); } -BOOST_AUTO_TEST_CASE(addrman_update_address) +FIXTURE_TEST_CASE("addrman_update_address", BasicTestingSetup) { // Tests updating nTime via Connected() and nServices via SetServices() and Add() auto addrman = std::make_unique(EMPTY_NETGROUPMAN, DETERMINISTIC, GetCheckRatio(m_node)); @@ -1159,8 +1159,8 @@ BOOST_AUTO_TEST_CASE(addrman_update_address) const auto start_time{Now() - 10000s}; addr.nTime = start_time; - BOOST_CHECK(addrman->Add({addr}, source)); - BOOST_CHECK_EQUAL(addrman->Size(), 1U); + CHECK(addrman->Add({addr}, source)); + CHECK(addrman->Size() == 1U); // Updating an addrman entry with a different port doesn't change it CAddress addr_diff_port{CAddress(ResolveService("250.1.1.1", 8334), NODE_NONE)}; @@ -1168,81 +1168,81 @@ BOOST_AUTO_TEST_CASE(addrman_update_address) addrman->Connected(addr_diff_port); addrman->SetServices(addr_diff_port, NODE_NETWORK_LIMITED); std::vector vAddr1{addrman->GetAddr(/*max_addresses=*/0, /*max_pct=*/0, /*network=*/std::nullopt)}; - BOOST_CHECK_EQUAL(vAddr1.size(), 1U); - BOOST_CHECK(vAddr1.at(0).nTime == start_time); - BOOST_CHECK_EQUAL(vAddr1.at(0).nServices, NODE_NONE); + CHECK(vAddr1.size() == 1U); + CHECK(vAddr1.at(0).nTime == start_time); + CHECK(vAddr1.at(0).nServices == NODE_NONE); // Updating an addrman entry with the correct port is successful addrman->Connected(addr); addrman->SetServices(addr, NODE_NETWORK_LIMITED); std::vector vAddr2 = addrman->GetAddr(/*max_addresses=*/0, /*max_pct=*/0, /*network=*/std::nullopt); - BOOST_CHECK_EQUAL(vAddr2.size(), 1U); - BOOST_CHECK(vAddr2.at(0).nTime >= start_time + 10000s); - BOOST_CHECK_EQUAL(vAddr2.at(0).nServices, NODE_NETWORK_LIMITED); + CHECK(vAddr2.size() == 1U); + CHECK(vAddr2.at(0).nTime >= start_time + 10000s); + CHECK(vAddr2.at(0).nServices == NODE_NETWORK_LIMITED); // Updating an existing addr through Add() (used in gossip relay) can add additional services but can't remove existing ones. CAddress addr_v2{CAddress(ResolveService("250.1.1.1", 8333), NODE_P2P_V2)}; addr_v2.nTime = start_time; - BOOST_CHECK(!addrman->Add({addr_v2}, source)); + CHECK(!addrman->Add({addr_v2}, source)); std::vector vAddr3{addrman->GetAddr(/*max_addresses=*/0, /*max_pct=*/0, /*network=*/std::nullopt)}; - BOOST_CHECK_EQUAL(vAddr3.size(), 1U); - BOOST_CHECK_EQUAL(vAddr3.at(0).nServices, NODE_P2P_V2 | NODE_NETWORK_LIMITED); + CHECK(vAddr3.size() == 1U); + CHECK(vAddr3.at(0).nServices == (NODE_P2P_V2 | NODE_NETWORK_LIMITED)); // SetServices() (used when we connected to them) overwrites existing service flags addrman->SetServices(addr, NODE_NETWORK); std::vector vAddr4{addrman->GetAddr(/*max_addresses=*/0, /*max_pct=*/0, /*network=*/std::nullopt)}; - BOOST_CHECK_EQUAL(vAddr4.size(), 1U); - BOOST_CHECK_EQUAL(vAddr4.at(0).nServices, NODE_NETWORK); + CHECK(vAddr4.size() == 1U); + CHECK(vAddr4.at(0).nServices == NODE_NETWORK); // Promoting to Tried does not affect the service flags - BOOST_CHECK(addrman->Good(addr)); // addr has NODE_NONE + CHECK(addrman->Good(addr)); // addr has NODE_NONE std::vector vAddr5{addrman->GetAddr(/*max_addresses=*/0, /*max_pct=*/0, /*network=*/std::nullopt)}; - BOOST_CHECK_EQUAL(vAddr5.size(), 1U); - BOOST_CHECK_EQUAL(vAddr5.at(0).nServices, NODE_NETWORK); + CHECK(vAddr5.size() == 1U); + CHECK(vAddr5.at(0).nServices == NODE_NETWORK); // Adding service flags even works when the addr is in Tried - BOOST_CHECK(!addrman->Add({addr_v2}, source)); + CHECK(!addrman->Add({addr_v2}, source)); std::vector vAddr6{addrman->GetAddr(/*max_addresses=*/0, /*max_pct=*/0, /*network=*/std::nullopt)}; - BOOST_CHECK_EQUAL(vAddr6.size(), 1U); - BOOST_CHECK_EQUAL(vAddr6.at(0).nServices, NODE_NETWORK | NODE_P2P_V2); + CHECK(vAddr6.size() == 1U); + CHECK(vAddr6.at(0).nServices == (NODE_NETWORK | NODE_P2P_V2)); } -BOOST_AUTO_TEST_CASE(addrman_size) +FIXTURE_TEST_CASE("addrman_size", BasicTestingSetup) { auto addrman = std::make_unique(EMPTY_NETGROUPMAN, DETERMINISTIC, GetCheckRatio(m_node)); const CNetAddr source = ResolveIP("252.2.2.2"); // empty addrman - BOOST_CHECK_EQUAL(addrman->Size(/*net=*/std::nullopt, /*in_new=*/std::nullopt), 0U); - BOOST_CHECK_EQUAL(addrman->Size(/*net=*/NET_IPV4, /*in_new=*/std::nullopt), 0U); - BOOST_CHECK_EQUAL(addrman->Size(/*net=*/std::nullopt, /*in_new=*/true), 0U); - BOOST_CHECK_EQUAL(addrman->Size(/*net=*/NET_IPV4, /*in_new=*/false), 0U); + CHECK(addrman->Size(/*net=*/std::nullopt, /*in_new=*/std::nullopt) == 0U); + CHECK(addrman->Size(/*net=*/NET_IPV4, /*in_new=*/std::nullopt) == 0U); + CHECK(addrman->Size(/*net=*/std::nullopt, /*in_new=*/true) == 0U); + CHECK(addrman->Size(/*net=*/NET_IPV4, /*in_new=*/false) == 0U); // add two ipv4 addresses, one to tried and new const CAddress addr1{ResolveService("250.1.1.1", 8333), NODE_NONE}; - BOOST_CHECK(addrman->Add({addr1}, source)); - BOOST_CHECK(addrman->Good(addr1)); + CHECK(addrman->Add({addr1}, source)); + CHECK(addrman->Good(addr1)); const CAddress addr2{ResolveService("250.1.1.2", 8333), NODE_NONE}; - BOOST_CHECK(addrman->Add({addr2}, source)); + CHECK(addrman->Add({addr2}, source)); - BOOST_CHECK_EQUAL(addrman->Size(/*net=*/std::nullopt, /*in_new=*/std::nullopt), 2U); - BOOST_CHECK_EQUAL(addrman->Size(/*net=*/NET_IPV4, /*in_new=*/std::nullopt), 2U); - BOOST_CHECK_EQUAL(addrman->Size(/*net=*/std::nullopt, /*in_new=*/true), 1U); - BOOST_CHECK_EQUAL(addrman->Size(/*net=*/std::nullopt, /*in_new=*/false), 1U); - BOOST_CHECK_EQUAL(addrman->Size(/*net=*/NET_IPV4, /*in_new=*/true), 1U); - BOOST_CHECK_EQUAL(addrman->Size(/*net=*/NET_IPV4, /*in_new=*/false), 1U); + CHECK(addrman->Size(/*net=*/std::nullopt, /*in_new=*/std::nullopt) == 2U); + CHECK(addrman->Size(/*net=*/NET_IPV4, /*in_new=*/std::nullopt) == 2U); + CHECK(addrman->Size(/*net=*/std::nullopt, /*in_new=*/true) == 1U); + CHECK(addrman->Size(/*net=*/std::nullopt, /*in_new=*/false) == 1U); + CHECK(addrman->Size(/*net=*/NET_IPV4, /*in_new=*/true) == 1U); + CHECK(addrman->Size(/*net=*/NET_IPV4, /*in_new=*/false) == 1U); // add one i2p address to new CService i2p_addr; i2p_addr.SetSpecial("UDHDrtrcetjm5sxzskjyr5ztpeszydbh4dpl3pl4utgqqw2v4jna.b32.I2P"); const CAddress addr3{i2p_addr, NODE_NONE}; - BOOST_CHECK(addrman->Add({addr3}, source)); - BOOST_CHECK_EQUAL(addrman->Size(/*net=*/std::nullopt, /*in_new=*/std::nullopt), 3U); - BOOST_CHECK_EQUAL(addrman->Size(/*net=*/NET_IPV4, /*in_new=*/std::nullopt), 2U); - BOOST_CHECK_EQUAL(addrman->Size(/*net=*/NET_I2P, /*in_new=*/std::nullopt), 1U); - BOOST_CHECK_EQUAL(addrman->Size(/*net=*/NET_I2P, /*in_new=*/true), 1U); - BOOST_CHECK_EQUAL(addrman->Size(/*net=*/std::nullopt, /*in_new=*/true), 2U); - BOOST_CHECK_EQUAL(addrman->Size(/*net=*/std::nullopt, /*in_new=*/false), 1U); + CHECK(addrman->Add({addr3}, source)); + CHECK(addrman->Size(/*net=*/std::nullopt, /*in_new=*/std::nullopt) == 3U); + CHECK(addrman->Size(/*net=*/NET_IPV4, /*in_new=*/std::nullopt) == 2U); + CHECK(addrman->Size(/*net=*/NET_I2P, /*in_new=*/std::nullopt) == 1U); + CHECK(addrman->Size(/*net=*/NET_I2P, /*in_new=*/true) == 1U); + CHECK(addrman->Size(/*net=*/std::nullopt, /*in_new=*/true) == 2U); + CHECK(addrman->Size(/*net=*/std::nullopt, /*in_new=*/false) == 1U); } -BOOST_AUTO_TEST_SUITE_END() +TEST_SUITE_END() diff --git a/src/test/allocator_tests.cpp b/src/test/allocator_tests.cpp index f5e9b202c3da..a81bf011264f 100644 --- a/src/test/allocator_tests.cpp +++ b/src/test/allocator_tests.cpp @@ -12,11 +12,11 @@ #include #include -#include +#include -BOOST_AUTO_TEST_SUITE(allocator_tests) +TEST_SUITE_BEGIN("allocator_tests") -BOOST_AUTO_TEST_CASE(arena_tests) +TEST_CASE("arena_tests") { // Fake memory base address for testing // without actually using memory. @@ -27,18 +27,18 @@ BOOST_AUTO_TEST_CASE(arena_tests) #ifdef ARENA_DEBUG b.walk(); #endif - BOOST_CHECK(chunk != nullptr); - BOOST_CHECK(b.stats().used == 1008); // Aligned to 16 - BOOST_CHECK(b.stats().total == synth_size); // Nothing has disappeared? + CHECK(chunk != nullptr); + CHECK(b.stats().used == 1008U); // Aligned to 16 + CHECK(b.stats().total == synth_size); // Nothing has disappeared? b.free(chunk); #ifdef ARENA_DEBUG b.walk(); #endif - BOOST_CHECK(b.stats().used == 0); - BOOST_CHECK(b.stats().free == synth_size); + CHECK(b.stats().used == 0U); + CHECK(b.stats().free == synth_size); try { // Test exception on double-free b.free(chunk); - BOOST_CHECK(0); + CHECK(0); } catch(std::runtime_error &) { } @@ -46,8 +46,8 @@ BOOST_AUTO_TEST_CASE(arena_tests) void *a0 = b.alloc(128); void *a1 = b.alloc(256); void *a2 = b.alloc(512); - BOOST_CHECK(b.stats().used == 896); - BOOST_CHECK(b.stats().total == synth_size); + CHECK(b.stats().used == 896U); + CHECK(b.stats().total == synth_size); #ifdef ARENA_DEBUG b.walk(); #endif @@ -55,25 +55,25 @@ BOOST_AUTO_TEST_CASE(arena_tests) #ifdef ARENA_DEBUG b.walk(); #endif - BOOST_CHECK(b.stats().used == 768); + CHECK(b.stats().used == 768U); b.free(a1); - BOOST_CHECK(b.stats().used == 512); + CHECK(b.stats().used == 512U); void *a3 = b.alloc(128); #ifdef ARENA_DEBUG b.walk(); #endif - BOOST_CHECK(b.stats().used == 640); + CHECK(b.stats().used == 640U); b.free(a2); - BOOST_CHECK(b.stats().used == 128); + CHECK(b.stats().used == 128U); b.free(a3); - BOOST_CHECK(b.stats().used == 0); - BOOST_CHECK_EQUAL(b.stats().chunks_used, 0U); - BOOST_CHECK(b.stats().total == synth_size); - BOOST_CHECK(b.stats().free == synth_size); - BOOST_CHECK_EQUAL(b.stats().chunks_free, 1U); + CHECK(b.stats().used == 0U); + CHECK(b.stats().chunks_used == 0U); + CHECK(b.stats().total == synth_size); + CHECK(b.stats().free == synth_size); + CHECK(b.stats().chunks_free == 1U); std::vector addr; - BOOST_CHECK(b.alloc(0) == nullptr); // allocating 0 always returns nullptr + CHECK(b.alloc(0) == nullptr); // allocating 0 always returns nullptr #ifdef ARENA_DEBUG b.walk(); #endif @@ -81,14 +81,14 @@ BOOST_AUTO_TEST_CASE(arena_tests) addr.reserve(2048); for (int x=0; x<1024; ++x) addr.push_back(b.alloc(1024)); - BOOST_CHECK(b.stats().free == 0); - BOOST_CHECK(b.alloc(1024) == nullptr); // memory is full, this must return nullptr - BOOST_CHECK(b.alloc(0) == nullptr); + CHECK(b.stats().free == 0U); + CHECK(b.alloc(1024) == nullptr); // memory is full, this must return nullptr + CHECK(b.alloc(0) == nullptr); for (int x=0; x<1024; ++x) b.free(addr[x]); addr.clear(); - BOOST_CHECK(b.stats().total == synth_size); - BOOST_CHECK(b.stats().free == synth_size); + CHECK(b.stats().total == synth_size); + CHECK(b.stats().free == synth_size); // Now in the other direction... for (int x=0; x<1024; ++x) @@ -128,8 +128,8 @@ BOOST_AUTO_TEST_CASE(arena_tests) b.free(ptr); addr.clear(); - BOOST_CHECK(b.stats().total == synth_size); - BOOST_CHECK(b.stats().free == synth_size); + CHECK(b.stats().total == synth_size); + CHECK(b.stats().free == synth_size); } /** Mock LockedPageAllocator for testing */ @@ -164,40 +164,40 @@ class TestLockedPageAllocator: public LockedPageAllocator int lockedcount; }; -BOOST_AUTO_TEST_CASE(lockedpool_tests_mock) +TEST_CASE("lockedpool_tests_mock") { // Test over three virtual arenas, of which one will succeed being locked std::unique_ptr x = std::make_unique(3, 1); LockedPool pool(std::move(x)); - BOOST_CHECK(pool.stats().total == 0); - BOOST_CHECK(pool.stats().locked == 0); + CHECK(pool.stats().total == 0U); + CHECK(pool.stats().locked == 0U); // Ensure unreasonable requests are refused without allocating anything void *invalid_toosmall = pool.alloc(0); - BOOST_CHECK(invalid_toosmall == nullptr); - BOOST_CHECK(pool.stats().used == 0); - BOOST_CHECK(pool.stats().free == 0); + CHECK(invalid_toosmall == nullptr); + CHECK(pool.stats().used == 0U); + CHECK(pool.stats().free == 0); void *invalid_toobig = pool.alloc(LockedPool::ARENA_SIZE+1); - BOOST_CHECK(invalid_toobig == nullptr); - BOOST_CHECK(pool.stats().used == 0); - BOOST_CHECK(pool.stats().free == 0); + CHECK(invalid_toobig == nullptr); + CHECK(pool.stats().used == 0); + CHECK(pool.stats().free == 0); void *a0 = pool.alloc(LockedPool::ARENA_SIZE / 2); - BOOST_CHECK(a0); - BOOST_CHECK(pool.stats().locked == LockedPool::ARENA_SIZE); + CHECK(a0); + CHECK(pool.stats().locked == LockedPool::ARENA_SIZE); void *a1 = pool.alloc(LockedPool::ARENA_SIZE / 2); - BOOST_CHECK(a1); + CHECK(a1); void *a2 = pool.alloc(LockedPool::ARENA_SIZE / 2); - BOOST_CHECK(a2); + CHECK(a2); void *a3 = pool.alloc(LockedPool::ARENA_SIZE / 2); - BOOST_CHECK(a3); + CHECK(a3); void *a4 = pool.alloc(LockedPool::ARENA_SIZE / 2); - BOOST_CHECK(a4); + CHECK(a4); void *a5 = pool.alloc(LockedPool::ARENA_SIZE / 2); - BOOST_CHECK(a5); + CHECK(a5); // We've passed a count of three arenas, so this allocation should fail void *a6 = pool.alloc(16); - BOOST_CHECK(!a6); + CHECK(!a6); pool.free(a0); pool.free(a2); @@ -205,36 +205,36 @@ BOOST_AUTO_TEST_CASE(lockedpool_tests_mock) pool.free(a1); pool.free(a3); pool.free(a5); - BOOST_CHECK(pool.stats().total == 3*LockedPool::ARENA_SIZE); - BOOST_CHECK(pool.stats().locked == LockedPool::ARENA_SIZE); - BOOST_CHECK(pool.stats().used == 0); + CHECK(pool.stats().total == 3*LockedPool::ARENA_SIZE); + CHECK(pool.stats().locked == LockedPool::ARENA_SIZE); + CHECK(pool.stats().used == 0); } // These tests used the live LockedPoolManager object, this is also used // by other tests so the conditions are somewhat less controllable and thus the // tests are somewhat more error-prone. -BOOST_AUTO_TEST_CASE(lockedpool_tests_live) +TEST_CASE("lockedpool_tests_live") { LockedPoolManager &pool = LockedPoolManager::Instance(); LockedPool::Stats initial = pool.stats(); void *a0 = pool.alloc(16); - BOOST_CHECK(a0); + CHECK(a0); // Test reading and writing the allocated memory *((uint32_t*)a0) = 0x1234; - BOOST_CHECK(*((uint32_t*)a0) == 0x1234); + CHECK(*((uint32_t*)a0) == 0x1234U); pool.free(a0); try { // Test exception on double-free pool.free(a0); - BOOST_CHECK(0); + CHECK(0); } catch(std::runtime_error &) { } // If more than one new arena was allocated for the above tests, something is wrong - BOOST_CHECK(pool.stats().total <= (initial.total + LockedPool::ARENA_SIZE)); + CHECK(pool.stats().total <= (initial.total + LockedPool::ARENA_SIZE)); // Usage must be back to where it started - BOOST_CHECK(pool.stats().used == initial.used); + CHECK(pool.stats().used == initial.used); } -BOOST_AUTO_TEST_SUITE_END() +TEST_SUITE_END() diff --git a/src/test/amount_tests.cpp b/src/test/amount_tests.cpp index e1630b41948d..fc7bbdc68ed4 100644 --- a/src/test/amount_tests.cpp +++ b/src/test/amount_tests.cpp @@ -7,139 +7,143 @@ #include -#include +#include -BOOST_AUTO_TEST_SUITE(amount_tests) +TEST_SUITE_BEGIN("amount_tests") -BOOST_AUTO_TEST_CASE(MoneyRangeTest) +TEST_CASE("MoneyRangeTest") { - BOOST_CHECK_EQUAL(MoneyRange(CAmount(-1)), false); - BOOST_CHECK_EQUAL(MoneyRange(CAmount(0)), true); - BOOST_CHECK_EQUAL(MoneyRange(CAmount(1)), true); - BOOST_CHECK_EQUAL(MoneyRange(MAX_MONEY), true); - BOOST_CHECK_EQUAL(MoneyRange(MAX_MONEY + CAmount(1)), false); + CHECK(MoneyRange(CAmount(-1)) == false); + CHECK(MoneyRange(CAmount(0)) == true); + CHECK(MoneyRange(CAmount(1)) == true); + CHECK(MoneyRange(MAX_MONEY) == true); + CHECK(MoneyRange(MAX_MONEY + CAmount(1)) == false); } -BOOST_AUTO_TEST_CASE(GetFeeTest) +TEST_CASE("GetFeeTest") { CFeeRate feeRate, altFeeRate; feeRate = CFeeRate(0); // Must always return 0 - BOOST_CHECK_EQUAL(feeRate.GetFee(0), CAmount(0)); - BOOST_CHECK_EQUAL(feeRate.GetFee(1e5), CAmount(0)); + CHECK(feeRate.GetFee(0) == CAmount(0)); + CHECK(feeRate.GetFee(1e5) == CAmount(0)); feeRate = CFeeRate(1000); // Must always just return the arg - BOOST_CHECK_EQUAL(feeRate.GetFee(0), CAmount(0)); - BOOST_CHECK_EQUAL(feeRate.GetFee(1), CAmount(1)); - BOOST_CHECK_EQUAL(feeRate.GetFee(121), CAmount(121)); - BOOST_CHECK_EQUAL(feeRate.GetFee(999), CAmount(999)); - BOOST_CHECK_EQUAL(feeRate.GetFee(1e3), CAmount(1e3)); - BOOST_CHECK_EQUAL(feeRate.GetFee(9e3), CAmount(9e3)); + CHECK(feeRate.GetFee(0) == CAmount(0)); + CHECK(feeRate.GetFee(1) == CAmount(1)); + CHECK(feeRate.GetFee(121) == CAmount(121)); + CHECK(feeRate.GetFee(999) == CAmount(999)); + CHECK(feeRate.GetFee(1e3) == CAmount(1e3)); + CHECK(feeRate.GetFee(9e3) == CAmount(9e3)); feeRate = CFeeRate(-1000); // Must always just return -1 * arg - BOOST_CHECK_EQUAL(feeRate.GetFee(0), CAmount(0)); - BOOST_CHECK_EQUAL(feeRate.GetFee(1), CAmount(-1)); - BOOST_CHECK_EQUAL(feeRate.GetFee(121), CAmount(-121)); - BOOST_CHECK_EQUAL(feeRate.GetFee(999), CAmount(-999)); - BOOST_CHECK_EQUAL(feeRate.GetFee(1e3), CAmount(-1e3)); - BOOST_CHECK_EQUAL(feeRate.GetFee(9e3), CAmount(-9e3)); + CHECK(feeRate.GetFee(0) == CAmount(0)); + CHECK(feeRate.GetFee(1) == CAmount(-1)); + CHECK(feeRate.GetFee(121) == CAmount(-121)); + CHECK(feeRate.GetFee(999) == CAmount(-999)); + CHECK(feeRate.GetFee(1e3) == CAmount(-1e3)); + CHECK(feeRate.GetFee(9e3) == CAmount(-9e3)); feeRate = CFeeRate(123); // Rounds up the result, if not integer - BOOST_CHECK_EQUAL(feeRate.GetFee(0), CAmount(0)); - BOOST_CHECK_EQUAL(feeRate.GetFee(8), CAmount(1)); // Special case: returns 1 instead of 0 - BOOST_CHECK_EQUAL(feeRate.GetFee(9), CAmount(2)); - BOOST_CHECK_EQUAL(feeRate.GetFee(121), CAmount(15)); - BOOST_CHECK_EQUAL(feeRate.GetFee(122), CAmount(16)); - BOOST_CHECK_EQUAL(feeRate.GetFee(999), CAmount(123)); - BOOST_CHECK_EQUAL(feeRate.GetFee(1e3), CAmount(123)); - BOOST_CHECK_EQUAL(feeRate.GetFee(9e3), CAmount(1107)); + CHECK(feeRate.GetFee(0) == CAmount(0)); + CHECK(feeRate.GetFee(8) == CAmount(1)); // Special case: returns 1 instead of 0 + CHECK(feeRate.GetFee(9) == CAmount(2)); + CHECK(feeRate.GetFee(121) == CAmount(15)); + CHECK(feeRate.GetFee(122) == CAmount(16)); + CHECK(feeRate.GetFee(999) == CAmount(123)); + CHECK(feeRate.GetFee(1e3) == CAmount(123)); + CHECK(feeRate.GetFee(9e3) == CAmount(1107)); feeRate = CFeeRate(-123); // Truncates the result, if not integer - BOOST_CHECK_EQUAL(feeRate.GetFee(0), CAmount(0)); - BOOST_CHECK_EQUAL(feeRate.GetFee(8), CAmount(-1)); // Special case: returns -1 instead of 0 - BOOST_CHECK_EQUAL(feeRate.GetFee(9), CAmount(-1)); + CHECK(feeRate.GetFee(0) == CAmount(0)); + CHECK(feeRate.GetFee(8) == CAmount(-1)); // Special case: returns -1 instead of 0 + CHECK(feeRate.GetFee(9) == CAmount(-1)); // check alternate constructor feeRate = CFeeRate(1000); altFeeRate = CFeeRate(feeRate); - BOOST_CHECK_EQUAL(feeRate.GetFee(100), altFeeRate.GetFee(100)); + CHECK(feeRate.GetFee(100) == altFeeRate.GetFee(100)); // Check full constructor - BOOST_CHECK(CFeeRate(CAmount(-1), 0) == CFeeRate(0)); - BOOST_CHECK(CFeeRate(CAmount(0), 0) == CFeeRate(0)); - BOOST_CHECK(CFeeRate(CAmount(1), 0) == CFeeRate(0)); - BOOST_CHECK(CFeeRate(CAmount(1), -1000) == CFeeRate(0)); + CHECK(CFeeRate(CAmount(-1), 0) == CFeeRate(0)); + CHECK(CFeeRate(CAmount(0), 0) == CFeeRate(0)); + CHECK(CFeeRate(CAmount(1), 0) == CFeeRate(0)); + CHECK(CFeeRate(CAmount(1), -1000) == CFeeRate(0)); // default value - BOOST_CHECK(CFeeRate(CAmount(-1), 1000) == CFeeRate(-1)); - BOOST_CHECK(CFeeRate(CAmount(0), 1000) == CFeeRate(0)); - BOOST_CHECK(CFeeRate(CAmount(1), 1000) == CFeeRate(1)); + CHECK(CFeeRate(CAmount(-1), 1000) == CFeeRate(-1)); + CHECK(CFeeRate(CAmount(0), 1000) == CFeeRate(0)); + CHECK(CFeeRate(CAmount(1), 1000) == CFeeRate(1)); // Previously, precision was limited to three decimal digits // due to only supporting satoshis per kB, so CFeeRate(CAmount(1), 1001) was equal to CFeeRate(0) // Since #32750, higher precision is maintained. - BOOST_CHECK(CFeeRate(CAmount(1), 1001) > CFeeRate(0) && CFeeRate(CAmount(1), 1001) < CFeeRate(1)); - BOOST_CHECK(CFeeRate(CAmount(2), 1001) > CFeeRate(1) && CFeeRate(CAmount(2), 1001) < CFeeRate(2)); + CHECK(CFeeRate(CAmount(1), 1001) > CFeeRate(0)); + CHECK(CFeeRate(CAmount(1), 1001) < CFeeRate(1)); + CHECK(CFeeRate(CAmount(2), 1001) > CFeeRate(1)); + CHECK(CFeeRate(CAmount(2), 1001) < CFeeRate(2)); // some more integer checks - BOOST_CHECK(CFeeRate(CAmount(26), 789) > CFeeRate(32) && CFeeRate(CAmount(26), 789) < CFeeRate(33)); - BOOST_CHECK(CFeeRate(CAmount(27), 789) > CFeeRate(34) && CFeeRate(CAmount(27), 789) < CFeeRate(35)); + CHECK(CFeeRate(CAmount(26), 789) > CFeeRate(32)); + CHECK(CFeeRate(CAmount(26), 789) < CFeeRate(33)); + CHECK(CFeeRate(CAmount(27), 789) > CFeeRate(34)); + CHECK(CFeeRate(CAmount(27), 789) < CFeeRate(35)); // Maximum size in bytes, should not crash CFeeRate(MAX_MONEY, std::numeric_limits::max()).GetFeePerK(); // check multiplication operator // check multiplying by zero feeRate = CFeeRate(1000); - BOOST_CHECK(0 * feeRate == CFeeRate(0)); - BOOST_CHECK(feeRate * 0 == CFeeRate(0)); + CHECK(0 * feeRate == CFeeRate(0)); + CHECK(feeRate * 0 == CFeeRate(0)); // check multiplying by a positive integer - BOOST_CHECK(3 * feeRate == CFeeRate(3000)); - BOOST_CHECK(feeRate * 3 == CFeeRate(3000)); + CHECK(3 * feeRate == CFeeRate(3000)); + CHECK(feeRate * 3 == CFeeRate(3000)); // check multiplying by a negative integer - BOOST_CHECK(-3 * feeRate == CFeeRate(-3000)); - BOOST_CHECK(feeRate * -3 == CFeeRate(-3000)); + CHECK(-3 * feeRate == CFeeRate(-3000)); + CHECK(feeRate * -3 == CFeeRate(-3000)); // check commutativity - BOOST_CHECK(2 * feeRate == feeRate * 2); + CHECK(2 * feeRate == feeRate * 2); // check with large numbers int largeNumber = 1000000; - BOOST_CHECK(largeNumber * feeRate == feeRate * largeNumber); + CHECK(largeNumber * feeRate == feeRate * largeNumber); // check boundary values int maxInt = std::numeric_limits::max(); feeRate = CFeeRate(maxInt); - BOOST_CHECK(feeRate * 2 == CFeeRate(static_cast(maxInt) * 2)); - BOOST_CHECK(2 * feeRate == CFeeRate(static_cast(maxInt) * 2)); + CHECK(feeRate * 2 == CFeeRate(static_cast(maxInt) * 2)); + CHECK(2 * feeRate == CFeeRate(static_cast(maxInt) * 2)); // check with zero fee rate feeRate = CFeeRate(0); - BOOST_CHECK(feeRate * 5 == CFeeRate(0)); - BOOST_CHECK(5 * feeRate == CFeeRate(0)); + CHECK(feeRate * 5 == CFeeRate(0)); + CHECK(5 * feeRate == CFeeRate(0)); } -BOOST_AUTO_TEST_CASE(BinaryOperatorTest) +TEST_CASE("BinaryOperatorTest") { CFeeRate a, b; a = CFeeRate(1); b = CFeeRate(2); - BOOST_CHECK(a < b); - BOOST_CHECK(b > a); - BOOST_CHECK(a == a); - BOOST_CHECK(a <= b); - BOOST_CHECK(a <= a); - BOOST_CHECK(b >= a); - BOOST_CHECK(b >= b); + CHECK(a < b); + CHECK(b > a); + CHECK(a == a); + CHECK(a <= b); + CHECK(a <= a); + CHECK(b >= a); + CHECK(b >= b); // a should be 0.00000002 BTC/kvB now a += a; - BOOST_CHECK(a == b); + CHECK(a == b); } -BOOST_AUTO_TEST_CASE(ToStringTest) +TEST_CASE("ToStringTest") { CFeeRate feeRate; feeRate = CFeeRate(1); - BOOST_CHECK_EQUAL(feeRate.ToString(), "0.00000001 BTC/kvB"); - BOOST_CHECK_EQUAL(feeRate.ToString(FeeRateFormat::BTC_KVB), "0.00000001 BTC/kvB"); - BOOST_CHECK_EQUAL(feeRate.ToString(FeeRateFormat::SAT_VB), "0.001 sat/vB"); + CHECK(feeRate.ToString() == "0.00000001 BTC/kvB"); + CHECK(feeRate.ToString(FeeRateFormat::BTC_KVB) == "0.00000001 BTC/kvB"); + CHECK(feeRate.ToString(FeeRateFormat::SAT_VB) == "0.001 sat/vB"); } -BOOST_AUTO_TEST_SUITE_END() +TEST_SUITE_END() diff --git a/src/test/argsman_tests.cpp b/src/test/argsman_tests.cpp index c8802d3641ca..e8bf783718ef 100644 --- a/src/test/argsman_tests.cpp +++ b/src/test/argsman_tests.cpp @@ -18,13 +18,13 @@ #include #include -#include +#include using util::ToString; -BOOST_FIXTURE_TEST_SUITE(argsman_tests, BasicTestingSetup) +TEST_SUITE_BEGIN("argsman_tests") -BOOST_AUTO_TEST_CASE(util_datadir) +FIXTURE_TEST_CASE("util_datadir", BasicTestingSetup) { // Use local args variable instead of m_args to avoid making assumptions about test setup ArgsManager args; @@ -34,26 +34,26 @@ BOOST_AUTO_TEST_CASE(util_datadir) args.ForceSetArg("-datadir", fs::PathToString(dd_norm) + "/"); args.ClearPathCache(); - BOOST_CHECK_EQUAL(dd_norm, args.GetDataDirBase()); + CHECK(dd_norm == args.GetDataDirBase()); args.ForceSetArg("-datadir", fs::PathToString(dd_norm) + "/."); args.ClearPathCache(); - BOOST_CHECK_EQUAL(dd_norm, args.GetDataDirBase()); + CHECK(dd_norm == args.GetDataDirBase()); args.ForceSetArg("-datadir", fs::PathToString(dd_norm) + "/./"); args.ClearPathCache(); - BOOST_CHECK_EQUAL(dd_norm, args.GetDataDirBase()); + CHECK(dd_norm == args.GetDataDirBase()); args.ForceSetArg("-datadir", fs::PathToString(dd_norm) + "/.//"); args.ClearPathCache(); - BOOST_CHECK_EQUAL(dd_norm, args.GetDataDirBase()); + CHECK(dd_norm == args.GetDataDirBase()); } struct TestArgsManager : public ArgsManager { void ReadConfigString(const std::string& str_config) { - BOOST_REQUIRE(ArgsManager::ReadConfigString(str_config)); + REQUIRE(ArgsManager::ReadConfigString(str_config)); } void SetupArgs(const std::vector>& args) { @@ -100,59 +100,59 @@ class CheckValueTest : public TestChain100Setup std::string error; bool success = test.ParseParameters(arg ? 2 : 1, argv, error); - BOOST_CHECK_EQUAL(test.GetSetting("-value").write(), expect.setting.write()); + CHECK(test.GetSetting("-value").write() == expect.setting.write()); auto settings_list = test.GetSettingsList("-value"); if (expect.setting.isNull() || expect.setting.isFalse()) { - BOOST_CHECK_EQUAL(settings_list.size(), 0U); + CHECK(settings_list.size() == 0U); } else { - BOOST_CHECK_EQUAL(settings_list.size(), 1U); - BOOST_CHECK_EQUAL(settings_list[0].write(), expect.setting.write()); + CHECK(settings_list.size() == 1U); + CHECK(settings_list[0].write() == expect.setting.write()); } if (expect.error) { - BOOST_CHECK(!success); - BOOST_CHECK_NE(error.find(expect.error), std::string::npos); + CHECK(!success); + CHECK(error.find(expect.error) != std::string::npos); } else { - BOOST_CHECK(success); - BOOST_CHECK_EQUAL(error, ""); + CHECK(success); + CHECK(error == ""); } if (expect.default_string) { - BOOST_CHECK_EQUAL(test.GetArg("-value", "zzzzz"), "zzzzz"); + CHECK(test.GetArg("-value", "zzzzz") == "zzzzz"); } else if (expect.string_value) { - BOOST_CHECK_EQUAL(test.GetArg("-value", "zzzzz"), expect.string_value); + CHECK(test.GetArg("-value", "zzzzz") == expect.string_value); } else { - BOOST_CHECK(!success); + CHECK(!success); } if (expect.default_int) { - BOOST_CHECK_EQUAL(test.GetIntArg("-value", 99999), 99999); + CHECK(test.GetIntArg("-value", 99999) == 99999); } else if (expect.int_value) { - BOOST_CHECK_EQUAL(test.GetIntArg("-value", 99999), *expect.int_value); + CHECK(test.GetIntArg("-value", 99999) == *expect.int_value); } else { - BOOST_CHECK(!success); + CHECK(!success); } if (expect.default_bool) { - BOOST_CHECK_EQUAL(test.GetBoolArg("-value", false), false); - BOOST_CHECK_EQUAL(test.GetBoolArg("-value", true), true); + CHECK(test.GetBoolArg("-value", false) == false); + CHECK(test.GetBoolArg("-value", true) == true); } else if (expect.bool_value) { - BOOST_CHECK_EQUAL(test.GetBoolArg("-value", false), *expect.bool_value); - BOOST_CHECK_EQUAL(test.GetBoolArg("-value", true), *expect.bool_value); + CHECK(test.GetBoolArg("-value", false) == *expect.bool_value); + CHECK(test.GetBoolArg("-value", true) == *expect.bool_value); } else { - BOOST_CHECK(!success); + CHECK(!success); } if (expect.list_value) { auto l = test.GetArgs("-value"); - BOOST_CHECK_EQUAL_COLLECTIONS(l.begin(), l.end(), expect.list_value->begin(), expect.list_value->end()); + CHECK(l == *expect.list_value); } else { - BOOST_CHECK(!success); + CHECK(!success); } } }; -BOOST_FIXTURE_TEST_CASE(util_CheckValue, CheckValueTest) +FIXTURE_TEST_CASE("util_CheckValue", CheckValueTest) { using M = ArgsManager; @@ -183,14 +183,14 @@ struct NoIncludeConfTest { } }; -BOOST_FIXTURE_TEST_CASE(util_NoIncludeConf, NoIncludeConfTest) +FIXTURE_TEST_CASE("util_NoIncludeConf", NoIncludeConfTest) { - BOOST_CHECK_EQUAL(Parse("-noincludeconf"), ""); - BOOST_CHECK_EQUAL(Parse("-includeconf"), "-includeconf cannot be used from commandline; -includeconf=\"\""); - BOOST_CHECK_EQUAL(Parse("-includeconf=file"), "-includeconf cannot be used from commandline; -includeconf=\"file\""); + CHECK(Parse("-noincludeconf") == ""); + CHECK(Parse("-includeconf") == "-includeconf cannot be used from commandline; -includeconf=\"\""); + CHECK(Parse("-includeconf=file") == "-includeconf cannot be used from commandline; -includeconf=\"file\""); } -BOOST_AUTO_TEST_CASE(util_ParseParameters) +FIXTURE_TEST_CASE("util_ParseParameters", BasicTestingSetup) { TestArgsManager testArgs; const auto a = std::make_pair("-a", ArgsManager::ALLOW_ANY); @@ -202,55 +202,64 @@ BOOST_AUTO_TEST_CASE(util_ParseParameters) std::string error; testArgs.SetupArgs({a, b, ccc, d}); - BOOST_CHECK(testArgs.ParseParameters(0, argv_test, error)); + CHECK(testArgs.ParseParameters(0, argv_test, error)); testArgs.LockSettings([&](const common::Settings& s) { - BOOST_CHECK(s.command_line_options.empty() && s.ro_config.empty()); + CHECK(s.command_line_options.empty()); + CHECK(s.ro_config.empty()); }); - BOOST_CHECK(testArgs.ParseParameters(1, argv_test, error)); + CHECK(testArgs.ParseParameters(1, argv_test, error)); testArgs.LockSettings([&](const common::Settings& s) { - BOOST_CHECK(s.command_line_options.empty() && s.ro_config.empty()); + CHECK(s.command_line_options.empty()); + CHECK(s.ro_config.empty()); }); - BOOST_CHECK(testArgs.ParseParameters(7, argv_test, error)); + CHECK(testArgs.ParseParameters(7, argv_test, error)); // expectation: -ignored is ignored (program name argument), // -a, -b and -ccc end up in map, -d ignored because it is after // a non-option argument (non-GNU option parsing) - BOOST_CHECK(testArgs.IsArgSet("-a") && testArgs.IsArgSet("-b") && testArgs.IsArgSet("-ccc") - && !testArgs.IsArgSet("f") && !testArgs.IsArgSet("-d")); + CHECK(testArgs.IsArgSet("-a")); + CHECK(testArgs.IsArgSet("-b")); + CHECK(testArgs.IsArgSet("-ccc")); + CHECK(!testArgs.IsArgSet("f")); + CHECK(!testArgs.IsArgSet("-d")); testArgs.LockSettings([&](const common::Settings& s) { - BOOST_CHECK(s.command_line_options.size() == 3 && s.ro_config.empty()); - BOOST_CHECK(s.command_line_options.contains("a") && s.command_line_options.contains("b") && s.command_line_options.contains("ccc") - && !s.command_line_options.contains("f") && !s.command_line_options.contains("d")); - - BOOST_CHECK(s.command_line_options.at("a").size() == 1); - BOOST_CHECK(s.command_line_options.at("a").front().get_str() == ""); - BOOST_CHECK(s.command_line_options.at("ccc").size() == 2); - BOOST_CHECK(s.command_line_options.at("ccc").front().get_str() == "argument"); - BOOST_CHECK(s.command_line_options.at("ccc").back().get_str() == "multiple"); + CHECK(s.command_line_options.size() == 3U); + CHECK(s.ro_config.empty()); + CHECK(s.command_line_options.contains("a")); + CHECK(s.command_line_options.contains("b")); + CHECK(s.command_line_options.contains("ccc")); + CHECK(!s.command_line_options.contains("f")); + CHECK(!s.command_line_options.contains("d")); + + CHECK(s.command_line_options.at("a").size() == 1U); + CHECK(s.command_line_options.at("a").front().get_str() == ""); + CHECK(s.command_line_options.at("ccc").size() == 2U); + CHECK(s.command_line_options.at("ccc").front().get_str() == "argument"); + CHECK(s.command_line_options.at("ccc").back().get_str() == "multiple"); }); - BOOST_CHECK(testArgs.GetArgs("-ccc").size() == 2); + CHECK(testArgs.GetArgs("-ccc").size() == 2U); } -BOOST_AUTO_TEST_CASE(util_ParseInvalidParameters) +FIXTURE_TEST_CASE("util_ParseInvalidParameters", BasicTestingSetup) { TestArgsManager test; test.SetupArgs({{"-registered", ArgsManager::ALLOW_ANY}}); const char* argv[] = {"ignored", "-registered"}; std::string error; - BOOST_CHECK(test.ParseParameters(2, argv, error)); - BOOST_CHECK_EQUAL(error, ""); + CHECK(test.ParseParameters(2, argv, error)); + CHECK(error == ""); argv[1] = "-unregistered"; - BOOST_CHECK(!test.ParseParameters(2, argv, error)); - BOOST_CHECK_EQUAL(error, "Invalid parameter -unregistered"); + CHECK(!test.ParseParameters(2, argv, error)); + CHECK(error == "Invalid parameter -unregistered"); // Make sure registered parameters prefixed with a chain type trigger errors. // (Previously, they were accepted and ignored.) argv[1] = "-test.registered"; - BOOST_CHECK(!test.ParseParameters(2, argv, error)); - BOOST_CHECK_EQUAL(error, "Invalid parameter -test.registered"); + CHECK(!test.ParseParameters(2, argv, error)); + CHECK(error == "Invalid parameter -test.registered"); } static void TestParse(const std::string& str, bool expected_bool, int64_t expected_int) @@ -260,15 +269,15 @@ static void TestParse(const std::string& str, bool expected_bool, int64_t expect std::string arg = "-value=" + str; const char* argv[] = {"ignored", arg.c_str()}; std::string error; - BOOST_CHECK(test.ParseParameters(2, argv, error)); - BOOST_CHECK_EQUAL(test.GetBoolArg("-value", false), expected_bool); - BOOST_CHECK_EQUAL(test.GetBoolArg("-value", true), expected_bool); - BOOST_CHECK_EQUAL(test.GetIntArg("-value", 99998), expected_int); - BOOST_CHECK_EQUAL(test.GetIntArg("-value", 99999), expected_int); + CHECK(test.ParseParameters(2, argv, error)); + CHECK(test.GetBoolArg("-value", false) == expected_bool); + CHECK(test.GetBoolArg("-value", true) == expected_bool); + CHECK(test.GetIntArg("-value", 99998) == expected_int); + CHECK(test.GetIntArg("-value", 99999) == expected_int); } // Test bool and int parsing. -BOOST_AUTO_TEST_CASE(util_ArgParsing) +FIXTURE_TEST_CASE("util_ArgParsing", BasicTestingSetup) { // Some of these cases could be ambiguous or surprising to users, and might // be worth triggering errors or warnings in the future. But for now basic @@ -307,7 +316,7 @@ BOOST_AUTO_TEST_CASE(util_ArgParsing) TestParse("no", false, 0); } -BOOST_AUTO_TEST_CASE(util_GetBoolArg) +FIXTURE_TEST_CASE("util_GetBoolArg", BasicTestingSetup) { TestArgsManager testArgs; const auto a = std::make_pair("-a", ArgsManager::ALLOW_ANY); @@ -321,34 +330,35 @@ BOOST_AUTO_TEST_CASE(util_GetBoolArg) "ignored", "-a", "-nob", "-c=0", "-d=1", "-e=false", "-f=true"}; std::string error; testArgs.SetupArgs({a, b, c, d, e, f}); - BOOST_CHECK(testArgs.ParseParameters(7, argv_test, error)); + CHECK(testArgs.ParseParameters(7, argv_test, error)); // Each letter should be set. for (const char opt : "abcdef") - BOOST_CHECK(testArgs.IsArgSet({'-', opt}) || !opt); + CHECK((testArgs.IsArgSet({'-', opt}) || !opt)); // Nothing else should be in the map testArgs.LockSettings([&](const common::Settings& s) { - BOOST_CHECK(s.command_line_options.size() == 6 && s.ro_config.empty()); + CHECK(s.command_line_options.size() == 6U); + CHECK(s.ro_config.empty()); }); // The -no prefix should get stripped on the way in. - BOOST_CHECK(!testArgs.IsArgSet("-nob")); + CHECK(!testArgs.IsArgSet("-nob")); // The -b option is flagged as negated, and nothing else is - BOOST_CHECK(testArgs.IsArgNegated("-b")); - BOOST_CHECK(!testArgs.IsArgNegated("-a")); + CHECK(testArgs.IsArgNegated("-b")); + CHECK(!testArgs.IsArgNegated("-a")); // Check expected values. - BOOST_CHECK(testArgs.GetBoolArg("-a", false) == true); - BOOST_CHECK(testArgs.GetBoolArg("-b", true) == false); - BOOST_CHECK(testArgs.GetBoolArg("-c", true) == false); - BOOST_CHECK(testArgs.GetBoolArg("-d", false) == true); - BOOST_CHECK(testArgs.GetBoolArg("-e", true) == false); - BOOST_CHECK(testArgs.GetBoolArg("-f", true) == false); + CHECK(testArgs.GetBoolArg("-a", false) == true); + CHECK(testArgs.GetBoolArg("-b", true) == false); + CHECK(testArgs.GetBoolArg("-c", true) == false); + CHECK(testArgs.GetBoolArg("-d", false) == true); + CHECK(testArgs.GetBoolArg("-e", true) == false); + CHECK(testArgs.GetBoolArg("-f", true) == false); } -BOOST_AUTO_TEST_CASE(util_GetBoolArgEdgeCases) +FIXTURE_TEST_CASE("util_GetBoolArgEdgeCases", BasicTestingSetup) { // Test some awful edge cases that hopefully no user will ever exercise. TestArgsManager testArgs; @@ -359,49 +369,49 @@ BOOST_AUTO_TEST_CASE(util_GetBoolArgEdgeCases) const char *argv_test[] = {"ignored", "-nofoo", "-foo", "-nobar=0"}; testArgs.SetupArgs({foo, bar}); std::string error; - BOOST_CHECK(testArgs.ParseParameters(4, argv_test, error)); + CHECK(testArgs.ParseParameters(4, argv_test, error)); // This was passed twice, second one overrides the negative setting. - BOOST_CHECK(!testArgs.IsArgNegated("-foo")); - BOOST_CHECK(testArgs.GetArg("-foo", "xxx") == ""); + CHECK(!testArgs.IsArgNegated("-foo")); + CHECK(testArgs.GetArg("-foo", "xxx") == ""); // A double negative is a positive, and not marked as negated. - BOOST_CHECK(!testArgs.IsArgNegated("-bar")); - BOOST_CHECK(testArgs.GetArg("-bar", "xxx") == "1"); + CHECK(!testArgs.IsArgNegated("-bar")); + CHECK(testArgs.GetArg("-bar", "xxx") == "1"); // Config test const char *conf_test = "nofoo=1\nfoo=1\nnobar=0\n"; - BOOST_CHECK(testArgs.ParseParameters(1, argv_test, error)); + CHECK(testArgs.ParseParameters(1, argv_test, error)); testArgs.ReadConfigString(conf_test); // This was passed twice, second one overrides the negative setting, // and the value. - BOOST_CHECK(!testArgs.IsArgNegated("-foo")); - BOOST_CHECK(testArgs.GetArg("-foo", "xxx") == "1"); + CHECK(!testArgs.IsArgNegated("-foo")); + CHECK(testArgs.GetArg("-foo", "xxx") == "1"); // A double negative is a positive, and does not count as negated. - BOOST_CHECK(!testArgs.IsArgNegated("-bar")); - BOOST_CHECK(testArgs.GetArg("-bar", "xxx") == "1"); + CHECK(!testArgs.IsArgNegated("-bar")); + CHECK(testArgs.GetArg("-bar", "xxx") == "1"); // Combined test const char *combo_test_args[] = {"ignored", "-nofoo", "-bar"}; const char *combo_test_conf = "foo=1\nnobar=1\n"; - BOOST_CHECK(testArgs.ParseParameters(3, combo_test_args, error)); + CHECK(testArgs.ParseParameters(3, combo_test_args, error)); testArgs.ReadConfigString(combo_test_conf); // Command line overrides, but doesn't erase old setting - BOOST_CHECK(testArgs.IsArgNegated("-foo")); - BOOST_CHECK(testArgs.GetArg("-foo", "xxx") == "0"); - BOOST_CHECK(testArgs.GetArgs("-foo").size() == 0); + CHECK(testArgs.IsArgNegated("-foo")); + CHECK(testArgs.GetArg("-foo", "xxx") == "0"); + CHECK(testArgs.GetArgs("-foo").size() == 0U); // Command line overrides, but doesn't erase old setting - BOOST_CHECK(!testArgs.IsArgNegated("-bar")); - BOOST_CHECK(testArgs.GetArg("-bar", "xxx") == ""); - BOOST_CHECK(testArgs.GetArgs("-bar").size() == 1 - && testArgs.GetArgs("-bar").front() == ""); + CHECK(!testArgs.IsArgNegated("-bar")); + CHECK(testArgs.GetArg("-bar", "xxx") == ""); + CHECK(testArgs.GetArgs("-bar").size() == 1U); + CHECK(testArgs.GetArgs("-bar").front() == ""); } -BOOST_AUTO_TEST_CASE(util_ReadConfigStream) +FIXTURE_TEST_CASE("util_ReadConfigStream", BasicTestingSetup) { const char *str_config = "a=\n" @@ -443,129 +453,129 @@ BOOST_AUTO_TEST_CASE(util_ReadConfigStream) // so do sec1.ccc, sec1.d, sec1.h, sec2.ccc, sec2.iii test_args.LockSettings([&](const common::Settings& s) { - BOOST_CHECK(s.command_line_options.empty()); - BOOST_CHECK(s.ro_config.size() == 3); - BOOST_CHECK(s.ro_config.at("").size() == 8); - BOOST_CHECK(s.ro_config.at("sec1").size() == 3); - BOOST_CHECK(s.ro_config.at("sec2").size() == 2); - - BOOST_CHECK(s.ro_config.at("").contains("a")); - BOOST_CHECK(s.ro_config.at("").contains("b")); - BOOST_CHECK(s.ro_config.at("").contains("ccc")); - BOOST_CHECK(s.ro_config.at("").contains("d")); - BOOST_CHECK(s.ro_config.at("").contains("fff")); - BOOST_CHECK(s.ro_config.at("").contains("ggg")); - BOOST_CHECK(s.ro_config.at("").contains("h")); - BOOST_CHECK(s.ro_config.at("").contains("i")); - BOOST_CHECK(s.ro_config.at("sec1").contains("ccc")); - BOOST_CHECK(s.ro_config.at("sec1").contains("h")); - BOOST_CHECK(s.ro_config.at("sec2").contains("ccc")); - BOOST_CHECK(s.ro_config.at("sec2").contains("iii")); + CHECK(s.command_line_options.empty()); + CHECK(s.ro_config.size() == 3U); + CHECK(s.ro_config.at("").size() == 8U); + CHECK(s.ro_config.at("sec1").size() == 3U); + CHECK(s.ro_config.at("sec2").size() == 2U); + + CHECK(s.ro_config.at("").contains("a")); + CHECK(s.ro_config.at("").contains("b")); + CHECK(s.ro_config.at("").contains("ccc")); + CHECK(s.ro_config.at("").contains("d")); + CHECK(s.ro_config.at("").contains("fff")); + CHECK(s.ro_config.at("").contains("ggg")); + CHECK(s.ro_config.at("").contains("h")); + CHECK(s.ro_config.at("").contains("i")); + CHECK(s.ro_config.at("sec1").contains("ccc")); + CHECK(s.ro_config.at("sec1").contains("h")); + CHECK(s.ro_config.at("sec2").contains("ccc")); + CHECK(s.ro_config.at("sec2").contains("iii")); }); - BOOST_CHECK(test_args.IsArgSet("-a")); - BOOST_CHECK(test_args.IsArgSet("-b")); - BOOST_CHECK(test_args.IsArgSet("-ccc")); - BOOST_CHECK(test_args.IsArgSet("-d")); - BOOST_CHECK(test_args.IsArgSet("-fff")); - BOOST_CHECK(test_args.IsArgSet("-ggg")); - BOOST_CHECK(test_args.IsArgSet("-h")); - BOOST_CHECK(test_args.IsArgSet("-i")); - BOOST_CHECK(!test_args.IsArgSet("-zzz")); - BOOST_CHECK(!test_args.IsArgSet("-iii")); - - BOOST_CHECK_EQUAL(test_args.GetArg("-a", "xxx"), ""); - BOOST_CHECK_EQUAL(test_args.GetArg("-b", "xxx"), "1"); - BOOST_CHECK_EQUAL(test_args.GetArg("-ccc", "xxx"), "argument"); - BOOST_CHECK_EQUAL(test_args.GetArg("-d", "xxx"), "e"); - BOOST_CHECK_EQUAL(test_args.GetArg("-fff", "xxx"), "0"); - BOOST_CHECK_EQUAL(test_args.GetArg("-ggg", "xxx"), "1"); - BOOST_CHECK_EQUAL(test_args.GetArg("-h", "xxx"), "0"); - BOOST_CHECK_EQUAL(test_args.GetArg("-i", "xxx"), "1"); - BOOST_CHECK_EQUAL(test_args.GetArg("-zzz", "xxx"), "xxx"); - BOOST_CHECK_EQUAL(test_args.GetArg("-iii", "xxx"), "xxx"); + CHECK(test_args.IsArgSet("-a")); + CHECK(test_args.IsArgSet("-b")); + CHECK(test_args.IsArgSet("-ccc")); + CHECK(test_args.IsArgSet("-d")); + CHECK(test_args.IsArgSet("-fff")); + CHECK(test_args.IsArgSet("-ggg")); + CHECK(test_args.IsArgSet("-h")); + CHECK(test_args.IsArgSet("-i")); + CHECK(!test_args.IsArgSet("-zzz")); + CHECK(!test_args.IsArgSet("-iii")); + + CHECK(test_args.GetArg("-a", "xxx") == ""); + CHECK(test_args.GetArg("-b", "xxx") == "1"); + CHECK(test_args.GetArg("-ccc", "xxx") == "argument"); + CHECK(test_args.GetArg("-d", "xxx") == "e"); + CHECK(test_args.GetArg("-fff", "xxx") == "0"); + CHECK(test_args.GetArg("-ggg", "xxx") == "1"); + CHECK(test_args.GetArg("-h", "xxx") == "0"); + CHECK(test_args.GetArg("-i", "xxx") == "1"); + CHECK(test_args.GetArg("-zzz", "xxx") == "xxx"); + CHECK(test_args.GetArg("-iii", "xxx") == "xxx"); for (const bool def : {false, true}) { - BOOST_CHECK(test_args.GetBoolArg("-a", def)); - BOOST_CHECK(test_args.GetBoolArg("-b", def)); - BOOST_CHECK(!test_args.GetBoolArg("-ccc", def)); - BOOST_CHECK(!test_args.GetBoolArg("-d", def)); - BOOST_CHECK(!test_args.GetBoolArg("-fff", def)); - BOOST_CHECK(test_args.GetBoolArg("-ggg", def)); - BOOST_CHECK(!test_args.GetBoolArg("-h", def)); - BOOST_CHECK(test_args.GetBoolArg("-i", def)); - BOOST_CHECK(test_args.GetBoolArg("-zzz", def) == def); - BOOST_CHECK(test_args.GetBoolArg("-iii", def) == def); + CHECK(test_args.GetBoolArg("-a", def)); + CHECK(test_args.GetBoolArg("-b", def)); + CHECK(!test_args.GetBoolArg("-ccc", def)); + CHECK(!test_args.GetBoolArg("-d", def)); + CHECK(!test_args.GetBoolArg("-fff", def)); + CHECK(test_args.GetBoolArg("-ggg", def)); + CHECK(!test_args.GetBoolArg("-h", def)); + CHECK(test_args.GetBoolArg("-i", def)); + CHECK(test_args.GetBoolArg("-zzz", def) == def); + CHECK(test_args.GetBoolArg("-iii", def) == def); } - BOOST_CHECK(test_args.GetArgs("-a").size() == 1 - && test_args.GetArgs("-a").front() == ""); - BOOST_CHECK(test_args.GetArgs("-b").size() == 1 - && test_args.GetArgs("-b").front() == "1"); - BOOST_CHECK(test_args.GetArgs("-ccc").size() == 2 - && test_args.GetArgs("-ccc").front() == "argument" - && test_args.GetArgs("-ccc").back() == "multiple"); - BOOST_CHECK(test_args.GetArgs("-fff").size() == 0); - BOOST_CHECK(test_args.GetArgs("-nofff").size() == 0); - BOOST_CHECK(test_args.GetArgs("-ggg").size() == 1 - && test_args.GetArgs("-ggg").front() == "1"); - BOOST_CHECK(test_args.GetArgs("-noggg").size() == 0); - BOOST_CHECK(test_args.GetArgs("-h").size() == 0); - BOOST_CHECK(test_args.GetArgs("-noh").size() == 0); - BOOST_CHECK(test_args.GetArgs("-i").size() == 1 - && test_args.GetArgs("-i").front() == "1"); - BOOST_CHECK(test_args.GetArgs("-noi").size() == 0); - BOOST_CHECK(test_args.GetArgs("-zzz").size() == 0); - - BOOST_CHECK(!test_args.IsArgNegated("-a")); - BOOST_CHECK(!test_args.IsArgNegated("-b")); - BOOST_CHECK(!test_args.IsArgNegated("-ccc")); - BOOST_CHECK(!test_args.IsArgNegated("-d")); - BOOST_CHECK(test_args.IsArgNegated("-fff")); - BOOST_CHECK(!test_args.IsArgNegated("-ggg")); - BOOST_CHECK(test_args.IsArgNegated("-h")); // last setting takes precedence - BOOST_CHECK(!test_args.IsArgNegated("-i")); // last setting takes precedence - BOOST_CHECK(!test_args.IsArgNegated("-zzz")); + CHECK(test_args.GetArgs("-a").size() == 1); + CHECK(test_args.GetArgs("-a").front() == ""); + CHECK(test_args.GetArgs("-b").size() == 1); + CHECK(test_args.GetArgs("-b").front() == "1"); + CHECK(test_args.GetArgs("-ccc").size() == 2); + CHECK(test_args.GetArgs("-ccc").front() == "argument"); + CHECK(test_args.GetArgs("-ccc").back() == "multiple"); + CHECK(test_args.GetArgs("-fff").size() == 0); + CHECK(test_args.GetArgs("-nofff").size() == 0); + CHECK(test_args.GetArgs("-ggg").size() == 1); + CHECK(test_args.GetArgs("-ggg").front() == "1"); + CHECK(test_args.GetArgs("-noggg").size() == 0); + CHECK(test_args.GetArgs("-h").size() == 0); + CHECK(test_args.GetArgs("-noh").size() == 0); + CHECK(test_args.GetArgs("-i").size() == 1); + CHECK(test_args.GetArgs("-i").front() == "1"); + CHECK(test_args.GetArgs("-noi").size() == 0); + CHECK(test_args.GetArgs("-zzz").size() == 0); + + CHECK(!test_args.IsArgNegated("-a")); + CHECK(!test_args.IsArgNegated("-b")); + CHECK(!test_args.IsArgNegated("-ccc")); + CHECK(!test_args.IsArgNegated("-d")); + CHECK(test_args.IsArgNegated("-fff")); + CHECK(!test_args.IsArgNegated("-ggg")); + CHECK(test_args.IsArgNegated("-h")); // last setting takes precedence + CHECK(!test_args.IsArgNegated("-i")); // last setting takes precedence + CHECK(!test_args.IsArgNegated("-zzz")); // Test sections work test_args.SelectConfigNetwork("sec1"); // same as original - BOOST_CHECK_EQUAL(test_args.GetArg("-a", "xxx"), ""); - BOOST_CHECK_EQUAL(test_args.GetArg("-b", "xxx"), "1"); - BOOST_CHECK_EQUAL(test_args.GetArg("-fff", "xxx"), "0"); - BOOST_CHECK_EQUAL(test_args.GetArg("-ggg", "xxx"), "1"); - BOOST_CHECK_EQUAL(test_args.GetArg("-zzz", "xxx"), "xxx"); - BOOST_CHECK_EQUAL(test_args.GetArg("-iii", "xxx"), "xxx"); + CHECK(test_args.GetArg("-a", "xxx") == ""); + CHECK(test_args.GetArg("-b", "xxx") == "1"); + CHECK(test_args.GetArg("-fff", "xxx") == "0"); + CHECK(test_args.GetArg("-ggg", "xxx") == "1"); + CHECK(test_args.GetArg("-zzz", "xxx") == "xxx"); + CHECK(test_args.GetArg("-iii", "xxx") == "xxx"); // d is overridden - BOOST_CHECK(test_args.GetArg("-d", "xxx") == "eee"); + CHECK(test_args.GetArg("-d", "xxx") == "eee"); // section-specific setting - BOOST_CHECK(test_args.GetArg("-h", "xxx") == "1"); + CHECK(test_args.GetArg("-h", "xxx") == "1"); // section takes priority for multiple values - BOOST_CHECK(test_args.GetArg("-ccc", "xxx") == "extend1"); + CHECK(test_args.GetArg("-ccc", "xxx") == "extend1"); // check multiple values works const std::vector sec1_ccc_expected = {"extend1","extend2","argument","multiple"}; const auto& sec1_ccc_res = test_args.GetArgs("-ccc"); - BOOST_CHECK_EQUAL_COLLECTIONS(sec1_ccc_res.begin(), sec1_ccc_res.end(), sec1_ccc_expected.begin(), sec1_ccc_expected.end()); + CHECK(sec1_ccc_res == sec1_ccc_expected); test_args.SelectConfigNetwork("sec2"); // same as original - BOOST_CHECK(test_args.GetArg("-a", "xxx") == ""); - BOOST_CHECK(test_args.GetArg("-b", "xxx") == "1"); - BOOST_CHECK(test_args.GetArg("-d", "xxx") == "e"); - BOOST_CHECK(test_args.GetArg("-fff", "xxx") == "0"); - BOOST_CHECK(test_args.GetArg("-ggg", "xxx") == "1"); - BOOST_CHECK(test_args.GetArg("-zzz", "xxx") == "xxx"); - BOOST_CHECK(test_args.GetArg("-h", "xxx") == "0"); + CHECK(test_args.GetArg("-a", "xxx") == ""); + CHECK(test_args.GetArg("-b", "xxx") == "1"); + CHECK(test_args.GetArg("-d", "xxx") == "e"); + CHECK(test_args.GetArg("-fff", "xxx") == "0"); + CHECK(test_args.GetArg("-ggg", "xxx") == "1"); + CHECK(test_args.GetArg("-zzz", "xxx") == "xxx"); + CHECK(test_args.GetArg("-h", "xxx") == "0"); // section-specific setting - BOOST_CHECK(test_args.GetArg("-iii", "xxx") == "2"); + CHECK(test_args.GetArg("-iii", "xxx") == "2"); // section takes priority for multiple values - BOOST_CHECK(test_args.GetArg("-ccc", "xxx") == "extend3"); + CHECK(test_args.GetArg("-ccc", "xxx") == "extend3"); // check multiple values works const std::vector sec2_ccc_expected = {"extend3","argument","multiple"}; const auto& sec2_ccc_res = test_args.GetArgs("-ccc"); - BOOST_CHECK_EQUAL_COLLECTIONS(sec2_ccc_res.begin(), sec2_ccc_res.end(), sec2_ccc_expected.begin(), sec2_ccc_expected.end()); + CHECK(sec2_ccc_res == sec2_ccc_expected); // Test section only options @@ -577,24 +587,24 @@ BOOST_AUTO_TEST_CASE(util_ReadConfigStream) test_args.ReadConfigString(str_config); test_args.SelectConfigNetwork(ChainTypeToString(ChainType::MAIN)); - BOOST_CHECK(test_args.GetArg("-d", "xxx") == "e"); - BOOST_CHECK(test_args.GetArgs("-ccc").size() == 2); - BOOST_CHECK(test_args.GetArg("-h", "xxx") == "0"); + CHECK(test_args.GetArg("-d", "xxx") == "e"); + CHECK(test_args.GetArgs("-ccc").size() == 2); + CHECK(test_args.GetArg("-h", "xxx") == "0"); test_args.SelectConfigNetwork("sec1"); - BOOST_CHECK(test_args.GetArg("-d", "xxx") == "eee"); - BOOST_CHECK(test_args.GetArgs("-d").size() == 1); - BOOST_CHECK(test_args.GetArgs("-ccc").size() == 2); - BOOST_CHECK(test_args.GetArg("-h", "xxx") == "1"); + CHECK(test_args.GetArg("-d", "xxx") == "eee"); + CHECK(test_args.GetArgs("-d").size() == 1); + CHECK(test_args.GetArgs("-ccc").size() == 2); + CHECK(test_args.GetArg("-h", "xxx") == "1"); test_args.SelectConfigNetwork("sec2"); - BOOST_CHECK(test_args.GetArg("-d", "xxx") == "xxx"); - BOOST_CHECK(test_args.GetArgs("-d").size() == 0); - BOOST_CHECK(test_args.GetArgs("-ccc").size() == 1); - BOOST_CHECK(test_args.GetArg("-h", "xxx") == "0"); + CHECK(test_args.GetArg("-d", "xxx") == "xxx"); + CHECK(test_args.GetArgs("-d").size() == 0); + CHECK(test_args.GetArgs("-ccc").size() == 1); + CHECK(test_args.GetArg("-h", "xxx") == "0"); } -BOOST_AUTO_TEST_CASE(util_GetArg) +FIXTURE_TEST_CASE("util_GetArg", BasicTestingSetup) { TestArgsManager testArgs; testArgs.LockSettings([&](common::Settings& s) { @@ -618,23 +628,23 @@ BOOST_AUTO_TEST_CASE(util_GetArg) s.ro_config[""]["pritest4"] = {"c","d"}; }); - BOOST_CHECK_EQUAL(testArgs.GetArg("strtest1", "default"), "string..."); - BOOST_CHECK_EQUAL(testArgs.GetArg("strtest2", "default"), "default"); - BOOST_CHECK_EQUAL(testArgs.GetIntArg("inttest1", -1), 12345); - BOOST_CHECK_EQUAL(testArgs.GetIntArg("inttest2", -1), 81985529216486895LL); - BOOST_CHECK_EQUAL(testArgs.GetIntArg("inttest3", -1), -1); - BOOST_CHECK_EQUAL(testArgs.GetBoolArg("booltest1", false), true); - BOOST_CHECK_EQUAL(testArgs.GetBoolArg("booltest2", false), false); - BOOST_CHECK_EQUAL(testArgs.GetBoolArg("booltest3", false), false); - BOOST_CHECK_EQUAL(testArgs.GetBoolArg("booltest4", false), true); - - BOOST_CHECK_EQUAL(testArgs.GetArg("pritest1", "default"), "b"); - BOOST_CHECK_EQUAL(testArgs.GetArg("pritest2", "default"), "a"); - BOOST_CHECK_EQUAL(testArgs.GetArg("pritest3", "default"), "a"); - BOOST_CHECK_EQUAL(testArgs.GetArg("pritest4", "default"), "b"); + CHECK(testArgs.GetArg("strtest1", "default") == "string..."); + CHECK(testArgs.GetArg("strtest2", "default") == "default"); + CHECK(testArgs.GetIntArg("inttest1", -1) == 12345); + CHECK(testArgs.GetIntArg("inttest2", -1) == 81985529216486895LL); + CHECK(testArgs.GetIntArg("inttest3", -1) == -1); + CHECK(testArgs.GetBoolArg("booltest1", false) == true); + CHECK(testArgs.GetBoolArg("booltest2", false) == false); + CHECK(testArgs.GetBoolArg("booltest3", false) == false); + CHECK(testArgs.GetBoolArg("booltest4", false) == true); + + CHECK(testArgs.GetArg("pritest1", "default") == "b"); + CHECK(testArgs.GetArg("pritest2", "default") == "a"); + CHECK(testArgs.GetArg("pritest3", "default") == "a"); + CHECK(testArgs.GetArg("pritest4", "default") == "b"); } -BOOST_AUTO_TEST_CASE(util_GetChainTypeString) +FIXTURE_TEST_CASE("util_GetChainTypeString", BasicTestingSetup) { TestArgsManager test_args; const auto testnet = std::make_pair("-testnet", ArgsManager::ALLOW_ANY); @@ -651,67 +661,67 @@ BOOST_AUTO_TEST_CASE(util_GetChainTypeString) const char* testnetconf = "testnet4=1\nregtest=0\n[testnet4]\nregtest=1"; std::string error; - BOOST_CHECK(test_args.ParseParameters(0, argv_testnet4, error)); - BOOST_CHECK_EQUAL(test_args.GetChainTypeString(), "main"); + CHECK(test_args.ParseParameters(0, argv_testnet4, error)); + CHECK(test_args.GetChainTypeString() == "main"); - BOOST_CHECK(test_args.ParseParameters(0, argv_testnet4, error)); - BOOST_CHECK_EQUAL(test_args.GetChainTypeString(), "main"); + CHECK(test_args.ParseParameters(0, argv_testnet4, error)); + CHECK(test_args.GetChainTypeString() == "main"); - BOOST_CHECK(test_args.ParseParameters(2, argv_testnet4, error)); - BOOST_CHECK_EQUAL(test_args.GetChainTypeString(), "testnet4"); + CHECK(test_args.ParseParameters(2, argv_testnet4, error)); + CHECK(test_args.GetChainTypeString() == "testnet4"); - BOOST_CHECK(test_args.ParseParameters(2, argv_regtest, error)); - BOOST_CHECK_EQUAL(test_args.GetChainTypeString(), "regtest"); + CHECK(test_args.ParseParameters(2, argv_regtest, error)); + CHECK(test_args.GetChainTypeString() == "regtest"); - BOOST_CHECK(test_args.ParseParameters(3, argv_test_no_reg, error)); - BOOST_CHECK_EQUAL(test_args.GetChainTypeString(), "testnet4"); + CHECK(test_args.ParseParameters(3, argv_test_no_reg, error)); + CHECK(test_args.GetChainTypeString() == "testnet4"); - BOOST_CHECK(test_args.ParseParameters(3, argv_both, error)); - BOOST_CHECK_THROW(test_args.GetChainTypeString(), std::runtime_error); + CHECK(test_args.ParseParameters(3, argv_both, error)); + CHECK_THROWS_AS(test_args.GetChainTypeString(), std::runtime_error); - BOOST_CHECK(test_args.ParseParameters(0, argv_testnet4, error)); + CHECK(test_args.ParseParameters(0, argv_testnet4, error)); test_args.ReadConfigString(testnetconf); - BOOST_CHECK_EQUAL(test_args.GetChainTypeString(), "testnet4"); + CHECK(test_args.GetChainTypeString() == "testnet4"); - BOOST_CHECK(test_args.ParseParameters(2, argv_testnet4, error)); + CHECK(test_args.ParseParameters(2, argv_testnet4, error)); test_args.ReadConfigString(testnetconf); - BOOST_CHECK_EQUAL(test_args.GetChainTypeString(), "testnet4"); + CHECK(test_args.GetChainTypeString() == "testnet4"); - BOOST_CHECK(test_args.ParseParameters(2, argv_regtest, error)); + CHECK(test_args.ParseParameters(2, argv_regtest, error)); test_args.ReadConfigString(testnetconf); - BOOST_CHECK_THROW(test_args.GetChainTypeString(), std::runtime_error); + CHECK_THROWS_AS(test_args.GetChainTypeString(), std::runtime_error); - BOOST_CHECK(test_args.ParseParameters(3, argv_test_no_reg, error)); + CHECK(test_args.ParseParameters(3, argv_test_no_reg, error)); test_args.ReadConfigString(testnetconf); - BOOST_CHECK_EQUAL(test_args.GetChainTypeString(), "testnet4"); + CHECK(test_args.GetChainTypeString() == "testnet4"); - BOOST_CHECK(test_args.ParseParameters(3, argv_both, error)); + CHECK(test_args.ParseParameters(3, argv_both, error)); test_args.ReadConfigString(testnetconf); - BOOST_CHECK_THROW(test_args.GetChainTypeString(), std::runtime_error); + CHECK_THROWS_AS(test_args.GetChainTypeString(), std::runtime_error); // check setting the network to testnet4 (and thus making // [testnet4] regtest=1 potentially relevant) doesn't break things test_args.SelectConfigNetwork("testnet4"); - BOOST_CHECK(test_args.ParseParameters(0, argv_testnet4, error)); + CHECK(test_args.ParseParameters(0, argv_testnet4, error)); test_args.ReadConfigString(testnetconf); - BOOST_CHECK_EQUAL(test_args.GetChainTypeString(), "testnet4"); + CHECK(test_args.GetChainTypeString() == "testnet4"); - BOOST_CHECK(test_args.ParseParameters(2, argv_testnet4, error)); + CHECK(test_args.ParseParameters(2, argv_testnet4, error)); test_args.ReadConfigString(testnetconf); - BOOST_CHECK_EQUAL(test_args.GetChainTypeString(), "testnet4"); + CHECK(test_args.GetChainTypeString() == "testnet4"); - BOOST_CHECK(test_args.ParseParameters(2, argv_regtest, error)); + CHECK(test_args.ParseParameters(2, argv_regtest, error)); test_args.ReadConfigString(testnetconf); - BOOST_CHECK_THROW(test_args.GetChainTypeString(), std::runtime_error); + CHECK_THROWS_AS(test_args.GetChainTypeString(), std::runtime_error); - BOOST_CHECK(test_args.ParseParameters(2, argv_test_no_reg, error)); + CHECK(test_args.ParseParameters(2, argv_test_no_reg, error)); test_args.ReadConfigString(testnetconf); - BOOST_CHECK_EQUAL(test_args.GetChainTypeString(), "testnet4"); + CHECK(test_args.GetChainTypeString() == "testnet4"); - BOOST_CHECK(test_args.ParseParameters(3, argv_both, error)); + CHECK(test_args.ParseParameters(3, argv_both, error)); test_args.ReadConfigString(testnetconf); - BOOST_CHECK_THROW(test_args.GetChainTypeString(), std::runtime_error); + CHECK_THROWS_AS(test_args.GetChainTypeString(), std::runtime_error); } // Test different ways settings can be merged, and verify results. This test can @@ -797,7 +807,7 @@ struct ArgsMergeTestingSetup : public BasicTestingSetup { // test parses and merges settings, representing the results as strings that get // compared against an expected hash. To debug, the result strings can be dumped // to a file (see comments below). -BOOST_FIXTURE_TEST_CASE(util_ArgsMerge, ArgsMergeTestingSetup) +FIXTURE_TEST_CASE("util_ArgsMerge", ArgsMergeTestingSetup) { CHash256 out_sha; FILE* out_file = nullptr; @@ -829,8 +839,8 @@ BOOST_FIXTURE_TEST_CASE(util_ArgsMerge, ArgsMergeTestingSetup) argv.push_back(arg.c_str()); } std::string error; - BOOST_CHECK(parser.ParseParameters(argv.size(), argv.data(), error)); - BOOST_CHECK_EQUAL(error, ""); + CHECK(parser.ParseParameters(argv.size(), argv.data(), error)); + CHECK(error == ""); std::string conf; for (auto& conf_val : GetValues(conf_actions, section, name, "c")) { @@ -840,8 +850,8 @@ BOOST_FIXTURE_TEST_CASE(util_ArgsMerge, ArgsMergeTestingSetup) conf += "\n"; } std::istringstream conf_stream(conf); - BOOST_CHECK(parser.ReadConfigStream(conf_stream, "filepath", error)); - BOOST_CHECK_EQUAL(error, ""); + CHECK(parser.ReadConfigStream(conf_stream, "filepath", error)); + CHECK(error == ""); if (soft_set) { desc += " soft"; @@ -859,13 +869,13 @@ BOOST_FIXTURE_TEST_CASE(util_ArgsMerge, ArgsMergeTestingSetup) if (!parser.IsArgSet(key)) { desc += "unset"; - BOOST_CHECK(!parser.IsArgNegated(key)); - BOOST_CHECK_EQUAL(parser.GetArg(key, "default"), "default"); - BOOST_CHECK(parser.GetArgs(key).empty()); + CHECK(!parser.IsArgNegated(key)); + CHECK(parser.GetArg(key, "default") == "default"); + CHECK(parser.GetArgs(key).empty()); } else if (parser.IsArgNegated(key)) { desc += "negated"; - BOOST_CHECK_EQUAL(parser.GetArg(key, "default"), "0"); - BOOST_CHECK(parser.GetArgs(key).empty()); + CHECK(parser.GetArg(key, "default") == "0"); + CHECK(parser.GetArgs(key).empty()); } else { desc += parser.GetArg(key, "default"); desc += " |"; @@ -888,7 +898,7 @@ BOOST_FIXTURE_TEST_CASE(util_ArgsMerge, ArgsMergeTestingSetup) out_sha.Write(MakeUCharSpan(desc)); if (out_file) { - BOOST_REQUIRE(fwrite(desc.data(), 1, desc.size(), out_file) == desc.size()); + REQUIRE(fwrite(desc.data(), 1, desc.size(), out_file) == desc.size()); } }); @@ -910,7 +920,7 @@ BOOST_FIXTURE_TEST_CASE(util_ArgsMerge, ArgsMergeTestingSetup) // Results file is formatted like: // // || | | - BOOST_CHECK_EQUAL(out_sha_hex, "f1ee5ab094cc43d16a6086fa7f2c10389e0f99902616b31bbf29189972ad1473"); + CHECK(out_sha_hex == "f1ee5ab094cc43d16a6086fa7f2c10389e0f99902616b31bbf29189972ad1473"); } // Similar test as above, but for ArgsManager::GetChainTypeString function. @@ -932,7 +942,7 @@ struct ChainMergeTestingSetup : public BasicTestingSetup { } }; -BOOST_FIXTURE_TEST_CASE(util_ChainMerge, ChainMergeTestingSetup) +FIXTURE_TEST_CASE("util_ChainMerge", ChainMergeTestingSetup) { CHash256 out_sha; FILE* out_file = nullptr; @@ -963,8 +973,8 @@ BOOST_FIXTURE_TEST_CASE(util_ChainMerge, ChainMergeTestingSetup) desc += argv.back(); } std::string error; - BOOST_CHECK(parser.ParseParameters(argv.size(), argv.data(), error)); - BOOST_CHECK_EQUAL(error, ""); + CHECK(parser.ParseParameters(argv.size(), argv.data(), error)); + CHECK(error == ""); std::string conf; for (Action action : conf_actions) { @@ -976,8 +986,8 @@ BOOST_FIXTURE_TEST_CASE(util_ChainMerge, ChainMergeTestingSetup) conf += "\n"; } std::istringstream conf_stream(conf); - BOOST_CHECK(parser.ReadConfigStream(conf_stream, "filepath", error)); - BOOST_CHECK_EQUAL(error, ""); + CHECK(parser.ReadConfigStream(conf_stream, "filepath", error)); + CHECK(error == ""); desc += " || "; try { @@ -990,7 +1000,7 @@ BOOST_FIXTURE_TEST_CASE(util_ChainMerge, ChainMergeTestingSetup) out_sha.Write(MakeUCharSpan(desc)); if (out_file) { - BOOST_REQUIRE(fwrite(desc.data(), 1, desc.size(), out_file) == desc.size()); + REQUIRE(fwrite(desc.data(), 1, desc.size(), out_file) == desc.size()); } }); @@ -1012,10 +1022,10 @@ BOOST_FIXTURE_TEST_CASE(util_ChainMerge, ChainMergeTestingSetup) // Results file is formatted like: // // || - BOOST_CHECK_EQUAL(out_sha_hex, "c0e33aab0c74e040ddcee9edad59e8148d8e1cacb3cccd9ea1a1f485cb6bad21"); + CHECK(out_sha_hex == "c0e33aab0c74e040ddcee9edad59e8148d8e1cacb3cccd9ea1a1f485cb6bad21"); } -BOOST_AUTO_TEST_CASE(util_ReadWriteSettings) +FIXTURE_TEST_CASE("util_ReadWriteSettings", BasicTestingSetup) { // Test writing setting. TestArgsManager args1; @@ -1027,7 +1037,7 @@ BOOST_AUTO_TEST_CASE(util_ReadWriteSettings) TestArgsManager args2; args2.ForceSetArg("-datadir", fs::PathToString(m_path_root)); args2.ReadSettingsFile(); - args2.LockSettings([&](common::Settings& s) { BOOST_CHECK_EQUAL(s.rw_settings["name"].get_str(), "value"); }); + args2.LockSettings([&](common::Settings& s) { CHECK(s.rw_settings["name"].get_str() == "value"); }); // Test error logging, and remove previously written setting. { @@ -1039,4 +1049,4 @@ BOOST_AUTO_TEST_CASE(util_ReadWriteSettings) } } -BOOST_AUTO_TEST_SUITE_END() +TEST_SUITE_END() diff --git a/src/test/arith_uint256_tests.cpp b/src/test/arith_uint256_tests.cpp index 016b46587191..557922c479d4 100644 --- a/src/test/arith_uint256_tests.cpp +++ b/src/test/arith_uint256_tests.cpp @@ -6,7 +6,7 @@ #include #include -#include +#include #include #include @@ -16,7 +16,7 @@ #include #include -BOOST_AUTO_TEST_SUITE(arith_uint256_tests) +TEST_SUITE_BEGIN("arith_uint256_tests") /// Convert vector to arith_uint256, via uint256 blob static inline arith_uint256 arith_uint256V(const std::vector& vch) @@ -63,61 +63,61 @@ static std::string ArrayToString(const unsigned char A[], unsigned int width) return Stream.str(); } -BOOST_AUTO_TEST_CASE( basics ) // constructors, equality, inequality +TEST_CASE("basics") // constructors, equality, inequality { - BOOST_CHECK(1 == 0+1); + CHECK(1 == 0+1); // constructor arith_uint256(vector): - BOOST_CHECK(R1L.ToString() == ArrayToString(R1Array,32)); - BOOST_CHECK(R2L.ToString() == ArrayToString(R2Array,32)); - BOOST_CHECK(ZeroL.ToString() == ArrayToString(ZeroArray,32)); - BOOST_CHECK(OneL.ToString() == ArrayToString(OneArray,32)); - BOOST_CHECK(MaxL.ToString() == ArrayToString(MaxArray,32)); - BOOST_CHECK(OneL.ToString() != ArrayToString(ZeroArray,32)); + CHECK(R1L.ToString() == ArrayToString(R1Array,32)); + CHECK(R2L.ToString() == ArrayToString(R2Array,32)); + CHECK(ZeroL.ToString() == ArrayToString(ZeroArray,32)); + CHECK(OneL.ToString() == ArrayToString(OneArray,32)); + CHECK(MaxL.ToString() == ArrayToString(MaxArray,32)); + CHECK(OneL.ToString() != ArrayToString(ZeroArray,32)); // == and != - BOOST_CHECK(R1L != R2L); - BOOST_CHECK(ZeroL != OneL); - BOOST_CHECK(OneL != ZeroL); - BOOST_CHECK(MaxL != ZeroL); - BOOST_CHECK(~MaxL == ZeroL); - BOOST_CHECK( ((R1L ^ R2L) ^ R1L) == R2L); + CHECK(R1L != R2L); + CHECK(ZeroL != OneL); + CHECK(OneL != ZeroL); + CHECK(MaxL != ZeroL); + CHECK(~MaxL == ZeroL); + CHECK(((R1L ^ R2L) ^ R1L) == R2L); uint64_t Tmp64 = 0xc4dab720d9c7acaaULL; for (unsigned int i = 0; i < 256; ++i) { - BOOST_CHECK(ZeroL != (OneL << i)); - BOOST_CHECK((OneL << i) != ZeroL); - BOOST_CHECK(R1L != (R1L ^ (OneL << i))); - BOOST_CHECK(((arith_uint256(Tmp64) ^ (OneL << i) ) != Tmp64 )); + CHECK(ZeroL != (OneL << i)); + CHECK((OneL << i) != ZeroL); + CHECK(R1L != (R1L ^ (OneL << i))); + CHECK(((arith_uint256(Tmp64) ^ (OneL << i) ) != Tmp64 )); } - BOOST_CHECK(ZeroL == (OneL << 256)); + CHECK(ZeroL == (OneL << 256)); // Construct from hex string - BOOST_CHECK_EQUAL(UintToArith256(uint256::FromHex(R1L.ToString()).value()), R1L); - BOOST_CHECK_EQUAL(UintToArith256(uint256::FromHex(R2L.ToString()).value()), R2L); - BOOST_CHECK_EQUAL(UintToArith256(uint256::FromHex(ZeroL.ToString()).value()), ZeroL); - BOOST_CHECK_EQUAL(UintToArith256(uint256::FromHex(OneL.ToString()).value()), OneL); - BOOST_CHECK_EQUAL(UintToArith256(uint256::FromHex(MaxL.ToString()).value()), MaxL); - BOOST_CHECK_EQUAL(UintToArith256(uint256::FromHex(R1ArrayHex).value()), R1L); + CHECK(UintToArith256(uint256::FromHex(R1L.ToString()).value()) == R1L); + CHECK(UintToArith256(uint256::FromHex(R2L.ToString()).value()) == R2L); + CHECK(UintToArith256(uint256::FromHex(ZeroL.ToString()).value()) == ZeroL); + CHECK(UintToArith256(uint256::FromHex(OneL.ToString()).value()) == OneL); + CHECK(UintToArith256(uint256::FromHex(MaxL.ToString()).value()) == MaxL); + CHECK(UintToArith256(uint256::FromHex(R1ArrayHex).value()) == R1L); // Copy constructor - BOOST_CHECK(arith_uint256(R1L) == R1L); - BOOST_CHECK((arith_uint256(R1L^R2L)^R2L) == R1L); - BOOST_CHECK(arith_uint256(ZeroL) == ZeroL); - BOOST_CHECK(arith_uint256(OneL) == OneL); + CHECK(arith_uint256(R1L) == R1L); + CHECK((arith_uint256(R1L^R2L)^R2L) == R1L); + CHECK(arith_uint256(ZeroL) == ZeroL); + CHECK(arith_uint256(OneL) == OneL); // uint64_t constructor - BOOST_CHECK_EQUAL(R1L & arith_uint256{0xffffffffffffffff}, arith_uint256{R1LLow64}); - BOOST_CHECK_EQUAL(ZeroL, arith_uint256{0}); - BOOST_CHECK_EQUAL(OneL, arith_uint256{1}); - BOOST_CHECK_EQUAL(arith_uint256{0xffffffffffffffff}, arith_uint256{0xffffffffffffffffULL}); + CHECK((R1L & arith_uint256{0xffffffffffffffff}) == arith_uint256{R1LLow64}); + CHECK(ZeroL == arith_uint256{0}); + CHECK(OneL == arith_uint256{1}); + CHECK(arith_uint256{0xffffffffffffffff} == arith_uint256{0xffffffffffffffffULL}); // Assignment (from base_uint) - arith_uint256 tmpL = ~ZeroL; BOOST_CHECK(tmpL == ~ZeroL); - tmpL = ~OneL; BOOST_CHECK(tmpL == ~OneL); - tmpL = ~R1L; BOOST_CHECK(tmpL == ~R1L); - tmpL = ~R2L; BOOST_CHECK(tmpL == ~R2L); - tmpL = ~MaxL; BOOST_CHECK(tmpL == ~MaxL); + arith_uint256 tmpL = ~ZeroL; CHECK(tmpL == ~ZeroL); + tmpL = ~OneL; CHECK(tmpL == ~OneL); + tmpL = ~R1L; CHECK(tmpL == ~R1L); + tmpL = ~R2L; CHECK(tmpL == ~R2L); + tmpL = ~MaxL; CHECK(tmpL == ~MaxL); } static void shiftArrayRight(unsigned char* to, const unsigned char* from, unsigned int arrayLength, unsigned int bitsToShift) @@ -151,61 +151,61 @@ static void shiftArrayLeft(unsigned char* to, const unsigned char* from, unsigne } } -BOOST_AUTO_TEST_CASE( shifts ) { // "<<" ">>" "<<=" ">>=" +TEST_CASE("shifts") { // "<<" ">>" "<<=" ">>=" unsigned char TmpArray[32]; arith_uint256 TmpL; for (unsigned int i = 0; i < 256; ++i) { shiftArrayLeft(TmpArray, OneArray, 32, i); - BOOST_CHECK(arith_uint256V(std::vector(TmpArray,TmpArray+32)) == (OneL << i)); + CHECK(arith_uint256V(std::vector(TmpArray,TmpArray+32)) == (OneL << i)); TmpL = OneL; TmpL <<= i; - BOOST_CHECK(TmpL == (OneL << i)); - BOOST_CHECK((HalfL >> (255-i)) == (OneL << i)); + CHECK(TmpL == (OneL << i)); + CHECK((HalfL >> (255-i)) == (OneL << i)); TmpL = HalfL; TmpL >>= (255-i); - BOOST_CHECK(TmpL == (OneL << i)); + CHECK(TmpL == (OneL << i)); shiftArrayLeft(TmpArray, R1Array, 32, i); - BOOST_CHECK(arith_uint256V(std::vector(TmpArray,TmpArray+32)) == (R1L << i)); + CHECK(arith_uint256V(std::vector(TmpArray,TmpArray+32)) == (R1L << i)); TmpL = R1L; TmpL <<= i; - BOOST_CHECK(TmpL == (R1L << i)); + CHECK(TmpL == (R1L << i)); shiftArrayRight(TmpArray, R1Array, 32, i); - BOOST_CHECK(arith_uint256V(std::vector(TmpArray,TmpArray+32)) == (R1L >> i)); + CHECK(arith_uint256V(std::vector(TmpArray,TmpArray+32)) == (R1L >> i)); TmpL = R1L; TmpL >>= i; - BOOST_CHECK(TmpL == (R1L >> i)); + CHECK(TmpL == (R1L >> i)); shiftArrayLeft(TmpArray, MaxArray, 32, i); - BOOST_CHECK(arith_uint256V(std::vector(TmpArray,TmpArray+32)) == (MaxL << i)); + CHECK(arith_uint256V(std::vector(TmpArray,TmpArray+32)) == (MaxL << i)); TmpL = MaxL; TmpL <<= i; - BOOST_CHECK(TmpL == (MaxL << i)); + CHECK(TmpL == (MaxL << i)); shiftArrayRight(TmpArray, MaxArray, 32, i); - BOOST_CHECK(arith_uint256V(std::vector(TmpArray,TmpArray+32)) == (MaxL >> i)); + CHECK(arith_uint256V(std::vector(TmpArray,TmpArray+32)) == (MaxL >> i)); TmpL = MaxL; TmpL >>= i; - BOOST_CHECK(TmpL == (MaxL >> i)); + CHECK(TmpL == (MaxL >> i)); } arith_uint256 c1L = arith_uint256(0x0123456789abcdefULL); arith_uint256 c2L = c1L << 128; for (unsigned int i = 0; i < 128; ++i) { - BOOST_CHECK((c1L << i) == (c2L >> (128-i))); + CHECK((c1L << i) == (c2L >> (128-i))); } for (unsigned int i = 128; i < 256; ++i) { - BOOST_CHECK((c1L << i) == (c2L << (i-128))); + CHECK((c1L << i) == (c2L << (i-128))); } } -BOOST_AUTO_TEST_CASE( unaryOperators ) // ! ~ - +TEST_CASE("unaryOperators") // ! ~ - { - BOOST_CHECK(~ZeroL == MaxL); + CHECK(~ZeroL == MaxL); unsigned char TmpArray[32]; for (unsigned int i = 0; i < 32; ++i) { TmpArray[i] = uint8_t(~R1Array[i]); } - BOOST_CHECK(arith_uint256V(std::vector(TmpArray,TmpArray+32)) == (~R1L)); + CHECK(arith_uint256V(std::vector(TmpArray,TmpArray+32)) == (~R1L)); - BOOST_CHECK(-ZeroL == ZeroL); - BOOST_CHECK(-R1L == (~R1L)+1); + CHECK(-ZeroL == ZeroL); + CHECK(-R1L == (~R1L)+1); for (unsigned int i = 0; i < 256; ++i) - BOOST_CHECK(-(OneL<(TmpArray,TmpArray+32)) == (_A_##L _OP_ _B_##L)); + CHECK(arith_uint256V(std::vector(TmpArray,TmpArray+32)) == (_A_##L _OP_ _B_##L)); #define CHECKASSIGNMENTOPERATOR(_A_,_B_,_OP_) \ - TmpL = _A_##L; TmpL _OP_##= _B_##L; BOOST_CHECK(TmpL == (_A_##L _OP_ _B_##L)); + TmpL = _A_##L; TmpL _OP_##= _B_##L; CHECK(TmpL == (_A_##L _OP_ _B_##L)); -BOOST_AUTO_TEST_CASE( bitwiseOperators ) +TEST_CASE("bitwiseOperators") { unsigned char TmpArray[32]; @@ -256,110 +256,109 @@ BOOST_AUTO_TEST_CASE( bitwiseOperators ) CHECKASSIGNMENTOPERATOR(Max,R1,&) uint64_t Tmp64 = 0xe1db685c9a0b47a2ULL; - TmpL = R1L; TmpL |= Tmp64; BOOST_CHECK(TmpL == (R1L | arith_uint256(Tmp64))); - TmpL = R1L; TmpL |= 0; BOOST_CHECK(TmpL == R1L); - TmpL ^= 0; BOOST_CHECK(TmpL == R1L); - TmpL ^= Tmp64; BOOST_CHECK(TmpL == (R1L ^ arith_uint256(Tmp64))); + TmpL = R1L; TmpL |= Tmp64; CHECK(TmpL == (R1L | arith_uint256(Tmp64))); + TmpL = R1L; TmpL |= 0; CHECK(TmpL == R1L); + TmpL ^= 0; CHECK(TmpL == R1L); + TmpL ^= Tmp64; CHECK(TmpL == (R1L ^ arith_uint256(Tmp64))); } -BOOST_AUTO_TEST_CASE( comparison ) // <= >= < > +TEST_CASE("comparison") // <= >= < > { arith_uint256 TmpL; for (unsigned int i = 0; i < 256; ++i) { TmpL= OneL<< i; - BOOST_CHECK( TmpL >= ZeroL && TmpL > ZeroL && ZeroL < TmpL && ZeroL <= TmpL); - BOOST_CHECK( TmpL >= 0 && TmpL > 0 && 0 < TmpL && 0 <= TmpL); + CHECK(TmpL >= ZeroL); CHECK(TmpL > ZeroL); CHECK(ZeroL < TmpL); CHECK(ZeroL <= TmpL); + CHECK(TmpL >= 0); CHECK(TmpL > 0); CHECK(0 < TmpL); CHECK(0 <= TmpL); TmpL |= R1L; - BOOST_CHECK( TmpL >= R1L ); BOOST_CHECK( (TmpL == R1L) != (TmpL > R1L)); BOOST_CHECK( (TmpL == R1L) || !( TmpL <= R1L)); - BOOST_CHECK( R1L <= TmpL ); BOOST_CHECK( (R1L == TmpL) != (R1L < TmpL)); BOOST_CHECK( (TmpL == R1L) || !( R1L >= TmpL)); - BOOST_CHECK(! (TmpL < R1L)); BOOST_CHECK(! (R1L > TmpL)); + CHECK(TmpL >= R1L); CHECK((TmpL == R1L) != (TmpL > R1L)); CHECK(((TmpL == R1L) || !(TmpL <= R1L))); + CHECK(R1L <= TmpL); CHECK((R1L == TmpL) != (R1L < TmpL)); CHECK(((TmpL == R1L) || !(R1L >= TmpL))); + CHECK(! (TmpL < R1L)); CHECK(! (R1L > TmpL)); } - BOOST_CHECK_LT(ZeroL, - OneL); + CHECK(ZeroL < OneL); } -BOOST_AUTO_TEST_CASE( plusMinus ) +TEST_CASE("plusMinus") { arith_uint256 TmpL = 0; - BOOST_CHECK_EQUAL(R1L + R2L, UintToArith256(uint256{"549fb09fea236a1ea3e31d4d58f1b1369288d204211ca751527cfc175767850c"})); + CHECK(R1L + R2L == UintToArith256(uint256{"549fb09fea236a1ea3e31d4d58f1b1369288d204211ca751527cfc175767850c"})); TmpL += R1L; - BOOST_CHECK(TmpL == R1L); + CHECK(TmpL == R1L); TmpL += R2L; - BOOST_CHECK(TmpL == R1L + R2L); - BOOST_CHECK(OneL+MaxL == ZeroL); - BOOST_CHECK(MaxL+OneL == ZeroL); + CHECK(TmpL == R1L + R2L); + CHECK(OneL+MaxL == ZeroL); + CHECK(MaxL+OneL == ZeroL); for (unsigned int i = 1; i < 256; ++i) { - BOOST_CHECK( (MaxL >> i) + OneL == (HalfL >> (i-1)) ); - BOOST_CHECK( OneL + (MaxL >> i) == (HalfL >> (i-1)) ); + CHECK((MaxL >> i) + OneL == (HalfL >> (i-1))); + CHECK(OneL + (MaxL >> i) == (HalfL >> (i-1))); TmpL = (MaxL>>i); TmpL += OneL; - BOOST_CHECK( TmpL == (HalfL >> (i-1)) ); + CHECK(TmpL == (HalfL >> (i-1))); TmpL = (MaxL>>i); TmpL += 1; - BOOST_CHECK( TmpL == (HalfL >> (i-1)) ); + CHECK(TmpL == (HalfL >> (i-1))); TmpL = (MaxL>>i); - BOOST_CHECK( TmpL++ == (MaxL>>i) ); - BOOST_CHECK( TmpL == (HalfL >> (i-1))); + CHECK(TmpL++ == (MaxL>>i)); + CHECK(TmpL == (HalfL >> (i-1))); } - BOOST_CHECK(arith_uint256(0xbedc77e27940a7ULL) + 0xee8d836fce66fbULL == arith_uint256(0xbedc77e27940a7ULL + 0xee8d836fce66fbULL)); + CHECK(arith_uint256(0xbedc77e27940a7ULL) + 0xee8d836fce66fbULL == arith_uint256(0xbedc77e27940a7ULL + 0xee8d836fce66fbULL)); TmpL = arith_uint256(0xbedc77e27940a7ULL); TmpL += 0xee8d836fce66fbULL; - BOOST_CHECK(TmpL == arith_uint256(0xbedc77e27940a7ULL+0xee8d836fce66fbULL)); - TmpL -= 0xee8d836fce66fbULL; BOOST_CHECK(TmpL == 0xbedc77e27940a7ULL); + CHECK(TmpL == arith_uint256(0xbedc77e27940a7ULL+0xee8d836fce66fbULL)); + TmpL -= 0xee8d836fce66fbULL; CHECK(TmpL == 0xbedc77e27940a7ULL); TmpL = R1L; - BOOST_CHECK(++TmpL == R1L+1); + CHECK(++TmpL == R1L+1); - BOOST_CHECK(R1L -(-R2L) == R1L+R2L); - BOOST_CHECK(R1L -(-OneL) == R1L+OneL); - BOOST_CHECK(R1L - OneL == R1L+(-OneL)); + CHECK(R1L -(-R2L) == R1L+R2L); + CHECK(R1L -(-OneL) == R1L+OneL); + CHECK(R1L - OneL == R1L+(-OneL)); for (unsigned int i = 1; i < 256; ++i) { - BOOST_CHECK((MaxL>>i) - (-OneL) == (HalfL >> (i-1))); - BOOST_CHECK((HalfL >> (i-1)) - OneL == (MaxL>>i)); + CHECK((MaxL>>i) - (-OneL) == (HalfL >> (i-1))); + CHECK((HalfL >> (i-1)) - OneL == (MaxL>>i)); TmpL = (HalfL >> (i-1)); - BOOST_CHECK(TmpL-- == (HalfL >> (i-1))); - BOOST_CHECK(TmpL == (MaxL >> i)); + CHECK(TmpL-- == (HalfL >> (i-1))); + CHECK(TmpL == (MaxL >> i)); TmpL = (HalfL >> (i-1)); - BOOST_CHECK(--TmpL == (MaxL >> i)); + CHECK(--TmpL == (MaxL >> i)); } TmpL = R1L; - BOOST_CHECK(--TmpL == R1L-1); + CHECK(--TmpL == R1L-1); } -BOOST_AUTO_TEST_CASE( multiply ) +TEST_CASE("multiply") { - BOOST_CHECK((R1L * R1L).ToString() == "62a38c0486f01e45879d7910a7761bf30d5237e9873f9bff3642a732c4d84f10"); - BOOST_CHECK((R1L * R2L).ToString() == "de37805e9986996cfba76ff6ba51c008df851987d9dd323f0e5de07760529c40"); - BOOST_CHECK((R1L * ZeroL) == ZeroL); - BOOST_CHECK((R1L * OneL) == R1L); - BOOST_CHECK((R1L * MaxL) == -R1L); - BOOST_CHECK((R2L * R1L) == (R1L * R2L)); - BOOST_CHECK((R2L * R2L).ToString() == "ac8c010096767d3cae5005dec28bb2b45a1d85ab7996ccd3e102a650f74ff100"); - BOOST_CHECK((R2L * ZeroL) == ZeroL); - BOOST_CHECK((R2L * OneL) == R2L); - BOOST_CHECK((R2L * MaxL) == -R2L); - - BOOST_CHECK(MaxL * MaxL == OneL); - - BOOST_CHECK((R1L * 0) == 0); - BOOST_CHECK((R1L * 1) == R1L); - BOOST_CHECK((R1L * 3).ToString() == "7759b1c0ed14047f961ad09b20ff83687876a0181a367b813634046f91def7d4"); - BOOST_CHECK((R2L * 0x87654321UL).ToString() == "23f7816e30c4ae2017257b7a0fa64d60402f5234d46e746b61c960d09a26d070"); + CHECK((R1L * R1L).ToString() == "62a38c0486f01e45879d7910a7761bf30d5237e9873f9bff3642a732c4d84f10"); + CHECK((R1L * R2L).ToString() == "de37805e9986996cfba76ff6ba51c008df851987d9dd323f0e5de07760529c40"); + CHECK((R1L * ZeroL) == ZeroL); + CHECK((R1L * OneL) == R1L); + CHECK((R1L * MaxL) == -R1L); + CHECK((R2L * R1L) == (R1L * R2L)); + CHECK((R2L * R2L).ToString() == "ac8c010096767d3cae5005dec28bb2b45a1d85ab7996ccd3e102a650f74ff100"); + CHECK((R2L * ZeroL) == ZeroL); + CHECK((R2L * OneL) == R2L); + CHECK((R2L * MaxL) == -R2L); + + CHECK(MaxL * MaxL == OneL); + + CHECK((R1L * 0) == 0); + CHECK((R1L * 1) == R1L); + CHECK((R1L * 3).ToString() == "7759b1c0ed14047f961ad09b20ff83687876a0181a367b813634046f91def7d4"); + CHECK((R2L * 0x87654321UL).ToString() == "23f7816e30c4ae2017257b7a0fa64d60402f5234d46e746b61c960d09a26d070"); } -BOOST_AUTO_TEST_CASE( divide ) +TEST_CASE("divide") { arith_uint256 D1L{UintToArith256(uint256{"00000000000000000000000000000000000000000000000ad7133ac1977fa2b7"})}; arith_uint256 D2L{UintToArith256(uint256{"0000000000000000000000000000000000000000000000000000000ecd751716"})}; - BOOST_CHECK((R1L / D1L).ToString() == "00000000000000000b8ac01106981635d9ed112290f8895545a7654dde28fb3a"); - BOOST_CHECK((R1L / D2L).ToString() == "000000000873ce8efec5b67150bad3aa8c5fcb70e947586153bf2cec7c37c57a"); - BOOST_CHECK(R1L / OneL == R1L); - BOOST_CHECK(R1L / MaxL == ZeroL); - BOOST_CHECK(MaxL / R1L == 2); - BOOST_CHECK_THROW(R1L / ZeroL, uint_error); - BOOST_CHECK((R2L / D1L).ToString() == "000000000000000013e1665895a1cc981de6d93670105a6b3ec3b73141b3a3c5"); - BOOST_CHECK((R2L / D2L).ToString() == "000000000e8f0abe753bb0afe2e9437ee85d280be60882cf0bd1aaf7fa3cc2c4"); - BOOST_CHECK(R2L / OneL == R2L); - BOOST_CHECK(R2L / MaxL == ZeroL); - BOOST_CHECK(MaxL / R2L == 1); - BOOST_CHECK_THROW(R2L / ZeroL, uint_error); + CHECK((R1L / D1L).ToString() == "00000000000000000b8ac01106981635d9ed112290f8895545a7654dde28fb3a"); + CHECK((R1L / D2L).ToString() == "000000000873ce8efec5b67150bad3aa8c5fcb70e947586153bf2cec7c37c57a"); + CHECK(R1L / OneL == R1L); + CHECK(R1L / MaxL == ZeroL); + CHECK(MaxL / R1L == 2); + CHECK_THROWS_AS(R1L / ZeroL, uint_error); + CHECK((R2L / D1L).ToString() == "000000000000000013e1665895a1cc981de6d93670105a6b3ec3b73141b3a3c5"); + CHECK((R2L / D2L).ToString() == "000000000e8f0abe753bb0afe2e9437ee85d280be60882cf0bd1aaf7fa3cc2c4"); + CHECK(R2L / OneL == R2L); + CHECK(R2L / MaxL == ZeroL); + CHECK(MaxL / R2L == 1); + CHECK_THROWS_AS(R2L / ZeroL, uint_error); } @@ -368,190 +367,190 @@ static bool almostEqual(double d1, double d2) return fabs(d1-d2) <= 4*fabs(d1)*std::numeric_limits::epsilon(); } -BOOST_AUTO_TEST_CASE(methods) +TEST_CASE("methods") { - BOOST_CHECK(R1L.GetHex() == R1L.ToString()); - BOOST_CHECK(R2L.GetHex() == R2L.ToString()); - BOOST_CHECK(OneL.GetHex() == OneL.ToString()); - BOOST_CHECK(MaxL.GetHex() == MaxL.ToString()); + CHECK(R1L.GetHex() == R1L.ToString()); + CHECK(R2L.GetHex() == R2L.ToString()); + CHECK(OneL.GetHex() == OneL.ToString()); + CHECK(MaxL.GetHex() == MaxL.ToString()); arith_uint256 TmpL(R1L); - BOOST_CHECK(TmpL == R1L); + CHECK(TmpL == R1L); TmpL = R2L; - BOOST_CHECK(TmpL == R2L); + CHECK(TmpL == R2L); TmpL = ZeroL; - BOOST_CHECK(TmpL == 0); + CHECK(TmpL == 0); TmpL = HalfL; - BOOST_CHECK(TmpL == HalfL); + CHECK(TmpL == HalfL); TmpL = R1L; - BOOST_CHECK(R1L.size() == 32); - BOOST_CHECK(R2L.size() == 32); - BOOST_CHECK(ZeroL.size() == 32); - BOOST_CHECK(MaxL.size() == 32); - BOOST_CHECK(R1L.GetLow64() == R1LLow64); - BOOST_CHECK(HalfL.GetLow64() ==0x0000000000000000ULL); - BOOST_CHECK(OneL.GetLow64() ==0x0000000000000001ULL); + CHECK(R1L.size() == 32U); + CHECK(R2L.size() == 32U); + CHECK(ZeroL.size() == 32U); + CHECK(MaxL.size() == 32U); + CHECK(R1L.GetLow64() == R1LLow64); + CHECK(HalfL.GetLow64() ==0x0000000000000000ULL); + CHECK(OneL.GetLow64() ==0x0000000000000001ULL); for (unsigned int i = 0; i < 255; ++i) { - BOOST_CHECK((OneL << i).getdouble() == ldexp(1.0,i)); + CHECK((OneL << i).getdouble() == ldexp(1.0,i)); } - BOOST_CHECK(ZeroL.getdouble() == 0.0); + CHECK(ZeroL.getdouble() == 0.0); for (int i = 256; i > 53; --i) - BOOST_CHECK(almostEqual((R1L>>(256-i)).getdouble(), ldexp(R1Ldouble,i))); + CHECK(almostEqual((R1L>>(256-i)).getdouble(), ldexp(R1Ldouble,i))); uint64_t R1L64part = (R1L>>192).GetLow64(); for (int i = 53; i > 0; --i) // doubles can store all integers in {0,...,2^54-1} exactly { - BOOST_CHECK((R1L>>(256-i)).getdouble() == (double)(R1L64part >> (64-i))); + CHECK((R1L>>(256-i)).getdouble() == (double)(R1L64part >> (64-i))); } } -BOOST_AUTO_TEST_CASE(bignum_SetCompact) +TEST_CASE("bignum_SetCompact") { arith_uint256 num; bool fNegative; bool fOverflow; num.SetCompact(0, &fNegative, &fOverflow); - BOOST_CHECK_EQUAL(num.GetHex(), "0000000000000000000000000000000000000000000000000000000000000000"); - BOOST_CHECK_EQUAL(num.GetCompact(), 0U); - BOOST_CHECK_EQUAL(fNegative, false); - BOOST_CHECK_EQUAL(fOverflow, false); + CHECK(num.GetHex() == "0000000000000000000000000000000000000000000000000000000000000000"); + CHECK(num.GetCompact() == 0U); + CHECK(fNegative == false); + CHECK(fOverflow == false); num.SetCompact(0x00123456, &fNegative, &fOverflow); - BOOST_CHECK_EQUAL(num.GetHex(), "0000000000000000000000000000000000000000000000000000000000000000"); - BOOST_CHECK_EQUAL(num.GetCompact(), 0U); - BOOST_CHECK_EQUAL(fNegative, false); - BOOST_CHECK_EQUAL(fOverflow, false); + CHECK(num.GetHex() == "0000000000000000000000000000000000000000000000000000000000000000"); + CHECK(num.GetCompact() == 0U); + CHECK(fNegative == false); + CHECK(fOverflow == false); num.SetCompact(0x01003456, &fNegative, &fOverflow); - BOOST_CHECK_EQUAL(num.GetHex(), "0000000000000000000000000000000000000000000000000000000000000000"); - BOOST_CHECK_EQUAL(num.GetCompact(), 0U); - BOOST_CHECK_EQUAL(fNegative, false); - BOOST_CHECK_EQUAL(fOverflow, false); + CHECK(num.GetHex() == "0000000000000000000000000000000000000000000000000000000000000000"); + CHECK(num.GetCompact() == 0U); + CHECK(fNegative == false); + CHECK(fOverflow == false); num.SetCompact(0x02000056, &fNegative, &fOverflow); - BOOST_CHECK_EQUAL(num.GetHex(), "0000000000000000000000000000000000000000000000000000000000000000"); - BOOST_CHECK_EQUAL(num.GetCompact(), 0U); - BOOST_CHECK_EQUAL(fNegative, false); - BOOST_CHECK_EQUAL(fOverflow, false); + CHECK(num.GetHex() == "0000000000000000000000000000000000000000000000000000000000000000"); + CHECK(num.GetCompact() == 0U); + CHECK(fNegative == false); + CHECK(fOverflow == false); num.SetCompact(0x03000000, &fNegative, &fOverflow); - BOOST_CHECK_EQUAL(num.GetHex(), "0000000000000000000000000000000000000000000000000000000000000000"); - BOOST_CHECK_EQUAL(num.GetCompact(), 0U); - BOOST_CHECK_EQUAL(fNegative, false); - BOOST_CHECK_EQUAL(fOverflow, false); + CHECK(num.GetHex() == "0000000000000000000000000000000000000000000000000000000000000000"); + CHECK(num.GetCompact() == 0U); + CHECK(fNegative == false); + CHECK(fOverflow == false); num.SetCompact(0x04000000, &fNegative, &fOverflow); - BOOST_CHECK_EQUAL(num.GetHex(), "0000000000000000000000000000000000000000000000000000000000000000"); - BOOST_CHECK_EQUAL(num.GetCompact(), 0U); - BOOST_CHECK_EQUAL(fNegative, false); - BOOST_CHECK_EQUAL(fOverflow, false); + CHECK(num.GetHex() == "0000000000000000000000000000000000000000000000000000000000000000"); + CHECK(num.GetCompact() == 0U); + CHECK(fNegative == false); + CHECK(fOverflow == false); num.SetCompact(0x00923456, &fNegative, &fOverflow); - BOOST_CHECK_EQUAL(num.GetHex(), "0000000000000000000000000000000000000000000000000000000000000000"); - BOOST_CHECK_EQUAL(num.GetCompact(), 0U); - BOOST_CHECK_EQUAL(fNegative, false); - BOOST_CHECK_EQUAL(fOverflow, false); + CHECK(num.GetHex() == "0000000000000000000000000000000000000000000000000000000000000000"); + CHECK(num.GetCompact() == 0U); + CHECK(fNegative == false); + CHECK(fOverflow == false); num.SetCompact(0x01803456, &fNegative, &fOverflow); - BOOST_CHECK_EQUAL(num.GetHex(), "0000000000000000000000000000000000000000000000000000000000000000"); - BOOST_CHECK_EQUAL(num.GetCompact(), 0U); - BOOST_CHECK_EQUAL(fNegative, false); - BOOST_CHECK_EQUAL(fOverflow, false); + CHECK(num.GetHex() == "0000000000000000000000000000000000000000000000000000000000000000"); + CHECK(num.GetCompact() == 0U); + CHECK(fNegative == false); + CHECK(fOverflow == false); num.SetCompact(0x02800056, &fNegative, &fOverflow); - BOOST_CHECK_EQUAL(num.GetHex(), "0000000000000000000000000000000000000000000000000000000000000000"); - BOOST_CHECK_EQUAL(num.GetCompact(), 0U); - BOOST_CHECK_EQUAL(fNegative, false); - BOOST_CHECK_EQUAL(fOverflow, false); + CHECK(num.GetHex() == "0000000000000000000000000000000000000000000000000000000000000000"); + CHECK(num.GetCompact() == 0U); + CHECK(fNegative == false); + CHECK(fOverflow == false); num.SetCompact(0x03800000, &fNegative, &fOverflow); - BOOST_CHECK_EQUAL(num.GetHex(), "0000000000000000000000000000000000000000000000000000000000000000"); - BOOST_CHECK_EQUAL(num.GetCompact(), 0U); - BOOST_CHECK_EQUAL(fNegative, false); - BOOST_CHECK_EQUAL(fOverflow, false); + CHECK(num.GetHex() == "0000000000000000000000000000000000000000000000000000000000000000"); + CHECK(num.GetCompact() == 0U); + CHECK(fNegative == false); + CHECK(fOverflow == false); num.SetCompact(0x04800000, &fNegative, &fOverflow); - BOOST_CHECK_EQUAL(num.GetHex(), "0000000000000000000000000000000000000000000000000000000000000000"); - BOOST_CHECK_EQUAL(num.GetCompact(), 0U); - BOOST_CHECK_EQUAL(fNegative, false); - BOOST_CHECK_EQUAL(fOverflow, false); + CHECK(num.GetHex() == "0000000000000000000000000000000000000000000000000000000000000000"); + CHECK(num.GetCompact() == 0U); + CHECK(fNegative == false); + CHECK(fOverflow == false); num.SetCompact(0x01123456, &fNegative, &fOverflow); - BOOST_CHECK_EQUAL(num.GetHex(), "0000000000000000000000000000000000000000000000000000000000000012"); - BOOST_CHECK_EQUAL(num.GetCompact(), 0x01120000U); - BOOST_CHECK_EQUAL(fNegative, false); - BOOST_CHECK_EQUAL(fOverflow, false); + CHECK(num.GetHex() == "0000000000000000000000000000000000000000000000000000000000000012"); + CHECK(num.GetCompact() == 0x01120000U); + CHECK(fNegative == false); + CHECK(fOverflow == false); // Make sure that we don't generate compacts with the 0x00800000 bit set num = 0x80; - BOOST_CHECK_EQUAL(num.GetCompact(), 0x02008000U); + CHECK(num.GetCompact() == 0x02008000U); num.SetCompact(0x01fedcba, &fNegative, &fOverflow); - BOOST_CHECK_EQUAL(num.GetHex(), "000000000000000000000000000000000000000000000000000000000000007e"); - BOOST_CHECK_EQUAL(num.GetCompact(true), 0x01fe0000U); - BOOST_CHECK_EQUAL(fNegative, true); - BOOST_CHECK_EQUAL(fOverflow, false); + CHECK(num.GetHex() == "000000000000000000000000000000000000000000000000000000000000007e"); + CHECK(num.GetCompact(true) == 0x01fe0000U); + CHECK(fNegative == true); + CHECK(fOverflow == false); num.SetCompact(0x02123456, &fNegative, &fOverflow); - BOOST_CHECK_EQUAL(num.GetHex(), "0000000000000000000000000000000000000000000000000000000000001234"); - BOOST_CHECK_EQUAL(num.GetCompact(), 0x02123400U); - BOOST_CHECK_EQUAL(fNegative, false); - BOOST_CHECK_EQUAL(fOverflow, false); + CHECK(num.GetHex() == "0000000000000000000000000000000000000000000000000000000000001234"); + CHECK(num.GetCompact() == 0x02123400U); + CHECK(fNegative == false); + CHECK(fOverflow == false); num.SetCompact(0x03123456, &fNegative, &fOverflow); - BOOST_CHECK_EQUAL(num.GetHex(), "0000000000000000000000000000000000000000000000000000000000123456"); - BOOST_CHECK_EQUAL(num.GetCompact(), 0x03123456U); - BOOST_CHECK_EQUAL(fNegative, false); - BOOST_CHECK_EQUAL(fOverflow, false); + CHECK(num.GetHex() == "0000000000000000000000000000000000000000000000000000000000123456"); + CHECK(num.GetCompact() == 0x03123456U); + CHECK(fNegative == false); + CHECK(fOverflow == false); num.SetCompact(0x04123456, &fNegative, &fOverflow); - BOOST_CHECK_EQUAL(num.GetHex(), "0000000000000000000000000000000000000000000000000000000012345600"); - BOOST_CHECK_EQUAL(num.GetCompact(), 0x04123456U); - BOOST_CHECK_EQUAL(fNegative, false); - BOOST_CHECK_EQUAL(fOverflow, false); + CHECK(num.GetHex() == "0000000000000000000000000000000000000000000000000000000012345600"); + CHECK(num.GetCompact() == 0x04123456U); + CHECK(fNegative == false); + CHECK(fOverflow == false); num.SetCompact(0x04923456, &fNegative, &fOverflow); - BOOST_CHECK_EQUAL(num.GetHex(), "0000000000000000000000000000000000000000000000000000000012345600"); - BOOST_CHECK_EQUAL(num.GetCompact(true), 0x04923456U); - BOOST_CHECK_EQUAL(fNegative, true); - BOOST_CHECK_EQUAL(fOverflow, false); + CHECK(num.GetHex() == "0000000000000000000000000000000000000000000000000000000012345600"); + CHECK(num.GetCompact(true) == 0x04923456U); + CHECK(fNegative == true); + CHECK(fOverflow == false); num.SetCompact(0x05009234, &fNegative, &fOverflow); - BOOST_CHECK_EQUAL(num.GetHex(), "0000000000000000000000000000000000000000000000000000000092340000"); - BOOST_CHECK_EQUAL(num.GetCompact(), 0x05009234U); - BOOST_CHECK_EQUAL(fNegative, false); - BOOST_CHECK_EQUAL(fOverflow, false); + CHECK(num.GetHex() == "0000000000000000000000000000000000000000000000000000000092340000"); + CHECK(num.GetCompact() == 0x05009234U); + CHECK(fNegative == false); + CHECK(fOverflow == false); num.SetCompact(0x20123456, &fNegative, &fOverflow); - BOOST_CHECK_EQUAL(num.GetHex(), "1234560000000000000000000000000000000000000000000000000000000000"); - BOOST_CHECK_EQUAL(num.GetCompact(), 0x20123456U); - BOOST_CHECK_EQUAL(fNegative, false); - BOOST_CHECK_EQUAL(fOverflow, false); + CHECK(num.GetHex() == "1234560000000000000000000000000000000000000000000000000000000000"); + CHECK(num.GetCompact() == 0x20123456U); + CHECK(fNegative == false); + CHECK(fOverflow == false); num.SetCompact(0xff123456, &fNegative, &fOverflow); - BOOST_CHECK_EQUAL(fNegative, false); - BOOST_CHECK_EQUAL(fOverflow, true); + CHECK(fNegative == false); + CHECK(fOverflow == true); } -BOOST_AUTO_TEST_CASE( getmaxcoverage ) // some more tests just to get 100% coverage +TEST_CASE("getmaxcoverage") // some more tests just to get 100% coverage { // ~R1L give a base_uint<256> - BOOST_CHECK((~~R1L >> 10) == (R1L >> 10)); - BOOST_CHECK((~~R1L << 10) == (R1L << 10)); - BOOST_CHECK(!(~~R1L < R1L)); - BOOST_CHECK(~~R1L <= R1L); - BOOST_CHECK(!(~~R1L > R1L)); - BOOST_CHECK(~~R1L >= R1L); - BOOST_CHECK(!(R1L < ~~R1L)); - BOOST_CHECK(R1L <= ~~R1L); - BOOST_CHECK(!(R1L > ~~R1L)); - BOOST_CHECK(R1L >= ~~R1L); - - BOOST_CHECK(~~R1L + R2L == R1L + ~~R2L); - BOOST_CHECK(~~R1L - R2L == R1L - ~~R2L); - BOOST_CHECK(~R1L != R1L); BOOST_CHECK(R1L != ~R1L); + CHECK((~~R1L >> 10) == (R1L >> 10)); + CHECK((~~R1L << 10) == (R1L << 10)); + CHECK(!(~~R1L < R1L)); + CHECK(~~R1L <= R1L); + CHECK(!(~~R1L > R1L)); + CHECK(~~R1L >= R1L); + CHECK(!(R1L < ~~R1L)); + CHECK(R1L <= ~~R1L); + CHECK(!(R1L > ~~R1L)); + CHECK(R1L >= ~~R1L); + + CHECK(~~R1L + R2L == R1L + ~~R2L); + CHECK(~~R1L - R2L == R1L - ~~R2L); + CHECK(~R1L != R1L); CHECK(R1L != ~R1L); unsigned char TmpArray[32]; CHECKBITWISEOPERATOR(~R1,R2,|) CHECKBITWISEOPERATOR(~R1,R2,^) @@ -561,34 +560,34 @@ BOOST_AUTO_TEST_CASE( getmaxcoverage ) // some more tests just to get 100% cover CHECKBITWISEOPERATOR(R1,~R2,&) } -BOOST_AUTO_TEST_CASE(conversion) +TEST_CASE("conversion") { for (const arith_uint256& arith : {ZeroL, OneL, R1L, R2L}) { const auto u256{uint256::FromHex(arith.GetHex()).value()}; - BOOST_CHECK_EQUAL(UintToArith256(ArithToUint256(arith)), arith); - BOOST_CHECK_EQUAL(UintToArith256(u256), arith); - BOOST_CHECK_EQUAL(u256, ArithToUint256(arith)); - BOOST_CHECK_EQUAL(ArithToUint256(arith).GetHex(), UintToArith256(u256).GetHex()); + CHECK(UintToArith256(ArithToUint256(arith)) == arith); + CHECK(UintToArith256(u256) == arith); + CHECK(u256 == ArithToUint256(arith)); + CHECK(ArithToUint256(arith).GetHex() == UintToArith256(u256).GetHex()); } for (uint8_t num : {0, 1, 0xff}) { - BOOST_CHECK_EQUAL(UintToArith256(uint256{num}), arith_uint256{num}); - BOOST_CHECK_EQUAL(uint256{num}, ArithToUint256(arith_uint256{num})); - BOOST_CHECK_EQUAL(UintToArith256(uint256{num}), num); + CHECK(UintToArith256(uint256{num}) == arith_uint256{num}); + CHECK(uint256{num} == ArithToUint256(arith_uint256{num})); + CHECK(UintToArith256(uint256{num}) == num); } } -BOOST_AUTO_TEST_CASE(operator_with_self) +TEST_CASE("operator_with_self") { arith_uint256 v{2}; v *= v; - BOOST_CHECK_EQUAL(v, arith_uint256{4}); + CHECK(v == arith_uint256{4}); v /= v; - BOOST_CHECK_EQUAL(v, arith_uint256{1}); + CHECK(v == arith_uint256{1}); v += v; - BOOST_CHECK_EQUAL(v, arith_uint256{2}); + CHECK(v == arith_uint256{2}); v -= v; - BOOST_CHECK_EQUAL(v, arith_uint256{0}); + CHECK(v == arith_uint256{0}); } -BOOST_AUTO_TEST_SUITE_END() +TEST_SUITE_END() diff --git a/src/test/banman_tests.cpp b/src/test/banman_tests.cpp index d1e79e357742..9b0bf1293bb2 100644 --- a/src/test/banman_tests.cpp +++ b/src/test/banman_tests.cpp @@ -11,11 +11,11 @@ #include #include -#include +#include -BOOST_FIXTURE_TEST_SUITE(banman_tests, BasicTestingSetup) +TEST_SUITE_BEGIN("banman_tests") -BOOST_AUTO_TEST_CASE(file) +FIXTURE_TEST_CASE("file", BasicTestingSetup) { NodeClockContext clock_ctx{777s}; const fs::path banlist_path{m_args.GetDataDirBase() / "banlist_test"}; @@ -27,7 +27,7 @@ BOOST_AUTO_TEST_CASE(file) " { \"version\": 1, \"ban_created\": 0, \"banned_until\": 778, \"address\": \"1.0.0.0/8\" }" "] }", }; - BOOST_REQUIRE(WriteBinaryFile(banlist_path + ".json", entries_write)); + REQUIRE(WriteBinaryFile(banlist_path + ".json", entries_write)); { // The invalid entries will be dropped, but the valid one remains ASSERT_DEBUG_LOG("Dropping entry with unparseable address or subnet (aaaaaaaaa) from ban list"); @@ -35,9 +35,9 @@ BOOST_AUTO_TEST_CASE(file) BanMan banman{banlist_path, /*client_interface=*/nullptr, /*default_ban_time=*/0}; banmap_t entries_read; banman.GetBanned(entries_read); - BOOST_CHECK_EQUAL(entries_read.size(), 1); + CHECK(entries_read.size() == 1U); } } } -BOOST_AUTO_TEST_SUITE_END() +TEST_SUITE_END() diff --git a/src/test/base32_tests.cpp b/src/test/base32_tests.cpp index 051a8fcd25dc..62a68ce9aa85 100644 --- a/src/test/base32_tests.cpp +++ b/src/test/base32_tests.cpp @@ -4,16 +4,16 @@ #include -#include +#include #include #include using namespace std::literals; -BOOST_AUTO_TEST_SUITE(base32_tests) +TEST_SUITE_BEGIN("base32_tests") -BOOST_AUTO_TEST_CASE(base32_testvectors) +TEST_CASE("base32_testvectors") { static const std::string vstrIn[] = {"","f","fo","foo","foob","fooba","foobar"}; static const std::string vstrOut[] = {"","my======","mzxq====","mzxw6===","mzxw6yq=","mzxw6ytb","mzxw6ytboi======"}; @@ -21,36 +21,36 @@ BOOST_AUTO_TEST_CASE(base32_testvectors) for (unsigned int i=0; i sourcedata = ParseHex(test[0].get_str()); std::string base58string = test[1].get_str(); - BOOST_CHECK_MESSAGE( - EncodeBase58(sourcedata) == base58string, - strTest); + CHECK(EncodeBase58(sourcedata) == base58string, strTest); } } // Goal: test low-level base58 decoding functionality -BOOST_AUTO_TEST_CASE(base58_DecodeBase58) +FIXTURE_TEST_CASE("base58_DecodeBase58", BasicTestingSetup) { UniValue tests = read_json(json_tests::base58_encode_decode); std::vector result; @@ -52,34 +50,35 @@ BOOST_AUTO_TEST_CASE(base58_DecodeBase58) std::string strTest = test.write(); if (test.size() < 2) // Allow for extra stuff (useful for comments) { - BOOST_ERROR("Bad test: " << strTest); + ; /* BOOST_ERROR("Bad test: " << strTest); */ continue; } std::vector expected = ParseHex(test[0].get_str()); std::string base58string = test[1].get_str(); - BOOST_CHECK_MESSAGE(DecodeBase58(base58string, result, 256), strTest); - BOOST_CHECK_MESSAGE(result.size() == expected.size() && std::equal(result.begin(), result.end(), expected.begin()), strTest); + CHECK(DecodeBase58(base58string, result, 256), strTest); + CHECK(result.size() == expected.size(), strTest); + CHECK(std::equal(result.begin(), result.end(), expected.begin()), strTest); } - BOOST_CHECK(!DecodeBase58("invalid"s, result, 100)); - BOOST_CHECK(!DecodeBase58("invalid\0"s, result, 100)); - BOOST_CHECK(!DecodeBase58("\0invalid"s, result, 100)); + CHECK(!DecodeBase58("invalid"s, result, 100)); + CHECK(!DecodeBase58("invalid\0"s, result, 100)); + CHECK(!DecodeBase58("\0invalid"s, result, 100)); - BOOST_CHECK( DecodeBase58("good"s, result, 100)); - BOOST_CHECK(!DecodeBase58("bad0IOl"s, result, 100)); - BOOST_CHECK(!DecodeBase58("goodbad0IOl"s, result, 100)); - BOOST_CHECK(!DecodeBase58("good\0bad0IOl"s, result, 100)); + CHECK(DecodeBase58("good"s, result, 100)); + CHECK(!DecodeBase58("bad0IOl"s, result, 100)); + CHECK(!DecodeBase58("goodbad0IOl"s, result, 100)); + CHECK(!DecodeBase58("good\0bad0IOl"s, result, 100)); // check that DecodeBase58 skips whitespace, but still fails with unexpected non-whitespace at the end. - BOOST_CHECK(!DecodeBase58(" \t\n\v\f\r skip \r\f\v\n\t a", result, 3)); - BOOST_CHECK( DecodeBase58(" \t\n\v\f\r skip \r\f\v\n\t ", result, 3)); + CHECK(!DecodeBase58(" \t\n\v\f\r skip \r\f\v\n\t a", result, 3)); + CHECK(DecodeBase58(" \t\n\v\f\r skip \r\f\v\n\t ", result, 3)); constexpr auto expected{"971a55"_hex_u8}; - BOOST_CHECK_EQUAL_COLLECTIONS(result.begin(), result.end(), expected.begin(), expected.end()); + CHECK_EQUAL_RANGES(result, expected); - BOOST_CHECK( DecodeBase58Check("3vQB7B6MrGQZaxCuFg4oh"s, result, 100)); - BOOST_CHECK(!DecodeBase58Check("3vQB7B6MrGQZaxCuFg4oi"s, result, 100)); - BOOST_CHECK(!DecodeBase58Check("3vQB7B6MrGQZaxCuFg4oh0IOl"s, result, 100)); - BOOST_CHECK(!DecodeBase58Check("3vQB7B6MrGQZaxCuFg4oh\0" "0IOl"s, result, 100)); + CHECK(DecodeBase58Check("3vQB7B6MrGQZaxCuFg4oh"s, result, 100)); + CHECK(!DecodeBase58Check("3vQB7B6MrGQZaxCuFg4oi"s, result, 100)); + CHECK(!DecodeBase58Check("3vQB7B6MrGQZaxCuFg4oh0IOl"s, result, 100)); + CHECK(!DecodeBase58Check("3vQB7B6MrGQZaxCuFg4oh\0" "0IOl"s, result, 100)); } -BOOST_AUTO_TEST_SUITE_END() +TEST_SUITE_END() diff --git a/src/test/base64_tests.cpp b/src/test/base64_tests.cpp index dbb56da64552..55facfff9658 100644 --- a/src/test/base64_tests.cpp +++ b/src/test/base64_tests.cpp @@ -4,26 +4,26 @@ #include -#include +#include #include #include using namespace std::literals; -BOOST_AUTO_TEST_SUITE(base64_tests) +TEST_SUITE_BEGIN("base64_tests") -BOOST_AUTO_TEST_CASE(base64_testvectors) +TEST_CASE("base64_testvectors") { static const std::string vstrIn[] = {"","f","fo","foo","foob","fooba","foobar"}; static const std::string vstrOut[] = {"","Zg==","Zm8=","Zm9v","Zm9vYg==","Zm9vYmE=","Zm9vYmFy"}; for (unsigned int i=0; i in_b{std::byte{0xff}, std::byte{0x01}, std::byte{0xff}}; const std::string in_s{"\xff\x01\xff"}; const std::string out_exp{"/wH/"}; - BOOST_CHECK_EQUAL(EncodeBase64(in_u), out_exp); - BOOST_CHECK_EQUAL(EncodeBase64(in_b), out_exp); - BOOST_CHECK_EQUAL(EncodeBase64(in_s), out_exp); + CHECK(EncodeBase64(in_u) == out_exp); + CHECK(EncodeBase64(in_b) == out_exp); + CHECK(EncodeBase64(in_s) == out_exp); } - BOOST_CHECK(DecodeBase64("nQB/pZw=")); // valid + CHECK(DecodeBase64("nQB/pZw=")); // valid // Decoding strings with embedded NUL characters should fail - BOOST_CHECK(!DecodeBase64("invalid\0"sv)); // correct size, invalid due to \0 - BOOST_CHECK(!DecodeBase64("nQB/pZw=\0invalid"sv)); - BOOST_CHECK(!DecodeBase64("nQB/pZw=invalid\0"sv)); // invalid, padding only allowed at the end + CHECK(!DecodeBase64("invalid\0"sv)); // correct size, invalid due to \0 + CHECK(!DecodeBase64("nQB/pZw=\0invalid"sv)); + CHECK(!DecodeBase64("nQB/pZw=invalid\0"sv)); // invalid, padding only allowed at the end } -BOOST_AUTO_TEST_CASE(base64_padding) +TEST_CASE("base64_padding") { // Is valid without padding - BOOST_CHECK_EQUAL(EncodeBase64("foobar"), "Zm9vYmFy"); + CHECK(EncodeBase64("foobar") == "Zm9vYmFy"); // Valid size - BOOST_CHECK(!DecodeBase64("====")); - BOOST_CHECK(!DecodeBase64("a===")); - BOOST_CHECK( DecodeBase64("YQ==")); - BOOST_CHECK( DecodeBase64("YWE=")); + CHECK(!DecodeBase64("====")); + CHECK(!DecodeBase64("a===")); + CHECK(DecodeBase64("YQ==")); + CHECK(DecodeBase64("YWE=")); } -BOOST_AUTO_TEST_SUITE_END() +TEST_SUITE_END() diff --git a/src/test/bech32_tests.cpp b/src/test/bech32_tests.cpp index 795510cfa21b..69317309ecd9 100644 --- a/src/test/bech32_tests.cpp +++ b/src/test/bech32_tests.cpp @@ -6,13 +6,13 @@ #include #include -#include +#include #include -BOOST_AUTO_TEST_SUITE(bech32_tests) +TEST_SUITE_BEGIN("bech32_tests") -BOOST_AUTO_TEST_CASE(bech32_testvectors_valid) +TEST_CASE("bech32_testvectors_valid") { static const std::string CASES[] = { "A12UEL5L", @@ -25,14 +25,14 @@ BOOST_AUTO_TEST_CASE(bech32_testvectors_valid) }; for (const std::string& str : CASES) { const auto dec = bech32::Decode(str); - BOOST_CHECK(dec.encoding == bech32::Encoding::BECH32); + CHECK(dec.encoding == bech32::Encoding::BECH32); std::string recode = bech32::Encode(bech32::Encoding::BECH32, dec.hrp, dec.data); - BOOST_CHECK(!recode.empty()); - BOOST_CHECK(CaseInsensitiveEqual(str, recode)); + CHECK(!recode.empty()); + CHECK(CaseInsensitiveEqual(str, recode)); } } -BOOST_AUTO_TEST_CASE(bech32m_testvectors_valid) +TEST_CASE("bech32m_testvectors_valid") { static const std::string CASES[] = { "A1LQFN3A", @@ -45,14 +45,14 @@ BOOST_AUTO_TEST_CASE(bech32m_testvectors_valid) }; for (const std::string& str : CASES) { const auto dec = bech32::Decode(str); - BOOST_CHECK(dec.encoding == bech32::Encoding::BECH32M); + CHECK(dec.encoding == bech32::Encoding::BECH32M); std::string recode = bech32::Encode(bech32::Encoding::BECH32M, dec.hrp, dec.data); - BOOST_CHECK(!recode.empty()); - BOOST_CHECK(CaseInsensitiveEqual(str, recode)); + CHECK(!recode.empty()); + CHECK(CaseInsensitiveEqual(str, recode)); } } -BOOST_AUTO_TEST_CASE(bech32_testvectors_invalid) +TEST_CASE("bech32_testvectors_invalid") { static const std::string CASES[] = { " 1nwldj5", @@ -96,15 +96,15 @@ BOOST_AUTO_TEST_CASE(bech32_testvectors_invalid) for (const std::string& str : CASES) { const auto& err = ERRORS[i]; const auto dec = bech32::Decode(str); - BOOST_CHECK(dec.encoding == bech32::Encoding::INVALID); + CHECK(dec.encoding == bech32::Encoding::INVALID); auto [error, error_locations] = bech32::LocateErrors(str); - BOOST_CHECK_EQUAL(err.first, error); - BOOST_CHECK(err.second == error_locations); + CHECK(err.first == error); + CHECK(err.second == error_locations); i++; } } -BOOST_AUTO_TEST_CASE(bech32m_testvectors_invalid) +TEST_CASE("bech32m_testvectors_invalid") { static const std::string CASES[] = { " 1xj0phk", @@ -148,12 +148,12 @@ BOOST_AUTO_TEST_CASE(bech32m_testvectors_invalid) for (const std::string& str : CASES) { const auto& err = ERRORS[i]; const auto dec = bech32::Decode(str); - BOOST_CHECK(dec.encoding == bech32::Encoding::INVALID); + CHECK(dec.encoding == bech32::Encoding::INVALID); auto [error, error_locations] = bech32::LocateErrors(str); - BOOST_CHECK_EQUAL(err.first, error); - BOOST_CHECK(err.second == error_locations); + CHECK(err.first == error); + CHECK(err.second == error_locations); i++; } } -BOOST_AUTO_TEST_SUITE_END() +TEST_SUITE_END() diff --git a/src/test/bip324_tests.cpp b/src/test/bip324_tests.cpp index b9f688148d05..83a7160a57d2 100644 --- a/src/test/bip324_tests.cpp +++ b/src/test/bip324_tests.cpp @@ -17,7 +17,7 @@ #include #include -#include +#include namespace { @@ -58,15 +58,15 @@ void TestBIP324PacketVector( // Instantiate encryption BIP324 cipher. BIP324Cipher cipher(key, ellswift_ours); - BOOST_CHECK(!cipher); - BOOST_CHECK(cipher.GetOurPubKey() == ellswift_ours); + CHECK(!cipher); + CHECK(cipher.GetOurPubKey() == ellswift_ours); cipher.Initialize(ellswift_theirs, in_initiating); - BOOST_CHECK(cipher); + CHECK(cipher); // Compare session variables. - BOOST_CHECK(std::ranges::equal(out_session_id, cipher.GetSessionID())); - BOOST_CHECK(std::ranges::equal(mid_send_garbage, cipher.GetSendGarbageTerminator())); - BOOST_CHECK(std::ranges::equal(mid_recv_garbage, cipher.GetReceiveGarbageTerminator())); + CHECK(std::ranges::equal(out_session_id, cipher.GetSessionID())); + CHECK(std::ranges::equal(mid_send_garbage, cipher.GetSendGarbageTerminator())); + CHECK(std::ranges::equal(mid_recv_garbage, cipher.GetReceiveGarbageTerminator())); // Vector of encrypted empty messages, encrypted in order to seek to the right position. std::vector> dummies(in_idx); @@ -88,10 +88,10 @@ void TestBIP324PacketVector( // Verify ciphertext. Note that the test vectors specify either out_ciphertext (for short // messages) or out_ciphertext_endswith (for long messages), so only check the relevant one. if (!out_ciphertext.empty()) { - BOOST_CHECK(out_ciphertext == ciphertext); + CHECK(out_ciphertext == ciphertext); } else { - BOOST_CHECK(ciphertext.size() >= out_ciphertext_endswith.size()); - BOOST_CHECK(std::ranges::equal(out_ciphertext_endswith, std::span{ciphertext}.last(out_ciphertext_endswith.size()))); + CHECK(ciphertext.size() >= out_ciphertext_endswith.size()); + CHECK(std::ranges::equal(out_ciphertext_endswith, std::span{ciphertext}.last(out_ciphertext_endswith.size()))); } for (unsigned error = 0; error <= 12; ++error) { @@ -105,15 +105,15 @@ void TestBIP324PacketVector( // Instantiate self-decrypting BIP324 cipher. BIP324Cipher dec_cipher(key, ellswift_ours); - BOOST_CHECK(!dec_cipher); - BOOST_CHECK(dec_cipher.GetOurPubKey() == ellswift_ours); + CHECK(!dec_cipher); + CHECK(dec_cipher.GetOurPubKey() == ellswift_ours); dec_cipher.Initialize(ellswift_theirs, (error == 1) ^ in_initiating, /*self_decrypt=*/true); - BOOST_CHECK(dec_cipher); + CHECK(dec_cipher); // Compare session variables. - BOOST_CHECK(std::ranges::equal(out_session_id, dec_cipher.GetSessionID()) == (error != 1)); - BOOST_CHECK(std::ranges::equal(mid_send_garbage, dec_cipher.GetSendGarbageTerminator()) == (error != 1)); - BOOST_CHECK(std::ranges::equal(mid_recv_garbage, dec_cipher.GetReceiveGarbageTerminator()) == (error != 1)); + CHECK(std::ranges::equal(out_session_id, dec_cipher.GetSessionID()) == (error != 1)); + CHECK(std::ranges::equal(mid_send_garbage, dec_cipher.GetSendGarbageTerminator()) == (error != 1)); + CHECK(std::ranges::equal(mid_recv_garbage, dec_cipher.GetReceiveGarbageTerminator()) == (error != 1)); // Seek to the numbered packet. if (in_idx == 0 && error == 12) continue; @@ -150,10 +150,10 @@ void TestBIP324PacketVector( bool dec_ok = dec_cipher.Decrypt(std::span{to_decrypt}.subspan(cipher.LENGTH_LEN), dec_aad, dec_ignore, decrypted); // Verify result. - BOOST_CHECK(dec_ok == !error); + CHECK(dec_ok == !error); if (dec_ok) { - BOOST_CHECK(decrypted == contents); - BOOST_CHECK(dec_ignore == in_ignore); + CHECK(decrypted == contents); + CHECK(dec_ignore == in_ignore); } } } @@ -161,9 +161,9 @@ void TestBIP324PacketVector( } // namespace -BOOST_FIXTURE_TEST_SUITE(bip324_tests, BIP324Test) +TEST_SUITE_BEGIN("bip324_tests") -BOOST_AUTO_TEST_CASE(packet_test_vectors) { +FIXTURE_TEST_CASE("packet_test_vectors", BIP324Test) { // BIP324 key derivation uses network magic in the HKDF process. We use mainnet params here // as that is what the test vectors are written for. SelectParams(ChainType::MAIN); @@ -300,4 +300,4 @@ BOOST_AUTO_TEST_CASE(packet_test_vectors) { "1a7f3fb83ad2b050b663b8df6b7c2cc2d8e169a869a58bf7ef5ab5db97a505c84a812e100d9445da4fc39a1176d6aed3995f6868631224b86f10603217c8d13270e0c6d054ad9e0d0b7dc0c8e59a37cd05a0a45faa14b4ffc8d12b641f62e6f1b71c1f72b737e9ce3fe74be779b25e70bf11d98766b3876d0fa28d3c669087fc"); } -BOOST_AUTO_TEST_SUITE_END() +TEST_SUITE_END() diff --git a/src/test/bip328_tests.cpp b/src/test/bip328_tests.cpp index 630771d5b6a4..bbf79f92bcaf 100644 --- a/src/test/bip328_tests.cpp +++ b/src/test/bip328_tests.cpp @@ -2,7 +2,7 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#include +#include #include #include @@ -22,9 +22,9 @@ struct BIP328TestVector { std::string expected_aggregate_xpub; }; -BOOST_FIXTURE_TEST_SUITE(bip328_tests, BasicTestingSetup) +TEST_SUITE_BEGIN("bip328_tests") -BOOST_AUTO_TEST_CASE(valid_keys) +FIXTURE_TEST_CASE("valid_keys", BasicTestingSetup) { // BIP 328 test vectors std::vector test_vectors = { @@ -74,28 +74,28 @@ BOOST_AUTO_TEST_CASE(valid_keys) // Aggregate public keys std::optional m_aggregate_pubkey = MuSig2AggregatePubkeys(pubkeys); - BOOST_CHECK_MESSAGE(m_aggregate_pubkey.has_value(), "Test vector " << i << ": Failed to aggregate pubkeys"); + CHECK(m_aggregate_pubkey.has_value(), "Test vector " << i << ": Failed to aggregate pubkeys"); // Check aggregate pubkey std::string combined_keys = HexStr(m_aggregate_pubkey.value()); - BOOST_CHECK_MESSAGE(combined_keys == test.expected_aggregate_pubkey, "Test vector " << i << ": Aggregate pubkey mismatch"); + CHECK(combined_keys == test.expected_aggregate_pubkey, "Test vector " << i << ": Aggregate pubkey mismatch"); // Create extended public key CExtPubKey extpub = CreateMuSig2SyntheticXpub(m_aggregate_pubkey.value()); // Check xpub std::string xpub = EncodeExtPubKey(extpub); - BOOST_CHECK_MESSAGE(xpub == test.expected_aggregate_xpub, "Test vector " << i << ": Synthetic xpub mismatch"); + CHECK(xpub == test.expected_aggregate_xpub, "Test vector " << i << ": Synthetic xpub mismatch"); } } -BOOST_AUTO_TEST_CASE(empty_pubkey_list) +FIXTURE_TEST_CASE("empty_pubkey_list", BasicTestingSetup) { const std::optional aggregate_pubkey{MuSig2AggregatePubkeys({})}; - BOOST_CHECK(!aggregate_pubkey.has_value()); + CHECK(!aggregate_pubkey.has_value()); } -BOOST_AUTO_TEST_CASE(invalid_key) +FIXTURE_TEST_CASE("invalid_key", BasicTestingSetup) { std::vector test_vectors = { "00ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", @@ -112,9 +112,9 @@ BOOST_AUTO_TEST_CASE(invalid_key) // Aggregate public keys std::optional m_aggregate_pubkey = MuSig2AggregatePubkeys(pubkeys); - BOOST_CHECK_MESSAGE(!m_aggregate_pubkey.has_value(), "Aggregate key with an invalid public key is null"); + CHECK(!m_aggregate_pubkey.has_value(), "Aggregate key with an invalid public key is null"); } -BOOST_AUTO_TEST_SUITE_END() +TEST_SUITE_END() } diff --git a/src/test/bip32_tests.cpp b/src/test/bip32_tests.cpp index 1df368ade744..fdca9fffb18c 100644 --- a/src/test/bip32_tests.cpp +++ b/src/test/bip32_tests.cpp @@ -2,7 +2,7 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#include +#include #include #include @@ -133,22 +133,22 @@ void RunTest(const TestVector& test) pubkey.Encode(data); // Test private key - BOOST_CHECK(EncodeExtKey(key) == derive.prv); - BOOST_CHECK(DecodeExtKey(derive.prv) == key); //ensure a base58 decoded key also matches + CHECK(EncodeExtKey(key) == derive.prv); + CHECK(DecodeExtKey(derive.prv) == key); //ensure a base58 decoded key also matches // Test public key - BOOST_CHECK(EncodeExtPubKey(pubkey) == derive.pub); - BOOST_CHECK(DecodeExtPubKey(derive.pub) == pubkey); //ensure a base58 decoded pubkey also matches + CHECK(EncodeExtPubKey(pubkey) == derive.pub); + CHECK(DecodeExtPubKey(derive.pub) == pubkey); //ensure a base58 decoded pubkey also matches // Derive new keys CExtKey keyNew; - BOOST_CHECK(key.Derive(keyNew, derive.nChild)); + CHECK(key.Derive(keyNew, derive.nChild)); CExtPubKey pubkeyNew = keyNew.Neuter(); if (!(derive.nChild & 0x80000000)) { // Compare with public derivation CExtPubKey pubkeyNew2; - BOOST_CHECK(pubkey.Derive(pubkeyNew2, derive.nChild)); - BOOST_CHECK(pubkeyNew == pubkeyNew2); + CHECK(pubkey.Derive(pubkeyNew2, derive.nChild)); + CHECK(pubkeyNew == pubkeyNew2); } key = keyNew; pubkey = pubkeyNew; @@ -157,49 +157,50 @@ void RunTest(const TestVector& test) } // namespace -BOOST_FIXTURE_TEST_SUITE(bip32_tests, BasicTestingSetup) +TEST_SUITE_BEGIN("bip32_tests") -BOOST_AUTO_TEST_CASE(bip32_test1) { +FIXTURE_TEST_CASE("bip32_test1", BasicTestingSetup) { RunTest(test1); } -BOOST_AUTO_TEST_CASE(bip32_test2) { +FIXTURE_TEST_CASE("bip32_test2", BasicTestingSetup) { RunTest(test2); } -BOOST_AUTO_TEST_CASE(bip32_test3) { +FIXTURE_TEST_CASE("bip32_test3", BasicTestingSetup) { RunTest(test3); } -BOOST_AUTO_TEST_CASE(bip32_test4) { +FIXTURE_TEST_CASE("bip32_test4", BasicTestingSetup) { RunTest(test4); } -BOOST_AUTO_TEST_CASE(bip32_test5) { +FIXTURE_TEST_CASE("bip32_test5", BasicTestingSetup) { for (const auto& str : TEST5) { auto dec_extkey = DecodeExtKey(str); auto dec_extpubkey = DecodeExtPubKey(str); - BOOST_CHECK_MESSAGE(!dec_extkey.key.IsValid(), "Decoding '" + str + "' as xprv should fail"); - BOOST_CHECK_MESSAGE(!dec_extpubkey.pubkey.IsValid(), "Decoding '" + str + "' as xpub should fail"); + CHECK(!dec_extkey.key.IsValid(), "Decoding '" + str + "' as xprv should fail"); + CHECK(!dec_extpubkey.pubkey.IsValid(), "Decoding '" + str + "' as xpub should fail"); } } -BOOST_AUTO_TEST_CASE(bip32_max_depth) { +FIXTURE_TEST_CASE("bip32_max_depth", BasicTestingSetup) { CExtKey key_parent{DecodeExtKey(test1.vDerive[0].prv)}, key_child; CExtPubKey pubkey_parent{DecodeExtPubKey(test1.vDerive[0].pub)}, pubkey_child; // We can derive up to the 255th depth.. for (auto i = 0; i++ < 255;) { - BOOST_CHECK(key_parent.Derive(key_child, 0)); + CHECK(key_parent.Derive(key_child, 0)); std::swap(key_parent, key_child); - BOOST_CHECK(pubkey_parent.Derive(pubkey_child, 0)); + CHECK(pubkey_parent.Derive(pubkey_child, 0)); std::swap(pubkey_parent, pubkey_child); } // But trying to derive a non-existent 256th depth will fail! - BOOST_CHECK(key_parent.nDepth == 255 && pubkey_parent.nDepth == 255); - BOOST_CHECK(!key_parent.Derive(key_child, 0)); - BOOST_CHECK(!pubkey_parent.Derive(pubkey_child, 0)); + CHECK(key_parent.nDepth == 255); + CHECK(pubkey_parent.nDepth == 255); + CHECK(!key_parent.Derive(key_child, 0)); + CHECK(!pubkey_parent.Derive(pubkey_child, 0)); } -BOOST_AUTO_TEST_SUITE_END() +TEST_SUITE_END() diff --git a/src/test/blockchain_tests.cpp b/src/test/blockchain_tests.cpp index 17cd5b6c2640..74645baef8a4 100644 --- a/src/test/blockchain_tests.cpp +++ b/src/test/blockchain_tests.cpp @@ -10,7 +10,7 @@ #include #include -#include +#include #include @@ -54,13 +54,6 @@ static CBlockIndex* CreateBlockIndexWithNbits(uint32_t nbits) return block_index; } -static void RejectDifficultyMismatch(double difficulty, double expected_difficulty) { - BOOST_CHECK_MESSAGE( - DoubleEquals(difficulty, expected_difficulty, 0.00001), - "Difficulty was " + ToString(difficulty) - + " but was expected to be " + ToString(expected_difficulty)); -} - /* Given a BlockIndex with the provided nbits, * verify that the expected difficulty results. */ @@ -70,32 +63,33 @@ static void TestDifficulty(uint32_t nbits, double expected_difficulty) double difficulty = GetDifficulty(*block_index); delete block_index; - RejectDifficultyMismatch(difficulty, expected_difficulty); + CHECK(DoubleEquals(difficulty, expected_difficulty, 0.00001), "Difficulty was " + ToString(difficulty) + + " but was expected to be " + ToString(expected_difficulty)); } -BOOST_FIXTURE_TEST_SUITE(blockchain_tests, BasicTestingSetup) +TEST_SUITE_BEGIN("blockchain_tests") -BOOST_AUTO_TEST_CASE(get_difficulty_for_very_low_target) +FIXTURE_TEST_CASE("get_difficulty_for_very_low_target", BasicTestingSetup) { TestDifficulty(0x1f111111, 0.000001); } -BOOST_AUTO_TEST_CASE(get_difficulty_for_low_target) +FIXTURE_TEST_CASE("get_difficulty_for_low_target", BasicTestingSetup) { TestDifficulty(0x1ef88f6f, 0.000016); } -BOOST_AUTO_TEST_CASE(get_difficulty_for_mid_target) +FIXTURE_TEST_CASE("get_difficulty_for_mid_target", BasicTestingSetup) { TestDifficulty(0x1df88f6f, 0.004023); } -BOOST_AUTO_TEST_CASE(get_difficulty_for_high_target) +FIXTURE_TEST_CASE("get_difficulty_for_high_target", BasicTestingSetup) { TestDifficulty(0x1cf88f6f, 1.029916); } -BOOST_AUTO_TEST_CASE(get_difficulty_for_very_high_target) +FIXTURE_TEST_CASE("get_difficulty_for_very_high_target", BasicTestingSetup) { TestDifficulty(0x12345678, 5913134931067755359633408.0); } @@ -113,18 +107,18 @@ static void CheckGetPruneHeight(const node::BlockManager& blockman, const CChain } const auto prune_height{GetPruneHeight(blockman, chain)}; - BOOST_REQUIRE(prune_height.has_value()); - BOOST_CHECK_EQUAL(*prune_height, height); + REQUIRE(prune_height.has_value()); + CHECK(*prune_height == height); } -BOOST_FIXTURE_TEST_CASE(get_prune_height, TestChain100Setup) +FIXTURE_TEST_CASE("get_prune_height", TestChain100Setup) { LOCK(::cs_main); const auto& chain = m_node.chainman->ActiveChain(); const auto& blockman = m_node.chainman->m_blockman; // Fresh chain of 100 blocks without any pruned blocks, so std::nullopt should be returned - BOOST_CHECK(!GetPruneHeight(blockman, chain).has_value()); + CHECK(!GetPruneHeight(blockman, chain).has_value()); // Start pruning CheckGetPruneHeight(blockman, chain, 1); @@ -132,14 +126,14 @@ BOOST_FIXTURE_TEST_CASE(get_prune_height, TestChain100Setup) CheckGetPruneHeight(blockman, chain, 100); } -BOOST_AUTO_TEST_CASE(num_chain_tx_max) +FIXTURE_TEST_CASE("num_chain_tx_max", BasicTestingSetup) { CBlockIndex block_index{}; block_index.m_chain_tx_count = std::numeric_limits::max(); - BOOST_CHECK_EQUAL(block_index.m_chain_tx_count, std::numeric_limits::max()); + CHECK(block_index.m_chain_tx_count == std::numeric_limits::max()); } -BOOST_FIXTURE_TEST_CASE(invalidate_block, TestChain100Setup) +FIXTURE_TEST_CASE("invalidate_block", TestChain100Setup) { const CChain& active{*WITH_LOCK(Assert(m_node.chainman)->GetMutex(), return &Assert(m_node.chainman)->ActiveChain())}; @@ -169,4 +163,4 @@ BOOST_FIXTURE_TEST_CASE(invalidate_block, TestChain100Setup) } } -BOOST_AUTO_TEST_SUITE_END() +TEST_SUITE_END() diff --git a/src/test/blockencodings_tests.cpp b/src/test/blockencodings_tests.cpp index e4200cace259..980a88ca8091 100644 --- a/src/test/blockencodings_tests.cpp +++ b/src/test/blockencodings_tests.cpp @@ -13,11 +13,11 @@ #include #include -#include +#include const std::vector> empty_extra_txn; -BOOST_FIXTURE_TEST_SUITE(blockencodings_tests, RegTestingSetup) +TEST_SUITE_BEGIN("blockencodings_tests") static CMutableTransaction BuildTransactionTestCase() { CMutableTransaction tx; @@ -60,7 +60,7 @@ static CBlock BuildBlockTestCase(FastRandomContext& ctx) { // (block + mempool entry + our copy from the GetSharedTx call) constexpr long SHARED_TX_OFFSET{3}; -BOOST_AUTO_TEST_CASE(SimpleRoundTripTest) +FIXTURE_TEST_CASE("SimpleRoundTripTest", RegTestingSetup) { CTxMemPool& pool = *Assert(m_node.mempool); TestMemPoolEntryHelper entry; @@ -69,7 +69,7 @@ BOOST_AUTO_TEST_CASE(SimpleRoundTripTest) LOCK2(cs_main, pool.cs); TryAddToMempool(pool, entry.FromTx(block.vtx[2])); - BOOST_CHECK_EQUAL(pool.get(block.vtx[2]->GetHash()).use_count(), SHARED_TX_OFFSET + 0); + CHECK(pool.get(block.vtx[2]->GetHash()).use_count() == SHARED_TX_OFFSET + 0); // Do a simple ShortTxIDs RT { @@ -82,21 +82,21 @@ BOOST_AUTO_TEST_CASE(SimpleRoundTripTest) stream >> shortIDs2; PartiallyDownloadedBlock partialBlock(&pool); - BOOST_CHECK(partialBlock.InitData(shortIDs2, empty_extra_txn) == READ_STATUS_OK); - BOOST_CHECK( partialBlock.IsTxAvailable(0)); - BOOST_CHECK(!partialBlock.IsTxAvailable(1)); - BOOST_CHECK( partialBlock.IsTxAvailable(2)); + CHECK(partialBlock.InitData(shortIDs2, empty_extra_txn) == READ_STATUS_OK); + CHECK(partialBlock.IsTxAvailable(0)); + CHECK(!partialBlock.IsTxAvailable(1)); + CHECK(partialBlock.IsTxAvailable(2)); - BOOST_CHECK_EQUAL(pool.get(block.vtx[2]->GetHash()).use_count(), SHARED_TX_OFFSET + 1); + CHECK(pool.get(block.vtx[2]->GetHash()).use_count() == SHARED_TX_OFFSET + 1); size_t poolSize = pool.size(); pool.removeRecursive(*block.vtx[2], MemPoolRemovalReason::REPLACED); - BOOST_CHECK_EQUAL(pool.size(), poolSize - 1); + CHECK(pool.size() == poolSize - 1); CBlock block2; { PartiallyDownloadedBlock tmp = partialBlock; - BOOST_CHECK(partialBlock.FillBlock(block2, {}, /*segwit_active=*/true) == READ_STATUS_INVALID); // No transactions + CHECK(partialBlock.FillBlock(block2, {}, /*segwit_active=*/true) == READ_STATUS_INVALID); // No transactions partialBlock = tmp; } @@ -107,13 +107,13 @@ BOOST_AUTO_TEST_CASE(SimpleRoundTripTest) partialBlock = tmp; } bool mutated; - BOOST_CHECK(block.hashMerkleRoot != BlockMerkleRoot(block2, &mutated)); + CHECK(block.hashMerkleRoot != BlockMerkleRoot(block2, &mutated)); CBlock block3; - BOOST_CHECK(partialBlock.FillBlock(block3, {block.vtx[1]}, /*segwit_active=*/true) == READ_STATUS_OK); - BOOST_CHECK_EQUAL(block.GetHash().ToString(), block3.GetHash().ToString()); - BOOST_CHECK_EQUAL(block.hashMerkleRoot.ToString(), BlockMerkleRoot(block3, &mutated).ToString()); - BOOST_CHECK(!mutated); + CHECK(partialBlock.FillBlock(block3, {block.vtx[1]}, /*segwit_active=*/true) == READ_STATUS_OK); + CHECK(block.GetHash().ToString() == block3.GetHash().ToString()); + CHECK(block.hashMerkleRoot.ToString() == BlockMerkleRoot(block3, &mutated).ToString()); + CHECK(!mutated); } } @@ -144,7 +144,7 @@ class TestHeaderAndShortIDs { SERIALIZE_METHODS(TestHeaderAndShortIDs, obj) { READWRITE(obj.header, obj.nonce, Using>>(obj.shorttxids), obj.prefilledtxn); } }; -BOOST_AUTO_TEST_CASE(NonCoinbasePreforwardRTTest) +FIXTURE_TEST_CASE("NonCoinbasePreforwardRTTest", RegTestingSetup) { CTxMemPool& pool = *Assert(m_node.mempool); TestMemPoolEntryHelper entry; @@ -153,7 +153,7 @@ BOOST_AUTO_TEST_CASE(NonCoinbasePreforwardRTTest) LOCK2(cs_main, pool.cs); TryAddToMempool(pool, entry.FromTx(block.vtx[2])); - BOOST_CHECK_EQUAL(pool.get(block.vtx[2]->GetHash()).use_count(), SHARED_TX_OFFSET + 0); + CHECK(pool.get(block.vtx[2]->GetHash()).use_count() == SHARED_TX_OFFSET + 0); Txid txhash; @@ -173,17 +173,17 @@ BOOST_AUTO_TEST_CASE(NonCoinbasePreforwardRTTest) stream >> shortIDs2; PartiallyDownloadedBlock partialBlock(&pool); - BOOST_CHECK(partialBlock.InitData(shortIDs2, empty_extra_txn) == READ_STATUS_OK); - BOOST_CHECK(!partialBlock.IsTxAvailable(0)); - BOOST_CHECK( partialBlock.IsTxAvailable(1)); - BOOST_CHECK( partialBlock.IsTxAvailable(2)); + CHECK(partialBlock.InitData(shortIDs2, empty_extra_txn) == READ_STATUS_OK); + CHECK(!partialBlock.IsTxAvailable(0)); + CHECK(partialBlock.IsTxAvailable(1)); + CHECK(partialBlock.IsTxAvailable(2)); - BOOST_CHECK_EQUAL(pool.get(block.vtx[2]->GetHash()).use_count(), SHARED_TX_OFFSET + 1); // +1 because of partialBlock + CHECK(pool.get(block.vtx[2]->GetHash()).use_count() == SHARED_TX_OFFSET + 1); // +1 because of partialBlock CBlock block2; { PartiallyDownloadedBlock tmp = partialBlock; - BOOST_CHECK(partialBlock.FillBlock(block2, {}, /*segwit_active=*/true) == READ_STATUS_INVALID); // No transactions + CHECK(partialBlock.FillBlock(block2, {}, /*segwit_active=*/true) == READ_STATUS_INVALID); // No transactions partialBlock = tmp; } @@ -193,29 +193,29 @@ BOOST_AUTO_TEST_CASE(NonCoinbasePreforwardRTTest) partialBlock.FillBlock(block2, {block.vtx[1]}, /*segwit_active=*/true); // Current implementation doesn't check txn here, but don't require that partialBlock = tmp; } - BOOST_CHECK_EQUAL(pool.get(block.vtx[2]->GetHash()).use_count(), SHARED_TX_OFFSET + 2); // +2 because of partialBlock and block2 + CHECK(pool.get(block.vtx[2]->GetHash()).use_count() == SHARED_TX_OFFSET + 2); // +2 because of partialBlock and block2 bool mutated; - BOOST_CHECK(block.hashMerkleRoot != BlockMerkleRoot(block2, &mutated)); + CHECK(block.hashMerkleRoot != BlockMerkleRoot(block2, &mutated)); CBlock block3; PartiallyDownloadedBlock partialBlockCopy = partialBlock; - BOOST_CHECK(partialBlock.FillBlock(block3, {block.vtx[0]}, /*segwit_active=*/true) == READ_STATUS_OK); - BOOST_CHECK_EQUAL(block.GetHash().ToString(), block3.GetHash().ToString()); - BOOST_CHECK_EQUAL(block.hashMerkleRoot.ToString(), BlockMerkleRoot(block3, &mutated).ToString()); - BOOST_CHECK(!mutated); + CHECK(partialBlock.FillBlock(block3, {block.vtx[0]}, /*segwit_active=*/true) == READ_STATUS_OK); + CHECK(block.GetHash().ToString() == block3.GetHash().ToString()); + CHECK(block.hashMerkleRoot.ToString() == BlockMerkleRoot(block3, &mutated).ToString()); + CHECK(!mutated); - BOOST_CHECK_EQUAL(pool.get(block.vtx[2]->GetHash()).use_count(), SHARED_TX_OFFSET + 3); // +2 because of partialBlock and block2 and block3 + CHECK(pool.get(block.vtx[2]->GetHash()).use_count() == SHARED_TX_OFFSET + 3); // +2 because of partialBlock and block2 and block3 txhash = block.vtx[2]->GetHash(); block.vtx.clear(); block2.vtx.clear(); block3.vtx.clear(); - BOOST_CHECK_EQUAL(pool.get(txhash).use_count(), SHARED_TX_OFFSET + 1 - 1); // + 1 because of partialBlock; -1 because of block. + CHECK(pool.get(txhash).use_count() == SHARED_TX_OFFSET + 1 - 1); // + 1 because of partialBlock; -1 because of block. } - BOOST_CHECK_EQUAL(pool.get(txhash).use_count(), SHARED_TX_OFFSET - 1); // -1 because of block + CHECK(pool.get(txhash).use_count() == SHARED_TX_OFFSET - 1); // -1 because of block } -BOOST_AUTO_TEST_CASE(SufficientPreforwardRTTest) +FIXTURE_TEST_CASE("SufficientPreforwardRTTest", RegTestingSetup) { CTxMemPool& pool = *Assert(m_node.mempool); TestMemPoolEntryHelper entry; @@ -224,7 +224,7 @@ BOOST_AUTO_TEST_CASE(SufficientPreforwardRTTest) LOCK2(cs_main, pool.cs); TryAddToMempool(pool, entry.FromTx(block.vtx[1])); - BOOST_CHECK_EQUAL(pool.get(block.vtx[1]->GetHash()).use_count(), SHARED_TX_OFFSET + 0); + CHECK(pool.get(block.vtx[1]->GetHash()).use_count() == SHARED_TX_OFFSET + 0); Txid txhash; @@ -244,30 +244,30 @@ BOOST_AUTO_TEST_CASE(SufficientPreforwardRTTest) stream >> shortIDs2; PartiallyDownloadedBlock partialBlock(&pool); - BOOST_CHECK(partialBlock.InitData(shortIDs2, empty_extra_txn) == READ_STATUS_OK); - BOOST_CHECK( partialBlock.IsTxAvailable(0)); - BOOST_CHECK( partialBlock.IsTxAvailable(1)); - BOOST_CHECK( partialBlock.IsTxAvailable(2)); + CHECK(partialBlock.InitData(shortIDs2, empty_extra_txn) == READ_STATUS_OK); + CHECK(partialBlock.IsTxAvailable(0)); + CHECK(partialBlock.IsTxAvailable(1)); + CHECK(partialBlock.IsTxAvailable(2)); - BOOST_CHECK_EQUAL(pool.get(block.vtx[1]->GetHash()).use_count(), SHARED_TX_OFFSET + 1); + CHECK(pool.get(block.vtx[1]->GetHash()).use_count() == SHARED_TX_OFFSET + 1); CBlock block2; PartiallyDownloadedBlock partialBlockCopy = partialBlock; - BOOST_CHECK(partialBlock.FillBlock(block2, {}, /*segwit_active=*/true) == READ_STATUS_OK); - BOOST_CHECK_EQUAL(block.GetHash().ToString(), block2.GetHash().ToString()); + CHECK(partialBlock.FillBlock(block2, {}, /*segwit_active=*/true) == READ_STATUS_OK); + CHECK(block.GetHash().ToString() == block2.GetHash().ToString()); bool mutated; - BOOST_CHECK_EQUAL(block.hashMerkleRoot.ToString(), BlockMerkleRoot(block2, &mutated).ToString()); - BOOST_CHECK(!mutated); + CHECK(block.hashMerkleRoot.ToString() == BlockMerkleRoot(block2, &mutated).ToString()); + CHECK(!mutated); txhash = block.vtx[1]->GetHash(); block.vtx.clear(); block2.vtx.clear(); - BOOST_CHECK_EQUAL(pool.get(txhash).use_count(), SHARED_TX_OFFSET + 1 - 1); // + 1 because of partialBlock; -1 because of block. + CHECK(pool.get(txhash).use_count() == SHARED_TX_OFFSET + 1 - 1); // + 1 because of partialBlock; -1 because of block. } - BOOST_CHECK_EQUAL(pool.get(txhash).use_count(), SHARED_TX_OFFSET - 1); // -1 because of block + CHECK(pool.get(txhash).use_count() == SHARED_TX_OFFSET - 1); // -1 because of block } -BOOST_AUTO_TEST_CASE(EmptyBlockRoundTripTest) +FIXTURE_TEST_CASE("EmptyBlockRoundTripTest", RegTestingSetup) { CTxMemPool& pool = *Assert(m_node.mempool); CMutableTransaction coinbase = BuildTransactionTestCase(); @@ -296,19 +296,19 @@ BOOST_AUTO_TEST_CASE(EmptyBlockRoundTripTest) stream >> shortIDs2; PartiallyDownloadedBlock partialBlock(&pool); - BOOST_CHECK(partialBlock.InitData(shortIDs2, empty_extra_txn) == READ_STATUS_OK); - BOOST_CHECK(partialBlock.IsTxAvailable(0)); + CHECK(partialBlock.InitData(shortIDs2, empty_extra_txn) == READ_STATUS_OK); + CHECK(partialBlock.IsTxAvailable(0)); CBlock block2; std::vector vtx_missing; - BOOST_CHECK(partialBlock.FillBlock(block2, vtx_missing, /*segwit_active=*/true) == READ_STATUS_OK); - BOOST_CHECK_EQUAL(block.GetHash().ToString(), block2.GetHash().ToString()); - BOOST_CHECK_EQUAL(block.hashMerkleRoot.ToString(), BlockMerkleRoot(block2, &mutated).ToString()); - BOOST_CHECK(!mutated); + CHECK(partialBlock.FillBlock(block2, vtx_missing, /*segwit_active=*/true) == READ_STATUS_OK); + CHECK(block.GetHash().ToString() == block2.GetHash().ToString()); + CHECK(block.hashMerkleRoot.ToString() == BlockMerkleRoot(block2, &mutated).ToString()); + CHECK(!mutated); } } -BOOST_AUTO_TEST_CASE(ReceiveWithExtraTransactions) { +FIXTURE_TEST_CASE("ReceiveWithExtraTransactions", RegTestingSetup) { CTxMemPool& pool = *Assert(m_node.mempool); TestMemPoolEntryHelper entry; auto rand_ctx(FastRandomContext(uint256{42})); @@ -324,38 +324,38 @@ BOOST_AUTO_TEST_CASE(ReceiveWithExtraTransactions) { LOCK2(cs_main, pool.cs); TryAddToMempool(pool, entry.FromTx(block.vtx[2])); - BOOST_CHECK_EQUAL(pool.get(block.vtx[2]->GetHash()).use_count(), SHARED_TX_OFFSET + 0); + CHECK(pool.get(block.vtx[2]->GetHash()).use_count() == SHARED_TX_OFFSET + 0); // Ensure the non_block_tx is actually not in the block for (const auto &block_tx : block.vtx) { - BOOST_CHECK_NE(block_tx->GetHash(), non_block_tx->GetHash()); + CHECK(block_tx->GetHash() != non_block_tx->GetHash()); } // Ensure block.vtx[1] is not in pool - BOOST_CHECK_EQUAL(pool.get(block.vtx[1]->GetHash()), nullptr); + CHECK(pool.get(block.vtx[1]->GetHash()) == nullptr); { const CBlockHeaderAndShortTxIDs cmpctblock{block, rand_ctx.rand64()}; PartiallyDownloadedBlock partial_block(&pool); PartiallyDownloadedBlock partial_block_with_extra(&pool); - BOOST_CHECK(partial_block.InitData(cmpctblock, extra_txn) == READ_STATUS_OK); - BOOST_CHECK( partial_block.IsTxAvailable(0)); - BOOST_CHECK(!partial_block.IsTxAvailable(1)); - BOOST_CHECK( partial_block.IsTxAvailable(2)); + CHECK(partial_block.InitData(cmpctblock, extra_txn) == READ_STATUS_OK); + CHECK(partial_block.IsTxAvailable(0)); + CHECK(!partial_block.IsTxAvailable(1)); + CHECK(partial_block.IsTxAvailable(2)); // Add an unrelated tx to extra_txn: extra_txn[0] = {non_block_tx->GetWitnessHash(), non_block_tx}; // and a tx from the block that's not in the mempool: extra_txn[1] = {block.vtx[1]->GetWitnessHash(), block.vtx[1]}; - BOOST_CHECK(partial_block_with_extra.InitData(cmpctblock, extra_txn) == READ_STATUS_OK); - BOOST_CHECK(partial_block_with_extra.IsTxAvailable(0)); + CHECK(partial_block_with_extra.InitData(cmpctblock, extra_txn) == READ_STATUS_OK); + CHECK(partial_block_with_extra.IsTxAvailable(0)); // This transaction is now available via extra_txn: - BOOST_CHECK(partial_block_with_extra.IsTxAvailable(1)); - BOOST_CHECK(partial_block_with_extra.IsTxAvailable(2)); + CHECK(partial_block_with_extra.IsTxAvailable(1)); + CHECK(partial_block_with_extra.IsTxAvailable(2)); } } -BOOST_AUTO_TEST_CASE(TransactionsRequestSerializationTest) { +FIXTURE_TEST_CASE("TransactionsRequestSerializationTest", RegTestingSetup) { BlockTransactionsRequest req1; req1.blockhash = m_rng.rand256(); req1.indexes.resize(4); @@ -370,15 +370,15 @@ BOOST_AUTO_TEST_CASE(TransactionsRequestSerializationTest) { BlockTransactionsRequest req2; stream >> req2; - BOOST_CHECK_EQUAL(req1.blockhash.ToString(), req2.blockhash.ToString()); - BOOST_CHECK_EQUAL(req1.indexes.size(), req2.indexes.size()); - BOOST_CHECK_EQUAL(req1.indexes[0], req2.indexes[0]); - BOOST_CHECK_EQUAL(req1.indexes[1], req2.indexes[1]); - BOOST_CHECK_EQUAL(req1.indexes[2], req2.indexes[2]); - BOOST_CHECK_EQUAL(req1.indexes[3], req2.indexes[3]); + CHECK(req1.blockhash.ToString() == req2.blockhash.ToString()); + CHECK(req1.indexes.size() == req2.indexes.size()); + CHECK(req1.indexes[0] == req2.indexes[0]); + CHECK(req1.indexes[1] == req2.indexes[1]); + CHECK(req1.indexes[2] == req2.indexes[2]); + CHECK(req1.indexes[3] == req2.indexes[3]); } -BOOST_AUTO_TEST_CASE(TransactionsRequestDeserializationMaxTest) { +FIXTURE_TEST_CASE("TransactionsRequestDeserializationMaxTest", RegTestingSetup) { // Check that the highest legal index is decoded correctly BlockTransactionsRequest req0; req0.blockhash = m_rng.rand256(); @@ -389,11 +389,11 @@ BOOST_AUTO_TEST_CASE(TransactionsRequestDeserializationMaxTest) { BlockTransactionsRequest req1; stream >> req1; - BOOST_CHECK_EQUAL(req0.indexes.size(), req1.indexes.size()); - BOOST_CHECK_EQUAL(req0.indexes[0], req1.indexes[0]); + CHECK(req0.indexes.size() == req1.indexes.size()); + CHECK(req0.indexes[0] == req1.indexes[0]); } -BOOST_AUTO_TEST_CASE(TransactionsRequestDeserializationOverflowTest) { +FIXTURE_TEST_CASE("TransactionsRequestDeserializationOverflowTest", RegTestingSetup) { // Any set of index deltas that starts with N values that sum to (0x10000 - N) // causes the edge-case overflow that was originally not checked for. Such // a request cannot be created by serializing a real BlockTransactionsRequest @@ -415,13 +415,13 @@ BOOST_AUTO_TEST_CASE(TransactionsRequestDeserializationOverflowTest) { try { stream >> req1; // before patch: deserialize above succeeds and this check fails, demonstrating the overflow - BOOST_CHECK(req1.indexes[1] < req1.indexes[2]); + CHECK(req1.indexes[1] < req1.indexes[2]); // this shouldn't be reachable before or after patch - BOOST_CHECK(0); + CHECK(0); } catch(std::ios_base::failure &) { // deserialize should fail - BOOST_CHECK(true); // Needed to suppress "Test case [...] did not check any assertions" + CHECK(true); // Needed to suppress "Test case [...] did not check any assertions" } } -BOOST_AUTO_TEST_SUITE_END() +TEST_SUITE_END() diff --git a/src/test/blockmanager_tests.cpp b/src/test/blockmanager_tests.cpp index 04bfd20c06d7..c60d8adf410b 100644 --- a/src/test/blockmanager_tests.cpp +++ b/src/test/blockmanager_tests.cpp @@ -3,6 +3,7 @@ // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include +#include #include #include #include @@ -13,7 +14,7 @@ #include #include -#include +#include #include #include #include @@ -25,9 +26,9 @@ using node::KernelNotifications; using node::MAX_BLOCKFILE_SIZE; // use BasicTestingSetup here for the data directory configuration, setup, and cleanup -BOOST_FIXTURE_TEST_SUITE(blockmanager_tests, BasicTestingSetup) +TEST_SUITE_BEGIN("blockmanager_tests") -BOOST_AUTO_TEST_CASE(blockmanager_find_block_pos) +FIXTURE_TEST_CASE("blockmanager_find_block_pos", BasicTestingSetup) { const auto params {CreateChainParams(ArgsManager{}, ChainType::MAIN)}; KernelNotifications notifications{Assert(m_node.shutdown_request), m_node.exit_status, *Assert(m_node.warnings)}; @@ -42,7 +43,7 @@ BOOST_AUTO_TEST_CASE(blockmanager_find_block_pos) }; BlockManager blockman{*Assert(m_node.shutdown_signal), blockman_opts}; // simulate adding a genesis block normally - BOOST_CHECK_EQUAL(blockman.WriteBlock(params->GenesisBlock(), 0).nPos, STORAGE_HEADER_BYTES); + CHECK(blockman.WriteBlock(params->GenesisBlock(), 0).nPos == STORAGE_HEADER_BYTES); // simulate what happens during reindex // simulate a well-formed genesis block being found at offset 8 in the blk00000.dat file // the block is found at offset 8 because there is an 8 byte serialization header @@ -56,10 +57,10 @@ BOOST_AUTO_TEST_CASE(blockmanager_find_block_pos) // 8 bytes (for serialization header) + 285 (for serialized genesis block) = 293 // add another 8 bytes for the second block's serialization header and we get 293 + 8 = 301 FlatFilePos actual{blockman.WriteBlock(params->GenesisBlock(), 1)}; - BOOST_CHECK_EQUAL(actual.nPos, STORAGE_HEADER_BYTES + ::GetSerializeSize(TX_WITH_WITNESS(params->GenesisBlock())) + STORAGE_HEADER_BYTES); + CHECK(actual.nPos == STORAGE_HEADER_BYTES + ::GetSerializeSize(TX_WITH_WITNESS(params->GenesisBlock())) + STORAGE_HEADER_BYTES); } -BOOST_FIXTURE_TEST_CASE(blockmanager_scan_unlink_already_pruned_files, TestChain100Setup) +FIXTURE_TEST_CASE("blockmanager_scan_unlink_already_pruned_files", TestChain100Setup) { // Cap last block file size, and mine new block in a new block file. auto& chainman{*Assert(m_node.chainman)}; @@ -81,26 +82,26 @@ BOOST_FIXTURE_TEST_CASE(blockmanager_scan_unlink_already_pruned_files, TestChain // Check that the file is not unlinked after ScanAndUnlinkAlreadyPrunedFiles // if m_have_pruned is not yet set WITH_LOCK(chainman.GetMutex(), blockman.ScanAndUnlinkAlreadyPrunedFiles()); - BOOST_CHECK(!blockman.OpenBlockFile(pos, true).IsNull()); + CHECK(!blockman.OpenBlockFile(pos, true).IsNull()); // Check that the file is unlinked after ScanAndUnlinkAlreadyPrunedFiles // once m_have_pruned is set blockman.m_have_pruned = true; WITH_LOCK(chainman.GetMutex(), blockman.ScanAndUnlinkAlreadyPrunedFiles()); - BOOST_CHECK(blockman.OpenBlockFile(pos, true).IsNull()); + CHECK(blockman.OpenBlockFile(pos, true).IsNull()); // Check that calling with already pruned files doesn't cause an error WITH_LOCK(chainman.GetMutex(), blockman.ScanAndUnlinkAlreadyPrunedFiles()); // Check that the new tip file has not been removed const CBlockIndex* new_tip{WITH_LOCK(chainman.GetMutex(), return chainman.ActiveChain().Tip())}; - BOOST_CHECK_NE(old_tip, new_tip); + CHECK(old_tip != new_tip); const int new_file_number{WITH_LOCK(chainman.GetMutex(), return new_tip->GetBlockPos().nFile)}; const FlatFilePos new_pos(new_file_number, 0); - BOOST_CHECK(!blockman.OpenBlockFile(new_pos, true).IsNull()); + CHECK(!blockman.OpenBlockFile(new_pos, true).IsNull()); } -BOOST_FIXTURE_TEST_CASE(blockmanager_block_data_availability, TestChain100Setup) +FIXTURE_TEST_CASE("blockmanager_block_data_availability", TestChain100Setup) { // The goal of the function is to return the first not pruned block in the range [upper_block, lower_block]. LOCK(::cs_main); @@ -120,20 +121,20 @@ BOOST_FIXTURE_TEST_CASE(blockmanager_block_data_availability, TestChain100Setup) }; // 1) Return genesis block when all blocks are available - BOOST_CHECK_EQUAL(&blockman.GetFirstBlock(tip, BLOCK_HAVE_DATA), chainman->ActiveChain()[0]); - BOOST_CHECK(blockman.CheckBlockDataAvailability(tip, *chainman->ActiveChain()[0])); + CHECK((&blockman.GetFirstBlock(tip, BLOCK_HAVE_DATA) == chainman->ActiveChain()[0])); + CHECK(blockman.CheckBlockDataAvailability(tip, *chainman->ActiveChain()[0])); // 2) Check lower_block when all blocks are available CBlockIndex* lower_block = chainman->ActiveChain()[tip.nHeight / 2]; - BOOST_CHECK(blockman.CheckBlockDataAvailability(tip, *lower_block)); + CHECK(blockman.CheckBlockDataAvailability(tip, *lower_block)); // Ensure we don't fail due to the expected absence of undo data in the genesis block CBlockIndex* upper_block = chainman->ActiveChain()[2]; CBlockIndex* genesis = chainman->ActiveChain()[0]; - BOOST_CHECK(blockman.CheckBlockDataAvailability(*upper_block, *genesis, BlockStatus{BLOCK_HAVE_DATA | BLOCK_HAVE_UNDO})); + CHECK(blockman.CheckBlockDataAvailability(*upper_block, *genesis, BlockStatus{BLOCK_HAVE_DATA | BLOCK_HAVE_UNDO})); // Ensure we detect absence of undo data in the first block chainman->ActiveChain()[1]->nStatus &= ~BLOCK_HAVE_UNDO; - BOOST_CHECK(!blockman.CheckBlockDataAvailability(tip, *genesis, BlockStatus{BLOCK_HAVE_DATA | BLOCK_HAVE_UNDO})); + CHECK(!blockman.CheckBlockDataAvailability(tip, *genesis, BlockStatus{BLOCK_HAVE_DATA | BLOCK_HAVE_UNDO})); // Prune half of the blocks int height_to_prune = tip.nHeight / 2; @@ -142,18 +143,18 @@ BOOST_FIXTURE_TEST_CASE(blockmanager_block_data_availability, TestChain100Setup) func_prune_blocks(last_pruned_block); // 3) The last block not pruned is in-between upper-block and the genesis block - BOOST_CHECK_EQUAL(&blockman.GetFirstBlock(tip, BLOCK_HAVE_DATA), first_available_block); - BOOST_CHECK(blockman.CheckBlockDataAvailability(tip, *first_available_block)); - BOOST_CHECK(!blockman.CheckBlockDataAvailability(tip, *last_pruned_block)); + CHECK((&blockman.GetFirstBlock(tip, BLOCK_HAVE_DATA) == first_available_block)); + CHECK(blockman.CheckBlockDataAvailability(tip, *first_available_block)); + CHECK(!blockman.CheckBlockDataAvailability(tip, *last_pruned_block)); // Simulate that the first available block is missing undo data and // detect this by using a status mask. first_available_block->nStatus &= ~BLOCK_HAVE_UNDO; - BOOST_CHECK(!blockman.CheckBlockDataAvailability(tip, *first_available_block, BlockStatus{BLOCK_HAVE_DATA | BLOCK_HAVE_UNDO})); - BOOST_CHECK(blockman.CheckBlockDataAvailability(tip, *first_available_block, BlockStatus{BLOCK_HAVE_DATA})); + CHECK(!blockman.CheckBlockDataAvailability(tip, *first_available_block, BlockStatus{BLOCK_HAVE_DATA | BLOCK_HAVE_UNDO})); + CHECK(blockman.CheckBlockDataAvailability(tip, *first_available_block, BlockStatus{BLOCK_HAVE_DATA})); } -BOOST_FIXTURE_TEST_CASE(blockmanager_block_data_part, TestChain100Setup) +FIXTURE_TEST_CASE("blockmanager_block_data_part", TestChain100Setup) { LOCK(::cs_main); auto& chainman{m_node.chainman}; @@ -162,14 +163,14 @@ BOOST_FIXTURE_TEST_CASE(blockmanager_block_data_part, TestChain100Setup) const FlatFilePos tip_block_pos{tip.GetBlockPos()}; auto block{blockman.ReadRawBlock(tip_block_pos)}; - BOOST_REQUIRE(block); - BOOST_REQUIRE_GE(block->size(), 200); + REQUIRE(block); + REQUIRE(block->size() >= 200U); const auto expect_part{[&](size_t offset, size_t size) { auto res{blockman.ReadRawBlock(tip_block_pos, std::pair{offset, size})}; - BOOST_CHECK(res); + CHECK(res); const auto& part{res.value()}; - BOOST_CHECK_EQUAL_COLLECTIONS(part.begin(), part.end(), block->begin() + offset, block->begin() + offset + size); + CHECK_EQUAL_RANGES(part, std::span(block->begin() + offset, size)); }}; expect_part(0, 20); @@ -181,7 +182,7 @@ BOOST_FIXTURE_TEST_CASE(blockmanager_block_data_part, TestChain100Setup) expect_part(block->size() - 1, 1); } -BOOST_FIXTURE_TEST_CASE(blockmanager_block_data_part_error, TestChain100Setup) +FIXTURE_TEST_CASE("blockmanager_block_data_part_error", TestChain100Setup) { LOCK(::cs_main); auto& chainman{m_node.chainman}; @@ -190,13 +191,13 @@ BOOST_FIXTURE_TEST_CASE(blockmanager_block_data_part_error, TestChain100Setup) const FlatFilePos tip_block_pos{tip.GetBlockPos()}; auto block{blockman.ReadRawBlock(tip_block_pos)}; - BOOST_REQUIRE(block); - BOOST_REQUIRE_GE(block->size(), 200); + REQUIRE(block); + REQUIRE(block->size() >= 200U); const auto expect_part_error{[&](size_t offset, size_t size) { auto res{blockman.ReadRawBlock(tip_block_pos, std::pair{offset, size})}; - BOOST_CHECK(!res); - BOOST_CHECK_EQUAL(res.error(), node::ReadRawError::BadPartRange); + CHECK(!res); + CHECK(res.error() == node::ReadRawError::BadPartRange); }}; expect_part_error(0, 0); @@ -215,7 +216,7 @@ BOOST_FIXTURE_TEST_CASE(blockmanager_block_data_part_error, TestChain100Setup) expect_part_error(std::numeric_limits::max(), std::numeric_limits::max()); } -BOOST_FIXTURE_TEST_CASE(blockmanager_readblock_hash_mismatch, TestingSetup) +FIXTURE_TEST_CASE("blockmanager_readblock_hash_mismatch", TestingSetup) { CBlockIndex index; { @@ -228,10 +229,10 @@ BOOST_FIXTURE_TEST_CASE(blockmanager_readblock_hash_mismatch, TestingSetup) ASSERT_DEBUG_LOG("GetHash() doesn't match index"); CBlock block; - BOOST_CHECK(!m_node.chainman->m_blockman.ReadBlock(block, index)); + CHECK(!m_node.chainman->m_blockman.ReadBlock(block, index)); } -BOOST_AUTO_TEST_CASE(blockmanager_flush_block_file) +FIXTURE_TEST_CASE("blockmanager_flush_block_file", BasicTestingSetup) { KernelNotifications notifications{Assert(m_node.shutdown_request), m_node.exit_status, *Assert(m_node.warnings)}; node::BlockManager::Options blockman_opts{ @@ -257,7 +258,7 @@ BOOST_AUTO_TEST_CASE(blockmanager_flush_block_file) constexpr int TEST_BLOCK_SIZE{81}; // Blockstore is empty - BOOST_CHECK_EQUAL(blockman.CalculateCurrentUsage(), 0); + CHECK(blockman.CalculateCurrentUsage() == 0U); // Write the first block to a new location. FlatFilePos pos1{blockman.WriteBlock(block1, /*nHeight=*/1)}; @@ -266,21 +267,21 @@ BOOST_AUTO_TEST_CASE(blockmanager_flush_block_file) FlatFilePos pos2{blockman.WriteBlock(block2, /*nHeight=*/2)}; // Two blocks in the file - BOOST_CHECK_EQUAL(blockman.CalculateCurrentUsage(), (TEST_BLOCK_SIZE + STORAGE_HEADER_BYTES) * 2); + CHECK(blockman.CalculateCurrentUsage() == (TEST_BLOCK_SIZE + STORAGE_HEADER_BYTES) * 2); // First two blocks are written as expected // Errors are expected because block data is junk, thrown AFTER successful read CBlock read_block; - BOOST_CHECK_EQUAL(read_block.nVersion, 0); + CHECK(read_block.nVersion == 0); { ASSERT_DEBUG_LOG("Errors in block header"); - BOOST_CHECK(!blockman.ReadBlock(read_block, pos1, {})); - BOOST_CHECK_EQUAL(read_block.nVersion, 1); + CHECK(!blockman.ReadBlock(read_block, pos1, {})); + CHECK(read_block.nVersion == 1); } { ASSERT_DEBUG_LOG("Errors in block header"); - BOOST_CHECK(!blockman.ReadBlock(read_block, pos2, {})); - BOOST_CHECK_EQUAL(read_block.nVersion, 2); + CHECK(!blockman.ReadBlock(read_block, pos2, {})); + CHECK(read_block.nVersion == 2); } // During reindex, the flat file block storage will not be written to. @@ -288,19 +289,19 @@ BOOST_AUTO_TEST_CASE(blockmanager_flush_block_file) // Verify this behavior by attempting (and failing) to write block 3 data // to block 2 location. CBlockFileInfo* block_data = blockman.GetBlockFileInfo(0); - BOOST_CHECK_EQUAL(block_data->nBlocks, 2); + CHECK(block_data->nBlocks == 2U); blockman.UpdateBlockInfo(block3, /*nHeight=*/3, /*pos=*/pos2); // Metadata is updated... - BOOST_CHECK_EQUAL(block_data->nBlocks, 3); + CHECK(block_data->nBlocks == 3U); // ...but there are still only two blocks in the file - BOOST_CHECK_EQUAL(blockman.CalculateCurrentUsage(), (TEST_BLOCK_SIZE + STORAGE_HEADER_BYTES) * 2); + CHECK(blockman.CalculateCurrentUsage() == (TEST_BLOCK_SIZE + STORAGE_HEADER_BYTES) * 2); // Block 2 was not overwritten: - BOOST_CHECK(!blockman.ReadBlock(read_block, pos2, {})); - BOOST_CHECK_EQUAL(read_block.nVersion, 2); + CHECK(!blockman.ReadBlock(read_block, pos2, {})); + CHECK(read_block.nVersion == 2); } -BOOST_FIXTURE_TEST_CASE(prune_lock_update_and_delete, TestingSetup) +FIXTURE_TEST_CASE("prune_lock_update_and_delete", TestingSetup) { LOCK(::cs_main); auto& chainman{*Assert(m_node.chainman)}; @@ -313,13 +314,13 @@ BOOST_FIXTURE_TEST_CASE(prune_lock_update_and_delete, TestingSetup) blockman.UpdatePruneLock("test_lock", node::PruneLockInfo{.height_first = 200}); // Delete existing prune lock - BOOST_CHECK(blockman.DeletePruneLock("test_lock")); + CHECK(blockman.DeletePruneLock("test_lock")); // Verify deletion worked by trying to delete the same lock again - BOOST_CHECK(!blockman.DeletePruneLock("test_lock")); + CHECK(!blockman.DeletePruneLock("test_lock")); // Deleting a non-existent lock returns false - BOOST_CHECK(!blockman.DeletePruneLock("nonexistent")); + CHECK(!blockman.DeletePruneLock("nonexistent")); } -BOOST_AUTO_TEST_SUITE_END() +TEST_SUITE_END() diff --git a/src/test/bloom_tests.cpp b/src/test/bloom_tests.cpp index ed333c34c0d9..eb0cf7f7cf93 100644 --- a/src/test/bloom_tests.cpp +++ b/src/test/bloom_tests.cpp @@ -21,7 +21,7 @@ #include -#include +#include using namespace util::hex_literals; @@ -29,59 +29,58 @@ namespace bloom_tests { struct BloomTest : public BasicTestingSetup { std::vector RandomData(); }; -} // namespace bloom_tests -BOOST_FIXTURE_TEST_SUITE(bloom_tests, BloomTest) +TEST_SUITE_BEGIN("bloom_tests") -BOOST_AUTO_TEST_CASE(bloom_create_insert_serialize) +FIXTURE_TEST_CASE("bloom_create_insert_serialize", BloomTest) { CBloomFilter filter(3, 0.01, 0, BLOOM_UPDATE_ALL); - BOOST_CHECK_MESSAGE( !filter.contains("99108ad8ed9bb6274d3980bab5a85c048f0950c8"_hex_u8), "Bloom filter should be empty!"); + CHECK(!filter.contains("99108ad8ed9bb6274d3980bab5a85c048f0950c8"_hex_u8), "Bloom filter should be empty!"); filter.insert("99108ad8ed9bb6274d3980bab5a85c048f0950c8"_hex_u8); - BOOST_CHECK_MESSAGE( filter.contains("99108ad8ed9bb6274d3980bab5a85c048f0950c8"_hex_u8), "Bloom filter doesn't contain just-inserted object!"); + CHECK(filter.contains("99108ad8ed9bb6274d3980bab5a85c048f0950c8"_hex_u8), "Bloom filter doesn't contain just-inserted object!"); // One bit different in first byte - BOOST_CHECK_MESSAGE(!filter.contains("19108ad8ed9bb6274d3980bab5a85c048f0950c8"_hex_u8), "Bloom filter contains something it shouldn't!"); + CHECK(!filter.contains("19108ad8ed9bb6274d3980bab5a85c048f0950c8"_hex_u8), "Bloom filter contains something it shouldn't!"); filter.insert("b5a2c786d9ef4658287ced5914b37a1b4aa32eee"_hex_u8); - BOOST_CHECK_MESSAGE(filter.contains("b5a2c786d9ef4658287ced5914b37a1b4aa32eee"_hex_u8), "Bloom filter doesn't contain just-inserted object (2)!"); + CHECK(filter.contains("b5a2c786d9ef4658287ced5914b37a1b4aa32eee"_hex_u8), "Bloom filter doesn't contain just-inserted object (2)!"); filter.insert("b9300670b4c5366e95b2699e8b18bc75e5f729c5"_hex_u8); - BOOST_CHECK_MESSAGE(filter.contains("b9300670b4c5366e95b2699e8b18bc75e5f729c5"_hex_u8), "Bloom filter doesn't contain just-inserted object (3)!"); + CHECK(filter.contains("b9300670b4c5366e95b2699e8b18bc75e5f729c5"_hex_u8), "Bloom filter doesn't contain just-inserted object (3)!"); DataStream stream{}; stream << filter; constexpr auto expected{"03614e9b050000000000000001"_hex}; - BOOST_CHECK_EQUAL_COLLECTIONS(stream.begin(), stream.end(), expected.begin(), expected.end()); + CHECK_EQUAL_RANGES(stream, expected); - BOOST_CHECK_MESSAGE( filter.contains("99108ad8ed9bb6274d3980bab5a85c048f0950c8"_hex_u8), "Bloom filter doesn't contain just-inserted object!"); + CHECK(filter.contains("99108ad8ed9bb6274d3980bab5a85c048f0950c8"_hex_u8), "Bloom filter doesn't contain just-inserted object!"); } -BOOST_AUTO_TEST_CASE(bloom_create_insert_serialize_with_tweak) +FIXTURE_TEST_CASE("bloom_create_insert_serialize_with_tweak", BloomTest) { // Same test as bloom_create_insert_serialize, but we add a nTweak of 100 CBloomFilter filter(3, 0.01, 2147483649UL, BLOOM_UPDATE_ALL); filter.insert("99108ad8ed9bb6274d3980bab5a85c048f0950c8"_hex_u8); - BOOST_CHECK_MESSAGE( filter.contains("99108ad8ed9bb6274d3980bab5a85c048f0950c8"_hex_u8), "Bloom filter doesn't contain just-inserted object!"); + CHECK(filter.contains("99108ad8ed9bb6274d3980bab5a85c048f0950c8"_hex_u8), "Bloom filter doesn't contain just-inserted object!"); // One bit different in first byte - BOOST_CHECK_MESSAGE(!filter.contains("19108ad8ed9bb6274d3980bab5a85c048f0950c8"_hex_u8), "Bloom filter contains something it shouldn't!"); + CHECK(!filter.contains("19108ad8ed9bb6274d3980bab5a85c048f0950c8"_hex_u8), "Bloom filter contains something it shouldn't!"); filter.insert("b5a2c786d9ef4658287ced5914b37a1b4aa32eee"_hex_u8); - BOOST_CHECK_MESSAGE(filter.contains("b5a2c786d9ef4658287ced5914b37a1b4aa32eee"_hex_u8), "Bloom filter doesn't contain just-inserted object (2)!"); + CHECK(filter.contains("b5a2c786d9ef4658287ced5914b37a1b4aa32eee"_hex_u8), "Bloom filter doesn't contain just-inserted object (2)!"); filter.insert("b9300670b4c5366e95b2699e8b18bc75e5f729c5"_hex_u8); - BOOST_CHECK_MESSAGE(filter.contains("b9300670b4c5366e95b2699e8b18bc75e5f729c5"_hex_u8), "Bloom filter doesn't contain just-inserted object (3)!"); + CHECK(filter.contains("b9300670b4c5366e95b2699e8b18bc75e5f729c5"_hex_u8), "Bloom filter doesn't contain just-inserted object (3)!"); DataStream stream{}; stream << filter; constexpr auto expected{"03ce4299050000000100008001"_hex}; - BOOST_CHECK_EQUAL_COLLECTIONS(stream.begin(), stream.end(), expected.begin(), expected.end()); + CHECK_EQUAL_RANGES(stream, expected); } -BOOST_AUTO_TEST_CASE(bloom_create_insert_key) +FIXTURE_TEST_CASE("bloom_create_insert_key", BloomTest) { std::string strSecret = std::string("5Kg1gnAjaLfKiwhhPpGS3QfRg2m6awQvaj98JCZBZQ5SuS2F15C"); CKey key = DecodeSecret(strSecret); @@ -97,10 +96,10 @@ BOOST_AUTO_TEST_CASE(bloom_create_insert_key) stream << filter; constexpr auto expected{"038fc16b080000000000000001"_hex}; - BOOST_CHECK_EQUAL_COLLECTIONS(stream.begin(), stream.end(), expected.begin(), expected.end()); + CHECK_EQUAL_RANGES(stream, expected); } -BOOST_AUTO_TEST_CASE(bloom_match) +FIXTURE_TEST_CASE("bloom_match", BloomTest) { // Random real transaction (b4749f017444b051c44dfd2720e88f314ff94f3dd6d56d40ef65854fcd7fff6b) DataStream stream{ @@ -116,33 +115,33 @@ BOOST_AUTO_TEST_CASE(bloom_match) CBloomFilter filter(10, 0.000001, 0, BLOOM_UPDATE_ALL); filter.insert(uint256{"b4749f017444b051c44dfd2720e88f314ff94f3dd6d56d40ef65854fcd7fff6b"}); - BOOST_CHECK_MESSAGE(filter.IsRelevantAndUpdate(tx), "Simple Bloom filter didn't match tx hash"); + CHECK(filter.IsRelevantAndUpdate(tx), "Simple Bloom filter didn't match tx hash"); filter = CBloomFilter(10, 0.000001, 0, BLOOM_UPDATE_ALL); // byte-reversed tx hash filter.insert("6bff7fcd4f8565ef406dd5d63d4ff94f318fe82027fd4dc451b04474019f74b4"_hex_u8); - BOOST_CHECK_MESSAGE(filter.IsRelevantAndUpdate(tx), "Simple Bloom filter didn't match manually serialized tx hash"); + CHECK(filter.IsRelevantAndUpdate(tx), "Simple Bloom filter didn't match manually serialized tx hash"); filter = CBloomFilter(10, 0.000001, 0, BLOOM_UPDATE_ALL); filter.insert("30450220070aca44506c5cef3a16ed519d7c3c39f8aab192c4e1c90d065f37b8a4af6141022100a8e160b856c2d43d27d8fba71e5aef6405b8643ac4cb7cb3c462aced7f14711a01"_hex_u8); - BOOST_CHECK_MESSAGE(filter.IsRelevantAndUpdate(tx), "Simple Bloom filter didn't match input signature"); + CHECK(filter.IsRelevantAndUpdate(tx), "Simple Bloom filter didn't match input signature"); filter = CBloomFilter(10, 0.000001, 0, BLOOM_UPDATE_ALL); filter.insert("046d11fee51b0e60666d5049a9101a72741df480b96ee26488a4d3466b95c9a40ac5eeef87e10a5cd336c19a84565f80fa6c547957b7700ff4dfbdefe76036c339"_hex_u8); - BOOST_CHECK_MESSAGE(filter.IsRelevantAndUpdate(tx), "Simple Bloom filter didn't match input pub key"); + CHECK(filter.IsRelevantAndUpdate(tx), "Simple Bloom filter didn't match input pub key"); filter = CBloomFilter(10, 0.000001, 0, BLOOM_UPDATE_ALL); filter.insert("04943fdd508053c75000106d3bc6e2754dbcff19"_hex_u8); - BOOST_CHECK_MESSAGE(filter.IsRelevantAndUpdate(tx), "Simple Bloom filter didn't match output address"); - BOOST_CHECK_MESSAGE(filter.IsRelevantAndUpdate(spendingTx), "Simple Bloom filter didn't add output"); + CHECK(filter.IsRelevantAndUpdate(tx), "Simple Bloom filter didn't match output address"); + CHECK(filter.IsRelevantAndUpdate(spendingTx), "Simple Bloom filter didn't add output"); filter = CBloomFilter(10, 0.000001, 0, BLOOM_UPDATE_ALL); filter.insert("a266436d2965547608b9e15d9032a7b9d64fa431"_hex_u8); - BOOST_CHECK_MESSAGE(filter.IsRelevantAndUpdate(tx), "Simple Bloom filter didn't match output address"); + CHECK(filter.IsRelevantAndUpdate(tx), "Simple Bloom filter didn't match output address"); filter = CBloomFilter(10, 0.000001, 0, BLOOM_UPDATE_ALL); filter.insert(COutPoint{Txid{"90c122d70786e899529d71dbeba91ba216982fb6ba58f3bdaab65e73b7e9260b"}, 0}); - BOOST_CHECK_MESSAGE(filter.IsRelevantAndUpdate(tx), "Simple Bloom filter didn't match COutPoint"); + CHECK(filter.IsRelevantAndUpdate(tx), "Simple Bloom filter didn't match COutPoint"); filter = CBloomFilter(10, 0.000001, 0, BLOOM_UPDATE_ALL); COutPoint prevOutPoint{Txid{"90c122d70786e899529d71dbeba91ba216982fb6ba58f3bdaab65e73b7e9260b"}, 0}; @@ -152,26 +151,26 @@ BOOST_AUTO_TEST_CASE(bloom_match) memcpy(data.data()+32, &prevOutPoint.n, sizeof(unsigned int)); filter.insert(data); } - BOOST_CHECK_MESSAGE(filter.IsRelevantAndUpdate(tx), "Simple Bloom filter didn't match manually serialized COutPoint"); + CHECK(filter.IsRelevantAndUpdate(tx), "Simple Bloom filter didn't match manually serialized COutPoint"); filter = CBloomFilter(10, 0.000001, 0, BLOOM_UPDATE_ALL); filter.insert(uint256{"00000009e784f32f62ef849763d4f45b98e07ba658647343b915ff832b110436"}); - BOOST_CHECK_MESSAGE(!filter.IsRelevantAndUpdate(tx), "Simple Bloom filter matched random tx hash"); + CHECK(!filter.IsRelevantAndUpdate(tx), "Simple Bloom filter matched random tx hash"); filter = CBloomFilter(10, 0.000001, 0, BLOOM_UPDATE_ALL); filter.insert("0000006d2965547608b9e15d9032a7b9d64fa431"_hex_u8); - BOOST_CHECK_MESSAGE(!filter.IsRelevantAndUpdate(tx), "Simple Bloom filter matched random address"); + CHECK(!filter.IsRelevantAndUpdate(tx), "Simple Bloom filter matched random address"); filter = CBloomFilter(10, 0.000001, 0, BLOOM_UPDATE_ALL); filter.insert(COutPoint{Txid{"90c122d70786e899529d71dbeba91ba216982fb6ba58f3bdaab65e73b7e9260b"}, 1}); - BOOST_CHECK_MESSAGE(!filter.IsRelevantAndUpdate(tx), "Simple Bloom filter matched COutPoint for an output we didn't care about"); + CHECK(!filter.IsRelevantAndUpdate(tx), "Simple Bloom filter matched COutPoint for an output we didn't care about"); filter = CBloomFilter(10, 0.000001, 0, BLOOM_UPDATE_ALL); filter.insert(COutPoint{Txid{"000000d70786e899529d71dbeba91ba216982fb6ba58f3bdaab65e73b7e9260b"}, 0}); - BOOST_CHECK_MESSAGE(!filter.IsRelevantAndUpdate(tx), "Simple Bloom filter matched COutPoint for an output we didn't care about"); + CHECK(!filter.IsRelevantAndUpdate(tx), "Simple Bloom filter matched COutPoint for an output we didn't care about"); } -BOOST_AUTO_TEST_CASE(merkle_block_1) +FIXTURE_TEST_CASE("merkle_block_1", BloomTest) { CBlock block = getBlock13b8a(); CBloomFilter filter(10, 0.000001, 0, BLOOM_UPDATE_ALL); @@ -179,40 +178,40 @@ BOOST_AUTO_TEST_CASE(merkle_block_1) filter.insert(uint256{"74d681e0e03bafa802c8aa084379aa98d9fcd632ddc2ed9782b586ec87451f20"}); CMerkleBlock merkleBlock(block, filter); - BOOST_CHECK_EQUAL(merkleBlock.header.GetHash().GetHex(), block.GetHash().GetHex()); + CHECK(merkleBlock.header.GetHash().GetHex() == block.GetHash().GetHex()); - BOOST_CHECK_EQUAL(merkleBlock.vMatchedTxn.size(), 1U); + CHECK(merkleBlock.vMatchedTxn.size() == 1U); std::pair pair = merkleBlock.vMatchedTxn[0]; - BOOST_CHECK(merkleBlock.vMatchedTxn[0].second == Txid::FromUint256(uint256{"74d681e0e03bafa802c8aa084379aa98d9fcd632ddc2ed9782b586ec87451f20"})); - BOOST_CHECK(merkleBlock.vMatchedTxn[0].first == 8); + CHECK(merkleBlock.vMatchedTxn[0].second == Txid::FromUint256(uint256{"74d681e0e03bafa802c8aa084379aa98d9fcd632ddc2ed9782b586ec87451f20"})); + CHECK(merkleBlock.vMatchedTxn[0].first == 8U); std::vector vMatched; std::vector vIndex; - BOOST_CHECK(merkleBlock.txn.ExtractMatches(vMatched, vIndex) == block.hashMerkleRoot); - BOOST_CHECK(vMatched.size() == merkleBlock.vMatchedTxn.size()); + CHECK(merkleBlock.txn.ExtractMatches(vMatched, vIndex) == block.hashMerkleRoot); + CHECK(vMatched.size() == merkleBlock.vMatchedTxn.size()); for (unsigned int i = 0; i < vMatched.size(); i++) - BOOST_CHECK(vMatched[i] == merkleBlock.vMatchedTxn[i].second); + CHECK(vMatched[i] == merkleBlock.vMatchedTxn[i].second); // Also match the 8th transaction filter.insert(uint256{"dd1fd2a6fc16404faf339881a90adbde7f4f728691ac62e8f168809cdfae1053"}); merkleBlock = CMerkleBlock(block, filter); - BOOST_CHECK(merkleBlock.header.GetHash() == block.GetHash()); + CHECK(merkleBlock.header.GetHash() == block.GetHash()); - BOOST_CHECK(merkleBlock.vMatchedTxn.size() == 2); + CHECK(merkleBlock.vMatchedTxn.size() == 2U); - BOOST_CHECK(merkleBlock.vMatchedTxn[1] == pair); + CHECK(merkleBlock.vMatchedTxn[1] == pair); - BOOST_CHECK(merkleBlock.vMatchedTxn[0].second == Txid::FromUint256(uint256{"dd1fd2a6fc16404faf339881a90adbde7f4f728691ac62e8f168809cdfae1053"})); - BOOST_CHECK(merkleBlock.vMatchedTxn[0].first == 7); + CHECK(merkleBlock.vMatchedTxn[0].second == Txid::FromUint256(uint256{"dd1fd2a6fc16404faf339881a90adbde7f4f728691ac62e8f168809cdfae1053"})); + CHECK(merkleBlock.vMatchedTxn[0].first == 7U); - BOOST_CHECK(merkleBlock.txn.ExtractMatches(vMatched, vIndex) == block.hashMerkleRoot); - BOOST_CHECK(vMatched.size() == merkleBlock.vMatchedTxn.size()); + CHECK(merkleBlock.txn.ExtractMatches(vMatched, vIndex) == block.hashMerkleRoot); + CHECK(vMatched.size() == merkleBlock.vMatchedTxn.size()); for (unsigned int i = 0; i < vMatched.size(); i++) - BOOST_CHECK(vMatched[i] == merkleBlock.vMatchedTxn[i].second); + CHECK(vMatched[i] == merkleBlock.vMatchedTxn[i].second); } -BOOST_AUTO_TEST_CASE(merkle_block_2) +FIXTURE_TEST_CASE("merkle_block_2", BloomTest) { // Random real block (000000005a4ded781e667e06ceefafb71410b511fe0d5adc3e5a27ecbec34ae6) // With 4 txes @@ -227,20 +226,20 @@ BOOST_AUTO_TEST_CASE(merkle_block_2) filter.insert(uint256{"e980fe9f792d014e73b95203dc1335c5f9ce19ac537a419e6df5b47aecb93b70"}); CMerkleBlock merkleBlock(block, filter); - BOOST_CHECK(merkleBlock.header.GetHash() == block.GetHash()); + CHECK(merkleBlock.header.GetHash() == block.GetHash()); - BOOST_CHECK(merkleBlock.vMatchedTxn.size() == 1); + CHECK(merkleBlock.vMatchedTxn.size() == 1U); std::pair pair = merkleBlock.vMatchedTxn[0]; - BOOST_CHECK(merkleBlock.vMatchedTxn[0].second == Txid::FromUint256(uint256{"e980fe9f792d014e73b95203dc1335c5f9ce19ac537a419e6df5b47aecb93b70"})); - BOOST_CHECK(merkleBlock.vMatchedTxn[0].first == 0); + CHECK(merkleBlock.vMatchedTxn[0].second == Txid::FromUint256(uint256{"e980fe9f792d014e73b95203dc1335c5f9ce19ac537a419e6df5b47aecb93b70"})); + CHECK(merkleBlock.vMatchedTxn[0].first == 0U); std::vector vMatched; std::vector vIndex; - BOOST_CHECK(merkleBlock.txn.ExtractMatches(vMatched, vIndex) == block.hashMerkleRoot); - BOOST_CHECK(vMatched.size() == merkleBlock.vMatchedTxn.size()); + CHECK(merkleBlock.txn.ExtractMatches(vMatched, vIndex) == block.hashMerkleRoot); + CHECK(vMatched.size() == merkleBlock.vMatchedTxn.size()); for (unsigned int i = 0; i < vMatched.size(); i++) - BOOST_CHECK(vMatched[i] == merkleBlock.vMatchedTxn[i].second); + CHECK(vMatched[i] == merkleBlock.vMatchedTxn[i].second); // Match an output from the second transaction (the pubkey for address 1DZTzaBHUDM7T3QvUKBz4qXMRpkg8jsfB5) // This should match the third transaction because it spends the output matched @@ -248,28 +247,28 @@ BOOST_AUTO_TEST_CASE(merkle_block_2) filter.insert("044a656f065871a353f216ca26cef8dde2f03e8c16202d2e8ad769f02032cb86a5eb5e56842e92e19141d60a01928f8dd2c875a390f67c1f6c94cfc617c0ea45af"_hex_u8); merkleBlock = CMerkleBlock(block, filter); - BOOST_CHECK(merkleBlock.header.GetHash() == block.GetHash()); + CHECK(merkleBlock.header.GetHash() == block.GetHash()); - BOOST_CHECK(merkleBlock.vMatchedTxn.size() == 4); + CHECK(merkleBlock.vMatchedTxn.size() == 4U); - BOOST_CHECK(pair == merkleBlock.vMatchedTxn[0]); + CHECK(pair == merkleBlock.vMatchedTxn[0]); - BOOST_CHECK(merkleBlock.vMatchedTxn[1].second == Txid::FromUint256(uint256{"28204cad1d7fc1d199e8ef4fa22f182de6258a3eaafe1bbe56ebdcacd3069a5f"})); - BOOST_CHECK(merkleBlock.vMatchedTxn[1].first == 1); + CHECK(merkleBlock.vMatchedTxn[1].second == Txid::FromUint256(uint256{"28204cad1d7fc1d199e8ef4fa22f182de6258a3eaafe1bbe56ebdcacd3069a5f"})); + CHECK(merkleBlock.vMatchedTxn[1].first == 1U); - BOOST_CHECK(merkleBlock.vMatchedTxn[2].second == Txid::FromUint256(uint256{"6b0f8a73a56c04b519f1883e8aafda643ba61a30bd1439969df21bea5f4e27e2"})); - BOOST_CHECK(merkleBlock.vMatchedTxn[2].first == 2); + CHECK(merkleBlock.vMatchedTxn[2].second == Txid::FromUint256(uint256{"6b0f8a73a56c04b519f1883e8aafda643ba61a30bd1439969df21bea5f4e27e2"})); + CHECK(merkleBlock.vMatchedTxn[2].first == 2U); - BOOST_CHECK(merkleBlock.vMatchedTxn[3].second == Txid::FromUint256(uint256{"3c1d7e82342158e4109df2e0b6348b6e84e403d8b4046d7007663ace63cddb23"})); - BOOST_CHECK(merkleBlock.vMatchedTxn[3].first == 3); + CHECK(merkleBlock.vMatchedTxn[3].second == Txid::FromUint256(uint256{"3c1d7e82342158e4109df2e0b6348b6e84e403d8b4046d7007663ace63cddb23"})); + CHECK(merkleBlock.vMatchedTxn[3].first == 3U); - BOOST_CHECK(merkleBlock.txn.ExtractMatches(vMatched, vIndex) == block.hashMerkleRoot); - BOOST_CHECK(vMatched.size() == merkleBlock.vMatchedTxn.size()); + CHECK(merkleBlock.txn.ExtractMatches(vMatched, vIndex) == block.hashMerkleRoot); + CHECK(vMatched.size() == merkleBlock.vMatchedTxn.size()); for (unsigned int i = 0; i < vMatched.size(); i++) - BOOST_CHECK(vMatched[i] == merkleBlock.vMatchedTxn[i].second); + CHECK(vMatched[i] == merkleBlock.vMatchedTxn[i].second); } -BOOST_AUTO_TEST_CASE(merkle_block_2_with_update_none) +FIXTURE_TEST_CASE("merkle_block_2_with_update_none", BloomTest) { // Random real block (000000005a4ded781e667e06ceefafb71410b511fe0d5adc3e5a27ecbec34ae6) // With 4 txes @@ -284,20 +283,20 @@ BOOST_AUTO_TEST_CASE(merkle_block_2_with_update_none) filter.insert(uint256{"e980fe9f792d014e73b95203dc1335c5f9ce19ac537a419e6df5b47aecb93b70"}); CMerkleBlock merkleBlock(block, filter); - BOOST_CHECK(merkleBlock.header.GetHash() == block.GetHash()); + CHECK(merkleBlock.header.GetHash() == block.GetHash()); - BOOST_CHECK(merkleBlock.vMatchedTxn.size() == 1); + CHECK(merkleBlock.vMatchedTxn.size() == 1U); std::pair pair = merkleBlock.vMatchedTxn[0]; - BOOST_CHECK(merkleBlock.vMatchedTxn[0].second == Txid::FromUint256(uint256{"e980fe9f792d014e73b95203dc1335c5f9ce19ac537a419e6df5b47aecb93b70"})); - BOOST_CHECK(merkleBlock.vMatchedTxn[0].first == 0); + CHECK(merkleBlock.vMatchedTxn[0].second == Txid::FromUint256(uint256{"e980fe9f792d014e73b95203dc1335c5f9ce19ac537a419e6df5b47aecb93b70"})); + CHECK(merkleBlock.vMatchedTxn[0].first == 0U); std::vector vMatched; std::vector vIndex; - BOOST_CHECK(merkleBlock.txn.ExtractMatches(vMatched, vIndex) == block.hashMerkleRoot); - BOOST_CHECK(vMatched.size() == merkleBlock.vMatchedTxn.size()); + CHECK(merkleBlock.txn.ExtractMatches(vMatched, vIndex) == block.hashMerkleRoot); + CHECK(vMatched.size() == merkleBlock.vMatchedTxn.size()); for (unsigned int i = 0; i < vMatched.size(); i++) - BOOST_CHECK(vMatched[i] == merkleBlock.vMatchedTxn[i].second); + CHECK(vMatched[i] == merkleBlock.vMatchedTxn[i].second); // Match an output from the second transaction (the pubkey for address 1DZTzaBHUDM7T3QvUKBz4qXMRpkg8jsfB5) // This should not match the third transaction though it spends the output matched @@ -305,25 +304,25 @@ BOOST_AUTO_TEST_CASE(merkle_block_2_with_update_none) filter.insert("044a656f065871a353f216ca26cef8dde2f03e8c16202d2e8ad769f02032cb86a5eb5e56842e92e19141d60a01928f8dd2c875a390f67c1f6c94cfc617c0ea45af"_hex_u8); merkleBlock = CMerkleBlock(block, filter); - BOOST_CHECK(merkleBlock.header.GetHash() == block.GetHash()); + CHECK(merkleBlock.header.GetHash() == block.GetHash()); - BOOST_CHECK(merkleBlock.vMatchedTxn.size() == 3); + CHECK(merkleBlock.vMatchedTxn.size() == 3U); - BOOST_CHECK(pair == merkleBlock.vMatchedTxn[0]); + CHECK(pair == merkleBlock.vMatchedTxn[0]); - BOOST_CHECK(merkleBlock.vMatchedTxn[1].second == Txid::FromUint256(uint256{"28204cad1d7fc1d199e8ef4fa22f182de6258a3eaafe1bbe56ebdcacd3069a5f"})); - BOOST_CHECK(merkleBlock.vMatchedTxn[1].first == 1); + CHECK(merkleBlock.vMatchedTxn[1].second == Txid::FromUint256(uint256{"28204cad1d7fc1d199e8ef4fa22f182de6258a3eaafe1bbe56ebdcacd3069a5f"})); + CHECK(merkleBlock.vMatchedTxn[1].first == 1U); - BOOST_CHECK(merkleBlock.vMatchedTxn[2].second == Txid::FromUint256(uint256{"3c1d7e82342158e4109df2e0b6348b6e84e403d8b4046d7007663ace63cddb23"})); - BOOST_CHECK(merkleBlock.vMatchedTxn[2].first == 3); + CHECK(merkleBlock.vMatchedTxn[2].second == Txid::FromUint256(uint256{"3c1d7e82342158e4109df2e0b6348b6e84e403d8b4046d7007663ace63cddb23"})); + CHECK(merkleBlock.vMatchedTxn[2].first == 3U); - BOOST_CHECK(merkleBlock.txn.ExtractMatches(vMatched, vIndex) == block.hashMerkleRoot); - BOOST_CHECK(vMatched.size() == merkleBlock.vMatchedTxn.size()); + CHECK(merkleBlock.txn.ExtractMatches(vMatched, vIndex) == block.hashMerkleRoot); + CHECK(vMatched.size() == merkleBlock.vMatchedTxn.size()); for (unsigned int i = 0; i < vMatched.size(); i++) - BOOST_CHECK(vMatched[i] == merkleBlock.vMatchedTxn[i].second); + CHECK(vMatched[i] == merkleBlock.vMatchedTxn[i].second); } -BOOST_AUTO_TEST_CASE(merkle_block_3_and_serialize) +FIXTURE_TEST_CASE("merkle_block_3_and_serialize", BloomTest) { // Random real block (000000000000dab0130bbcc991d3d7ae6b81aa6f50a798888dfe62337458dc45) // With one tx @@ -338,28 +337,28 @@ BOOST_AUTO_TEST_CASE(merkle_block_3_and_serialize) filter.insert(uint256{"63194f18be0af63f2c6bc9dc0f777cbefed3d9415c4af83f3ee3a3d669c00cb5"}); CMerkleBlock merkleBlock(block, filter); - BOOST_CHECK(merkleBlock.header.GetHash() == block.GetHash()); + CHECK(merkleBlock.header.GetHash() == block.GetHash()); - BOOST_CHECK(merkleBlock.vMatchedTxn.size() == 1); + CHECK(merkleBlock.vMatchedTxn.size() == 1U); - BOOST_CHECK(merkleBlock.vMatchedTxn[0].second == Txid::FromUint256(uint256{"63194f18be0af63f2c6bc9dc0f777cbefed3d9415c4af83f3ee3a3d669c00cb5"})); - BOOST_CHECK(merkleBlock.vMatchedTxn[0].first == 0); + CHECK(merkleBlock.vMatchedTxn[0].second == Txid::FromUint256(uint256{"63194f18be0af63f2c6bc9dc0f777cbefed3d9415c4af83f3ee3a3d669c00cb5"})); + CHECK(merkleBlock.vMatchedTxn[0].first == 0U); std::vector vMatched; std::vector vIndex; - BOOST_CHECK(merkleBlock.txn.ExtractMatches(vMatched, vIndex) == block.hashMerkleRoot); - BOOST_CHECK(vMatched.size() == merkleBlock.vMatchedTxn.size()); + CHECK(merkleBlock.txn.ExtractMatches(vMatched, vIndex) == block.hashMerkleRoot); + CHECK(vMatched.size() == merkleBlock.vMatchedTxn.size()); for (unsigned int i = 0; i < vMatched.size(); i++) - BOOST_CHECK(vMatched[i] == merkleBlock.vMatchedTxn[i].second); + CHECK(vMatched[i] == merkleBlock.vMatchedTxn[i].second); DataStream merkleStream{}; merkleStream << merkleBlock; constexpr auto expected{"0100000079cda856b143d9db2c1caff01d1aecc8630d30625d10e8b4b8b0000000000000b50cc069d6a3e33e3ff84a5c41d9d3febe7c770fdcc96b2c3ff60abe184f196367291b4d4c86041b8fa45d630100000001b50cc069d6a3e33e3ff84a5c41d9d3febe7c770fdcc96b2c3ff60abe184f19630101"_hex}; - BOOST_CHECK_EQUAL_COLLECTIONS(merkleStream.begin(), merkleStream.end(), expected.begin(), expected.end()); + CHECK_EQUAL_RANGES(merkleStream, expected); } -BOOST_AUTO_TEST_CASE(merkle_block_4) +FIXTURE_TEST_CASE("merkle_block_4", BloomTest) { // Random real block (000000000000b731f2eef9e8c63173adfb07e41bd53eb0ef0a6b720d6cb6dea4) // With 7 txes @@ -374,40 +373,40 @@ BOOST_AUTO_TEST_CASE(merkle_block_4) filter.insert(uint256{"0a2a92f0bda4727d0a13eaddf4dd9ac6b5c61a1429e6b2b818f19b15df0ac154"}); CMerkleBlock merkleBlock(block, filter); - BOOST_CHECK(merkleBlock.header.GetHash() == block.GetHash()); + CHECK(merkleBlock.header.GetHash() == block.GetHash()); - BOOST_CHECK(merkleBlock.vMatchedTxn.size() == 1); + CHECK(merkleBlock.vMatchedTxn.size() == 1U); std::pair pair = merkleBlock.vMatchedTxn[0]; - BOOST_CHECK(merkleBlock.vMatchedTxn[0].second == Txid::FromUint256(uint256{"0a2a92f0bda4727d0a13eaddf4dd9ac6b5c61a1429e6b2b818f19b15df0ac154"})); - BOOST_CHECK(merkleBlock.vMatchedTxn[0].first == 6); + CHECK(merkleBlock.vMatchedTxn[0].second == Txid::FromUint256(uint256{"0a2a92f0bda4727d0a13eaddf4dd9ac6b5c61a1429e6b2b818f19b15df0ac154"})); + CHECK(merkleBlock.vMatchedTxn[0].first == 6U); std::vector vMatched; std::vector vIndex; - BOOST_CHECK(merkleBlock.txn.ExtractMatches(vMatched, vIndex) == block.hashMerkleRoot); - BOOST_CHECK(vMatched.size() == merkleBlock.vMatchedTxn.size()); + CHECK(merkleBlock.txn.ExtractMatches(vMatched, vIndex) == block.hashMerkleRoot); + CHECK(vMatched.size() == merkleBlock.vMatchedTxn.size()); for (unsigned int i = 0; i < vMatched.size(); i++) - BOOST_CHECK(vMatched[i] == merkleBlock.vMatchedTxn[i].second); + CHECK(vMatched[i] == merkleBlock.vMatchedTxn[i].second); // Also match the 4th transaction filter.insert(uint256{"02981fa052f0481dbc5868f4fc2166035a10f27a03cfd2de67326471df5bc041"}); merkleBlock = CMerkleBlock(block, filter); - BOOST_CHECK(merkleBlock.header.GetHash() == block.GetHash()); + CHECK(merkleBlock.header.GetHash() == block.GetHash()); - BOOST_CHECK(merkleBlock.vMatchedTxn.size() == 2); + CHECK(merkleBlock.vMatchedTxn.size() == 2U); - BOOST_CHECK(merkleBlock.vMatchedTxn[0].second == Txid::FromUint256(uint256{"02981fa052f0481dbc5868f4fc2166035a10f27a03cfd2de67326471df5bc041"})); - BOOST_CHECK(merkleBlock.vMatchedTxn[0].first == 3); + CHECK(merkleBlock.vMatchedTxn[0].second == Txid::FromUint256(uint256{"02981fa052f0481dbc5868f4fc2166035a10f27a03cfd2de67326471df5bc041"})); + CHECK(merkleBlock.vMatchedTxn[0].first == 3); - BOOST_CHECK(merkleBlock.vMatchedTxn[1] == pair); + CHECK(merkleBlock.vMatchedTxn[1] == pair); - BOOST_CHECK(merkleBlock.txn.ExtractMatches(vMatched, vIndex) == block.hashMerkleRoot); - BOOST_CHECK(vMatched.size() == merkleBlock.vMatchedTxn.size()); + CHECK(merkleBlock.txn.ExtractMatches(vMatched, vIndex) == block.hashMerkleRoot); + CHECK(vMatched.size() == merkleBlock.vMatchedTxn.size()); for (unsigned int i = 0; i < vMatched.size(); i++) - BOOST_CHECK(vMatched[i] == merkleBlock.vMatchedTxn[i].second); + CHECK(vMatched[i] == merkleBlock.vMatchedTxn[i].second); } -BOOST_AUTO_TEST_CASE(merkle_block_4_test_p2pubkey_only) +FIXTURE_TEST_CASE("merkle_block_4_test_p2pubkey_only", BloomTest) { // Random real block (000000000000b731f2eef9e8c63173adfb07e41bd53eb0ef0a6b720d6cb6dea4) // With 7 txes @@ -424,15 +423,15 @@ BOOST_AUTO_TEST_CASE(merkle_block_4_test_p2pubkey_only) filter.insert("b6efd80d99179f4f4ff6f4dd0a007d018c385d21"_hex_u8); CMerkleBlock merkleBlock(block, filter); - BOOST_CHECK(merkleBlock.header.GetHash() == block.GetHash()); + CHECK(merkleBlock.header.GetHash() == block.GetHash()); // We should match the generation outpoint - BOOST_CHECK(filter.contains(COutPoint{Txid{"147caa76786596590baa4e98f5d9f48b86c7765e489f7a6ff3360fe5c674360b"}, 0})); + CHECK(filter.contains(COutPoint{Txid{"147caa76786596590baa4e98f5d9f48b86c7765e489f7a6ff3360fe5c674360b"}, 0})); // ... but not the 4th transaction's output (its not pay-2-pubkey) - BOOST_CHECK(!filter.contains(COutPoint{Txid{"02981fa052f0481dbc5868f4fc2166035a10f27a03cfd2de67326471df5bc041"}, 0})); + CHECK(!filter.contains(COutPoint{Txid{"02981fa052f0481dbc5868f4fc2166035a10f27a03cfd2de67326471df5bc041"}, 0})); } -BOOST_AUTO_TEST_CASE(merkle_block_4_test_update_none) +FIXTURE_TEST_CASE("merkle_block_4_test_update_none", BloomTest) { // Random real block (000000000000b731f2eef9e8c63173adfb07e41bd53eb0ef0a6b720d6cb6dea4) // With 7 txes @@ -449,11 +448,11 @@ BOOST_AUTO_TEST_CASE(merkle_block_4_test_update_none) filter.insert("b6efd80d99179f4f4ff6f4dd0a007d018c385d21"_hex_u8); CMerkleBlock merkleBlock(block, filter); - BOOST_CHECK(merkleBlock.header.GetHash() == block.GetHash()); + CHECK(merkleBlock.header.GetHash() == block.GetHash()); // We shouldn't match any outpoints (UPDATE_NONE) - BOOST_CHECK(!filter.contains(COutPoint{Txid{"147caa76786596590baa4e98f5d9f48b86c7765e489f7a6ff3360fe5c674360b"}, 0})); - BOOST_CHECK(!filter.contains(COutPoint{Txid{"02981fa052f0481dbc5868f4fc2166035a10f27a03cfd2de67326471df5bc041"}, 0})); + CHECK(!filter.contains(COutPoint{Txid{"147caa76786596590baa4e98f5d9f48b86c7765e489f7a6ff3360fe5c674360b"}, 0})); + CHECK(!filter.contains(COutPoint{Txid{"02981fa052f0481dbc5868f4fc2166035a10f27a03cfd2de67326471df5bc041"}, 0})); } std::vector BloomTest::RandomData() @@ -462,7 +461,7 @@ std::vector BloomTest::RandomData() return std::vector(r.begin(), r.end()); } -BOOST_AUTO_TEST_CASE(rolling_bloom) +FIXTURE_TEST_CASE("rolling_bloom", BloomTest) { SeedRandomForTest(SeedRand::ZEROS); @@ -478,7 +477,7 @@ BOOST_AUTO_TEST_CASE(rolling_bloom) } // Last 100 guaranteed to be remembered: for (int i = 299; i < DATASIZE; i++) { - BOOST_CHECK(rb1.contains(data[i])); + CHECK(rb1.contains(data[i])); } // false positive rate is 1%, so we should get about 100 hits if @@ -491,26 +490,26 @@ BOOST_AUTO_TEST_CASE(rolling_bloom) ++nHits; } // Expect about 100 hits - BOOST_CHECK_EQUAL(nHits, 71U); + CHECK(nHits == 71U); - BOOST_CHECK(rb1.contains(data[DATASIZE-1])); + CHECK(rb1.contains(data[DATASIZE-1])); rb1.reset(); - BOOST_CHECK(!rb1.contains(data[DATASIZE-1])); + CHECK(!rb1.contains(data[DATASIZE-1])); // Now roll through data, make sure last 100 entries // are always remembered: for (int i = 0; i < DATASIZE; i++) { if (i >= 100) - BOOST_CHECK(rb1.contains(data[i-100])); + CHECK(rb1.contains(data[i-100])); rb1.insert(data[i]); - BOOST_CHECK(rb1.contains(data[i])); + CHECK(rb1.contains(data[i])); } // Insert 999 more random entries: for (int i = 0; i < 999; i++) { std::vector d = RandomData(); rb1.insert(d); - BOOST_CHECK(rb1.contains(d)); + CHECK(rb1.contains(d)); } // Sanity check to make sure the filter isn't just filling up: nHits = 0; @@ -519,7 +518,7 @@ BOOST_AUTO_TEST_CASE(rolling_bloom) ++nHits; } // Expect about 5 false positives - BOOST_CHECK_EQUAL(nHits, 3U); + CHECK(nHits == 3U); // last-1000-entry, 0.01% false positive: CRollingBloomFilter rb2(1000, 0.001); @@ -528,8 +527,9 @@ BOOST_AUTO_TEST_CASE(rolling_bloom) } // ... room for all of them: for (int i = 0; i < DATASIZE; i++) { - BOOST_CHECK(rb2.contains(data[i])); + CHECK(rb2.contains(data[i])); } } -BOOST_AUTO_TEST_SUITE_END() +TEST_SUITE_END() +} // namespace bloom_tests diff --git a/src/test/bswap_tests.cpp b/src/test/bswap_tests.cpp index a2df1ea87c8a..a7e2a315d72e 100644 --- a/src/test/bswap_tests.cpp +++ b/src/test/bswap_tests.cpp @@ -4,11 +4,11 @@ #include -#include +#include -BOOST_AUTO_TEST_SUITE(bswap_tests) +TEST_SUITE_BEGIN("bswap_tests") -BOOST_AUTO_TEST_CASE(bswap_tests) +TEST_CASE("bswap_tests") { uint16_t u1 = 0x1234; uint32_t u2 = 0x56789abc; @@ -16,9 +16,9 @@ BOOST_AUTO_TEST_CASE(bswap_tests) uint16_t e1 = 0x3412; uint32_t e2 = 0xbc9a7856; uint64_t e3 = 0xbc9a78563412f0de; - BOOST_CHECK(internal_bswap_16(u1) == e1); - BOOST_CHECK(internal_bswap_32(u2) == e2); - BOOST_CHECK(internal_bswap_64(u3) == e3); + CHECK(internal_bswap_16(u1) == e1); + CHECK(internal_bswap_32(u2) == e2); + CHECK(internal_bswap_64(u3) == e3); } -BOOST_AUTO_TEST_SUITE_END() +TEST_SUITE_END() diff --git a/src/test/btcsignals_tests.cpp b/src/test/btcsignals_tests.cpp index b3203ebeb231..348c93596f84 100644 --- a/src/test/btcsignals_tests.cpp +++ b/src/test/btcsignals_tests.cpp @@ -5,7 +5,7 @@ #include #include -#include +#include #include @@ -48,93 +48,93 @@ bool ReturnFalse() } // anonymous namespace -BOOST_FIXTURE_TEST_SUITE(btcsignals_tests, BasicTestingSetup) +TEST_SUITE_BEGIN("btcsignals_tests") /* Callbacks should always be executed in the order in which they were added */ -BOOST_AUTO_TEST_CASE(callback_order) +FIXTURE_TEST_CASE("callback_order", BasicTestingSetup) { btcsignals::signal sig0; sig0.connect(IncrementCallback); sig0.connect(SquareCallback); int val{3}; sig0(val); - BOOST_CHECK_EQUAL(val, 16); - BOOST_CHECK(!sig0.empty()); + CHECK(val == 16); + CHECK(!sig0.empty()); } -BOOST_AUTO_TEST_CASE(disconnects) +FIXTURE_TEST_CASE("disconnects", BasicTestingSetup) { btcsignals::signal sig0; auto conn0 = sig0.connect(IncrementCallback); auto conn1 = sig0.connect(SquareCallback); conn1.disconnect(); - BOOST_CHECK(!sig0.empty()); + CHECK(!sig0.empty()); int val{3}; sig0(val); - BOOST_CHECK_EQUAL(val, 4); + CHECK(val == 4); - BOOST_CHECK(!sig0.empty()); + CHECK(!sig0.empty()); conn0.disconnect(); - BOOST_CHECK(sig0.empty()); + CHECK(sig0.empty()); sig0(val); - BOOST_CHECK_EQUAL(val, 4); + CHECK(val == 4); conn0 = sig0.connect(IncrementCallback); conn1 = sig0.connect(IncrementCallback); - BOOST_CHECK(!sig0.empty()); + CHECK(!sig0.empty()); sig0(val); - BOOST_CHECK_EQUAL(val, 6); + CHECK(val == 6); conn1.disconnect(); - BOOST_CHECK(conn0.connected()); + CHECK(conn0.connected()); { btcsignals::scoped_connection scope(conn0); } - BOOST_CHECK(!conn0.connected()); - BOOST_CHECK(sig0.empty()); + CHECK(!conn0.connected()); + CHECK(sig0.empty()); sig0(val); - BOOST_CHECK_EQUAL(val, 6); + CHECK(val == 6); } /* Check that move-only return types work correctly */ -BOOST_AUTO_TEST_CASE(moveonly_return) +FIXTURE_TEST_CASE("moveonly_return", BasicTestingSetup) { btcsignals::signal sig0; sig0.connect(MoveOnlyReturnCallback); int data{3}; auto ret = sig0(data); - BOOST_CHECK_EQUAL(ret->m_data, 3); + CHECK(ret->m_data == 3); } /* The result of the signal invocation should always be the result of the last * enabled callback. */ -BOOST_AUTO_TEST_CASE(return_value) +FIXTURE_TEST_CASE("return_value", BasicTestingSetup) { btcsignals::signal sig0; decltype(sig0)::result_type ret; ret = sig0(); - BOOST_CHECK(!ret); + CHECK(!ret); { btcsignals::scoped_connection conn0 = sig0.connect(ReturnTrue); ret = sig0(); - BOOST_CHECK(ret && *ret == true); + CHECK((ret && *ret == true)); } ret = sig0(); - BOOST_CHECK(!ret); + CHECK(!ret); { btcsignals::scoped_connection conn1 = sig0.connect(ReturnTrue); btcsignals::scoped_connection conn0 = sig0.connect(ReturnFalse); ret = sig0(); - BOOST_CHECK(ret && *ret == false); + CHECK((ret && *ret == false)); conn0.disconnect(); ret = sig0(); - BOOST_CHECK(ret && *ret == true); + CHECK((ret && *ret == true)); } ret = sig0(); - BOOST_CHECK(!ret); + CHECK(!ret); } /* Test the thread-safety of connect/disconnect/empty/connected/callbacks. @@ -145,7 +145,7 @@ BOOST_AUTO_TEST_CASE(return_value) * total callbacks executed, this should all be completely threadsafe. * Sanitizers should pick up any buggy data race behavior (if present). */ -BOOST_AUTO_TEST_CASE(thread_safety) +FIXTURE_TEST_CASE("thread_safety", BasicTestingSetup) { btcsignals::signal sig0; std::atomic val{0}; @@ -169,8 +169,8 @@ BOOST_AUTO_TEST_CASE(thread_safety) std::vector extra_conns; extra_conns.reserve(num_extra_conns); for (size_t i = 0; i < num_extra_conns; i++) { - BOOST_CHECK(!sig0.empty()); - BOOST_CHECK(conn0.connected()); + CHECK(!sig0.empty()); + CHECK(conn0.connected()); extra_conns.emplace_back(sig0.connect([&val] { val++; })); @@ -180,18 +180,18 @@ BOOST_AUTO_TEST_CASE(thread_safety) incrementor.join(); extra_increment_injector.join(); conn0.disconnect(); - BOOST_CHECK(sig0.empty()); + CHECK(sig0.empty()); // sig will have been called 2000 times, and at least 1000 of those will // have been executing multiple incrementing callbacks. So while val is // probably MUCH bigger, it's guaranteed to be at least 3000. - BOOST_CHECK_GE(val.load(), 3000); + CHECK(val.load() >= 3000U); } /* Test that connection and disconnection works from within signal * callbacks. */ -BOOST_AUTO_TEST_CASE(recursion_safety) +FIXTURE_TEST_CASE("recursion_safety", BasicTestingSetup) { btcsignals::connection conn0, conn1, conn2; btcsignals::signal sig0; @@ -199,31 +199,31 @@ BOOST_AUTO_TEST_CASE(recursion_safety) bool recursive_callback_ran{false}; conn0 = sig0.connect([&] { - BOOST_CHECK(!sig0.empty()); + CHECK(!sig0.empty()); nonrecursive_callback_ran = true; }); - BOOST_CHECK(!nonrecursive_callback_ran); + CHECK(!nonrecursive_callback_ran); sig0(); - BOOST_CHECK(nonrecursive_callback_ran); - BOOST_CHECK(conn0.connected()); + CHECK(nonrecursive_callback_ran); + CHECK(conn0.connected()); nonrecursive_callback_ran = false; conn1 = sig0.connect([&] { nonrecursive_callback_ran = true; conn1.disconnect(); }); - BOOST_CHECK(!nonrecursive_callback_ran); - BOOST_CHECK(conn0.connected()); - BOOST_CHECK(conn1.connected()); + CHECK(!nonrecursive_callback_ran); + CHECK(conn0.connected()); + CHECK(conn1.connected()); sig0(); - BOOST_CHECK(nonrecursive_callback_ran); - BOOST_CHECK(conn0.connected()); - BOOST_CHECK(!conn1.connected()); + CHECK(nonrecursive_callback_ran); + CHECK(conn0.connected()); + CHECK(!conn1.connected()); nonrecursive_callback_ran = false; conn1 = sig0.connect([&] { conn2 = sig0.connect([&] { - BOOST_CHECK(conn0.connected()); + CHECK(conn0.connected()); recursive_callback_ran = true; conn0.disconnect(); conn2.disconnect(); @@ -231,27 +231,27 @@ BOOST_AUTO_TEST_CASE(recursion_safety) nonrecursive_callback_ran = true; conn1.disconnect(); }); - BOOST_CHECK(!nonrecursive_callback_ran); - BOOST_CHECK(!recursive_callback_ran); - BOOST_CHECK(conn0.connected()); - BOOST_CHECK(conn1.connected()); - BOOST_CHECK(!conn2.connected()); + CHECK(!nonrecursive_callback_ran); + CHECK(!recursive_callback_ran); + CHECK(conn0.connected()); + CHECK(conn1.connected()); + CHECK(!conn2.connected()); sig0(); - BOOST_CHECK(nonrecursive_callback_ran); - BOOST_CHECK(!recursive_callback_ran); - BOOST_CHECK(conn0.connected()); - BOOST_CHECK(!conn1.connected()); - BOOST_CHECK(conn2.connected()); + CHECK(nonrecursive_callback_ran); + CHECK(!recursive_callback_ran); + CHECK(conn0.connected()); + CHECK(!conn1.connected()); + CHECK(conn2.connected()); sig0(); - BOOST_CHECK(recursive_callback_ran); - BOOST_CHECK(!conn0.connected()); - BOOST_CHECK(!conn1.connected()); - BOOST_CHECK(!conn2.connected()); + CHECK(recursive_callback_ran); + CHECK(!conn0.connected()); + CHECK(!conn1.connected()); + CHECK(!conn2.connected()); } /* Test that disconnection from another thread works in real time */ -BOOST_AUTO_TEST_CASE(disconnect_thread_safety) +FIXTURE_TEST_CASE("disconnect_thread_safety", BasicTestingSetup) { btcsignals::connection conn0, conn1, conn2; btcsignals::signal sig0; @@ -273,8 +273,8 @@ BOOST_AUTO_TEST_CASE(disconnect_thread_safety) }); sig0(val); thr.join(); - BOOST_CHECK_EQUAL(val, 0); + CHECK(val == 0); } -BOOST_AUTO_TEST_SUITE_END() +TEST_SUITE_END() diff --git a/src/test/caches_tests.cpp b/src/test/caches_tests.cpp index 69c42f0bbf18..69a602ec84f7 100644 --- a/src/test/caches_tests.cpp +++ b/src/test/caches_tests.cpp @@ -5,38 +5,38 @@ #include #include -#include +#include using namespace node; -BOOST_AUTO_TEST_SUITE(caches_tests) +TEST_SUITE_BEGIN("caches_tests") -BOOST_AUTO_TEST_CASE(oversized_dbcache_warning) +TEST_CASE("oversized_dbcache_warning") { // memory restricted setup - cap is DEFAULT_DB_CACHE (450 MiB) - BOOST_CHECK(!ShouldWarnOversizedDbCache(/*dbcache=*/4_MiB, /*total_ram=*/1_GiB)); // Under cap - BOOST_CHECK( ShouldWarnOversizedDbCache(/*dbcache=*/512_MiB, /*total_ram=*/1_GiB)); // At cap - BOOST_CHECK( ShouldWarnOversizedDbCache(/*dbcache=*/1500_MiB, /*total_ram=*/1_GiB)); // Over cap + CHECK(!ShouldWarnOversizedDbCache(/*dbcache=*/4_MiB, /*total_ram=*/1_GiB)); // Under cap + CHECK(ShouldWarnOversizedDbCache(/*dbcache=*/512_MiB, /*total_ram=*/1_GiB)); // At cap + CHECK(ShouldWarnOversizedDbCache(/*dbcache=*/1500_MiB, /*total_ram=*/1_GiB)); // Over cap // 2 GiB RAM - cap is 75% - BOOST_CHECK(!ShouldWarnOversizedDbCache(/*dbcache=*/1500_MiB, /*total_ram=*/2_GiB)); // Under cap - BOOST_CHECK( ShouldWarnOversizedDbCache(/*dbcache=*/1600_MiB, /*total_ram=*/2_GiB)); // Over cap + CHECK(!ShouldWarnOversizedDbCache(/*dbcache=*/1500_MiB, /*total_ram=*/2_GiB)); // Under cap + CHECK(ShouldWarnOversizedDbCache(/*dbcache=*/1600_MiB, /*total_ram=*/2_GiB)); // Over cap // 4 GiB RAM - cap is 75% - BOOST_CHECK(!ShouldWarnOversizedDbCache(/*dbcache=*/2500_MiB, /*total_ram=*/4_GiB)); // Under cap - BOOST_CHECK( ShouldWarnOversizedDbCache(/*dbcache=*/3500_MiB, /*total_ram=*/4_GiB)); // Over cap + CHECK(!ShouldWarnOversizedDbCache(/*dbcache=*/2500_MiB, /*total_ram=*/4_GiB)); // Under cap + CHECK(ShouldWarnOversizedDbCache(/*dbcache=*/3500_MiB, /*total_ram=*/4_GiB)); // Over cap // 8 GiB RAM - cap is 75% - BOOST_CHECK(!ShouldWarnOversizedDbCache(/*dbcache=*/6000_MiB, /*total_ram=*/8_GiB)); // Under cap - BOOST_CHECK( ShouldWarnOversizedDbCache(/*dbcache=*/7000_MiB, /*total_ram=*/8_GiB)); // Over cap + CHECK(!ShouldWarnOversizedDbCache(/*dbcache=*/6000_MiB, /*total_ram=*/8_GiB)); // Under cap + CHECK(ShouldWarnOversizedDbCache(/*dbcache=*/7000_MiB, /*total_ram=*/8_GiB)); // Over cap // 16 GiB RAM - cap is 75% - BOOST_CHECK(!ShouldWarnOversizedDbCache(/*dbcache=*/10_GiB, /*total_ram=*/16_GiB)); // Under cap - BOOST_CHECK( ShouldWarnOversizedDbCache(/*dbcache=*/15_GiB, /*total_ram=*/16_GiB)); // Over cap + CHECK(!ShouldWarnOversizedDbCache(/*dbcache=*/10_GiB, /*total_ram=*/16_GiB)); // Under cap + CHECK(ShouldWarnOversizedDbCache(/*dbcache=*/15_GiB, /*total_ram=*/16_GiB)); // Over cap // 32 GiB RAM - cap is 75% - BOOST_CHECK(!ShouldWarnOversizedDbCache(/*dbcache=*/20_GiB, /*total_ram=*/32_GiB)); // Under cap - BOOST_CHECK( ShouldWarnOversizedDbCache(/*dbcache=*/30_GiB, /*total_ram=*/32_GiB)); // Over cap + CHECK(!ShouldWarnOversizedDbCache(/*dbcache=*/20_GiB, /*total_ram=*/32_GiB)); // Under cap + CHECK(ShouldWarnOversizedDbCache(/*dbcache=*/30_GiB, /*total_ram=*/32_GiB)); // Over cap } -BOOST_AUTO_TEST_SUITE_END() +TEST_SUITE_END() diff --git a/src/test/chain_tests.cpp b/src/test/chain_tests.cpp index 966802b65adc..3f0a608eaaa6 100644 --- a/src/test/chain_tests.cpp +++ b/src/test/chain_tests.cpp @@ -2,7 +2,7 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#include +#include #include #include @@ -10,7 +10,7 @@ #include #include -BOOST_FIXTURE_TEST_SUITE(chain_tests, BasicTestingSetup) +TEST_SUITE_BEGIN("chain_tests") namespace { @@ -19,7 +19,7 @@ const CBlockIndex* NaiveGetAncestor(const CBlockIndex* a, int height) while (a->nHeight > height) { a = a->pprev; } - BOOST_REQUIRE_EQUAL(a->nHeight, height); + REQUIRE(a->nHeight == height); return a; } @@ -32,17 +32,17 @@ const CBlockIndex* NaiveLastCommonAncestor(const CBlockIndex* a, const CBlockInd b = b->pprev; } while (a != b) { - BOOST_REQUIRE_EQUAL(a->nHeight, b->nHeight); + REQUIRE(a->nHeight == b->nHeight); a = a->pprev; b = b->pprev; } - BOOST_REQUIRE_EQUAL(a, b); + REQUIRE(a == b); return a; } } // namespace -BOOST_AUTO_TEST_CASE(basic_tests) +FIXTURE_TEST_CASE("basic_tests", BasicTestingSetup) { // An empty chain const CChain chain_0; @@ -58,33 +58,33 @@ BOOST_AUTO_TEST_CASE(basic_tests) bi1.nHeight = 1; chain_2.SetTip(bi1); - BOOST_CHECK_EQUAL(chain_0.Height(), -1); - BOOST_CHECK_EQUAL(chain_2.Height(), 1); + CHECK(chain_0.Height() == -1); + CHECK(chain_2.Height() == 1); - BOOST_CHECK_EQUAL(chain_0.Tip(), nullptr); - BOOST_CHECK_EQUAL(chain_2.Tip(), &bi1); + CHECK(chain_0.Tip() == nullptr); + CHECK((chain_2.Tip() == &bi1)); // Indexer accessor: call with valid and invalid (low & high) values - BOOST_CHECK_EQUAL(chain_2[-1], nullptr); - BOOST_CHECK_EQUAL(chain_2[0], &genesis); - BOOST_CHECK_EQUAL(chain_2[1], &bi1); - BOOST_CHECK_EQUAL(chain_2[2], nullptr); + CHECK(chain_2[-1] == nullptr); + CHECK((chain_2[0] == &genesis)); + CHECK((chain_2[1] == &bi1)); + CHECK(chain_2[2] == nullptr); // Contains: call with contained & non-contained blocks - BOOST_CHECK(chain_2.Contains(genesis)); - BOOST_CHECK(chain_2.Contains(bi1)); - BOOST_CHECK(!chain_0.Contains(genesis)); + CHECK(chain_2.Contains(genesis)); + CHECK(chain_2.Contains(bi1)); + CHECK(!chain_0.Contains(genesis)); // Call with non-tip & tip blocks - BOOST_CHECK_EQUAL(chain_2.Next(genesis), &bi1); - BOOST_CHECK_EQUAL(chain_2.Next(bi1), nullptr); - BOOST_CHECK_EQUAL(chain_0.Next(genesis), nullptr); + CHECK((chain_2.Next(genesis) == &bi1)); + CHECK(chain_2.Next(bi1) == nullptr); + CHECK(chain_0.Next(genesis) == nullptr); - BOOST_CHECK_EQUAL(chain_2.Genesis(), &genesis); - BOOST_CHECK_EQUAL(chain_0.Genesis(), nullptr); + CHECK((chain_2.Genesis() == &genesis)); + CHECK(chain_0.Genesis() == nullptr); } -BOOST_AUTO_TEST_CASE(findfork_tests) +FIXTURE_TEST_CASE("findfork_tests", BasicTestingSetup) { // Create a forking chain const auto init_branch{[](auto& blocks, CBlockIndex* parent, int start_height) { @@ -96,13 +96,13 @@ BOOST_AUTO_TEST_CASE(findfork_tests) const auto check_same{[](const CChain& chain, const auto& blocks) { for (const auto& block : blocks) { - BOOST_CHECK_EQUAL(chain.FindFork(block), &block); + CHECK((chain.FindFork(block) == &block)); } }}; const auto check_fork_point{[](const CChain& chain, const auto& blocks, const CBlockIndex& fork_point) { for (const auto& block : blocks) { - BOOST_CHECK_EQUAL(chain.FindFork(block), &fork_point); + CHECK((chain.FindFork(block) == &fork_point)); } }}; @@ -118,7 +118,7 @@ BOOST_AUTO_TEST_CASE(findfork_tests) // Create a chain with the longer fork CChain chain_long; chain_long.SetTip(blocks_long.back()); - BOOST_CHECK_EQUAL(chain_long.Height(), 10 + 10 - 1); + CHECK(chain_long.Height() == 10 + 10 - 1); // Test the blocks in the common part -> result should be the same check_same(chain_long, blocks_common); // Test the blocks on the longer fork -> result should be the same @@ -129,7 +129,7 @@ BOOST_AUTO_TEST_CASE(findfork_tests) // Create a chain with the shorter fork CChain chain_short; chain_short.SetTip(blocks_short.back()); - BOOST_CHECK_EQUAL(chain_short.Height(), 10 + 5 - 1); + CHECK(chain_short.Height() == 10 + 5 - 1); // Test the blocks in the common part -> result should be the same check_same(chain_short, blocks_common); // Test the blocks on the shorter fork -> result should be the same @@ -139,10 +139,10 @@ BOOST_AUTO_TEST_CASE(findfork_tests) // Invalid test case. Mixing chains is not supported CBlockIndex block_on_unrelated_chain; - BOOST_CHECK_EQUAL(chain_long.FindFork(block_on_unrelated_chain), nullptr); + CHECK(chain_long.FindFork(block_on_unrelated_chain) == nullptr); } -BOOST_AUTO_TEST_CASE(chain_test) +FIXTURE_TEST_CASE("chain_test", BasicTestingSetup) { FastRandomContext ctx; std::vector> block_index; @@ -171,16 +171,16 @@ BOOST_AUTO_TEST_CASE(chain_test) const CBlockIndex* block = block_index[ctx.randrange(block_index.size())].get(); unsigned height = ctx.randrange(block->nHeight + 1); const CBlockIndex* result = block->GetAncestor(height); - BOOST_CHECK(result == NaiveGetAncestor(block, height)); + CHECK(result == NaiveGetAncestor(block, height)); } // Run 10000 random LastCommonAncestor queries. for (int q = 0; q < 10000; ++q) { const CBlockIndex* block1 = block_index[ctx.randrange(block_index.size())].get(); const CBlockIndex* block2 = block_index[ctx.randrange(block_index.size())].get(); const CBlockIndex* result = LastCommonAncestor(block1, block2); - BOOST_CHECK(result == NaiveLastCommonAncestor(block1, block2)); + CHECK(result == NaiveLastCommonAncestor(block1, block2)); } } } -BOOST_AUTO_TEST_SUITE_END() +TEST_SUITE_END() diff --git a/src/test/chainstate_write_tests.cpp b/src/test/chainstate_write_tests.cpp index cafadf38f528..8be0e95eac3e 100644 --- a/src/test/chainstate_write_tests.cpp +++ b/src/test/chainstate_write_tests.cpp @@ -7,15 +7,15 @@ #include #include -#include +#include // Taken from validation.cpp static constexpr auto DATABASE_WRITE_INTERVAL_MIN{50min}; static constexpr auto DATABASE_WRITE_INTERVAL_MAX{70min}; -BOOST_AUTO_TEST_SUITE(chainstate_write_tests) +TEST_SUITE_BEGIN("chainstate_write_tests") -BOOST_FIXTURE_TEST_CASE(chainstate_write_interval, TestingSetup) +FIXTURE_TEST_CASE("chainstate_write_interval", TestingSetup) { struct TestSubscriber final : CValidationInterface { bool m_did_flush{false}; @@ -34,24 +34,24 @@ BOOST_FIXTURE_TEST_CASE(chainstate_write_interval, TestingSetup) // The first periodic flush sets m_next_write and does not flush chainstate.FlushStateToDisk(state_dummy, FlushStateMode::PERIODIC); m_node.validation_signals->SyncWithValidationInterfaceQueue(); - BOOST_CHECK(!sub->m_did_flush); + CHECK(!sub->m_did_flush); // The periodic flush interval is between 50 and 70 minutes (inclusive) clock_ctx += DATABASE_WRITE_INTERVAL_MIN - 1min; chainstate.FlushStateToDisk(state_dummy, FlushStateMode::PERIODIC); m_node.validation_signals->SyncWithValidationInterfaceQueue(); - BOOST_CHECK(!sub->m_did_flush); + CHECK(!sub->m_did_flush); clock_ctx += DATABASE_WRITE_INTERVAL_MAX; chainstate.FlushStateToDisk(state_dummy, FlushStateMode::PERIODIC); m_node.validation_signals->SyncWithValidationInterfaceQueue(); - BOOST_CHECK(sub->m_did_flush); + CHECK(sub->m_did_flush); } // Test that we do PERIODIC flushes inside ActivateBestChain. // This is necessary for reindex-chainstate to be able to periodically flush // before reaching chain tip. -BOOST_FIXTURE_TEST_CASE(write_during_multiblock_activation, TestChain100Setup) +FIXTURE_TEST_CASE("write_during_multiblock_activation", TestChain100Setup) { struct TestSubscriber final : CValidationInterface { @@ -79,7 +79,7 @@ BOOST_FIXTURE_TEST_CASE(write_during_multiblock_activation, TestChain100Setup) chainstate.DisconnectTip(state_dummy, nullptr); } - BOOST_CHECK_EQUAL(second_from_tip->pprev, chainstate.m_chain.Tip()); + CHECK(second_from_tip->pprev == chainstate.m_chain.Tip()); // Set m_next_write to current time chainstate.FlushStateToDisk(state_dummy, FlushStateMode::FORCE_FLUSH); @@ -93,12 +93,12 @@ BOOST_FIXTURE_TEST_CASE(write_during_multiblock_activation, TestChain100Setup) // ActivateBestChain back to tip chainstate.ActivateBestChain(state_dummy, nullptr); - BOOST_CHECK_EQUAL(tip, chainstate.m_chain.Tip()); + CHECK(tip == chainstate.m_chain.Tip()); // Check that we flushed inside ActivateBestChain while we were at the // second block from tip, since FlushStateToDisk is called with PERIODIC // inside the outer loop. m_node.validation_signals->SyncWithValidationInterfaceQueue(); - BOOST_CHECK_EQUAL(sub->m_flushed_at_block, second_from_tip); + CHECK(sub->m_flushed_at_block == second_from_tip); } -BOOST_AUTO_TEST_SUITE_END() +TEST_SUITE_END() diff --git a/src/test/checkqueue_tests.cpp b/src/test/checkqueue_tests.cpp index 3e2fc83ff28e..0a4999ae5ea2 100644 --- a/src/test/checkqueue_tests.cpp +++ b/src/test/checkqueue_tests.cpp @@ -10,7 +10,7 @@ #include #include -#include +#include #include #include @@ -172,16 +172,16 @@ void CheckQueueTest::Correct_Queue_range(std::vector range) total -= vChecks.size(); control.Add(std::move(vChecks)); } - BOOST_REQUIRE(!control.Complete().has_value()); - BOOST_REQUIRE_EQUAL(FakeCheckCheckCompletion::n_calls, i); + REQUIRE(!control.Complete().has_value()); + REQUIRE(FakeCheckCheckCompletion::n_calls == i); } } -BOOST_FIXTURE_TEST_SUITE(checkqueue_tests, CheckQueueTest) +TEST_SUITE_BEGIN("checkqueue_tests") /** Test that 0 checks is correct */ -BOOST_AUTO_TEST_CASE(test_CheckQueue_Correct_Zero) +FIXTURE_TEST_CASE("test_CheckQueue_Correct_Zero", CheckQueueTest) { std::vector range; range.push_back(size_t{0}); @@ -189,7 +189,7 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_Correct_Zero) } /** Test that 1 check is correct */ -BOOST_AUTO_TEST_CASE(test_CheckQueue_Correct_One) +FIXTURE_TEST_CASE("test_CheckQueue_Correct_One", CheckQueueTest) { std::vector range; range.push_back(size_t{1}); @@ -197,7 +197,7 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_Correct_One) } /** Test that MAX check is correct */ -BOOST_AUTO_TEST_CASE(test_CheckQueue_Correct_Max) +FIXTURE_TEST_CASE("test_CheckQueue_Correct_Max", CheckQueueTest) { std::vector range; range.push_back(100000); @@ -205,7 +205,7 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_Correct_Max) } /** Test that random numbers of checks are correct */ -BOOST_AUTO_TEST_CASE(test_CheckQueue_Correct_Random) +FIXTURE_TEST_CASE("test_CheckQueue_Correct_Random", CheckQueueTest) { std::vector range; range.reserve(100000/1000); @@ -216,7 +216,7 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_Correct_Random) /** Test that distinct failing checks are caught */ -BOOST_AUTO_TEST_CASE(test_CheckQueue_Catches_Failure) +FIXTURE_TEST_CASE("test_CheckQueue_Catches_Failure", CheckQueueTest) { auto fixed_queue = std::make_unique(QUEUE_BATCH_SIZE, SCRIPT_CHECK_THREADS); for (size_t i = 0; i < 1001; ++i) { @@ -233,15 +233,15 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_Catches_Failure) } auto result = control.Complete(); if (i > 0) { - BOOST_REQUIRE(result.has_value() && *result == static_cast(17 * i)); + REQUIRE((result.has_value() && *result == static_cast(17 * i))); } else { - BOOST_REQUIRE(!result.has_value()); + REQUIRE(!result.has_value()); } } } // Test that a block validation which fails does not interfere with // future blocks, ie, the bad state is cleared. -BOOST_AUTO_TEST_CASE(test_CheckQueue_Recovers_From_Failure) +FIXTURE_TEST_CASE("test_CheckQueue_Recovers_From_Failure", CheckQueueTest) { auto fail_queue = std::make_unique(QUEUE_BATCH_SIZE, SCRIPT_CHECK_THREADS); for (auto times = 0; times < 10; ++times) { @@ -254,7 +254,7 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_Recovers_From_Failure) control.Add(std::move(vChecks)); } bool r = !control.Complete().has_value(); - BOOST_REQUIRE(r != end_fails); + REQUIRE(r != end_fails); } } } @@ -262,7 +262,7 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_Recovers_From_Failure) // Test that unique checks are actually all called individually, rather than // just one check being called repeatedly. Test that checks are not called // more than once as well -BOOST_AUTO_TEST_CASE(test_CheckQueue_UniqueCheck) +FIXTURE_TEST_CASE("test_CheckQueue_UniqueCheck", CheckQueueTest) { auto queue = std::make_unique(QUEUE_BATCH_SIZE, SCRIPT_CHECK_THREADS); size_t COUNT = 100000; @@ -280,11 +280,11 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_UniqueCheck) { LOCK(UniqueCheck::m); bool r = true; - BOOST_REQUIRE_EQUAL(UniqueCheck::results.size(), COUNT); + REQUIRE(UniqueCheck::results.size() == COUNT); for (size_t i = 0; i < COUNT; ++i) { r = r && UniqueCheck::results.count(i) == 1; } - BOOST_REQUIRE(r); + REQUIRE(r); } } @@ -294,7 +294,7 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_UniqueCheck) // This test attempts to catch a pathological case where by lazily freeing // checks might mean leaving a check un-swapped out, and decreasing by 1 each // time could leave the data hanging across a sequence of blocks. -BOOST_AUTO_TEST_CASE(test_CheckQueue_Memory) +FIXTURE_TEST_CASE("test_CheckQueue_Memory", CheckQueueTest) { auto queue = std::make_unique(QUEUE_BATCH_SIZE, SCRIPT_CHECK_THREADS); for (size_t i = 0; i < 1000; ++i) { @@ -313,13 +313,13 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_Memory) control.Add(std::move(vChecks)); } } - BOOST_REQUIRE_EQUAL(MemoryCheck::fake_allocated_memory, 0U); + REQUIRE(MemoryCheck::fake_allocated_memory == 0U); } } // Test that a new verification cannot occur until all checks // have been destructed -BOOST_AUTO_TEST_CASE(test_CheckQueue_FrozenCleanup) +FIXTURE_TEST_CASE("test_CheckQueue_FrozenCleanup", CheckQueueTest) { auto queue = std::make_unique(QUEUE_BATCH_SIZE, SCRIPT_CHECK_THREADS); bool fails = false; @@ -348,12 +348,12 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_FrozenCleanup) FrozenCleanupCheck::cv.notify_one(); // Wait for control to finish t0.join(); - BOOST_REQUIRE(!fails); + REQUIRE(!fails); } /** Test that CCheckQueueControl is threadsafe */ -BOOST_AUTO_TEST_CASE(test_CheckQueueControl_Locks) +FIXTURE_TEST_CASE("test_CheckQueueControl_Locks", CheckQueueTest) { auto queue = std::make_unique(QUEUE_BATCH_SIZE, SCRIPT_CHECK_THREADS); { @@ -374,7 +374,7 @@ BOOST_AUTO_TEST_CASE(test_CheckQueueControl_Locks) for (auto& thread: tg) { if (thread.joinable()) thread.join(); } - BOOST_REQUIRE_EQUAL(fails, 0); + REQUIRE(fails == 0); } { std::vector tg; @@ -410,11 +410,11 @@ BOOST_AUTO_TEST_CASE(test_CheckQueueControl_Locks) // Acknowledge the done done_ack = true; cv.notify_one(); - BOOST_REQUIRE(!fails); + REQUIRE(!fails); } for (auto& thread: tg) { if (thread.joinable()) thread.join(); } } } -BOOST_AUTO_TEST_SUITE_END() +TEST_SUITE_END() diff --git a/src/test/cluster_linearize_tests.cpp b/src/test/cluster_linearize_tests.cpp index 4f851c1d5ff7..310b4790510b 100644 --- a/src/test/cluster_linearize_tests.cpp +++ b/src/test/cluster_linearize_tests.cpp @@ -10,9 +10,9 @@ #include -#include +#include -BOOST_FIXTURE_TEST_SUITE(cluster_linearize_tests, BasicTestingSetup) +TEST_SUITE_BEGIN("cluster_linearize_tests") using namespace cluster_linearize; using namespace util::hex_literals; @@ -44,14 +44,14 @@ void TestDepGraphSerialization(const std::vector>& c std::vector encoding; VectorWriter writer(encoding, 0); writer << Using(depgraph); - BOOST_CHECK_EQUAL(HexStr(encoding), hexenc); + CHECK(HexStr(encoding) == hexenc); // Test that deserializing that encoding yields depgraph. This is effectively already implied // by the round-trip test above (if depgraph is acyclic), but verify it explicitly again here. SpanReader reader(encoding); DepGraph depgraph_read; reader >> Using(depgraph_read); - BOOST_CHECK(depgraph == depgraph_read); + CHECK(depgraph == depgraph_read); } void TestOptimalLinearization(std::span enc, std::initializer_list optimal_linearization) @@ -95,10 +95,10 @@ void TestOptimalLinearization(std::span enc, std::initializer_lis /*fallback_order=*/IndexTxOrder{}, /*old_linearization=*/lin, /*is_topological=*/is_topological); - BOOST_CHECK(opt); - BOOST_CHECK(cost <= MaxOptimalLinearizationCost(depgraph.TxCount())); + CHECK(opt); + CHECK(cost <= MaxOptimalLinearizationCost(depgraph.TxCount())); SanityCheck(depgraph, lin); - BOOST_CHECK(std::ranges::equal(lin, optimal_linearization)); + CHECK(std::ranges::equal(lin, optimal_linearization)); } tx_count = depgraph.PositionRange(); }; @@ -122,7 +122,7 @@ void TestOptimalLinearization(std::span enc, std::initializer_lis } // namespace -BOOST_AUTO_TEST_CASE(depgraph_ser_tests) +FIXTURE_TEST_CASE("depgraph_ser_tests", BasicTestingSetup) { // Empty cluster. TestDepGraphSerialization( @@ -242,7 +242,7 @@ BOOST_AUTO_TEST_CASE(depgraph_ser_tests) ); } -BOOST_AUTO_TEST_CASE(depgraph_optimal_tests) +FIXTURE_TEST_CASE("depgraph_optimal_tests", BasicTestingSetup) { // Compare linearizations with known-optimal chunk feerate diagrams. @@ -482,4 +482,4 @@ BOOST_AUTO_TEST_CASE(depgraph_optimal_tests) TestOptimalLinearization("866faa23008646b71501851f96130282588f1103804d851c0000000003822097600100000003850a8f310200000003856e9201000000038656935f01000003855b8f5f020000018743923a0000000a812b810b010000098403a328020000068712970203000005833e98400400000200"_hex_u8, {11, 14, 1, 10, 4, 3, 5, 13, 9, 7, 6, 12, 8, 0, 2}); } -BOOST_AUTO_TEST_SUITE_END() +TEST_SUITE_END() diff --git a/src/test/coins_tests.cpp b/src/test/coins_tests.cpp index 5ae46b3badf4..3400e3978907 100644 --- a/src/test/coins_tests.cpp +++ b/src/test/coins_tests.cpp @@ -22,7 +22,7 @@ #include #include -#include +#include using namespace util::hex_literals; @@ -85,8 +85,8 @@ class CCoinsViewCacheTest : public CCoinsViewCache ret += entry.second.coin.DynamicMemoryUsage(); ++count; } - BOOST_CHECK_EQUAL(GetCacheSize(), count); - BOOST_CHECK_EQUAL(DynamicMemoryUsage(), ret); + CHECK(GetCacheSize() == count); + CHECK(DynamicMemoryUsage() == ret); if (sanity_check) { SanityCheck(); } @@ -163,15 +163,15 @@ void SimulationTest(CCoinsView* base, bool fake_best_block) // former just delegates to the latter and returns the first unspent in a txn. const Coin& entry = (m_rng.randrange(500) == 0) ? AccessByTxid(*stack.back(), txid) : stack.back()->AccessCoin(COutPoint(txid, 0)); - BOOST_CHECK(coin == entry); + CHECK((coin == entry)); if (test_havecoin_before) { - BOOST_CHECK(result_havecoin == !entry.IsSpent()); + CHECK(result_havecoin == !entry.IsSpent()); } if (test_havecoin_after) { bool ret = stack.back()->HaveCoin(COutPoint(txid, 0)); - BOOST_CHECK(ret == !entry.IsSpent()); + CHECK(ret == !entry.IsSpent()); } if (m_rng.randrange(5) == 0 || coin.IsSpent()) { @@ -182,7 +182,7 @@ void SimulationTest(CCoinsView* base, bool fake_best_block) // Infrequently test adding unspendable coins. if (m_rng.randrange(16) == 0 && coin.IsSpent()) { newcoin.out.scriptPubKey.assign(1 + m_rng.randbits(6), OP_RETURN); - BOOST_CHECK(newcoin.out.scriptPubKey.IsUnspendable()); + CHECK(newcoin.out.scriptPubKey.IsUnspendable()); added_an_unspendable_entry = true; } else { // Random sizes so we can test memory usage accounting @@ -199,7 +199,7 @@ void SimulationTest(CCoinsView* base, bool fake_best_block) // Spend the coin. removed_an_entry = true; coin.Clear(); - BOOST_CHECK(stack.back()->SpendCoin(COutPoint(txid, 0))); + CHECK(stack.back()->SpendCoin(COutPoint(txid, 0))); } } @@ -216,12 +216,12 @@ void SimulationTest(CCoinsView* base, bool fake_best_block) for (const auto& entry : result) { bool have = stack.back()->HaveCoin(entry.first); const Coin& coin = stack.back()->AccessCoin(entry.first); - BOOST_CHECK(have == !coin.IsSpent()); - BOOST_CHECK(coin == entry.second); + CHECK(have == !coin.IsSpent()); + CHECK((coin == entry.second)); if (coin.IsSpent()) { missed_an_entry = true; } else { - BOOST_CHECK(stack.back()->HaveCoinInCache(entry.first)); + CHECK(stack.back()->HaveCoinInCache(entry.first)); found_an_entry = true; } } @@ -267,41 +267,41 @@ void SimulationTest(CCoinsView* base, bool fake_best_block) } // Verify coverage. - BOOST_CHECK(removed_all_caches); - BOOST_CHECK(reached_4_caches); - BOOST_CHECK(added_an_entry); - BOOST_CHECK(added_an_unspendable_entry); - BOOST_CHECK(removed_an_entry); - BOOST_CHECK(updated_an_entry); - BOOST_CHECK(found_an_entry); - BOOST_CHECK(missed_an_entry); - BOOST_CHECK(uncached_an_entry); - BOOST_CHECK(flushed_without_erase); + CHECK(removed_all_caches); + CHECK(reached_4_caches); + CHECK(added_an_entry); + CHECK(added_an_unspendable_entry); + CHECK(removed_an_entry); + CHECK(updated_an_entry); + CHECK(found_an_entry); + CHECK(missed_an_entry); + CHECK(uncached_an_entry); + CHECK(flushed_without_erase); } }; // struct CacheTest -BOOST_FIXTURE_TEST_SUITE(coins_tests_base, BasicTestingSetup) +TEST_SUITE_BEGIN("coins_tests_base") // Run the above simulation for multiple base types. -BOOST_FIXTURE_TEST_CASE(coins_cache_base_simulation_test, CacheTest) +FIXTURE_TEST_CASE("coins_cache_base_simulation_test", CacheTest) { CCoinsViewTest base{m_rng}; SimulationTest(&base, false); } -BOOST_AUTO_TEST_SUITE_END() +TEST_SUITE_END() -BOOST_FIXTURE_TEST_SUITE(coins_tests_dbbase, BasicTestingSetup) +TEST_SUITE_BEGIN("coins_tests_dbbase") -BOOST_FIXTURE_TEST_CASE(coins_cache_dbbase_simulation_test, CacheTest) +FIXTURE_TEST_CASE("coins_cache_dbbase_simulation_test", CacheTest) { CCoinsViewDB db_base{{.path = "test", .cache_bytes = 8_MiB, .memory_only = true}, {}}; SimulationTest(&db_base, true); } -BOOST_AUTO_TEST_SUITE_END() +TEST_SUITE_END() -BOOST_FIXTURE_TEST_SUITE(coins_tests, BasicTestingSetup) +TEST_SUITE_BEGIN("coins_tests") struct UpdateTest : BasicTestingSetup { // Store of all necessary tx and undo data for next test @@ -326,7 +326,7 @@ UtxoData::iterator FindRandomFrom(const std::set &utxoSet) { // random txs are created and UpdateCoins is used to update the cache stack // In particular it is tested that spending a duplicate coinbase tx // has the expected effect (the other duplicate is overwritten at all cache levels) -BOOST_FIXTURE_TEST_CASE(updatecoins_simulation_test, UpdateTest) +FIXTURE_TEST_CASE("updatecoins_simulation_test", UpdateTest) { SeedRandomForTest(SeedRand::ZEROS); @@ -454,7 +454,7 @@ BOOST_FIXTURE_TEST_CASE(updatecoins_simulation_test, UpdateTest) // Disconnect the tx from the current UTXO // See code in DisconnectBlock // remove outputs - BOOST_CHECK(stack.back()->SpendCoin(utxod->first)); + CHECK(stack.back()->SpendCoin(utxod->first)); // restore inputs if (!tx.IsCoinBase()) { const COutPoint &out = tx.vin[0].prevout; @@ -475,8 +475,8 @@ BOOST_FIXTURE_TEST_CASE(updatecoins_simulation_test, UpdateTest) for (const auto& entry : result) { bool have = stack.back()->HaveCoin(entry.first); const Coin& coin = stack.back()->AccessCoin(entry.first); - BOOST_CHECK(have == !coin.IsSpent()); - BOOST_CHECK(coin == entry.second); + CHECK(have == !coin.IsSpent()); + CHECK((coin == entry.second)); } } @@ -515,40 +515,40 @@ BOOST_FIXTURE_TEST_CASE(updatecoins_simulation_test, UpdateTest) } // Verify coverage. - BOOST_CHECK(spent_a_duplicate_coinbase); + CHECK(spent_a_duplicate_coinbase); } -BOOST_AUTO_TEST_CASE(ccoins_serialization) +FIXTURE_TEST_CASE("ccoins_serialization", BasicTestingSetup) { // Good example Coin cc1; SpanReader{"97f23c835800816115944e077fe7c803cfa57f29b36bf87c1d35"_hex} >> cc1; - BOOST_CHECK_EQUAL(cc1.IsCoinBase(), false); - BOOST_CHECK_EQUAL(cc1.nHeight, 203998U); - BOOST_CHECK_EQUAL(cc1.out.nValue, CAmount{60000000000}); - BOOST_CHECK_EQUAL(HexStr(cc1.out.scriptPubKey), HexStr(GetScriptForDestination(PKHash(uint160("816115944e077fe7c803cfa57f29b36bf87c1d35"_hex_u8))))); + CHECK(cc1.IsCoinBase() == false); + CHECK(cc1.nHeight == 203998U); + CHECK(cc1.out.nValue == CAmount{60000000000}); + CHECK(HexStr(cc1.out.scriptPubKey) == HexStr(GetScriptForDestination(PKHash(uint160("816115944e077fe7c803cfa57f29b36bf87c1d35"_hex_u8))))); // Good example Coin cc2; SpanReader{"8ddf77bbd123008c988f1a4a4de2161e0f50aac7f17e7f9555caa4"_hex} >> cc2; - BOOST_CHECK_EQUAL(cc2.IsCoinBase(), true); - BOOST_CHECK_EQUAL(cc2.nHeight, 120891U); - BOOST_CHECK_EQUAL(cc2.out.nValue, 110397); - BOOST_CHECK_EQUAL(HexStr(cc2.out.scriptPubKey), HexStr(GetScriptForDestination(PKHash(uint160("8c988f1a4a4de2161e0f50aac7f17e7f9555caa4"_hex_u8))))); + CHECK(cc2.IsCoinBase() == true); + CHECK(cc2.nHeight == 120891U); + CHECK(cc2.out.nValue == 110397); + CHECK(HexStr(cc2.out.scriptPubKey) == HexStr(GetScriptForDestination(PKHash(uint160("8c988f1a4a4de2161e0f50aac7f17e7f9555caa4"_hex_u8))))); // Smallest possible example Coin cc3; SpanReader{"000006"_hex} >> cc3; - BOOST_CHECK_EQUAL(cc3.IsCoinBase(), false); - BOOST_CHECK_EQUAL(cc3.nHeight, 0U); - BOOST_CHECK_EQUAL(cc3.out.nValue, 0); - BOOST_CHECK_EQUAL(cc3.out.scriptPubKey.size(), 0U); + CHECK(cc3.IsCoinBase() == false); + CHECK(cc3.nHeight == 0U); + CHECK(cc3.out.nValue == 0); + CHECK(cc3.out.scriptPubKey.size() == 0U); // scriptPubKey that ends beyond the end of the stream try { Coin cc4; SpanReader{"000007"_hex} >> cc4; - BOOST_CHECK_MESSAGE(false, "We should have thrown"); + CHECK(false, "We should have thrown"); } catch (const std::ios_base::failure&) { } @@ -556,11 +556,11 @@ BOOST_AUTO_TEST_CASE(ccoins_serialization) DataStream tmp{}; uint64_t x = 3000000000ULL; tmp << VARINT(x); - BOOST_CHECK_EQUAL(HexStr(tmp), "8a95c0bb00"); + CHECK(HexStr(tmp) == "8a95c0bb00"); try { Coin cc5; SpanReader{"00008a95c0bb00"_hex} >> cc5; - BOOST_CHECK_MESSAGE(false, "We should have thrown"); + CHECK(false, "We should have thrown"); } catch (const std::ios_base::failure&) { } } @@ -660,7 +660,7 @@ static void WriteCoinsViewEntry(CCoinsView& view, const MaybeCoin& cache_coin) size_t dirty_count{cache_coin && cache_coin->IsDirty()}; auto cursor{CoinsViewCacheCursor(dirty_count, sentinel, map, /*will_erase=*/true)}; view.BatchWrite(cursor, {}); - BOOST_CHECK_EQUAL(dirty_count, 0U); + CHECK(dirty_count == 0U); } class SingleEntryCacheTest @@ -684,12 +684,12 @@ static void CheckAccessCoin(const CAmount base_value, const MaybeCoin& cache_coi { SingleEntryCacheTest test{base_value, cache_coin}; auto& coin = test.cache.AccessCoin(OUTPOINT); - BOOST_CHECK_EQUAL(coin.IsSpent(), !test.cache.GetCoin(OUTPOINT)); + CHECK(coin.IsSpent() == !test.cache.GetCoin(OUTPOINT)); test.cache.SelfTest(/*sanity_check=*/false); - BOOST_CHECK_EQUAL(GetCoinsMapEntry(test.cache.map()), expected); + CHECK(GetCoinsMapEntry(test.cache.map()) == expected); } -BOOST_AUTO_TEST_CASE(ccoins_access) +FIXTURE_TEST_CASE("ccoins_access", BasicTestingSetup) { /* Check AccessCoin behavior, requesting a coin from a cache view layered on * top of a base view, and checking the resulting entry in the cache after @@ -716,10 +716,10 @@ static void CheckSpendCoins(const CAmount base_value, const MaybeCoin& cache_coi SingleEntryCacheTest test{base_value, cache_coin}; test.cache.SpendCoin(OUTPOINT); test.cache.SelfTest(); - BOOST_CHECK_EQUAL(GetCoinsMapEntry(test.cache.map()), expected); + CHECK(GetCoinsMapEntry(test.cache.map()) == expected); } -BOOST_AUTO_TEST_CASE(ccoins_spend) +FIXTURE_TEST_CASE("ccoins_spend", BasicTestingSetup) { /* Check SpendCoin behavior, requesting a coin from a cache view layered on * top of a base view, spending, and then checking @@ -749,13 +749,13 @@ static void CheckAddCoin(const CAmount base_value, const MaybeCoin& cache_coin, if (auto* expected_coin{std::get_if(&expected)}) { add_coin(); test.cache.SelfTest(); - BOOST_CHECK_EQUAL(GetCoinsMapEntry(test.cache.map()), *expected_coin); + CHECK(GetCoinsMapEntry(test.cache.map()) == *expected_coin); } else { - BOOST_CHECK_EXCEPTION(add_coin(), std::logic_error, HasReason(std::get(expected))); + CHECK_EXCEPTION(add_coin(), std::logic_error, HasReason(std::get(expected))); } } -BOOST_AUTO_TEST_CASE(ccoins_add) +FIXTURE_TEST_CASE("ccoins_add", BasicTestingSetup) { /* Check AddCoin behavior, requesting a new coin from a cache view, * writing a modification to the coin, and then checking the resulting @@ -794,13 +794,13 @@ static void CheckWriteCoins(const MaybeCoin& parent, const MaybeCoin& child, con if (auto* expected_coin{std::get_if(&expected)}) { write_coins(); test.cache.SelfTest(/*sanity_check=*/false); - BOOST_CHECK_EQUAL(GetCoinsMapEntry(test.cache.map()), *expected_coin); + CHECK(GetCoinsMapEntry(test.cache.map()) == *expected_coin); } else { - BOOST_CHECK_EXCEPTION(write_coins(), std::logic_error, HasReason(std::get(expected))); + CHECK_EXCEPTION(write_coins(), std::logic_error, HasReason(std::get(expected))); } } -BOOST_AUTO_TEST_CASE(ccoins_write) +FIXTURE_TEST_CASE("ccoins_write", BasicTestingSetup) { /* Check BatchWrite behavior, flushing one entry from a child cache to a * parent cache, and checking the resulting entry in the parent cache @@ -919,8 +919,8 @@ void TestFlushBehavior( COutPoint outp = COutPoint(txid, 0); Coin coin = MakeCoin(); // Ensure the coins views haven't seen this coin before. - BOOST_CHECK(!base.HaveCoin(outp)); - BOOST_CHECK(!view->HaveCoin(outp)); + CHECK(!base.HaveCoin(outp)); + CHECK(!view->HaveCoin(outp)); // --- 1. Adding a random coin to the child cache // @@ -930,26 +930,26 @@ void TestFlushBehavior( cache_size = view->map().size(); // `base` shouldn't have coin (no flush yet) but `view` should have cached it. - BOOST_CHECK(!base.HaveCoin(outp)); - BOOST_CHECK(view->HaveCoin(outp)); + CHECK(!base.HaveCoin(outp)); + CHECK(view->HaveCoin(outp)); - BOOST_CHECK_EQUAL(GetCoinsMapEntry(view->map(), outp), CoinEntry(coin.out.nValue, CoinEntry::State::DIRTY_FRESH)); + CHECK(GetCoinsMapEntry(view->map(), outp) == CoinEntry(coin.out.nValue, CoinEntry::State::DIRTY_FRESH)); // --- 2. Flushing all caches (without erasing) // flush_all(/*erase=*/ false); // CoinsMap usage should be unchanged since we didn't erase anything. - BOOST_CHECK_EQUAL(cache_usage, view->DynamicMemoryUsage()); - BOOST_CHECK_EQUAL(cache_size, view->map().size()); + CHECK(cache_usage == view->DynamicMemoryUsage()); + CHECK(cache_size == view->map().size()); // --- 3. Ensuring the entry still exists in the cache and has been written to parent // - BOOST_CHECK_EQUAL(GetCoinsMapEntry(view->map(), outp), CoinEntry(coin.out.nValue, CoinEntry::State::CLEAN)); // State should have been wiped. + CHECK(GetCoinsMapEntry(view->map(), outp) == CoinEntry(coin.out.nValue, CoinEntry::State::CLEAN)); // State should have been wiped. // Both views should now have the coin. - BOOST_CHECK(base.HaveCoin(outp)); - BOOST_CHECK(view->HaveCoin(outp)); + CHECK(base.HaveCoin(outp)); + CHECK(view->HaveCoin(outp)); if (do_erasing_flush) { // --- 4. Flushing the caches again (with erasing) @@ -957,40 +957,38 @@ void TestFlushBehavior( flush_all(/*erase=*/ true); // Memory does not necessarily go down due to the map using a memory pool - BOOST_TEST(view->DynamicMemoryUsage() <= cache_usage); + CHECK(view->DynamicMemoryUsage() <= cache_usage); // Size of the cache must go down though - BOOST_TEST(view->map().size() < cache_size); + CHECK(view->map().size() < cache_size); // --- 5. Ensuring the entry is no longer in the cache // - BOOST_CHECK(!GetCoinsMapEntry(view->map(), outp)); + CHECK(!GetCoinsMapEntry(view->map(), outp)); view->AccessCoin(outp); - BOOST_CHECK_EQUAL(GetCoinsMapEntry(view->map(), outp), CoinEntry(coin.out.nValue, CoinEntry::State::CLEAN)); + CHECK(GetCoinsMapEntry(view->map(), outp) == CoinEntry(coin.out.nValue, CoinEntry::State::CLEAN)); } // Can't overwrite an entry without specifying that an overwrite is // expected. - BOOST_CHECK_THROW( - view->AddCoin(outp, Coin(coin), /*possible_overwrite=*/ false), - std::logic_error); + CHECK_THROWS_AS(view->AddCoin(outp, Coin(coin), /*possible_overwrite=*/ false), std::logic_error); // --- 6. Spend the coin. // - BOOST_CHECK(view->SpendCoin(outp)); + CHECK(view->SpendCoin(outp)); // The coin should be in the cache, but spent and marked dirty. - BOOST_CHECK_EQUAL(GetCoinsMapEntry(view->map(), outp), SPENT_DIRTY); - BOOST_CHECK(!view->HaveCoin(outp)); // Coin should be considered spent in `view`. - BOOST_CHECK(base.HaveCoin(outp)); // But coin should still be unspent in `base`. + CHECK(GetCoinsMapEntry(view->map(), outp) == SPENT_DIRTY); + CHECK(!view->HaveCoin(outp)); // Coin should be considered spent in `view`. + CHECK(base.HaveCoin(outp)); // But coin should still be unspent in `base`. flush_all(/*erase=*/ false); // Coin should be considered spent in both views. - BOOST_CHECK(!view->HaveCoin(outp)); - BOOST_CHECK(!base.HaveCoin(outp)); + CHECK(!view->HaveCoin(outp)); + CHECK(!base.HaveCoin(outp)); // Spent coin should not be spendable. - BOOST_CHECK(!view->SpendCoin(outp)); + CHECK(!view->SpendCoin(outp)); // --- Bonus check: ensure that a coin added to the base view via one cache // can be spent by another cache which has never seen it. @@ -998,21 +996,21 @@ void TestFlushBehavior( txid = Txid::FromUint256(m_rng.rand256()); outp = COutPoint(txid, 0); coin = MakeCoin(); - BOOST_CHECK(!base.HaveCoin(outp)); - BOOST_CHECK(!all_caches[0]->HaveCoin(outp)); - BOOST_CHECK(!all_caches[1]->HaveCoin(outp)); + CHECK(!base.HaveCoin(outp)); + CHECK(!all_caches[0]->HaveCoin(outp)); + CHECK(!all_caches[1]->HaveCoin(outp)); all_caches[0]->AddCoin(outp, std::move(coin), false); all_caches[0]->Sync(); - BOOST_CHECK(base.HaveCoin(outp)); - BOOST_CHECK(all_caches[0]->HaveCoin(outp)); - BOOST_CHECK(!all_caches[1]->HaveCoinInCache(outp)); + CHECK(base.HaveCoin(outp)); + CHECK(all_caches[0]->HaveCoin(outp)); + CHECK(!all_caches[1]->HaveCoinInCache(outp)); - BOOST_CHECK(all_caches[1]->SpendCoin(outp)); + CHECK(all_caches[1]->SpendCoin(outp)); flush_all(/*erase=*/ false); - BOOST_CHECK(!base.HaveCoin(outp)); - BOOST_CHECK(!all_caches[0]->HaveCoin(outp)); - BOOST_CHECK(!all_caches[1]->HaveCoin(outp)); + CHECK(!base.HaveCoin(outp)); + CHECK(!all_caches[0]->HaveCoin(outp)); + CHECK(!all_caches[1]->HaveCoin(outp)); flush_all(/*erase=*/ true); // Erase all cache content. @@ -1022,29 +1020,29 @@ void TestFlushBehavior( outp = COutPoint(txid, 0); coin = MakeCoin(); CAmount coin_val = coin.out.nValue; - BOOST_CHECK(!base.HaveCoin(outp)); - BOOST_CHECK(!all_caches[0]->HaveCoin(outp)); - BOOST_CHECK(!all_caches[1]->HaveCoin(outp)); + CHECK(!base.HaveCoin(outp)); + CHECK(!all_caches[0]->HaveCoin(outp)); + CHECK(!all_caches[1]->HaveCoin(outp)); // Add and spend from same cache without flushing. all_caches[0]->AddCoin(outp, std::move(coin), false); // Coin should be FRESH in the cache. - BOOST_CHECK_EQUAL(GetCoinsMapEntry(all_caches[0]->map(), outp), CoinEntry(coin_val, CoinEntry::State::DIRTY_FRESH)); + CHECK(GetCoinsMapEntry(all_caches[0]->map(), outp) == CoinEntry(coin_val, CoinEntry::State::DIRTY_FRESH)); // Base shouldn't have seen coin. - BOOST_CHECK(!base.HaveCoin(outp)); + CHECK(!base.HaveCoin(outp)); - BOOST_CHECK(all_caches[0]->SpendCoin(outp)); + CHECK(all_caches[0]->SpendCoin(outp)); all_caches[0]->Sync(); // Ensure there is no sign of the coin after spend/flush. - BOOST_CHECK(!GetCoinsMapEntry(all_caches[0]->map(), outp)); - BOOST_CHECK(!all_caches[0]->HaveCoinInCache(outp)); - BOOST_CHECK(!base.HaveCoin(outp)); + CHECK(!GetCoinsMapEntry(all_caches[0]->map(), outp)); + CHECK(!all_caches[0]->HaveCoinInCache(outp)); + CHECK(!base.HaveCoin(outp)); } }; // struct FlushTest -BOOST_FIXTURE_TEST_CASE(ccoins_flush_behavior, FlushTest) +FIXTURE_TEST_CASE("ccoins_flush_behavior", FlushTest) { // Create two in-memory caches atop a leveldb view. CCoinsViewDB base{{.path = "test", .cache_bytes = 8_MiB, .memory_only = true}, {}}; @@ -1058,14 +1056,14 @@ BOOST_FIXTURE_TEST_CASE(ccoins_flush_behavior, FlushTest) } } -BOOST_AUTO_TEST_CASE(coins_resource_is_used) +FIXTURE_TEST_CASE("coins_resource_is_used", BasicTestingSetup) { CCoinsMapMemoryResource resource; PoolResourceTester::CheckAllDataAccountedFor(resource); { CCoinsMap map{0, CCoinsMap::hasher{}, CCoinsMap::key_equal{}, &resource}; - BOOST_TEST(memusage::DynamicUsage(map) >= resource.ChunkSizeBytes()); + CHECK(memusage::DynamicUsage(map) >= resource.ChunkSizeBytes()); map.reserve(1000); @@ -1077,13 +1075,13 @@ BOOST_AUTO_TEST_CASE(coins_resource_is_used) out_point.n = i; map[out_point]; } - BOOST_TEST(usage_before == memusage::DynamicUsage(map)); + CHECK(usage_before == memusage::DynamicUsage(map)); } PoolResourceTester::CheckAllDataAccountedFor(resource); } -BOOST_AUTO_TEST_CASE(ccoins_addcoin_exception_keeps_usage_balanced) +FIXTURE_TEST_CASE("ccoins_addcoin_exception_keeps_usage_balanced", BasicTestingSetup) { CCoinsViewCacheTest cache{&CoinsViewEmpty::Get()}; @@ -1094,13 +1092,13 @@ BOOST_AUTO_TEST_CASE(ccoins_addcoin_exception_keeps_usage_balanced) cache.SelfTest(); const Coin coin2{CTxOut{m_rng.randrange(20), CScript{} << m_rng.randbytes(CScriptBase::STATIC_SIZE + 2)}, 2, false}; - BOOST_CHECK_THROW(cache.AddCoin(outpoint, Coin{coin2}, /*possible_overwrite=*/false), std::logic_error); + CHECK_THROWS_AS(cache.AddCoin(outpoint, Coin{coin2}, /*possible_overwrite=*/false), std::logic_error); cache.SelfTest(); - BOOST_CHECK(cache.AccessCoin(outpoint) == coin1); + CHECK((cache.AccessCoin(outpoint) == coin1)); } -BOOST_AUTO_TEST_CASE(ccoins_emplace_duplicate_keeps_usage_balanced) +FIXTURE_TEST_CASE("ccoins_emplace_duplicate_keeps_usage_balanced", BasicTestingSetup) { CCoinsViewCacheTest cache{&CoinsViewEmpty::Get()}; @@ -1114,10 +1112,10 @@ BOOST_AUTO_TEST_CASE(ccoins_emplace_duplicate_keeps_usage_balanced) cache.EmplaceCoinInternalDANGER(COutPoint{outpoint}, Coin{coin2}); cache.SelfTest(); - BOOST_CHECK(cache.AccessCoin(outpoint) == coin1); + CHECK((cache.AccessCoin(outpoint) == coin1)); } -BOOST_AUTO_TEST_CASE(ccoins_reset_guard) +FIXTURE_TEST_CASE("ccoins_reset_guard", BasicTestingSetup) { CCoinsViewTest root{m_rng}; CCoinsViewCache root_cache{&root}; @@ -1131,44 +1129,44 @@ BOOST_AUTO_TEST_CASE(ccoins_reset_guard) const Coin coin{CTxOut{m_rng.randrange(10), CScript{} << m_rng.randbytes(CScriptBase::STATIC_SIZE + 1)}, 1, false}; cache.EmplaceCoinInternalDANGER(COutPoint{outpoint}, Coin{coin}); - BOOST_CHECK_EQUAL(cache.GetDirtyCount(), 1U); + CHECK(cache.GetDirtyCount() == 1U); uint256 cache_best_block{m_rng.rand256()}; cache.SetBestBlock(cache_best_block); { const auto reset_guard{cache.CreateResetGuard()}; - BOOST_CHECK(cache.AccessCoin(outpoint) == coin); - BOOST_CHECK(!cache.AccessCoin(outpoint).IsSpent()); - BOOST_CHECK_EQUAL(cache.GetCacheSize(), 1); - BOOST_CHECK_EQUAL(cache.GetDirtyCount(), 1); - BOOST_CHECK_EQUAL(cache.GetBestBlock(), cache_best_block); - BOOST_CHECK(!root_cache.HaveCoinInCache(outpoint)); + CHECK((cache.AccessCoin(outpoint) == coin)); + CHECK(!cache.AccessCoin(outpoint).IsSpent()); + CHECK(cache.GetCacheSize() == 1U); + CHECK(cache.GetDirtyCount() == 1U); + CHECK(cache.GetBestBlock() == cache_best_block); + CHECK(!root_cache.HaveCoinInCache(outpoint)); } - BOOST_CHECK(cache.AccessCoin(outpoint).IsSpent()); - BOOST_CHECK_EQUAL(cache.GetCacheSize(), 0); - BOOST_CHECK_EQUAL(cache.GetDirtyCount(), 0); - BOOST_CHECK_EQUAL(cache.GetBestBlock(), base_best_block); - BOOST_CHECK(!root_cache.HaveCoinInCache(outpoint)); + CHECK(cache.AccessCoin(outpoint).IsSpent()); + CHECK(cache.GetCacheSize() == 0U); + CHECK(cache.GetDirtyCount() == 0U); + CHECK(cache.GetBestBlock() == base_best_block); + CHECK(!root_cache.HaveCoinInCache(outpoint)); // Using a reset guard again is idempotent { const auto reset_guard{cache.CreateResetGuard()}; } - BOOST_CHECK(cache.AccessCoin(outpoint).IsSpent()); - BOOST_CHECK_EQUAL(cache.GetCacheSize(), 0); - BOOST_CHECK_EQUAL(cache.GetDirtyCount(), 0U); - BOOST_CHECK_EQUAL(cache.GetBestBlock(), base_best_block); - BOOST_CHECK(!root_cache.HaveCoinInCache(outpoint)); + CHECK(cache.AccessCoin(outpoint).IsSpent()); + CHECK(cache.GetCacheSize() == 0U); + CHECK(cache.GetDirtyCount() == 0U); + CHECK(cache.GetBestBlock() == base_best_block); + CHECK(!root_cache.HaveCoinInCache(outpoint)); // Flush should be a no-op after reset. cache.Flush(); - BOOST_CHECK_EQUAL(cache.GetDirtyCount(), 0U); + CHECK(cache.GetDirtyCount() == 0U); } -BOOST_AUTO_TEST_CASE(ccoins_peekcoin) +FIXTURE_TEST_CASE("ccoins_peekcoin", BasicTestingSetup) { CCoinsViewTest base{m_rng}; @@ -1184,9 +1182,9 @@ BOOST_AUTO_TEST_CASE(ccoins_peekcoin) // Verify PeekCoin can read through the cache stack without mutating the intermediate cache. CCoinsViewCacheTest main_cache{&base}; const auto fetched{main_cache.PeekCoin(outpoint)}; - BOOST_CHECK(fetched.has_value()); - BOOST_CHECK(*fetched == coin); - BOOST_CHECK(!main_cache.HaveCoinInCache(outpoint)); + CHECK(fetched.has_value()); + CHECK((*fetched == coin)); + CHECK(!main_cache.HaveCoinInCache(outpoint)); } -BOOST_AUTO_TEST_SUITE_END() +TEST_SUITE_END() diff --git a/src/test/coinscachepair_tests.cpp b/src/test/coinscachepair_tests.cpp index 0c208e93dfb4..4e1a369a5389 100644 --- a/src/test/coinscachepair_tests.cpp +++ b/src/test/coinscachepair_tests.cpp @@ -4,11 +4,11 @@ #include -#include +#include #include -BOOST_AUTO_TEST_SUITE(coinscachepair_tests) +TEST_SUITE_BEGIN("coinscachepair_tests") static constexpr auto NUM_NODES{4}; @@ -21,19 +21,20 @@ std::list CreatePairs(CoinsCachePair& sentinel) auto node{std::prev(nodes.end())}; CCoinsCacheEntry::SetDirty(*node, sentinel); - BOOST_CHECK(node->second.IsDirty() && !node->second.IsFresh()); - BOOST_CHECK_EQUAL(node->second.Next(), &sentinel); - BOOST_CHECK_EQUAL(sentinel.second.Prev(), &(*node)); + CHECK(node->second.IsDirty()); + CHECK(!node->second.IsFresh()); + CHECK((node->second.Next() == &sentinel)); + CHECK((sentinel.second.Prev() == &(*node))); if (i > 0) { - BOOST_CHECK_EQUAL(std::prev(node)->second.Next(), &(*node)); - BOOST_CHECK_EQUAL(node->second.Prev(), &(*std::prev(node))); + CHECK((std::prev(node)->second.Next() == &(*node))); + CHECK((node->second.Prev() == &(*std::prev(node)))); } } return nodes; } -BOOST_AUTO_TEST_CASE(linked_list_iteration) +TEST_CASE("linked_list_iteration") { CoinsCachePair sentinel; sentinel.second.SelfRef(sentinel); @@ -42,32 +43,33 @@ BOOST_AUTO_TEST_CASE(linked_list_iteration) // Check iterating through pairs is identical to iterating through a list auto node{sentinel.second.Next()}; for (const auto& expected : nodes) { - BOOST_CHECK_EQUAL(&expected, node); + CHECK((&expected == node)); node = node->second.Next(); } - BOOST_CHECK_EQUAL(node, &sentinel); + CHECK((node == &sentinel)); // Check iterating through pairs is identical to iterating through a list // Clear the state during iteration node = sentinel.second.Next(); for (const auto& expected : nodes) { - BOOST_CHECK_EQUAL(&expected, node); + CHECK((&expected == node)); auto next = node->second.Next(); node->second.SetClean(); node = next; } - BOOST_CHECK_EQUAL(node, &sentinel); + CHECK((node == &sentinel)); // Check that sentinel's next and prev are itself - BOOST_CHECK_EQUAL(sentinel.second.Next(), &sentinel); - BOOST_CHECK_EQUAL(sentinel.second.Prev(), &sentinel); + CHECK((sentinel.second.Next() == &sentinel)); + CHECK((sentinel.second.Prev() == &sentinel)); // Delete the nodes from the list to make sure there are no dangling pointers for (auto it{nodes.begin()}; it != nodes.end(); it = nodes.erase(it)) { - BOOST_CHECK(!it->second.IsDirty() && !it->second.IsFresh()); + CHECK(!it->second.IsDirty()); + CHECK(!it->second.IsFresh()); } } -BOOST_AUTO_TEST_CASE(linked_list_iterate_erase) +TEST_CASE("linked_list_iterate_erase") { CoinsCachePair sentinel; sentinel.second.SelfRef(sentinel); @@ -78,17 +80,17 @@ BOOST_AUTO_TEST_CASE(linked_list_iterate_erase) // The state will be cleared by the CCoinsCacheEntry's destructor auto node{sentinel.second.Next()}; for (auto expected{nodes.begin()}; expected != nodes.end(); expected = nodes.erase(expected)) { - BOOST_CHECK_EQUAL(&(*expected), node); + CHECK((&(*expected) == node)); node = node->second.Next(); } - BOOST_CHECK_EQUAL(node, &sentinel); + CHECK((node == &sentinel)); // Check that sentinel's next and prev are itself - BOOST_CHECK_EQUAL(sentinel.second.Next(), &sentinel); - BOOST_CHECK_EQUAL(sentinel.second.Prev(), &sentinel); + CHECK((sentinel.second.Next() == &sentinel)); + CHECK((sentinel.second.Prev() == &sentinel)); } -BOOST_AUTO_TEST_CASE(linked_list_random_deletion) +TEST_CASE("linked_list_random_deletion") { CoinsCachePair sentinel; sentinel.second.SelfRef(sentinel); @@ -105,41 +107,45 @@ BOOST_AUTO_TEST_CASE(linked_list_random_deletion) nodes.erase(n2); // Check that n1 now points to n3, and n3 still points to n4 // Also check that state was not altered - BOOST_CHECK(n1->second.IsDirty() && !n1->second.IsFresh()); - BOOST_CHECK_EQUAL(n1->second.Next(), &(*n3)); - BOOST_CHECK(n3->second.IsDirty() && !n3->second.IsFresh()); - BOOST_CHECK_EQUAL(n3->second.Next(), &(*n4)); - BOOST_CHECK_EQUAL(n3->second.Prev(), &(*n1)); + CHECK(n1->second.IsDirty()); + CHECK(!n1->second.IsFresh()); + CHECK((n1->second.Next() == &(*n3))); + CHECK(n3->second.IsDirty()); + CHECK(!n3->second.IsFresh()); + CHECK((n3->second.Next() == &(*n4))); + CHECK((n3->second.Prev() == &(*n1))); // Delete n1 // sentinel->n3->n4->sentinel nodes.erase(n1); // Check that sentinel now points to n3, and n3 still points to n4 // Also check that state was not altered - BOOST_CHECK(n3->second.IsDirty() && !n3->second.IsFresh()); - BOOST_CHECK_EQUAL(sentinel.second.Next(), &(*n3)); - BOOST_CHECK_EQUAL(n3->second.Next(), &(*n4)); - BOOST_CHECK_EQUAL(n3->second.Prev(), &sentinel); + CHECK(n3->second.IsDirty()); + CHECK(!n3->second.IsFresh()); + CHECK((sentinel.second.Next() == &(*n3))); + CHECK((n3->second.Next() == &(*n4))); + CHECK((n3->second.Prev() == &sentinel)); // Delete n4 // sentinel->n3->sentinel nodes.erase(n4); // Check that sentinel still points to n3, and n3 points to sentinel // Also check that state was not altered - BOOST_CHECK(n3->second.IsDirty() && !n3->second.IsFresh()); - BOOST_CHECK_EQUAL(sentinel.second.Next(), &(*n3)); - BOOST_CHECK_EQUAL(n3->second.Next(), &sentinel); - BOOST_CHECK_EQUAL(sentinel.second.Prev(), &(*n3)); + CHECK(n3->second.IsDirty()); + CHECK(!n3->second.IsFresh()); + CHECK((sentinel.second.Next() == &(*n3))); + CHECK((n3->second.Next() == &sentinel)); + CHECK((sentinel.second.Prev() == &(*n3))); // Delete n3 // sentinel->sentinel nodes.erase(n3); // Check that sentinel's next and prev are itself - BOOST_CHECK_EQUAL(sentinel.second.Next(), &sentinel); - BOOST_CHECK_EQUAL(sentinel.second.Prev(), &sentinel); + CHECK((sentinel.second.Next() == &sentinel)); + CHECK((sentinel.second.Prev() == &sentinel)); } -BOOST_AUTO_TEST_CASE(linked_list_set_state) +TEST_CASE("linked_list_set_state") { CoinsCachePair sentinel; sentinel.second.SelfRef(sentinel); @@ -148,51 +154,57 @@ BOOST_AUTO_TEST_CASE(linked_list_set_state) // Check that setting DIRTY inserts it into linked list and sets state CCoinsCacheEntry::SetDirty(n1, sentinel); - BOOST_CHECK(n1.second.IsDirty() && !n1.second.IsFresh()); - BOOST_CHECK_EQUAL(n1.second.Next(), &sentinel); - BOOST_CHECK_EQUAL(n1.second.Prev(), &sentinel); - BOOST_CHECK_EQUAL(sentinel.second.Next(), &n1); - BOOST_CHECK_EQUAL(sentinel.second.Prev(), &n1); + CHECK(n1.second.IsDirty()); + CHECK(!n1.second.IsFresh()); + CHECK((n1.second.Next() == &sentinel)); + CHECK((n1.second.Prev() == &sentinel)); + CHECK((sentinel.second.Next() == &n1)); + CHECK((sentinel.second.Prev() == &n1)); // Check that setting FRESH on new node inserts it after n1 CCoinsCacheEntry::SetFresh(n2, sentinel); - BOOST_CHECK(n2.second.IsFresh() && !n2.second.IsDirty()); - BOOST_CHECK_EQUAL(n2.second.Next(), &sentinel); - BOOST_CHECK_EQUAL(n2.second.Prev(), &n1); - BOOST_CHECK_EQUAL(n1.second.Next(), &n2); - BOOST_CHECK_EQUAL(sentinel.second.Prev(), &n2); + CHECK(n2.second.IsFresh()); + CHECK(!n2.second.IsDirty()); + CHECK((n2.second.Next() == &sentinel)); + CHECK((n2.second.Prev() == &n1)); + CHECK((n1.second.Next() == &n2)); + CHECK((sentinel.second.Prev() == &n2)); // Check that we can set extra state, but they don't change our position CCoinsCacheEntry::SetFresh(n1, sentinel); - BOOST_CHECK(n1.second.IsDirty() && n1.second.IsFresh()); - BOOST_CHECK_EQUAL(n1.second.Next(), &n2); - BOOST_CHECK_EQUAL(n1.second.Prev(), &sentinel); - BOOST_CHECK_EQUAL(sentinel.second.Next(), &n1); - BOOST_CHECK_EQUAL(n2.second.Prev(), &n1); + CHECK(n1.second.IsDirty()); + CHECK(n1.second.IsFresh()); + CHECK((n1.second.Next() == &n2)); + CHECK((n1.second.Prev() == &sentinel)); + CHECK((sentinel.second.Next() == &n1)); + CHECK((n2.second.Prev() == &n1)); // Check that we can clear state then re-set it n1.second.SetClean(); - BOOST_CHECK(!n1.second.IsDirty() && !n1.second.IsFresh()); - BOOST_CHECK_EQUAL(sentinel.second.Next(), &n2); - BOOST_CHECK_EQUAL(sentinel.second.Prev(), &n2); - BOOST_CHECK_EQUAL(n2.second.Next(), &sentinel); - BOOST_CHECK_EQUAL(n2.second.Prev(), &sentinel); + CHECK(!n1.second.IsDirty()); + CHECK(!n1.second.IsFresh()); + CHECK((sentinel.second.Next() == &n2)); + CHECK((sentinel.second.Prev() == &n2)); + CHECK((n2.second.Next() == &sentinel)); + CHECK((n2.second.Prev() == &sentinel)); // Calling `SetClean` a second time has no effect n1.second.SetClean(); - BOOST_CHECK(!n1.second.IsDirty() && !n1.second.IsFresh()); - BOOST_CHECK_EQUAL(sentinel.second.Next(), &n2); - BOOST_CHECK_EQUAL(sentinel.second.Prev(), &n2); - BOOST_CHECK_EQUAL(n2.second.Next(), &sentinel); - BOOST_CHECK_EQUAL(n2.second.Prev(), &sentinel); + CHECK(!n1.second.IsDirty()); + CHECK(!n1.second.IsFresh()); + CHECK((sentinel.second.Next() == &n2)); + CHECK((sentinel.second.Prev() == &n2)); + CHECK((n2.second.Next() == &sentinel)); + CHECK((n2.second.Prev() == &sentinel)); // Adding DIRTY re-inserts it after n2 CCoinsCacheEntry::SetDirty(n1, sentinel); - BOOST_CHECK(n1.second.IsDirty() && !n1.second.IsFresh()); - BOOST_CHECK_EQUAL(n2.second.Next(), &n1); - BOOST_CHECK_EQUAL(n1.second.Prev(), &n2); - BOOST_CHECK_EQUAL(n1.second.Next(), &sentinel); - BOOST_CHECK_EQUAL(sentinel.second.Prev(), &n1); + CHECK(n1.second.IsDirty()); + CHECK(!n1.second.IsFresh()); + CHECK((n2.second.Next() == &n1)); + CHECK((n1.second.Prev() == &n2)); + CHECK((n1.second.Next() == &sentinel)); + CHECK((sentinel.second.Prev() == &n1)); } -BOOST_AUTO_TEST_SUITE_END() +TEST_SUITE_END() diff --git a/src/test/coinsviewoverlay_tests.cpp b/src/test/coinsviewoverlay_tests.cpp index 6b20b31211a6..07679e6200e5 100644 --- a/src/test/coinsviewoverlay_tests.cpp +++ b/src/test/coinsviewoverlay_tests.cpp @@ -11,13 +11,13 @@ #include #include -#include +#include #include #include #include -BOOST_AUTO_TEST_SUITE(coinsviewoverlay_tests) +TEST_SUITE_BEGIN("coinsviewoverlay_tests") namespace { @@ -61,24 +61,24 @@ void CheckCache(const CBlock& block, const CCoinsViewCache& cache) for (const auto& tx : block.vtx) { if (tx->IsCoinBase()) { - BOOST_CHECK(!cache.HaveCoinInCache(tx->vin[0].prevout)); + CHECK(!cache.HaveCoinInCache(tx->vin[0].prevout)); } else { for (const auto& in : tx->vin) { const auto& outpoint{in.prevout}; const auto& first{cache.AccessCoin(outpoint)}; const auto& second{cache.AccessCoin(outpoint)}; - BOOST_CHECK_EQUAL(&first, &second); + CHECK((&first == &second)); ++counter; - BOOST_CHECK(cache.HaveCoinInCache(outpoint)); + CHECK(cache.HaveCoinInCache(outpoint)); } } } - BOOST_CHECK_EQUAL(cache.GetCacheSize(), counter); + CHECK(cache.GetCacheSize() == counter); } } // namespace -BOOST_AUTO_TEST_CASE(fetch_inputs_from_db) +TEST_CASE("fetch_inputs_from_db") { const auto block{CreateBlock()}; CCoinsViewDB db{{.path = "", .cache_bytes = 1_MiB, .memory_only = true}, {}}; @@ -87,25 +87,25 @@ BOOST_AUTO_TEST_CASE(fetch_inputs_from_db) CoinsViewOverlay view{&main_cache}; const auto& outpoint{block.vtx[1]->vin[0].prevout}; - BOOST_CHECK(view.HaveCoin(outpoint)); - BOOST_CHECK(view.GetCoin(outpoint).has_value()); - BOOST_CHECK(!main_cache.HaveCoinInCache(outpoint)); + CHECK(view.HaveCoin(outpoint)); + CHECK(view.GetCoin(outpoint).has_value()); + CHECK(!main_cache.HaveCoinInCache(outpoint)); CheckCache(block, view); // Check that no coins have been moved up to main cache from db for (const auto& tx : block.vtx) { for (const auto& in : tx->vin) { - BOOST_CHECK(!main_cache.HaveCoinInCache(in.prevout)); + CHECK(!main_cache.HaveCoinInCache(in.prevout)); } } view.SetBestBlock(uint256::ONE); - BOOST_CHECK(view.SpendCoin(outpoint)); + CHECK(view.SpendCoin(outpoint)); view.Flush(); - BOOST_CHECK(!main_cache.PeekCoin(outpoint).has_value()); + CHECK(!main_cache.PeekCoin(outpoint).has_value()); } -BOOST_AUTO_TEST_CASE(fetch_inputs_from_cache) +TEST_CASE("fetch_inputs_from_cache") { const auto block{CreateBlock()}; CCoinsViewDB db{{.path = "", .cache_bytes = 1_MiB, .memory_only = true}, {}}; @@ -116,14 +116,14 @@ BOOST_AUTO_TEST_CASE(fetch_inputs_from_cache) const auto& outpoint{block.vtx[1]->vin[0].prevout}; view.SetBestBlock(uint256::ONE); - BOOST_CHECK(view.SpendCoin(outpoint)); + CHECK(view.SpendCoin(outpoint)); view.Flush(); - BOOST_CHECK(!main_cache.PeekCoin(outpoint).has_value()); + CHECK(!main_cache.PeekCoin(outpoint).has_value()); } // Test for the case where a block spends coins that are spent in the cache, but // the spentness has not been flushed to the db. -BOOST_AUTO_TEST_CASE(fetch_no_double_spend) +TEST_CASE("fetch_no_double_spend") { const auto block{CreateBlock()}; CCoinsViewDB db{{.path = "", .cache_bytes = 1_MiB, .memory_only = true}, {}}; @@ -135,16 +135,16 @@ BOOST_AUTO_TEST_CASE(fetch_no_double_spend) for (const auto& tx : block.vtx) { for (const auto& in : tx->vin) { const auto& c{view.AccessCoin(in.prevout)}; - BOOST_CHECK(c.IsSpent()); - BOOST_CHECK(!view.HaveCoin(in.prevout)); - BOOST_CHECK(!view.GetCoin(in.prevout)); + CHECK(c.IsSpent()); + CHECK(!view.HaveCoin(in.prevout)); + CHECK(!view.GetCoin(in.prevout)); } } // Coins are not added to the view, even though they exist unspent in the parent db - BOOST_CHECK_EQUAL(view.GetCacheSize(), 0); + CHECK(view.GetCacheSize() == 0U); } -BOOST_AUTO_TEST_CASE(fetch_no_inputs) +TEST_CASE("fetch_no_inputs") { const auto block{CreateBlock()}; CCoinsViewDB db{{.path = "", .cache_bytes = 1_MiB, .memory_only = true}, {}}; @@ -153,13 +153,13 @@ BOOST_AUTO_TEST_CASE(fetch_no_inputs) for (const auto& tx : block.vtx) { for (const auto& in : tx->vin) { const auto& c{view.AccessCoin(in.prevout)}; - BOOST_CHECK(c.IsSpent()); - BOOST_CHECK(!view.HaveCoin(in.prevout)); - BOOST_CHECK(!view.GetCoin(in.prevout)); + CHECK(c.IsSpent()); + CHECK(!view.HaveCoin(in.prevout)); + CHECK(!view.GetCoin(in.prevout)); } } - BOOST_CHECK_EQUAL(view.GetCacheSize(), 0); + CHECK(view.GetCacheSize() == 0U); } -BOOST_AUTO_TEST_SUITE_END() +TEST_SUITE_END() diff --git a/src/test/common_url_tests.cpp b/src/test/common_url_tests.cpp index 4827c96528d7..3c8dab3a13ed 100644 --- a/src/test/common_url_tests.cpp +++ b/src/test/common_url_tests.cpp @@ -6,67 +6,65 @@ #include -#include - -BOOST_AUTO_TEST_SUITE(common_url_tests) - -BOOST_AUTO_TEST_CASE(encode_decode_test) { - BOOST_CHECK_EQUAL(UrlDecode("Hello"), "Hello"); - BOOST_CHECK_EQUAL(UrlDecode("99"), "99"); - BOOST_CHECK_EQUAL(UrlDecode(""), ""); - BOOST_CHECK_EQUAL(UrlDecode("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789-.~_"), - "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789-.~_"); - BOOST_CHECK_EQUAL(UrlDecode("%20"), " "); - BOOST_CHECK_EQUAL(UrlDecode("%FF%F0%E0"), "\xff\xf0\xe0"); - BOOST_CHECK_EQUAL(UrlDecode("%01%19"), "\x01\x19"); - BOOST_CHECK_EQUAL(UrlDecode("http%3A%2F%2Fwww.ietf.org%2Frfc%2Frfc3986.txt"), - "http://www.ietf.org/rfc/rfc3986.txt"); - BOOST_CHECK_EQUAL(UrlDecode("1%2B2%3D3"), "1+2=3"); +#include + +TEST_SUITE_BEGIN("common_url_tests") + +TEST_CASE("encode_decode_test") { + CHECK(UrlDecode("Hello") == "Hello"); + CHECK(UrlDecode("99") == "99"); + CHECK(UrlDecode("") == ""); + CHECK(UrlDecode("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789-.~_") == "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789-.~_"); + CHECK(UrlDecode("%20") == " "); + CHECK(UrlDecode("%FF%F0%E0") == "\xff\xf0\xe0"); + CHECK(UrlDecode("%01%19") == "\x01\x19"); + CHECK(UrlDecode("http%3A%2F%2Fwww.ietf.org%2Frfc%2Frfc3986.txt") == "http://www.ietf.org/rfc/rfc3986.txt"); + CHECK(UrlDecode("1%2B2%3D3") == "1+2=3"); } -BOOST_AUTO_TEST_CASE(decode_malformed_test) { - BOOST_CHECK_EQUAL(UrlDecode("%%xhello th+ere \xff"), "%%xhello th+ere \xff"); +TEST_CASE("decode_malformed_test") { + CHECK(UrlDecode("%%xhello th+ere \xff") == "%%xhello th+ere \xff"); - BOOST_CHECK_EQUAL(UrlDecode("%"), "%"); - BOOST_CHECK_EQUAL(UrlDecode("%%"), "%%"); - BOOST_CHECK_EQUAL(UrlDecode("%%%"), "%%%"); - BOOST_CHECK_EQUAL(UrlDecode("%%%%"), "%%%%"); + CHECK(UrlDecode("%") == "%"); + CHECK(UrlDecode("%%") == "%%"); + CHECK(UrlDecode("%%%") == "%%%"); + CHECK(UrlDecode("%%%%") == "%%%%"); - BOOST_CHECK_EQUAL(UrlDecode("+"), "+"); - BOOST_CHECK_EQUAL(UrlDecode("++"), "++"); + CHECK(UrlDecode("+") == "+"); + CHECK(UrlDecode("++") == "++"); - BOOST_CHECK_EQUAL(UrlDecode("?"), "?"); - BOOST_CHECK_EQUAL(UrlDecode("??"), "??"); + CHECK(UrlDecode("?") == "?"); + CHECK(UrlDecode("??") == "??"); - BOOST_CHECK_EQUAL(UrlDecode("%G1"), "%G1"); - BOOST_CHECK_EQUAL(UrlDecode("%2"), "%2"); - BOOST_CHECK_EQUAL(UrlDecode("%ZX"), "%ZX"); + CHECK(UrlDecode("%G1") == "%G1"); + CHECK(UrlDecode("%2") == "%2"); + CHECK(UrlDecode("%ZX") == "%ZX"); - BOOST_CHECK_EQUAL(UrlDecode("valid%20string%G1"), "valid string%G1"); - BOOST_CHECK_EQUAL(UrlDecode("%20invalid%ZX"), " invalid%ZX"); - BOOST_CHECK_EQUAL(UrlDecode("%20%G1%ZX"), " %G1%ZX"); + CHECK(UrlDecode("valid%20string%G1") == "valid string%G1"); + CHECK(UrlDecode("%20invalid%ZX") == " invalid%ZX"); + CHECK(UrlDecode("%20%G1%ZX") == " %G1%ZX"); - BOOST_CHECK_EQUAL(UrlDecode("%1 "), "%1 "); - BOOST_CHECK_EQUAL(UrlDecode("% 9"), "% 9"); - BOOST_CHECK_EQUAL(UrlDecode(" %Z "), " %Z "); - BOOST_CHECK_EQUAL(UrlDecode(" % X"), " % X"); + CHECK(UrlDecode("%1 ") == "%1 "); + CHECK(UrlDecode("% 9") == "% 9"); + CHECK(UrlDecode(" %Z ") == " %Z "); + CHECK(UrlDecode(" % X") == " % X"); - BOOST_CHECK_EQUAL(UrlDecode("%%ffg"), "%\xffg"); - BOOST_CHECK_EQUAL(UrlDecode("%fg"), "%fg"); + CHECK(UrlDecode("%%ffg") == "%\xffg"); + CHECK(UrlDecode("%fg") == "%fg"); - BOOST_CHECK_EQUAL(UrlDecode("%-1"), "%-1"); - BOOST_CHECK_EQUAL(UrlDecode("%1-"), "%1-"); + CHECK(UrlDecode("%-1") == "%-1"); + CHECK(UrlDecode("%1-") == "%1-"); } -BOOST_AUTO_TEST_CASE(decode_lowercase_hex_test) { - BOOST_CHECK_EQUAL(UrlDecode("%f0%a0%b0"), "\xf0\xa0\xb0"); +TEST_CASE("decode_lowercase_hex_test") { + CHECK(UrlDecode("%f0%a0%b0") == "\xf0\xa0\xb0"); } -BOOST_AUTO_TEST_CASE(decode_internal_nulls_test) { +TEST_CASE("decode_internal_nulls_test") { std::string result1{"\0\0x\0\0", 5}; - BOOST_CHECK_EQUAL(UrlDecode("%00%00x%00%00"), result1); + CHECK(UrlDecode("%00%00x%00%00") == result1); std::string result2{"abc\0\0", 5}; - BOOST_CHECK_EQUAL(UrlDecode("abc%00%00"), result2); + CHECK(UrlDecode("abc%00%00") == result2); } -BOOST_AUTO_TEST_SUITE_END() +TEST_SUITE_END() diff --git a/src/test/compress_tests.cpp b/src/test/compress_tests.cpp index 7fefa467448a..edecf9772a75 100644 --- a/src/test/compress_tests.cpp +++ b/src/test/compress_tests.cpp @@ -9,7 +9,7 @@ #include -#include +#include // amounts 0.00000001 .. 0.00100000 #define NUM_MULTIPLES_UNIT 100000 @@ -23,7 +23,7 @@ // amounts 50 .. 21000000 #define NUM_MULTIPLES_50BTC 420000 -BOOST_FIXTURE_TEST_SUITE(compress_tests, BasicTestingSetup) +TEST_SUITE_BEGIN("compress_tests") bool static TestEncode(uint64_t in) { return in == DecompressAmount(CompressAmount(in)); @@ -38,101 +38,101 @@ bool static TestPair(uint64_t dec, uint64_t enc) { DecompressAmount(enc) == dec; } -BOOST_AUTO_TEST_CASE(compress_amounts) +FIXTURE_TEST_CASE("compress_amounts", BasicTestingSetup) { - BOOST_CHECK(TestPair( 0, 0x0)); - BOOST_CHECK(TestPair( 1, 0x1)); - BOOST_CHECK(TestPair( CENT, 0x7)); - BOOST_CHECK(TestPair( COIN, 0x9)); - BOOST_CHECK(TestPair( 50*COIN, 0x32)); - BOOST_CHECK(TestPair(21000000*COIN, 0x1406f40)); + CHECK(TestPair( 0, 0x0)); + CHECK(TestPair( 1, 0x1)); + CHECK(TestPair( CENT, 0x7)); + CHECK(TestPair( COIN, 0x9)); + CHECK(TestPair( 50*COIN, 0x32)); + CHECK(TestPair(21000000*COIN, 0x1406f40)); for (uint64_t i = 1; i <= NUM_MULTIPLES_UNIT; i++) - BOOST_CHECK(TestEncode(i)); + CHECK(TestEncode(i)); for (uint64_t i = 1; i <= NUM_MULTIPLES_CENT; i++) - BOOST_CHECK(TestEncode(i * CENT)); + CHECK(TestEncode(i * CENT)); for (uint64_t i = 1; i <= NUM_MULTIPLES_1BTC; i++) - BOOST_CHECK(TestEncode(i * COIN)); + CHECK(TestEncode(i * COIN)); for (uint64_t i = 1; i <= NUM_MULTIPLES_50BTC; i++) - BOOST_CHECK(TestEncode(i * 50 * COIN)); + CHECK(TestEncode(i * 50 * COIN)); for (uint64_t i = 0; i < 100000; i++) - BOOST_CHECK(TestDecode(i)); + CHECK(TestDecode(i)); } -BOOST_AUTO_TEST_CASE(compress_script_to_ckey_id) +FIXTURE_TEST_CASE("compress_script_to_ckey_id", BasicTestingSetup) { // case CKeyID CKey key = GenerateRandomKey(); CPubKey pubkey = key.GetPubKey(); CScript script = CScript() << OP_DUP << OP_HASH160 << ToByteVector(pubkey.GetID()) << OP_EQUALVERIFY << OP_CHECKSIG; - BOOST_CHECK_EQUAL(script.size(), 25U); + CHECK(script.size() == 25U); CompressedScript out; bool done = CompressScript(script, out); - BOOST_CHECK_EQUAL(done, true); + CHECK(done == true); // Check compressed script - BOOST_CHECK_EQUAL(out.size(), 21U); - BOOST_CHECK_EQUAL(out[0], 0x00); - BOOST_CHECK_EQUAL(memcmp(out.data() + 1, script.data() + 3, 20), 0); // compare the 20 relevant chars of the CKeyId in the script + CHECK(out.size() == 21U); + CHECK(out[0] == 0x00); + CHECK(memcmp(out.data() + 1, script.data() + 3, 20) == 0); // compare the 20 relevant chars of the CKeyId in the script } -BOOST_AUTO_TEST_CASE(compress_script_to_cscript_id) +FIXTURE_TEST_CASE("compress_script_to_cscript_id", BasicTestingSetup) { // case CScriptID CScript script, redeemScript; script << OP_HASH160 << ToByteVector(CScriptID(redeemScript)) << OP_EQUAL; - BOOST_CHECK_EQUAL(script.size(), 23U); + CHECK(script.size() == 23U); CompressedScript out; bool done = CompressScript(script, out); - BOOST_CHECK_EQUAL(done, true); + CHECK(done == true); // Check compressed script - BOOST_CHECK_EQUAL(out.size(), 21U); - BOOST_CHECK_EQUAL(out[0], 0x01); - BOOST_CHECK_EQUAL(memcmp(out.data() + 1, script.data() + 2, 20), 0); // compare the 20 relevant chars of the CScriptId in the script + CHECK(out.size() == 21U); + CHECK(out[0] == 0x01); + CHECK(memcmp(out.data() + 1, script.data() + 2, 20) == 0); // compare the 20 relevant chars of the CScriptId in the script } -BOOST_AUTO_TEST_CASE(compress_script_to_compressed_pubkey_id) +FIXTURE_TEST_CASE("compress_script_to_compressed_pubkey_id", BasicTestingSetup) { CKey key = GenerateRandomKey(); // case compressed PubKeyID CScript script = CScript() << ToByteVector(key.GetPubKey()) << OP_CHECKSIG; // COMPRESSED_PUBLIC_KEY_SIZE (33) - BOOST_CHECK_EQUAL(script.size(), 35U); + CHECK(script.size() == 35U); CompressedScript out; bool done = CompressScript(script, out); - BOOST_CHECK_EQUAL(done, true); + CHECK(done == true); // Check compressed script - BOOST_CHECK_EQUAL(out.size(), 33U); - BOOST_CHECK_EQUAL(memcmp(out.data(), script.data() + 1, 1), 0); - BOOST_CHECK_EQUAL(memcmp(out.data() + 1, script.data() + 2, 32), 0); // compare the 32 chars of the compressed CPubKey + CHECK(out.size() == 33U); + CHECK(memcmp(out.data(), script.data() + 1, 1) == 0); + CHECK(memcmp(out.data() + 1, script.data() + 2, 32) == 0); // compare the 32 chars of the compressed CPubKey } -BOOST_AUTO_TEST_CASE(compress_script_to_uncompressed_pubkey_id) +FIXTURE_TEST_CASE("compress_script_to_uncompressed_pubkey_id", BasicTestingSetup) { CKey key = GenerateRandomKey(/*compressed=*/false); // case uncompressed PubKeyID CScript script = CScript() << ToByteVector(key.GetPubKey()) << OP_CHECKSIG; // PUBLIC_KEY_SIZE (65) - BOOST_CHECK_EQUAL(script.size(), 67U); // 1 char code + 65 char pubkey + OP_CHECKSIG + CHECK(script.size() == 67U); // 1 char code + 65 char pubkey + OP_CHECKSIG CompressedScript out; bool done = CompressScript(script, out); - BOOST_CHECK_EQUAL(done, true); + CHECK(done == true); // Check compressed script - BOOST_CHECK_EQUAL(out.size(), 33U); - BOOST_CHECK_EQUAL(memcmp(out.data() + 1, script.data() + 2, 32), 0); // first 32 chars of CPubKey are copied into out[1:] - BOOST_CHECK_EQUAL(out[0], 0x04 | (script[65] & 0x01)); // least significant bit (lsb) of last char of pubkey is mapped into out[0] + CHECK(out.size() == 33U); + CHECK(memcmp(out.data() + 1, script.data() + 2, 32) == 0); // first 32 chars of CPubKey are copied into out[1:] + CHECK(out[0] == (0x04 | (script[65] & 0x01))); // least significant bit (lsb) of last char of pubkey is mapped into out[0] } -BOOST_AUTO_TEST_CASE(compress_p2pk_scripts_not_on_curve) +FIXTURE_TEST_CASE("compress_p2pk_scripts_not_on_curve", BasicTestingSetup) { XOnlyPubKey x_not_on_curve; do { @@ -148,11 +148,11 @@ BOOST_AUTO_TEST_CASE(compress_p2pk_scripts_not_on_curve) assert(pubkey_not_on_curve.IsValid()); assert(!pubkey_not_on_curve.IsFullyValid()); CScript script = CScript() << ToByteVector(pubkey_not_on_curve) << OP_CHECKSIG; - BOOST_CHECK_EQUAL(script.size(), 67U); + CHECK(script.size() == 67U); CompressedScript out; bool done = CompressScript(script, out); - BOOST_CHECK_EQUAL(done, false); + CHECK(done == false); // Check that compressed P2PK script with uncompressed pubkey that is not fully // valid (i.e. x coordinate of the pubkey is not on curve) can't be decompressed @@ -160,8 +160,8 @@ BOOST_AUTO_TEST_CASE(compress_p2pk_scripts_not_on_curve) for (unsigned int compression_id : {4, 5}) { CScript uncompressed_script; bool success = DecompressScript(uncompressed_script, compression_id, compressed_script); - BOOST_CHECK_EQUAL(success, false); + CHECK(success == false); } } -BOOST_AUTO_TEST_SUITE_END() +TEST_SUITE_END() diff --git a/src/test/crypto_tests.cpp b/src/test/crypto_tests.cpp index b348793bfb63..48f26aa3d62d 100644 --- a/src/test/crypto_tests.cpp +++ b/src/test/crypto_tests.cpp @@ -25,7 +25,7 @@ #include #include -#include +#include using namespace util::hex_literals; @@ -35,12 +35,12 @@ struct CryptoTest : BasicTestingSetup { template void TestVector(const Hasher &h, const In &in, const Out &out) { Out hash; - BOOST_CHECK(out.size() == h.OUTPUT_SIZE); + CHECK(out.size() == h.OUTPUT_SIZE); hash.resize(out.size()); { // Test that writing the whole input string at once works. Hasher(h).Write((const uint8_t*)in.data(), in.size()).Finalize(hash.data()); - BOOST_CHECK(hash == out); + CHECK(hash == out); } for (int i=0; i<32; i++) { // Test that writing the string broken up in random pieces works. @@ -53,11 +53,11 @@ void TestVector(const Hasher &h, const In &in, const Out &out) { if (pos > 0 && pos + 2 * out.size() > in.size() && pos < in.size()) { // Test that writing the rest at once to a copy of a hasher works. Hasher(hasher).Write((const uint8_t*)in.data() + pos, in.size() - pos).Finalize(hash.data()); - BOOST_CHECK(hash == out); + CHECK(hash == out); } } hasher.Finalize(hash.data()); - BOOST_CHECK(hash == out); + CHECK(hash == out); } } @@ -89,10 +89,10 @@ void TestAES256(const std::string &hexkey, const std::string &hexin, const std:: AES256Encrypt enc(key.data()); buf.resize(correctout.size()); enc.Encrypt(buf.data(), in.data()); - BOOST_CHECK(buf == correctout); + CHECK(buf == correctout); AES256Decrypt dec(key.data()); dec.Decrypt(buf.data(), buf.data()); - BOOST_CHECK(buf == in); + CHECK(buf == in); } void TestAES256CBC(const std::string &hexkey, const std::string &hexiv, bool pad, const std::string &hexin, const std::string &hexout) @@ -107,16 +107,16 @@ void TestAES256CBC(const std::string &hexkey, const std::string &hexiv, bool pad AES256CBCEncrypt enc(key.data(), iv.data(), pad); int size = enc.Encrypt(in.data(), in.size(), realout.data()); realout.resize(size); - BOOST_CHECK(realout.size() == correctout.size()); - BOOST_CHECK_MESSAGE(realout == correctout, HexStr(realout) + std::string(" != ") + hexout); + CHECK(realout.size() == correctout.size()); + CHECK(realout == correctout, HexStr(realout) + std::string(" != ") + hexout); // Decrypt the cipher and verify that it equals the plaintext std::vector decrypted(correctout.size()); AES256CBCDecrypt dec(key.data(), iv.data(), pad); size = dec.Decrypt(correctout.data(), correctout.size(), decrypted.data()); decrypted.resize(size); - BOOST_CHECK(decrypted.size() == in.size()); - BOOST_CHECK_MESSAGE(decrypted == in, HexStr(decrypted) + std::string(" != ") + hexin); + CHECK(decrypted.size() == in.size()); + CHECK(decrypted == in, HexStr(decrypted) + std::string(" != ") + hexin); // Encrypt and re-decrypt substrings of the plaintext and verify that they equal each-other for(std::vector::iterator i(in.begin()); i != in.end(); ++i) @@ -130,8 +130,8 @@ void TestAES256CBC(const std::string &hexkey, const std::string &hexiv, bool pad std::vector subdecrypted(subout.size()); _size = dec.Decrypt(subout.data(), subout.size(), subdecrypted.data()); subdecrypted.resize(_size); - BOOST_CHECK(decrypted.size() == in.size()); - BOOST_CHECK_MESSAGE(subdecrypted == sub, HexStr(subdecrypted) + std::string(" != ") + HexStr(sub)); + CHECK(decrypted.size() == in.size()); + CHECK(subdecrypted == sub, HexStr(subdecrypted) + std::string(" != ") + HexStr(sub)); } } } @@ -153,7 +153,7 @@ void TestChaCha20(const std::string &hex_message, const std::string &hexkey, Cha } else { rng.Keystream(outres); } - BOOST_CHECK_EQUAL(hexout, HexStr(outres)); + CHECK(hexout == HexStr(outres)); if (!hex_message.empty()) { // Manually XOR with the keystream and compare the output rng.Seek(nonce, seek); @@ -162,7 +162,7 @@ void TestChaCha20(const std::string &hex_message, const std::string &hexkey, Cha for (size_t i = 0; i != m.size(); i++) { outres[i] = m[i] ^ only_keystream[i]; } - BOOST_CHECK_EQUAL(hexout, HexStr(outres)); + CHECK(hexout == HexStr(outres)); } // Repeat 10x, but fragmented into 3 chunks, to exercise the ChaCha20 class's caching. @@ -183,14 +183,14 @@ void TestChaCha20(const std::string &hex_message, const std::string &hexkey, Cha } pos += lens[j]; } - BOOST_CHECK_EQUAL(hexout, HexStr(outres)); + CHECK(hexout == HexStr(outres)); } } void TestFSChaCha20(const std::string& hex_plaintext, const std::string& hexkey, uint32_t rekey_interval, const std::string& ciphertext_after_rotation) { auto key = ParseHex(hexkey); - BOOST_CHECK_EQUAL(FSChaCha20::KEYLEN, key.size()); + CHECK(FSChaCha20::KEYLEN == key.size()); auto plaintext = ParseHex(hex_plaintext); @@ -206,14 +206,14 @@ void TestFSChaCha20(const std::string& hex_plaintext, const std::string& hexkey, for (size_t i = 0; i < rekey_interval; i++) { fsc20.Crypt(plaintext, fsc20_output); c20.Crypt(plaintext, c20_output); - BOOST_CHECK(c20_output == fsc20_output); + CHECK(c20_output == fsc20_output); } // At the rotation interval, the outputs will no longer match fsc20.Crypt(plaintext, fsc20_output); auto c20_copy = c20; c20.Crypt(plaintext, c20_output); - BOOST_CHECK(c20_output != fsc20_output); + CHECK(c20_output != fsc20_output); std::byte new_key[FSChaCha20::KEYLEN]; c20_copy.Keystream(new_key); @@ -222,9 +222,9 @@ void TestFSChaCha20(const std::string& hex_plaintext, const std::string& hexkey, // Outputs should match again after simulating key rotation c20.Crypt(plaintext, c20_output); - BOOST_CHECK(c20_output == fsc20_output); + CHECK(c20_output == fsc20_output); - BOOST_CHECK_EQUAL(HexStr(fsc20_output), ciphertext_after_rotation); + CHECK(HexStr(fsc20_output) == ciphertext_after_rotation); } void TestPoly1305(const std::string &hexmessage, const std::string &hexkey, const std::string& hextag) @@ -233,7 +233,7 @@ void TestPoly1305(const std::string &hexmessage, const std::string &hexkey, cons auto m = ParseHex(hexmessage); std::vector tagres(Poly1305::TAGLEN); Poly1305{key}.Update(m).Finalize(tagres); - BOOST_CHECK_EQUAL(HexStr(tagres), hextag); + CHECK(HexStr(tagres) == hextag); // Test incremental interface for (int splits = 0; splits < 10; ++splits) { @@ -247,7 +247,7 @@ void TestPoly1305(const std::string &hexmessage, const std::string &hexkey, cons } tagres.assign(Poly1305::TAGLEN, std::byte{}); poly1305.Update(data).Finalize(tagres); - BOOST_CHECK_EQUAL(HexStr(tagres), hextag); + CHECK(HexStr(tagres) == hextag); } } } @@ -270,7 +270,7 @@ void TestChaCha20Poly1305(const std::string& plain_hex, const std::string& aad_h } else { aead.Encrypt(std::span{plain}.first(prefix), std::span{plain}.subspan(prefix), aad, nonce, cipher); } - BOOST_CHECK(cipher == expected_cipher); + CHECK(cipher == expected_cipher); // Decrypt. std::vector decipher(cipher.size() - AEADChaCha20Poly1305::EXPANSION); @@ -280,8 +280,8 @@ void TestChaCha20Poly1305(const std::string& plain_hex, const std::string& aad_h } else { ret = aead.Decrypt(cipher, aad, nonce, std::span{decipher}.first(prefix), std::span{decipher}.subspan(prefix)); } - BOOST_CHECK(ret); - BOOST_CHECK(decipher == plain); + CHECK(ret); + CHECK(decipher == plain); } // Test Keystream output. @@ -289,7 +289,7 @@ void TestChaCha20Poly1305(const std::string& plain_hex, const std::string& aad_h AEADChaCha20Poly1305 aead{key}; aead.Keystream(nonce, keystream); for (size_t i = 0; i < plain.size(); ++i) { - BOOST_CHECK_EQUAL(plain[i] ^ keystream[i], expected_cipher[i]); + CHECK((plain[i] ^ keystream[i]) == expected_cipher[i]); } } @@ -318,7 +318,7 @@ void TestFSChaCha20Poly1305(const std::string& plain_hex, const std::string& aad } else { enc_aead.Encrypt(std::span{plain}.first(prefix), std::span{plain}.subspan(prefix), aad, cipher); } - BOOST_CHECK(cipher == expected_cipher); + CHECK(cipher == expected_cipher); // Do msg_idx dummy decryptions to seek to the correct packet. FSChaCha20Poly1305 dec_aead{key, 224}; @@ -334,8 +334,8 @@ void TestFSChaCha20Poly1305(const std::string& plain_hex, const std::string& aad } else { ret = dec_aead.Decrypt(cipher, aad, std::span{decipher}.first(prefix), std::span{decipher}.subspan(prefix)); } - BOOST_CHECK(ret); - BOOST_CHECK(decipher == plain); + CHECK(ret); + CHECK(decipher == plain); } } @@ -352,12 +352,11 @@ void TestHKDF_SHA256_32(const std::string &ikm_hex, const std::string &salt_hex, CHKDF_HMAC_SHA256_L32 hkdf32(initial_key_material.data(), initial_key_material.size(), salt_stringified); unsigned char out[32]; hkdf32.Expand32(info_stringified, out); - BOOST_CHECK(HexStr(out) == okm_check_hex); + CHECK(HexStr(out) == okm_check_hex); } void TestSHA3_256(const std::string& input, const std::string& output); }; // struct CryptoTests -} // namespace crypto_tests static std::string LongTestString() { @@ -374,9 +373,9 @@ static std::string LongTestString() const std::string test1 = LongTestString(); -BOOST_FIXTURE_TEST_SUITE(crypto_tests, CryptoTest) +TEST_SUITE_BEGIN("crypto_tests") -BOOST_AUTO_TEST_CASE(ripemd160_testvectors) { +FIXTURE_TEST_CASE("ripemd160_testvectors", CryptoTest) { TestRIPEMD160("", "9c1185a5c5e9fc54612808977ee8f548b2258d31"); TestRIPEMD160("abc", "8eb208f7e05d987a9b044a8e98c6b087f15a0bfc"); TestRIPEMD160("message digest", "5d0689ef49d2fae572b881b123a85ffa21595f36"); @@ -392,7 +391,7 @@ BOOST_AUTO_TEST_CASE(ripemd160_testvectors) { TestRIPEMD160(test1, "464243587bd146ea835cdf57bdae582f25ec45f1"); } -BOOST_AUTO_TEST_CASE(sha1_testvectors) { +FIXTURE_TEST_CASE("sha1_testvectors", CryptoTest) { TestSHA1("", "da39a3ee5e6b4b0d3255bfef95601890afd80709"); TestSHA1("abc", "a9993e364706816aba3e25717850c26c9cd0d89d"); TestSHA1("message digest", "c12252ceda8be8994d5fa0290a47231c1d16aae3"); @@ -408,7 +407,7 @@ BOOST_AUTO_TEST_CASE(sha1_testvectors) { TestSHA1(test1, "b7755760681cbfd971451668f32af5774f4656b5"); } -BOOST_AUTO_TEST_CASE(sha256_testvectors) { +FIXTURE_TEST_CASE("sha256_testvectors", CryptoTest) { TestSHA256("", "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"); TestSHA256("abc", "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"); TestSHA256("message digest", @@ -430,7 +429,7 @@ BOOST_AUTO_TEST_CASE(sha256_testvectors) { TestSHA256(test1, "a316d55510b49662420f49d145d42fb83f31ef8dc016aa4e32df049991a91e26"); } -BOOST_AUTO_TEST_CASE(sha512_testvectors) { +FIXTURE_TEST_CASE("sha512_testvectors", CryptoTest) { TestSHA512("", "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce" "47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e"); @@ -467,7 +466,7 @@ BOOST_AUTO_TEST_CASE(sha512_testvectors) { "37de8c3ef5459d76a52cedc02dc499a3c9ed9dedbfb3281afd9653b8a112fafc"); } -BOOST_AUTO_TEST_CASE(hmac_sha256_testvectors) { +FIXTURE_TEST_CASE("hmac_sha256_testvectors", CryptoTest) { // test cases 1, 2, 3, 4, 6 and 7 of RFC 4231 TestHMACSHA256("0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b", "4869205468657265", @@ -520,7 +519,7 @@ BOOST_AUTO_TEST_CASE(hmac_sha256_testvectors) { "d06af337f359a2330deffb8e3cbe4b5b7aa8ca1f208528cdbd245d5dc63c4483"); } -BOOST_AUTO_TEST_CASE(hmac_sha512_testvectors) { +FIXTURE_TEST_CASE("hmac_sha512_testvectors", CryptoTest) { // test cases 1, 2, 3, 4, 6 and 7 of RFC 4231 TestHMACSHA512("0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b", "4869205468657265", @@ -588,7 +587,7 @@ BOOST_AUTO_TEST_CASE(hmac_sha512_testvectors) { "fb29795e79f2ef27f68cb1e16d76178c307a67beaad9456fac5fdffeadb16e2c"); } -BOOST_AUTO_TEST_CASE(aes_testvectors) { +FIXTURE_TEST_CASE("aes_testvectors", CryptoTest) { // AES test vectors from FIPS 197. TestAES256("000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", "00112233445566778899aabbccddeeff", "8ea2b7ca516745bfeafc49904b496089"); @@ -599,7 +598,7 @@ BOOST_AUTO_TEST_CASE(aes_testvectors) { TestAES256("603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4", "f69f2445df4f9b17ad2b417be66c3710", "23304b7a39f9f3ff067d8d8f9e24ecc7"); } -BOOST_AUTO_TEST_CASE(aes_cbc_testvectors) { +FIXTURE_TEST_CASE("aes_cbc_testvectors", CryptoTest) { // NIST AES CBC 256-bit encryption test-vectors TestAES256CBC("603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4", \ "000102030405060708090A0B0C0D0E0F", false, "6bc1bee22e409f96e93d7e117393172a", \ @@ -630,7 +629,7 @@ BOOST_AUTO_TEST_CASE(aes_cbc_testvectors) { } -BOOST_AUTO_TEST_CASE(chacha20_testvector) +FIXTURE_TEST_CASE("chacha20_testvector", CryptoTest) { /* Example from RFC8439 section 2.3.2. */ TestChaCha20("", @@ -831,7 +830,7 @@ BOOST_AUTO_TEST_CASE(chacha20_testvector) "8bfaa4eacff308fdb4a94a5ff25bd9d0c1f84b77f81239f67ff39d6e1ac280c9"); } -BOOST_AUTO_TEST_CASE(chacha20_midblock) +FIXTURE_TEST_CASE("chacha20_midblock", CryptoTest) { auto key = "0000000000000000000000000000000000000000000000000000000000000000"_hex; ChaCha20 c20{key}; @@ -844,12 +843,12 @@ BOOST_AUTO_TEST_CASE(chacha20_midblock) c20.Keystream(b2); c20.Keystream(b3); - BOOST_CHECK(std::ranges::equal(std::span{block}.first(5), b1)); - BOOST_CHECK(std::ranges::equal(std::span{block}.subspan(5, 7), b2)); - BOOST_CHECK(std::ranges::equal(std::span{block}.last(52), b3)); + CHECK(std::ranges::equal(std::span{block}.first(5), b1)); + CHECK(std::ranges::equal(std::span{block}.subspan(5, 7), b2)); + CHECK(std::ranges::equal(std::span{block}.last(52), b3)); } -BOOST_AUTO_TEST_CASE(poly1305_testvector) +FIXTURE_TEST_CASE("poly1305_testvector", CryptoTest) { // RFC 7539, section 2.5.2. TestPoly1305("43727970746f6772617068696320466f72756d2052657365617263682047726f7570", @@ -940,7 +939,7 @@ BOOST_AUTO_TEST_CASE(poly1305_testvector) } std::vector total_tag(Poly1305::TAGLEN); total_ctx.Finalize(total_tag); - BOOST_CHECK_EQUAL(HexStr(total_tag), "64afe2e8d6ad7bbdd287f97c44623d39"); + CHECK(HexStr(total_tag) == "64afe2e8d6ad7bbdd287f97c44623d39"); } // Tests with sparse messages and random keys. @@ -970,7 +969,7 @@ BOOST_AUTO_TEST_CASE(poly1305_testvector) "0e410fa9d7a40ac582e77546be9a72bb"); } -BOOST_AUTO_TEST_CASE(chacha20poly1305_testvectors) +FIXTURE_TEST_CASE("chacha20poly1305_testvectors", CryptoTest) { // Note that in our implementation, the authentication is suffixed to the ciphertext. // The RFC test vectors specify them separately. @@ -1051,7 +1050,7 @@ BOOST_AUTO_TEST_CASE(chacha20poly1305_testvectors) "14b94829deb27f0b1923a2af704ae5d6"); } -BOOST_AUTO_TEST_CASE(hkdf_hmac_sha256_l32_tests) +FIXTURE_TEST_CASE("hkdf_hmac_sha256_l32_tests", CryptoTest) { // Use rfc5869 test vectors but truncated to 32 bytes (our implementation only support length 32) TestHKDF_SHA256_32( @@ -1071,7 +1070,7 @@ BOOST_AUTO_TEST_CASE(hkdf_hmac_sha256_l32_tests) "8da4e775a563c18f715f802a063c5a31b8a11f5c5ee1879ec3454e5f3c738d2d"); } -BOOST_AUTO_TEST_CASE(sha256d64) +FIXTURE_TEST_CASE("sha256d64", CryptoTest) { for (int i = 0; i <= 32; ++i) { unsigned char in[64 * 32]; @@ -1083,7 +1082,7 @@ BOOST_AUTO_TEST_CASE(sha256d64) CHash256().Write({in + 64 * j, 64}).Finalize({out1 + 32 * j, 32}); } SHA256D64(out2, in, i); - BOOST_CHECK(memcmp(out1, out2, 32 * i) == 0); + CHECK(memcmp(out1, out2, 32 * i) == 0); } } @@ -1097,7 +1096,7 @@ void CryptoTest::TestSHA3_256(const std::string& input, const std::string& outpu unsigned char out[SHA3_256::OUTPUT_SIZE]; sha.Write(in_bytes).Finalize(out); assert(out_bytes.size() == sizeof(out)); - BOOST_CHECK(std::equal(std::begin(out_bytes), std::end(out_bytes), out)); + CHECK(std::equal(std::begin(out_bytes), std::end(out_bytes), out)); // Reset and split randomly in 3 sha.Reset(); @@ -1106,10 +1105,10 @@ void CryptoTest::TestSHA3_256(const std::string& input, const std::string& outpu int s3 = in_bytes.size() - s1 - s2; sha.Write(std::span{in_bytes}.first(s1)).Write(std::span{in_bytes}.subspan(s1, s2)); sha.Write(std::span{in_bytes}.last(s3)).Finalize(out); - BOOST_CHECK(std::equal(std::begin(out_bytes), std::end(out_bytes), out)); + CHECK(std::equal(std::begin(out_bytes), std::end(out_bytes), out)); } -BOOST_AUTO_TEST_CASE(keccak_tests) +FIXTURE_TEST_CASE("keccak_tests", CryptoTest) { // Start with the zero state. uint64_t state[25] = {0}; @@ -1126,10 +1125,10 @@ BOOST_AUTO_TEST_CASE(keccak_tests) tester.Finalize(out.begin()); // Expected hash of the concatenated serialized states after 1...262144 iterations of KeccakF. // Verified against an independent implementation. - BOOST_CHECK_EQUAL(out.ToString(), "5f4a7f2eca7d57740ef9f1a077b4fc67328092ec62620447fe27ad8ed5f7e34f"); + CHECK(out.ToString() == "5f4a7f2eca7d57740ef9f1a077b4fc67328092ec62620447fe27ad8ed5f7e34f"); } -BOOST_AUTO_TEST_CASE(sha3_256_tests) +FIXTURE_TEST_CASE("sha3_256_tests", CryptoTest) { // Test vectors from https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Algorithm-Validation-Program/documents/sha3/sha-3bytetestvectors.zip @@ -1198,7 +1197,7 @@ static MuHash3072 FromInt(unsigned char i) { return MuHash3072(tmp); } -BOOST_AUTO_TEST_CASE(muhash_tests) +FIXTURE_TEST_CASE("muhash_tests", CryptoTest) { uint256 out; @@ -1222,7 +1221,7 @@ BOOST_AUTO_TEST_CASE(muhash_tests) if (order == 0) { res = out; } else { - BOOST_CHECK(res == out); + CHECK(res == out); } } @@ -1239,14 +1238,14 @@ BOOST_AUTO_TEST_CASE(muhash_tests) MuHash3072 a; a.Finalize(out2); - BOOST_CHECK_EQUAL(out, out2); + CHECK(out == out2); } MuHash3072 acc = FromInt(0); acc *= FromInt(1); acc /= FromInt(2); acc.Finalize(out); - BOOST_CHECK_EQUAL(out, uint256{"10d312b100cbd32ada024a6646e40d3482fcff103668d2625f10002a607d5863"}); + CHECK(out == uint256{"10d312b100cbd32ada024a6646e40d3482fcff103668d2625f10002a607d5863"}); MuHash3072 acc2 = FromInt(0); unsigned char tmp[32] = {1, 0}; @@ -1254,14 +1253,14 @@ BOOST_AUTO_TEST_CASE(muhash_tests) unsigned char tmp2[32] = {2, 0}; acc2.Remove(tmp2); acc2.Finalize(out); - BOOST_CHECK_EQUAL(out, uint256{"10d312b100cbd32ada024a6646e40d3482fcff103668d2625f10002a607d5863"}); + CHECK(out == uint256{"10d312b100cbd32ada024a6646e40d3482fcff103668d2625f10002a607d5863"}); // Test MuHash3072 serialization MuHash3072 serchk = FromInt(1); serchk *= FromInt(2); std::string ser_exp = "1fa093295ea30a6a3acdc7b3f770fa538eff537528e990e2910e40bbcfd7f6696b1256901929094694b56316de342f593303dd12ac43e06dce1be1ff8301c845beb15468fff0ef002dbf80c29f26e6452bccc91b5cb9437ad410d2a67ea847887fa3c6a6553309946880fe20db2c73fe0641adbd4e86edfee0d9f8cd0ee1230898873dc13ed8ddcaf045c80faa082774279007a2253f8922ee3ef361d378a6af3ddaf180b190ac97e556888c36b3d1fb1c85aab9ccd46e3deaeb7b7cf5db067a7e9ff86b658cf3acd6662bbcce37232daa753c48b794356c020090c831a8304416e2aa7ad633c0ddb2f11be1be316a81be7f7e472071c042cb68faef549c221ebff209273638b741aba5a81675c45a5fa92fea4ca821d7a324cb1e1a2ccd3b76c4228ec8066dad2a5df6e1bd0de45c7dd5de8070bdb46db6c554cf9aefc9b7b2bbf9f75b1864d9f95005314593905c0109b71f703d49944ae94477b51dac10a816bb6d1c700bafabc8bd86fac8df24be519a2f2836b16392e18036cb13e48c5c010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"; DataStream ss_chk{}; ss_chk << serchk; - BOOST_CHECK_EQUAL(ser_exp, HexStr(ss_chk.str())); + CHECK(ser_exp == HexStr(ss_chk.str())); // Test MuHash3072 deserialization MuHash3072 deserchk; @@ -1269,7 +1268,7 @@ BOOST_AUTO_TEST_CASE(muhash_tests) uint256 out3; serchk.Finalize(out); deserchk.Finalize(out3); - BOOST_CHECK_EQUAL(HexStr(out), HexStr(out3)); + CHECK(HexStr(out) == HexStr(out3)); // Test MuHash3072 overflow, meaning the internal data is larger than the modulus. DataStream ss_max{"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"_hex}; @@ -1278,7 +1277,8 @@ BOOST_AUTO_TEST_CASE(muhash_tests) uint256 out4; overflowchk.Finalize(out4); - BOOST_CHECK_EQUAL(HexStr(out4), "3a31e6903aff0de9f62f9a9f7f8b861de76ce2cda09822b90014319ae5dc2271"); + CHECK(HexStr(out4) == "3a31e6903aff0de9f62f9a9f7f8b861de76ce2cda09822b90014319ae5dc2271"); } -BOOST_AUTO_TEST_SUITE_END() +TEST_SUITE_END() +} // namespace crypto_tests diff --git a/src/test/cuckoocache_tests.cpp b/src/test/cuckoocache_tests.cpp index 7566d22262df..0b8b627c2d18 100644 --- a/src/test/cuckoocache_tests.cpp +++ b/src/test/cuckoocache_tests.cpp @@ -9,7 +9,7 @@ #include #include -#include +#include #include #include @@ -30,13 +30,13 @@ * using BOOST_CHECK_CLOSE to fail. * */ -BOOST_FIXTURE_TEST_SUITE(cuckoocache_tests, BasicTestingSetup); +TEST_SUITE_BEGIN("cuckoocache_tests"); /* Test that no values not inserted into the cache are read out of it. * * There are no repeats in the first 200000 m_rng.rand256() calls */ -BOOST_AUTO_TEST_CASE(test_cuckoocache_no_fakes) +FIXTURE_TEST_CASE("test_cuckoocache_no_fakes", BasicTestingSetup) { SeedRandomForTest(SeedRand::ZEROS); CuckooCache::cache cc{}; @@ -45,7 +45,7 @@ BOOST_AUTO_TEST_CASE(test_cuckoocache_no_fakes) cc.insert(m_rng.rand256()); } for (int x = 0; x < 100000; ++x) { - BOOST_CHECK(!cc.contains(m_rng.rand256(), false)); + CHECK(!cc.contains(m_rng.rand256(), false)); } }; @@ -107,7 +107,7 @@ static double normalize_hit_rate(double hits, double load) }; // struct HitRateTest /** Check the hit rate on loads ranging from 0.1 to 1.6 */ -BOOST_FIXTURE_TEST_CASE(cuckoocache_hit_rate_ok, HitRateTest) +FIXTURE_TEST_CASE("cuckoocache_hit_rate_ok", HitRateTest) { /** Arbitrarily selected Hit Rate threshold that happens to work for this test * as a lower bound on performance. @@ -115,7 +115,7 @@ BOOST_FIXTURE_TEST_CASE(cuckoocache_hit_rate_ok, HitRateTest) double HitRateThresh = 0.98; for (double load = 0.1; load < 2; load *= 2) { double hits = test_cache>(4_MiB, load); - BOOST_CHECK(normalize_hit_rate(hits, load) > HitRateThresh); + CHECK(normalize_hit_rate(hits, load) > HitRateThresh); } } @@ -149,7 +149,7 @@ void test_cache_erase(size_t bytes) set.insert(hashes_insert_copy[i]); /** Erase the first quarter */ for (uint32_t i = 0; i < (n_insert / 4); ++i) - BOOST_CHECK(set.contains(hashes[i], true)); + CHECK(set.contains(hashes[i], true)); /** Insert the second half */ for (uint32_t i = (n_insert / 2); i < n_insert; ++i) set.insert(hashes_insert_copy[i]); @@ -173,14 +173,14 @@ void test_cache_erase(size_t bytes) double hit_rate_fresh = double(count_fresh) / (double(n_insert) / 2.0); // Check that our hit_rate_fresh is perfect - BOOST_CHECK_EQUAL(hit_rate_fresh, 1.0); + CHECK(hit_rate_fresh == 1.0); // Check that we have a more than 2x better hit rate on stale elements than // erased elements. - BOOST_CHECK(hit_rate_stale > 2 * hit_rate_erased_but_contained); + CHECK(hit_rate_stale > 2 * hit_rate_erased_but_contained); } }; // struct EraseTest -BOOST_FIXTURE_TEST_CASE(cuckoocache_erase_ok, EraseTest) +FIXTURE_TEST_CASE("cuckoocache_erase_ok", EraseTest) { test_cache_erase>(4_MiB); } @@ -264,13 +264,13 @@ void test_cache_erase_parallel(size_t bytes) double hit_rate_fresh = double(count_fresh) / (double(n_insert) / 2.0); // Check that our hit_rate_fresh is perfect - BOOST_CHECK_EQUAL(hit_rate_fresh, 1.0); + CHECK(hit_rate_fresh == 1.0); // Check that we have a more than 2x better hit rate on stale elements than // erased elements. - BOOST_CHECK(hit_rate_stale > 2 * hit_rate_erased_but_contained); + CHECK(hit_rate_stale > 2 * hit_rate_erased_but_contained); } }; // struct EraseParallelTest -BOOST_FIXTURE_TEST_CASE(cuckoocache_erase_parallel_ok, EraseParallelTest) +FIXTURE_TEST_CASE("cuckoocache_erase_parallel_ok", EraseParallelTest) { test_cache_erase_parallel>(4_MiB); } @@ -357,19 +357,19 @@ void test_cache_generations() // full yet. double hit = (double(count)) / (last_few.size() * POP_AMOUNT); // Loose Check that hit rate is above min_hit_rate - BOOST_CHECK(hit > min_hit_rate); + CHECK(hit > min_hit_rate); // Tighter check, count number of times we are less than tight_hit_rate // (and implicitly, greater than min_hit_rate) out_of_tight_tolerance += hit < tight_hit_rate; } // Check that being out of tolerance happens less than // max_rate_less_than_tight_hit_rate of the time - BOOST_CHECK(double(out_of_tight_tolerance) / double(total) < max_rate_less_than_tight_hit_rate); + CHECK(double(out_of_tight_tolerance) / double(total) < max_rate_less_than_tight_hit_rate); } }; // struct GenerationsTest -BOOST_FIXTURE_TEST_CASE(cuckoocache_generations, GenerationsTest) +FIXTURE_TEST_CASE("cuckoocache_generations", GenerationsTest) { test_cache_generations>(); } -BOOST_AUTO_TEST_SUITE_END(); +TEST_SUITE_END(); diff --git a/src/test/dbwrapper_tests.cpp b/src/test/dbwrapper_tests.cpp index 185bf491e57b..f55cc7a87cd5 100644 --- a/src/test/dbwrapper_tests.cpp +++ b/src/test/dbwrapper_tests.cpp @@ -13,13 +13,13 @@ #include #include -#include +#include using util::ToString; -BOOST_FIXTURE_TEST_SUITE(dbwrapper_tests, BasicTestingSetup) +TEST_SUITE_BEGIN("dbwrapper_tests") -BOOST_AUTO_TEST_CASE(dbwrapper) +FIXTURE_TEST_CASE("dbwrapper", BasicTestingSetup) { // Perform tests both obfuscated and non-obfuscated. for (const bool obfuscate : {false, true}) { @@ -32,11 +32,11 @@ BOOST_AUTO_TEST_CASE(dbwrapper) // Write values { CDBWrapper dbw{{.path = path, .cache_bytes = CACHE_SIZE, .wipe_data = true, .obfuscate = obfuscate}}; - BOOST_CHECK_EQUAL(obfuscate, !dbw.IsEmpty()); + CHECK(obfuscate == !dbw.IsEmpty()); // Ensure that we're doing real obfuscation when obfuscate=true obfuscation = dbwrapper_private::GetObfuscation(dbw); - BOOST_CHECK_EQUAL(obfuscate, dbwrapper_private::GetObfuscation(dbw)); + CHECK(obfuscate == dbwrapper_private::GetObfuscation(dbw)); for (uint8_t k{0}; k < 10; ++k) { uint8_t key{k}; @@ -49,7 +49,7 @@ BOOST_AUTO_TEST_CASE(dbwrapper) // Verify that the obfuscation key is never obfuscated { CDBWrapper dbw{{.path = path, .cache_bytes = CACHE_SIZE, .obfuscate = false}}; - BOOST_CHECK_EQUAL(obfuscation, dbwrapper_private::GetObfuscation(dbw)); + CHECK(obfuscation == dbwrapper_private::GetObfuscation(dbw)); } // Read back the values @@ -57,20 +57,20 @@ BOOST_AUTO_TEST_CASE(dbwrapper) CDBWrapper dbw{{.path = path, .cache_bytes = CACHE_SIZE, .obfuscate = obfuscate}}; // Ensure obfuscation is read back correctly - BOOST_CHECK_EQUAL(obfuscation, dbwrapper_private::GetObfuscation(dbw)); - BOOST_CHECK_EQUAL(obfuscate, dbwrapper_private::GetObfuscation(dbw)); + CHECK(obfuscation == dbwrapper_private::GetObfuscation(dbw)); + CHECK(obfuscate == dbwrapper_private::GetObfuscation(dbw)); // Verify all written values for (const auto& [key, expected_value] : key_values) { uint256 read_value{}; - BOOST_CHECK(dbw.Read(key, read_value)); - BOOST_CHECK_EQUAL(read_value, expected_value); + CHECK(dbw.Read(key, read_value)); + CHECK(read_value == expected_value); } } } } -BOOST_AUTO_TEST_CASE(dbwrapper_basic_data) +FIXTURE_TEST_CASE("dbwrapper_basic_data", BasicTestingSetup) { // Perform tests both obfuscated and non-obfuscated. for (bool obfuscate : {false, true}) { @@ -82,60 +82,60 @@ BOOST_AUTO_TEST_CASE(dbwrapper_basic_data) bool res_bool; // Ensure that we're doing real obfuscation when obfuscate=true - BOOST_CHECK_EQUAL(obfuscate, dbwrapper_private::GetObfuscation(dbw)); + CHECK(obfuscate == dbwrapper_private::GetObfuscation(dbw)); //Simulate block raw data - "b + block hash" std::string key_block = "b" + m_rng.rand256().ToString(); uint256 in_block = m_rng.rand256(); dbw.Write(key_block, in_block); - BOOST_CHECK(dbw.Read(key_block, res)); - BOOST_CHECK_EQUAL(res.ToString(), in_block.ToString()); + CHECK(dbw.Read(key_block, res)); + CHECK(res.ToString() == in_block.ToString()); //Simulate file raw data - "f + file_number" std::string key_file = strprintf("f%04x", m_rng.rand32()); uint256 in_file_info = m_rng.rand256(); dbw.Write(key_file, in_file_info); - BOOST_CHECK(dbw.Read(key_file, res)); - BOOST_CHECK_EQUAL(res.ToString(), in_file_info.ToString()); + CHECK(dbw.Read(key_file, res)); + CHECK(res.ToString() == in_file_info.ToString()); //Simulate transaction raw data - "t + transaction hash" std::string key_transaction = "t" + m_rng.rand256().ToString(); uint256 in_transaction = m_rng.rand256(); dbw.Write(key_transaction, in_transaction); - BOOST_CHECK(dbw.Read(key_transaction, res)); - BOOST_CHECK_EQUAL(res.ToString(), in_transaction.ToString()); + CHECK(dbw.Read(key_transaction, res)); + CHECK(res.ToString() == in_transaction.ToString()); //Simulate UTXO raw data - "c + transaction hash" std::string key_utxo = "c" + m_rng.rand256().ToString(); uint256 in_utxo = m_rng.rand256(); dbw.Write(key_utxo, in_utxo); - BOOST_CHECK(dbw.Read(key_utxo, res)); - BOOST_CHECK_EQUAL(res.ToString(), in_utxo.ToString()); + CHECK(dbw.Read(key_utxo, res)); + CHECK(res.ToString() == in_utxo.ToString()); //Simulate last block file number - "l" uint8_t key_last_blockfile_number{'l'}; uint32_t lastblockfilenumber = m_rng.rand32(); dbw.Write(key_last_blockfile_number, lastblockfilenumber); - BOOST_CHECK(dbw.Read(key_last_blockfile_number, res_uint_32)); - BOOST_CHECK_EQUAL(lastblockfilenumber, res_uint_32); + CHECK(dbw.Read(key_last_blockfile_number, res_uint_32)); + CHECK(lastblockfilenumber == res_uint_32); //Simulate Is Reindexing - "R" uint8_t key_IsReindexing{'R'}; bool isInReindexing = m_rng.randbool(); dbw.Write(key_IsReindexing, isInReindexing); - BOOST_CHECK(dbw.Read(key_IsReindexing, res_bool)); - BOOST_CHECK_EQUAL(isInReindexing, res_bool); + CHECK(dbw.Read(key_IsReindexing, res_bool)); + CHECK(isInReindexing == res_bool); //Simulate last block hash up to which UXTO covers - 'B' uint8_t key_lastblockhash_uxto{'B'}; uint256 lastblock_hash = m_rng.rand256(); dbw.Write(key_lastblockhash_uxto, lastblock_hash); - BOOST_CHECK(dbw.Read(key_lastblockhash_uxto, res)); - BOOST_CHECK_EQUAL(lastblock_hash, res); + CHECK(dbw.Read(key_lastblockhash_uxto, res)); + CHECK(lastblock_hash == res); //Simulate file raw data - "F + filename_number + filename" std::string file_option_tag = "F"; @@ -145,13 +145,13 @@ BOOST_AUTO_TEST_CASE(dbwrapper_basic_data) bool in_file_bool = m_rng.randbool(); dbw.Write(key_file_option, in_file_bool); - BOOST_CHECK(dbw.Read(key_file_option, res_bool)); - BOOST_CHECK_EQUAL(res_bool, in_file_bool); + CHECK(dbw.Read(key_file_option, res_bool)); + CHECK(res_bool == in_file_bool); } } // Test batch operations -BOOST_AUTO_TEST_CASE(dbwrapper_batch) +FIXTURE_TEST_CASE("dbwrapper_batch", BasicTestingSetup) { // Perform tests both obfuscated and non-obfuscated. for (const bool obfuscate : {false, true}) { @@ -177,24 +177,24 @@ BOOST_AUTO_TEST_CASE(dbwrapper_batch) dbw.WriteBatch(batch); - BOOST_CHECK(dbw.Read(key, res)); - BOOST_CHECK_EQUAL(res.ToString(), in.ToString()); - BOOST_CHECK(dbw.Read(key2, res)); - BOOST_CHECK_EQUAL(res.ToString(), in2.ToString()); + CHECK(dbw.Read(key, res)); + CHECK(res.ToString() == in.ToString()); + CHECK(dbw.Read(key2, res)); + CHECK(res.ToString() == in2.ToString()); // key3 should've never been written - BOOST_CHECK(dbw.Read(key3, res) == false); + CHECK(dbw.Read(key3, res) == false); batch.Clear(); batch.Write(key3, in3); dbw.WriteBatch(batch); - BOOST_CHECK(dbw.Read(key3, res)); - BOOST_CHECK_EQUAL(res.ToString(), in3.ToString()); + CHECK(dbw.Read(key3, res)); + CHECK(res.ToString() == in3.ToString()); } } -BOOST_AUTO_TEST_CASE(dbwrapper_iterator) +FIXTURE_TEST_CASE("dbwrapper_iterator", BasicTestingSetup) { // Perform tests both obfuscated and non-obfuscated. for (const bool obfuscate : {false, true}) { @@ -216,48 +216,48 @@ BOOST_AUTO_TEST_CASE(dbwrapper_iterator) // A failed key decode must not consume the current iterator entry. uint16_t key_too_large{0}; - BOOST_CHECK(!it->GetKey(key_too_large)); + CHECK(!it->GetKey(key_too_large)); uint8_t key_res; - BOOST_REQUIRE(it->GetKey(key_res)); - BOOST_CHECK_EQUAL(key_res, key); + REQUIRE(it->GetKey(key_res)); + CHECK(key_res == key); // A failed value decode must not leave the iterator's scratch stream dirty. std::pair value_too_large; - BOOST_CHECK(!it->GetValue(value_too_large)); + CHECK(!it->GetValue(value_too_large)); uint256 val_res; - BOOST_REQUIRE(it->GetValue(val_res)); - BOOST_CHECK_EQUAL(val_res.ToString(), in.ToString()); + REQUIRE(it->GetValue(val_res)); + CHECK(val_res.ToString() == in.ToString()); it->Seek(key2); - BOOST_REQUIRE(it->GetKey(key_res)); - BOOST_CHECK_EQUAL(key_res, key2); - BOOST_REQUIRE(it->GetValue(val_res)); - BOOST_CHECK_EQUAL(val_res.ToString(), in2.ToString()); + REQUIRE(it->GetKey(key_res)); + CHECK(key_res == key2); + REQUIRE(it->GetValue(val_res)); + CHECK(val_res.ToString() == in2.ToString()); it->Seek(key); - BOOST_REQUIRE(it->GetKey(key_res)); - BOOST_CHECK_EQUAL(key_res, key); - BOOST_REQUIRE(it->GetValue(val_res)); - BOOST_CHECK_EQUAL(val_res.ToString(), in.ToString()); + REQUIRE(it->GetKey(key_res)); + CHECK(key_res == key); + REQUIRE(it->GetValue(val_res)); + CHECK(val_res.ToString() == in.ToString()); it->Next(); - BOOST_REQUIRE(it->GetKey(key_res)); - BOOST_CHECK_EQUAL(key_res, key2); - BOOST_REQUIRE(it->GetValue(val_res)); - BOOST_CHECK_EQUAL(val_res.ToString(), in2.ToString()); + REQUIRE(it->GetKey(key_res)); + CHECK(key_res == key2); + REQUIRE(it->GetValue(val_res)); + CHECK(val_res.ToString() == in2.ToString()); it->Next(); - BOOST_CHECK_EQUAL(it->Valid(), false); + CHECK(it->Valid() == false); } } // Test that we do not obfuscation if there is existing data. -BOOST_AUTO_TEST_CASE(existing_data_no_obfuscate) +FIXTURE_TEST_CASE("existing_data_no_obfuscate", BasicTestingSetup) { // We're going to share this fs::path between two wrappers fs::path ph = m_args.GetDataDirBase() / "existing_data_no_obfuscate"; @@ -270,8 +270,8 @@ BOOST_AUTO_TEST_CASE(existing_data_no_obfuscate) uint256 res; dbw->Write(key, in); - BOOST_CHECK(dbw->Read(key, res)); - BOOST_CHECK_EQUAL(res.ToString(), in.ToString()); + CHECK(dbw->Read(key, res)); + CHECK(res.ToString() == in.ToString()); // Call the destructor to free leveldb LOCK dbw.reset(); @@ -282,23 +282,23 @@ BOOST_AUTO_TEST_CASE(existing_data_no_obfuscate) // Check that the key/val we wrote with unobfuscated wrapper exists and // is readable. uint256 res2; - BOOST_CHECK(odbw.Read(key, res2)); - BOOST_CHECK_EQUAL(res2.ToString(), in.ToString()); + CHECK(odbw.Read(key, res2)); + CHECK(res2.ToString() == in.ToString()); - BOOST_CHECK(!odbw.IsEmpty()); - BOOST_CHECK(!dbwrapper_private::GetObfuscation(odbw)); // The key should be an empty string + CHECK(!odbw.IsEmpty()); + CHECK(!dbwrapper_private::GetObfuscation(odbw)); // The key should be an empty string uint256 in2 = m_rng.rand256(); uint256 res3; // Check that we can write successfully odbw.Write(key, in2); - BOOST_CHECK(odbw.Read(key, res3)); - BOOST_CHECK_EQUAL(res3.ToString(), in2.ToString()); + CHECK(odbw.Read(key, res3)); + CHECK(res3.ToString() == in2.ToString()); } // Ensure that we start obfuscating during a reindex. -BOOST_AUTO_TEST_CASE(existing_data_reindex) +FIXTURE_TEST_CASE("existing_data_reindex", BasicTestingSetup) { // We're going to share this fs::path between two wrappers fs::path ph = m_args.GetDataDirBase() / "existing_data_reindex"; @@ -311,8 +311,8 @@ BOOST_AUTO_TEST_CASE(existing_data_reindex) uint256 res; dbw->Write(key, in); - BOOST_CHECK(dbw->Read(key, res)); - BOOST_CHECK_EQUAL(res.ToString(), in.ToString()); + CHECK(dbw->Read(key, res)); + CHECK(res.ToString() == in.ToString()); // Call the destructor to free leveldb LOCK dbw.reset(); @@ -322,19 +322,19 @@ BOOST_AUTO_TEST_CASE(existing_data_reindex) // Check that the key/val we wrote with unobfuscated wrapper doesn't exist uint256 res2; - BOOST_CHECK(!odbw.Read(key, res2)); - BOOST_CHECK(dbwrapper_private::GetObfuscation(odbw)); + CHECK(!odbw.Read(key, res2)); + CHECK(dbwrapper_private::GetObfuscation(odbw)); uint256 in2 = m_rng.rand256(); uint256 res3; // Check that we can write successfully odbw.Write(key, in2); - BOOST_CHECK(odbw.Read(key, res3)); - BOOST_CHECK_EQUAL(res3.ToString(), in2.ToString()); + CHECK(odbw.Read(key, res3)); + CHECK(res3.ToString() == in2.ToString()); } -BOOST_AUTO_TEST_CASE(iterator_ordering) +FIXTURE_TEST_CASE("iterator_ordering", BasicTestingSetup) { fs::path ph = m_args.GetDataDirBase() / "iterator_ordering"; CDBWrapper dbw({.path = ph, .cache_bytes = 1_MiB, .memory_only = true, .wipe_data = false, .obfuscate = false}); @@ -358,20 +358,20 @@ BOOST_AUTO_TEST_CASE(iterator_ordering) for (unsigned int x=seek_start; x<255; ++x) { uint8_t key; uint32_t value; - BOOST_CHECK(it->Valid()); + CHECK(it->Valid()); if (!it->Valid()) // Avoid spurious errors about invalid iterator's key and value in case of failure break; - BOOST_CHECK(it->GetKey(key)); + CHECK(it->GetKey(key)); if (x & 1) { - BOOST_CHECK_EQUAL(key, x + 1); + CHECK(key == x + 1); continue; } - BOOST_CHECK(it->GetValue(value)); - BOOST_CHECK_EQUAL(key, x); - BOOST_CHECK_EQUAL(value, x*x); + CHECK(it->GetValue(value)); + CHECK(key == x); + CHECK(value == x*x); it->Next(); } - BOOST_CHECK(!it->Valid()); + CHECK(!it->Valid()); } } @@ -402,7 +402,7 @@ struct StringContentsSerializer { } }; -BOOST_AUTO_TEST_CASE(iterator_string_ordering) +FIXTURE_TEST_CASE("iterator_string_ordering", BasicTestingSetup) { fs::path ph = m_args.GetDataDirBase() / "iterator_string_ordering"; CDBWrapper dbw({.path = ph, .cache_bytes = 1_MiB, .memory_only = true, .wipe_data = false, .obfuscate = false}); @@ -425,22 +425,22 @@ BOOST_AUTO_TEST_CASE(iterator_string_ordering) for (int z = 0; z < y; ++z) exp_key += exp_key; StringContentsSerializer key; - uint32_t value; - BOOST_CHECK(it->Valid()); + uint32_t value{0}; + CHECK(it->Valid()); if (!it->Valid()) // Avoid spurious errors about invalid iterator's key and value in case of failure break; - BOOST_CHECK(it->GetKey(key)); - BOOST_CHECK(it->GetValue(value)); - BOOST_CHECK_EQUAL(key.str, exp_key); - BOOST_CHECK_EQUAL(value, x*x); + CHECK(it->GetKey(key)); + CHECK(it->GetValue(value)); + CHECK(key.str == exp_key); + CHECK(value == x*x); it->Next(); } } - BOOST_CHECK(!it->Valid()); + CHECK(!it->Valid()); } } -BOOST_AUTO_TEST_CASE(unicodepath) +FIXTURE_TEST_CASE("unicodepath", BasicTestingSetup) { // Attempt to create a database with a UTF8 character in the path. // On Windows this test will fail if the directory is created using @@ -450,8 +450,8 @@ BOOST_AUTO_TEST_CASE(unicodepath) CDBWrapper dbw({.path = ph, .cache_bytes = 1_MiB}); fs::path lockPath = ph / "LOCK"; - BOOST_CHECK(fs::exists(lockPath)); + CHECK(fs::exists(lockPath)); } -BOOST_AUTO_TEST_SUITE_END() +TEST_SUITE_END() diff --git a/src/test/denialofservice_tests.cpp b/src/test/denialofservice_tests.cpp index 05dfcb1e2327..1aa212f5523e 100644 --- a/src/test/denialofservice_tests.cpp +++ b/src/test/denialofservice_tests.cpp @@ -24,7 +24,7 @@ #include #include -#include +#include static CService ip(uint32_t i) { @@ -33,7 +33,7 @@ static CService ip(uint32_t i) return CService(CNetAddr(s), Params().GetDefaultPort()); } -BOOST_FIXTURE_TEST_SUITE(denialofservice_tests, TestingSetup) +TEST_SUITE_BEGIN("denialofservice_tests") // Test eviction of an outbound peer whose chain never advances // Mock a node connection, and use mocktime to simulate a peer @@ -43,7 +43,7 @@ BOOST_FIXTURE_TEST_SUITE(denialofservice_tests, TestingSetup) // this logic; this test takes advantage of that protection only // being applied to nodes which send headers with sufficient // work. -BOOST_AUTO_TEST_CASE(outbound_slow_chain_eviction) +FIXTURE_TEST_CASE("outbound_slow_chain_eviction", TestingSetup) { LOCK(NetEventsInterface::g_msgproc_mutex); @@ -77,33 +77,33 @@ BOOST_AUTO_TEST_CASE(outbound_slow_chain_eviction) // This test requires that we have a chain with non-zero work. { LOCK(cs_main); - BOOST_CHECK(m_node.chainman->ActiveChain().Tip() != nullptr); - BOOST_CHECK(m_node.chainman->ActiveChain().Tip()->nChainWork > 0); + CHECK(m_node.chainman->ActiveChain().Tip() != nullptr); + CHECK(m_node.chainman->ActiveChain().Tip()->nChainWork > 0); } // Test starts here - BOOST_CHECK(peerman.SendMessages(dummyNode1)); // should result in getheaders + CHECK(peerman.SendMessages(dummyNode1)); // should result in getheaders { LOCK(dummyNode1.cs_vSend); const auto& [to_send, _more, _msg_type] = dummyNode1.m_transport->GetBytesToSend(false); - BOOST_CHECK(!to_send.empty()); + CHECK(!to_send.empty()); } connman.FlushSendBuffer(dummyNode1); NodeClockContext clock_ctx{}; clock_ctx += 21min; - BOOST_CHECK(peerman.SendMessages(dummyNode1)); // should result in getheaders + CHECK(peerman.SendMessages(dummyNode1)); // should result in getheaders { LOCK(dummyNode1.cs_vSend); const auto& [to_send, _more, _msg_type] = dummyNode1.m_transport->GetBytesToSend(false); - BOOST_CHECK(!to_send.empty()); + CHECK(!to_send.empty()); } clock_ctx += 3min; - BOOST_CHECK(peerman.SendMessages(dummyNode1)); // should result in disconnect - BOOST_CHECK(dummyNode1.fDisconnect == true); + CHECK(peerman.SendMessages(dummyNode1)); // should result in disconnect + CHECK(dummyNode1.fDisconnect == true); peerman.FinalizeNode(dummyNode1); } @@ -115,7 +115,7 @@ void AddRandomOutboundPeer(NodeId& id, std::vector& vNodes, PeerManager& if (onion_peer) { auto tor_addr{m_rng.randbytes(ADDR_TORV3_SIZE)}; - BOOST_REQUIRE(addr.SetSpecial(OnionToString(tor_addr))); + REQUIRE(addr.SetSpecial(OnionToString(tor_addr))); } while (!addr.IsRoutable()) { @@ -142,7 +142,7 @@ void AddRandomOutboundPeer(NodeId& id, std::vector& vNodes, PeerManager& } }; // struct OutboundTest -BOOST_FIXTURE_TEST_CASE(stale_tip_peer_management, OutboundTest) +FIXTURE_TEST_CASE("stale_tip_peer_management", OutboundTest) { NodeId id{0}; auto connman = std::make_unique(0x1337, 0x1337, *m_node.addrman, *m_node.netgroupman, Params()); @@ -167,7 +167,7 @@ BOOST_FIXTURE_TEST_CASE(stale_tip_peer_management, OutboundTest) // No nodes should be marked for disconnection while we have no extra peers for (const CNode *node : vNodes) { - BOOST_CHECK(node->fDisconnect == false); + CHECK(node->fDisconnect == false); } clock_ctx += delta; @@ -175,11 +175,11 @@ BOOST_FIXTURE_TEST_CASE(stale_tip_peer_management, OutboundTest) // Now tip should definitely be stale, and we should look for an extra // outbound peer peerLogic->CheckForStaleTipAndEvictPeers(); - BOOST_CHECK(connman->GetTryNewOutboundPeer()); + CHECK(connman->GetTryNewOutboundPeer()); // Still no peers should be marked for disconnection for (const CNode *node : vNodes) { - BOOST_CHECK(node->fDisconnect == false); + CHECK(node->fDisconnect == false); } // If we add one more peer, something should get marked for eviction @@ -191,10 +191,10 @@ BOOST_FIXTURE_TEST_CASE(stale_tip_peer_management, OutboundTest) peerLogic->CheckForStaleTipAndEvictPeers(); for (int i = 0; i < max_outbound_full_relay; ++i) { - BOOST_CHECK(vNodes[i]->fDisconnect == false); + CHECK(vNodes[i]->fDisconnect == false); } // Last added node should get marked for eviction - BOOST_CHECK(vNodes.back()->fDisconnect == true); + CHECK(vNodes.back()->fDisconnect == true); vNodes.back()->fDisconnect = false; @@ -204,10 +204,10 @@ BOOST_FIXTURE_TEST_CASE(stale_tip_peer_management, OutboundTest) peerLogic->CheckForStaleTipAndEvictPeers(); for (int i = 0; i < max_outbound_full_relay - 1; ++i) { - BOOST_CHECK(vNodes[i]->fDisconnect == false); + CHECK(vNodes[i]->fDisconnect == false); } - BOOST_CHECK(vNodes[max_outbound_full_relay-1]->fDisconnect == true); - BOOST_CHECK(vNodes.back()->fDisconnect == false); + CHECK(vNodes[max_outbound_full_relay-1]->fDisconnect == true); + CHECK(vNodes.back()->fDisconnect == false); vNodes[max_outbound_full_relay - 1]->fDisconnect = false; @@ -219,11 +219,11 @@ BOOST_FIXTURE_TEST_CASE(stale_tip_peer_management, OutboundTest) peerLogic->CheckForStaleTipAndEvictPeers(); for (int i = 0; i < max_outbound_full_relay - 2; ++i) { - BOOST_CHECK(vNodes[i]->fDisconnect == false); + CHECK(vNodes[i]->fDisconnect == false); } - BOOST_CHECK(vNodes[max_outbound_full_relay - 2]->fDisconnect == false); - BOOST_CHECK(vNodes[max_outbound_full_relay - 1]->fDisconnect == true); - BOOST_CHECK(vNodes[max_outbound_full_relay]->fDisconnect == false); + CHECK(vNodes[max_outbound_full_relay - 2]->fDisconnect == false); + CHECK(vNodes[max_outbound_full_relay - 1]->fDisconnect == true); + CHECK(vNodes[max_outbound_full_relay]->fDisconnect == false); // Add a second onion peer which won't be protected clock_ctx.set(time_init); @@ -231,7 +231,7 @@ BOOST_FIXTURE_TEST_CASE(stale_tip_peer_management, OutboundTest) clock_ctx += delta; peerLogic->CheckForStaleTipAndEvictPeers(); - BOOST_CHECK(vNodes.back()->fDisconnect == true); + CHECK(vNodes.back()->fDisconnect == true); for (const CNode *node : vNodes) { peerLogic->FinalizeNode(*node); @@ -240,7 +240,7 @@ BOOST_FIXTURE_TEST_CASE(stale_tip_peer_management, OutboundTest) connman->ClearTestNodes(); } -BOOST_FIXTURE_TEST_CASE(block_relay_only_eviction, OutboundTest) +FIXTURE_TEST_CASE("block_relay_only_eviction", OutboundTest) { NodeId id{0}; auto connman = std::make_unique(0x1337, 0x1337, *m_node.addrman, *m_node.netgroupman, Params()); @@ -261,7 +261,7 @@ BOOST_FIXTURE_TEST_CASE(block_relay_only_eviction, OutboundTest) peerLogic->CheckForStaleTipAndEvictPeers(); for (int i = 0; i < max_outbound_block_relay; ++i) { - BOOST_CHECK(vNodes[i]->fDisconnect == false); + CHECK(vNodes[i]->fDisconnect == false); } // Add an extra block-relay-only peer breaking the limit (mocks logic in ThreadOpenConnections) @@ -270,17 +270,17 @@ BOOST_FIXTURE_TEST_CASE(block_relay_only_eviction, OutboundTest) // The extra peer should only get marked for eviction after MINIMUM_CONNECT_TIME for (int i = 0; i < max_outbound_block_relay; ++i) { - BOOST_CHECK(vNodes[i]->fDisconnect == false); + CHECK(vNodes[i]->fDisconnect == false); } - BOOST_CHECK(vNodes.back()->fDisconnect == false); + CHECK(vNodes.back()->fDisconnect == false); NodeClockContext clock_ctx{}; clock_ctx += MINIMUM_CONNECT_TIME; peerLogic->CheckForStaleTipAndEvictPeers(); for (int i = 0; i < max_outbound_block_relay; ++i) { - BOOST_CHECK(vNodes[i]->fDisconnect == false); + CHECK(vNodes[i]->fDisconnect == false); } - BOOST_CHECK(vNodes.back()->fDisconnect == true); + CHECK(vNodes.back()->fDisconnect == true); // Update the last block time for the extra peer, // and check that the next youngest peer gets evicted. @@ -289,10 +289,10 @@ BOOST_FIXTURE_TEST_CASE(block_relay_only_eviction, OutboundTest) peerLogic->CheckForStaleTipAndEvictPeers(); for (int i = 0; i < max_outbound_block_relay - 1; ++i) { - BOOST_CHECK(vNodes[i]->fDisconnect == false); + CHECK(vNodes[i]->fDisconnect == false); } - BOOST_CHECK(vNodes[max_outbound_block_relay - 1]->fDisconnect == true); - BOOST_CHECK(vNodes.back()->fDisconnect == false); + CHECK(vNodes[max_outbound_block_relay - 1]->fDisconnect == true); + CHECK(vNodes.back()->fDisconnect == false); for (const CNode* node : vNodes) { peerLogic->FinalizeNode(*node); @@ -300,7 +300,7 @@ BOOST_FIXTURE_TEST_CASE(block_relay_only_eviction, OutboundTest) connman->ClearTestNodes(); } -BOOST_AUTO_TEST_CASE(peer_discouragement) +FIXTURE_TEST_CASE("peer_discouragement", TestingSetup) { LOCK(NetEventsInterface::g_msgproc_mutex); @@ -309,8 +309,7 @@ BOOST_AUTO_TEST_CASE(peer_discouragement) auto peerLogic = PeerManager::make(*connman, *m_node.addrman, banman.get(), *m_node.chainman, *m_node.mempool, *m_node.warnings, {}); CNetAddr tor_netaddr; - BOOST_REQUIRE( - tor_netaddr.SetSpecial("pg6mmjiyjmcrsslvykfwnntlaru7p5svn6y2ymmju6nubxndf4pscryd.onion")); + REQUIRE(tor_netaddr.SetSpecial("pg6mmjiyjmcrsslvykfwnntlaru7p5svn6y2ymmju6nubxndf4pscryd.onion")); const CService tor_service{tor_netaddr, Params().GetDefaultPort()}; const std::array addr{CAddress{ip(0xa0b0c001), NODE_NONE}, @@ -338,11 +337,11 @@ BOOST_AUTO_TEST_CASE(peer_discouragement) nodes[0]->fSuccessfullyConnected = true; connman->AddTestNode(*nodes[0]); peerLogic->UnitTestMisbehaving(nodes[0]->GetId()); // Should be discouraged - BOOST_CHECK(peerLogic->SendMessages(*nodes[0])); + CHECK(peerLogic->SendMessages(*nodes[0])); - BOOST_CHECK(banman->IsDiscouraged(addr[0])); - BOOST_CHECK(nodes[0]->fDisconnect); - BOOST_CHECK(!banman->IsDiscouraged(other_addr)); // Different address, not discouraged + CHECK(banman->IsDiscouraged(addr[0])); + CHECK(nodes[0]->fDisconnect); + CHECK(!banman->IsDiscouraged(other_addr)); // Different address, not discouraged nodes[1] = new CNode{id++, /*sock=*/nullptr, @@ -358,20 +357,20 @@ BOOST_AUTO_TEST_CASE(peer_discouragement) peerLogic->InitializeNode(*nodes[1], NODE_NETWORK); nodes[1]->fSuccessfullyConnected = true; connman->AddTestNode(*nodes[1]); - BOOST_CHECK(peerLogic->SendMessages(*nodes[1])); + CHECK(peerLogic->SendMessages(*nodes[1])); // [0] is still discouraged/disconnected. - BOOST_CHECK(banman->IsDiscouraged(addr[0])); - BOOST_CHECK(nodes[0]->fDisconnect); + CHECK(banman->IsDiscouraged(addr[0])); + CHECK(nodes[0]->fDisconnect); // [1] is not discouraged/disconnected yet. - BOOST_CHECK(!banman->IsDiscouraged(addr[1])); - BOOST_CHECK(!nodes[1]->fDisconnect); + CHECK(!banman->IsDiscouraged(addr[1])); + CHECK(!nodes[1]->fDisconnect); peerLogic->UnitTestMisbehaving(nodes[1]->GetId()); - BOOST_CHECK(peerLogic->SendMessages(*nodes[1])); + CHECK(peerLogic->SendMessages(*nodes[1])); // Expect both [0] and [1] to be discouraged/disconnected now. - BOOST_CHECK(banman->IsDiscouraged(addr[0])); - BOOST_CHECK(nodes[0]->fDisconnect); - BOOST_CHECK(banman->IsDiscouraged(addr[1])); - BOOST_CHECK(nodes[1]->fDisconnect); + CHECK(banman->IsDiscouraged(addr[0])); + CHECK(nodes[0]->fDisconnect); + CHECK(banman->IsDiscouraged(addr[1])); + CHECK(nodes[1]->fDisconnect); // Make sure non-IP peers are discouraged and disconnected properly. @@ -390,13 +389,13 @@ BOOST_AUTO_TEST_CASE(peer_discouragement) nodes[2]->fSuccessfullyConnected = true; connman->AddTestNode(*nodes[2]); peerLogic->UnitTestMisbehaving(nodes[2]->GetId()); - BOOST_CHECK(peerLogic->SendMessages(*nodes[2])); - BOOST_CHECK(banman->IsDiscouraged(addr[0])); - BOOST_CHECK(banman->IsDiscouraged(addr[1])); - BOOST_CHECK(banman->IsDiscouraged(addr[2])); - BOOST_CHECK(nodes[0]->fDisconnect); - BOOST_CHECK(nodes[1]->fDisconnect); - BOOST_CHECK(nodes[2]->fDisconnect); + CHECK(peerLogic->SendMessages(*nodes[2])); + CHECK(banman->IsDiscouraged(addr[0])); + CHECK(banman->IsDiscouraged(addr[1])); + CHECK(banman->IsDiscouraged(addr[2])); + CHECK(nodes[0]->fDisconnect); + CHECK(nodes[1]->fDisconnect); + CHECK(nodes[2]->fDisconnect); for (CNode* node : nodes) { peerLogic->FinalizeNode(*node); @@ -404,7 +403,7 @@ BOOST_AUTO_TEST_CASE(peer_discouragement) connman->ClearTestNodes(); } -BOOST_AUTO_TEST_CASE(DoS_bantime) +FIXTURE_TEST_CASE("DoS_bantime", TestingSetup) { LOCK(NetEventsInterface::g_msgproc_mutex); @@ -432,10 +431,10 @@ BOOST_AUTO_TEST_CASE(DoS_bantime) dummyNode.fSuccessfullyConnected = true; peerLogic->UnitTestMisbehaving(dummyNode.GetId()); - BOOST_CHECK(peerLogic->SendMessages(dummyNode)); - BOOST_CHECK(banman->IsDiscouraged(addr)); + CHECK(peerLogic->SendMessages(dummyNode)); + CHECK(banman->IsDiscouraged(addr)); peerLogic->FinalizeNode(dummyNode); } -BOOST_AUTO_TEST_SUITE_END() +TEST_SUITE_END() diff --git a/src/test/descriptor_tests.cpp b/src/test/descriptor_tests.cpp index 0ede4dc9dfe7..ed08d24142cf 100644 --- a/src/test/descriptor_tests.cpp +++ b/src/test/descriptor_tests.cpp @@ -10,7 +10,7 @@ #include #include -#include +#include #include #include @@ -28,9 +28,9 @@ void CheckUnparsable(const std::string& prv, const std::string& pub, const std:: std::string error; auto parse_priv = Parse(prv, keys_priv, error); auto parse_pub = Parse(pub, keys_pub, error); - BOOST_CHECK_MESSAGE(parse_priv.empty(), prv); - BOOST_CHECK_MESSAGE(parse_pub.empty(), pub); - BOOST_CHECK_EQUAL(error, expected_error); + CHECK(parse_priv.empty(), prv); + CHECK(parse_pub.empty(), pub); + CHECK(error == expected_error); } /** Check that the script is inferred as non-standard */ @@ -38,7 +38,7 @@ void CheckInferRaw(const CScript& script) { FlatSigningProvider dummy_provider; std::unique_ptr desc = InferDescriptor(script, dummy_provider); - BOOST_CHECK(desc->ToString().rfind("raw(", 0) == 0); + CHECK(desc->ToString().rfind("raw(", 0) == 0U); } constexpr int DEFAULT = 0; @@ -127,7 +127,7 @@ std::set GetKeyData(const FlatSigningProvider& provider, int flags) { for (const auto& [_, pubkey] : provider.pubkeys) { if (flags & XONLY_KEYS) { unsigned char bytes[33]; - BOOST_CHECK_EQUAL(pubkey.size(), 33); + CHECK(pubkey.size() == 33U); std::copy(pubkey.begin(), pubkey.end(), bytes); bytes[0] = 0x02; CPubKey norm_pubkey{bytes}; @@ -154,7 +154,7 @@ std::set> GetKeyOriginData(const FlatSigningPr if (ignored.contains(keyid)) continue; if (flags & XONLY_KEYS) { unsigned char bytes[33]; - BOOST_CHECK_EQUAL(data.first.size(), 33); + CHECK(data.first.size() == 33U); std::copy(data.first.begin(), data.first.end(), bytes); bytes[0] = 0x02; CPubKey norm_pubkey{bytes}; @@ -186,12 +186,12 @@ void DoCheck(std::string prv, std::string pub, const std::string& norm_pub, int prv = UseHInsteadOfApostrophe(prv); } parse_privs = Parse(prv, keys_priv, error); - BOOST_CHECK_MESSAGE(!parse_privs.empty(), error); + CHECK(!parse_privs.empty(), error); if (replace_apostrophe_with_h_in_pub) { pub = UseHInsteadOfApostrophe(pub); } parse_pubs = Parse(pub, keys_pub, error); - BOOST_CHECK_MESSAGE(!parse_pubs.empty(), error); + CHECK(!parse_pubs.empty(), error); auto& parse_priv = parse_privs.at(desc_index); auto& parse_pub = parse_pubs.at(desc_index); @@ -200,61 +200,61 @@ void DoCheck(std::string prv, std::string pub, const std::string& norm_pub, int const bool is_nontop_or_nonsolvable{!parse_priv->IsSolvable() || !parse_priv->GetOutputType()}; const auto max_sat_maxsig{parse_priv->MaxSatisfactionWeight(true)}; const auto max_sat_nonmaxsig{parse_priv->MaxSatisfactionWeight(false)}; - BOOST_CHECK(max_sat_nonmaxsig <= max_sat_maxsig); + CHECK(max_sat_nonmaxsig <= max_sat_maxsig); const auto max_elems{parse_priv->MaxSatisfactionElems()}; const bool is_input_size_info_set{max_sat_maxsig && max_sat_nonmaxsig && max_elems}; - BOOST_CHECK_MESSAGE(is_input_size_info_set || is_nontop_or_nonsolvable, prv); + CHECK((is_input_size_info_set || is_nontop_or_nonsolvable), prv); // The ScriptSize() must match the size of the Script string. (ScriptSize() is set for all descs but 'combo()'.) const bool is_combo{!parse_priv->IsSingleType()}; - BOOST_CHECK_MESSAGE(is_combo || parse_priv->ScriptSize() == scripts[0][0].size() / 2, "Invalid ScriptSize() for " + prv); + CHECK((is_combo || parse_priv->ScriptSize() == scripts[0][0].size() / 2), "Invalid ScriptSize() for " + prv); // Check that the correct OutputType is inferred - BOOST_CHECK(parse_priv->GetOutputType() == type); - BOOST_CHECK(parse_pub->GetOutputType() == type); + CHECK(parse_priv->GetOutputType() == type); + CHECK(parse_pub->GetOutputType() == type); // Check private keys are extracted from the private version but not the public one. - BOOST_CHECK(keys_priv.keys.size()); - BOOST_CHECK(!keys_pub.keys.size()); + CHECK(keys_priv.keys.size()); + CHECK(!keys_pub.keys.size()); // If expected_pub is provided, check that the serialize matches that. // Otherwise check that they serialize back to the public version. std::string pub1 = parse_priv->ToString(); std::string pub2 = parse_pub->ToString(); if (expected_pub) { - BOOST_CHECK_MESSAGE(EqualDescriptor(*expected_pub, pub1), "Private ser: " + pub1 + " Public desc: " + *expected_pub); - BOOST_CHECK_MESSAGE(EqualDescriptor(*expected_pub, pub2), "Public ser: " + pub2 + " Public desc: " + *expected_pub); + CHECK(EqualDescriptor(*expected_pub, pub1), "Private ser: " + pub1 + " Public desc: " + *expected_pub); + CHECK(EqualDescriptor(*expected_pub, pub2), "Public ser: " + pub2 + " Public desc: " + *expected_pub); } else { - BOOST_CHECK_MESSAGE(EqualDescriptor(pub, pub1), "Private ser: " + pub1 + " Public desc: " + pub); - BOOST_CHECK_MESSAGE(EqualDescriptor(pub, pub2), "Public ser: " + pub2 + " Public desc: " + pub); + CHECK(EqualDescriptor(pub, pub1), "Private ser: " + pub1 + " Public desc: " + pub); + CHECK(EqualDescriptor(pub, pub2), "Public ser: " + pub2 + " Public desc: " + pub); } // Check that the COMPAT identifier did not change if (op_desc_id) { - BOOST_CHECK_MESSAGE(DescriptorID(*parse_priv) == *op_desc_id, "DescriptorID() " + DescriptorID(*parse_priv).ToString() + " does not match for priv " + prv); + CHECK(DescriptorID(*parse_priv) == *op_desc_id, "DescriptorID() " + DescriptorID(*parse_priv).ToString() + " does not match for priv " + prv); } // Check that both can be serialized with private key back to the private version, but not without private key. if (!(flags & MISSING_PRIVKEYS)) { std::string prv1; - BOOST_CHECK(parse_priv->ToPrivateString(keys_priv, prv1)); + CHECK(parse_priv->ToPrivateString(keys_priv, prv1)); if (expected_prv) { - BOOST_CHECK_MESSAGE(EqualDescriptor(*expected_prv, prv1), "Private ser: " + prv1 + "Private desc: " + *expected_prv); + CHECK(EqualDescriptor(*expected_prv, prv1), "Private ser: " + prv1 + "Private desc: " + *expected_prv); } else { - BOOST_CHECK_MESSAGE(EqualDescriptor(prv, prv1), "Private ser: " + prv1 + " Private desc: " + prv); + CHECK(EqualDescriptor(prv, prv1), "Private ser: " + prv1 + " Private desc: " + prv); } - BOOST_CHECK(!parse_priv->HavePrivateKeys(keys_pub)); - BOOST_CHECK(parse_pub->HavePrivateKeys(keys_priv)); + CHECK(!parse_priv->HavePrivateKeys(keys_pub)); + CHECK(parse_pub->HavePrivateKeys(keys_priv)); - BOOST_CHECK(!parse_priv->ToPrivateString(keys_pub, prv1)); - BOOST_CHECK(parse_pub->ToPrivateString(keys_priv, prv1)); + CHECK(!parse_priv->ToPrivateString(keys_pub, prv1)); + CHECK(parse_pub->ToPrivateString(keys_priv, prv1)); if (expected_prv) { - BOOST_CHECK(EqualDescriptor(*expected_prv, prv1)); - BOOST_CHECK_MESSAGE(EqualDescriptor(*expected_prv, prv1), "Private ser: " + prv1 + " Private desc: " + *expected_prv); + CHECK(EqualDescriptor(*expected_prv, prv1)); + CHECK(EqualDescriptor(*expected_prv, prv1), "Private ser: " + prv1 + " Private desc: " + *expected_prv); } else { - BOOST_CHECK_MESSAGE(EqualDescriptor(prv, prv1), "Private ser: " + prv1 + " Private desc: " + prv); + CHECK(EqualDescriptor(prv, prv1), "Private ser: " + prv1 + " Private desc: " + prv); } - BOOST_CHECK(!parse_pub->ToPrivateString(keys_pub, prv1)); + CHECK(!parse_pub->ToPrivateString(keys_pub, prv1)); // Check that both can ExpandPrivate and get the same SigningProviders FlatSigningProvider priv_prov; @@ -263,33 +263,33 @@ void DoCheck(std::string prv, std::string pub, const std::string& norm_pub, int FlatSigningProvider pub_prov; parse_pub->ExpandPrivate(0, keys_priv, pub_prov); - BOOST_CHECK_MESSAGE(EqualSigningProviders(priv_prov, pub_prov), "Private desc: " + prv + " Pub desc: " + pub); + CHECK(EqualSigningProviders(priv_prov, pub_prov), "Private desc: " + prv + " Pub desc: " + pub); } else if (keys_priv.keys.size() > 0) { // If there is at least one private key, ToPrivateString() should return true and include that key std::string prv_str; - BOOST_CHECK(parse_priv->ToPrivateString(keys_priv, prv_str)); + CHECK(parse_priv->ToPrivateString(keys_priv, prv_str)); size_t checksum_len = 9; // Including the '#' character - BOOST_CHECK_MESSAGE(prv == prv_str.substr(0, prv_str.length() - checksum_len), prv); + CHECK(prv == prv_str.substr(0, prv_str.length() - checksum_len), prv); } // Check that private can produce the normalized descriptors std::string norm1; - BOOST_CHECK(parse_priv->ToNormalizedString(keys_priv, norm1)); - BOOST_CHECK_MESSAGE(EqualDescriptor(norm1, norm_pub), "priv->ToNormalizedString(): " + norm1 + " Norm. desc: " + norm_pub); - BOOST_CHECK(parse_pub->ToNormalizedString(keys_priv, norm1)); - BOOST_CHECK_MESSAGE(EqualDescriptor(norm1, norm_pub), "pub->ToNormalizedString(): " + norm1 + " Norm. desc: " + norm_pub); + CHECK(parse_priv->ToNormalizedString(keys_priv, norm1)); + CHECK(EqualDescriptor(norm1, norm_pub), "priv->ToNormalizedString(): " + norm1 + " Norm. desc: " + norm_pub); + CHECK(parse_pub->ToNormalizedString(keys_priv, norm1)); + CHECK(EqualDescriptor(norm1, norm_pub), "pub->ToNormalizedString(): " + norm1 + " Norm. desc: " + norm_pub); // Check whether IsRange on both returns the expected result - BOOST_CHECK_EQUAL(parse_pub->IsRange(), (flags & RANGE) != 0); - BOOST_CHECK_EQUAL(parse_priv->IsRange(), (flags & RANGE) != 0); + CHECK(parse_pub->IsRange() == ((flags & RANGE) != 0)); + CHECK(parse_priv->IsRange() == ((flags & RANGE) != 0)); // Check that the highest key expression index matches the number of keys in the descriptor - BOOST_TEST_INFO("Pub desc: " + pub); + ; /* BOOST_TEST_INFO("Pub desc: " + pub); */ uint32_t key_exprs = parse_pub->GetMaxKeyExpr(); - BOOST_CHECK_EQUAL(key_exprs + 1, parse_pub->GetKeyCount()); - BOOST_TEST_INFO("Priv desc: " + prv); - BOOST_CHECK_EQUAL(key_exprs, parse_priv->GetMaxKeyExpr()); - BOOST_CHECK_EQUAL(key_exprs + 1, parse_priv->GetKeyCount()); + CHECK(key_exprs + 1 == parse_pub->GetKeyCount()); + ; /* BOOST_TEST_INFO("Priv desc: " + prv); */ + CHECK(key_exprs == parse_priv->GetMaxKeyExpr()); + CHECK(key_exprs + 1 == parse_priv->GetKeyCount()); // * For ranged descriptors, the `scripts` parameter is a list of expected result outputs, for subsequent // positions to evaluate the descriptors on (so the first element of `scripts` is for evaluating the @@ -314,17 +314,17 @@ void DoCheck(std::string prv, std::string pub, const std::string& norm_pub, int FlatSigningProvider script_provider, script_provider_cached; std::vector spks, spks_cached; DescriptorCache desc_cache; - BOOST_CHECK((t ? parse_priv : parse_pub)->Expand(i, key_provider, spks, script_provider, &desc_cache)); + CHECK((t ? parse_priv : parse_pub)->Expand(i, key_provider, spks, script_provider, &desc_cache)); // Compare the output with the expected result. - BOOST_CHECK_EQUAL(spks.size(), ref.size()); + CHECK(spks.size() == ref.size()); // Try to expand again using cached data, and compare. - BOOST_CHECK(parse_pub->ExpandFromCache(i, desc_cache, spks_cached, script_provider_cached)); - BOOST_CHECK(spks == spks_cached); - BOOST_CHECK(GetKeyData(script_provider, flags) == GetKeyData(script_provider_cached, flags)); - BOOST_CHECK(script_provider.scripts == script_provider_cached.scripts); - BOOST_CHECK(GetKeyOriginData(script_provider, flags) == GetKeyOriginData(script_provider_cached, flags)); + CHECK(parse_pub->ExpandFromCache(i, desc_cache, spks_cached, script_provider_cached)); + CHECK(spks == spks_cached); + CHECK(GetKeyData(script_provider, flags) == GetKeyData(script_provider_cached, flags)); + CHECK(script_provider.scripts == script_provider_cached.scripts); + CHECK(GetKeyOriginData(script_provider, flags) == GetKeyOriginData(script_provider_cached, flags)); // Check whether keys are in the cache const auto& der_xpub_cache = desc_cache.GetCachedDerivedExtPubKeys(); @@ -339,13 +339,13 @@ void DoCheck(std::string prv, std::string pub, const std::string& norm_pub, int if ((flags & RANGE) && !(flags & (DERIVE_HARDENED))) { // For ranged, unhardened derivation, None of the keys in origins should appear in the cache but the cache should have parent keys // But we can derive one level from each of those parent keys and find them all - BOOST_CHECK(der_xpub_cache.empty()); - BOOST_CHECK(parent_xpub_cache.size() > 0); + CHECK(der_xpub_cache.empty()); + CHECK(parent_xpub_cache.size() > 0U); std::set pubkeys; for (const auto& xpub_pair : parent_xpub_cache) { const CExtPubKey& xpub = xpub_pair.second; CExtPubKey der; - BOOST_CHECK(xpub.Derive(der, i)); + CHECK(xpub.Derive(der, i)); pubkeys.insert(der.pubkey); } int count_pks = 0; @@ -355,25 +355,25 @@ void DoCheck(std::string prv, std::string pub, const std::string& norm_pub, int } if (flags & MUSIG_DERIVATION) { if (!(flags & MIXED_MUSIG)) { - BOOST_CHECK_EQUAL(count_pks, 1); + CHECK(count_pks == 1); } - BOOST_CHECK_EQUAL(num_xpubs, pubkeys.size()); + CHECK(num_xpubs == pubkeys.size()); } else { if (flags & MUSIG) count_pks++; // One extra key for the aggregate key that is not in the cache if (flags & MIXED_PUBKEYS) { - BOOST_CHECK_EQUAL(num_xpubs, count_pks); + CHECK(num_xpubs == count_pks); } else { - BOOST_CHECK_EQUAL(script_provider_cached.origins.size(), count_pks); + CHECK(script_provider_cached.origins.size() == count_pks); } } } else if (num_xpubs > 0) { // For ranged, hardened derivation, or not ranged, but has an xpub, all of the keys should appear in the cache - BOOST_CHECK_EQUAL(der_xpub_cache.size() + parent_xpub_cache.size(), num_xpubs); + CHECK(der_xpub_cache.size() + parent_xpub_cache.size() == num_xpubs); if (!(flags & MIXED_PUBKEYS)) { if (flags & UNIQUE_XPUBS) { - BOOST_CHECK_EQUAL(script_provider_cached.origins.size(), num_unique_xpubs); + CHECK(script_provider_cached.origins.size() == num_unique_xpubs); } else { - BOOST_CHECK_EQUAL(script_provider_cached.origins.size(), num_xpubs); + CHECK(script_provider_cached.origins.size() == num_xpubs); } } // Get all of the derived pubkeys @@ -389,7 +389,7 @@ void DoCheck(std::string prv, std::string pub, const std::string& norm_pub, int const CExtPubKey& xpub = xpub_pair.second; pubkeys.insert(xpub.pubkey); CExtPubKey der; - BOOST_CHECK(xpub.Derive(der, i)); + CHECK(xpub.Derive(der, i)); pubkeys.insert(der.pubkey); } int count_pks = 0; @@ -399,24 +399,24 @@ void DoCheck(std::string prv, std::string pub, const std::string& norm_pub, int } if (flags & MUSIG_DERIVATION && !(flags & MIXED_PUBKEYS)) { // pubkeys is one key per xpub + one derived key per xpub - BOOST_CHECK_EQUAL(2 * count_pks, pubkeys.size()); + CHECK(2 * count_pks == pubkeys.size()); if (flags & UNIQUE_XPUBS) { - BOOST_CHECK_EQUAL(2 * num_unique_xpubs, pubkeys.size()); + CHECK(2 * num_unique_xpubs == pubkeys.size()); } else { - BOOST_CHECK_EQUAL(2 * num_xpubs, pubkeys.size()); + CHECK(2 * num_xpubs == pubkeys.size()); } } else { if (flags & MUSIG) count_pks++; // One extra key for the aggregate key that is not in the cache if (flags & MIXED_PUBKEYS) { - BOOST_CHECK_EQUAL(num_xpubs, count_pks); + CHECK(num_xpubs == count_pks); } else { - BOOST_CHECK_EQUAL(script_provider_cached.origins.size(), count_pks); + CHECK(script_provider_cached.origins.size() == count_pks); } } } else if (!(flags & MIXED_PUBKEYS)) { // Only const pubkeys, nothing should be cached - BOOST_CHECK(der_xpub_cache.empty()); - BOOST_CHECK(parent_xpub_cache.empty()); + CHECK(der_xpub_cache.empty()); + CHECK(parent_xpub_cache.empty()); } // Make sure we can expand using cached xpubs for unhardened derivation @@ -424,19 +424,19 @@ void DoCheck(std::string prv, std::string pub, const std::string& norm_pub, int // Evaluate the descriptor at i + 1 FlatSigningProvider script_provider1, script_provider_cached1; std::vector spks1, spk1_from_cache; - BOOST_CHECK((t ? parse_priv : parse_pub)->Expand(i + 1, key_provider, spks1, script_provider1, nullptr)); + CHECK((t ? parse_priv : parse_pub)->Expand(i + 1, key_provider, spks1, script_provider1, nullptr)); // Try again but use the cache from expanding i. That cache won't have the pubkeys for i + 1, but will have the parent xpub for derivation. - BOOST_CHECK(parse_pub->ExpandFromCache(i + 1, desc_cache, spk1_from_cache, script_provider_cached1)); - BOOST_CHECK(spks1 == spk1_from_cache); - BOOST_CHECK(GetKeyData(script_provider1, flags) == GetKeyData(script_provider_cached1, flags)); - BOOST_CHECK(script_provider1.scripts == script_provider_cached1.scripts); - BOOST_CHECK(GetKeyOriginData(script_provider1, flags) == GetKeyOriginData(script_provider_cached1, flags)); + CHECK(parse_pub->ExpandFromCache(i + 1, desc_cache, spk1_from_cache, script_provider_cached1)); + CHECK(spks1 == spk1_from_cache); + CHECK(GetKeyData(script_provider1, flags) == GetKeyData(script_provider_cached1, flags)); + CHECK(script_provider1.scripts == script_provider_cached1.scripts); + CHECK(GetKeyOriginData(script_provider1, flags) == GetKeyOriginData(script_provider_cached1, flags)); } // For each of the produced scripts, verify solvability, and when possible, try to sign a transaction spending it. for (size_t n = 0; n < spks.size(); ++n) { - BOOST_CHECK_EQUAL(ref[n], HexStr(spks[n])); + CHECK(ref[n] == HexStr(spks[n])); if (flags & (SIGNABLE | SIGNABLE_FAILS)) { CMutableTransaction spend; @@ -455,32 +455,32 @@ void DoCheck(std::string prv, std::string pub, const std::string& norm_pub, int sigdata.ripemd160_preimages = preimages; sigdata.hash160_preimages = preimages; const auto prod_sig_res = ProduceSignature(FlatSigningProvider{keys_priv}.Merge(FlatSigningProvider{script_provider}), creator, spks[n], sigdata); - BOOST_CHECK_MESSAGE(prod_sig_res == !(flags & SIGNABLE_FAILS), prv); + CHECK(prod_sig_res == !(flags & SIGNABLE_FAILS), prv); } /* Infer a descriptor from the generated script, and verify its solvability and that it roundtrips. */ auto inferred = InferDescriptor(spks[n], script_provider); - BOOST_CHECK_EQUAL(inferred->IsSolvable(), !(flags & UNSOLVABLE)); + CHECK(inferred->IsSolvable() == !(flags & UNSOLVABLE)); std::vector spks_inferred; FlatSigningProvider provider_inferred; - BOOST_CHECK(inferred->Expand(0, provider_inferred, spks_inferred, provider_inferred)); - BOOST_CHECK_EQUAL(spks_inferred.size(), 1U); - BOOST_CHECK(spks_inferred[0] == spks[n]); - BOOST_CHECK_EQUAL(InferDescriptor(spks_inferred[0], provider_inferred)->IsSolvable(), !(flags & UNSOLVABLE)); - BOOST_CHECK(GetKeyOriginData(provider_inferred, flags) == GetKeyOriginData(script_provider, flags)); + CHECK(inferred->Expand(0, provider_inferred, spks_inferred, provider_inferred)); + CHECK(spks_inferred.size() == 1U); + CHECK(spks_inferred[0] == spks[n]); + CHECK(InferDescriptor(spks_inferred[0], provider_inferred)->IsSolvable() == !(flags & UNSOLVABLE)); + CHECK(GetKeyOriginData(provider_inferred, flags) == GetKeyOriginData(script_provider, flags)); } // Test whether the observed key path is present in the 'paths' variable (which contains expected, unobserved paths), // and then remove it from that set. for (const auto& origin : script_provider.origins) { - BOOST_CHECK_MESSAGE(paths.contains(origin.second.second.path), "Unexpected key path: " + prv); + CHECK(paths.contains(origin.second.second.path), "Unexpected key path: " + prv); left_paths.erase(origin.second.second.path); } } } // Verify no expected paths remain that were not observed. - BOOST_CHECK_MESSAGE(left_paths.empty(), "Not all expected key paths found: " + prv); + CHECK(left_paths.empty(), "Not all expected key paths found: " + prv); } void Check(const std::string& prv, const std::string& pub, const std::string& norm_pub, int flags, @@ -582,14 +582,14 @@ void CheckInferDescriptor(const std::string& script_hex, const std::string& expe std::string checksum{GetDescriptorChecksum(expected_desc)}; std::unique_ptr desc = InferDescriptor(script, provider); - BOOST_CHECK_EQUAL(desc->ToString(), expected_desc + "#" + checksum); + CHECK(desc->ToString() == expected_desc + "#" + checksum); } } -BOOST_FIXTURE_TEST_SUITE(descriptor_tests, BasicTestingSetup) +TEST_SUITE_BEGIN("descriptor_tests") -BOOST_AUTO_TEST_CASE(descriptor_test) +FIXTURE_TEST_CASE("descriptor_test", BasicTestingSetup) { // Basic single-key compressed Check("combo(L4rK1yDtCWekvXuE6oXD9jCYfFNV2cWRpVuPLBcCU2z8TrisoyY1)", "combo(03a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd)", "combo(03a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd)", SIGNABLE, {{"2103a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bdac","76a9149a1c78a507689f6f54b847ad1cef1e614ee23f1e88ac","00149a1c78a507689f6f54b847ad1cef1e614ee23f1e","a91484ab21b1b2fd065d4504ff693d832434b6108d7b87"}}, std::nullopt, /*op_desc_id=*/uint256{"8ef71f7b6ac0918663f6706be469d6109f6922e21f484009d7ab49d77da36e8b"}); @@ -1279,24 +1279,24 @@ BOOST_AUTO_TEST_CASE(descriptor_test) CheckUnparsable("tr(musig(tuus(oldepk(gg)ggggfgg)<,z(((((((((((((((((((((st)", "tr(musig(tuus(oldepk(gg)ggggfgg)<,z(((((((((((((((((((((st)","tr(): Too many ')' in musig() expression"); } -BOOST_AUTO_TEST_CASE(descriptor_literal_null_byte) +FIXTURE_TEST_CASE("descriptor_literal_null_byte", BasicTestingSetup) { // Trailing '\0' string literal should be ignored. FlatSigningProvider keys; std::string err; auto descs = Parse("pk(0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798)", keys, err, /*require_checksum=*/false); - BOOST_REQUIRE_MESSAGE(!descs.empty(), err); + REQUIRE(!descs.empty(), err); } -BOOST_AUTO_TEST_CASE(descriptor_older_warnings) +FIXTURE_TEST_CASE("descriptor_older_warnings", BasicTestingSetup) { // A safe boundary value should yield no warnings. { FlatSigningProvider keys; std::string err; auto descs = Parse("wsh(and_v(v:pk(0379e45b3cf75f9c5f9befd8e9506fb962f6a9d185ac87001ec44a8d3df8d4a9e3),older(65535)))", keys, err, /*require_checksum=*/false); - BOOST_REQUIRE_MESSAGE(!descs.empty(), err); - BOOST_CHECK(descs[0]->Warnings().empty()); + REQUIRE(!descs.empty(), err); + CHECK(descs[0]->Warnings().empty()); } // Height-based unsafe value (65536) should produce one warning. @@ -1305,10 +1305,10 @@ BOOST_AUTO_TEST_CASE(descriptor_older_warnings) std::string err; const uint32_t height_unsafe = 65536; auto descs = Parse(strprintf("wsh(and_v(v:pk(0379e45b3cf75f9c5f9befd8e9506fb962f6a9d185ac87001ec44a8d3df8d4a9e3),older(%u)))", height_unsafe), keys, err, /*require_checksum=*/false); - BOOST_REQUIRE_MESSAGE(!descs.empty(), err); + REQUIRE(!descs.empty(), err); const auto& ws = descs[0]->Warnings(); - BOOST_REQUIRE_EQUAL(ws.size(), 1U); - BOOST_CHECK_EQUAL(ws[0], strprintf("height-based relative locktime: older(%u) > 65535 blocks is unsafe", height_unsafe)); + REQUIRE(ws.size() == 1U); + CHECK(ws[0] == strprintf("height-based relative locktime: older(%u) > 65535 blocks is unsafe", height_unsafe)); } // Time-based unsafe value: add SEQUENCE_LOCKTIME_TYPE_FLAG (1<<22) @@ -1317,10 +1317,10 @@ BOOST_AUTO_TEST_CASE(descriptor_older_warnings) std::string err; const uint32_t time_unsafe = 65536 | CTxIn::SEQUENCE_LOCKTIME_TYPE_FLAG; auto descs = Parse(strprintf("wsh(and_v(v:pk(0379e45b3cf75f9c5f9befd8e9506fb962f6a9d185ac87001ec44a8d3df8d4a9e3),older(%u)))", time_unsafe), keys, err, /*require_checksum=*/false); - BOOST_REQUIRE_MESSAGE(!descs.empty(), err); + REQUIRE(!descs.empty(), err); const auto& warnings = descs[0]->Warnings(); - BOOST_REQUIRE_EQUAL(warnings.size(), 1U); - BOOST_CHECK_EQUAL(warnings[0], strprintf("time-based relative locktime: older(%u) > (65535 * 512) seconds is unsafe", time_unsafe)); + REQUIRE(warnings.size() == 1U); + CHECK(warnings[0] == strprintf("time-based relative locktime: older(%u) > (65535 * 512) seconds is unsafe", time_unsafe)); } // Ensure no false positive warnings for absolute timelocks @@ -1329,9 +1329,9 @@ BOOST_AUTO_TEST_CASE(descriptor_older_warnings) std::string err; // Using after() with a large timestamp (> 65535) auto descs = Parse("wsh(and_v(v:pk(0379e45b3cf75f9c5f9befd8e9506fb962f6a9d185ac87001ec44a8d3df8d4a9e3),after(1000000)))", keys, err, /*require_checksum=*/false); - BOOST_REQUIRE_MESSAGE(!descs.empty(), err); - BOOST_CHECK(descs[0]->Warnings().empty()); + REQUIRE(!descs.empty(), err); + CHECK(descs[0]->Warnings().empty()); } } -BOOST_AUTO_TEST_SUITE_END() +TEST_SUITE_END() diff --git a/src/test/disconnected_transactions.cpp b/src/test/disconnected_transactions.cpp index 076d81cfb351..9faa81b689da 100644 --- a/src/test/disconnected_transactions.cpp +++ b/src/test/disconnected_transactions.cpp @@ -2,21 +2,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. // -#include +#include #include #include #include -BOOST_AUTO_TEST_SUITE(disconnected_transactions) +TEST_SUITE_BEGIN("disconnected_transactions") //! Tests that DisconnectedBlockTransactions limits its own memory properly -BOOST_FIXTURE_TEST_CASE(disconnectpool_memory_limits, TestChain100Setup) +FIXTURE_TEST_CASE("disconnectpool_memory_limits", TestChain100Setup) { // Use the coinbase transactions from TestChain100Setup. It doesn't matter whether these // transactions would realistically be in a block together, they just need distinct txids and // uniform size for this test to work. std::vector block_vtx(m_coinbase_txns); - BOOST_CHECK_EQUAL(block_vtx.size(), 100); + CHECK(block_vtx.size() == 100U); // Roughly estimate sizes to sanity check that DisconnectedBlockTransactions::DynamicMemoryUsage // is within an expected range. @@ -30,7 +30,7 @@ BOOST_FIXTURE_TEST_CASE(disconnectpool_memory_limits, TestChain100Setup) const size_t TX_USAGE{RecursiveDynamicUsage(block_vtx.front())}; for (const auto& tx : block_vtx) - BOOST_CHECK_EQUAL(RecursiveDynamicUsage(tx), TX_USAGE); + CHECK(RecursiveDynamicUsage(tx) == TX_USAGE); // Our overall formula is unordered map overhead + usage per entry. // Implementations may vary, but we're trying to guess the usage of data structures. @@ -49,12 +49,12 @@ BOOST_FIXTURE_TEST_CASE(disconnectpool_memory_limits, TestChain100Setup) // to a minimum and avoid all (instead of all but 1) transactions getting evicted. std::vector two_txns({block_vtx.at(0), block_vtx.at(1)}); auto evicted_txns{disconnectpool.AddTransactionsFromBlock(two_txns)}; - BOOST_CHECK(disconnectpool.DynamicMemoryUsage() <= MAP_1 + ENTRY_USAGE_ESTIMATE); + CHECK(disconnectpool.DynamicMemoryUsage() <= MAP_1 + ENTRY_USAGE_ESTIMATE); // Only 1 transaction can be kept - BOOST_CHECK_EQUAL(1, evicted_txns.size()); + CHECK(1U == evicted_txns.size()); // Transactions are added from back to front and eviction is FIFO. - BOOST_CHECK_EQUAL(block_vtx.at(1), evicted_txns.front()); + CHECK(block_vtx.at(1) == evicted_txns.front()); disconnectpool.clear(); } @@ -66,8 +66,8 @@ BOOST_FIXTURE_TEST_CASE(disconnectpool_memory_limits, TestChain100Setup) const size_t USAGE_100_OVERESTIMATE{MAP_100 + ENTRY_USAGE_ESTIMATE * 100}; DisconnectedBlockTransactions disconnectpool{USAGE_100_OVERESTIMATE}; auto evicted_txns{disconnectpool.AddTransactionsFromBlock(block_vtx)}; - BOOST_CHECK_EQUAL(evicted_txns.size(), 0); - BOOST_CHECK(disconnectpool.DynamicMemoryUsage() <= USAGE_100_OVERESTIMATE); + CHECK(evicted_txns.size() == 0U); + CHECK(disconnectpool.DynamicMemoryUsage() <= USAGE_100_OVERESTIMATE); usage_full = disconnectpool.DynamicMemoryUsage(); @@ -79,17 +79,17 @@ BOOST_FIXTURE_TEST_CASE(disconnectpool_memory_limits, TestChain100Setup) const size_t MAX_MEMUSAGE_99{usage_full - sizeof(void*)}; DisconnectedBlockTransactions disconnectpool{MAX_MEMUSAGE_99}; auto evicted_txns{disconnectpool.AddTransactionsFromBlock(block_vtx)}; - BOOST_CHECK(disconnectpool.DynamicMemoryUsage() <= MAX_MEMUSAGE_99); + CHECK(disconnectpool.DynamicMemoryUsage() <= MAX_MEMUSAGE_99); // Only 1 transaction needed to be evicted - BOOST_CHECK_EQUAL(1, evicted_txns.size()); + CHECK(1U == evicted_txns.size()); // Transactions are added from back to front and eviction is FIFO. // The last transaction of block_vtx should be the first to be evicted. - BOOST_CHECK_EQUAL(block_vtx.back(), evicted_txns.front()); + CHECK(block_vtx.back() == evicted_txns.front()); disconnectpool.clear(); } } -BOOST_AUTO_TEST_SUITE_END() +TEST_SUITE_END() diff --git a/src/test/feefrac_tests.cpp b/src/test/feefrac_tests.cpp index 3d5fe0cb88cf..a842aafbbf8a 100644 --- a/src/test/feefrac_tests.cpp +++ b/src/test/feefrac_tests.cpp @@ -5,11 +5,11 @@ #include #include -#include +#include -BOOST_AUTO_TEST_SUITE(feefrac_tests) +TEST_SUITE_BEGIN("feefrac_tests") -BOOST_AUTO_TEST_CASE(feefrac_operators) +TEST_CASE("feefrac_operators") { FeeFrac p1{1000, 100}, p2{500, 300}; FeeFrac sum{1500, 400}; @@ -17,139 +17,139 @@ BOOST_AUTO_TEST_CASE(feefrac_operators) FeeFrac empty{0, 0}; FeeFrac zero_fee{0, 1}; // zero-fee allowed - BOOST_CHECK_EQUAL(zero_fee.EvaluateFeeDown(0), 0); - BOOST_CHECK_EQUAL(zero_fee.EvaluateFeeDown(1), 0); - BOOST_CHECK_EQUAL(zero_fee.EvaluateFeeDown(1000000), 0); - BOOST_CHECK_EQUAL(zero_fee.EvaluateFeeDown(0x7fffffff), 0); - BOOST_CHECK_EQUAL(zero_fee.EvaluateFeeUp(0), 0); - BOOST_CHECK_EQUAL(zero_fee.EvaluateFeeUp(1), 0); - BOOST_CHECK_EQUAL(zero_fee.EvaluateFeeUp(1000000), 0); - BOOST_CHECK_EQUAL(zero_fee.EvaluateFeeUp(0x7fffffff), 0); - - BOOST_CHECK_EQUAL(p1.EvaluateFeeDown(0), 0); - BOOST_CHECK_EQUAL(p1.EvaluateFeeDown(1), 10); - BOOST_CHECK_EQUAL(p1.EvaluateFeeDown(100000000), 1000000000); - BOOST_CHECK_EQUAL(p1.EvaluateFeeDown(0x7fffffff), int64_t(0x7fffffff) * 10); - BOOST_CHECK_EQUAL(p1.EvaluateFeeUp(0), 0); - BOOST_CHECK_EQUAL(p1.EvaluateFeeUp(1), 10); - BOOST_CHECK_EQUAL(p1.EvaluateFeeUp(100000000), 1000000000); - BOOST_CHECK_EQUAL(p1.EvaluateFeeUp(0x7fffffff), int64_t(0x7fffffff) * 10); + CHECK(zero_fee.EvaluateFeeDown(0) == 0); + CHECK(zero_fee.EvaluateFeeDown(1) == 0); + CHECK(zero_fee.EvaluateFeeDown(1000000) == 0); + CHECK(zero_fee.EvaluateFeeDown(0x7fffffff) == 0); + CHECK(zero_fee.EvaluateFeeUp(0) == 0); + CHECK(zero_fee.EvaluateFeeUp(1) == 0); + CHECK(zero_fee.EvaluateFeeUp(1000000) == 0); + CHECK(zero_fee.EvaluateFeeUp(0x7fffffff) == 0); + + CHECK(p1.EvaluateFeeDown(0) == 0); + CHECK(p1.EvaluateFeeDown(1) == 10); + CHECK(p1.EvaluateFeeDown(100000000) == 1000000000); + CHECK(p1.EvaluateFeeDown(0x7fffffff) == int64_t(0x7fffffff) * 10); + CHECK(p1.EvaluateFeeUp(0) == 0); + CHECK(p1.EvaluateFeeUp(1) == 10); + CHECK(p1.EvaluateFeeUp(100000000) == 1000000000); + CHECK(p1.EvaluateFeeUp(0x7fffffff) == int64_t(0x7fffffff) * 10); FeeFrac neg{-1001, 100}; - BOOST_CHECK_EQUAL(neg.EvaluateFeeDown(0), 0); - BOOST_CHECK_EQUAL(neg.EvaluateFeeDown(1), -11); - BOOST_CHECK_EQUAL(neg.EvaluateFeeDown(2), -21); - BOOST_CHECK_EQUAL(neg.EvaluateFeeDown(3), -31); - BOOST_CHECK_EQUAL(neg.EvaluateFeeDown(100), -1001); - BOOST_CHECK_EQUAL(neg.EvaluateFeeDown(101), -1012); - BOOST_CHECK_EQUAL(neg.EvaluateFeeDown(100000000), -1001000000); - BOOST_CHECK_EQUAL(neg.EvaluateFeeDown(100000001), -1001000011); - BOOST_CHECK_EQUAL(neg.EvaluateFeeDown(0x7fffffff), -21496311307); - BOOST_CHECK_EQUAL(neg.EvaluateFeeUp(0), 0); - BOOST_CHECK_EQUAL(neg.EvaluateFeeUp(1), -10); - BOOST_CHECK_EQUAL(neg.EvaluateFeeUp(2), -20); - BOOST_CHECK_EQUAL(neg.EvaluateFeeUp(3), -30); - BOOST_CHECK_EQUAL(neg.EvaluateFeeUp(100), -1001); - BOOST_CHECK_EQUAL(neg.EvaluateFeeUp(101), -1011); - BOOST_CHECK_EQUAL(neg.EvaluateFeeUp(100000000), -1001000000); - BOOST_CHECK_EQUAL(neg.EvaluateFeeUp(100000001), -1001000010); - BOOST_CHECK_EQUAL(neg.EvaluateFeeUp(0x7fffffff), -21496311306); - - BOOST_CHECK(empty == FeeFrac{}); // same as no-args - - BOOST_CHECK(p1 == p1); - BOOST_CHECK(p1 + p2 == sum); - BOOST_CHECK(p1 - p2 == diff); + CHECK(neg.EvaluateFeeDown(0) == 0); + CHECK(neg.EvaluateFeeDown(1) == -11); + CHECK(neg.EvaluateFeeDown(2) == -21); + CHECK(neg.EvaluateFeeDown(3) == -31); + CHECK(neg.EvaluateFeeDown(100) == -1001); + CHECK(neg.EvaluateFeeDown(101) == -1012); + CHECK(neg.EvaluateFeeDown(100000000) == -1001000000); + CHECK(neg.EvaluateFeeDown(100000001) == -1001000011); + CHECK(neg.EvaluateFeeDown(0x7fffffff) == -21496311307); + CHECK(neg.EvaluateFeeUp(0) == 0); + CHECK(neg.EvaluateFeeUp(1) == -10); + CHECK(neg.EvaluateFeeUp(2) == -20); + CHECK(neg.EvaluateFeeUp(3) == -30); + CHECK(neg.EvaluateFeeUp(100) == -1001); + CHECK(neg.EvaluateFeeUp(101) == -1011); + CHECK(neg.EvaluateFeeUp(100000000) == -1001000000); + CHECK(neg.EvaluateFeeUp(100000001) == -1001000010); + CHECK(neg.EvaluateFeeUp(0x7fffffff) == -21496311306); + + CHECK(empty == FeeFrac{}); // same as no-args + + CHECK(p1 == p1); + CHECK(p1 + p2 == sum); + CHECK(p1 - p2 == diff); FeeFrac p3{2000, 200}; - BOOST_CHECK(p1 != p3); // feefracs only equal if both fee and size are same - BOOST_CHECK(p2 != p3); + CHECK(p1 != p3); // feefracs only equal if both fee and size are same + CHECK(p2 != p3); FeeFrac p4{3000, 300}; - BOOST_CHECK(p1 == p4-p3); - BOOST_CHECK(p1 + p3 == p4); + CHECK(p1 == p4-p3); + CHECK(p1 + p3 == p4); // Fee-rate comparison - BOOST_CHECK(ByRatioNegSize{p1} > ByRatioNegSize{p2}); - BOOST_CHECK(ByRatioNegSize{p1} >= ByRatioNegSize{p2}); - BOOST_CHECK(ByRatioNegSize{p1} >= ByRatioNegSize{p4-p3}); - BOOST_CHECK(!(ByRatio{p1} > ByRatio{p3})); // not strictly better - BOOST_CHECK(ByRatio{p1} > ByRatio{p2}); // strictly greater feerate - - BOOST_CHECK(ByRatioNegSize{p2} < ByRatioNegSize{p1}); - BOOST_CHECK(ByRatioNegSize{p2} <= ByRatioNegSize{p1}); - BOOST_CHECK(ByRatioNegSize{p1} <= ByRatioNegSize{p4-p3}); - BOOST_CHECK(!(ByRatio{p3} < ByRatio{p1})); // not strictly worse - BOOST_CHECK(ByRatio{p2} < ByRatio{p1}); // strictly lower feerate + CHECK(ByRatioNegSize{p1} > ByRatioNegSize{p2}); + CHECK(ByRatioNegSize{p1} >= ByRatioNegSize{p2}); + CHECK(ByRatioNegSize{p1} >= ByRatioNegSize{p4-p3}); + CHECK(!(ByRatio{p1} > ByRatio{p3})); // not strictly better + CHECK(ByRatio{p1} > ByRatio{p2}); // strictly greater feerate + + CHECK(ByRatioNegSize{p2} < ByRatioNegSize{p1}); + CHECK(ByRatioNegSize{p2} <= ByRatioNegSize{p1}); + CHECK(ByRatioNegSize{p1} <= ByRatioNegSize{p4-p3}); + CHECK(!(ByRatio{p3} < ByRatio{p1})); // not strictly worse + CHECK(ByRatio{p2} < ByRatio{p1}); // strictly lower feerate // "empty" comparisons - BOOST_CHECK(!(ByRatio{p1} > ByRatio{empty})); // << will always result in false - BOOST_CHECK(!(ByRatio{p1} < ByRatio{empty})); - BOOST_CHECK(!(ByRatio{empty} > ByRatio{empty})); - BOOST_CHECK(!(ByRatio{empty} < ByRatio{empty})); + CHECK(!(ByRatio{p1} > ByRatio{empty})); // << will always result in false + CHECK(!(ByRatio{p1} < ByRatio{empty})); + CHECK(!(ByRatio{empty} > ByRatio{empty})); + CHECK(!(ByRatio{empty} < ByRatio{empty})); // empty is always bigger than everything else - BOOST_CHECK(ByRatioNegSize{empty} > ByRatioNegSize{p1}); - BOOST_CHECK(ByRatioNegSize{empty} > ByRatioNegSize{p2}); - BOOST_CHECK(ByRatioNegSize{empty} > ByRatioNegSize{p3}); - BOOST_CHECK(ByRatioNegSize{empty} >= ByRatioNegSize{p1}); - BOOST_CHECK(ByRatioNegSize{empty} >= ByRatioNegSize{p2}); - BOOST_CHECK(ByRatioNegSize{empty} >= ByRatioNegSize{p3}); + CHECK(ByRatioNegSize{empty} > ByRatioNegSize{p1}); + CHECK(ByRatioNegSize{empty} > ByRatioNegSize{p2}); + CHECK(ByRatioNegSize{empty} > ByRatioNegSize{p3}); + CHECK(ByRatioNegSize{empty} >= ByRatioNegSize{p1}); + CHECK(ByRatioNegSize{empty} >= ByRatioNegSize{p2}); + CHECK(ByRatioNegSize{empty} >= ByRatioNegSize{p3}); // check "max" values for comparison FeeFrac oversized_1{4611686000000, 4000000}; FeeFrac oversized_2{184467440000000, 100000}; - BOOST_CHECK(ByRatioNegSize{oversized_1} < ByRatioNegSize{oversized_2}); - BOOST_CHECK(ByRatioNegSize{oversized_1} <= ByRatioNegSize{oversized_2}); - BOOST_CHECK(ByRatio{oversized_1} < ByRatio{oversized_2}); - BOOST_CHECK(ByRatioNegSize{oversized_1} != ByRatioNegSize{oversized_2}); + CHECK(ByRatioNegSize{oversized_1} < ByRatioNegSize{oversized_2}); + CHECK(ByRatioNegSize{oversized_1} <= ByRatioNegSize{oversized_2}); + CHECK(ByRatio{oversized_1} < ByRatio{oversized_2}); + CHECK(ByRatioNegSize{oversized_1} != ByRatioNegSize{oversized_2}); - BOOST_CHECK_EQUAL(oversized_1.EvaluateFeeDown(0), 0); - BOOST_CHECK_EQUAL(oversized_1.EvaluateFeeDown(1), 1152921); - BOOST_CHECK_EQUAL(oversized_1.EvaluateFeeDown(2), 2305843); - BOOST_CHECK_EQUAL(oversized_1.EvaluateFeeDown(1548031267), 1784758530396540); - BOOST_CHECK_EQUAL(oversized_1.EvaluateFeeUp(0), 0); - BOOST_CHECK_EQUAL(oversized_1.EvaluateFeeUp(1), 1152922); - BOOST_CHECK_EQUAL(oversized_1.EvaluateFeeUp(2), 2305843); - BOOST_CHECK_EQUAL(oversized_1.EvaluateFeeUp(1548031267), 1784758530396541); + CHECK(oversized_1.EvaluateFeeDown(0) == 0); + CHECK(oversized_1.EvaluateFeeDown(1) == 1152921); + CHECK(oversized_1.EvaluateFeeDown(2) == 2305843); + CHECK(oversized_1.EvaluateFeeDown(1548031267) == 1784758530396540); + CHECK(oversized_1.EvaluateFeeUp(0) == 0); + CHECK(oversized_1.EvaluateFeeUp(1) == 1152922); + CHECK(oversized_1.EvaluateFeeUp(2) == 2305843); + CHECK(oversized_1.EvaluateFeeUp(1548031267) == 1784758530396541); // Test cases on the threshold where FeeFrac::Evaluate start using Mul/Div. - BOOST_CHECK_EQUAL(FeeFrac(0x1ffffffff, 123456789).EvaluateFeeDown(98765432), 6871947728); - BOOST_CHECK_EQUAL(FeeFrac(0x200000000, 123456789).EvaluateFeeDown(98765432), 6871947729); - BOOST_CHECK_EQUAL(FeeFrac(0x200000001, 123456789).EvaluateFeeDown(98765432), 6871947730); - BOOST_CHECK_EQUAL(FeeFrac(0x1ffffffff, 123456789).EvaluateFeeUp(98765432), 6871947729); - BOOST_CHECK_EQUAL(FeeFrac(0x200000000, 123456789).EvaluateFeeUp(98765432), 6871947730); - BOOST_CHECK_EQUAL(FeeFrac(0x200000001, 123456789).EvaluateFeeUp(98765432), 6871947731); + CHECK(FeeFrac(0x1ffffffff, 123456789).EvaluateFeeDown(98765432) == 6871947728); + CHECK(FeeFrac(0x200000000, 123456789).EvaluateFeeDown(98765432) == 6871947729); + CHECK(FeeFrac(0x200000001, 123456789).EvaluateFeeDown(98765432) == 6871947730); + CHECK(FeeFrac(0x1ffffffff, 123456789).EvaluateFeeUp(98765432) == 6871947729); + CHECK(FeeFrac(0x200000000, 123456789).EvaluateFeeUp(98765432) == 6871947730); + CHECK(FeeFrac(0x200000001, 123456789).EvaluateFeeUp(98765432) == 6871947731); // Tests paths that use double arithmetic FeeFrac busted{(static_cast(INT32_MAX)) + 1, INT32_MAX}; - BOOST_CHECK(!(ByRatioNegSize{busted} < ByRatioNegSize{busted})); + CHECK(!(ByRatioNegSize{busted} < ByRatioNegSize{busted})); FeeFrac max_fee{2100000000000000, INT32_MAX}; - BOOST_CHECK(!(ByRatioNegSize{max_fee} < ByRatioNegSize{max_fee})); - BOOST_CHECK(!(ByRatioNegSize{max_fee} > ByRatioNegSize{max_fee})); - BOOST_CHECK(ByRatioNegSize{max_fee} <= ByRatioNegSize{max_fee}); - BOOST_CHECK(ByRatioNegSize{max_fee} >= ByRatioNegSize{max_fee}); - - BOOST_CHECK_EQUAL(max_fee.EvaluateFeeDown(0), 0); - BOOST_CHECK_EQUAL(max_fee.EvaluateFeeDown(1), 977888); - BOOST_CHECK_EQUAL(max_fee.EvaluateFeeDown(2), 1955777); - BOOST_CHECK_EQUAL(max_fee.EvaluateFeeDown(3), 2933666); - BOOST_CHECK_EQUAL(max_fee.EvaluateFeeDown(1256796054), 1229006664189047); - BOOST_CHECK_EQUAL(max_fee.EvaluateFeeDown(INT32_MAX), 2100000000000000); - BOOST_CHECK_EQUAL(max_fee.EvaluateFeeUp(0), 0); - BOOST_CHECK_EQUAL(max_fee.EvaluateFeeUp(1), 977889); - BOOST_CHECK_EQUAL(max_fee.EvaluateFeeUp(2), 1955778); - BOOST_CHECK_EQUAL(max_fee.EvaluateFeeUp(3), 2933667); - BOOST_CHECK_EQUAL(max_fee.EvaluateFeeUp(1256796054), 1229006664189048); - BOOST_CHECK_EQUAL(max_fee.EvaluateFeeUp(INT32_MAX), 2100000000000000); + CHECK(!(ByRatioNegSize{max_fee} < ByRatioNegSize{max_fee})); + CHECK(!(ByRatioNegSize{max_fee} > ByRatioNegSize{max_fee})); + CHECK(ByRatioNegSize{max_fee} <= ByRatioNegSize{max_fee}); + CHECK(ByRatioNegSize{max_fee} >= ByRatioNegSize{max_fee}); + + CHECK(max_fee.EvaluateFeeDown(0) == 0); + CHECK(max_fee.EvaluateFeeDown(1) == 977888); + CHECK(max_fee.EvaluateFeeDown(2) == 1955777); + CHECK(max_fee.EvaluateFeeDown(3) == 2933666); + CHECK(max_fee.EvaluateFeeDown(1256796054) == 1229006664189047); + CHECK(max_fee.EvaluateFeeDown(INT32_MAX) == 2100000000000000); + CHECK(max_fee.EvaluateFeeUp(0) == 0); + CHECK(max_fee.EvaluateFeeUp(1) == 977889); + CHECK(max_fee.EvaluateFeeUp(2) == 1955778); + CHECK(max_fee.EvaluateFeeUp(3) == 2933667); + CHECK(max_fee.EvaluateFeeUp(1256796054) == 1229006664189048); + CHECK(max_fee.EvaluateFeeUp(INT32_MAX) == 2100000000000000); FeeFrac max_fee2{1, 1}; - BOOST_CHECK(ByRatioNegSize{max_fee} >= ByRatioNegSize{max_fee2}); + CHECK(ByRatioNegSize{max_fee} >= ByRatioNegSize{max_fee2}); // Test for integer overflow issue (https://github.com/bitcoin/bitcoin/issues/32294) - BOOST_CHECK_EQUAL((FeeFrac{0x7ffffffdfffffffb, 0x7ffffffd}.EvaluateFeeDown(0x7fffffff)), 0x7fffffffffffffff); + CHECK((FeeFrac{0x7ffffffdfffffffb, 0x7ffffffd}.EvaluateFeeDown(0x7fffffff)) == 0x7fffffffffffffff); } -BOOST_AUTO_TEST_SUITE_END() +TEST_SUITE_END() diff --git a/src/test/feerounder_tests.cpp b/src/test/feerounder_tests.cpp index 82cd7d65b409..d20d8883cae1 100644 --- a/src/test/feerounder_tests.cpp +++ b/src/test/feerounder_tests.cpp @@ -5,13 +5,13 @@ #include #include -#include +#include #include -BOOST_AUTO_TEST_SUITE(fee_rounder_tests) +TEST_SUITE_BEGIN("feerounder_tests") -BOOST_AUTO_TEST_CASE(FeeRounder) +TEST_CASE("FeeRounder") { FastRandomContext rng{/*fDeterministic=*/true}; FeeFilterRounder fee_rounder{CFeeRate{1000}, rng}; @@ -21,15 +21,15 @@ BOOST_AUTO_TEST_CASE(FeeRounder) while (results.size() < 2) { results.emplace(fee_rounder.round(1000)); } - BOOST_CHECK_EQUAL(*results.begin(), 974); - BOOST_CHECK_EQUAL(*++results.begin(), 1071); + CHECK(*results.begin() == 974); + CHECK(*++results.begin() == 1071); // check that negative amounts rounds to 0 - BOOST_CHECK_EQUAL(fee_rounder.round(-0), 0); - BOOST_CHECK_EQUAL(fee_rounder.round(-1), 0); + CHECK(fee_rounder.round(-0) == 0); + CHECK(fee_rounder.round(-1) == 0); // check that MAX_MONEY rounds to 9170997 - BOOST_CHECK_EQUAL(fee_rounder.round(MAX_MONEY), 9170997); + CHECK(fee_rounder.round(MAX_MONEY) == 9170997); } -BOOST_AUTO_TEST_SUITE_END() +TEST_SUITE_END() diff --git a/src/test/flatfile_tests.cpp b/src/test/flatfile_tests.cpp index a14c7c635e41..56e7315f16d1 100644 --- a/src/test/flatfile_tests.cpp +++ b/src/test/flatfile_tests.cpp @@ -8,27 +8,27 @@ #include #include -#include +#include -BOOST_FIXTURE_TEST_SUITE(flatfile_tests, BasicTestingSetup) +TEST_SUITE_BEGIN("flatfile_tests") -BOOST_AUTO_TEST_CASE(flatfile_filename) +FIXTURE_TEST_CASE("flatfile_filename", BasicTestingSetup) { const auto data_dir = m_args.GetDataDirBase(); FlatFilePos pos(456, 789); FlatFileSeq seq1(data_dir, "a", 16 * 1024); - BOOST_CHECK_EQUAL(seq1.FileName(pos), data_dir / "a00456.dat"); + CHECK(seq1.FileName(pos) == data_dir / "a00456.dat"); FlatFileSeq seq2(data_dir / "a", "b", 16 * 1024); - BOOST_CHECK_EQUAL(seq2.FileName(pos), data_dir / "a" / "b00456.dat"); + CHECK(seq2.FileName(pos) == data_dir / "a" / "b00456.dat"); // Check default constructor IsNull assert(FlatFilePos{}.IsNull()); } -BOOST_AUTO_TEST_CASE(flatfile_open) +FIXTURE_TEST_CASE("flatfile_open", BasicTestingSetup) { const auto data_dir = m_args.GetDataDirBase(); FlatFileSeq seq(data_dir, "a", 16 * 1024); @@ -46,20 +46,20 @@ BOOST_AUTO_TEST_CASE(flatfile_open) { AutoFile file{seq.Open(FlatFilePos(0, pos1))}; file << LIMITED_STRING(line1, 256); - BOOST_REQUIRE_EQUAL(file.fclose(), 0); + REQUIRE(file.fclose() == 0); } // Attempt to append to file opened in read-only mode. { AutoFile file{seq.Open(FlatFilePos(0, pos2), true)}; - BOOST_CHECK_THROW(file << LIMITED_STRING(line2, 256), std::ios_base::failure); + CHECK_THROWS_AS(file << LIMITED_STRING(line2, 256), std::ios_base::failure); } // Append second line to file. { AutoFile file{seq.Open(FlatFilePos(0, pos2))}; file << LIMITED_STRING(line2, 256); - BOOST_REQUIRE_EQUAL(file.fclose(), 0); + REQUIRE(file.fclose() == 0); } // Read text from file in read-only mode. @@ -68,10 +68,10 @@ BOOST_AUTO_TEST_CASE(flatfile_open) AutoFile file{seq.Open(FlatFilePos(0, pos1), true)}; file >> LIMITED_STRING(text, 256); - BOOST_CHECK_EQUAL(text, line1); + CHECK(text == line1); file >> LIMITED_STRING(text, 256); - BOOST_CHECK_EQUAL(text, line2); + CHECK(text == line2); } // Read text from file with position offset. @@ -80,40 +80,40 @@ BOOST_AUTO_TEST_CASE(flatfile_open) AutoFile file{seq.Open(FlatFilePos(0, pos2))}; file >> LIMITED_STRING(text, 256); - BOOST_CHECK_EQUAL(text, line2); - BOOST_REQUIRE_EQUAL(file.fclose(), 0); + CHECK(text == line2); + REQUIRE(file.fclose() == 0); } // Ensure another file in the sequence has no data. { std::string text; AutoFile file{seq.Open(FlatFilePos(1, pos2))}; - BOOST_CHECK_THROW(file >> LIMITED_STRING(text, 256), std::ios_base::failure); - BOOST_REQUIRE_EQUAL(file.fclose(), 0); + CHECK_THROWS_AS(file >> LIMITED_STRING(text, 256), std::ios_base::failure); + REQUIRE(file.fclose() == 0); } } -BOOST_AUTO_TEST_CASE(flatfile_allocate) +FIXTURE_TEST_CASE("flatfile_allocate", BasicTestingSetup) { const auto data_dir = m_args.GetDataDirBase(); FlatFileSeq seq(data_dir, "a", 100); bool out_of_space; - BOOST_CHECK_EQUAL(seq.Allocate(FlatFilePos(0, 0), 1, out_of_space), 100U); - BOOST_CHECK_EQUAL(fs::file_size(seq.FileName(FlatFilePos(0, 0))), 100U); - BOOST_CHECK(!out_of_space); + CHECK(seq.Allocate(FlatFilePos(0, 0), 1, out_of_space) == 100U); + CHECK(fs::file_size(seq.FileName(FlatFilePos(0, 0))) == 100U); + CHECK(!out_of_space); - BOOST_CHECK_EQUAL(seq.Allocate(FlatFilePos(0, 99), 1, out_of_space), 0U); - BOOST_CHECK_EQUAL(fs::file_size(seq.FileName(FlatFilePos(0, 99))), 100U); - BOOST_CHECK(!out_of_space); + CHECK(seq.Allocate(FlatFilePos(0, 99), 1, out_of_space) == 0U); + CHECK(fs::file_size(seq.FileName(FlatFilePos(0, 99))) == 100U); + CHECK(!out_of_space); - BOOST_CHECK_EQUAL(seq.Allocate(FlatFilePos(0, 99), 2, out_of_space), 101U); - BOOST_CHECK_EQUAL(fs::file_size(seq.FileName(FlatFilePos(0, 99))), 200U); - BOOST_CHECK(!out_of_space); + CHECK(seq.Allocate(FlatFilePos(0, 99), 2, out_of_space) == 101U); + CHECK(fs::file_size(seq.FileName(FlatFilePos(0, 99))) == 200U); + CHECK(!out_of_space); } -BOOST_AUTO_TEST_CASE(flatfile_flush) +FIXTURE_TEST_CASE("flatfile_flush", BasicTestingSetup) { const auto data_dir = m_args.GetDataDirBase(); FlatFileSeq seq(data_dir, "a", 100); @@ -123,11 +123,11 @@ BOOST_AUTO_TEST_CASE(flatfile_flush) // Flush without finalize should not truncate file. seq.Flush(FlatFilePos(0, 1)); - BOOST_CHECK_EQUAL(fs::file_size(seq.FileName(FlatFilePos(0, 1))), 100U); + CHECK(fs::file_size(seq.FileName(FlatFilePos(0, 1))) == 100U); // Flush with finalize should truncate file. seq.Flush(FlatFilePos(0, 1), true); - BOOST_CHECK_EQUAL(fs::file_size(seq.FileName(FlatFilePos(0, 1))), 1U); + CHECK(fs::file_size(seq.FileName(FlatFilePos(0, 1))) == 1U); } -BOOST_AUTO_TEST_SUITE_END() +TEST_SUITE_END() diff --git a/src/test/fs_tests.cpp b/src/test/fs_tests.cpp index 7fd1de00e02b..5da8cbb8ea5d 100644 --- a/src/test/fs_tests.cpp +++ b/src/test/fs_tests.cpp @@ -6,24 +6,24 @@ #include #include -#include +#include #include #include #include -BOOST_FIXTURE_TEST_SUITE(fs_tests, BasicTestingSetup) +TEST_SUITE_BEGIN("fs_tests") -BOOST_AUTO_TEST_CASE(fsbridge_pathtostring) +FIXTURE_TEST_CASE("fsbridge_pathtostring", BasicTestingSetup) { std::string u8_str = "fs_tests_₿_🏃"; std::u8string str8{u8"fs_tests_₿_🏃"}; - BOOST_CHECK_EQUAL(fs::PathToString(fs::PathFromString(u8_str)), u8_str); - BOOST_CHECK_EQUAL(fs::u8path(u8_str).utf8string(), u8_str); - BOOST_CHECK_EQUAL(fs::path(str8).utf8string(), u8_str); - BOOST_CHECK(fs::path(str8).u8string() == str8); - BOOST_CHECK_EQUAL(fs::PathFromString(u8_str).utf8string(), u8_str); - BOOST_CHECK_EQUAL(fs::PathToString(fs::u8path(u8_str)), u8_str); + CHECK(fs::PathToString(fs::PathFromString(u8_str)) == u8_str); + CHECK(fs::u8path(u8_str).utf8string() == u8_str); + CHECK(fs::path(str8).utf8string() == u8_str); + CHECK(fs::path(str8).u8string() == str8); + CHECK(fs::PathFromString(u8_str).utf8string() == u8_str); + CHECK(fs::PathToString(fs::u8path(u8_str)) == u8_str); #ifndef WIN32 // On non-windows systems, verify that arbitrary byte strings containing // invalid UTF-8 can be round tripped successfully with PathToString and @@ -32,19 +32,19 @@ BOOST_AUTO_TEST_CASE(fsbridge_pathtostring) // and these functions do encoding and decoding, so the behavior of this // test would be undefined. std::string invalid_u8_str = "\xf0"; - BOOST_CHECK_EQUAL(invalid_u8_str.size(), 1); - BOOST_CHECK_EQUAL(fs::PathToString(fs::PathFromString(invalid_u8_str)), invalid_u8_str); + CHECK(invalid_u8_str.size() == 1U); + CHECK(fs::PathToString(fs::PathFromString(invalid_u8_str)) == invalid_u8_str); #endif } -BOOST_AUTO_TEST_CASE(fsbridge_stem) +FIXTURE_TEST_CASE("fsbridge_stem", BasicTestingSetup) { std::string test_filename = "fs_tests_₿_🏃.dat"; std::string expected_stem = "fs_tests_₿_🏃"; - BOOST_CHECK_EQUAL(fs::PathToString(fs::PathFromString(test_filename).stem()), expected_stem); + CHECK(fs::PathToString(fs::PathFromString(test_filename).stem()) == expected_stem); } -BOOST_AUTO_TEST_CASE(fsbridge_fstream) +FIXTURE_TEST_CASE("fsbridge_fstream", BasicTestingSetup) { fs::path tmpfolder = m_args.GetDataDirBase(); // tmpfile1 should be the same as tmpfile2 @@ -58,13 +58,13 @@ BOOST_AUTO_TEST_CASE(fsbridge_fstream) std::ifstream file{tmpfile2.std_path()}; std::string input_buffer; file >> input_buffer; - BOOST_CHECK_EQUAL(input_buffer, "bitcoin"); + CHECK(input_buffer == "bitcoin"); } { std::ifstream file{tmpfile1.std_path(), std::ios_base::in | std::ios_base::ate}; std::string input_buffer; file >> input_buffer; - BOOST_CHECK_EQUAL(input_buffer, ""); + CHECK(input_buffer == ""); } { std::ofstream file{tmpfile2.std_path(), std::ios_base::out | std::ios_base::app}; @@ -74,7 +74,7 @@ BOOST_AUTO_TEST_CASE(fsbridge_fstream) std::ifstream file{tmpfile1.std_path()}; std::string input_buffer; file >> input_buffer; - BOOST_CHECK_EQUAL(input_buffer, "bitcointests"); + CHECK(input_buffer == "bitcointests"); } { std::ofstream file{tmpfile2.std_path(), std::ios_base::out | std::ios_base::trunc}; @@ -84,28 +84,28 @@ BOOST_AUTO_TEST_CASE(fsbridge_fstream) std::ifstream file{tmpfile1.std_path()}; std::string input_buffer; file >> input_buffer; - BOOST_CHECK_EQUAL(input_buffer, "bitcoin"); + CHECK(input_buffer == "bitcoin"); } { // Join an absolute path and a relative path. fs::path p = fsbridge::AbsPathJoin(tmpfolder, fs::u8path("fs_tests_₿_🏃")); - BOOST_CHECK(p.is_absolute()); - BOOST_CHECK_EQUAL(tmpfile1, p); + CHECK(p.is_absolute()); + CHECK(tmpfile1 == p); } { // Join two absolute paths. fs::path p = fsbridge::AbsPathJoin(tmpfile1, tmpfile2); - BOOST_CHECK(p.is_absolute()); - BOOST_CHECK_EQUAL(tmpfile2, p); + CHECK(p.is_absolute()); + CHECK(tmpfile2 == p); } { // Ensure joining with empty paths does not add trailing path components. - BOOST_CHECK_EQUAL(tmpfile1, fsbridge::AbsPathJoin(tmpfile1, "")); - BOOST_CHECK_EQUAL(tmpfile1, fsbridge::AbsPathJoin(tmpfile1, {})); + CHECK(tmpfile1 == fsbridge::AbsPathJoin(tmpfile1, "")); + CHECK(tmpfile1 == fsbridge::AbsPathJoin(tmpfile1, {})); } } -BOOST_AUTO_TEST_CASE(rename) +FIXTURE_TEST_CASE("rename", BasicTestingSetup) { const fs::path tmpfolder{m_args.GetDataDirBase()}; @@ -126,17 +126,17 @@ BOOST_AUTO_TEST_CASE(rename) } // Rename path1 -> path2. - BOOST_CHECK(RenameOver(path1, path2)); + CHECK(RenameOver(path1, path2)); - BOOST_CHECK(!fs::exists(path1)); + CHECK(!fs::exists(path1)); { std::ifstream file{path2.std_path()}; std::string contents; file >> contents; - BOOST_CHECK_EQUAL(contents, path1_contents); + CHECK(contents == path1_contents); } fs::remove(path2); } -BOOST_AUTO_TEST_SUITE_END() +TEST_SUITE_END() diff --git a/src/test/getarg_tests.cpp b/src/test/getarg_tests.cpp index d349ceea44b6..75de44790eaf 100644 --- a/src/test/getarg_tests.cpp +++ b/src/test/getarg_tests.cpp @@ -15,11 +15,11 @@ #include #include -#include +#include using util::SplitString; -BOOST_FIXTURE_TEST_SUITE(getarg_tests, BasicTestingSetup) +TEST_SUITE_BEGIN("getarg_tests") void ResetArgs(ArgsManager& local_args, const std::string& strArg) { @@ -38,7 +38,7 @@ void ResetArgs(ArgsManager& local_args, const std::string& strArg) vecChar.push_back(s.c_str()); std::string error; - BOOST_CHECK(local_args.ParseParameters(vecChar.size(), vecChar.data(), error)); + CHECK(local_args.ParseParameters(vecChar.size(), vecChar.data(), error)); } void SetupArgs(ArgsManager& local_args, const std::vector>& args) @@ -55,7 +55,7 @@ void SetupArgs(ArgsManager& local_args, const std::vector("-foo").has_value()); - BOOST_CHECK(!local_args.GetArg("-bar").has_value()); - BOOST_CHECK_EQUAL(local_args.GetIntArg("-foo", 11), 11); - BOOST_CHECK_EQUAL(local_args.GetIntArg("-foo", 0), 0); - BOOST_CHECK_EQUAL(local_args.GetArg("-bar", uint8_t{222}), 222); - BOOST_CHECK_EQUAL(local_args.GetArg("-bar", uint8_t{0}), 0); + CHECK(!local_args.GetArg("-foo").has_value()); + CHECK(!local_args.GetArg("-bar").has_value()); + CHECK(local_args.GetIntArg("-foo", 11) == 11); + CHECK(local_args.GetIntArg("-foo", 0) == 0); + CHECK(local_args.GetArg("-bar", uint8_t{222}) == 222); + CHECK(local_args.GetArg("-bar", uint8_t{0}) == 0); ResetArgs(local_args, "-foo -bar"); - BOOST_CHECK_EQUAL(local_args.GetArg("-foo"), 0); - BOOST_CHECK_EQUAL(local_args.GetArg("-bar"), 0); - BOOST_CHECK_EQUAL(local_args.GetIntArg("-foo", 11), 0); - BOOST_CHECK_EQUAL(local_args.GetArg("-bar", uint8_t{222}), 0); + CHECK(local_args.GetArg("-foo") == 0); + CHECK(local_args.GetArg("-bar") == 0); + CHECK(local_args.GetIntArg("-foo", 11) == 0); + CHECK(local_args.GetArg("-bar", uint8_t{222}) == 0); // Check under-/overflow behavior. ResetArgs(local_args, "-foo=-9223372036854775809 -bar=9223372036854775808"); - BOOST_CHECK_EQUAL(local_args.GetArg("-foo"), std::numeric_limits::min()); - BOOST_CHECK_EQUAL(local_args.GetArg("-bar"), std::numeric_limits::max()); - BOOST_CHECK_EQUAL(local_args.GetIntArg("-foo", 0), std::numeric_limits::min()); - BOOST_CHECK_EQUAL(local_args.GetIntArg("-bar", 0), std::numeric_limits::max()); - BOOST_CHECK_EQUAL(local_args.GetArg("-foo", uint8_t{0}), std::numeric_limits::min()); - BOOST_CHECK_EQUAL(local_args.GetArg("-bar", uint8_t{0}), std::numeric_limits::max()); + CHECK(local_args.GetArg("-foo") == std::numeric_limits::min()); + CHECK(local_args.GetArg("-bar") == std::numeric_limits::max()); + CHECK(local_args.GetIntArg("-foo", 0) == std::numeric_limits::min()); + CHECK(local_args.GetIntArg("-bar", 0) == std::numeric_limits::max()); + CHECK(local_args.GetArg("-foo", uint8_t{0}) == std::numeric_limits::min()); + CHECK(local_args.GetArg("-bar", uint8_t{0}) == std::numeric_limits::max()); ResetArgs(local_args, "-foo=11 -bar=12"); - BOOST_CHECK_EQUAL(local_args.GetArg("-foo"), 11); - BOOST_CHECK_EQUAL(local_args.GetArg("-bar"), 12); - BOOST_CHECK_EQUAL(local_args.GetIntArg("-foo", 0), 11); - BOOST_CHECK_EQUAL(local_args.GetArg("-bar", uint8_t{11}), 12); + CHECK(local_args.GetArg("-foo") == 11); + CHECK(local_args.GetArg("-bar") == 12); + CHECK(local_args.GetIntArg("-foo", 0) == 11); + CHECK(local_args.GetArg("-bar", uint8_t{11}) == 12); ResetArgs(local_args, "-foo=NaN -bar=NotANumber"); - BOOST_CHECK_EQUAL(local_args.GetArg("-foo"), 0); - BOOST_CHECK_EQUAL(local_args.GetArg("-bar"), 0); - BOOST_CHECK_EQUAL(local_args.GetIntArg("-foo", 1), 0); - BOOST_CHECK_EQUAL(local_args.GetArg("-bar", uint8_t{11}), 0); + CHECK(local_args.GetArg("-foo") == 0); + CHECK(local_args.GetArg("-bar") == 0); + CHECK(local_args.GetIntArg("-foo", 1) == 0); + CHECK(local_args.GetArg("-bar", uint8_t{11}) == 0); } -BOOST_AUTO_TEST_CASE(patharg) +FIXTURE_TEST_CASE("patharg", BasicTestingSetup) { ArgsManager local_args; const auto dir = std::make_pair("-dir", ArgsManager::ALLOW_ANY); SetupArgs(local_args, {dir}); ResetArgs(local_args, ""); - BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir"), fs::path{}); + CHECK(local_args.GetPathArg("-dir") == fs::path{}); const fs::path root_path{"/"}; ResetArgs(local_args, "-dir=/"); - BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir"), root_path); + CHECK(local_args.GetPathArg("-dir") == root_path); ResetArgs(local_args, "-dir=/."); - BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir"), root_path); + CHECK(local_args.GetPathArg("-dir") == root_path); ResetArgs(local_args, "-dir=/./"); - BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir"), root_path); + CHECK(local_args.GetPathArg("-dir") == root_path); ResetArgs(local_args, "-dir=/.//"); - BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir"), root_path); + CHECK(local_args.GetPathArg("-dir") == root_path); #ifdef WIN32 const fs::path win_root_path{"C:\\"}; ResetArgs(local_args, "-dir=C:\\"); - BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir"), win_root_path); + CHECK(local_args.GetPathArg("-dir") == win_root_path); ResetArgs(local_args, "-dir=C:/"); - BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir"), win_root_path); + CHECK(local_args.GetPathArg("-dir") == win_root_path); ResetArgs(local_args, "-dir=C:\\\\"); - BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir"), win_root_path); + CHECK(local_args.GetPathArg("-dir") == win_root_path); ResetArgs(local_args, "-dir=C:\\."); - BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir"), win_root_path); + CHECK(local_args.GetPathArg("-dir") == win_root_path); ResetArgs(local_args, "-dir=C:\\.\\"); - BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir"), win_root_path); + CHECK(local_args.GetPathArg("-dir") == win_root_path); ResetArgs(local_args, "-dir=C:\\.\\\\"); - BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir"), win_root_path); + CHECK(local_args.GetPathArg("-dir") == win_root_path); #endif const fs::path absolute_path{"/home/user/.bitcoin"}; ResetArgs(local_args, "-dir=/home/user/.bitcoin"); - BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir"), absolute_path); + CHECK(local_args.GetPathArg("-dir") == absolute_path); ResetArgs(local_args, "-dir=/root/../home/user/.bitcoin"); - BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir"), absolute_path); + CHECK(local_args.GetPathArg("-dir") == absolute_path); ResetArgs(local_args, "-dir=/home/./user/.bitcoin"); - BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir"), absolute_path); + CHECK(local_args.GetPathArg("-dir") == absolute_path); ResetArgs(local_args, "-dir=/home/user/.bitcoin/"); - BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir"), absolute_path); + CHECK(local_args.GetPathArg("-dir") == absolute_path); ResetArgs(local_args, "-dir=/home/user/.bitcoin//"); - BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir"), absolute_path); + CHECK(local_args.GetPathArg("-dir") == absolute_path); ResetArgs(local_args, "-dir=/home/user/.bitcoin/."); - BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir"), absolute_path); + CHECK(local_args.GetPathArg("-dir") == absolute_path); ResetArgs(local_args, "-dir=/home/user/.bitcoin/./"); - BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir"), absolute_path); + CHECK(local_args.GetPathArg("-dir") == absolute_path); ResetArgs(local_args, "-dir=/home/user/.bitcoin/.//"); - BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir"), absolute_path); + CHECK(local_args.GetPathArg("-dir") == absolute_path); const fs::path relative_path{"user/.bitcoin"}; ResetArgs(local_args, "-dir=user/.bitcoin"); - BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir"), relative_path); + CHECK(local_args.GetPathArg("-dir") == relative_path); ResetArgs(local_args, "-dir=somewhere/../user/.bitcoin"); - BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir"), relative_path); + CHECK(local_args.GetPathArg("-dir") == relative_path); ResetArgs(local_args, "-dir=user/./.bitcoin"); - BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir"), relative_path); + CHECK(local_args.GetPathArg("-dir") == relative_path); ResetArgs(local_args, "-dir=user/.bitcoin/"); - BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir"), relative_path); + CHECK(local_args.GetPathArg("-dir") == relative_path); ResetArgs(local_args, "-dir=user/.bitcoin//"); - BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir"), relative_path); + CHECK(local_args.GetPathArg("-dir") == relative_path); ResetArgs(local_args, "-dir=user/.bitcoin/."); - BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir"), relative_path); + CHECK(local_args.GetPathArg("-dir") == relative_path); ResetArgs(local_args, "-dir=user/.bitcoin/./"); - BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir"), relative_path); + CHECK(local_args.GetPathArg("-dir") == relative_path); ResetArgs(local_args, "-dir=user/.bitcoin/.//"); - BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir"), relative_path); + CHECK(local_args.GetPathArg("-dir") == relative_path); // Check negated and default argument handling. Specifying an empty argument // is the same as not specifying the argument. This is convenient for @@ -386,18 +386,18 @@ BOOST_AUTO_TEST_CASE(patharg) // ability to distinguish these in the future (and treat the no-assign case // like an imperative command or an error). ResetArgs(local_args, ""); - BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir", "default"), fs::path{"default"}); + CHECK(local_args.GetPathArg("-dir", "default") == fs::path{"default"}); ResetArgs(local_args, "-dir=override"); - BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir", "default"), fs::path{"override"}); + CHECK(local_args.GetPathArg("-dir", "default") == fs::path{"override"}); ResetArgs(local_args, "-dir="); - BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir", "default"), fs::path{"default"}); + CHECK(local_args.GetPathArg("-dir", "default") == fs::path{"default"}); ResetArgs(local_args, "-dir"); - BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir", "default"), fs::path{"default"}); + CHECK(local_args.GetPathArg("-dir", "default") == fs::path{"default"}); ResetArgs(local_args, "-nodir"); - BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir", "default"), fs::path{""}); + CHECK(local_args.GetPathArg("-dir", "default") == fs::path{""}); } -BOOST_AUTO_TEST_CASE(doubledash) +FIXTURE_TEST_CASE("doubledash", BasicTestingSetup) { ArgsManager local_args; @@ -405,14 +405,14 @@ BOOST_AUTO_TEST_CASE(doubledash) const auto bar = std::make_pair("-bar", ArgsManager::ALLOW_ANY); SetupArgs(local_args, {foo, bar}); ResetArgs(local_args, "--foo"); - BOOST_CHECK_EQUAL(local_args.GetBoolArg("-foo", false), true); + CHECK(local_args.GetBoolArg("-foo", false) == true); ResetArgs(local_args, "--foo=verbose --bar=1"); - BOOST_CHECK_EQUAL(local_args.GetArg("-foo", ""), "verbose"); - BOOST_CHECK_EQUAL(local_args.GetIntArg("-bar", 0), 1); + CHECK(local_args.GetArg("-foo", "") == "verbose"); + CHECK(local_args.GetIntArg("-bar", 0) == 1); } -BOOST_AUTO_TEST_CASE(boolargno) +FIXTURE_TEST_CASE("boolargno", BasicTestingSetup) { ArgsManager local_args; @@ -420,27 +420,27 @@ BOOST_AUTO_TEST_CASE(boolargno) const auto bar = std::make_pair("-bar", ArgsManager::ALLOW_ANY); SetupArgs(local_args, {foo, bar}); ResetArgs(local_args, "-nofoo"); - BOOST_CHECK(!local_args.GetBoolArg("-foo", true)); - BOOST_CHECK(!local_args.GetBoolArg("-foo", false)); + CHECK(!local_args.GetBoolArg("-foo", true)); + CHECK(!local_args.GetBoolArg("-foo", false)); ResetArgs(local_args, "-nofoo=1"); - BOOST_CHECK(!local_args.GetBoolArg("-foo", true)); - BOOST_CHECK(!local_args.GetBoolArg("-foo", false)); + CHECK(!local_args.GetBoolArg("-foo", true)); + CHECK(!local_args.GetBoolArg("-foo", false)); ResetArgs(local_args, "-nofoo=0"); - BOOST_CHECK(local_args.GetBoolArg("-foo", true)); - BOOST_CHECK(local_args.GetBoolArg("-foo", false)); + CHECK(local_args.GetBoolArg("-foo", true)); + CHECK(local_args.GetBoolArg("-foo", false)); ResetArgs(local_args, "-foo --nofoo"); // --nofoo should win - BOOST_CHECK(!local_args.GetBoolArg("-foo", true)); - BOOST_CHECK(!local_args.GetBoolArg("-foo", false)); + CHECK(!local_args.GetBoolArg("-foo", true)); + CHECK(!local_args.GetBoolArg("-foo", false)); ResetArgs(local_args, "-nofoo -foo"); // foo always wins: - BOOST_CHECK(local_args.GetBoolArg("-foo", true)); - BOOST_CHECK(local_args.GetBoolArg("-foo", false)); + CHECK(local_args.GetBoolArg("-foo", true)); + CHECK(local_args.GetBoolArg("-foo", false)); } -BOOST_AUTO_TEST_CASE(logargs) +FIXTURE_TEST_CASE("logargs", BasicTestingSetup) { ArgsManager local_args; @@ -463,11 +463,11 @@ BOOST_AUTO_TEST_CASE(logargs) LogInstance().DeleteCallback(print_connection); // Check that what should appear does, and what shouldn't doesn't. - BOOST_CHECK(str.find("Command-line arg: okaylog-bool=\"\"") != std::string::npos); - BOOST_CHECK(str.find("Command-line arg: okaylog-negbool=false") != std::string::npos); - BOOST_CHECK(str.find("Command-line arg: okaylog=\"public\"") != std::string::npos); - BOOST_CHECK(str.find("dontlog=****") != std::string::npos); - BOOST_CHECK(str.find("private42") == std::string::npos); + CHECK(str.find("Command-line arg: okaylog-bool=\"\"") != std::string::npos); + CHECK(str.find("Command-line arg: okaylog-negbool=false") != std::string::npos); + CHECK(str.find("Command-line arg: okaylog=\"public\"") != std::string::npos); + CHECK(str.find("dontlog=****") != std::string::npos); + CHECK(str.find("private42") == std::string::npos); } -BOOST_AUTO_TEST_SUITE_END() +TEST_SUITE_END() diff --git a/src/test/hash_tests.cpp b/src/test/hash_tests.cpp index a5059a8fe8c8..b45639afdf7d 100644 --- a/src/test/hash_tests.cpp +++ b/src/test/hash_tests.cpp @@ -9,14 +9,14 @@ #include #include -#include +#include -BOOST_FIXTURE_TEST_SUITE(hash_tests, BasicTestingSetup) +TEST_SUITE_BEGIN("hash_tests") -BOOST_AUTO_TEST_CASE(murmurhash3) +FIXTURE_TEST_CASE("murmurhash3", BasicTestingSetup) { -#define T(expected, seed, data) BOOST_CHECK_EQUAL(MurmurHash3(seed, ParseHex(data)), expected) +#define T(expected, seed, data) CHECK(MurmurHash3(seed, ParseHex(data)) == expected) // Test MurmurHash3 with various inputs. Of course this is retested in the // bloom filter tests - they would fail if MurmurHash3() had any problems - @@ -78,46 +78,46 @@ uint64_t siphash_4_2_testvec[] = { 0x6ca4ecb15c5f91e1, 0x9f626da15c9625f3, 0xe51b38608ef25f57, 0x958a324ceb064572 }; -BOOST_AUTO_TEST_CASE(siphash) +FIXTURE_TEST_CASE("siphash", BasicTestingSetup) { CSipHasher hasher(0x0706050403020100ULL, 0x0F0E0D0C0B0A0908ULL); - BOOST_CHECK_EQUAL(hasher.Finalize(), 0x726fdb47dd0e0e31ull); + CHECK(hasher.Finalize() == 0x726fdb47dd0e0e31ull); static const unsigned char t0[1] = {0}; hasher.Write(t0); - BOOST_CHECK_EQUAL(hasher.Finalize(), 0x74f839c593dc67fdull); + CHECK(hasher.Finalize() == 0x74f839c593dc67fdull); static const unsigned char t1[7] = {1,2,3,4,5,6,7}; hasher.Write(t1); - BOOST_CHECK_EQUAL(hasher.Finalize(), 0x93f5f5799a932462ull); + CHECK(hasher.Finalize() == 0x93f5f5799a932462ull); hasher.Write(0x0F0E0D0C0B0A0908ULL); - BOOST_CHECK_EQUAL(hasher.Finalize(), 0x3f2acc7f57c29bdbull); + CHECK(hasher.Finalize() == 0x3f2acc7f57c29bdbull); static const unsigned char t2[2] = {16,17}; hasher.Write(t2); - BOOST_CHECK_EQUAL(hasher.Finalize(), 0x4bc1b3f0968dd39cull); + CHECK(hasher.Finalize() == 0x4bc1b3f0968dd39cull); static const unsigned char t3[9] = {18,19,20,21,22,23,24,25,26}; hasher.Write(t3); - BOOST_CHECK_EQUAL(hasher.Finalize(), 0x2f2e6163076bcfadull); + CHECK(hasher.Finalize() == 0x2f2e6163076bcfadull); static const unsigned char t4[5] = {27,28,29,30,31}; hasher.Write(t4); - BOOST_CHECK_EQUAL(hasher.Finalize(), 0x7127512f72f27cceull); + CHECK(hasher.Finalize() == 0x7127512f72f27cceull); hasher.Write(0x2726252423222120ULL); - BOOST_CHECK_EQUAL(hasher.Finalize(), 0x0e3ea96b5304a7d0ull); + CHECK(hasher.Finalize() == 0x0e3ea96b5304a7d0ull); hasher.Write(0x2F2E2D2C2B2A2928ULL); - BOOST_CHECK_EQUAL(hasher.Finalize(), 0xe612a3cb9ecba951ull); + CHECK(hasher.Finalize() == 0xe612a3cb9ecba951ull); - BOOST_CHECK_EQUAL(PresaltedSipHasher(0x0706050403020100ULL, 0x0F0E0D0C0B0A0908ULL)(uint256{"1f1e1d1c1b1a191817161514131211100f0e0d0c0b0a09080706050403020100"}), 0x7127512f72f27cceull); + CHECK(PresaltedSipHasher(0x0706050403020100ULL, 0x0F0E0D0C0B0A0908ULL)(uint256{"1f1e1d1c1b1a191817161514131211100f0e0d0c0b0a09080706050403020100"}) == 0x7127512f72f27cceull); // Check test vectors from spec, one byte at a time CSipHasher hasher2(0x0706050403020100ULL, 0x0F0E0D0C0B0A0908ULL); for (uint8_t x=0; x #include -#include +#include using State = HeadersSyncState::State; @@ -24,21 +24,21 @@ using State = HeadersSyncState::State; exp_headers_size, exp_pow_validated_prev, exp_locator_hash) \ do { \ const auto result{result_expression}; \ - BOOST_REQUIRE_EQUAL(hss.GetState(), exp_state); \ - BOOST_CHECK_EQUAL(result.success, exp_success); \ - BOOST_CHECK_EQUAL(result.request_more, exp_request_more); \ - BOOST_CHECK_EQUAL(result.pow_validated_headers.size(), exp_headers_size); \ + REQUIRE(hss.GetState() == exp_state); \ + CHECK(result.success == exp_success); \ + CHECK(result.request_more == exp_request_more); \ + CHECK(result.pow_validated_headers.size() == exp_headers_size); \ const std::optional pow_validated_prev_opt{exp_pow_validated_prev}; \ if (pow_validated_prev_opt) { \ - BOOST_CHECK_EQUAL(result.pow_validated_headers.at(0).hashPrevBlock, pow_validated_prev_opt); \ + CHECK(result.pow_validated_headers.at(0).hashPrevBlock == pow_validated_prev_opt); \ } else { \ - BOOST_CHECK_EQUAL(exp_headers_size, 0); \ + CHECK(exp_headers_size == 0); \ } \ const std::optional locator_hash_opt{exp_locator_hash}; \ if (locator_hash_opt) { \ - BOOST_CHECK_EQUAL(hss.NextHeadersRequestLocator().vHave.at(0), locator_hash_opt); \ + CHECK(hss.NextHeadersRequestLocator().vHave.at(0) == locator_hash_opt); \ } else { \ - BOOST_CHECK_EQUAL(exp_state, State::FINAL); \ + CHECK(exp_state == State::FINAL); \ } \ } while (false) @@ -139,9 +139,9 @@ std::vector HeadersGeneratorSetup::GenerateHeaders( // successful. // 3. Repeat the second set of headers in both phases to demonstrate behavior // when the chain a peer provides has too little work. -BOOST_FIXTURE_TEST_SUITE(headers_sync_chainwork_tests, HeadersGeneratorSetup) +TEST_SUITE_BEGIN("headers_sync_chainwork_tests") -BOOST_AUTO_TEST_CASE(sneaky_redownload) +FIXTURE_TEST_CASE("sneaky_redownload", HeadersGeneratorSetup) { const auto& first_chain{FirstChain()}; const auto& second_chain{SecondChain()}; @@ -180,7 +180,7 @@ BOOST_AUTO_TEST_CASE(sneaky_redownload) /*exp_locator_hash=*/std::nullopt); } -BOOST_AUTO_TEST_CASE(happy_path) +FIXTURE_TEST_CASE("happy_path", HeadersGeneratorSetup) { const auto& first_chain{FirstChain()}; @@ -223,14 +223,14 @@ BOOST_AUTO_TEST_CASE(happy_path) } } -BOOST_AUTO_TEST_CASE(too_little_work) +FIXTURE_TEST_CASE("too_little_work", HeadersGeneratorSetup) { const auto& second_chain{SecondChain()}; // Verify that just trying to process the second chain would not succeed // (too little work). HeadersSyncState hss{CreateState()}; - BOOST_REQUIRE_EQUAL(hss.GetState(), State::PRESYNC); + REQUIRE(hss.GetState() == State::PRESYNC); // Pretend just the first message is "full", so we don't abort. CHECK_RESULT(hss.ProcessNextHeaders({{second_chain.front()}}, true), @@ -252,4 +252,4 @@ BOOST_AUTO_TEST_CASE(too_little_work) /*exp_locator_hash=*/std::nullopt); } -BOOST_AUTO_TEST_SUITE_END() +TEST_SUITE_END() diff --git a/src/test/i2p_tests.cpp b/src/test/i2p_tests.cpp index 08f3fade8462..3839b248be27 100644 --- a/src/test/i2p_tests.cpp +++ b/src/test/i2p_tests.cpp @@ -14,7 +14,7 @@ #include #include -#include +#include #include #include @@ -43,9 +43,9 @@ class EnvTestingSetup : public BasicTestingSetup const decltype(CreateSock) m_create_sock_orig; }; -BOOST_FIXTURE_TEST_SUITE(i2p_tests, EnvTestingSetup) +TEST_SUITE_BEGIN("i2p_tests") -BOOST_AUTO_TEST_CASE(unlimited_recv) +FIXTURE_TEST_CASE("unlimited_recv", EnvTestingSetup) { CreateSock = [](int, int, int) { return std::make_unique(std::string(i2p::sam::MAX_MSG_SIZE + 1, 'a')); @@ -62,11 +62,11 @@ BOOST_AUTO_TEST_CASE(unlimited_recv) i2p::Connection conn; bool proxy_error; - BOOST_REQUIRE(!session.Connect(CService{}, conn, proxy_error)); + REQUIRE(!session.Connect(CService{}, conn, proxy_error)); } } -BOOST_AUTO_TEST_CASE(listen_ok_accept_fail) +FIXTURE_TEST_CASE("listen_ok_accept_fail", EnvTestingSetup) { size_t num_sockets{0}; CreateSock = [&num_sockets](int, int, int) { @@ -126,12 +126,12 @@ BOOST_AUTO_TEST_CASE(listen_ok_accept_fail) ASSERT_DEBUG_LOG("Persistent I2P SAM session" /* ... created */); ASSERT_DEBUG_LOG("Error accepting"); ASSERT_DEBUG_LOG("Destroying I2P SAM session"); - BOOST_REQUIRE(session.Listen(conn)); - BOOST_REQUIRE(!session.Accept(conn)); + REQUIRE(session.Listen(conn)); + REQUIRE(!session.Accept(conn)); } } -BOOST_AUTO_TEST_CASE(damaged_private_key) +FIXTURE_TEST_CASE("damaged_private_key", EnvTestingSetup) { CreateSock = [](int, int, int) { return std::make_unique("HELLO REPLY RESULT=OK VERSION=3.1\n" @@ -154,7 +154,7 @@ BOOST_AUTO_TEST_CASE(damaged_private_key) {std::string(385, '\0') + '\0' + '\5' + "abcd", "Certificate length (5) designates that the private key should be 392 bytes, but it is only " "391 bytes"}}) { - BOOST_REQUIRE(WriteBinaryFile(i2p_private_key_file, file_contents)); + REQUIRE(WriteBinaryFile(i2p_private_key_file, file_contents)); auto interrupt{std::make_shared()}; const CService addr{in6_addr(COMPAT_IN6ADDR_LOOPBACK_INIT), /*port=*/7656}; @@ -167,9 +167,9 @@ BOOST_AUTO_TEST_CASE(damaged_private_key) i2p::Connection conn; bool proxy_error; - BOOST_CHECK(!session.Connect(CService{}, conn, proxy_error)); + CHECK(!session.Connect(CService{}, conn, proxy_error)); } } } -BOOST_AUTO_TEST_SUITE_END() +TEST_SUITE_END() diff --git a/src/test/interfaces_tests.cpp b/src/test/interfaces_tests.cpp index b34ac961c912..c35afa565921 100644 --- a/src/test/interfaces_tests.cpp +++ b/src/test/interfaces_tests.cpp @@ -10,93 +10,93 @@ #include