Mercurial > hg > bitcoin
changeset 1263:32d9404d58dc draft
Merge branch 'master' of https://github.com/bitcoin/bitcoin
author | Wladimir J. van der Laan <laanwj@gmail.com> |
---|---|
date | Thu, 11 Aug 2011 10:17:21 +0200 |
parents | ee115fab6952 (current diff) 50b3023b72c4 (diff) |
children | eea709595ed2 |
files | src/db.cpp src/key.h src/main.cpp src/net.cpp src/net.h src/script.h src/serialize.h |
diffstat | 16 files changed, 118 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/src/db.cpp +++ b/src/db.cpp @@ -610,7 +610,7 @@ 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) @@ -638,7 +638,7 @@ // 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;
--- a/src/key.h +++ b/src/key.h @@ -4,10 +4,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;
--- a/src/main.cpp +++ b/src/main.cpp @@ -314,6 +314,15 @@ 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) @@ -1766,7 +1775,7 @@ // 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)
--- a/src/makefile.linux-mingw +++ b/src/makefile.linux-mingw @@ -90,7 +90,7 @@ 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
--- a/src/makefile.mingw +++ b/src/makefile.mingw @@ -86,7 +86,7 @@ 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:
--- a/src/makefile.osx +++ b/src/makefile.osx @@ -79,7 +79,7 @@ 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:
--- a/src/makefile.unix +++ b/src/makefile.unix @@ -78,10 +78,10 @@ $(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
--- a/src/net.cpp +++ b/src/net.cpp @@ -98,7 +98,7 @@ 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 @@ -1143,6 +1143,11 @@ printf("Error: ThreadMapPort(ThreadMapPort) failed\n"); } } +#else +void MapPort(bool /* unused fMapPort */) +{ + // Intentionally left blank. +} #endif @@ -1579,7 +1584,7 @@ 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
--- a/src/net.h +++ b/src/net.h @@ -67,7 +67,7 @@ // (4) size // (4) checksum -extern char pchMessageStart[4]; +extern unsigned char pchMessageStart[4]; class CMessageHeader {
--- a/src/script.h +++ b/src/script.h @@ -10,6 +10,8 @@ #include <string> #include <vector> +#include <boost/foreach.hpp> + class CTransaction; enum @@ -689,6 +691,7 @@ +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);
--- a/src/serialize.h +++ b/src/serialize.h @@ -35,6 +35,7 @@ // 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
new file mode 100644 --- /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()
--- 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); +}
new file mode 100644 --- /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, 0x00, 0x00, 0x00, 0x8c, 0x49, 0x30, 0x46, 0x02, 0x21, 0x00, 0xda, 0x0d, 0xc6, 0xae, 0xce, 0xfe, 0x1e, 0x06, 0xef, 0xdf, 0x05, 0x77, 0x37, 0x57, 0xde, 0xb1, 0x68, 0x82, 0x09, 0x30, 0xe3, 0xb0, 0xd0, 0x3f, 0x46, 0xf5, 0xfc, 0xf1, 0x50, 0xbf, 0x99, 0x0c, 0x02, 0x21, 0x00, 0xd2, 0x5b, 0x5c, 0x87, 0x04, 0x00, 0x76, 0xe4, 0xf2, 0x53, 0xf8, 0x26, 0x2e, 0x76, 0x3e, 0x2d, 0xd5, 0x1e, 0x7f, 0xf0, 0xbe, 0x15, 0x77, 0x27, 0xc4, 0xbc, 0x42, 0x80, 0x7f, 0x17, 0xbd, 0x39, 0x01, 0x41, 0x04, 0xe6, 0xc2, 0x6e, 0xf6, 0x7d, 0xc6, 0x10, 0xd2, 0xcd, 0x19, 0x24, 0x84, 0x78, 0x9a, 0x6c, 0xf9, 0xae, 0xa9, 0x93, 0x0b, 0x94, 0x4b, 0x7e, 0x2d, 0xb5, 0x34, 0x2b, 0x9d, 0x9e, 0x5b, 0x9f, 0xf7, 0x9a, 0xff, 0x9a, 0x2e, 0xe1, 0x97, 0x8d, 0xd7, 0xfd, 0x01, 0xdf, 0xc5, 0x22, 0xee, 0x02, 0x28, 0x3d, 0x3b, 0x06, 0xa9, 0xd0, 0x3a, 0xcf, 0x80, 0x96, 0x96, 0x8d, 0x7d, 0xbb, 0x0f, 0x91, 0x78, 0xff, 0xff, 0xff, 0xff, 0x02, 0x8b, 0xa7, 0x94, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x19, 0x76, 0xa9, 0x14, 0xba, 0xde, 0xec, 0xfd, 0xef, 0x05, 0x07, 0x24, 0x7f, 0xc8, 0xf7, 0x42, 0x41, 0xd7, 0x3b, 0xc0, 0x39, 0x97, 0x2d, 0x7b, 0x88, 0xac, 0x40, 0x94, 0xa8, 0x02, 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()