test, build: Separate read_json function into its own module

This commit is contained in:
Hennadii Stepanov 2023-01-27 09:26:29 +00:00
parent 835212cd1d
commit 7a820cee0e
No known key found for this signature in database
GPG key ID: 410108112E7EA81F
8 changed files with 38 additions and 21 deletions

View file

@ -10,6 +10,7 @@ EXTRA_LIBRARIES += \
TEST_UTIL_H = \
test/util/blockfilter.h \
test/util/chainstate.h \
test/util/json.h \
test/util/logging.h \
test/util/mining.h \
test/util/net.h \
@ -28,6 +29,7 @@ libtest_util_a_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) $(BOOST_CPPFLAGS)
libtest_util_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
libtest_util_a_SOURCES = \
test/util/blockfilter.cpp \
test/util/json.cpp \
test/util/logging.cpp \
test/util/mining.cpp \
test/util/net.cpp \

View file

@ -5,6 +5,7 @@
#include <test/data/base58_encode_decode.json.h>
#include <base58.h>
#include <test/util/json.h>
#include <test/util/setup_common.h>
#include <util/strencodings.h>
#include <util/vector.h>
@ -16,8 +17,6 @@
using namespace std::literals;
UniValue read_json(const std::string& jsondata);
BOOST_FIXTURE_TEST_SUITE(base58_tests, BasicTestingSetup)
// Goal: test low-level base58 encoding functionality

View file

@ -8,6 +8,7 @@
#include <key.h>
#include <key_io.h>
#include <script/script.h>
#include <test/util/json.h>
#include <test/util/setup_common.h>
#include <util/strencodings.h>
@ -15,8 +16,6 @@
#include <univalue.h>
UniValue read_json(const std::string& jsondata);
BOOST_FIXTURE_TEST_SUITE(key_io_tests, BasicTestingSetup)
// Goal: check that parsed keys match test payload

View file

@ -15,6 +15,7 @@
#include <script/sign.h>
#include <script/signingprovider.h>
#include <streams.h>
#include <test/util/json.h>
#include <test/util/setup_common.h>
#include <test/util/transaction_utils.h>
#include <util/strencodings.h>
@ -41,18 +42,6 @@ static const unsigned int gFlags = SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_STRICTENC;
unsigned int ParseScriptFlags(std::string strFlags);
std::string FormatScriptFlags(unsigned int flags);
UniValue read_json(const std::string& jsondata)
{
UniValue v;
if (!v.read(jsondata) || !v.isArray())
{
BOOST_ERROR("Parse error.");
return UniValue(UniValue::VARR);
}
return v.get_array();
}
struct ScriptErrorDesc
{
ScriptError_t err;

View file

@ -10,6 +10,7 @@
#include <serialize.h>
#include <streams.h>
#include <test/data/sighash.json.h>
#include <test/util/json.h>
#include <test/util/setup_common.h>
#include <util/strencodings.h>
#include <util/system.h>
@ -21,8 +22,6 @@
#include <univalue.h>
UniValue read_json(const std::string& jsondata);
// Old script.cpp SignatureHash function
uint256 static SignatureHashOld(CScript scriptCode, const CTransaction& txTo, unsigned int nIn, int nHashType)
{

View file

@ -21,6 +21,7 @@
#include <script/signingprovider.h>
#include <script/standard.h>
#include <streams.h>
#include <test/util/json.h>
#include <test/util/script.h>
#include <test/util/transaction_utils.h>
#include <util/strencodings.h>
@ -37,9 +38,6 @@
typedef std::vector<unsigned char> valtype;
// In script_tests.cpp
UniValue read_json(const std::string& jsondata);
static CFeeRate g_dust{DUST_RELAY_TX_FEE};
static bool g_bare_multi{DEFAULT_PERMIT_BAREMULTISIG};

17
src/test/util/json.cpp Normal file
View file

@ -0,0 +1,17 @@
// Copyright (c) 2023 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/json.h>
#include <string>
#include <util/check.h>
#include <univalue.h>
UniValue read_json(const std::string& jsondata)
{
UniValue v;
Assert(v.read(jsondata) && v.isArray());
return v.get_array();
}

14
src/test/util/json.h Normal file
View file

@ -0,0 +1,14 @@
// Copyright (c) 2023 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef BITCOIN_TEST_UTIL_JSON_H
#define BITCOIN_TEST_UTIL_JSON_H
#include <string>
#include <univalue.h>
UniValue read_json(const std::string& jsondata);
#endif // BITCOIN_TEST_UTIL_JSON_H