diff --git a/.travis.yml b/.travis.yml index 6fc29f6..cccba32 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,12 @@ language: cpp matrix: include: + - os: linux + dist: trusty + sudo: required + env: + - DEPLOY_FILE=tests.txt + - ARCH="tests" - os: linux dist: trusty sudo: required @@ -109,6 +115,10 @@ services: install: - export REPOL=https://github.com/bitbaymarket/bitbay-prebuilt-libs1 - export BASE1=$REPOL/releases/download/base1 +- > + if [[ $ARCH == "tests" ]]; then + export ; + fi - > if [[ $ARCH == "mainnet-node" ]]; then export ; @@ -250,6 +260,10 @@ install: before_script: - export REPOL=https://github.com/bitbaymarket/bitbay-prebuilt-libs1 - export BASE1=$REPOL/releases/download/base1 +- > + if [[ $ARCH == "tests" ]]; then + docker pull bitbayofficial/builder-linux64:alpine; + fi - > if [[ $ARCH == "mainnet-node" ]]; then docker pull bitbayofficial/builder-linux64:alpine; @@ -321,6 +335,30 @@ before_script: script: - cd "$TRAVIS_BUILD_DIR" +- > + if [[ $ARCH == "tests" ]]; then + echo "LIBS += -static" > bitbayd-local.pri && + echo "CONFIG += silent" >> bitbayd-local.pri && + docker run --rm \ + -v $(pwd):/mnt \ + -u $(stat -c %u:%g .) \ + bitbayofficial/builder-linux64:alpine \ + /bin/sh -c "qmake-qt5 -v && \ + cd /mnt && \ + ls -al && \ + qmake-qt5 \ + CICD=travis_x64 \ + \"USE_DBUS=0\" \ + \"USE_QRCODE=0\" \ + \"BOOST_LIB_SUFFIX=-mt\" \ + bitbay-test.pro && \ + sed -i 's/\/usr\/lib\/libssl.so/-lssl/' Makefile && + sed -i 's/\/usr\/lib\/libcrypto.so/-lcrypto/' Makefile && + sed -i s:sys/fcntl.h:fcntl.h: src/compat.h && + make -j2 && + ./bitbay-test > tests.txt && + cat tests.txt"; + fi - > if [[ $ARCH == "mainnet-node" ]]; then echo "LIBS += -static" > bitbayd-local.pri && @@ -622,7 +660,6 @@ script: qmake \ CICD=travis_x32 \ QMAKE_LRELEASE=lrelease \ - \"USE_QRCODE=1\" \ bitbayd.pro && \ mv Makefile.Release Makefile.tmp && ( \ cat Makefile.tmp | \ @@ -641,7 +678,6 @@ script: qmake \ CICD=travis_x64 \ QMAKE_LRELEASE=lrelease \ - \"USE_QRCODE=1\" \ bitbayd.pro && \ mv Makefile.Release Makefile.tmp && ( \ cat Makefile.tmp | \ diff --git a/bitbay-qt.pro b/bitbay-qt.pro index b952b17..db559e7 100644 --- a/bitbay-qt.pro +++ b/bitbay-qt.pro @@ -172,6 +172,8 @@ QWT_CONFIG += QwtWidgets DEFINES += QWT_MOC_INCLUDE include(src/qt/qwt/qwt.pri) +SOURCES += src/init.cpp + CODECFORTR = UTF-8 isEmpty(QMAKE_LRELEASE) { diff --git a/bitbay-test.pro b/bitbay-test.pro new file mode 100644 index 0000000..6eeb96b --- /dev/null +++ b/bitbay-test.pro @@ -0,0 +1,193 @@ +TEMPLATE = app +TARGET = bitbay-test +VERSION = 3.0.0 + +count(USE_WALLET, 0) { + USE_WALLET=1 +} +contains(USE_WALLET, 1) { + message(Building with WALLET support) + CONFIG += wallet +} + +count(USE_TESTNET, 1) { + contains(USE_TESTNET, 1) { + message(Building with TESTNET enabled) + DEFINES += USE_TESTNET + } +} + +exists(bitbayd-local.pri) { + include(bitbayd-local.pri) +} + +CONFIG -= qt +INCLUDEPATH += build + +# mac builds +include(bitbay-mac.pri) + +INCLUDEPATH += src src/json src/qt $$PWD +DEFINES += BOOST_THREAD_USE_LIB +DEFINES += BOOST_SPIRIT_THREADSAFE +DEFINES += BOOST_NO_CXX11_SCOPED_ENUMS +CONFIG += console +CONFIG -= app_bundle +CONFIG += no_include_pwd +CONFIG += thread +CONFIG += c++11 + +greaterThan(QT_MAJOR_VERSION, 4) { + DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 +} + +# for boost 1.37, add -mt to the boost libraries +# use: qmake BOOST_LIB_SUFFIX=-mt +# for boost thread win32 with _win32 sufix +# use: BOOST_THREAD_LIB_SUFFIX=_win32-... +# or when linking against a specific BerkelyDB version: BDB_LIB_SUFFIX=-4.8 + +# Dependency library locations can be customized with: +# BOOST_INCLUDE_PATH, BOOST_LIB_PATH, BDB_INCLUDE_PATH, +# BDB_LIB_PATH, OPENSSL_INCLUDE_PATH and OPENSSL_LIB_PATH respectively + +OBJECTS_DIR = build +MOC_DIR = build +UI_DIR = build + +!win32 { + # for extra security against potential buffer overflows: enable GCCs Stack Smashing Protection + QMAKE_CXXFLAGS *= -fstack-protector-all --param ssp-buffer-size=1 + QMAKE_LFLAGS *= -fstack-protector-all --param ssp-buffer-size=1 + # We need to exclude this for Windows cross compile with MinGW 4.2.x, as it will result in a non-working executable! + # This can be enabled for Windows, when we switch to MinGW >= 4.4.x. +} +# for extra security on Windows: enable ASLR and DEP via GCC linker flags +#win32:QMAKE_LFLAGS *= -Wl,--dynamicbase -Wl,--nxcompat +#win32:QMAKE_LFLAGS += -static-libgcc -static-libstdc++ + +# use: qmake "USE_UPNP=1" ( enabled by default; default) +# or: qmake "USE_UPNP=0" (disabled by default) +# or: qmake "USE_UPNP=-" (not supported) +# miniupnpc (http://miniupnp.free.fr/files/) must be installed for support +contains(USE_UPNP, -) { + message(Building without UPNP support) +} else { + message(Building with UPNP support) + count(USE_UPNP, 0) { + USE_UPNP=1 + } + DEFINES += USE_UPNP=$$USE_UPNP MINIUPNP_STATICLIB STATICLIB + INCLUDEPATH += $$MINIUPNPC_INCLUDE_PATH + LIBS += $$join(MINIUPNPC_LIB_PATH,,-L,) -lminiupnpc + win32:LIBS += -liphlpapi +} + +INCLUDEPATH += src/leveldb/include src/leveldb/helpers +LIBS += $$PWD/src/leveldb/out-static/libleveldb.a $$PWD/src/leveldb/out-static/libmemenv.a +HEADERS += src/txdb-leveldb.h +SOURCES += src/txdb-leveldb.cpp +!win32 { + # we use QMAKE_CXXFLAGS_RELEASE even without RELEASE=1 because we use RELEASE to indicate linking preferences not -O preferences + macx:LEVELDB_CXXFLAGS=-mmacosx-version-min=10.9 + genleveldb.commands = cd $$PWD/src/leveldb && CC=$$QMAKE_CC CXX=$$QMAKE_CXX $(MAKE) OPT=\"$$QMAKE_CXXFLAGS $$LEVELDB_CXXFLAGS $$QMAKE_CXXFLAGS_RELEASE\" out-static/libleveldb.a out-static/libmemenv.a +} else { + # make an educated guess about what the ranlib command is called + isEmpty(QMAKE_RANLIB) { + # QMAKE_RANLIB = $$replace(QMAKE_STRIP, strip, ranlib) + QMAKE_RANLIB = echo + } + LIBS += -lshlwapi + genleveldb.commands = cd $$PWD/src/leveldb && CC=$$QMAKE_CC CXX=$$QMAKE_CXX TARGET_OS=OS_WINDOWS_CROSSCOMPILE $(MAKE) OPT=\"$$QMAKE_CXXFLAGS $$QMAKE_CXXFLAGS_RELEASE\" out-static/libleveldb.a out-static/libmemenv.a && $$QMAKE_RANLIB $$PWD/src/leveldb/out-static/libleveldb.a && $$QMAKE_RANLIB $$PWD/src/leveldb/out-static/libmemenv.a +} +genleveldb.target = $$PWD/src/leveldb/out-static/libleveldb.a +genleveldb.depends = FORCE +PRE_TARGETDEPS += $$PWD/src/leveldb/out-static/libleveldb.a +QMAKE_EXTRA_TARGETS += genleveldb +# Gross ugly hack that depends on qmake internals, unfortunately there is no other way to do it. +QMAKE_CLEAN += $$PWD/src/leveldb/out-static/libleveldb.a; cd $$PWD/src/leveldb ; $(MAKE) clean + +QMAKE_CXXFLAGS_WARN_ON = -fdiagnostics-show-option -Wall -Wextra -Wno-ignored-qualifiers -Wformat -Wformat-security -Wno-unused-parameter -Wstack-protector + +#json lib +include(src/json/json.pri) + +#core +include(src/core.pri) + +SOURCES += \ + src/test/test_bitcoin.cpp \ + \ + src/test/allocator_tests.cpp \ + src/test/base32_tests.cpp \ + src/test/base64_tests.cpp \ + src/test/bignum_tests.cpp \ + src/test/getarg_tests.cpp \ + src/test/hmac_tests.cpp \ + src/test/mruset_tests.cpp \ + src/test/netbase_tests.cpp \ + src/test/serialize_tests.cpp \ + src/test/sigopcount_tests.cpp \ + src/test/uint160_tests.cpp \ + src/test/uint256_tests.cpp \ + +# disabled tests +#SOURCES += \ +# src/test/accounting_tests.cpp \ +# src/test/bip32_tests.cpp \ +# src/test/base58_tests.cpp \ +# src/test/Checkpoints_tests.cpp \ +# src/test/key_tests.cpp \ +# src/test/script_tests.cpp \ +# src/test/wallet_tests.cpp \ + + +CODECFORTR = UTF-8 + +# platform specific defaults, if not overridden on command line +isEmpty(BOOST_LIB_SUFFIX) { + macx:BOOST_LIB_SUFFIX = -mt + windows:BOOST_LIB_SUFFIX = -mt +} + +isEmpty(BOOST_THREAD_LIB_SUFFIX) { + win32:BOOST_THREAD_LIB_SUFFIX = $$BOOST_LIB_SUFFIX + else:BOOST_THREAD_LIB_SUFFIX = $$BOOST_LIB_SUFFIX +} + +windows:DEFINES += WIN32 +windows:RC_FILE = src/qt/res/bitcoin-qt.rc + +# Set libraries and includes at end, to use platform-defined defaults if not overridden +INCLUDEPATH += $$BDB_INCLUDE_PATH +INCLUDEPATH += $$BOOST_INCLUDE_PATH +INCLUDEPATH += $$OPENSSL_INCLUDE_PATH + +LIBS += $$join(BDB_LIB_PATH,,-L,) +LIBS += $$join(BOOST_LIB_PATH,,-L,) +LIBS += $$join(OPENSSL_LIB_PATH,,-L,) +LIBS += -lssl -lcrypto +LIBS += -ldb$$BDB_LIB_SUFFIX +LIBS += -ldb_cxx$$BDB_LIB_SUFFIX +LIBS += -lz + +# -lgdi32 has to happen after -lcrypto (see #681) +windows:LIBS += -lws2_32 -lshlwapi -lmswsock -lole32 -loleaut32 -luuid -lgdi32 + +LIBS += -lboost_system$$BOOST_LIB_SUFFIX +LIBS += -lboost_filesystem$$BOOST_LIB_SUFFIX +LIBS += -lboost_program_options$$BOOST_LIB_SUFFIX +LIBS += -lboost_thread$$BOOST_THREAD_LIB_SUFFIX +LIBS += -lboost_chrono$$BOOST_LIB_SUFFIX +LIBS += -lboost_unit_test_framework$$BOOST_LIB_SUFFIX + +!contains(LIBS, -static) { + DEFINES += BOOST_TEST_DYN_LINK +} + +DISTFILES += \ + src/makefile.osx \ + src/makefile.unix \ + .travis.yml \ + .appveyor.yml + diff --git a/bitbayd.pro b/bitbayd.pro index 2f6d577..18565a1 100644 --- a/bitbayd.pro +++ b/bitbayd.pro @@ -155,6 +155,7 @@ include(src/json/json.pri) include(src/core.pri) SOURCES += \ + src/init.cpp \ src/bitcoind.cpp \ CODECFORTR = UTF-8 diff --git a/src/Makefile.am b/src/Makefile.am index 098fd57..5fbc141 100755 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -97,8 +97,6 @@ libbitcoin_server_a_SOURCES = \ addrman.cpp \ crypter.cpp \ key.cpp \ - init.cpp \ - bitcoind.cpp \ keystore.cpp \ core.cpp \ main.cpp \ @@ -137,7 +135,7 @@ libbitcoin_server_a_SOURCES += compat/glibc_compat.cpp endif # bitcoin binary # -bitbayd_SOURCES = bitcoind.cpp +bitbayd_SOURCES = bitcoind.cpp init.cpp bitbayd_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) $(EVENT_CFLAGS) bitbayd_CXXFLAGS = $(AM_CXXFLAGS) $(PIC_FLAGS) $(PIE_FLAGS) bitbayd_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) diff --git a/src/Makefile.test.include b/src/Makefile.test.include index db52e25..76da057 100755 --- a/src/Makefile.test.include +++ b/src/Makefile.test.include @@ -1,33 +1,12 @@ TESTS += test/test_bitcoin bin_PROGRAMS += test/test_bitcoin -noinst_PROGRAMS = test/test_bitcoin_fuzzy TEST_SRCDIR = test TEST_BINARY=test/test_bitcoin$(EXEEXT) - -EXTRA_DIST += \ - test/bctest.py \ - test/bitcoin-util-test.py \ - test/data/bitcoin-util-test.json \ - test/data/blanktx.hex \ - test/data/tt-delin1-out.hex \ - test/data/tt-delout1-out.hex \ - test/data/tt-locktime317000-out.hex \ - test/data/tx394b54bb.hex \ - test/data/txcreate1.hex \ - test/data/txcreate2.hex \ - test/data/txcreatedata1.hex \ - test/data/txcreatedata2.hex \ - test/data/txcreatesign.hex - JSON_TEST_FILES = \ - test/data/script_tests.json \ test/data/base58_keys_valid.json \ test/data/base58_encode_decode.json \ - test/data/base58_keys_invalid.json \ - test/data/tx_invalid.json \ - test/data/tx_valid.json \ - test/data/sighash.json + test/data/base58_keys_invalid.json RAW_TEST_FILES = @@ -61,42 +40,25 @@ GENERATED_TEST_FILES = $(JSON_TEST_FILES:.json=.json.h) $(RAW_TEST_FILES:.raw=.r BITCOIN_TEST_SUITE = \ - test/scriptnum10.h \ test/test_bitcoin.cpp \ - test/test_bitcoin.h \ - test/testutil.cpp \ - test/testutil.h + test/test_bitcoin.h BITCOIN_TESTS = \ - test/arith_uint256_tests.cpp \ - test/addrman_tests.cpp \ test/allocator_tests.cpp \ test/base32_tests.cpp \ test/base64_tests.cpp \ - test/bswap_tests.cpp \ - test/coins_tests.cpp \ - test/crypto_tests.cpp \ + test/bignum_tests.cpp \ test/getarg_tests.cpp \ - test/jsonutil.h \ - test/jsonutil.cpp \ - test/limitedmap_tests.cpp \ - test/dbwrapper_tests.cpp \ + test/hmac_tests.cpp \ + test/mruset_tests.cpp \ test/netbase_tests.cpp \ - test/pmt_tests.cpp \ - test/reverselock_tests.cpp \ - test/sanity_tests.cpp \ - test/scheduler_tests.cpp \ - test/scriptnum_tests.cpp \ test/serialize_tests.cpp \ test/sigopcount_tests.cpp \ - test/skiplist_tests.cpp \ - test/streams_tests.cpp \ - test/timedata_tests.cpp \ - test/uint256_tests.cpp \ - test/univalue_tests.cpp - -BITCOIN_TESTS += \ - wallet/test/wallet_tests.cpp + test/uint160_tests.cpp \ + test/uint256_tests.cpp + +#BITCOIN_TESTS += \ +# wallet/test/wallet_tests.cpp # wallet/test/walletdb_tests.cpp \ # wallet/test/crypto_tests.cpp @@ -135,25 +97,25 @@ test_test_bitcoin_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) -s # # test_bitcoin_fuzzy binary # -test_test_bitcoin_fuzzy_SOURCES = test/test_bitcoin_fuzzy.cpp -test_test_bitcoin_fuzzy_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) -test_test_bitcoin_fuzzy_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) -test_test_bitcoin_fuzzy_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) - -test_test_bitcoin_fuzzy_LDADD = \ - $(LIBBITCOIN_SERVER) \ - $(LIBBITCOIN_COMMON) \ - $(LIBUNIVALUE) \ - $(LIBBITCOIN_UTIL) \ - $(LIBBITCOIN_WALLET) \ - $(LIBBITCOIN_CONSENSUS) \ - $(LIBBITCOIN_CRYPTO) \ - $(LIBLEVELDB) \ - $(LIBLEVELDB_SSE42) \ - $(LIBMEMENV) \ - $(LIBSECP256K1) - -test_test_bitcoin_fuzzy_LDADD += $(BOOST_LIBS) $(BDB_LIBS) $(SSL_LIBS) $(CRYPTO_LIBS) $(MINIUPNPC_LIBS) $(EVENT_PTHREADS_LIBS) $(EVENT_LIBS) +#test_test_bitcoin_fuzzy_SOURCES = test/test_bitcoin_fuzzy.cpp +#test_test_bitcoin_fuzzy_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) +#test_test_bitcoin_fuzzy_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) +#test_test_bitcoin_fuzzy_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) +# +#test_test_bitcoin_fuzzy_LDADD = \ +# $(LIBBITCOIN_SERVER) \ +# $(LIBBITCOIN_COMMON) \ +# $(LIBUNIVALUE) \ +# $(LIBBITCOIN_UTIL) \ +# $(LIBBITCOIN_WALLET) \ +# $(LIBBITCOIN_CONSENSUS) \ +# $(LIBBITCOIN_CRYPTO) \ +# $(LIBLEVELDB) \ +# $(LIBLEVELDB_SSE42) \ +# $(LIBMEMENV) \ +# $(LIBSECP256K1) +# +#test_test_bitcoin_fuzzy_LDADD += $(BOOST_LIBS) $(BDB_LIBS) $(SSL_LIBS) $(CRYPTO_LIBS) $(MINIUPNPC_LIBS) $(EVENT_PTHREADS_LIBS) $(EVENT_LIBS) # nodist_test_test_bitcoin_SOURCES = $(GENERATED_TEST_FILES) diff --git a/src/core.pri b/src/core.pri index fab78c0..208c76b 100644 --- a/src/core.pri +++ b/src/core.pri @@ -51,7 +51,6 @@ SOURCES += \ $$PWD/script.cpp \ $$PWD/core.cpp \ $$PWD/main.cpp \ - $$PWD/init.cpp \ $$PWD/net.cpp \ $$PWD/checkpoints.cpp \ $$PWD/addrman.cpp \ diff --git a/src/test/base32_tests.cpp b/src/test/base32_tests.cpp index fdf3285..6063a88 100644 --- a/src/test/base32_tests.cpp +++ b/src/test/base32_tests.cpp @@ -1,6 +1,7 @@ #include #include "util.h" +//#include "utilstrencodings.h" BOOST_AUTO_TEST_SUITE(base32_tests) diff --git a/src/test/bignum_tests.cpp b/src/test/bignum_tests.cpp index 7446818..b161f2c 100644 --- a/src/test/bignum_tests.cpp +++ b/src/test/bignum_tests.cpp @@ -46,7 +46,7 @@ BOOST_AUTO_TEST_SUITE(bignum_tests) // Let's force this code not to be inlined, in order to actually // test a generic version of the function. This increases the chance // that -ftrapv will detect overflows. -NOINLINE void mysetint64(CBigNum& num, int64 n) +NOINLINE void mysetint64(CBigNum& num, int64_t n) { num.setint64(n); } @@ -55,7 +55,7 @@ NOINLINE void mysetint64(CBigNum& num, int64 n) // value to 0, then the second one with a non-inlined function. BOOST_AUTO_TEST_CASE(bignum_setint64) { - int64 n; + int64_t n; { n = 0; @@ -103,7 +103,7 @@ BOOST_AUTO_TEST_CASE(bignum_setint64) BOOST_CHECK(num.ToString() == "-5"); } { - n = std::numeric_limits::min(); + n = std::numeric_limits::min(); CBigNum num(n); BOOST_CHECK(num.ToString() == "-9223372036854775808"); num.setulong(0); @@ -112,7 +112,7 @@ BOOST_AUTO_TEST_CASE(bignum_setint64) BOOST_CHECK(num.ToString() == "-9223372036854775808"); } { - n = std::numeric_limits::max(); + n = std::numeric_limits::max(); CBigNum num(n); BOOST_CHECK(num.ToString() == "9223372036854775807"); num.setulong(0); diff --git a/src/test/hmac_tests.cpp b/src/test/hmac_tests.cpp index 92ca5e6..6b153dc 100644 --- a/src/test/hmac_tests.cpp +++ b/src/test/hmac_tests.cpp @@ -2,6 +2,7 @@ #include "hash.h" #include "util.h" +//#include "utilstrencodings.h" using namespace std; diff --git a/src/test/serialize_tests.cpp b/src/test/serialize_tests.cpp index 90ac89f..c3f5f0a 100644 --- a/src/test/serialize_tests.cpp +++ b/src/test/serialize_tests.cpp @@ -4,6 +4,7 @@ #include #include "serialize.h" +#include "uint256.h" using namespace std; @@ -21,7 +22,7 @@ BOOST_AUTO_TEST_CASE(varints) BOOST_CHECK(size == ss.size()); } - for (uint64 i = 0; i < 100000000000ULL; i += 999999937) { + for (uint64_t i = 0; i < 100000000000ULL; i += 999999937) { ss << VARINT(i); size += ::GetSerializeSize(VARINT(i), 0, 0); BOOST_CHECK(size == ss.size()); @@ -34,8 +35,8 @@ BOOST_AUTO_TEST_CASE(varints) BOOST_CHECK_MESSAGE(i == j, "decoded:" << j << " expected:" << i); } - for (uint64 i = 0; i < 100000000000ULL; i += 999999937) { - uint64 j; + for (uint64_t i = 0; i < 100000000000ULL; i += 999999937) { + uint64_t j; ss >> VARINT(j); BOOST_CHECK_MESSAGE(i == j, "decoded:" << j << " expected:" << i); } diff --git a/src/test/test_bitcoin.cpp b/src/test/test_bitcoin.cpp new file mode 100644 index 0000000..8e0bb07 --- /dev/null +++ b/src/test/test_bitcoin.cpp @@ -0,0 +1,46 @@ +#define BOOST_TEST_MODULE Bitcoin Test Suite +#include + +#include "main.h" +#include "wallet.h" + +CWallet* pwalletMain; +CClientUIInterface uiInterface; +bool fConfChange = false; +unsigned int nNodeLifespan = 7; +unsigned int nMinerSleep = 500; +bool fUseFastIndex = true; +unsigned int nDerivationMethodIndex = 0; +bool fMinimizeCoinAge = false; + +extern bool fPrintToConsole; +extern void noui_connect(); +extern void InitParamsOnStart(); + +struct TestingSetup { + TestingSetup() { + fPrintToConsole = true; // don't want to write to debug.log file + noui_connect(); + InitParamsOnStart(); + pwalletMain = new CWallet(); + RegisterWallet(pwalletMain); + } + ~TestingSetup() + { + delete pwalletMain; + pwalletMain = NULL; + } +}; + +BOOST_GLOBAL_FIXTURE(TestingSetup); + +void Shutdown(void* parg) +{ + exit(0); +} + +void StartShutdown() +{ + exit(0); +} + diff --git a/src/test/test_bitcoin.h b/src/test/test_bitcoin.h new file mode 100644 index 0000000..769ae5a --- /dev/null +++ b/src/test/test_bitcoin.h @@ -0,0 +1,92 @@ +// Copyright (c) 2015 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_TEST_BITCOIN_H +#define BITCOIN_TEST_TEST_BITCOIN_H + +#include "chainparamsbase.h" +#include "key.h" +#include "pubkey.h" +#include "txdb.h" +#include "txmempool.h" + +#include +#include + +/** Basic testing setup. + * This just configures logging and chain parameters. + */ +struct BasicTestingSetup { + ECCVerifyHandle globalVerifyHandle; + + BasicTestingSetup(const std::string& chainName = CBaseChainParams::MAIN); + ~BasicTestingSetup(); +}; + +/** Testing setup that configures a complete environment. + * Included are data directory, coins database, script check threads + * and wallet (if enabled) setup. + */ +struct TestingSetup: public BasicTestingSetup { + CCoinsViewDB *pcoinsdbview; + boost::filesystem::path pathTemp; + boost::thread_group threadGroup; + + TestingSetup(const std::string& chainName = CBaseChainParams::MAIN); + ~TestingSetup(); +}; + +class CBlock; +struct CMutableTransaction; +class CScript; + +// +// Testing fixture that pre-creates a +// 100-block REGTEST-mode block chain +// +struct TestChain100Setup : public TestingSetup { + TestChain100Setup(); + + // Create a new block with just given transactions, coinbase paying to + // scriptPubKey, and try to add it to the current chain. + CBlock CreateAndProcessBlock(const std::vector& txns, + const CScript& scriptPubKey); + + ~TestChain100Setup(); + + std::vector coinbaseTxns; // For convenience, coinbase transactions + CKey coinbaseKey; // private/public key needed to spend coinbase transactions +}; + +class CTxMemPoolEntry; +class CTxMemPool; + +struct TestMemPoolEntryHelper +{ + // Default values + CAmount nFee; + int64_t nTime; + double dPriority; + unsigned int nHeight; + bool hadNoDependencies; + bool spendsCoinbase; + unsigned int sigOpCount; + LockPoints lp; + + TestMemPoolEntryHelper() : + nFee(0), nTime(0), dPriority(0.0), nHeight(1), + hadNoDependencies(false), spendsCoinbase(false), sigOpCount(1) { } + + CTxMemPoolEntry FromTx(CMutableTransaction &tx, CTxMemPool *pool = NULL); + + // Change the default value + TestMemPoolEntryHelper &Fee(CAmount _fee) { nFee = _fee; return *this; } + TestMemPoolEntryHelper &Time(int64_t _time) { nTime = _time; return *this; } + TestMemPoolEntryHelper &Priority(double _priority) { dPriority = _priority; return *this; } + TestMemPoolEntryHelper &Height(unsigned int _height) { nHeight = _height; return *this; } + TestMemPoolEntryHelper &HadNoDependencies(bool _hnd) { hadNoDependencies = _hnd; return *this; } + TestMemPoolEntryHelper &SpendsCoinbase(bool _flag) { spendsCoinbase = _flag; return *this; } + TestMemPoolEntryHelper &SigOps(unsigned int _sigops) { sigOpCount = _sigops; return *this; } +}; +#endif diff --git a/src/test/uint160_tests.cpp b/src/test/uint160_tests.cpp index 35cb35b..3d0b4a1 100644 --- a/src/test/uint160_tests.cpp +++ b/src/test/uint160_tests.cpp @@ -10,7 +10,7 @@ BOOST_AUTO_TEST_CASE(uint160_equality) uint160 num2 = 11; BOOST_CHECK(num1+1 == num2); - uint64 num3 = 10; + uint64_t num3 = 10; BOOST_CHECK(num1 == num3); BOOST_CHECK(num1+num2 == num3+num2); } diff --git a/src/test/uint256_tests.cpp b/src/test/uint256_tests.cpp index efdc8a6..cd2a3ef 100644 --- a/src/test/uint256_tests.cpp +++ b/src/test/uint256_tests.cpp @@ -10,7 +10,7 @@ BOOST_AUTO_TEST_CASE(uint256_equality) uint256 num2 = 11; BOOST_CHECK(num1+1 == num2); - uint64 num3 = 10; + uint64_t num3 = 10; BOOST_CHECK(num1 == num3); BOOST_CHECK(num1+num2 == num3+num2); }