mirror of
https://github.com/dashpay/dash.git
synced 2024-12-29 13:59:06 +01:00
fixed unit tests
This commit is contained in:
parent
419d605239
commit
ec9cfc1289
30
src/main.cpp
30
src/main.cpp
@ -5872,15 +5872,17 @@ void CDarkSendPool::SetNull(){
|
||||
UnlockCoins();
|
||||
}
|
||||
|
||||
void CDarkSendPool::SetCollateralAddress(std::string strAddress){
|
||||
bool CDarkSendPool::SetCollateralAddress(std::string strAddress){
|
||||
CBitcoinAddress address;
|
||||
if (!address.SetString(strAddress))
|
||||
{
|
||||
printf("CDarkSendPool::SetCollateralAddress - Invalid DarkSend collateral address\n");
|
||||
|
||||
return false;
|
||||
}
|
||||
collateralPubKey.SetDestination(address.Get());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void CDarkSendPool::UnlockCoins(){
|
||||
BOOST_FOREACH(CTxIn v, lockedCoins)
|
||||
pwalletMain->UnlockCoin(v.prevout);
|
||||
@ -6925,10 +6927,12 @@ bool CDarkSendPool::GetCurrentMasterNodeConsessus(int64 blockHeight, CScript& pa
|
||||
printf("MasternodeConsessus - found a winner\n");
|
||||
|
||||
// we want a strong consessus, otherwise take any payee
|
||||
//if (winner_votes < 8) return CScript();
|
||||
if (winner_votes < 8) return false;
|
||||
|
||||
printf("MasternodeConsessus - strong consessus\n");
|
||||
|
||||
if (unitTest) return true;
|
||||
|
||||
CTransaction tx;
|
||||
uint256 hash;
|
||||
if(GetTransaction(winner_vin.prevout.hash, tx, hash, true)){
|
||||
@ -7001,15 +7005,17 @@ void CMasterNode::Check()
|
||||
return;
|
||||
}
|
||||
|
||||
CValidationState state;
|
||||
CTransaction tx = CTransaction();
|
||||
CTxOut vout = CTxOut(999.99*COIN, darkSendPool.collateralPubKey);
|
||||
tx.vin.push_back(vin);
|
||||
tx.vout.push_back(vout);
|
||||
if(!unitTest){
|
||||
CValidationState state;
|
||||
CTransaction tx = CTransaction();
|
||||
CTxOut vout = CTxOut(999.99*COIN, darkSendPool.collateralPubKey);
|
||||
tx.vin.push_back(vin);
|
||||
tx.vout.push_back(vout);
|
||||
|
||||
if(!tx.AcceptableInputs(state, true)) {
|
||||
enabled = 3;
|
||||
return;
|
||||
if(!tx.AcceptableInputs(state, true)) {
|
||||
enabled = 3;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
enabled = 1; // OK
|
||||
|
@ -2451,6 +2451,7 @@ public:
|
||||
std::vector<unsigned char> sig;
|
||||
int64 now;
|
||||
int enabled;
|
||||
bool unitTest;
|
||||
|
||||
CMasterNode(CService newAddr, CTxIn newVin, CPubKey newPubkey, std::vector<unsigned char> newSig, int64 newNow, CPubKey newPubkey2)
|
||||
{
|
||||
@ -2462,7 +2463,7 @@ public:
|
||||
now = newNow;
|
||||
enabled = 1;
|
||||
lastTimeSeen = 0;
|
||||
|
||||
unitTest = false;
|
||||
}
|
||||
|
||||
uint256 CalculateScore(int mod=10, int64 nBlockHeight=0);
|
||||
@ -2609,6 +2610,8 @@ public:
|
||||
std::string lastMessage;
|
||||
bool completedTransaction;
|
||||
|
||||
bool unitTest;
|
||||
|
||||
CDarkSendPool()
|
||||
{
|
||||
//printf("CDarkSendPool::INIT()\n");
|
||||
@ -2624,12 +2627,13 @@ public:
|
||||
|
||||
isCapableMasterNode = MASTERNODE_NOT_PROCESSED;
|
||||
masternodePortOpen = 0;
|
||||
unitTest = false;
|
||||
|
||||
SetCollateralAddress(strAddress);
|
||||
SetNull();
|
||||
}
|
||||
|
||||
void SetCollateralAddress(std::string strAddress);
|
||||
bool SetCollateralAddress(std::string strAddress);
|
||||
void SetNull();
|
||||
|
||||
void UnlockCoins();
|
||||
|
@ -79,6 +79,8 @@ BOOST_AUTO_TEST_CASE(darksend_masternode_voting)
|
||||
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);
|
||||
@ -86,27 +88,29 @@ BOOST_AUTO_TEST_CASE(darksend_masternode_voting)
|
||||
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) == -1);
|
||||
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) == -1); //
|
||||
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) == -1); //
|
||||
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) == 1); // vin2
|
||||
BOOST_CHECK(darkSendPool.GetCurrentMasterNodeConsessus(1000, payee) == true); // vin2
|
||||
}
|
||||
|
||||
|
||||
@ -152,11 +156,11 @@ BOOST_AUTO_TEST_CASE(darksend_add_entry)
|
||||
BOOST_CHECK(e.sev.size() == 2);
|
||||
|
||||
//sign one of the vin
|
||||
BOOST_CHECK(e.AddSig(CScript(), CScript(), CTxIn(1001, 0)) == true);
|
||||
BOOST_CHECK(e.AddSig(CScript(), CScript(), CTxIn(1001, 0)) == false);
|
||||
BOOST_CHECK(e.AddSig(CTxIn(1001, 0)) == true);
|
||||
BOOST_CHECK(e.AddSig(CTxIn(1001, 0)) == false);
|
||||
|
||||
//sign non-existant
|
||||
BOOST_CHECK(e.AddSig(CScript(), CScript(), CTxIn(9999001, 0)) == false);
|
||||
BOOST_CHECK(e.AddSig(CTxIn(9999001, 0)) == false);
|
||||
|
||||
}
|
||||
|
||||
@ -169,9 +173,10 @@ BOOST_AUTO_TEST_CASE(darksend_masternode_class)
|
||||
int64 newNow = GetTimeMicros();
|
||||
|
||||
CMasterNode mn(CService("10.10.10.10:9999"), CTxIn(1000, 0), pubkey, newSig, newNow, pubkey);
|
||||
mn.unitTest = true;
|
||||
mn.UpdateLastSeen();
|
||||
mn.Check();
|
||||
BOOST_CHECK(mn.enabled == 3); // bad vin
|
||||
BOOST_CHECK(mn.enabled == 1); // ok
|
||||
mn.lastTimeSeen -= MASTERNODE_EXPIRATION_MICROSECONDS;
|
||||
mn.Check();
|
||||
BOOST_CHECK(mn.enabled == 2); // hasn't pinged
|
||||
@ -215,7 +220,7 @@ BOOST_AUTO_TEST_CASE(darksend_pool_add_entry)
|
||||
BOOST_CHECK(darkSendPool.state == POOL_STATUS_ACCEPTING_ENTRIES);
|
||||
BOOST_CHECK(darkSendPool.entries.size() == 3);
|
||||
darkSendPool.Check();
|
||||
BOOST_CHECK(darkSendPool.state == POOL_STATUS_FINALIZE_TRANSACTION);
|
||||
BOOST_CHECK(darkSendPool.state == POOL_STATUS_SIGNING);
|
||||
BOOST_CHECK(darkSendPool.entries.size() == 3);
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user