Skip to content

Commit 8a25781

Browse files
random-zebraFuzzbawls
authored andcommitted
[Tests] Refactor POS reorg test
Also trivial fix btc-->pivx in createrawtransaction help Also move coldStaking test from 'feature' group to 'mining_pos' group. Github-Pull: #1218 Rebased-From: 0f2349b
1 parent ddc6b8a commit 8a25781

File tree

5 files changed

+33
-37
lines changed

5 files changed

+33
-37
lines changed

src/rpc/rawtransaction.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ UniValue createrawtransaction(const UniValue& params, bool fHelp)
346346
" ]\n"
347347
"2. \"addresses\" (string, required) a json object with addresses as keys and amounts as values\n"
348348
" {\n"
349-
" \"address\": x.xxx (numeric, required) The key is the pivx address, the value is the btc amount\n"
349+
" \"address\": x.xxx (numeric, required) The key is the pivx address, the value is the pivx amount\n"
350350
" ,...\n"
351351
" }\n"
352352
"3. locktime (numeric, optional, default=0) Raw locktime. Non-0 value also locktime-activates inputs\n"
@@ -1006,7 +1006,7 @@ UniValue createrawzerocoinspend(const UniValue& params, bool fHelp)
10061006
{
10071007
if (fHelp || params.size() < 1 || params.size() > 3)
10081008
throw std::runtime_error(
1009-
"createrawzerocoinspend mint_input \n"
1009+
"createrawzerocoinspend mint_input ( \"address\" isPublicSpend )\n"
10101010
"\nCreates raw zPIV public spend.\n" +
10111011
HelpRequiringPassphrase() + "\n"
10121012

test/functional/mining_pos_reorg.py

Lines changed: 24 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@
33
# Distributed under the MIT software license, see the accompanying
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
55

6-
from time import sleep
7-
import urllib
8-
9-
from test_framework.authproxy import JSONRPCException
10-
from test_framework.messages import COutPoint
116
from test_framework.test_framework import PivxTestFramework
127
from test_framework.util import (
138
sync_blocks,
@@ -16,7 +11,6 @@
1611
connect_nodes_bi,
1712
connect_nodes_clique,
1813
disconnect_nodes,
19-
bytes_to_hex_str,
2014
set_node_times,
2115
DecimalAmt,
2216
)
@@ -92,16 +86,18 @@ def findUtxoInList(txid, vout, utxo_list):
9286
self.log.info("Balances ok.")
9387

9488
# create the raw zerocoin spend txes
89+
addy = self.nodes[2].getnewaddress()
9590
self.log.info("Creating the raw zerocoin public spends...")
9691
mints = self.nodes[2].listmintedzerocoins(True, True)
97-
tx_A0 = self.nodes[2].createrawzerocoinspend(mints[0]["serial hash"])
98-
tx_A1 = self.nodes[2].createrawzerocoinspend(mints[1]["serial hash"])
92+
tx_A0 = self.nodes[2].createrawzerocoinspend(mints[0]["serial hash"], addy)
93+
tx_A1 = self.nodes[2].createrawzerocoinspend(mints[1]["serial hash"], addy)
9994
# Spending same coins to different recipients to get different txids
100-
my_addy = "yAVWM5urwaTyhiuFQHP2aP47rdZsLUG5PH"
101-
tx_B0 = self.nodes[2].createrawzerocoinspend(mints[0]["serial hash"], my_addy)
102-
tx_B1 = self.nodes[2].createrawzerocoinspend(mints[1]["serial hash"], my_addy)
95+
new_addy = "yAVWM5urwaTyhiuFQHP2aP47rdZsLUG5PH"
96+
tx_B0 = self.nodes[2].createrawzerocoinspend(mints[0]["serial hash"], new_addy)
97+
tx_B1 = self.nodes[2].createrawzerocoinspend(mints[1]["serial hash"], new_addy)
10398

10499
# Disconnect nodes
100+
minted_amount = mints[0]["denomination"] + mints[1]["denomination"]
105101
self.disconnect_all()
106102

107103
# Stake one block with node-0 and save the stake input
@@ -126,8 +122,8 @@ def findUtxoInList(txid, vout, utxo_list):
126122
stakeinput["txid"][:9], stakeinput["txid"][-4:], stakeinput["vout"]))
127123

128124
# Relay zerocoin spends
129-
txid_A0 = self.nodes[0].sendrawtransaction(tx_A0)
130-
txid_A1 = self.nodes[0].sendrawtransaction(tx_A1)
125+
self.nodes[0].sendrawtransaction(tx_A0)
126+
self.nodes[0].sendrawtransaction(tx_A1)
131127

132128
# Stake 10 more blocks with node-0 and check balances
133129
self.log.info("Staking 10 more blocks with node 0...")
@@ -138,10 +134,14 @@ def findUtxoInList(txid, vout, utxo_list):
138134
self.log.info("Balance for node 0 checks out.")
139135

140136
# Connect with node 2, sync and check zerocoin balance
137+
self.log.info("Reconnecting node 0 and node 2")
141138
connect_nodes_bi(self.nodes, 0, 2)
142139
sync_blocks([self.nodes[i] for i in [0, 2]])
143-
assert_equal(self.get_tot_balance(2), initial_balance[2] + DecimalAmt(6666))
144-
assert_equal(self.nodes[2].getzerocoinbalance()['Total'], DecimalAmt(0))
140+
self.log.info("Resetting zerocoin mints on node 2")
141+
self.nodes[2].resetmintzerocoin(True)
142+
assert_equal(self.get_tot_balance(2), initial_balance[2] + DecimalAmt(minted_amount))
143+
assert_equal(self.nodes[2].getzerocoinbalance()['Total'], DecimalAmt(6666-minted_amount))
144+
self.log.info("Balance for node 2 checks out.")
145145

146146
# Double spending txes not possible
147147
assert_raises_rpc_error(-26, "bad-txns-invalid-zpiv",
@@ -150,25 +150,26 @@ def findUtxoInList(txid, vout, utxo_list):
150150
self.nodes[0].sendrawtransaction, tx_B1)
151151

152152
# verify that the stakeinput can't be spent
153+
stakeinput_tx_json = self.nodes[0].getrawtransaction(stakeinput["txid"], True)
154+
stakeinput_amount = float(stakeinput_tx_json["vout"][int(stakeinput["vout"])]["value"])
153155
rawtx_unsigned = self.nodes[0].createrawtransaction(
154-
[{"txid": str(stakeinput["txid"]), "vout": int(stakeinput["vout"])}],
155-
{"xxncEuJK27ygNh7imNfaX8JV6ZQUnoBqzN": 249.99})
156+
[{"txid": stakeinput["txid"], "vout": int(stakeinput["vout"])}],
157+
{"xxncEuJK27ygNh7imNfaX8JV6ZQUnoBqzN": (stakeinput_amount-0.01)})
156158
rawtx = self.nodes[0].signrawtransaction(rawtx_unsigned)
157159
assert(rawtx["complete"])
158-
assert_raises_rpc_error(-25, "Missing inputs",self.nodes[0].sendrawtransaction, rawtx["hex"])
160+
assert_raises_rpc_error(-26, "bad-txns-inputs-spent", self.nodes[0].sendrawtransaction, rawtx["hex"])
159161

160162
# Spend tx_B0 and tx_B1 on the other chain
161-
txid_B0 = self.nodes[1].sendrawtransaction(tx_B0)
162-
txid_B1 = self.nodes[1].sendrawtransaction(tx_B1)
163+
self.nodes[1].sendrawtransaction(tx_B0)
164+
self.nodes[1].sendrawtransaction(tx_B1)
163165

164166
# Stake 12 blocks with node-1
165167
set_node_times(self.nodes, block_time_1)
166168
self.log.info("Staking 12 blocks with node 1...")
167169
for i in range(12):
168170
block_time_1 = self.generate_pos(1, block_time_1)
169171
expected_balance_1 = initial_balance[1] + DecimalAmt(12 * 250.0)
170-
w_info = self.nodes[1].getwalletinfo()
171-
assert_equal(w_info["balance"] + w_info["immature_balance"], expected_balance_1)
172+
assert_equal(self.get_tot_balance(1), expected_balance_1)
172173
self.log.info("Balance for node 1 checks out.")
173174

174175
# re-connect and sync nodes and check that node-0 and node-2 get on the other chain
@@ -180,19 +181,8 @@ def findUtxoInList(txid, vout, utxo_list):
180181
for i in [0, 2]:
181182
assert_equal(self.nodes[i].getbestblockhash(), new_best_hash)
182183

183-
# check that old zc spends have been removed and new one are present
184-
for i in range(self.num_nodes):
185-
print(i)
186-
try:
187-
print(self.nodes[i].getrawtransaction(txid_A0))
188-
print(self.nodes[i].getrawtransaction(txid_A1))
189-
except Exception as e:
190-
print(str(e))
191-
192184
# check balance of node-0
193-
balance_0 = initial_balance[0]
194-
w_info = self.nodes[0].getwalletinfo()
195-
assert_equal(w_info["balance"] + w_info["immature_balance"], initial_balance[0])
185+
assert_equal(self.get_tot_balance(0), initial_balance[0])
196186
self.log.info("Balance for node 0 checks out.")
197187

198188
# check that NOW the original stakeinput is present and spendable

test/functional/test_framework/util.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,12 @@ def connect_nodes_bi(nodes, a, b):
368368
connect_nodes(nodes[a], b)
369369
connect_nodes(nodes[b], a)
370370

371+
def connect_nodes_clique(nodes):
372+
l = len(nodes)
373+
for a in range(l):
374+
for b in range(a, l):
375+
connect_nodes_bi(nodes, a, b)
376+
371377
def sync_blocks(rpc_connections, *, wait=1, timeout=60):
372378
"""
373379
Wait until everybody has the same tip.

test/functional/test_runner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
# vv Tests less than 5m vv
6262
'wallet_abandonconflict.py',
6363
'mining_pos_reorg.py',
64-
'feature_coldStaking.py',
64+
'mining_pos_coldStaking.py',
6565
'rpc_rawtransaction.py',
6666
'wallet_zapwallettxes.py',
6767
'wallet_keypool_topup.py',

0 commit comments

Comments
 (0)