Skip to content

Commit 4a62021

Browse files
digitalotenalex v
authored andcommitted
Added new details for getstakinginfo error message as suggested in #288 (#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
1 parent aa4bbaa commit 4a62021

File tree

5 files changed

+110
-8
lines changed

5 files changed

+110
-8
lines changed

qa/pull-tester/rpc-tests.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@
169169
'reject-version-bit.py',
170170
'getcoldstakingaddress.py',
171171
'getstakereport.py',
172+
'getstakinginfo.py',
172173
'coldstaking_staking.py',
173174
'coldstaking_spending.py',
174175
'staticr-staking-amount.py',

qa/rpc-tests/getstakinginfo.py

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#!/usr/bin/env python3
2+
# Copyright (c) 2018 The Navcoin Core developers
3+
# Distributed under the MIT software license, see the accompanying
4+
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
5+
6+
from test_framework.test_framework import NavCoinTestFramework
7+
from test_framework.staticr_util import *
8+
9+
#import time
10+
11+
class GetStakingInfo(NavCoinTestFramework):
12+
"""Tests getstakereport accounting."""
13+
14+
def __init__(self):
15+
super().__init__()
16+
self.setup_clean_chain = True
17+
self.num_nodes = 1
18+
19+
def setup_network(self, split=False):
20+
self.nodes = self.setup_nodes()
21+
self.is_network_split = False
22+
23+
def run_test(self):
24+
# Turn off staking
25+
self.nodes[0].staking(False)
26+
27+
# Check if we get the error for nWeight
28+
assert(not self.nodes[0].getstakinginfo()['enabled'])
29+
assert(not self.nodes[0].getstakinginfo()['staking'])
30+
assert_equal("Warning: We don't appear to have mature coins.", self.nodes[0].getstakinginfo()['errors'])
31+
32+
# Make it to the static rewards fork!
33+
activate_staticr(self.nodes[0])
34+
35+
# Check balance
36+
assert_equal(59814950, self.nodes[0].getwalletinfo()['balance'] + self.nodes[0].getwalletinfo()['immature_balance'])
37+
38+
# Turn on staking
39+
self.nodes[0].staking(True)
40+
41+
# Check for staking after we have matured coins
42+
assert(self.nodes[0].getstakinginfo()['enabled'])
43+
assert(not self.nodes[0].getstakinginfo()['staking'])
44+
assert_equal("", self.nodes[0].getstakinginfo()['errors'])
45+
46+
# Get the current block count to check against while we wait for a stake
47+
blockcount = self.nodes[0].getblockcount()
48+
49+
# wait for a new block to be mined
50+
while self.nodes[0].getblockcount() == blockcount:
51+
print("waiting for a new block...")
52+
time.sleep(1)
53+
54+
# We got one
55+
print("found a new block...")
56+
57+
# Check balance
58+
assert_equal(59814952, self.nodes[0].getwalletinfo()['balance'] + self.nodes[0].getwalletinfo()['immature_balance'])
59+
60+
# Check if we get the error for nWeight again after a stake
61+
assert(self.nodes[0].getstakinginfo()['enabled'])
62+
assert(self.nodes[0].getstakinginfo()['staking'])
63+
assert_equal("", self.nodes[0].getstakinginfo()['errors'])
64+
65+
# LOCK the wallet
66+
self.nodes[0].encryptwallet("password")
67+
stop_nodes(self.nodes)
68+
wait_navcoinds()
69+
self.nodes = start_nodes(self.num_nodes, self.options.tmpdir)
70+
71+
# Check if we get the error for nWeight again after a stake
72+
assert(self.nodes[0].getstakinginfo()['enabled'])
73+
assert(not self.nodes[0].getstakinginfo()['staking'])
74+
assert_equal("Warning: Wallet is locked. Please enter the wallet passphrase with walletpassphrase first.", self.nodes[0].getstakinginfo()['errors'])
75+
76+
77+
if __name__ == '__main__':
78+
GetStakingInfo().main()

src/main.cpp

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2542,7 +2542,7 @@ bool DisconnectBlock(const CBlock& block, CValidationState& state, const CBlockI
25422542
} else if (prevout.scriptPubKey.IsPayToPublicKey() || prevout.scriptPubKey.IsColdStaking()) {
25432543
uint160 hashBytes;
25442544
int type = 0;
2545-
CTxDestination destination;
2545+
CTxDestination destination;
25462546
ExtractDestination(prevout.scriptPubKey, destination);
25472547
CNavCoinAddress address(destination);
25482548
if (prevout.scriptPubKey.IsColdStaking())
@@ -6260,6 +6260,11 @@ void static CheckBlockIndex(const Consensus::Params& consensusParams)
62606260
}
62616261

62626262
std::string GetWarnings(const std::string& strFor)
6263+
{
6264+
return GetWarnings(strFor, false);
6265+
}
6266+
6267+
std::string GetWarnings(const std::string& strFor, bool fForStaking)
62636268
{
62646269
string strStatusBar;
62656270
string strRPC;
@@ -6275,7 +6280,6 @@ std::string GetWarnings(const std::string& strFor)
62756280
strStatusBar = "This is a Release Candidate build - use at your own risk - please make sure your wallet is backed up";
62766281
strGUI = _("This is a Release Candidate build - use at your own risk - please make sure your wallet is backed up");
62776282
}
6278-
62796283
}
62806284

62816285
if (GetBoolArg("-testsafemode", DEFAULT_TESTSAFEMODE))
@@ -6290,20 +6294,38 @@ std::string GetWarnings(const std::string& strFor)
62906294
if (fLargeWorkForkFound)
62916295
{
62926296
strStatusBar = strRPC = "Warning: The network does not appear to fully agree! Some miners appear to be experiencing issues.";
6293-
strGUI = _("Warning: The network does not appear to fully agree! Some miners appear to be experiencing issues.");
6297+
strGUI = _(strRPC.c_str());
62946298
}
62956299
else if (fLargeWorkInvalidChainFound)
62966300
{
62976301
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.";
6298-
strGUI = _("Warning: We do not appear to fully agree with our peers! You may need to upgrade, or other nodes may need to upgrade.");
6302+
strGUI = _(strRPC.c_str());
6303+
}
6304+
6305+
if (fForStaking)
6306+
{
6307+
if (pwalletMain->IsLocked())
6308+
{
6309+
strStatusBar = strRPC = "Warning: Wallet is locked. Please enter the wallet passphrase with walletpassphrase first.";
6310+
strGUI = _(strRPC.c_str());
6311+
}
6312+
6313+
if (!pwalletMain->GetStakeWeight())
6314+
{
6315+
strStatusBar = strRPC = "Warning: We don't appear to have mature coins.";
6316+
strGUI = _(strRPC.c_str());
6317+
}
62996318
}
63006319

63016320
if (strFor == "gui")
63026321
return strGUI;
6303-
else if (strFor == "statusbar")
6322+
6323+
if (strFor == "statusbar")
63046324
return strStatusBar;
6305-
else if (strFor == "rpc")
6325+
6326+
if (strFor == "rpc")
63066327
return strRPC;
6328+
63076329
assert(!"GetWarnings(): invalid parameter");
63086330
return "error";
63096331
}
@@ -7120,7 +7142,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
71207142
CTransaction tx;
71217143
vRecv >> tx;
71227144

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

71257147
CInv inv(MSG_TX, tx.GetHash());
71267148
pfrom->AddInventoryKnown(inv);

src/main.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ bool IsInitialBlockDownload();
289289
* This function only returns the highest priority warning of the set selected by strFor.
290290
*/
291291
std::string GetWarnings(const std::string& strFor);
292+
std::string GetWarnings(const std::string& strFor, bool fForStaking);
292293
/** Retrieve a transaction (from memory pool, or from disk, if possible) */
293294
bool GetTransaction(const uint256 &hash, CTransaction &tx, const Consensus::Params& params, uint256 &hashBlock, bool fAllowSlow = false);
294295
/** Find the best known block, and make it the tip of the block chain */

src/rpc/net.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ UniValue getstakinginfo(const UniValue& params, bool fHelp)
649649

650650
obj.push_back(Pair("enabled", GetStaking()));
651651
obj.push_back(Pair("staking", staking));
652-
obj.push_back(Pair("errors", GetWarnings("statusbar")));
652+
obj.push_back(Pair("errors", GetWarnings("statusbar", true)));
653653

654654
obj.push_back(Pair("currentblocksize", (uint64_t)nLastBlockSize));
655655
obj.push_back(Pair("currentblocktx", (uint64_t)nLastBlockTx));

0 commit comments

Comments
 (0)