aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'src/test')
-rw-r--r--src/test/Checkpoints_tests.cpp10
-rw-r--r--src/test/DoS_tests.cpp26
-rw-r--r--src/test/Makefile.am25
-rw-r--r--src/test/accounting_tests.cpp14
-rw-r--r--src/test/alert_tests.cpp24
-rw-r--r--src/test/allocator_tests.cpp6
-rw-r--r--src/test/base32_tests.cpp4
-rw-r--r--src/test/base58_tests.cpp17
-rw-r--r--src/test/base64_tests.cpp6
-rw-r--r--src/test/bignum_tests.cpp23
-rw-r--r--src/test/bip32_tests.cpp8
-rw-r--r--src/test/bloom_tests.cpp14
-rw-r--r--src/test/canonical_tests.cpp11
-rw-r--r--src/test/checkblock_tests.cpp16
-rw-r--r--src/test/compress_tests.cpp26
-rw-r--r--src/test/data/alertTests.rawbin1283 -> 1279 bytes
-rw-r--r--src/test/data/script_valid.json10
-rw-r--r--src/test/data/tx_valid.json6
-rw-r--r--src/test/getarg_tests.cpp9
-rw-r--r--src/test/hash_tests.cpp9
-rw-r--r--src/test/hmac_tests.cpp4
-rw-r--r--src/test/key_tests.cpp12
-rw-r--r--src/test/miner_tests.cpp30
-rw-r--r--src/test/mruset_tests.cpp11
-rw-r--r--src/test/multisig_tests.cpp16
-rw-r--r--src/test/netbase_tests.cpp5
-rw-r--r--src/test/pmt_tests.cpp9
-rw-r--r--src/test/rpc_tests.cpp81
-rw-r--r--src/test/rpc_wallet_tests.cpp82
-rw-r--r--src/test/script_P2SH_tests.cpp18
-rw-r--r--src/test/script_tests.cpp25
-rw-r--r--src/test/serialize_tests.cpp13
-rw-r--r--src/test/sigopcount_tests.cpp12
-rw-r--r--src/test/test_bitcoin.cpp24
-rw-r--r--src/test/transaction_tests.cpp16
-rw-r--r--src/test/uint160_tests.cpp8
-rw-r--r--src/test/uint256_tests.cpp17
-rw-r--r--src/test/util_tests.cpp40
-rw-r--r--src/test/wallet_tests.cpp15
39 files changed, 433 insertions, 269 deletions
diff --git a/src/test/Checkpoints_tests.cpp b/src/test/Checkpoints_tests.cpp
index b14e9f7057..78b0236b74 100644
--- a/src/test/Checkpoints_tests.cpp
+++ b/src/test/Checkpoints_tests.cpp
@@ -1,12 +1,12 @@
//
// Unit tests for block-chain checkpoints
//
-#include <boost/assign/list_of.hpp> // for 'map_list_of()'
-#include <boost/test/unit_test.hpp>
-#include <boost/foreach.hpp>
-#include "../checkpoints.h"
-#include "../util.h"
+#include "checkpoints.h"
+
+#include "uint256.h"
+
+#include <boost/test/unit_test.hpp>
using namespace std;
diff --git a/src/test/DoS_tests.cpp b/src/test/DoS_tests.cpp
index c7f968da7c..f0fb84bc54 100644
--- a/src/test/DoS_tests.cpp
+++ b/src/test/DoS_tests.cpp
@@ -1,21 +1,23 @@
//
// Unit tests for denial-of-service detection/prevention code
//
-#include <algorithm>
-#include <boost/assign/list_of.hpp> // for 'map_list_of()'
-#include <boost/date_time/posix_time/posix_time_types.hpp>
-#include <boost/test/unit_test.hpp>
-#include <boost/foreach.hpp>
-#include "chainparams.h"
+
+#include "bignum.h"
+#include "keystore.h"
#include "main.h"
-#include "wallet.h"
#include "net.h"
-#include "util.h"
+#include "script.h"
+#include "serialize.h"
#include <stdint.h>
+#include <boost/assign/list_of.hpp> // for 'map_list_of()'
+#include <boost/date_time/posix_time/posix_time_types.hpp>
+#include <boost/foreach.hpp>
+#include <boost/test/unit_test.hpp>
+
// Tests this internal-to-main.cpp method:
extern bool AddOrphanTx(const CTransaction& tx);
extern unsigned int LimitOrphanTxSize(unsigned int nMaxOrphans);
@@ -67,7 +69,7 @@ BOOST_AUTO_TEST_CASE(DoS_banscore)
BOOST_AUTO_TEST_CASE(DoS_bantime)
{
CNode::ClearBanned();
- int64 nStartTime = GetTime();
+ int64_t nStartTime = GetTime();
SetMockTime(nStartTime); // Overrides future calls to GetTime()
CAddress addr(ip(0xa0b0c001));
@@ -83,11 +85,11 @@ BOOST_AUTO_TEST_CASE(DoS_bantime)
BOOST_CHECK(!CNode::IsBanned(addr));
}
-static bool CheckNBits(unsigned int nbits1, int64 time1, unsigned int nbits2, int64 time2)\
+static bool CheckNBits(unsigned int nbits1, int64_t time1, unsigned int nbits2, int64_t time2)\
{
if (time1 > time2)
return CheckNBits(nbits2, time2, nbits1, time1);
- int64 deltaTime = time2-time1;
+ int64_t deltaTime = time2-time1;
CBigNum required;
required.SetCompact(ComputeMinWork(nbits1, deltaTime));
@@ -102,7 +104,7 @@ BOOST_AUTO_TEST_CASE(DoS_checknbits)
// Timestamps,nBits from the bitcoin block chain.
// These are the block-chain checkpoint blocks
- typedef std::map<int64, unsigned int> BlockData;
+ typedef std::map<int64_t, unsigned int> BlockData;
BlockData chainData =
map_list_of(1239852051,486604799)(1262749024,486594666)
(1279305360,469854461)(1280200847,469830746)(1281678674,469809688)
diff --git a/src/test/Makefile.am b/src/test/Makefile.am
index c3495095d9..dccd264e5a 100644
--- a/src/test/Makefile.am
+++ b/src/test/Makefile.am
@@ -1,10 +1,6 @@
include $(top_srcdir)/src/Makefile.include
-AM_CPPFLAGS = $(INCLUDES) -I$(top_builddir)/src/obj \
- -I$(top_srcdir)/src/leveldb/include -I$(top_srcdir)/src/leveldb/helpers \
- -I$(top_srcdir)/src $(BOOST_INCLUDES) $(BDB_CPPFLAGS)
-
-AM_LDFLAGS = $(PTHREAD_CFLAGS)
+AM_CPPFLAGS += -I$(top_srcdir)/src
bin_PROGRAMS = test_bitcoin
@@ -24,17 +20,26 @@ BUILT_SOURCES = $(JSON_TEST_FILES:.json=.json.h) $(RAW_TEST_FILES:.raw=.raw.h)
# test_bitcoin binary #
test_bitcoin_CPPFLAGS = $(AM_CPPFLAGS) $(TESTDEFS)
-test_bitcoin_LDADD = $(LIBBITCOIN) $(LIBLEVELDB) $(LIBMEMENV) \
- $(BOOST_LIBS) $(BOOST_UNIT_TEST_FRAMEWORK_LIB) $(BDB_LIBS)
-test_bitcoin_SOURCES = accounting_tests.cpp alert_tests.cpp \
+test_bitcoin_LDADD = $(LIBBITCOIN_SERVER) $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBLEVELDB) $(LIBMEMENV) \
+ $(BOOST_LIBS) $(BOOST_UNIT_TEST_FRAMEWORK_LIB)
+if ENABLE_WALLET
+test_bitcoin_LDADD += $(LIBBITCOIN_WALLET)
+endif
+test_bitcoin_LDADD += $(BDB_LIBS)
+
+test_bitcoin_SOURCES = alert_tests.cpp \
allocator_tests.cpp base32_tests.cpp base58_tests.cpp base64_tests.cpp \
bignum_tests.cpp bloom_tests.cpp canonical_tests.cpp checkblock_tests.cpp \
Checkpoints_tests.cpp compress_tests.cpp DoS_tests.cpp getarg_tests.cpp \
- key_tests.cpp miner_tests.cpp mruset_tests.cpp multisig_tests.cpp \
+ key_tests.cpp mruset_tests.cpp multisig_tests.cpp \
netbase_tests.cpp pmt_tests.cpp rpc_tests.cpp script_P2SH_tests.cpp \
script_tests.cpp serialize_tests.cpp sigopcount_tests.cpp test_bitcoin.cpp \
transaction_tests.cpp uint160_tests.cpp uint256_tests.cpp util_tests.cpp \
- wallet_tests.cpp sighash_tests.cpp $(JSON_TEST_FILES) $(RAW_TEST_FILES)
+ sighash_tests.cpp $(JSON_TEST_FILES) $(RAW_TEST_FILES)
+
+if ENABLE_WALLET
+test_bitcoin_SOURCES += accounting_tests.cpp wallet_tests.cpp miner_tests.cpp rpc_wallet_tests.cpp
+endif
nodist_test_bitcoin_SOURCES = $(BUILT_SOURCES)
diff --git a/src/test/accounting_tests.cpp b/src/test/accounting_tests.cpp
index 8ac657288b..5f79436e48 100644
--- a/src/test/accounting_tests.cpp
+++ b/src/test/accounting_tests.cpp
@@ -1,15 +1,19 @@
-#include <boost/test/unit_test.hpp>
-#include <boost/foreach.hpp>
-#include "init.h"
#include "wallet.h"
#include "walletdb.h"
+#include <stdint.h>
+
+#include <boost/foreach.hpp>
+#include <boost/test/unit_test.hpp>
+
+extern CWallet* pwalletMain;
+
BOOST_AUTO_TEST_SUITE(accounting_tests)
static void
-GetResults(CWalletDB& walletdb, std::map<int64, CAccountingEntry>& results)
+GetResults(CWalletDB& walletdb, std::map<int64_t, CAccountingEntry>& results)
{
std::list<CAccountingEntry> aes;
@@ -28,7 +32,7 @@ BOOST_AUTO_TEST_CASE(acc_orderupgrade)
std::vector<CWalletTx*> vpwtx;
CWalletTx wtx;
CAccountingEntry ae;
- std::map<int64, CAccountingEntry> results;
+ std::map<int64_t, CAccountingEntry> results;
ae.strAccount = "";
ae.nCreditDebit = 1;
diff --git a/src/test/alert_tests.cpp b/src/test/alert_tests.cpp
index cb941943f7..a7e668222d 100644
--- a/src/test/alert_tests.cpp
+++ b/src/test/alert_tests.cpp
@@ -2,14 +2,18 @@
// Unit tests for alert system
//
-#include <boost/foreach.hpp>
-#include <boost/test/unit_test.hpp>
-#include <fstream>
-
#include "alert.h"
+#include "data/alertTests.raw.h"
+
#include "serialize.h"
#include "util.h"
-#include "data/alertTests.raw.h"
+#include "version.h"
+
+#include <fstream>
+
+#include <boost/filesystem/operations.hpp>
+#include <boost/foreach.hpp>
+#include <boost/test/unit_test.hpp>
#if 0
//
@@ -23,7 +27,7 @@
alert.nID = 1;
alert.nCancel = 0; // cancels previous messages up to this ID number
alert.nMinVer = 0; // These versions are protocol versions
- alert.nMaxVer = 70001;
+ alert.nMaxVer = 999001;
alert.nPriority = 1;
alert.strComment = "Alert comment";
alert.strStatusBar = "Alert 1";
@@ -117,25 +121,25 @@ BOOST_AUTO_TEST_CASE(AlertApplies)
// Matches:
BOOST_CHECK(alerts[0].AppliesTo(1, ""));
- BOOST_CHECK(alerts[0].AppliesTo(70001, ""));
+ BOOST_CHECK(alerts[0].AppliesTo(999001, ""));
BOOST_CHECK(alerts[0].AppliesTo(1, "/Satoshi:11.11.11/"));
BOOST_CHECK(alerts[1].AppliesTo(1, "/Satoshi:0.1.0/"));
- BOOST_CHECK(alerts[1].AppliesTo(70001, "/Satoshi:0.1.0/"));
+ BOOST_CHECK(alerts[1].AppliesTo(999001, "/Satoshi:0.1.0/"));
BOOST_CHECK(alerts[2].AppliesTo(1, "/Satoshi:0.1.0/"));
BOOST_CHECK(alerts[2].AppliesTo(1, "/Satoshi:0.2.0/"));
// Don't match:
BOOST_CHECK(!alerts[0].AppliesTo(-1, ""));
- BOOST_CHECK(!alerts[0].AppliesTo(70002, ""));
+ BOOST_CHECK(!alerts[0].AppliesTo(999002, ""));
BOOST_CHECK(!alerts[1].AppliesTo(1, ""));
BOOST_CHECK(!alerts[1].AppliesTo(1, "Satoshi:0.1.0"));
BOOST_CHECK(!alerts[1].AppliesTo(1, "/Satoshi:0.1.0"));
BOOST_CHECK(!alerts[1].AppliesTo(1, "Satoshi:0.1.0/"));
BOOST_CHECK(!alerts[1].AppliesTo(-1, "/Satoshi:0.1.0/"));
- BOOST_CHECK(!alerts[1].AppliesTo(70002, "/Satoshi:0.1.0/"));
+ BOOST_CHECK(!alerts[1].AppliesTo(999002, "/Satoshi:0.1.0/"));
BOOST_CHECK(!alerts[1].AppliesTo(1, "/Satoshi:0.2.0/"));
BOOST_CHECK(!alerts[2].AppliesTo(1, "/Satoshi:0.3.0/"));
diff --git a/src/test/allocator_tests.cpp b/src/test/allocator_tests.cpp
index d5cb8e8101..490dff87e5 100644
--- a/src/test/allocator_tests.cpp
+++ b/src/test/allocator_tests.cpp
@@ -1,9 +1,9 @@
-#include <boost/test/unit_test.hpp>
-#include "init.h"
-#include "main.h"
+
#include "util.h"
+#include <boost/test/unit_test.hpp>
+
BOOST_AUTO_TEST_SUITE(allocator_tests)
// Dummy memory page locker for platform independent tests
diff --git a/src/test/base32_tests.cpp b/src/test/base32_tests.cpp
index fdf3285913..580e87f65f 100644
--- a/src/test/base32_tests.cpp
+++ b/src/test/base32_tests.cpp
@@ -1,7 +1,9 @@
-#include <boost/test/unit_test.hpp>
+
#include "util.h"
+#include <boost/test/unit_test.hpp>
+
BOOST_AUTO_TEST_SUITE(base32_tests)
BOOST_AUTO_TEST_CASE(base32_testvectors)
diff --git a/src/test/base58_tests.cpp b/src/test/base58_tests.cpp
index 05675685bd..84db99d816 100644
--- a/src/test/base58_tests.cpp
+++ b/src/test/base58_tests.cpp
@@ -1,13 +1,20 @@
-#include <boost/test/unit_test.hpp>
-#include "json/json_spirit_reader_template.h"
-#include "json/json_spirit_writer_template.h"
-#include "json/json_spirit_utils.h"
+#include "base58.h"
+
#include "data/base58_encode_decode.json.h"
#include "data/base58_keys_invalid.json.h"
#include "data/base58_keys_valid.json.h"
-#include "base58.h"
+#include "key.h"
+#include "script.h"
+#include "uint256.h"
#include "util.h"
+
+#include <boost/foreach.hpp>
+#include <boost/test/unit_test.hpp>
+#include "json/json_spirit_reader_template.h"
+#include "json/json_spirit_utils.h"
+#include "json/json_spirit_writer_template.h"
+
using namespace json_spirit;
extern Array read_json(const std::string& jsondata);
diff --git a/src/test/base64_tests.cpp b/src/test/base64_tests.cpp
index c5a053e2eb..c59c290669 100644
--- a/src/test/base64_tests.cpp
+++ b/src/test/base64_tests.cpp
@@ -1,9 +1,9 @@
-#include <boost/test/unit_test.hpp>
-#include "main.h"
-#include "wallet.h"
+
#include "util.h"
+#include <boost/test/unit_test.hpp>
+
BOOST_AUTO_TEST_SUITE(base64_tests)
BOOST_AUTO_TEST_CASE(base64_testvectors)
diff --git a/src/test/bignum_tests.cpp b/src/test/bignum_tests.cpp
index 196b7274f4..9d67324c76 100644
--- a/src/test/bignum_tests.cpp
+++ b/src/test/bignum_tests.cpp
@@ -1,8 +1,9 @@
-#include <boost/test/unit_test.hpp>
+#include "bignum.h"
+
#include <limits>
+#include <stdint.h>
-#include "bignum.h"
-#include "util.h"
+#include <boost/test/unit_test.hpp>
BOOST_AUTO_TEST_SUITE(bignum_tests)
@@ -46,7 +47,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 +56,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 +104,7 @@ BOOST_AUTO_TEST_CASE(bignum_setint64)
BOOST_CHECK(num.ToString() == "-5");
}
{
- n = std::numeric_limits<int64>::min();
+ n = std::numeric_limits<int64_t>::min();
CBigNum num(n);
BOOST_CHECK(num.ToString() == "-9223372036854775808");
num.setulong(0);
@@ -112,7 +113,7 @@ BOOST_AUTO_TEST_CASE(bignum_setint64)
BOOST_CHECK(num.ToString() == "-9223372036854775808");
}
{
- n = std::numeric_limits<int64>::max();
+ n = std::numeric_limits<int64_t>::max();
CBigNum num(n);
BOOST_CHECK(num.ToString() == "9223372036854775807");
num.setulong(0);
@@ -175,4 +176,12 @@ BOOST_AUTO_TEST_CASE(bignum_SetCompact)
BOOST_CHECK_EQUAL(num.GetCompact(), 0xff123456U);
}
+BOOST_AUTO_TEST_CASE(bignum_SetHex)
+{
+ std::string hexStr = "deecf97fd890808b9cc0f1b6a3e7a60b400f52710e6ad075b1340755bfa58cc9";
+ CBigNum num;
+ num.SetHex(hexStr);
+ BOOST_CHECK_EQUAL(num.GetHex(), hexStr);
+}
+
BOOST_AUTO_TEST_SUITE_END()
diff --git a/src/test/bip32_tests.cpp b/src/test/bip32_tests.cpp
index 66d2330fbf..2bcca24336 100644
--- a/src/test/bip32_tests.cpp
+++ b/src/test/bip32_tests.cpp
@@ -1,13 +1,13 @@
#include <boost/test/unit_test.hpp>
-#include <string>
-#include <vector>
-
-#include "key.h"
#include "base58.h"
+#include "key.h"
#include "uint256.h"
#include "util.h"
+#include <string>
+#include <vector>
+
struct TestDerivation {
std::string pub;
std::string prv;
diff --git a/src/test/bloom_tests.cpp b/src/test/bloom_tests.cpp
index 0d349a990c..c4e4403b70 100644
--- a/src/test/bloom_tests.cpp
+++ b/src/test/bloom_tests.cpp
@@ -1,11 +1,15 @@
-#include <boost/test/unit_test.hpp>
-#include <vector>
-
#include "bloom.h"
-#include "util.h"
-#include "key.h"
+
#include "base58.h"
+#include "key.h"
#include "main.h"
+#include "serialize.h"
+#include "uint256.h"
+#include "util.h"
+
+#include <vector>
+
+#include <boost/test/unit_test.hpp>
using namespace std;
using namespace boost::tuples;
diff --git a/src/test/canonical_tests.cpp b/src/test/canonical_tests.cpp
index ec32ceb8a4..c521f2cf9c 100644
--- a/src/test/canonical_tests.cpp
+++ b/src/test/canonical_tests.cpp
@@ -1,16 +1,19 @@
//
// Unit tests for canonical signatures
+//
+
-#include "json/json_spirit_writer_template.h"
-#include <boost/test/unit_test.hpp>
-#include <openssl/ecdsa.h>
-#include "key.h"
#include "script.h"
#include "util.h"
#include "data/sig_noncanonical.json.h"
#include "data/sig_canonical.json.h"
+#include <boost/foreach.hpp>
+#include <boost/test/unit_test.hpp>
+#include "json/json_spirit_writer_template.h"
+#include <openssl/ecdsa.h>
+
using namespace std;
using namespace json_spirit;
diff --git a/src/test/checkblock_tests.cpp b/src/test/checkblock_tests.cpp
index e34680db99..d47a33fd46 100644
--- a/src/test/checkblock_tests.cpp
+++ b/src/test/checkblock_tests.cpp
@@ -1,17 +1,17 @@
//
// Unit tests for block.CheckBlock()
//
-#include <algorithm>
-#include <boost/assign/list_of.hpp> // for 'map_list_of()'
-#include <boost/date_time/posix_time/posix_time_types.hpp>
-#include <boost/test/unit_test.hpp>
-#include <boost/foreach.hpp>
+
#include "main.h"
-#include "wallet.h"
-#include "net.h"
-#include "util.h"
+
+#include <cstdio>
+
+#include <boost/filesystem/operations.hpp>
+#include <boost/filesystem/path.hpp>
+#include <boost/test/unit_test.hpp>
+
BOOST_AUTO_TEST_SUITE(CheckBlock_tests)
diff --git a/src/test/compress_tests.cpp b/src/test/compress_tests.cpp
index 71b86bcb41..4d16914774 100644
--- a/src/test/compress_tests.cpp
+++ b/src/test/compress_tests.cpp
@@ -1,9 +1,11 @@
-#include <boost/test/unit_test.hpp>
-#include <string>
-#include <vector>
#include "main.h"
+#include "util.h"
+
+#include <stdint.h>
+
+#include <boost/test/unit_test.hpp>
// amounts 0.00000001 .. 0.00100000
#define NUM_MULTIPLES_UNIT 100000
@@ -17,19 +19,17 @@
// amounts 50 .. 21000000
#define NUM_MULTIPLES_50BTC 420000
-using namespace std;
-
BOOST_AUTO_TEST_SUITE(compress_tests)
-bool static TestEncode(uint64 in) {
+bool static TestEncode(uint64_t in) {
return in == CTxOutCompressor::DecompressAmount(CTxOutCompressor::CompressAmount(in));
}
-bool static TestDecode(uint64 in) {
+bool static TestDecode(uint64_t in) {
return in == CTxOutCompressor::CompressAmount(CTxOutCompressor::DecompressAmount(in));
}
-bool static TestPair(uint64 dec, uint64 enc) {
+bool static TestPair(uint64_t dec, uint64_t enc) {
return CTxOutCompressor::CompressAmount(dec) == enc &&
CTxOutCompressor::DecompressAmount(enc) == dec;
}
@@ -43,19 +43,19 @@ BOOST_AUTO_TEST_CASE(compress_amounts)
BOOST_CHECK(TestPair( 50*COIN, 0x32));
BOOST_CHECK(TestPair(21000000*COIN, 0x1406f40));
- for (uint64 i = 1; i <= NUM_MULTIPLES_UNIT; i++)
+ for (uint64_t i = 1; i <= NUM_MULTIPLES_UNIT; i++)
BOOST_CHECK(TestEncode(i));
- for (uint64 i = 1; i <= NUM_MULTIPLES_CENT; i++)
+ for (uint64_t i = 1; i <= NUM_MULTIPLES_CENT; i++)
BOOST_CHECK(TestEncode(i * CENT));
- for (uint64 i = 1; i <= NUM_MULTIPLES_1BTC; i++)
+ for (uint64_t i = 1; i <= NUM_MULTIPLES_1BTC; i++)
BOOST_CHECK(TestEncode(i * COIN));
- for (uint64 i = 1; i <= NUM_MULTIPLES_50BTC; i++)
+ for (uint64_t i = 1; i <= NUM_MULTIPLES_50BTC; i++)
BOOST_CHECK(TestEncode(i * 50 * COIN));
- for (uint64 i = 0; i < 100000; i++)
+ for (uint64_t i = 0; i < 100000; i++)
BOOST_CHECK(TestDecode(i));
}
diff --git a/src/test/data/alertTests.raw b/src/test/data/alertTests.raw
index 7fc4528961..01f50680b9 100644
--- a/src/test/data/alertTests.raw
+++ b/src/test/data/alertTests.raw
Binary files differ
diff --git a/src/test/data/script_valid.json b/src/test/data/script_valid.json
index 13b0af6c45..e4c181cae8 100644
--- a/src/test/data/script_valid.json
+++ b/src/test/data/script_valid.json
@@ -403,5 +403,13 @@
["NOP", "NOP10 1"],
["0 0x01 1", "HASH160 0x14 0xda1745e9b549bd0bfa1a569971c77eba30cd5a4b EQUAL", "Very basic P2SH"],
-["0x4c 0 0x01 1", "HASH160 0x14 0xda1745e9b549bd0bfa1a569971c77eba30cd5a4b EQUAL"]
+["0x4c 0 0x01 1", "HASH160 0x14 0xda1745e9b549bd0bfa1a569971c77eba30cd5a4b EQUAL"],
+
+["0x40 0x42424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242",
+"0x4d 0x4000 0x42424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242 EQUAL",
+"Basic PUSH signedness check"],
+
+["0x4c 0x40 0x42424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242",
+"0x4d 0x4000 0x42424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242 EQUAL",
+"Basic PUSHDATA1 signedness check"]
]
diff --git a/src/test/data/tx_valid.json b/src/test/data/tx_valid.json
index faf911a97f..63e7074a32 100644
--- a/src/test/data/tx_valid.json
+++ b/src/test/data/tx_valid.json
@@ -83,5 +83,9 @@
[[["63cfa5a09dc540bf63e53713b82d9ea3692ca97cd608c384f2aa88e51a0aac70", 0, "DUP HASH160 0x14 0xdcf72c4fd02f5a987cf9b02f2fabfcac3341a87d EQUALVERIFY CHECKSIG"],
["04e8d0fcf3846c6734477b98f0f3d4badfb78f020ee097a0be5fe347645b817d", 1, "DUP HASH160 0x14 0xdcf72c4fd02f5a987cf9b02f2fabfcac3341a87d EQUALVERIFY CHECKSIG"],
["ee1377aff5d0579909e11782e1d2f5f7b84d26537be7f5516dd4e43373091f3f", 1, "DUP HASH160 0x14 0xdcf72c4fd02f5a987cf9b02f2fabfcac3341a87d EQUALVERIFY CHECKSIG"]],
- "010000000370ac0a1ae588aaf284c308d67ca92c69a39e2db81337e563bf40c59da0a5cf63000000006a4730440220360d20baff382059040ba9be98947fd678fb08aab2bb0c172efa996fd8ece9b702201b4fb0de67f015c90e7ac8a193aeab486a1f587e0f54d0fb9552ef7f5ce6caec032103579ca2e6d107522f012cd00b52b9a65fb46f0c57b9b8b6e377c48f526a44741affffffff7d815b6447e35fbea097e00e028fb7dfbad4f3f0987b4734676c84f3fcd0e804010000006b483045022100c714310be1e3a9ff1c5f7cacc65c2d8e781fc3a88ceb063c6153bf950650802102200b2d0979c76e12bb480da635f192cc8dc6f905380dd4ac1ff35a4f68f462fffd032103579ca2e6d107522f012cd00b52b9a65fb46f0c57b9b8b6e377c48f526a44741affffffff3f1f097333e4d46d51f5e77b53264db8f7f5d2e18217e1099957d0f5af7713ee010000006c493046022100b663499ef73273a3788dea342717c2640ac43c5a1cf862c9e09b206fcb3f6bb8022100b09972e75972d9148f2bdd462e5cb69b57c1214b88fc55ca638676c07cfc10d8032103579ca2e6d107522f012cd00b52b9a65fb46f0c57b9b8b6e377c48f526a44741affffffff0380841e00000000001976a914bfb282c70c4191f45b5a6665cad1682f2c9cfdfb88ac80841e00000000001976a9149857cc07bed33a5cf12b9c5e0500b675d500c81188ace0fd1c00000000001976a91443c52850606c872403c0601e69fa34b26f62db4a88ac00000000", true]
+ "010000000370ac0a1ae588aaf284c308d67ca92c69a39e2db81337e563bf40c59da0a5cf63000000006a4730440220360d20baff382059040ba9be98947fd678fb08aab2bb0c172efa996fd8ece9b702201b4fb0de67f015c90e7ac8a193aeab486a1f587e0f54d0fb9552ef7f5ce6caec032103579ca2e6d107522f012cd00b52b9a65fb46f0c57b9b8b6e377c48f526a44741affffffff7d815b6447e35fbea097e00e028fb7dfbad4f3f0987b4734676c84f3fcd0e804010000006b483045022100c714310be1e3a9ff1c5f7cacc65c2d8e781fc3a88ceb063c6153bf950650802102200b2d0979c76e12bb480da635f192cc8dc6f905380dd4ac1ff35a4f68f462fffd032103579ca2e6d107522f012cd00b52b9a65fb46f0c57b9b8b6e377c48f526a44741affffffff3f1f097333e4d46d51f5e77b53264db8f7f5d2e18217e1099957d0f5af7713ee010000006c493046022100b663499ef73273a3788dea342717c2640ac43c5a1cf862c9e09b206fcb3f6bb8022100b09972e75972d9148f2bdd462e5cb69b57c1214b88fc55ca638676c07cfc10d8032103579ca2e6d107522f012cd00b52b9a65fb46f0c57b9b8b6e377c48f526a44741affffffff0380841e00000000001976a914bfb282c70c4191f45b5a6665cad1682f2c9cfdfb88ac80841e00000000001976a9149857cc07bed33a5cf12b9c5e0500b675d500c81188ace0fd1c00000000001976a91443c52850606c872403c0601e69fa34b26f62db4a88ac00000000", true],
+
+ ["ddc454a1c0c35c188c98976b17670f69e586d9c0f3593ea879928332f0a069e7, which spends an input that pushes using a PUSHDATA1 that is negative when read as signed"],
+ [[["c5510a5dd97a25f43175af1fe649b707b1df8e1a41489bac33a23087027a2f48", 0, "0x4c 0xae 0x606563686f2022553246736447566b58312b5a536e587574356542793066794778625456415675534a6c376a6a334878416945325364667657734f53474f36633338584d7439435c6e543249584967306a486956304f376e775236644546673d3d22203e20743b206f70656e73736c20656e63202d7061737320706173733a5b314a564d7751432d707269766b65792d6865785d202d64202d6165732d3235362d636263202d61202d696e207460 DROP DUP HASH160 0x14 0xbfd7436b6265aa9de506f8a994f881ff08cc2872 EQUALVERIFY CHECKSIG"]],
+ "0100000001482f7a028730a233ac9b48411a8edfb107b749e61faf7531f4257ad95d0a51c5000000008b483045022100bf0bbae9bde51ad2b222e87fbf67530fbafc25c903519a1e5dcc52a32ff5844e022028c4d9ad49b006dd59974372a54291d5764be541574bb0c4dc208ec51f80b7190141049dd4aad62741dc27d5f267f7b70682eee22e7e9c1923b9c0957bdae0b96374569b460eb8d5b40d972e8c7c0ad441de3d94c4a29864b212d56050acb980b72b2bffffffff0180969800000000001976a914e336d0017a9d28de99d16472f6ca6d5a3a8ebc9988ac00000000", true]
]
diff --git a/src/test/getarg_tests.cpp b/src/test/getarg_tests.cpp
index c89d218f80..d76124885b 100644
--- a/src/test/getarg_tests.cpp
+++ b/src/test/getarg_tests.cpp
@@ -1,9 +1,14 @@
+
+
+#include "util.h"
+
+#include <string>
+#include <vector>
+
#include <boost/algorithm/string.hpp>
#include <boost/foreach.hpp>
#include <boost/test/unit_test.hpp>
-#include "util.h"
-
BOOST_AUTO_TEST_SUITE(getarg_tests)
static void ResetArgs(const std::string& strArg)
diff --git a/src/test/hash_tests.cpp b/src/test/hash_tests.cpp
index d69cfd706d..28410f0fed 100644
--- a/src/test/hash_tests.cpp
+++ b/src/test/hash_tests.cpp
@@ -1,8 +1,11 @@
-#include <boost/test/unit_test.hpp>
-#include <vector>
-#include "util.h"
+
#include "hash.h"
+#include "util.h"
+
+#include <vector>
+
+#include <boost/test/unit_test.hpp>
using namespace std;
diff --git a/src/test/hmac_tests.cpp b/src/test/hmac_tests.cpp
index 92ca5e6aff..68868866aa 100644
--- a/src/test/hmac_tests.cpp
+++ b/src/test/hmac_tests.cpp
@@ -1,8 +1,10 @@
-#include <boost/test/unit_test.hpp>
+
#include "hash.h"
#include "util.h"
+#include <boost/test/unit_test.hpp>
+
using namespace std;
BOOST_AUTO_TEST_SUITE(hmac_tests)
diff --git a/src/test/key_tests.cpp b/src/test/key_tests.cpp
index c004521d1a..421ffeac45 100644
--- a/src/test/key_tests.cpp
+++ b/src/test/key_tests.cpp
@@ -1,13 +1,15 @@
-#include <boost/test/unit_test.hpp>
-
-#include <string>
-#include <vector>
-
#include "key.h"
+
#include "base58.h"
+#include "script.h"
#include "uint256.h"
#include "util.h"
+#include <string>
+#include <vector>
+
+#include <boost/test/unit_test.hpp>
+
using namespace std;
static const string strSecret1 ("5HxWvvfubhXpYYpS3tJkw6fq9jE9j18THftkZjHHfmFiWtmAbrj");
diff --git a/src/test/miner_tests.cpp b/src/test/miner_tests.cpp
index 67165760b2..46c9ae021d 100644
--- a/src/test/miner_tests.cpp
+++ b/src/test/miner_tests.cpp
@@ -1,12 +1,14 @@
-#include <boost/test/unit_test.hpp>
-#include "init.h"
+
#include "main.h"
+#include "miner.h"
#include "uint256.h"
#include "util.h"
-#include "miner.h"
#include "wallet.h"
+#include <boost/test/unit_test.hpp>
+
+extern CWallet* pwalletMain;
extern void SHA256Transform(void* pstate, void* pinput, const void* pinit);
BOOST_AUTO_TEST_SUITE(miner_tests)
@@ -55,6 +57,8 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
CScript script;
uint256 hash;
+ LOCK(cs_main);
+
// Simple block creation, nothing special yet:
BOOST_CHECK(pblocktemplate = CreateNewBlockWithKey(reservekey));
@@ -97,7 +101,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
{
tx.vout[0].nValue -= 1000000;
hash = tx.GetHash();
- mempool.addUnchecked(hash, tx);
+ mempool.addUnchecked(hash, CTxMemPoolEntry(tx, 11, GetTime(), 111.0, 11));
tx.vin[0].prevout.hash = hash;
}
BOOST_CHECK(pblocktemplate = CreateNewBlockWithKey(reservekey));
@@ -117,7 +121,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
{
tx.vout[0].nValue -= 10000000;
hash = tx.GetHash();
- mempool.addUnchecked(hash, tx);
+ mempool.addUnchecked(hash, CTxMemPoolEntry(tx, 11, GetTime(), 111.0, 11));
tx.vin[0].prevout.hash = hash;
}
BOOST_CHECK(pblocktemplate = CreateNewBlockWithKey(reservekey));
@@ -126,7 +130,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
// orphan in mempool
hash = tx.GetHash();
- mempool.addUnchecked(hash, tx);
+ mempool.addUnchecked(hash, CTxMemPoolEntry(tx, 11, GetTime(), 111.0, 11));
BOOST_CHECK(pblocktemplate = CreateNewBlockWithKey(reservekey));
delete pblocktemplate;
mempool.clear();
@@ -136,7 +140,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
tx.vin[0].prevout.hash = txFirst[1]->GetHash();
tx.vout[0].nValue = 4900000000LL;
hash = tx.GetHash();
- mempool.addUnchecked(hash, tx);
+ mempool.addUnchecked(hash, CTxMemPoolEntry(tx, 11, GetTime(), 111.0, 11));
tx.vin[0].prevout.hash = hash;
tx.vin.resize(2);
tx.vin[1].scriptSig = CScript() << OP_1;
@@ -144,7 +148,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
tx.vin[1].prevout.n = 0;
tx.vout[0].nValue = 5900000000LL;
hash = tx.GetHash();
- mempool.addUnchecked(hash, tx);
+ mempool.addUnchecked(hash, CTxMemPoolEntry(tx, 11, GetTime(), 111.0, 11));
BOOST_CHECK(pblocktemplate = CreateNewBlockWithKey(reservekey));
delete pblocktemplate;
mempool.clear();
@@ -155,7 +159,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
tx.vin[0].scriptSig = CScript() << OP_0 << OP_1;
tx.vout[0].nValue = 0;
hash = tx.GetHash();
- mempool.addUnchecked(hash, tx);
+ mempool.addUnchecked(hash, CTxMemPoolEntry(tx, 11, GetTime(), 111.0, 11));
BOOST_CHECK(pblocktemplate = CreateNewBlockWithKey(reservekey));
delete pblocktemplate;
mempool.clear();
@@ -168,12 +172,12 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
script = CScript() << OP_0;
tx.vout[0].scriptPubKey.SetDestination(script.GetID());
hash = tx.GetHash();
- mempool.addUnchecked(hash, tx);
+ mempool.addUnchecked(hash, CTxMemPoolEntry(tx, 11, GetTime(), 111.0, 11));
tx.vin[0].prevout.hash = hash;
tx.vin[0].scriptSig = CScript() << (std::vector<unsigned char>)script;
tx.vout[0].nValue -= 1000000;
hash = tx.GetHash();
- mempool.addUnchecked(hash,tx);
+ mempool.addUnchecked(hash, CTxMemPoolEntry(tx, 11, GetTime(), 111.0, 11));
BOOST_CHECK(pblocktemplate = CreateNewBlockWithKey(reservekey));
delete pblocktemplate;
mempool.clear();
@@ -184,10 +188,10 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
tx.vout[0].nValue = 4900000000LL;
tx.vout[0].scriptPubKey = CScript() << OP_1;
hash = tx.GetHash();
- mempool.addUnchecked(hash, tx);
+ mempool.addUnchecked(hash, CTxMemPoolEntry(tx, 11, GetTime(), 111.0, 11));
tx.vout[0].scriptPubKey = CScript() << OP_2;
hash = tx.GetHash();
- mempool.addUnchecked(hash, tx);
+ mempool.addUnchecked(hash, CTxMemPoolEntry(tx, 11, GetTime(), 111.0, 11));
BOOST_CHECK(pblocktemplate = CreateNewBlockWithKey(reservekey));
delete pblocktemplate;
mempool.clear();
diff --git a/src/test/mruset_tests.cpp b/src/test/mruset_tests.cpp
index 64a6678a73..638c88fabe 100644
--- a/src/test/mruset_tests.cpp
+++ b/src/test/mruset_tests.cpp
@@ -1,13 +1,16 @@
-#include <boost/test/unit_test.hpp>
-
-using namespace std;
-
#include "mruset.h"
+
#include "util.h"
+#include <set>
+
+#include <boost/test/unit_test.hpp>
+
#define NUM_TESTS 16
#define MAX_SIZE 100
+using namespace std;
+
class mrutester
{
private:
diff --git a/src/test/multisig_tests.cpp b/src/test/multisig_tests.cpp
index 05309f1a4d..772217b888 100644
--- a/src/test/multisig_tests.cpp
+++ b/src/test/multisig_tests.cpp
@@ -1,18 +1,14 @@
-#include <boost/assert.hpp>
-#include <boost/assign/list_of.hpp>
-#include <boost/assign/list_inserter.hpp>
-#include <boost/assign/std/vector.hpp>
-#include <boost/test/unit_test.hpp>
-#include <boost/foreach.hpp>
-#include <boost/tuple/tuple.hpp>
-#include <openssl/ec.h>
-#include <openssl/err.h>
+#include "key.h"
#include "keystore.h"
#include "main.h"
#include "script.h"
-#include "wallet.h"
+#include "uint256.h"
+
+#include <boost/assign/std/vector.hpp>
+#include <boost/foreach.hpp>
+#include <boost/test/unit_test.hpp>
using namespace std;
using namespace boost::assign;
diff --git a/src/test/netbase_tests.cpp b/src/test/netbase_tests.cpp
index e5a7562d97..412ba04910 100644
--- a/src/test/netbase_tests.cpp
+++ b/src/test/netbase_tests.cpp
@@ -1,9 +1,8 @@
-#include <boost/test/unit_test.hpp>
+#include "netbase.h"
#include <string>
-#include <vector>
-#include "netbase.h"
+#include <boost/test/unit_test.hpp>
using namespace std;
diff --git a/src/test/pmt_tests.cpp b/src/test/pmt_tests.cpp
index cf09421617..dea5e1b824 100644
--- a/src/test/pmt_tests.cpp
+++ b/src/test/pmt_tests.cpp
@@ -1,7 +1,12 @@
-#include <boost/test/unit_test.hpp>
-#include "uint256.h"
+
#include "main.h"
+#include "serialize.h"
+#include "uint256.h"
+
+#include <vector>
+
+#include <boost/test/unit_test.hpp>
using namespace std;
diff --git a/src/test/rpc_tests.cpp b/src/test/rpc_tests.cpp
index 25849054eb..29195545da 100644
--- a/src/test/rpc_tests.cpp
+++ b/src/test/rpc_tests.cpp
@@ -1,17 +1,15 @@
-#include <boost/algorithm/string.hpp>
-#include <boost/foreach.hpp>
-#include <boost/test/unit_test.hpp>
+#include "rpcserver.h"
+#include "rpcclient.h"
#include "base58.h"
-#include "util.h"
-#include "bitcoinrpc.h"
+
+#include <boost/algorithm/string.hpp>
+#include <boost/test/unit_test.hpp>
using namespace std;
using namespace json_spirit;
-BOOST_AUTO_TEST_SUITE(rpc_tests)
-
-static Array
+Array
createArgs(int nRequired, const char* address1=NULL, const char* address2=NULL)
{
Array result;
@@ -23,44 +21,7 @@ createArgs(int nRequired, const char* address1=NULL, const char* address2=NULL)
return result;
}
-BOOST_AUTO_TEST_CASE(rpc_addmultisig)
-{
- rpcfn_type addmultisig = tableRPC["addmultisigaddress"]->actor;
-
- // old, 65-byte-long:
- const char address1Hex[] = "0434e3e09f49ea168c5bbf53f877ff4206923858aab7c7e1df25bc263978107c95e35065a27ef6f1b27222db0ec97e0e895eaca603d3ee0d4c060ce3d8a00286c8";
- // new, compressed:
- const char address2Hex[] = "0388c2037017c62240b6b72ac1a2a5f94da790596ebd06177c8572752922165cb4";
-
- Value v;
- CBitcoinAddress address;
- BOOST_CHECK_NO_THROW(v = addmultisig(createArgs(1, address1Hex), false));
- address.SetString(v.get_str());
- BOOST_CHECK(address.IsValid() && address.IsScript());
-
- BOOST_CHECK_NO_THROW(v = addmultisig(createArgs(1, address1Hex, address2Hex), false));
- address.SetString(v.get_str());
- BOOST_CHECK(address.IsValid() && address.IsScript());
-
- BOOST_CHECK_NO_THROW(v = addmultisig(createArgs(2, address1Hex, address2Hex), false));
- address.SetString(v.get_str());
- BOOST_CHECK(address.IsValid() && address.IsScript());
-
- BOOST_CHECK_THROW(addmultisig(createArgs(0), false), runtime_error);
- BOOST_CHECK_THROW(addmultisig(createArgs(1), false), runtime_error);
- BOOST_CHECK_THROW(addmultisig(createArgs(2, address1Hex), false), runtime_error);
-
- BOOST_CHECK_THROW(addmultisig(createArgs(1, ""), false), runtime_error);
- BOOST_CHECK_THROW(addmultisig(createArgs(1, "NotAValidPubkey"), false), runtime_error);
-
- string short1(address1Hex, address1Hex+sizeof(address1Hex)-2); // last byte missing
- BOOST_CHECK_THROW(addmultisig(createArgs(2, short1.c_str()), false), runtime_error);
-
- string short2(address1Hex+1, address1Hex+sizeof(address1Hex)); // first byte missing
- BOOST_CHECK_THROW(addmultisig(createArgs(2, short2.c_str()), false), runtime_error);
-}
-
-static Value CallRPC(string args)
+Value CallRPC(string args)
{
vector<string> vArgs;
boost::split(vArgs, args, boost::is_any_of(" \t"));
@@ -79,34 +40,8 @@ static Value CallRPC(string args)
}
}
-BOOST_AUTO_TEST_CASE(rpc_wallet)
-{
- // Test RPC calls for various wallet statistics
- Value r;
-
- BOOST_CHECK_NO_THROW(CallRPC("listunspent"));
- BOOST_CHECK_THROW(CallRPC("listunspent string"), runtime_error);
- BOOST_CHECK_THROW(CallRPC("listunspent 0 string"), runtime_error);
- BOOST_CHECK_THROW(CallRPC("listunspent 0 1 not_array"), runtime_error);
- BOOST_CHECK_THROW(CallRPC("listunspent 0 1 [] extra"), runtime_error);
- BOOST_CHECK_NO_THROW(r=CallRPC("listunspent 0 1 []"));
- BOOST_CHECK(r.get_array().empty());
-
- BOOST_CHECK_NO_THROW(CallRPC("listreceivedbyaddress"));
- BOOST_CHECK_NO_THROW(CallRPC("listreceivedbyaddress 0"));
- BOOST_CHECK_THROW(CallRPC("listreceivedbyaddress not_int"), runtime_error);
- BOOST_CHECK_THROW(CallRPC("listreceivedbyaddress 0 not_bool"), runtime_error);
- BOOST_CHECK_NO_THROW(CallRPC("listreceivedbyaddress 0 true"));
- BOOST_CHECK_THROW(CallRPC("listreceivedbyaddress 0 true extra"), runtime_error);
-
- BOOST_CHECK_NO_THROW(CallRPC("listreceivedbyaccount"));
- BOOST_CHECK_NO_THROW(CallRPC("listreceivedbyaccount 0"));
- BOOST_CHECK_THROW(CallRPC("listreceivedbyaccount not_int"), runtime_error);
- BOOST_CHECK_THROW(CallRPC("listreceivedbyaccount 0 not_bool"), runtime_error);
- BOOST_CHECK_NO_THROW(CallRPC("listreceivedbyaccount 0 true"));
- BOOST_CHECK_THROW(CallRPC("listreceivedbyaccount 0 true extra"), runtime_error);
-}
+BOOST_AUTO_TEST_SUITE(rpc_tests)
BOOST_AUTO_TEST_CASE(rpc_rawparams)
{
diff --git a/src/test/rpc_wallet_tests.cpp b/src/test/rpc_wallet_tests.cpp
new file mode 100644
index 0000000000..2cf0fb350b
--- /dev/null
+++ b/src/test/rpc_wallet_tests.cpp
@@ -0,0 +1,82 @@
+#include "rpcserver.h"
+#include "rpcclient.h"
+
+#include "base58.h"
+
+#include <boost/algorithm/string.hpp>
+#include <boost/test/unit_test.hpp>
+
+using namespace std;
+using namespace json_spirit;
+
+extern Array createArgs(int nRequired, const char* address1=NULL, const char* address2=NULL);
+extern Value CallRPC(string args);
+
+BOOST_AUTO_TEST_SUITE(rpc_wallet_tests)
+
+BOOST_AUTO_TEST_CASE(rpc_addmultisig)
+{
+ rpcfn_type addmultisig = tableRPC["addmultisigaddress"]->actor;
+
+ // old, 65-byte-long:
+ const char address1Hex[] = "0434e3e09f49ea168c5bbf53f877ff4206923858aab7c7e1df25bc263978107c95e35065a27ef6f1b27222db0ec97e0e895eaca603d3ee0d4c060ce3d8a00286c8";
+ // new, compressed:
+ const char address2Hex[] = "0388c2037017c62240b6b72ac1a2a5f94da790596ebd06177c8572752922165cb4";
+
+ Value v;
+ CBitcoinAddress address;
+ BOOST_CHECK_NO_THROW(v = addmultisig(createArgs(1, address1Hex), false));
+ address.SetString(v.get_str());
+ BOOST_CHECK(address.IsValid() && address.IsScript());
+
+ BOOST_CHECK_NO_THROW(v = addmultisig(createArgs(1, address1Hex, address2Hex), false));
+ address.SetString(v.get_str());
+ BOOST_CHECK(address.IsValid() && address.IsScript());
+
+ BOOST_CHECK_NO_THROW(v = addmultisig(createArgs(2, address1Hex, address2Hex), false));
+ address.SetString(v.get_str());
+ BOOST_CHECK(address.IsValid() && address.IsScript());
+
+ BOOST_CHECK_THROW(addmultisig(createArgs(0), false), runtime_error);
+ BOOST_CHECK_THROW(addmultisig(createArgs(1), false), runtime_error);
+ BOOST_CHECK_THROW(addmultisig(createArgs(2, address1Hex), false), runtime_error);
+
+ BOOST_CHECK_THROW(addmultisig(createArgs(1, ""), false), runtime_error);
+ BOOST_CHECK_THROW(addmultisig(createArgs(1, "NotAValidPubkey"), false), runtime_error);
+
+ string short1(address1Hex, address1Hex+sizeof(address1Hex)-2); // last byte missing
+ BOOST_CHECK_THROW(addmultisig(createArgs(2, short1.c_str()), false), runtime_error);
+
+ string short2(address1Hex+1, address1Hex+sizeof(address1Hex)); // first byte missing
+ BOOST_CHECK_THROW(addmultisig(createArgs(2, short2.c_str()), false), runtime_error);
+}
+
+BOOST_AUTO_TEST_CASE(rpc_wallet)
+{
+ // Test RPC calls for various wallet statistics
+ Value r;
+
+ BOOST_CHECK_NO_THROW(CallRPC("listunspent"));
+ BOOST_CHECK_THROW(CallRPC("listunspent string"), runtime_error);
+ BOOST_CHECK_THROW(CallRPC("listunspent 0 string"), runtime_error);
+ BOOST_CHECK_THROW(CallRPC("listunspent 0 1 not_array"), runtime_error);
+ BOOST_CHECK_THROW(CallRPC("listunspent 0 1 [] extra"), runtime_error);
+ BOOST_CHECK_NO_THROW(r=CallRPC("listunspent 0 1 []"));
+ BOOST_CHECK(r.get_array().empty());
+
+ BOOST_CHECK_NO_THROW(CallRPC("listreceivedbyaddress"));
+ BOOST_CHECK_NO_THROW(CallRPC("listreceivedbyaddress 0"));
+ BOOST_CHECK_THROW(CallRPC("listreceivedbyaddress not_int"), runtime_error);
+ BOOST_CHECK_THROW(CallRPC("listreceivedbyaddress 0 not_bool"), runtime_error);
+ BOOST_CHECK_NO_THROW(CallRPC("listreceivedbyaddress 0 true"));
+ BOOST_CHECK_THROW(CallRPC("listreceivedbyaddress 0 true extra"), runtime_error);
+
+ BOOST_CHECK_NO_THROW(CallRPC("listreceivedbyaccount"));
+ BOOST_CHECK_NO_THROW(CallRPC("listreceivedbyaccount 0"));
+ BOOST_CHECK_THROW(CallRPC("listreceivedbyaccount not_int"), runtime_error);
+ BOOST_CHECK_THROW(CallRPC("listreceivedbyaccount 0 not_bool"), runtime_error);
+ BOOST_CHECK_NO_THROW(CallRPC("listreceivedbyaccount 0 true"));
+ BOOST_CHECK_THROW(CallRPC("listreceivedbyaccount 0 true extra"), runtime_error);
+}
+
+BOOST_AUTO_TEST_SUITE_END()
diff --git a/src/test/script_P2SH_tests.cpp b/src/test/script_P2SH_tests.cpp
index 3c666d2842..e57dc9bbba 100644
--- a/src/test/script_P2SH_tests.cpp
+++ b/src/test/script_P2SH_tests.cpp
@@ -1,13 +1,13 @@
-#include <boost/assert.hpp>
-#include <boost/assign/list_of.hpp>
-#include <boost/assign/list_inserter.hpp>
-#include <boost/assign/std/vector.hpp>
-#include <boost/test/unit_test.hpp>
-#include <boost/foreach.hpp>
+#include "script.h"
+
+#include "key.h"
+#include "keystore.h"
+#include "main.h"
+#include "script.h"
-#include "../main.h"
-#include "../script.h"
-#include "../wallet.h"
+#include <vector>
+
+#include <boost/test/unit_test.hpp>
using namespace std;
diff --git a/src/test/script_tests.cpp b/src/test/script_tests.cpp
index 32be914414..dee0f110ad 100644
--- a/src/test/script_tests.cpp
+++ b/src/test/script_tests.cpp
@@ -1,21 +1,28 @@
-#include <iostream>
+#include "script.h"
+
+#include "data/script_invalid.json.h"
+#include "data/script_valid.json.h"
+
+#include "key.h"
+#include "keystore.h"
+#include "main.h"
+
#include <fstream>
+#include <stdint.h>
+#include <string>
#include <vector>
+
#include <boost/algorithm/string/classification.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/algorithm/string/replace.hpp>
#include <boost/algorithm/string/split.hpp>
+#include <boost/filesystem/operations.hpp>
+#include <boost/filesystem/path.hpp>
#include <boost/foreach.hpp>
-#include <boost/preprocessor/stringize.hpp>
#include <boost/test/unit_test.hpp>
#include "json/json_spirit_reader_template.h"
-#include "json/json_spirit_writer_template.h"
#include "json/json_spirit_utils.h"
-
-#include "main.h"
-#include "wallet.h"
-#include "data/script_invalid.json.h"
-#include "data/script_valid.json.h"
+#include "json/json_spirit_writer_template.h"
using namespace std;
using namespace json_spirit;
@@ -60,7 +67,7 @@ ParseScript(string s)
(starts_with(w, "-") && all(string(w.begin()+1, w.end()), is_digit())))
{
// Number
- int64 n = atoi64(w);
+ int64_t n = atoi64(w);
result << n;
}
else if (starts_with(w, "0x") && IsHex(string(w.begin()+2, w.end())))
diff --git a/src/test/serialize_tests.cpp b/src/test/serialize_tests.cpp
index 7e193c88ce..afcdd118bc 100644
--- a/src/test/serialize_tests.cpp
+++ b/src/test/serialize_tests.cpp
@@ -1,9 +1,8 @@
-#include <boost/test/unit_test.hpp>
+#include "serialize.h"
-#include <string>
-#include <vector>
+#include <stdint.h>
-#include "serialize.h"
+#include <boost/test/unit_test.hpp>
using namespace std;
@@ -21,7 +20,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 +33,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 = -1;
+ for (uint64_t i = 0; i < 100000000000ULL; i += 999999937) {
+ uint64_t j = -1;
ss >> VARINT(j);
BOOST_CHECK_MESSAGE(i == j, "decoded:" << j << " expected:" << i);
}
diff --git a/src/test/sigopcount_tests.cpp b/src/test/sigopcount_tests.cpp
index 5a87f17600..96f663ccef 100644
--- a/src/test/sigopcount_tests.cpp
+++ b/src/test/sigopcount_tests.cpp
@@ -1,9 +1,13 @@
-#include <vector>
-#include <boost/test/unit_test.hpp>
-#include <boost/foreach.hpp>
-#include "script.h"
+
#include "key.h"
+#include "script.h"
+#include "uint256.h"
+
+#include <vector>
+
+#include <boost/foreach.hpp>
+#include <boost/test/unit_test.hpp>
using namespace std;
diff --git a/src/test/test_bitcoin.cpp b/src/test/test_bitcoin.cpp
index 1bf9a28acc..a804ff3803 100644
--- a/src/test/test_bitcoin.cpp
+++ b/src/test/test_bitcoin.cpp
@@ -1,15 +1,21 @@
#define BOOST_TEST_MODULE Bitcoin Test Suite
-#include <boost/test/unit_test.hpp>
-#include <boost/filesystem.hpp>
+
+
#include "db.h"
-#include "txdb.h"
#include "main.h"
-#include "wallet.h"
+#include "txdb.h"
+#include "ui_interface.h"
#include "util.h"
+#ifdef ENABLE_WALLET
+#include "wallet.h"
+#endif
+
+#include <boost/filesystem.hpp>
+#include <boost/test/unit_test.hpp>
+
CWallet* pwalletMain;
-CClientUIInterface uiInterface;
extern bool fPrintToConsole;
extern void noui_connect();
@@ -22,7 +28,9 @@ struct TestingSetup {
TestingSetup() {
fPrintToDebugger = true; // don't want to write to debug.log file
noui_connect();
+#ifdef ENABLE_WALLET
bitdb.MakeMock();
+#endif
pathTemp = GetTempPath() / strprintf("test_bitcoin_%lu_%i", (unsigned long)GetTime(), (int)(GetRand(100000)));
boost::filesystem::create_directories(pathTemp);
mapArgs["-datadir"] = pathTemp.string();
@@ -30,10 +38,12 @@ struct TestingSetup {
pcoinsdbview = new CCoinsViewDB(1 << 23, true);
pcoinsTip = new CCoinsViewCache(*pcoinsdbview);
InitBlockIndex();
+#ifdef ENABLE_WALLET
bool fFirstRun;
pwalletMain = new CWallet("wallet.dat");
pwalletMain->LoadWallet(fFirstRun);
RegisterWallet(pwalletMain);
+#endif
nScriptCheckThreads = 3;
for (int i=0; i < nScriptCheckThreads-1; i++)
threadGroup.create_thread(&ThreadScriptCheck);
@@ -42,12 +52,16 @@ struct TestingSetup {
{
threadGroup.interrupt_all();
threadGroup.join_all();
+#ifdef ENABLE_WALLET
delete pwalletMain;
pwalletMain = NULL;
+#endif
delete pcoinsTip;
delete pcoinsdbview;
delete pblocktree;
+#ifdef ENABLE_WALLET
bitdb.Flush(true);
+#endif
boost::filesystem::remove_all(pathTemp);
}
};
diff --git a/src/test/transaction_tests.cpp b/src/test/transaction_tests.cpp
index bd999caa14..ad33184bc5 100644
--- a/src/test/transaction_tests.cpp
+++ b/src/test/transaction_tests.cpp
@@ -1,13 +1,19 @@
+
+
+#include "data/tx_invalid.json.h"
+#include "data/tx_valid.json.h"
+
+#include "key.h"
+#include "keystore.h"
+#include "main.h"
+#include "script.h"
+
#include <map>
#include <string>
+
#include <boost/test/unit_test.hpp>
#include "json/json_spirit_writer_template.h"
-#include "main.h"
-#include "wallet.h"
-#include "data/tx_invalid.json.h"
-#include "data/tx_valid.json.h"
-
using namespace std;
using namespace json_spirit;
diff --git a/src/test/uint160_tests.cpp b/src/test/uint160_tests.cpp
index 35cb35b25a..87418fabec 100644
--- a/src/test/uint160_tests.cpp
+++ b/src/test/uint160_tests.cpp
@@ -1,7 +1,9 @@
-#include <boost/test/unit_test.hpp>
-
#include "uint256.h"
+#include <stdint.h>
+
+#include <boost/test/unit_test.hpp>
+
BOOST_AUTO_TEST_SUITE(uint160_tests)
BOOST_AUTO_TEST_CASE(uint160_equality)
@@ -10,7 +12,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 efdc8a6aeb..188635dcbd 100644
--- a/src/test/uint256_tests.cpp
+++ b/src/test/uint256_tests.cpp
@@ -1,6 +1,9 @@
-#include <boost/test/unit_test.hpp>
-
#include "uint256.h"
+#include <string>
+
+#include <stdint.h>
+
+#include <boost/test/unit_test.hpp>
BOOST_AUTO_TEST_SUITE(uint256_tests)
@@ -10,9 +13,17 @@ 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);
}
+BOOST_AUTO_TEST_CASE(uint256_hex)
+{
+ std::string hexStr = "d35583ed493a5eee756931353144f558e6a9ab3ad6024a63ced7f10daf7faad9";
+ uint256 num1;
+ num1.SetHex(hexStr);
+ BOOST_CHECK(num1.GetHex() == hexStr);
+}
+
BOOST_AUTO_TEST_SUITE_END()
diff --git a/src/test/util_tests.cpp b/src/test/util_tests.cpp
index abfd882655..b57945d061 100644
--- a/src/test/util_tests.cpp
+++ b/src/test/util_tests.cpp
@@ -1,10 +1,11 @@
+#include "util.h"
+
+#include "sync.h"
+
+#include <stdint.h>
#include <vector>
-#include <boost/test/unit_test.hpp>
-#include <boost/foreach.hpp>
-#include "main.h"
-#include "wallet.h"
-#include "util.h"
+#include <boost/test/unit_test.hpp>
using namespace std;
@@ -200,7 +201,7 @@ BOOST_AUTO_TEST_CASE(util_FormatMoney)
BOOST_AUTO_TEST_CASE(util_ParseMoney)
{
- int64 ret = 0;
+ int64_t ret = 0;
BOOST_CHECK(ParseMoney("0.0", ret));
BOOST_CHECK_EQUAL(ret, 0);
@@ -302,4 +303,31 @@ BOOST_AUTO_TEST_CASE(util_TimingResistantEqual)
BOOST_CHECK(!TimingResistantEqual(std::string("abc"), std::string("aba")));
}
+/* Test strprintf formatting directives.
+ * Put a string before and after to ensure sanity of element sizes on stack. */
+#define B "check_prefix"
+#define E "check_postfix"
+BOOST_AUTO_TEST_CASE(strprintf_numbers)
+{
+ int64_t s64t = -9223372036854775807LL; /* signed 64 bit test value */
+ uint64_t u64t = 18446744073709551615ULL; /* unsigned 64 bit test value */
+ BOOST_CHECK(strprintf("%s %"PRId64" %s", B, s64t, E) == B" -9223372036854775807 "E);
+ BOOST_CHECK(strprintf("%s %"PRIu64" %s", B, u64t, E) == B" 18446744073709551615 "E);
+ BOOST_CHECK(strprintf("%s %"PRIx64" %s", B, u64t, E) == B" ffffffffffffffff "E);
+
+ size_t st = 12345678; /* unsigned size_t test value */
+ ssize_t sst = -12345678; /* signed size_t test value */
+ BOOST_CHECK(strprintf("%s %"PRIszd" %s", B, sst, E) == B" -12345678 "E);
+ BOOST_CHECK(strprintf("%s %"PRIszu" %s", B, st, E) == B" 12345678 "E);
+ BOOST_CHECK(strprintf("%s %"PRIszx" %s", B, st, E) == B" bc614e "E);
+
+ ptrdiff_t pt = 87654321; /* positive ptrdiff_t test value */
+ ptrdiff_t spt = -87654321; /* negative ptrdiff_t test value */
+ BOOST_CHECK(strprintf("%s %"PRIpdd" %s", B, spt, E) == B" -87654321 "E);
+ BOOST_CHECK(strprintf("%s %"PRIpdu" %s", B, pt, E) == B" 87654321 "E);
+ BOOST_CHECK(strprintf("%s %"PRIpdx" %s", B, pt, E) == B" 5397fb1 "E);
+}
+#undef B
+#undef E
+
BOOST_AUTO_TEST_SUITE_END()
diff --git a/src/test/wallet_tests.cpp b/src/test/wallet_tests.cpp
index 51f3b27c8b..0acd94ef36 100644
--- a/src/test/wallet_tests.cpp
+++ b/src/test/wallet_tests.cpp
@@ -1,8 +1,13 @@
-#include <boost/test/unit_test.hpp>
-
-#include "main.h"
#include "wallet.h"
+#include <set>
+#include <stdint.h>
+#include <utility>
+#include <vector>
+
+#include <boost/foreach.hpp>
+#include <boost/test/unit_test.hpp>
+
// how many times to run all the tests to have a chance to catch errors that only show up with particular random shuffles
#define RUN_TESTS 100
@@ -19,7 +24,7 @@ BOOST_AUTO_TEST_SUITE(wallet_tests)
static CWallet wallet;
static vector<COutput> vCoins;
-static void add_coin(int64 nValue, int nAge = 6*24, bool fIsFromMe = false, int nInput=0)
+static void add_coin(int64_t nValue, int nAge = 6*24, bool fIsFromMe = false, int nInput=0)
{
static int nextLockTime = 0;
CTransaction tx;
@@ -55,7 +60,7 @@ static bool equal_sets(CoinSet a, CoinSet b)
BOOST_AUTO_TEST_CASE(coin_selection_tests)
{
CoinSet setCoinsRet, setCoinsRet2;
- int64 nValueRet;
+ int64_t nValueRet;
// test multiple times to allow for differences in the shuffle order
for (int i = 0; i < RUN_TESTS; i++)