unit tests and sanity checks

This commit is contained in:
Evan Duffield 2014-09-23 10:19:13 -07:00
parent 50fad9e08e
commit f2072c3c89
4 changed files with 51 additions and 86 deletions

View File

@ -1511,13 +1511,15 @@ bool CDarkSendPool::IsCompatibleWithSession(int64 nAmount, std::string& strReaso
sessionUsers++;
lastTimeChanged = GetTimeMillis();
//broadcast that I'm accepting entries, only if it's the first entry though
CDarksendQueue dsq;
dsq.nDenom = GetDenominationsByAmount(nAmount);
dsq.vin = vinMasterNode;
dsq.time = GetTime();
dsq.Sign();
dsq.Relay();
if(!unitTest){
//broadcast that I'm accepting entries, only if it's the first entry though
CDarksendQueue dsq;
dsq.nDenom = GetDenominationsByAmount(nAmount);
dsq.vin = vinMasterNode;
dsq.time = GetTime();
dsq.Sign();
dsq.Relay();
}
UpdateState(POOL_STATUS_QUEUE);

View File

@ -379,6 +379,11 @@ public:
return POOL_MAX_TRANSACTIONS;
}
//Do we have enough users to take entries?
bool IsSessionReady(){
return sessionUsers >= GetMaxPoolTransactions();
}
// Are these outputs compatible with other client in the pool?
bool IsCompatibleWithEntries(std::vector<CTxOut> vout);

View File

@ -3962,6 +3962,10 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
return false;
}
if(!fMasterNode){
return false;
}
std::vector<CTxIn> in;
int64 nAmount;
CTransaction txCollateral;
@ -3970,26 +3974,22 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
std::string error = "";
/* if(!darkSendPool.IsCompatibleWithEntries(out))
//do we have enough users in the current session?
if(darkSendPool.IsSessionReady()){
LogPrintf("dsi -- session not complete! \n");
error = "session not complete!";
pfrom->PushMessage("dssu", darkSendPool.sessionID, darkSendPool.GetState(), darkSendPool.GetEntriesCount(), MASTERNODE_REJECTED, error);
return false;
}
//do we have the same denominations as the current session?
if(!darkSendPool.IsCompatibleWithEntries(out))
{
LogPrintf("dsi -- not compatible with existing transactions! \n");
error = "not compatible with existing transactions";
pfrom->PushMessage("dssu", darkSendPool.sessionID, darkSendPool.GetState(), darkSendPool.GetEntriesCount(), MASTERNODE_REJECTED, error);
return true;
}
or
if(GetDenominationByAmount(sessionAmount) != GetDenominationByAmount(nAmount)){
}
also
if(entries.size() == 0 && GetDenominationByAmount(sessionAmount) != GetDenominationByAmount(nAmount)) {
sessionAmount = nAmount;
}
*/
//check it like a transaction
{

View File

@ -5,6 +5,7 @@
#include "base58.h"
#include "util.h"
#include "main.h"
#include "darksend.h"
using namespace std;
@ -108,77 +109,34 @@ BOOST_AUTO_TEST_CASE(darksend_denom)
BOOST_AUTO_TEST_CASE(darksend_session)
{
BOOST_CHECK(darkSendPool.IsCompatibleWithSession(511*COIN));
BOOST_CHECK(darkSendPool.IsCompatibleWithSession(131*COIN) == false);
BOOST_CHECK(darkSendPool.IsCompatibleWithSession(31*COIN) == false);
BOOST_CHECK(darkSendPool.IsCompatibleWithSession(151*COIN) == false);
BOOST_CHECK(darkSendPool.IsCompatibleWithSession(751*COIN) == false);
BOOST_CHECK(darkSendPool.IsCompatibleWithSession(531*COIN));
if(darkSendPool.GetMaxPoolTransactions() >= 3) BOOST_CHECK(darkSendPool.IsCompatibleWithSession(551*COIN));
if(darkSendPool.GetMaxPoolTransactions() >= 4) BOOST_CHECK(darkSendPool.IsCompatibleWithSession(571*COIN));
if(darkSendPool.GetMaxPoolTransactions() >= 5) BOOST_CHECK(darkSendPool.IsCompatibleWithSession(514*COIN));
BOOST_CHECK(darkSendPool.IsCompatibleWithSession(531*COIN) == false);
darkSendPool.unitTest = true;
std::string strReason = "";
BOOST_CHECK(darkSendPool.IsCompatibleWithSession(511*COIN, strReason));
BOOST_CHECK(darkSendPool.IsCompatibleWithSession(131*COIN, strReason) == false);
BOOST_CHECK(darkSendPool.IsCompatibleWithSession(31*COIN, strReason) == false);
BOOST_CHECK(darkSendPool.IsCompatibleWithSession(151*COIN, strReason) == false);
BOOST_CHECK(darkSendPool.IsCompatibleWithSession(751*COIN, strReason) == false);
BOOST_CHECK(darkSendPool.IsCompatibleWithSession(531*COIN, strReason));
if(darkSendPool.GetMaxPoolTransactions() >= 3) BOOST_CHECK(darkSendPool.IsCompatibleWithSession(551*COIN, strReason));
if(darkSendPool.GetMaxPoolTransactions() >= 4) BOOST_CHECK(darkSendPool.IsCompatibleWithSession(571*COIN, strReason));
if(darkSendPool.GetMaxPoolTransactions() >= 5) BOOST_CHECK(darkSendPool.IsCompatibleWithSession(514*COIN, strReason));
BOOST_CHECK(darkSendPool.IsCompatibleWithSession(531*COIN, strReason) == false);
darkSendPool.SetNull();
BOOST_CHECK(darkSendPool.IsCompatibleWithSession(12*COIN));
BOOST_CHECK(darkSendPool.IsCompatibleWithSession(131*COIN) == false);
BOOST_CHECK(darkSendPool.IsCompatibleWithSession(151*COIN) == false);
BOOST_CHECK(darkSendPool.IsCompatibleWithSession(751*COIN) == false);
BOOST_CHECK(darkSendPool.IsCompatibleWithSession(34*COIN));
if(darkSendPool.GetMaxPoolTransactions() >= 3) BOOST_CHECK(darkSendPool.IsCompatibleWithSession(22*COIN));
if(darkSendPool.GetMaxPoolTransactions() >= 4) BOOST_CHECK(darkSendPool.IsCompatibleWithSession(32*COIN));
if(darkSendPool.GetMaxPoolTransactions() >= 5) BOOST_CHECK(darkSendPool.IsCompatibleWithSession(44*COIN));
BOOST_CHECK(darkSendPool.IsCompatibleWithSession(33*COIN) == false);
BOOST_CHECK(darkSendPool.IsCompatibleWithSession(12*COIN, strReason));
BOOST_CHECK(darkSendPool.IsCompatibleWithSession(131*COIN, strReason) == false);
BOOST_CHECK(darkSendPool.IsCompatibleWithSession(151*COIN, strReason) == false);
BOOST_CHECK(darkSendPool.IsCompatibleWithSession(751*COIN, strReason) == false);
BOOST_CHECK(darkSendPool.IsCompatibleWithSession(34*COIN, strReason));
if(darkSendPool.GetMaxPoolTransactions() >= 3) BOOST_CHECK(darkSendPool.IsCompatibleWithSession(22*COIN, strReason));
if(darkSendPool.GetMaxPoolTransactions() >= 4) BOOST_CHECK(darkSendPool.IsCompatibleWithSession(32*COIN, strReason));
if(darkSendPool.GetMaxPoolTransactions() >= 5) BOOST_CHECK(darkSendPool.IsCompatibleWithSession(44*COIN, strReason));
BOOST_CHECK(darkSendPool.IsCompatibleWithSession(33*COIN, strReason) == false);
}
BOOST_AUTO_TEST_CASE(darksend_masternode_voting)
{
uint256 n1 = 10000;
uint256 n2 = 10001;
CTxIn fromMn1 = CTxIn(n2, 0);
CTxIn testVin1 = CTxIn(n1, 0);
CTxIn testVin2 = CTxIn(n2, 0);
CService addr;
int i = 0;
std::vector<unsigned char> vchSig;
CScript payee = CScript();
//setup a couple fake masternodes
CMasterNode mn1(addr, testVin1, CPubKey(), vchSig, 0, CPubKey());
darkSendMasterNodes.push_back(mn1);
CMasterNode mn2(addr, testVin2, CPubKey(), vchSig, 0, CPubKey());
darkSendMasterNodes.push_back(mn2);
darkSendPool.unitTest = true;
// return -1 if nothing present
BOOST_CHECK(darkSendPool.GetCurrentMasterNodeConsessus(1000, payee) == false);
//block 1000
for(i = 0; i <= 2; i++)
darkSendPool.SubmitMasternodeVote(testVin1, fromMn1,1000);
// not enough votes
BOOST_CHECK(darkSendPool.GetCurrentMasterNodeConsessus(1000, payee) == false); //
for(i = 0; i <= 4; i++)
darkSendPool.SubmitMasternodeVote(testVin2, fromMn1, 1000);
// not enough votes
BOOST_CHECK(darkSendPool.GetCurrentMasterNodeConsessus(1000, payee) == false); //
for(i = 0; i <= 4; i++)
darkSendPool.SubmitMasternodeVote(testVin2, fromMn1, 1000);
// should have 8 votes now
BOOST_CHECK(darkSendPool.GetCurrentMasterNodeConsessus(1000, payee) == true); // vin2
}
BOOST_AUTO_TEST_CASE(darksend_masternode_search_by_vin)
{
uint256 n1 = 10000;