mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-15 12:51:00 +02:00
1667577042 2022-11-04T16:50:42+01:00e42ba134f4Bitcoin Merge bitcoin/bitcoin#26448: test: fix intermittent failure in p2p_sendtxrcncl.py 1667576919 2022-11-04T15:48:39+00:0083cf055befBitcoin Merge bitcoin/bitcoin#26443: doc: mention BIP86 in doc/bips.md 1667478613 2022-11-03T13:30:13+01:0028653a596aBitcoin Merge bitcoin/bitcoin#26445: .python-version: bump patch version to 3.6.15 1667471345 2022-11-03T10:29:05+00:002a7c9984dbBitcoin Merge bitcoin/bitcoin#25248: refactor: Add LIFETIMEBOUND / -Wdangling-gsl to Assert() 1667397640 2022-11-02T15:00:40+01:005274f32437Bitcoin Merge bitcoin/bitcoin#26417: test: fix intermittent failure in feature_index_prune.py 1667372848 2022-11-02T08:07:28+01:0039f026b1ecBitcoin Merge bitcoin/bitcoin#26396: net: Avoid SetTxRelay for feeler connections 1667316369 2022-11-01T16:26:09+01:00bf0cb43990Bitcoin Merge bitcoin/bitcoin#26437: test: remove unused `CHANGE_{XPRV,XPUB}` constants 1667300957 2022-11-01T11:09:17+00:005668ccec1dBitcoin Merge bitcoin/bitcoin#25548: gui: Check for readlink buffer overflow and handle gracefully 1667297563 2022-11-01T10:12:43+00:00c041d8f2c9Bitcoin Merge bitcoin/bitcoin#26360: build: remove threadinterrupt from libbitcoinkernel 1667297149 2022-11-01T10:05:49+00:0027e76afe24Bitcoin Merge bitcoin/bitcoin#26294: build: move util/url to common/url 1667291397 2022-11-01T08:29:57+00:00d08b63baa0Bitcoin Merge bitcoin/bitcoin#26373: Update minisketch subtree to latest upstream 1667230521 2022-10-31T15:35:21+00:0043e813cab2Bitcoin Merge bitcoin/bitcoin#26387: p2p: TryLowWorkHeadersSync follow-ups 1667217075 2022-10-31T11:51:15+00:004766cd1981Bitcoin Merge bitcoin/bitcoin#24051: Bugfix: configure: bitcoin-{cli,tx,util} don't need UPnP, NAT-PMP, or ZMQ 1667213203 2022-10-31T11:46:43+01:002856dee808Bitcoin Merge bitcoin/bitcoin#26402: doc: Fix typos 1667202170 2022-10-31T08:42:50+01:00c75c0d8e11Bitcoin Merge bitcoin/bitcoin#26424: doc: correct deriveaddresses RPC name 1667034850 2022-10-29T11:14:10+02:004f270d2b63Bitcoin Merge bitcoin/bitcoin#26404: test: fix intermittent failure in rpc_getblockfrompeer.py 1667030363 2022-10-29T09:59:23+02:00984a01589bBitcoin Merge bitcoin/bitcoin#26408: test: Remove spam from debug log 1666985837 2022-10-28T15:37:17-04:008b050762b1Bitcoin Merge bitcoin/bitcoin#26409: refactor: Silence GCC Wmissing-field-initializers in ChainstateManagerOpts 1666949533 2022-10-28T11:32:13+02:001bad29fe02Bitcoin Merge bitcoin/bitcoin#26377: test: Make `system_tests/run_command` test locale and platform agnostic
110 lines
3.8 KiB
C++
110 lines
3.8 KiB
C++
// Copyright (c) 2019-2021 The Bitcoin Core developers
|
|
// Distributed under the MIT software license, see the accompanying
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
//
|
|
#include <test/util/setup_common.h>
|
|
#include <common/run_command.h>
|
|
#include <univalue.h>
|
|
|
|
#ifdef ENABLE_EXTERNAL_SIGNER
|
|
#if defined(__GNUC__)
|
|
// Boost 1.78 requires the following workaround.
|
|
// See: https://github.com/boostorg/process/issues/235
|
|
#pragma GCC diagnostic push
|
|
#pragma GCC diagnostic ignored "-Wnarrowing"
|
|
#endif
|
|
#if defined(__GNUC__)
|
|
// Boost 1.78 requires the following workaround.
|
|
// See: https://github.com/boostorg/process/issues/235
|
|
#pragma GCC diagnostic push
|
|
#pragma GCC diagnostic ignored "-Wnarrowing"
|
|
#endif
|
|
#include <boost/process.hpp>
|
|
#if defined(__GNUC__)
|
|
#pragma GCC diagnostic pop
|
|
#endif
|
|
#endif // ENABLE_EXTERNAL_SIGNER
|
|
|
|
#include <boost/test/unit_test.hpp>
|
|
|
|
BOOST_FIXTURE_TEST_SUITE(system_tests, BasicTestingSetup)
|
|
|
|
// At least one test is required (in case ENABLE_EXTERNAL_SIGNER is not defined).
|
|
// Workaround for https://github.com/bitcoin/bitcoin/issues/19128
|
|
BOOST_AUTO_TEST_CASE(dummy)
|
|
{
|
|
BOOST_CHECK(true);
|
|
}
|
|
|
|
#ifdef ENABLE_EXTERNAL_SIGNER
|
|
|
|
BOOST_AUTO_TEST_CASE(run_command)
|
|
{
|
|
{
|
|
const UniValue result = RunCommandParseJSON("");
|
|
BOOST_CHECK(result.isNull());
|
|
}
|
|
{
|
|
#ifdef WIN32
|
|
const UniValue result = RunCommandParseJSON("cmd.exe /c echo {\"success\": true}");
|
|
#else
|
|
const UniValue result = RunCommandParseJSON("echo \"{\"success\": true}\"");
|
|
#endif
|
|
BOOST_CHECK(result.isObject());
|
|
const UniValue& success = find_value(result, "success");
|
|
BOOST_CHECK(!success.isNull());
|
|
BOOST_CHECK_EQUAL(success.getBool(), true);
|
|
}
|
|
{
|
|
// An invalid command is handled by Boost
|
|
BOOST_CHECK_EXCEPTION(RunCommandParseJSON("invalid_command"), boost::process::process_error, [&](const boost::process::process_error& e) {
|
|
BOOST_CHECK(std::string(e.what()).find("RunCommandParseJSON error:") == std::string::npos);
|
|
BOOST_CHECK_EQUAL(e.code().value(), 2);
|
|
return true;
|
|
});
|
|
}
|
|
{
|
|
// Return non-zero exit code, no output to stderr
|
|
#ifdef WIN32
|
|
const std::string command{"cmd.exe /c call"};
|
|
#else
|
|
const std::string command{"false"};
|
|
#endif
|
|
BOOST_CHECK_EXCEPTION(RunCommandParseJSON(command), std::runtime_error, [&](const std::runtime_error& e) {
|
|
BOOST_CHECK(std::string(e.what()).find(strprintf("RunCommandParseJSON error: process(%s) returned 1: \n", command)) != std::string::npos);
|
|
return true;
|
|
});
|
|
}
|
|
{
|
|
// Return non-zero exit code, with error message for stderr
|
|
#ifdef WIN32
|
|
const std::string command{"cmd.exe /c dir nosuchfile"};
|
|
const std::string expected{"File Not Found"};
|
|
#else
|
|
const std::string command{"ls nosuchfile"};
|
|
const std::string expected{"No such file or directory"};
|
|
#endif
|
|
BOOST_CHECK_EXCEPTION(RunCommandParseJSON(command), std::runtime_error, [&](const std::runtime_error& e) {
|
|
const std::string what(e.what());
|
|
BOOST_CHECK(what.find(strprintf("RunCommandParseJSON error: process(%s) returned", command)) != std::string::npos);
|
|
BOOST_CHECK(what.find(expected) != std::string::npos);
|
|
return true;
|
|
});
|
|
}
|
|
{
|
|
BOOST_REQUIRE_THROW(RunCommandParseJSON("echo \"{\""), std::runtime_error); // Unable to parse JSON
|
|
}
|
|
// Test std::in, except for Windows
|
|
#ifndef WIN32
|
|
{
|
|
const UniValue result = RunCommandParseJSON("cat", "{\"success\": true}");
|
|
BOOST_CHECK(result.isObject());
|
|
const UniValue& success = find_value(result, "success");
|
|
BOOST_CHECK(!success.isNull());
|
|
BOOST_CHECK_EQUAL(success.getBool(), true);
|
|
}
|
|
#endif
|
|
}
|
|
#endif // ENABLE_EXTERNAL_SIGNER
|
|
|
|
BOOST_AUTO_TEST_SUITE_END()
|