aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/db.cpp4
-rw-r--r--src/key.h7
-rw-r--r--src/main.cpp11
-rw-r--r--src/makefile.linux-mingw2
-rw-r--r--src/makefile.mingw2
-rw-r--r--src/makefile.osx2
-rw-r--r--src/makefile.unix6
-rw-r--r--src/net.cpp9
-rw-r--r--src/net.h3
-rw-r--r--src/script.h3
-rw-r--r--src/serialize.h1
-rw-r--r--src/test/script_tests.cpp37
-rw-r--r--src/test/test_bitcoin.cpp14
-rw-r--r--src/test/transaction_tests.cpp25
-rw-r--r--src/test/uint160_tests.cpp4
-rw-r--r--src/test/uint256_tests.cpp4
16 files changed, 119 insertions, 15 deletions
diff --git a/src/db.cpp b/src/db.cpp
index b1c99a03f2..72542705a6 100644
--- a/src/db.cpp
+++ b/src/db.cpp
@@ -611,7 +611,7 @@ bool CWalletDB::WriteAccount(const string& strAccount, const CAccount& account)
bool CWalletDB::WriteAccountingEntry(const CAccountingEntry& acentry)
{
- return Write(make_tuple(string("acentry"), acentry.strAccount, ++nAccountingEntryNumber), acentry);
+ return Write(boost::make_tuple(string("acentry"), acentry.strAccount, ++nAccountingEntryNumber), acentry);
}
int64 CWalletDB::GetAccountCreditDebit(const string& strAccount)
@@ -639,7 +639,7 @@ void CWalletDB::ListAccountCreditDebit(const string& strAccount, list<CAccountin
// Read next record
CDataStream ssKey;
if (fFlags == DB_SET_RANGE)
- ssKey << make_tuple(string("acentry"), (fAllAccounts? string("") : strAccount), uint64(0));
+ ssKey << boost::make_tuple(string("acentry"), (fAllAccounts? string("") : strAccount), uint64(0));
CDataStream ssValue;
int ret = ReadAtCursor(pcursor, ssKey, ssValue, fFlags);
fFlags = DB_NEXT;
diff --git a/src/key.h b/src/key.h
index 4c7f9baf93..d2e6689456 100644
--- a/src/key.h
+++ b/src/key.h
@@ -5,10 +5,17 @@
#ifndef BITCOIN_KEY_H
#define BITCOIN_KEY_H
+#include <stdexcept>
+#include <vector>
+
#include <openssl/ec.h>
#include <openssl/ecdsa.h>
#include <openssl/obj_mac.h>
+#include "serialize.h"
+#include "uint256.h"
+#include "base58.h"
+
// secp160k1
// const unsigned int PRIVATE_KEY_SIZE = 192;
// const unsigned int PUBLIC_KEY_SIZE = 41;
diff --git a/src/main.cpp b/src/main.cpp
index 289c295b88..ee9165095a 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -315,6 +315,15 @@ bool CTransaction::CheckTransaction() const
return error("CTransaction::CheckTransaction() : txout total out of range");
}
+ // Check for duplicate inputs
+ set<COutPoint> vInOutPoints;
+ BOOST_FOREACH(const CTxIn& txin, vin)
+ {
+ if (vInOutPoints.count(txin.prevout))
+ return false;
+ vInOutPoints.insert(txin.prevout);
+ }
+
if (IsCoinBase())
{
if (vin[0].scriptSig.size() < 2 || vin[0].scriptSig.size() > 100)
@@ -1767,7 +1776,7 @@ bool static AlreadyHave(CTxDB& txdb, const CInv& inv)
// The message start string is designed to be unlikely to occur in normal data.
// The characters are rarely used upper ascii, not valid as UTF-8, and produce
// a large 4-byte int at any alignment.
-char pchMessageStart[4] = { 0xf9, 0xbe, 0xb4, 0xd9 };
+unsigned char pchMessageStart[4] = { 0xf9, 0xbe, 0xb4, 0xd9 };
bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
diff --git a/src/makefile.linux-mingw b/src/makefile.linux-mingw
index 59ff03c48d..e2ef4213aa 100644
--- a/src/makefile.linux-mingw
+++ b/src/makefile.linux-mingw
@@ -90,7 +90,7 @@ bitcoind.exe: $(OBJS:obj/%=obj/nogui/%) obj/ui_res.o
obj/test/%.o: obj/test/%.cpp $(HEADERS)
i586-mingw32msvc-g++ -c $(CFLAGS) -o $@ $<
-test_bitcoin.exe: obj/test/test_bitcoin.o
+test_bitcoin.exe: obj/test/test_bitcoin.o $(filter-out obj/nogui/init.o,$(OBJS:obj/%=obj/nogui/%))
i586-mingw32msvc-g++ $(CFLAGS) -o $@ $(LIBPATHS) $^ $(LIBS) -lboost_unit_test_framework-mt-s
diff --git a/src/makefile.mingw b/src/makefile.mingw
index 16a0540094..96f81b3067 100644
--- a/src/makefile.mingw
+++ b/src/makefile.mingw
@@ -86,7 +86,7 @@ bitcoind.exe: $(OBJS:obj/%=obj/nogui/%) obj/ui_res.o
obj/test/%.o: obj/test/%.cpp $(HEADERS)
g++ -c $(CFLAGS) -o $@ $<
-test_bitcoin: obj/test/test_bitcoin.o
+test_bitcoin.exe: obj/test/test_bitcoin.o $(filter-out obj/nogui/init.o,$(OBJS:obj/%=obj/nogui/%))
g++ $(CFLAGS) -o $@ $(LIBPATHS) $^ $(LIBS)
clean:
diff --git a/src/makefile.osx b/src/makefile.osx
index 89788562c3..699911d4e6 100644
--- a/src/makefile.osx
+++ b/src/makefile.osx
@@ -79,7 +79,7 @@ bitcoind: $(OBJS:obj/%=obj/nogui/%)
obj/test/%.o: test/%.cpp $(HEADERS)
$(CXX) -c $(CFLAGS) -o $@ $<
-test_bitcoin: obj/test/test_bitcoin.o
+test_bitcoin: obj/test/test_bitcoin.o $(filter-out obj/nogui/init.o,$(OBJS:obj/%=obj/nogui/%))
$(CXX) $(CFLAGS) -o $@ $(LIBPATHS) $^ $(LIBS) -lboost_unit_test_framework
clean:
diff --git a/src/makefile.unix b/src/makefile.unix
index 0567f8b75e..ba9d0ca11d 100644
--- a/src/makefile.unix
+++ b/src/makefile.unix
@@ -78,10 +78,10 @@ bitcoind: $(OBJS:obj/%=obj/nogui/%)
$(CXX) $(CXXFLAGS) -o $@ $^ $(LIBS)
obj/test/%.o: test/%.cpp $(HEADERS)
- $(CXX) -c $(CFLAGS) -o $@ $<
+ $(CXX) -c $(CXXFLAGS) -o $@ $<
-test_bitcoin: obj/test/test_bitcoin.o
- $(CXX) $(CFLAGS) -o $@ $(LIBPATHS) $^ $(LIBS) -lboost_unit_test_framework
+test_bitcoin: obj/test/test_bitcoin.o $(filter-out obj/nogui/init.o,$(OBJS:obj/%=obj/nogui/%))
+ $(CXX) $(CXXFLAGS) -o $@ $(LIBPATHS) $^ -Wl,-Bstatic -lboost_unit_test_framework $(LIBS)
clean:
-rm -f bitcoin bitcoind test_bitcoin
diff --git a/src/net.cpp b/src/net.cpp
index 2bb2156684..3953f021e9 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -99,7 +99,7 @@ bool ConnectSocket(const CAddress& addrConnect, SOCKET& hSocketRet, int nTimeout
SOCKET hSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (hSocket == INVALID_SOCKET)
return false;
-#ifdef BSD
+#ifdef SO_NOSIGPIPE
int set = 1;
setsockopt(hSocket, SOL_SOCKET, SO_NOSIGPIPE, (void*)&set, sizeof(int));
#endif
@@ -1144,6 +1144,11 @@ void MapPort(bool fMapPort)
printf("Error: ThreadMapPort(ThreadMapPort) failed\n");
}
}
+#else
+void MapPort(bool /* unused fMapPort */)
+{
+ // Intentionally left blank.
+}
#endif
@@ -1580,7 +1585,7 @@ bool BindListenPort(string& strError)
return false;
}
-#ifdef BSD
+#ifdef SO_NOSIGPIPE
// Different way of disabling SIGPIPE on BSD
setsockopt(hListenSocket, SOL_SOCKET, SO_NOSIGPIPE, (void*)&nOne, sizeof(int));
#endif
diff --git a/src/net.h b/src/net.h
index ce41226f64..37fab7f8b0 100644
--- a/src/net.h
+++ b/src/net.h
@@ -7,6 +7,7 @@
#include <deque>
#include <boost/array.hpp>
+#include <boost/foreach.hpp>
#include <openssl/rand.h>
#ifndef __WXMSW__
@@ -67,7 +68,7 @@ bool StopNode();
// (4) size
// (4) checksum
-extern char pchMessageStart[4];
+extern unsigned char pchMessageStart[4];
class CMessageHeader
{
diff --git a/src/script.h b/src/script.h
index f866dde714..e61ea2fd7e 100644
--- a/src/script.h
+++ b/src/script.h
@@ -11,6 +11,8 @@
#include <string>
#include <vector>
+#include <boost/foreach.hpp>
+
class CTransaction;
enum
@@ -690,6 +692,7 @@ public:
+bool EvalScript(std::vector<std::vector<unsigned char> >& stack, const CScript& script, const CTransaction& txTo, unsigned int nIn, int nHashType);
bool IsStandard(const CScript& scriptPubKey);
bool IsMine(const CKeyStore& keystore, const CScript& scriptPubKey);
diff --git a/src/serialize.h b/src/serialize.h
index c183d4b38f..c55775242b 100644
--- a/src/serialize.h
+++ b/src/serialize.h
@@ -35,6 +35,7 @@ typedef unsigned long long uint64;
// Note that VirtualLock does not provide this as a guarantee on Windows,
// but, in practice, memory that has been VirtualLock'd almost never gets written to
// the pagefile except in rare circumstances where memory is extremely low.
+#include <windows.h>
#define mlock(p, n) VirtualLock((p), (n));
#define munlock(p, n) VirtualUnlock((p), (n));
#else
diff --git a/src/test/script_tests.cpp b/src/test/script_tests.cpp
new file mode 100644
index 0000000000..5e74648c4b
--- /dev/null
+++ b/src/test/script_tests.cpp
@@ -0,0 +1,37 @@
+#include <vector>
+#include <boost/test/unit_test.hpp>
+#include <boost/foreach.hpp>
+
+#include "../main.h"
+#include "../wallet.h"
+
+using namespace std;
+
+BOOST_AUTO_TEST_SUITE(script_tests)
+
+BOOST_AUTO_TEST_CASE(script_PushData)
+{
+ // Check that PUSHDATA1, PUSHDATA2, and PUSHDATA4 create the same value on
+ // the stack as the 1-75 opcodes do.
+ static const unsigned char direct[] = { 1, 0x5a };
+ static const unsigned char pushdata1[] = { OP_PUSHDATA1, 1, 0x5a };
+ static const unsigned char pushdata2[] = { OP_PUSHDATA2, 1, 0, 0x5a };
+ static const unsigned char pushdata4[] = { OP_PUSHDATA4, 1, 0, 0, 0, 0x5a };
+
+ vector<vector<unsigned char> > directStack;
+ BOOST_CHECK(EvalScript(directStack, CScript(&direct[0], &direct[sizeof(direct)]), CTransaction(), 0, 0));
+
+ vector<vector<unsigned char> > pushdata1Stack;
+ BOOST_CHECK(EvalScript(pushdata1Stack, CScript(&pushdata1[0], &pushdata1[sizeof(pushdata1)]), CTransaction(), 0, 0));
+ BOOST_CHECK(pushdata1Stack == directStack);
+
+ vector<vector<unsigned char> > pushdata2Stack;
+ BOOST_CHECK(EvalScript(pushdata2Stack, CScript(&pushdata2[0], &pushdata2[sizeof(pushdata2)]), CTransaction(), 0, 0));
+ BOOST_CHECK(pushdata2Stack == directStack);
+
+ vector<vector<unsigned char> > pushdata4Stack;
+ BOOST_CHECK(EvalScript(pushdata4Stack, CScript(&pushdata4[0], &pushdata4[sizeof(pushdata4)]), CTransaction(), 0, 0));
+ BOOST_CHECK(pushdata4Stack == directStack);
+}
+
+BOOST_AUTO_TEST_SUITE_END()
diff --git a/src/test/test_bitcoin.cpp b/src/test/test_bitcoin.cpp
index 3b7d2d2f2c..0230bb6eca 100644
--- a/src/test/test_bitcoin.cpp
+++ b/src/test/test_bitcoin.cpp
@@ -1,6 +1,18 @@
-#define BOOST_TEST_MODULE uint160
+#define BOOST_TEST_MODULE Bitcoin Test Suite
#include <boost/test/unit_test.hpp>
+#include "../main.h"
+#include "../wallet.h"
+
#include "uint160_tests.cpp"
#include "uint256_tests.cpp"
+#include "script_tests.cpp"
+#include "transaction_tests.cpp"
+
+
+CWallet* pwalletMain;
+void Shutdown(void* parg)
+{
+ exit(0);
+}
diff --git a/src/test/transaction_tests.cpp b/src/test/transaction_tests.cpp
new file mode 100644
index 0000000000..e6eb0f054f
--- /dev/null
+++ b/src/test/transaction_tests.cpp
@@ -0,0 +1,25 @@
+#include <boost/test/unit_test.hpp>
+
+#include "../main.h"
+#include "../wallet.h"
+
+using namespace std;
+
+BOOST_AUTO_TEST_SUITE(transaction_tests)
+
+BOOST_AUTO_TEST_CASE(basic_transaction_tests)
+{
+ // Random real transaction (e2769b09e784f32f62ef849763d4f45b98e07ba658647343b915ff832b110436)
+ unsigned char ch[] = {0x01, 0x00, 0x00, 0x00, 0x01, 0x6b, 0xff, 0x7f, 0xcd, 0x4f, 0x85, 0x65, 0xef, 0x40, 0x6d, 0xd5, 0xd6, 0x3d, 0x4f, 0xf9, 0x4f, 0x31, 0x8f, 0xe8, 0x20, 0x27, 0xfd, 0x4d, 0xc4, 0x51, 0xb0, 0x44, 0x74, 0x01, 0x9f, 0x74, 0xb4, 0x00, 0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0x00, 0x00, 0x00, 0x00, 0x19, 0x76, 0xa9, 0x14, 0xc1, 0x09, 0x32, 0x48, 0x3f, 0xec, 0x93, 0xed, 0x51, 0xf5, 0xfe, 0x95, 0xe7, 0x25, 0x59, 0xf2, 0xcc, 0x70, 0x43, 0xf9, 0x88, 0xac, 0x00, 0x00, 0x00, 0x00, 0x00};
+ vector<unsigned char> vch(ch, ch + sizeof(ch) -1);
+ CDataStream stream(vch);
+ CTransaction tx;
+ stream >> tx;
+ BOOST_CHECK_MESSAGE(tx.CheckTransaction(), "Simple deserialized transaction should be valid.");
+
+ // Check that duplicate txins fail
+ tx.vin.push_back(tx.vin[0]);
+ BOOST_CHECK_MESSAGE(!tx.CheckTransaction(), "Transaction with duplicate txins should be invalid.");
+}
+
+BOOST_AUTO_TEST_SUITE_END()
diff --git a/src/test/uint160_tests.cpp b/src/test/uint160_tests.cpp
index 66ffd285b8..42c8275afe 100644
--- a/src/test/uint160_tests.cpp
+++ b/src/test/uint160_tests.cpp
@@ -1,8 +1,10 @@
+#include <boost/test/unit_test.hpp>
+
#include "../uint256.h"
BOOST_AUTO_TEST_SUITE(uint160_tests)
-BOOST_AUTO_TEST_CASE(equality)
+BOOST_AUTO_TEST_CASE(uint160_equality)
{
uint160 num1 = 10;
uint160 num2 = 11;
diff --git a/src/test/uint256_tests.cpp b/src/test/uint256_tests.cpp
index cbae9bf6d2..c5d45e215e 100644
--- a/src/test/uint256_tests.cpp
+++ b/src/test/uint256_tests.cpp
@@ -1,8 +1,10 @@
+#include <boost/test/unit_test.hpp>
+
#include "../uint256.h"
BOOST_AUTO_TEST_SUITE(uint256_tests)
-BOOST_AUTO_TEST_CASE(equality)
+BOOST_AUTO_TEST_CASE(uint256_equality)
{
uint256 num1 = 10;
uint256 num2 = 11;