mirror of
https://github.com/dashpay/dash.git
synced 2024-12-27 13:03:17 +01:00
unit tests and sanity checks
This commit is contained in:
parent
50fad9e08e
commit
f2072c3c89
@ -1511,13 +1511,15 @@ bool CDarkSendPool::IsCompatibleWithSession(int64 nAmount, std::string& strReaso
|
|||||||
sessionUsers++;
|
sessionUsers++;
|
||||||
lastTimeChanged = GetTimeMillis();
|
lastTimeChanged = GetTimeMillis();
|
||||||
|
|
||||||
//broadcast that I'm accepting entries, only if it's the first entry though
|
if(!unitTest){
|
||||||
CDarksendQueue dsq;
|
//broadcast that I'm accepting entries, only if it's the first entry though
|
||||||
dsq.nDenom = GetDenominationsByAmount(nAmount);
|
CDarksendQueue dsq;
|
||||||
dsq.vin = vinMasterNode;
|
dsq.nDenom = GetDenominationsByAmount(nAmount);
|
||||||
dsq.time = GetTime();
|
dsq.vin = vinMasterNode;
|
||||||
dsq.Sign();
|
dsq.time = GetTime();
|
||||||
dsq.Relay();
|
dsq.Sign();
|
||||||
|
dsq.Relay();
|
||||||
|
}
|
||||||
|
|
||||||
UpdateState(POOL_STATUS_QUEUE);
|
UpdateState(POOL_STATUS_QUEUE);
|
||||||
|
|
||||||
|
@ -379,6 +379,11 @@ public:
|
|||||||
return POOL_MAX_TRANSACTIONS;
|
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?
|
// Are these outputs compatible with other client in the pool?
|
||||||
bool IsCompatibleWithEntries(std::vector<CTxOut> vout);
|
bool IsCompatibleWithEntries(std::vector<CTxOut> vout);
|
||||||
|
28
src/main.cpp
28
src/main.cpp
@ -3962,6 +3962,10 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!fMasterNode){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<CTxIn> in;
|
std::vector<CTxIn> in;
|
||||||
int64 nAmount;
|
int64 nAmount;
|
||||||
CTransaction txCollateral;
|
CTransaction txCollateral;
|
||||||
@ -3970,26 +3974,22 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
|
|||||||
|
|
||||||
std::string error = "";
|
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");
|
LogPrintf("dsi -- not compatible with existing transactions! \n");
|
||||||
error = "not compatible with existing transactions";
|
error = "not compatible with existing transactions";
|
||||||
pfrom->PushMessage("dssu", darkSendPool.sessionID, darkSendPool.GetState(), darkSendPool.GetEntriesCount(), MASTERNODE_REJECTED, error);
|
pfrom->PushMessage("dssu", darkSendPool.sessionID, darkSendPool.GetState(), darkSendPool.GetEntriesCount(), MASTERNODE_REJECTED, error);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
or
|
|
||||||
|
|
||||||
if(GetDenominationByAmount(sessionAmount) != GetDenominationByAmount(nAmount)){
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
also
|
|
||||||
|
|
||||||
if(entries.size() == 0 && GetDenominationByAmount(sessionAmount) != GetDenominationByAmount(nAmount)) {
|
|
||||||
sessionAmount = nAmount;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
//check it like a transaction
|
//check it like a transaction
|
||||||
{
|
{
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
#include "base58.h"
|
#include "base58.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
#include "darksend.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
@ -108,77 +109,34 @@ BOOST_AUTO_TEST_CASE(darksend_denom)
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(darksend_session)
|
BOOST_AUTO_TEST_CASE(darksend_session)
|
||||||
{
|
{
|
||||||
BOOST_CHECK(darkSendPool.IsCompatibleWithSession(511*COIN));
|
darkSendPool.unitTest = true;
|
||||||
BOOST_CHECK(darkSendPool.IsCompatibleWithSession(131*COIN) == false);
|
|
||||||
BOOST_CHECK(darkSendPool.IsCompatibleWithSession(31*COIN) == false);
|
std::string strReason = "";
|
||||||
BOOST_CHECK(darkSendPool.IsCompatibleWithSession(151*COIN) == false);
|
BOOST_CHECK(darkSendPool.IsCompatibleWithSession(511*COIN, strReason));
|
||||||
BOOST_CHECK(darkSendPool.IsCompatibleWithSession(751*COIN) == false);
|
BOOST_CHECK(darkSendPool.IsCompatibleWithSession(131*COIN, strReason) == false);
|
||||||
BOOST_CHECK(darkSendPool.IsCompatibleWithSession(531*COIN));
|
BOOST_CHECK(darkSendPool.IsCompatibleWithSession(31*COIN, strReason) == false);
|
||||||
if(darkSendPool.GetMaxPoolTransactions() >= 3) BOOST_CHECK(darkSendPool.IsCompatibleWithSession(551*COIN));
|
BOOST_CHECK(darkSendPool.IsCompatibleWithSession(151*COIN, strReason) == false);
|
||||||
if(darkSendPool.GetMaxPoolTransactions() >= 4) BOOST_CHECK(darkSendPool.IsCompatibleWithSession(571*COIN));
|
BOOST_CHECK(darkSendPool.IsCompatibleWithSession(751*COIN, strReason) == false);
|
||||||
if(darkSendPool.GetMaxPoolTransactions() >= 5) BOOST_CHECK(darkSendPool.IsCompatibleWithSession(514*COIN));
|
BOOST_CHECK(darkSendPool.IsCompatibleWithSession(531*COIN, strReason));
|
||||||
BOOST_CHECK(darkSendPool.IsCompatibleWithSession(531*COIN) == false);
|
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();
|
darkSendPool.SetNull();
|
||||||
|
|
||||||
BOOST_CHECK(darkSendPool.IsCompatibleWithSession(12*COIN));
|
BOOST_CHECK(darkSendPool.IsCompatibleWithSession(12*COIN, strReason));
|
||||||
BOOST_CHECK(darkSendPool.IsCompatibleWithSession(131*COIN) == false);
|
BOOST_CHECK(darkSendPool.IsCompatibleWithSession(131*COIN, strReason) == false);
|
||||||
BOOST_CHECK(darkSendPool.IsCompatibleWithSession(151*COIN) == false);
|
BOOST_CHECK(darkSendPool.IsCompatibleWithSession(151*COIN, strReason) == false);
|
||||||
BOOST_CHECK(darkSendPool.IsCompatibleWithSession(751*COIN) == false);
|
BOOST_CHECK(darkSendPool.IsCompatibleWithSession(751*COIN, strReason) == false);
|
||||||
BOOST_CHECK(darkSendPool.IsCompatibleWithSession(34*COIN));
|
BOOST_CHECK(darkSendPool.IsCompatibleWithSession(34*COIN, strReason));
|
||||||
if(darkSendPool.GetMaxPoolTransactions() >= 3) BOOST_CHECK(darkSendPool.IsCompatibleWithSession(22*COIN));
|
if(darkSendPool.GetMaxPoolTransactions() >= 3) BOOST_CHECK(darkSendPool.IsCompatibleWithSession(22*COIN, strReason));
|
||||||
if(darkSendPool.GetMaxPoolTransactions() >= 4) BOOST_CHECK(darkSendPool.IsCompatibleWithSession(32*COIN));
|
if(darkSendPool.GetMaxPoolTransactions() >= 4) BOOST_CHECK(darkSendPool.IsCompatibleWithSession(32*COIN, strReason));
|
||||||
if(darkSendPool.GetMaxPoolTransactions() >= 5) BOOST_CHECK(darkSendPool.IsCompatibleWithSession(44*COIN));
|
if(darkSendPool.GetMaxPoolTransactions() >= 5) BOOST_CHECK(darkSendPool.IsCompatibleWithSession(44*COIN, strReason));
|
||||||
BOOST_CHECK(darkSendPool.IsCompatibleWithSession(33*COIN) == false);
|
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)
|
BOOST_AUTO_TEST_CASE(darksend_masternode_search_by_vin)
|
||||||
{
|
{
|
||||||
uint256 n1 = 10000;
|
uint256 n1 = 10000;
|
||||||
|
Loading…
Reference in New Issue
Block a user