Skip to content

Commit 4dab65b

Browse files
committed
test: autogenerate data headers
1 parent 9a023cf commit 4dab65b

21 files changed

+117
-411015
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,7 @@ contrib/devtools/split-debug.sh
9696
*.lo
9797
*.la
9898

99-
/doc/doxygen/
99+
doc/doxygen/
100+
src/test/data/*.bin.h
101+
src/test/data/*.json.h
102+
src/test/data/*.txt.h

src/Makefile.test.include

Lines changed: 88 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -8,71 +8,78 @@ TEST_SRCDIR = test
88
TEST_BINARY=test/test_gridcoin$(EXEEXT)
99

1010
JSON_TEST_FILES = \
11-
test/data/base58_keys_valid.json.h \
12-
test/data/base58_encode_decode.json.h \
13-
test/data/base58_keys_invalid.json.h \
14-
test/data/script_valid.json.h \
15-
test/data/script_invalid.json.h \
16-
test/data/tx_invalid.json.h \
17-
test/data/tx_valid.json.h
18-
19-
OTHER_TEST_FILES = \
20-
test/data/mainnet_beacon.bin.h \
21-
test/data/superblock.txt.h \
22-
test/data/superblock.txt.h \
23-
test/data/superblock_packed.bin.h \
24-
test/data/superblock_unpacked.txt.h \
25-
test/data/testnet_beacon.bin.h
11+
test/data/base58_keys_valid.json \
12+
test/data/base58_encode_decode.json \
13+
test/data/base58_keys_invalid.json \
14+
test/data/script_valid.json \
15+
test/data/script_invalid.json \
16+
test/data/tx_invalid.json \
17+
test/data/tx_valid.json
18+
19+
BINARY_TEST_FILES = \
20+
test/data/mainnet_beacon.bin \
21+
test/data/superblock_packed.bin \
22+
test/data/testnet_beacon.bin
23+
24+
TEXT_TEST_FILES = \
25+
test/data/superblock.txt \
26+
test/data/superblock_unpacked.txt
27+
28+
GENERATED_TEST_FILES = $(JSON_TEST_FILES:.json=.json.h) $(BINARY_TEST_FILES:.bin=.bin.h) $(TEXT_TEST_FILES:.txt=.txt.h)
2629

2730
# test_n binary #
2831
GRIDCOIN_TESTS =\
29-
test/checkpoints_tests.cpp \
30-
test/dos_tests.cpp \
31-
test/accounting_tests.cpp \
32-
test/allocator_tests.cpp \
33-
test/base32_tests.cpp \
34-
test/base58_tests.cpp \
35-
test/base64_tests.cpp \
36-
test/bignum_tests.cpp \
37-
test/fs_tests.cpp \
38-
test/getarg_tests.cpp \
39-
test/gridcoin_tests.cpp \
40-
test/gridcoin/appcache_tests.cpp \
41-
test/gridcoin/block_finder_tests.cpp \
42-
test/gridcoin/beacon_tests.cpp \
43-
test/gridcoin/claim_tests.cpp \
44-
test/gridcoin/contract_tests.cpp \
45-
test/gridcoin/cpid_tests.cpp \
46-
test/gridcoin/enumbytes_tests.cpp \
47-
test/gridcoin/magnitude_tests.cpp \
48-
test/gridcoin/project_tests.cpp \
49-
test/gridcoin/researcher_tests.cpp \
50-
test/gridcoin/superblock_tests.cpp \
51-
test/key_tests.cpp \
52-
test/mruset_tests.cpp \
53-
test/multisig_tests.cpp \
54-
test/netbase_tests.cpp \
55-
test/rpc_tests.cpp \
56-
test/script_p2sh_tests.cpp \
57-
test/script_tests.cpp \
58-
test/serialize_tests.cpp \
59-
test/sigopcount_tests.cpp \
60-
test/test_gridcoin.cpp \
61-
test/transaction_tests.cpp \
62-
test/uint256_tests.cpp \
63-
test/util_tests.cpp \
64-
test/wallet_tests.cpp
65-
66-
67-
test_test_gridcoin_SOURCES = $(GRIDCOIN_TESTS) $(JSON_TEST_FILES) $(OTHER_TEST_FILES)
32+
test/checkpoints_tests.cpp \
33+
test/dos_tests.cpp \
34+
test/accounting_tests.cpp \
35+
test/allocator_tests.cpp \
36+
test/base32_tests.cpp \
37+
test/base58_tests.cpp \
38+
test/base64_tests.cpp \
39+
test/bignum_tests.cpp \
40+
test/fs_tests.cpp \
41+
test/getarg_tests.cpp \
42+
test/gridcoin_tests.cpp \
43+
test/gridcoin/appcache_tests.cpp \
44+
test/gridcoin/block_finder_tests.cpp \
45+
test/gridcoin/beacon_tests.cpp \
46+
test/gridcoin/claim_tests.cpp \
47+
test/gridcoin/contract_tests.cpp \
48+
test/gridcoin/cpid_tests.cpp \
49+
test/gridcoin/enumbytes_tests.cpp \
50+
test/gridcoin/magnitude_tests.cpp \
51+
test/gridcoin/project_tests.cpp \
52+
test/gridcoin/researcher_tests.cpp \
53+
test/gridcoin/superblock_tests.cpp \
54+
test/key_tests.cpp \
55+
test/mruset_tests.cpp \
56+
test/multisig_tests.cpp \
57+
test/netbase_tests.cpp \
58+
test/rpc_tests.cpp \
59+
test/script_p2sh_tests.cpp \
60+
test/script_tests.cpp \
61+
test/serialize_tests.cpp \
62+
test/sigopcount_tests.cpp \
63+
test/test_gridcoin.cpp \
64+
test/transaction_tests.cpp \
65+
test/uint256_tests.cpp \
66+
test/util_tests.cpp \
67+
test/wallet_tests.cpp
68+
69+
70+
test_test_gridcoin_SOURCES = $(GRIDCOIN_TESTS) $(JSON_TEST_FILES) $(BINARY_TEST_FILES) $(TEXT_TEST_FILES)
6871
test_test_gridcoin_CPPFLAGS = $(AM_CPPFLAGS) $(GRIDCOIN_INCLUDES) -I$(builddir)/test/ $(TESTDEFS) $(EVENT_CFLAGS)
6972
test_test_gridcoin_LDADD = $(LIBGRIDCOIN_UTIL) $(LIBUNIVALUE) $(LIBLEVELDB) $(LIBLEVELDB_SSE42) $(LIBMEMENV) $(BOOST_LIBS) $(BOOST_UNIT_TEST_FRAMEWORK_LIB) $(EVENT_LIBS) $(EVENT_PTHREADS_LIBS) $(CURL_LIBS) $(LIBZIP_LIBS)
7073
test_test_gridcoin_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
7174

7275
test_test_gridcoin_LDADD += $(BDB_LIBS) $(SSL_LIBS) $(CRYPTO_LIBS) $(MINIUPNPC_LIBS) $(LIBGRIDCOIN_CRYPTO)
7376
test_test_gridcoin_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) -static
7477

75-
CLEAN_GRIDCOIN_TEST = test/*.gcda test/*.gcno
78+
nodist_test_test_gridcoin_SOURCES = $(GENERATED_TEST_FILES)
79+
80+
$(GRIDCOIN_TESTS): $(GENERATED_TEST_FILES)
81+
82+
CLEAN_GRIDCOIN_TEST = test/*.gcda test/*.gcno $(GENERATED_TEST_FILES)
7683

7784
CLEANFILES += $(CLEAN_GRIDCOIN_TEST)
7885

@@ -83,3 +90,29 @@ gridcoin_test_check: $(TEST_BINARY) FORCE
8390

8491
gridcoin_test_clean : FORCE
8592
rm -f $(CLEAN_GRIDCOIN_TEST) $(test_test_GRIDCOIN_OBJECTS) $(TEST_BINARY)
93+
94+
%.json.h: %.json
95+
@$(MKDIR_P) $(@D)
96+
@{ \
97+
echo "namespace json_tests{" && \
98+
echo "static unsigned const char $(*F)[] = {" && \
99+
$(HEXDUMP) -v -e '8/1 "0x%02x, "' -e '"\n"' $< | $(SED) -e 's/0x ,//g' && \
100+
echo "};};"; \
101+
} > "[email protected]" && mv -f "[email protected]" "$@"
102+
@echo "Generated $@"
103+
104+
%.bin.h: %.bin
105+
@$(MKDIR_P) $(@D)
106+
@{ \
107+
echo "static unsigned const char $(*F)_bin[] = {" && \
108+
$(HEXDUMP) -v -e '8/1 "0x%02x, "' -e '"\n"' $< | $(SED) -e 's/0x ,//g' && \
109+
echo "};"; \
110+
} > "[email protected]" && mv -f "[email protected]" "$@"
111+
@echo "Generated $@"
112+
113+
%.txt.h: %.txt
114+
@$(MKDIR_P) $(@D)
115+
@{ \
116+
echo "static const std::string $(*F)_text = R\"(" && cat $< && echo ")\";"; \
117+
} > "[email protected]" && mv -f "[email protected]" "$@"
118+
@echo "Generated $@"

src/test/base58_tests.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@
22

33
#include "base58.h"
44
#include "util.h"
5-
#include "data/base58_encode_decode.json.h"
6-
#include "data/base58_keys_valid.json.h"
7-
#include "data/base58_keys_invalid.json.h"
5+
#include "test/data/base58_encode_decode.json.h"
6+
#include "test/data/base58_keys_valid.json.h"
7+
#include "test/data/base58_keys_invalid.json.h"
88

99
#include <univalue.h>
1010

11-
extern UniValue read_json(std::string& jsondata);
11+
extern UniValue read_json(const std::string& jsondata);
1212

1313
BOOST_AUTO_TEST_SUITE(base58_tests)
1414

1515
// Goal: test low-level base58 encoding functionality
1616
BOOST_AUTO_TEST_CASE(base58_EncodeBase58)
1717
{
18-
UniValue tests = read_json(json_tests::base58_encode_decode);
18+
UniValue tests = read_json(std::string(json_tests::base58_encode_decode, json_tests::base58_encode_decode + sizeof(json_tests::base58_encode_decode)));
1919
for (unsigned int idx = 0; idx < tests.size(); idx++)
2020
{
2121
UniValue test = tests[idx];
@@ -36,7 +36,7 @@ BOOST_AUTO_TEST_CASE(base58_EncodeBase58)
3636
// Goal: test low-level base58 decoding functionality
3737
BOOST_AUTO_TEST_CASE(base58_DecodeBase58)
3838
{
39-
UniValue tests = read_json(json_tests::base58_encode_decode);
39+
UniValue tests = read_json(std::string(json_tests::base58_encode_decode, json_tests::base58_encode_decode + sizeof(json_tests::base58_encode_decode)));
4040
std::vector<unsigned char> result;
4141

4242
for (unsigned int idx = 0; idx < tests.size(); idx++) {
@@ -104,7 +104,7 @@ class TestPayloadVisitor : public boost::static_visitor<bool>
104104
// Goal: check that parsed keys match test payload
105105
BOOST_AUTO_TEST_CASE(base58_keys_valid_parse)
106106
{
107-
UniValue tests = read_json(json_tests::base58_keys_valid);
107+
UniValue tests = read_json(std::string(json_tests::base58_keys_valid, json_tests::base58_keys_valid + sizeof(json_tests::base58_keys_valid)));
108108
std::vector<unsigned char> result;
109109
CBitcoinSecret secret;
110110
CBitcoinAddress addr;
@@ -162,7 +162,7 @@ BOOST_AUTO_TEST_CASE(base58_keys_valid_parse)
162162
// Goal: check that generated keys match test vectors
163163
BOOST_AUTO_TEST_CASE(base58_keys_valid_gen)
164164
{
165-
UniValue tests = read_json(json_tests::base58_keys_valid);
165+
UniValue tests = read_json(std::string(json_tests::base58_keys_valid, json_tests::base58_keys_valid + sizeof(json_tests::base58_keys_valid)));
166166
std::vector<unsigned char> result;
167167
// Save global state
168168
bool fTestNet_stored = fTestNet;
@@ -226,7 +226,7 @@ BOOST_AUTO_TEST_CASE(base58_keys_valid_gen)
226226
// Goal: check that base58 parsing code is robust against a variety of corrupted data
227227
BOOST_AUTO_TEST_CASE(base58_keys_invalid)
228228
{
229-
UniValue tests = read_json(json_tests::base58_keys_invalid);
229+
UniValue tests = read_json(std::string(json_tests::base58_keys_invalid, json_tests::base58_keys_invalid + sizeof(json_tests::base58_keys_invalid)));
230230
std::vector<unsigned char> result;
231231
CBitcoinSecret secret;
232232
CBitcoinAddress addr;

src/test/data/base58_encode_decode.json.h

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/test/data/base58_keys_invalid.json.h

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)