Skip to content

Commit cc8e213

Browse files
Merge pull request #334 from aguycalled/cfund-rpc
Community Fund RPC commands
2 parents 210a22d + 9a607b0 commit cc8e213

File tree

7 files changed

+274
-62
lines changed

7 files changed

+274
-62
lines changed

qa/pull-tester/rpc-tests.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@
157157
'cfund-rawtx-paymentrequest-vote.py',
158158
'cfund-rawtx-proposal-vote.py',
159159
'cfund-vote.py',
160+
'cfund-proposalvotelist.py',
161+
'cfund-paymentrequestvotelist.py',
160162
'reject-version-bit.py',
161163
'staticr-staking-amount.py',
162164

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
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.cfund_util import *
8+
9+
import time
10+
11+
class CommunityFundPaymentRequestVoteListTest(NavCoinTestFramework):
12+
"""Tests the paymentrequestvotelist function of the Community fund."""
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 = split
22+
23+
def run_test(self):
24+
# Make sure cfund is active
25+
activate_cfund(self.nodes[0])
26+
self.nodes[0].donatefund(1000)
27+
28+
address0 = self.nodes[0].getnewaddress()
29+
30+
# Set up 2 proposals
31+
proposalid0 = self.nodes[0].createproposal(address0, 100, 3600, "test0")["hash"]
32+
proposalid1 = self.nodes[0].createproposal(address0, 100, 3600, "test1")["hash"]
33+
start_new_cycle(self.nodes[0])
34+
35+
# Vote yes and pass proposals
36+
self.nodes[0].proposalvote(proposalid0, "yes")
37+
self.nodes[0].proposalvote(proposalid1, "yes")
38+
start_new_cycle(self.nodes[0])
39+
40+
# Preflight checks
41+
assert(len(self.nodes[0].paymentrequestvotelist()["yes"]) == 0)
42+
assert(len(self.nodes[0].paymentrequestvotelist()["no"]) == 0)
43+
assert(len(self.nodes[0].paymentrequestvotelist()["null"]) == 0)
44+
45+
# Create payment requests
46+
preqid0_a = self.nodes[0].createpaymentrequest(proposalid0, 1, "preq0_a")["hash"]
47+
preqid0_b = self.nodes[0].createpaymentrequest(proposalid0, 1, "preq0_b")["hash"]
48+
preqid1_c = self.nodes[0].createpaymentrequest(proposalid1, 10, "preq1_c")["hash"]
49+
slow_gen(self.nodes[0], 1)
50+
51+
# Verify the payment requests are now in the payment request vote list
52+
assert(len(self.nodes[0].paymentrequestvotelist()["yes"]) == 0)
53+
assert(len(self.nodes[0].paymentrequestvotelist()["no"]) == 0)
54+
assert(len(self.nodes[0].paymentrequestvotelist()["null"]) == 3)
55+
56+
# Vote on the payment requests as wished
57+
self.nodes[0].paymentrequestvote(preqid0_a, "yes")
58+
self.nodes[0].paymentrequestvote(preqid0_b, "no")
59+
self.nodes[0].paymentrequestvote(preqid1_c, "yes")
60+
self.nodes[0].paymentrequestvote(preqid1_c, "remove")
61+
62+
# Verify the payment request vote list has changed according to the wallet's votes
63+
assert(len(self.nodes[0].paymentrequestvotelist()["yes"]) == 1)
64+
assert(len(self.nodes[0].paymentrequestvotelist()["no"]) == 1)
65+
assert(len(self.nodes[0].paymentrequestvotelist()["null"]) == 1)
66+
67+
# Verify the hashes are contained in the output vote list
68+
assert("hash=" + preqid0_a in self.nodes[0].paymentrequestvotelist()["yes"][0])
69+
assert("hash=" + preqid0_b in self.nodes[0].paymentrequestvotelist()["no"][0])
70+
assert("hash=" + preqid1_c in self.nodes[0].paymentrequestvotelist()["null"][0])
71+
72+
# Revote differently
73+
self.nodes[0].paymentrequestvote(preqid0_a, "no")
74+
self.nodes[0].paymentrequestvote(preqid0_b, "yes")
75+
self.nodes[0].paymentrequestvote(preqid1_c, "no")
76+
77+
# Verify the payment request vote list has changed according to the wallet's votes
78+
assert(len(self.nodes[0].paymentrequestvotelist()["yes"]) == 1)
79+
assert(len(self.nodes[0].paymentrequestvotelist()["no"]) == 2)
80+
assert(len(self.nodes[0].paymentrequestvotelist()["null"]) == 0)
81+
82+
83+
# Create new payment request
84+
preq0_d = self.nodes[0].createpaymentrequest(proposalid0, 1, "preq0_d")["hash"]
85+
slow_gen(self.nodes[0], 1)
86+
87+
# Check the new payment request has been added to "null" of payment request vote list
88+
assert(len(self.nodes[0].paymentrequestvotelist()["null"]) == 1)
89+
assert("hash=" + preq0_d in self.nodes[0].paymentrequestvotelist()["null"][0])
90+
91+
92+
if __name__ == '__main__':
93+
CommunityFundPaymentRequestVoteListTest().main()
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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.cfund_util import *
8+
9+
import time
10+
11+
class CommunityFundProposalVoteListTest(NavCoinTestFramework):
12+
"""Tests the proposalvotelist function of the Community fund."""
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 = split
22+
23+
def run_test(self):
24+
# Make sure cfund is active
25+
activate_cfund(self.nodes[0])
26+
self.nodes[0].donatefund(1000)
27+
28+
# Preflight checks
29+
assert(len(self.nodes[0].proposalvotelist()["yes"]) == 0)
30+
assert(len(self.nodes[0].proposalvotelist()["no"]) == 0)
31+
assert(len(self.nodes[0].proposalvotelist()["null"]) == 0)
32+
33+
address0 = self.nodes[0].getnewaddress()
34+
35+
# Create 3 proposals
36+
proposalid0 = self.nodes[0].createproposal(address0, 1, 3600, "test0")["hash"]
37+
proposalid1 = self.nodes[0].createproposal(address0, 1, 3600, "test1")["hash"]
38+
proposalid2 = self.nodes[0].createproposal(address0, 1, 3600, "test2")["hash"]
39+
slow_gen(self.nodes[0], 1)
40+
41+
# Verify the proposals are now in the proposal vote list
42+
assert(len(self.nodes[0].proposalvotelist()["yes"]) == 0)
43+
assert(len(self.nodes[0].proposalvotelist()["no"]) == 0)
44+
assert(len(self.nodes[0].proposalvotelist()["null"]) == 3)
45+
46+
# Vote on the proposals as wished
47+
self.nodes[0].proposalvote(proposalid0, "yes")
48+
self.nodes[0].proposalvote(proposalid1, "no")
49+
self.nodes[0].proposalvote(proposalid2, "yes")
50+
self.nodes[0].proposalvote(proposalid2, "remove")
51+
52+
# Verify the proposal vote list has changed according to the wallet's votes
53+
assert(len(self.nodes[0].proposalvotelist()["yes"]) == 1)
54+
assert(len(self.nodes[0].proposalvotelist()["no"]) == 1)
55+
assert(len(self.nodes[0].proposalvotelist()["null"]) == 1)
56+
57+
# Verify the hashes are contained in the output vote list
58+
assert("hash=" + proposalid0 in self.nodes[0].proposalvotelist()["yes"][0])
59+
assert("hash=" + proposalid1 in self.nodes[0].proposalvotelist()["no"][0])
60+
assert("hash=" + proposalid2 in self.nodes[0].proposalvotelist()["null"][0])
61+
62+
# Revote differently
63+
self.nodes[0].proposalvote(proposalid0, "no")
64+
self.nodes[0].proposalvote(proposalid1, "yes")
65+
self.nodes[0].proposalvote(proposalid2, "no")
66+
67+
# Verify the proposal vote list has changed according to the wallet's votes
68+
assert(len(self.nodes[0].proposalvotelist()["yes"]) == 1)
69+
assert(len(self.nodes[0].proposalvotelist()["no"]) == 2)
70+
assert(len(self.nodes[0].proposalvotelist()["null"]) == 0)
71+
72+
73+
# Create new proposal
74+
proposalid3 = self.nodes[0].createproposal(address0, 1, 3600, "test3")["hash"]
75+
slow_gen(self.nodes[0], 1)
76+
77+
# Check the new proposal has been added to "null" of proposal vote list
78+
assert(len(self.nodes[0].proposalvotelist()["null"]) == 1)
79+
assert("hash=" + proposalid3 in self.nodes[0].proposalvotelist()["null"][0])
80+
81+
82+
if __name__ == '__main__':
83+
CommunityFundProposalVoteListTest().main()

qa/rpc-tests/cfund-vote.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,9 @@ def setup_network(self, split=False):
2121
self.is_network_split = split
2222

2323
def run_test(self):
24-
slow_gen(self.nodes[0], 100)
25-
# Verify the Community Fund is started
26-
assert(self.nodes[0].getblockchaininfo()["bip9_softforks"]["communityfund"]["status"] == "started")
27-
28-
slow_gen(self.nodes[0], 100)
29-
# Verify the Community Fund is locked_in
30-
assert(self.nodes[0].getblockchaininfo()["bip9_softforks"]["communityfund"]["status"] == "locked_in")
31-
32-
slow_gen(self.nodes[0], 100)
33-
# Verify the Community Fund is active
34-
assert(self.nodes[0].getblockchaininfo()["bip9_softforks"]["communityfund"]["status"] == "active")
24+
# Make sure cfund is active
25+
activate_cfund(self.nodes[0])
26+
self.nodes[0].donatefund(1000)
3527

3628
proposalid0 = self.nodes[0].createproposal(self.nodes[0].getnewaddress(), 1, 3600, "test")["hash"]
3729
slow_gen(self.nodes[0], 1)

src/consensus/cfund.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ class CPaymentRequest
112112
std::string ToString() const {
113113
return strprintf("CPaymentRequest(hash=%s, nVersion=%d, nAmount=%f, fState=%s, nVotesYes=%u, nVotesNo=%u, nVotingCycle=%u, "
114114
" proposalhash=%s, blockhash=%s, paymenthash=%s, strDZeel=%s)",
115-
hash.ToString().substr(0,10), nVersion, (float)nAmount/COIN, GetState(), nVotesYes, nVotesNo,
116-
nVotingCycle, proposalhash.ToString().substr(0,10), blockhash.ToString().substr(0,10),
115+
hash.ToString(), nVersion, (float)nAmount/COIN, GetState(), nVotesYes, nVotesNo,
116+
nVotingCycle, proposalhash.ToString(), blockhash.ToString().substr(0,10),
117117
paymenthash.ToString().substr(0,10), strDZeel);
118118
}
119119

src/rpc/blockchain.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -897,7 +897,7 @@ UniValue listproposals(const UniValue& params, bool fHelp)
897897

898898
if (fHelp)
899899
throw runtime_error(
900-
"listproposals filter\n"
900+
"listproposals \"filter\"\n"
901901
"\nList the proposals and all the relating data including payment requests and status.\n"
902902
"\nNote passing no argument returns all proposals regardless of state.\n"
903903
"\nArguments:\n"
@@ -954,7 +954,7 @@ UniValue listproposals(const UniValue& params, bool fHelp)
954954
UniValue cfundstats(const UniValue& params, bool fHelp)
955955
{
956956

957-
if (fHelp)
957+
if (fHelp || params.size() != 0)
958958
throw runtime_error(
959959
"cfundstats\n"
960960
"\nReturns statistics about the community fund.\n"
@@ -1602,7 +1602,7 @@ UniValue reconsiderblock(const UniValue& params, bool fHelp)
16021602
static const CRPCCommand commands[] =
16031603
{ // category name actor (function) okSafeMode
16041604
// --------------------- ------------------------ ----------------------- ----------
1605-
{ "blockchain", "cfundstats", &cfundstats, true },
1605+
{ "communityfund", "cfundstats", &cfundstats, true },
16061606
{ "blockchain", "getblockchaininfo", &getblockchaininfo, true },
16071607
{ "blockchain", "getbestblockhash", &getbestblockhash, true },
16081608
{ "blockchain", "getblockcount", &getblockcount, true },
@@ -1617,13 +1617,13 @@ static const CRPCCommand commands[] =
16171617
{ "blockchain", "getmempooldescendants", &getmempooldescendants, true },
16181618
{ "blockchain", "getmempoolentry", &getmempoolentry, true },
16191619
{ "blockchain", "getmempoolinfo", &getmempoolinfo, true },
1620-
{ "blockchain", "getproposal", &getproposal, true },
1621-
{ "blockchain", "getpaymentrequest", &getpaymentrequest, true },
1620+
{ "communityfund", "getproposal", &getproposal, true },
1621+
{ "communityfund", "getpaymentrequest", &getpaymentrequest, true },
16221622
{ "blockchain", "getrawmempool", &getrawmempool, true },
16231623
{ "blockchain", "gettxout", &gettxout, true },
16241624
{ "blockchain", "gettxoutsetinfo", &gettxoutsetinfo, true },
16251625
{ "blockchain", "verifychain", &verifychain, true },
1626-
{ "blockchain", "listproposals", &listproposals, true },
1626+
{ "communityfund", "listproposals", &listproposals, true },
16271627

16281628
/* Not shown in help */
16291629
{ "hidden", "invalidateblock", &invalidateblock, true },

0 commit comments

Comments
 (0)