Skip to content

Commit 2881b44

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 55c4fa8 commit 2881b44

File tree

7 files changed

+27
-22
lines changed

7 files changed

+27
-22
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/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
@@ -188,17 +188,6 @@ def connect_nodes_bi(nodes, a, b):
188188
connect_nodes(nodes[a], b)
189189
connect_nodes(nodes[b], a)
190190

191-
def find_output(node, txid, amount):
192-
"""
193-
Return index to output of txid with value amount
194-
Raises exception if there is none.
195-
"""
196-
txdata = node.getrawtransaction(txid, 1)
197-
for i in range(len(txdata["vout"])):
198-
if txdata["vout"][i]["value"] == amount:
199-
return i
200-
raise RuntimeError("find_output txid %s : %s not found"%(txid,str(amount)))
201-
202191
def gather_inputs(from_node, amount_needed, confirmations_required=1):
203192
"""
204193
Return a random set of unspent txouts that are enough to pay amount_needed
@@ -211,7 +200,7 @@ def gather_inputs(from_node, amount_needed, confirmations_required=1):
211200
while total_in < amount_needed and len(utxo) > 0:
212201
t = utxo.pop()
213202
total_in += t["amount"]
214-
inputs.append({ "txid" : t["txid"], "vout" : t["vout"], "address" : t["address"] } )
203+
inputs.append({ "txid" : t["outputhash"], "vout" : t["vout"], "address" : t["address"] } )
215204
if total_in < amount_needed:
216205
raise RuntimeError("Insufficient funds: need %d, have %d"%(amount_needed, total_in))
217206
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)