Skip to content

Commit fa940f4

Browse files
author
MarcoFalke
committed
Remove unused raw-pointer read helper from univalue
1 parent dfe2dc1 commit fa940f4

13 files changed

+27
-26
lines changed

build_msvc/test_bitcoin/test_bitcoin.vcxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
<RawTestFile Include="..\..\src\test\data\*.raw" />
6969
</ItemGroup>
7070
<HeaderFromHexdump RawFilePath="%(RawTestFile.FullPath)" HeaderFilePath="%(RawTestFile.FullPath).h" SourceHeader="static unsigned const char %(RawTestFile.Filename)_raw[] = {" SourceFooter="};" />
71-
<HeaderFromHexdump RawFilePath="%(JsonTestFile.FullPath)" HeaderFilePath="%(JsonTestFile.FullPath).h" SourceHeader="namespace json_tests{ static unsigned const char %(JsonTestFile.Filename)[] = {" SourceFooter="};}" />
71+
<HeaderFromHexdump RawFilePath="%(JsonTestFile.FullPath)" HeaderFilePath="%(JsonTestFile.FullPath).h" SourceHeader="#include &lt;string&gt;&#x0D;&#x0A;namespace json_tests{ static const std::string %(JsonTestFile.Filename){" SourceFooter="};}" />
7272
</Target>
7373
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
7474
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />

src/Makefile.test.include

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,8 +427,9 @@ endif
427427
%.json.h: %.json
428428
@$(MKDIR_P) $(@D)
429429
$(AM_V_GEN) { \
430+
echo "#include <string>" && \
430431
echo "namespace json_tests{" && \
431-
echo "static unsigned const char $(*F)[] = {" && \
432+
echo "static const std::string $(*F){" && \
432433
$(HEXDUMP) -v -e '8/1 "0x%02x, "' -e '"\n"' $< | $(SED) -e 's/0x ,//g' && \
433434
echo "};};"; \
434435
} > "[email protected]" && mv -f "[email protected]" "$@"

src/test/base58_tests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ BOOST_FIXTURE_TEST_SUITE(base58_tests, BasicTestingSetup)
2323
// Goal: test low-level base58 encoding functionality
2424
BOOST_AUTO_TEST_CASE(base58_EncodeBase58)
2525
{
26-
UniValue tests = read_json(std::string(json_tests::base58_encode_decode, json_tests::base58_encode_decode + sizeof(json_tests::base58_encode_decode)));
26+
UniValue tests = read_json(json_tests::base58_encode_decode);
2727
for (unsigned int idx = 0; idx < tests.size(); idx++) {
2828
const UniValue& test = tests[idx];
2929
std::string strTest = test.write();
@@ -43,7 +43,7 @@ BOOST_AUTO_TEST_CASE(base58_EncodeBase58)
4343
// Goal: test low-level base58 decoding functionality
4444
BOOST_AUTO_TEST_CASE(base58_DecodeBase58)
4545
{
46-
UniValue tests = read_json(std::string(json_tests::base58_encode_decode, json_tests::base58_encode_decode + sizeof(json_tests::base58_encode_decode)));
46+
UniValue tests = read_json(json_tests::base58_encode_decode);
4747
std::vector<unsigned char> result;
4848

4949
for (unsigned int idx = 0; idx < tests.size(); idx++) {

src/test/blockfilter_tests.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,7 @@ BOOST_AUTO_TEST_CASE(blockfilter_basic_test)
128128
BOOST_AUTO_TEST_CASE(blockfilters_json_test)
129129
{
130130
UniValue json;
131-
std::string json_data(json_tests::blockfilters,
132-
json_tests::blockfilters + sizeof(json_tests::blockfilters));
133-
if (!json.read(json_data) || !json.isArray()) {
131+
if (!json.read(json_tests::blockfilters) || !json.isArray()) {
134132
BOOST_ERROR("Parse error.");
135133
return;
136134
}

src/test/key_io_tests.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ BOOST_FIXTURE_TEST_SUITE(key_io_tests, BasicTestingSetup)
2222
// Goal: check that parsed keys match test payload
2323
BOOST_AUTO_TEST_CASE(key_io_valid_parse)
2424
{
25-
UniValue tests = read_json(std::string(json_tests::key_io_valid, json_tests::key_io_valid + sizeof(json_tests::key_io_valid)));
25+
UniValue tests = read_json(json_tests::key_io_valid);
2626
CKey privkey;
2727
CTxDestination destination;
2828
SelectParams(ChainType::MAIN);
@@ -83,7 +83,7 @@ BOOST_AUTO_TEST_CASE(key_io_valid_parse)
8383
// Goal: check that generated keys match test vectors
8484
BOOST_AUTO_TEST_CASE(key_io_valid_gen)
8585
{
86-
UniValue tests = read_json(std::string(json_tests::key_io_valid, json_tests::key_io_valid + sizeof(json_tests::key_io_valid)));
86+
UniValue tests = read_json(json_tests::key_io_valid);
8787

8888
for (unsigned int idx = 0; idx < tests.size(); idx++) {
8989
const UniValue& test = tests[idx];
@@ -121,7 +121,7 @@ BOOST_AUTO_TEST_CASE(key_io_valid_gen)
121121
// Goal: check that base58 parsing code is robust against a variety of corrupted data
122122
BOOST_AUTO_TEST_CASE(key_io_invalid)
123123
{
124-
UniValue tests = read_json(std::string(json_tests::key_io_invalid, json_tests::key_io_invalid + sizeof(json_tests::key_io_invalid))); // Negative testcases
124+
UniValue tests = read_json(json_tests::key_io_invalid); // Negative testcases
125125
CKey privkey;
126126
CTxDestination destination;
127127

src/test/rpc_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
static UniValue JSON(std::string_view json)
2121
{
2222
UniValue value;
23-
BOOST_CHECK(value.read(json.data(), json.size()));
23+
BOOST_CHECK(value.read(json));
2424
return value;
2525
}
2626

src/test/script_standard_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ BOOST_AUTO_TEST_CASE(bip341_spk_test_vectors)
394394
using control_set = decltype(TaprootSpendData::scripts)::mapped_type;
395395

396396
UniValue tests;
397-
tests.read((const char*)json_tests::bip341_wallet_vectors, sizeof(json_tests::bip341_wallet_vectors));
397+
tests.read(json_tests::bip341_wallet_vectors);
398398

399399
const auto& vectors = tests["scriptPubKey"];
400400

src/test/script_tests.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -890,7 +890,7 @@ BOOST_AUTO_TEST_CASE(script_build)
890890
std::set<std::string> tests_set;
891891

892892
{
893-
UniValue json_tests = read_json(std::string(json_tests::script_tests, json_tests::script_tests + sizeof(json_tests::script_tests)));
893+
UniValue json_tests = read_json(json_tests::script_tests);
894894

895895
for (unsigned int idx = 0; idx < json_tests.size(); idx++) {
896896
const UniValue& tv = json_tests[idx];
@@ -929,7 +929,7 @@ BOOST_AUTO_TEST_CASE(script_json_test)
929929
// scripts.
930930
// If a witness is given, then the last value in the array should be the
931931
// amount (nValue) to use in the crediting tx
932-
UniValue tests = read_json(std::string(json_tests::script_tests, json_tests::script_tests + sizeof(json_tests::script_tests)));
932+
UniValue tests = read_json(json_tests::script_tests);
933933

934934
for (unsigned int idx = 0; idx < tests.size(); idx++) {
935935
const UniValue& test = tests[idx];
@@ -1743,7 +1743,7 @@ BOOST_AUTO_TEST_CASE(script_assets_test)
17431743
BOOST_AUTO_TEST_CASE(bip341_keypath_test_vectors)
17441744
{
17451745
UniValue tests;
1746-
tests.read((const char*)json_tests::bip341_wallet_vectors, sizeof(json_tests::bip341_wallet_vectors));
1746+
tests.read(json_tests::bip341_wallet_vectors);
17471747

17481748
const auto& vectors = tests["keyPathSpending"];
17491749

src/test/sighash_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ BOOST_AUTO_TEST_CASE(sighash_test)
162162
// Goal: check that SignatureHash generates correct hash
163163
BOOST_AUTO_TEST_CASE(sighash_from_data)
164164
{
165-
UniValue tests = read_json(std::string(json_tests::sighash, json_tests::sighash + sizeof(json_tests::sighash)));
165+
UniValue tests = read_json(json_tests::sighash);
166166

167167
for (unsigned int idx = 0; idx < tests.size(); idx++) {
168168
const UniValue& test = tests[idx];

src/test/transaction_tests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ BOOST_AUTO_TEST_CASE(tx_valid)
190190
{
191191
BOOST_CHECK_MESSAGE(CheckMapFlagNames(), "mapFlagNames is missing a script verification flag");
192192
// Read tests from test/data/tx_valid.json
193-
UniValue tests = read_json(std::string(json_tests::tx_valid, json_tests::tx_valid + sizeof(json_tests::tx_valid)));
193+
UniValue tests = read_json(json_tests::tx_valid);
194194

195195
for (unsigned int idx = 0; idx < tests.size(); idx++) {
196196
const UniValue& test = tests[idx];
@@ -278,7 +278,7 @@ BOOST_AUTO_TEST_CASE(tx_valid)
278278
BOOST_AUTO_TEST_CASE(tx_invalid)
279279
{
280280
// Read tests from test/data/tx_invalid.json
281-
UniValue tests = read_json(std::string(json_tests::tx_invalid, json_tests::tx_invalid + sizeof(json_tests::tx_invalid)));
281+
UniValue tests = read_json(json_tests::tx_invalid);
282282

283283
for (unsigned int idx = 0; idx < tests.size(); idx++) {
284284
const UniValue& test = tests[idx];

0 commit comments

Comments
 (0)