Skip to content

Commit 68cf8a1

Browse files
committed
Test custom reward address in mnoperation.py.
Use a custom reward address for one of the two masternodes in the mnoperation.py regtest, verifying that this works. For the test, we activate the new protocol version on regtest without any forking logic.
1 parent 6cc84b8 commit 68cf8a1

File tree

4 files changed

+32
-7
lines changed

4 files changed

+32
-7
lines changed

divi/qa/rpc-tests/masternode.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class MnConfigLine (object):
1212

1313
def __init__ (self, line):
1414
parts = line.split (" ")
15-
assert_equal (len (parts), 5)
15+
assert len (parts) in [5, 6]
1616

1717
self.line = line
1818

@@ -22,6 +22,21 @@ def __init__ (self, line):
2222
self.txid = parts[3]
2323
self.vout = int (parts[4])
2424

25+
if len (parts) >= 6:
26+
self.rewardAddr = parts[5]
27+
else:
28+
self.rewardAddr = None
29+
30+
def getLine (self):
31+
"""Returns the config line as string, to put into masternode.conf."""
32+
33+
res = "%s %s %s %s %d" % (self.alias, self.ip, self.privkey,
34+
self.txid, self.vout)
35+
if self.rewardAddr is not None:
36+
res += " %s" % self.rewardAddr
37+
38+
return res
39+
2540

2641
def fund_masternode (node, alias, tier, txid, ip):
2742
"""Calls fundmasternode with the given data and returns the

divi/qa/rpc-tests/mncollateral.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ def run_test (self):
5959
assert_equal (cfg.alias, "spent")
6060
assert_equal (cfg.ip, "1.2.3.4:51476")
6161
assert_equal (cfg.txid, txid)
62+
assert_equal (cfg.rewardAddr, None)
6263
assert_equal (node.gettxout (cfg.txid, cfg.vout)["value"], 300)
6364

6465
# It should still be possible to spend the coins, invalidating the

divi/qa/rpc-tests/mnoperation.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ def start_node (self, n):
6969
and masternode config for it."""
7070

7171
configs = [
72-
[c.line for c in self.cfg],
73-
[self.cfg[0].line],
74-
[self.cfg[1].line],
72+
[c.getLine () for c in self.cfg],
73+
[self.cfg[0].getLine ()],
74+
[self.cfg[1].getLine ()],
7575
]
7676

7777
args = self.base_args[:]
@@ -143,6 +143,8 @@ def fund_masternodes (self):
143143
fund_masternode (self.nodes[0], "mn2", "silver", id2, "localhost:%d" % p2p_port (2)),
144144
]
145145

146+
self.cfg[1].rewardAddr = self.nodes[0].getnewaddress ("reward2")
147+
146148
def start_masternodes (self):
147149
print ("Starting masternodes...")
148150

@@ -267,7 +269,7 @@ def payments_both_active (self):
267269
winners = self.verify_number_of_votes_exist_and_tally_winners(startHeight,endHeight, 2)
268270

269271
addr1 = self.nodes[1].getmasternodestatus ()["addr"]
270-
addr2 = self.nodes[2].getmasternodestatus ()["addr"]
272+
addr2 = self.cfg[1].rewardAddr
271273
assert_equal (len (winners), 2)
272274
assert_greater_than (winners[addr1], 0)
273275
assert_greater_than (winners[addr2], 0)
@@ -313,8 +315,9 @@ def check_rewards (self):
313315
self.start_node (0)
314316
sync_blocks (self.nodes)
315317

316-
assert_greater_than (self.nodes[0].getbalance ("alloc->mn1"), 0)
317-
assert_greater_than (self.nodes[0].getbalance ("alloc->mn2"), 0)
318+
assert_greater_than (self.nodes[0].getbalance ("alloc->mn1"), 100)
319+
assert_equal (self.nodes[0].getbalance ("alloc->mn2"), 300)
320+
assert_greater_than (self.nodes[0].getbalance ("reward2"), 0)
318321

319322

320323
if __name__ == '__main__':

divi/src/version.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <version.h>
22

3+
#include <chainparams.h>
34
#include <Settings.h>
45

56
extern Settings& settings;
@@ -13,5 +14,10 @@ int ActiveProtocol()
1314
if (settings.ParameterIsSet("-activeversion"))
1415
return settings.GetArg("-activeversion", 0);
1516

17+
/* On regtest, we set the new protocol as active without any further
18+
ado. This allows proper testing of the changed logic. */
19+
if (Params().NetworkID() == CBaseChainParams::REGTEST)
20+
return MN_REWARD_SCRIPT_VERSION;
21+
1622
return MIN_PEER_PROTO_VERSION_AFTER_ENFORCEMENT;
1723
}

0 commit comments

Comments
 (0)