mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-27 11:43:26 -03:00
test, build: Separate read_json
function into its own module
This commit is contained in:
parent
835212cd1d
commit
7a820cee0e
8 changed files with 38 additions and 21 deletions
|
@ -10,6 +10,7 @@ EXTRA_LIBRARIES += \
|
||||||
TEST_UTIL_H = \
|
TEST_UTIL_H = \
|
||||||
test/util/blockfilter.h \
|
test/util/blockfilter.h \
|
||||||
test/util/chainstate.h \
|
test/util/chainstate.h \
|
||||||
|
test/util/json.h \
|
||||||
test/util/logging.h \
|
test/util/logging.h \
|
||||||
test/util/mining.h \
|
test/util/mining.h \
|
||||||
test/util/net.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_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
|
||||||
libtest_util_a_SOURCES = \
|
libtest_util_a_SOURCES = \
|
||||||
test/util/blockfilter.cpp \
|
test/util/blockfilter.cpp \
|
||||||
|
test/util/json.cpp \
|
||||||
test/util/logging.cpp \
|
test/util/logging.cpp \
|
||||||
test/util/mining.cpp \
|
test/util/mining.cpp \
|
||||||
test/util/net.cpp \
|
test/util/net.cpp \
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include <test/data/base58_encode_decode.json.h>
|
#include <test/data/base58_encode_decode.json.h>
|
||||||
|
|
||||||
#include <base58.h>
|
#include <base58.h>
|
||||||
|
#include <test/util/json.h>
|
||||||
#include <test/util/setup_common.h>
|
#include <test/util/setup_common.h>
|
||||||
#include <util/strencodings.h>
|
#include <util/strencodings.h>
|
||||||
#include <util/vector.h>
|
#include <util/vector.h>
|
||||||
|
@ -16,8 +17,6 @@
|
||||||
|
|
||||||
using namespace std::literals;
|
using namespace std::literals;
|
||||||
|
|
||||||
UniValue read_json(const std::string& jsondata);
|
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_SUITE(base58_tests, BasicTestingSetup)
|
BOOST_FIXTURE_TEST_SUITE(base58_tests, BasicTestingSetup)
|
||||||
|
|
||||||
// Goal: test low-level base58 encoding functionality
|
// Goal: test low-level base58 encoding functionality
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include <key.h>
|
#include <key.h>
|
||||||
#include <key_io.h>
|
#include <key_io.h>
|
||||||
#include <script/script.h>
|
#include <script/script.h>
|
||||||
|
#include <test/util/json.h>
|
||||||
#include <test/util/setup_common.h>
|
#include <test/util/setup_common.h>
|
||||||
#include <util/strencodings.h>
|
#include <util/strencodings.h>
|
||||||
|
|
||||||
|
@ -15,8 +16,6 @@
|
||||||
|
|
||||||
#include <univalue.h>
|
#include <univalue.h>
|
||||||
|
|
||||||
UniValue read_json(const std::string& jsondata);
|
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_SUITE(key_io_tests, BasicTestingSetup)
|
BOOST_FIXTURE_TEST_SUITE(key_io_tests, BasicTestingSetup)
|
||||||
|
|
||||||
// Goal: check that parsed keys match test payload
|
// Goal: check that parsed keys match test payload
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
#include <script/sign.h>
|
#include <script/sign.h>
|
||||||
#include <script/signingprovider.h>
|
#include <script/signingprovider.h>
|
||||||
#include <streams.h>
|
#include <streams.h>
|
||||||
|
#include <test/util/json.h>
|
||||||
#include <test/util/setup_common.h>
|
#include <test/util/setup_common.h>
|
||||||
#include <test/util/transaction_utils.h>
|
#include <test/util/transaction_utils.h>
|
||||||
#include <util/strencodings.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);
|
unsigned int ParseScriptFlags(std::string strFlags);
|
||||||
std::string FormatScriptFlags(unsigned int flags);
|
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
|
struct ScriptErrorDesc
|
||||||
{
|
{
|
||||||
ScriptError_t err;
|
ScriptError_t err;
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#include <serialize.h>
|
#include <serialize.h>
|
||||||
#include <streams.h>
|
#include <streams.h>
|
||||||
#include <test/data/sighash.json.h>
|
#include <test/data/sighash.json.h>
|
||||||
|
#include <test/util/json.h>
|
||||||
#include <test/util/setup_common.h>
|
#include <test/util/setup_common.h>
|
||||||
#include <util/strencodings.h>
|
#include <util/strencodings.h>
|
||||||
#include <util/system.h>
|
#include <util/system.h>
|
||||||
|
@ -21,8 +22,6 @@
|
||||||
|
|
||||||
#include <univalue.h>
|
#include <univalue.h>
|
||||||
|
|
||||||
UniValue read_json(const std::string& jsondata);
|
|
||||||
|
|
||||||
// Old script.cpp SignatureHash function
|
// Old script.cpp SignatureHash function
|
||||||
uint256 static SignatureHashOld(CScript scriptCode, const CTransaction& txTo, unsigned int nIn, int nHashType)
|
uint256 static SignatureHashOld(CScript scriptCode, const CTransaction& txTo, unsigned int nIn, int nHashType)
|
||||||
{
|
{
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#include <script/signingprovider.h>
|
#include <script/signingprovider.h>
|
||||||
#include <script/standard.h>
|
#include <script/standard.h>
|
||||||
#include <streams.h>
|
#include <streams.h>
|
||||||
|
#include <test/util/json.h>
|
||||||
#include <test/util/script.h>
|
#include <test/util/script.h>
|
||||||
#include <test/util/transaction_utils.h>
|
#include <test/util/transaction_utils.h>
|
||||||
#include <util/strencodings.h>
|
#include <util/strencodings.h>
|
||||||
|
@ -37,9 +38,6 @@
|
||||||
|
|
||||||
typedef std::vector<unsigned char> valtype;
|
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 CFeeRate g_dust{DUST_RELAY_TX_FEE};
|
||||||
static bool g_bare_multi{DEFAULT_PERMIT_BAREMULTISIG};
|
static bool g_bare_multi{DEFAULT_PERMIT_BAREMULTISIG};
|
||||||
|
|
||||||
|
|
17
src/test/util/json.cpp
Normal file
17
src/test/util/json.cpp
Normal 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
14
src/test/util/json.h
Normal 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
|
Loading…
Add table
Reference in a new issue