Skip to content

Commit

Permalink
Added new details for getstakinginfo error message as suggested in #288
Browse files Browse the repository at this point in the history
… (#472)

* Added new details for getstakinginfo error message as suggested in #288

* Updated the test cases to be more thorough

* Updated variable name as per suggesstion
  • Loading branch information
francisjyap authored and alex v committed May 14, 2019
1 parent aa4bbaa commit 4a62021
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 8 deletions.
1 change: 1 addition & 0 deletions qa/pull-tester/rpc-tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@
'reject-version-bit.py',
'getcoldstakingaddress.py',
'getstakereport.py',
'getstakinginfo.py',
'coldstaking_staking.py',
'coldstaking_spending.py',
'staticr-staking-amount.py',
Expand Down
78 changes: 78 additions & 0 deletions qa/rpc-tests/getstakinginfo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/usr/bin/env python3
# Copyright (c) 2018 The Navcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.

from test_framework.test_framework import NavCoinTestFramework
from test_framework.staticr_util import *

#import time

class GetStakingInfo(NavCoinTestFramework):
"""Tests getstakereport accounting."""

def __init__(self):
super().__init__()
self.setup_clean_chain = True
self.num_nodes = 1

def setup_network(self, split=False):
self.nodes = self.setup_nodes()
self.is_network_split = False

def run_test(self):
# Turn off staking
self.nodes[0].staking(False)

# Check if we get the error for nWeight
assert(not self.nodes[0].getstakinginfo()['enabled'])
assert(not self.nodes[0].getstakinginfo()['staking'])
assert_equal("Warning: We don't appear to have mature coins.", self.nodes[0].getstakinginfo()['errors'])

# Make it to the static rewards fork!
activate_staticr(self.nodes[0])

# Check balance
assert_equal(59814950, self.nodes[0].getwalletinfo()['balance'] + self.nodes[0].getwalletinfo()['immature_balance'])

# Turn on staking
self.nodes[0].staking(True)

# Check for staking after we have matured coins
assert(self.nodes[0].getstakinginfo()['enabled'])
assert(not self.nodes[0].getstakinginfo()['staking'])
assert_equal("", self.nodes[0].getstakinginfo()['errors'])

# Get the current block count to check against while we wait for a stake
blockcount = self.nodes[0].getblockcount()

# wait for a new block to be mined
while self.nodes[0].getblockcount() == blockcount:
print("waiting for a new block...")
time.sleep(1)

# We got one
print("found a new block...")

# Check balance
assert_equal(59814952, self.nodes[0].getwalletinfo()['balance'] + self.nodes[0].getwalletinfo()['immature_balance'])

# Check if we get the error for nWeight again after a stake
assert(self.nodes[0].getstakinginfo()['enabled'])
assert(self.nodes[0].getstakinginfo()['staking'])
assert_equal("", self.nodes[0].getstakinginfo()['errors'])

# LOCK the wallet
self.nodes[0].encryptwallet("password")
stop_nodes(self.nodes)
wait_navcoinds()
self.nodes = start_nodes(self.num_nodes, self.options.tmpdir)

# Check if we get the error for nWeight again after a stake
assert(self.nodes[0].getstakinginfo()['enabled'])
assert(not self.nodes[0].getstakinginfo()['staking'])
assert_equal("Warning: Wallet is locked. Please enter the wallet passphrase with walletpassphrase first.", self.nodes[0].getstakinginfo()['errors'])


if __name__ == '__main__':
GetStakingInfo().main()
36 changes: 29 additions & 7 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2542,7 +2542,7 @@ bool DisconnectBlock(const CBlock& block, CValidationState& state, const CBlockI
} else if (prevout.scriptPubKey.IsPayToPublicKey() || prevout.scriptPubKey.IsColdStaking()) {
uint160 hashBytes;
int type = 0;
CTxDestination destination;
CTxDestination destination;
ExtractDestination(prevout.scriptPubKey, destination);
CNavCoinAddress address(destination);
if (prevout.scriptPubKey.IsColdStaking())
Expand Down Expand Up @@ -6260,6 +6260,11 @@ void static CheckBlockIndex(const Consensus::Params& consensusParams)
}

std::string GetWarnings(const std::string& strFor)
{
return GetWarnings(strFor, false);
}

std::string GetWarnings(const std::string& strFor, bool fForStaking)
{
string strStatusBar;
string strRPC;
Expand All @@ -6275,7 +6280,6 @@ std::string GetWarnings(const std::string& strFor)
strStatusBar = "This is a Release Candidate build - use at your own risk - please make sure your wallet is backed up";
strGUI = _("This is a Release Candidate build - use at your own risk - please make sure your wallet is backed up");
}

}

if (GetBoolArg("-testsafemode", DEFAULT_TESTSAFEMODE))
Expand All @@ -6290,20 +6294,38 @@ std::string GetWarnings(const std::string& strFor)
if (fLargeWorkForkFound)
{
strStatusBar = strRPC = "Warning: The network does not appear to fully agree! Some miners appear to be experiencing issues.";
strGUI = _("Warning: The network does not appear to fully agree! Some miners appear to be experiencing issues.");
strGUI = _(strRPC.c_str());
}
else if (fLargeWorkInvalidChainFound)
{
strStatusBar = strRPC = "Warning: We do not appear to fully agree with our peers! You may need to upgrade, or other nodes may need to upgrade.";
strGUI = _("Warning: We do not appear to fully agree with our peers! You may need to upgrade, or other nodes may need to upgrade.");
strGUI = _(strRPC.c_str());
}

if (fForStaking)
{
if (pwalletMain->IsLocked())
{
strStatusBar = strRPC = "Warning: Wallet is locked. Please enter the wallet passphrase with walletpassphrase first.";
strGUI = _(strRPC.c_str());
}

if (!pwalletMain->GetStakeWeight())
{
strStatusBar = strRPC = "Warning: We don't appear to have mature coins.";
strGUI = _(strRPC.c_str());
}
}

if (strFor == "gui")
return strGUI;
else if (strFor == "statusbar")

if (strFor == "statusbar")
return strStatusBar;
else if (strFor == "rpc")

if (strFor == "rpc")
return strRPC;

assert(!"GetWarnings(): invalid parameter");
return "error";
}
Expand Down Expand Up @@ -7120,7 +7142,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
CTransaction tx;
vRecv >> tx;

LogPrint("net", "Received tx %s peer=%d\n%s\n", tx.GetHash().ToString(), pfrom->id, tx.ToString());
LogPrint("net", "Received tx %s peer=%d\n%s\n", tx.GetHash().ToString(), pfrom->id, tx.ToString());

CInv inv(MSG_TX, tx.GetHash());
pfrom->AddInventoryKnown(inv);
Expand Down
1 change: 1 addition & 0 deletions src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ bool IsInitialBlockDownload();
* This function only returns the highest priority warning of the set selected by strFor.
*/
std::string GetWarnings(const std::string& strFor);
std::string GetWarnings(const std::string& strFor, bool fForStaking);
/** Retrieve a transaction (from memory pool, or from disk, if possible) */
bool GetTransaction(const uint256 &hash, CTransaction &tx, const Consensus::Params& params, uint256 &hashBlock, bool fAllowSlow = false);
/** Find the best known block, and make it the tip of the block chain */
Expand Down
2 changes: 1 addition & 1 deletion src/rpc/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ UniValue getstakinginfo(const UniValue& params, bool fHelp)

obj.push_back(Pair("enabled", GetStaking()));
obj.push_back(Pair("staking", staking));
obj.push_back(Pair("errors", GetWarnings("statusbar")));
obj.push_back(Pair("errors", GetWarnings("statusbar", true)));

obj.push_back(Pair("currentblocksize", (uint64_t)nLastBlockSize));
obj.push_back(Pair("currentblocktx", (uint64_t)nLastBlockTx));
Expand Down

0 comments on commit 4a62021

Please sign in to comment.