Skip to content

Commit c07a0da

Browse files
committed
Use outputhash in regtests.
This updates the regtests to use "outputhash" for listunspent results in some places, to make sure the code will also work after activating segwit-light. Some other places remain where outputs are not from listunspent and that still needs to be updated when segwit-light gets activated generally, but this is a first step to reduce the amount of required changes then.
1 parent d8d5cda commit c07a0da

File tree

8 files changed

+35
-28
lines changed

8 files changed

+35
-28
lines changed

divi/qa/rpc-tests/BlocksOnlyHaveSingleCoinstake.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def build_coinstake_tx (self):
4242
tx = CTransaction ()
4343
tx.vout.append( CTxOut(0, CScript() ) )
4444
tx.vout.append( CTxOut(amountToSend, scriptToSendTo ) )
45-
tx.vin.append (CTxIn (COutPoint (txid=inp["txid"], n=inp["vout"])))
45+
tx.vin.append (CTxIn (COutPoint (txid=inp["outputhash"], n=inp["vout"])))
4646

4747

4848
unsigned = tx.serialize ().hex ()

divi/qa/rpc-tests/mnvaults.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env python3
2-
# Copyright (c) 2020 The DIVI developers
2+
# Copyright (c) 2020-2021 The DIVI developers
33
# Distributed under the MIT/X11 software license, see the accompanying
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
55

@@ -26,11 +26,12 @@
2626
class MnVaultsTest (BitcoinTestFramework):
2727

2828
def __init__ (self):
29-
super (MnVaultsTest, self).__init__ ()
29+
super ().__init__ ()
3030
self.base_args = ["-debug=masternode", "-debug=mocktime"]
3131
self.cfg = None
3232

3333
def setup_chain (self):
34+
print("Initializing test directory " + self.options.tmpdir)
3435
for i in range (7):
3536
initialize_datadir (self.options.tmpdir, i)
3637

@@ -127,6 +128,7 @@ def fund_vault (self):
127128
amount = 100
128129
txid = self.nodes[0].sendtoaddress (addr, amount)
129130
raw = self.nodes[0].getrawtransaction (txid, 1)
131+
outputId = raw["txid"]
130132
vout = None
131133
for i in range (len (raw["vout"])):
132134
o = raw["vout"][i]
@@ -139,19 +141,19 @@ def fund_vault (self):
139141
data = self.nodes[0].validateaddress (unvaultAddr)
140142

141143
tx = CTransaction ()
142-
tx.vin.append (CTxIn (COutPoint (txid=txid, n=vout)))
144+
tx.vin.append (CTxIn (COutPoint (txid=outputId, n=vout)))
143145
tx.vout.append (CTxOut (amount * COIN, unhexlify (data["scriptPubKey"])))
144146
unsigned = ToHex (tx)
145147

146148
validated = self.nodes[0].validateaddress (addr)
147149
script = validated["scriptPubKey"]
148-
prevtx = [{"txid": txid, "vout": vout, "scriptPubKey": script}]
150+
prevtx = [{"txid": outputId, "vout": vout, "scriptPubKey": script}]
149151
signed = self.nodes[0].signrawtransaction (unsigned, prevtx, [privkey],
150152
"SINGLE|ANYONECANPAY")
151153
assert_equal (signed["complete"], True)
152154
self.unvaultTx = signed["hex"]
153155

154-
self.cfg = fund_masternode (self.nodes[0], "mn", "copper", txid,
156+
self.cfg = fund_masternode (self.nodes[0], "mn", "copper", outputId,
155157
"localhost:%d" % p2p_port (1))
156158
# FIXME: Use reward address from node 0.
157159
self.cfg.rewardAddr = addr
@@ -260,7 +262,7 @@ def unvault (self):
260262
data = self.nodes[0].validateaddress (changeAddr)
261263

262264
tx = FromHex (CTransaction (), self.unvaultTx)
263-
tx.vin.append (CTxIn (COutPoint (txid=inp["txid"], n=inp["vout"])))
265+
tx.vin.append (CTxIn (COutPoint (txid=inp["outputhash"], n=inp["vout"])))
264266
tx.vout.append (CTxOut (change, unhexlify (data["scriptPubKey"])))
265267
partial = ToHex (tx)
266268

divi/qa/rpc-tests/op_meta.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ def build_op_meta_tx (self, utxos, payload, fee):
4646
inp = None
4747
for i in range (len (utxos)):
4848
if utxos[i]["amount"] >= required:
49-
inp = utxos[i]
49+
inp = {
50+
"txid": utxos[i]["outputhash"],
51+
"vout": utxos[i]["vout"],
52+
"amount": utxos[i]["amount"],
53+
}
5054
del utxos[i]
5155
break
5256
assert inp is not None, "found no suitable output"
@@ -59,8 +63,9 @@ def build_op_meta_tx (self, utxos, payload, fee):
5963
tx = self.node.createrawtransaction ([inp], {changeAddr: change})
6064
signed = self.node.signrawtransaction (tx)
6165
assert_equal (signed["complete"], True)
62-
txid = self.node.sendrawtransaction (signed["hex"])
63-
inp["txid"] = txid
66+
data = self.node.decoderawtransaction (signed["hex"])
67+
self.node.sendrawtransaction (signed["hex"])
68+
inp["txid"] = data["txid"]
6469
inp["vout"] = 0
6570
inp["amount"] = change
6671

divi/qa/rpc-tests/rawtransactions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def find_output (self, node, value):
2626

2727
for u in node.listunspent ():
2828
if u["amount"] == value:
29-
return {"txid": u["txid"], "vout": u["vout"]}
29+
return {"txid": u["outputhash"], "vout": u["vout"]}
3030

3131
raise AssertionError ("no output with value %s found" % str (value))
3232

divi/qa/rpc-tests/smartfees.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,17 @@
1212
from util import *
1313

1414

15+
def find_output(node, txid, amount):
16+
"""
17+
Return index to output of txid with value amount
18+
Raises exception if there is none.
19+
"""
20+
txdata = node.getrawtransaction(txid, 1)
21+
for i in range(len(txdata["vout"])):
22+
if txdata["vout"][i]["value"] == amount:
23+
return {"txid": txdata["txid"], "vout": i}
24+
raise RuntimeError("find_output txid %s : %s not found"%(txid,str(amount)))
25+
1526
def send_zeropri_transaction(from_node, to_node, amount, fee):
1627
"""
1728
Create&broadcast a zero-priority transaction.
@@ -31,10 +42,9 @@ def send_zeropri_transaction(from_node, to_node, amount, fee):
3142
self_signresult = from_node.signrawtransaction(self_rawtx)
3243
self_txid = from_node.sendrawtransaction(self_signresult["hex"], True)
3344

34-
vout = find_output(from_node, self_txid, amount+fee)
3545
# Now immediately spend the output to create a 1-input, 1-output
3646
# zero-priority transaction:
37-
inputs = [ { "txid" : self_txid, "vout" : vout } ]
47+
inputs = [find_output(from_node, self_txid, amount + fee)]
3848
outputs = { to_node.getnewaddress() : float(amount) }
3949

4050
rawtx = from_node.createrawtransaction(inputs, outputs)

divi/qa/rpc-tests/util.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -197,17 +197,6 @@ def connect_nodes_bi(nodes, a, b):
197197
connect_nodes(nodes[a], b)
198198
connect_nodes(nodes[b], a)
199199

200-
def find_output(node, txid, amount):
201-
"""
202-
Return index to output of txid with value amount
203-
Raises exception if there is none.
204-
"""
205-
txdata = node.getrawtransaction(txid, 1)
206-
for i in range(len(txdata["vout"])):
207-
if txdata["vout"][i]["value"] == amount:
208-
return i
209-
raise RuntimeError("find_output txid %s : %s not found"%(txid,str(amount)))
210-
211200
def gather_inputs(from_node, amount_needed, confirmations_required=1):
212201
"""
213202
Return a random set of unspent txouts that are enough to pay amount_needed
@@ -220,7 +209,7 @@ def gather_inputs(from_node, amount_needed, confirmations_required=1):
220209
while total_in < amount_needed and len(utxo) > 0:
221210
t = utxo.pop()
222211
total_in += t["amount"]
223-
inputs.append({ "txid" : t["txid"], "vout" : t["vout"], "address" : t["address"] } )
212+
inputs.append({ "txid" : t["outputhash"], "vout" : t["vout"], "address" : t["address"] } )
224213
if total_in < amount_needed:
225214
raise RuntimeError("Insufficient funds: need %d, have %d"%(amount_needed, total_in))
226215
return (total_in, inputs)

divi/qa/rpc-tests/vaultfork.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,11 @@ def fund_vault (self, owner, staker, amount):
3131
"""
3232

3333
txid = owner.fundvault (staker.getnewaddress (), amount)["txhash"]
34-
outputs = owner.getrawtransaction (txid, 1)["vout"]
34+
data = owner.getrawtransaction (txid, 1)
35+
outputs = data["vout"]
3536
for n in range (len (outputs)):
3637
if outputs[n]["scriptPubKey"]["type"] == "vault":
37-
return {"txid": txid, "vout": n}
38+
return {"txid": data["txid"], "vout": n}
3839

3940
raise AssertionError ("constructed transaction has no vault output")
4041

divi/qa/rpc-tests/wallet.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def run_test (self):
7070
for utxo in node0utxos:
7171
inputs = []
7272
outputs = {}
73-
inputs.append({ "txid" : utxo["txid"], "vout" : utxo["vout"]})
73+
inputs.append({ "txid" : utxo["outputhash"], "vout" : utxo["vout"]})
7474
outputs[self.nodes[2].getnewaddress("from1")] = utxo["amount"]
7575
raw_tx = self.nodes[0].createrawtransaction(inputs, outputs)
7676
txns_to_send.append(self.nodes[0].signrawtransaction(raw_tx))

0 commit comments

Comments
 (0)