aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'src/test')
-rw-r--r--src/test/accounting_tests.cpp2
-rw-r--r--src/test/miner_tests.cpp51
-rw-r--r--src/test/rpc_wallet_tests.cpp7
-rw-r--r--src/test/wallet_tests.cpp2
4 files changed, 61 insertions, 1 deletions
diff --git a/src/test/accounting_tests.cpp b/src/test/accounting_tests.cpp
index 5f79436e48..bfdb95927b 100644
--- a/src/test/accounting_tests.cpp
+++ b/src/test/accounting_tests.cpp
@@ -34,6 +34,8 @@ BOOST_AUTO_TEST_CASE(acc_orderupgrade)
CAccountingEntry ae;
std::map<int64_t, CAccountingEntry> results;
+ LOCK(pwalletMain->cs_wallet);
+
ae.strAccount = "";
ae.nCreditDebit = 1;
ae.nTime = 1333333333;
diff --git a/src/test/miner_tests.cpp b/src/test/miner_tests.cpp
index 8e3091d555..d35137a663 100644
--- a/src/test/miner_tests.cpp
+++ b/src/test/miner_tests.cpp
@@ -51,7 +51,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
{
CScript scriptPubKey = CScript() << ParseHex("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f") << OP_CHECKSIG;
CBlockTemplate *pblocktemplate;
- CTransaction tx;
+ CTransaction tx,tx2;
CScript script;
uint256 hash;
@@ -204,8 +204,57 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
delete pblocktemplate;
chainActive.Tip()->nHeight = nHeight;
+ // non-final txs in mempool
+ SetMockTime(chainActive.Tip()->GetMedianTimePast()+1);
+
+ // height locked
+ tx.vin[0].prevout.hash = txFirst[0]->GetHash();
+ tx.vin[0].scriptSig = CScript() << OP_1;
+ tx.vin[0].nSequence = 0;
+ tx.vout[0].nValue = 4900000000LL;
+ tx.vout[0].scriptPubKey = CScript() << OP_1;
+ tx.nLockTime = chainActive.Tip()->nHeight+1;
+ hash = tx.GetHash();
+ mempool.addUnchecked(hash, CTxMemPoolEntry(tx, 11, GetTime(), 111.0, 11));
+ BOOST_CHECK(!IsFinalTx(tx, chainActive.Tip()->nHeight + 1));
+
+ // time locked
+ tx2.vin.resize(1);
+ tx2.vin[0].prevout.hash = txFirst[1]->GetHash();
+ tx2.vin[0].prevout.n = 0;
+ tx2.vin[0].scriptSig = CScript() << OP_1;
+ tx2.vin[0].nSequence = 0;
+ tx2.vout.resize(1);
+ tx2.vout[0].nValue = 4900000000LL;
+ tx2.vout[0].scriptPubKey = CScript() << OP_1;
+ tx2.nLockTime = chainActive.Tip()->GetMedianTimePast()+1;
+ hash = tx2.GetHash();
+ mempool.addUnchecked(hash, CTxMemPoolEntry(tx2, 11, GetTime(), 111.0, 11));
+ BOOST_CHECK(!IsFinalTx(tx2));
+
+ BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey));
+
+ // Neither tx should have make it into the template.
+ BOOST_CHECK_EQUAL(pblocktemplate->block.vtx.size(), 1);
+ delete pblocktemplate;
+
+ // However if we advance height and time by one, both will.
+ chainActive.Tip()->nHeight++;
+ SetMockTime(chainActive.Tip()->GetMedianTimePast()+2);
+
+ BOOST_CHECK(IsFinalTx(tx, chainActive.Tip()->nHeight + 1));
+ BOOST_CHECK(IsFinalTx(tx2));
+
+ BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey));
+ BOOST_CHECK_EQUAL(pblocktemplate->block.vtx.size(), 3);
+ delete pblocktemplate;
+
+ chainActive.Tip()->nHeight--;
+ SetMockTime(0);
+
BOOST_FOREACH(CTransaction *tx, txFirst)
delete tx;
+
}
BOOST_AUTO_TEST_CASE(sha256transform_equality)
diff --git a/src/test/rpc_wallet_tests.cpp b/src/test/rpc_wallet_tests.cpp
index 2cf0fb350b..628ba95067 100644
--- a/src/test/rpc_wallet_tests.cpp
+++ b/src/test/rpc_wallet_tests.cpp
@@ -2,6 +2,7 @@
#include "rpcclient.h"
#include "base58.h"
+#include "wallet.h"
#include <boost/algorithm/string.hpp>
#include <boost/test/unit_test.hpp>
@@ -12,10 +13,14 @@ using namespace json_spirit;
extern Array createArgs(int nRequired, const char* address1=NULL, const char* address2=NULL);
extern Value CallRPC(string args);
+extern CWallet* pwalletMain;
+
BOOST_AUTO_TEST_SUITE(rpc_wallet_tests)
BOOST_AUTO_TEST_CASE(rpc_addmultisig)
{
+ LOCK(pwalletMain->cs_wallet);
+
rpcfn_type addmultisig = tableRPC["addmultisigaddress"]->actor;
// old, 65-byte-long:
@@ -56,6 +61,8 @@ BOOST_AUTO_TEST_CASE(rpc_wallet)
// Test RPC calls for various wallet statistics
Value r;
+ LOCK(pwalletMain->cs_wallet);
+
BOOST_CHECK_NO_THROW(CallRPC("listunspent"));
BOOST_CHECK_THROW(CallRPC("listunspent string"), runtime_error);
BOOST_CHECK_THROW(CallRPC("listunspent 0 string"), runtime_error);
diff --git a/src/test/wallet_tests.cpp b/src/test/wallet_tests.cpp
index 0acd94ef36..bd0517ae08 100644
--- a/src/test/wallet_tests.cpp
+++ b/src/test/wallet_tests.cpp
@@ -62,6 +62,8 @@ BOOST_AUTO_TEST_CASE(coin_selection_tests)
CoinSet setCoinsRet, setCoinsRet2;
int64_t nValueRet;
+ LOCK(wallet.cs_wallet);
+
// test multiple times to allow for differences in the shuffle order
for (int i = 0; i < RUN_TESTS; i++)
{