Skip to content

Commit

Permalink
Use outputhash in regtests.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
domob1812 committed Jan 21, 2021
1 parent bc87e43 commit 5760e8e
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 22 deletions.
2 changes: 1 addition & 1 deletion divi/qa/rpc-tests/BlocksOnlyHaveSingleCoinstake.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def build_coinstake_tx (self):
tx = CTransaction ()
tx.vout.append( CTxOut(0, CScript() ) )
tx.vout.append( CTxOut(amountToSend, scriptToSendTo ) )
tx.vin.append (CTxIn (COutPoint (txid=inp["txid"], n=inp["vout"])))
tx.vin.append (CTxIn (COutPoint (txid=inp["outputhash"], n=inp["vout"])))


unsigned = tx.serialize ().hex ()
Expand Down
11 changes: 8 additions & 3 deletions divi/qa/rpc-tests/op_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ def build_op_meta_tx (self, utxos, payload, fee):
inp = None
for i in range (len (utxos)):
if utxos[i]["amount"] >= required:
inp = utxos[i]
inp = {
"txid": utxos[i]["outputhash"],
"vout": utxos[i]["vout"],
"amount": utxos[i]["amount"],
}
del utxos[i]
break
assert inp is not None, "found no suitable output"
Expand All @@ -59,8 +63,9 @@ def build_op_meta_tx (self, utxos, payload, fee):
tx = self.node.createrawtransaction ([inp], {changeAddr: change})
signed = self.node.signrawtransaction (tx)
assert_equal (signed["complete"], True)
txid = self.node.sendrawtransaction (signed["hex"])
inp["txid"] = txid
data = self.node.decoderawtransaction (signed["hex"])
self.node.sendrawtransaction (signed["hex"])
inp["txid"] = data["txid"]
inp["vout"] = 0
inp["amount"] = change

Expand Down
2 changes: 1 addition & 1 deletion divi/qa/rpc-tests/rawtransactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def find_output (self, node, value):

for u in node.listunspent ():
if u["amount"] == value:
return {"txid": u["txid"], "vout": u["vout"]}
return {"txid": u["outputhash"], "vout": u["vout"]}

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

Expand Down
14 changes: 12 additions & 2 deletions divi/qa/rpc-tests/smartfees.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@
from util import *


def find_output(node, txid, amount):
"""
Return index to output of txid with value amount
Raises exception if there is none.
"""
txdata = node.getrawtransaction(txid, 1)
for i in range(len(txdata["vout"])):
if txdata["vout"][i]["value"] == amount:
return {"txid": txdata["txid"], "vout": i}
raise RuntimeError("find_output txid %s : %s not found"%(txid,str(amount)))

def send_zeropri_transaction(from_node, to_node, amount, fee):
"""
Create&broadcast a zero-priority transaction.
Expand All @@ -31,10 +42,9 @@ def send_zeropri_transaction(from_node, to_node, amount, fee):
self_signresult = from_node.signrawtransaction(self_rawtx)
self_txid = from_node.sendrawtransaction(self_signresult["hex"], True)

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

rawtx = from_node.createrawtransaction(inputs, outputs)
Expand Down
13 changes: 1 addition & 12 deletions divi/qa/rpc-tests/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,17 +188,6 @@ def connect_nodes_bi(nodes, a, b):
connect_nodes(nodes[a], b)
connect_nodes(nodes[b], a)

def find_output(node, txid, amount):
"""
Return index to output of txid with value amount
Raises exception if there is none.
"""
txdata = node.getrawtransaction(txid, 1)
for i in range(len(txdata["vout"])):
if txdata["vout"][i]["value"] == amount:
return i
raise RuntimeError("find_output txid %s : %s not found"%(txid,str(amount)))

def gather_inputs(from_node, amount_needed, confirmations_required=1):
"""
Return a random set of unspent txouts that are enough to pay amount_needed
Expand All @@ -211,7 +200,7 @@ def gather_inputs(from_node, amount_needed, confirmations_required=1):
while total_in < amount_needed and len(utxo) > 0:
t = utxo.pop()
total_in += t["amount"]
inputs.append({ "txid" : t["txid"], "vout" : t["vout"], "address" : t["address"] } )
inputs.append({ "txid" : t["outputhash"], "vout" : t["vout"], "address" : t["address"] } )
if total_in < amount_needed:
raise RuntimeError("Insufficient funds: need %d, have %d"%(amount_needed, total_in))
return (total_in, inputs)
Expand Down
5 changes: 3 additions & 2 deletions divi/qa/rpc-tests/vaultfork.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ def fund_vault (self, owner, staker, amount):
"""

txid = owner.fundvault (staker.getnewaddress (), amount)["txhash"]
outputs = owner.getrawtransaction (txid, 1)["vout"]
data = owner.getrawtransaction (txid, 1)
outputs = data["vout"]
for n in range (len (outputs)):
if outputs[n]["scriptPubKey"]["type"] == "vault":
return {"txid": txid, "vout": n}
return {"txid": data["txid"], "vout": n}

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

Expand Down
2 changes: 1 addition & 1 deletion divi/qa/rpc-tests/wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def run_test (self):
for utxo in node0utxos:
inputs = []
outputs = {}
inputs.append({ "txid" : utxo["txid"], "vout" : utxo["vout"]})
inputs.append({ "txid" : utxo["outputhash"], "vout" : utxo["vout"]})
outputs[self.nodes[2].getnewaddress("from1")] = utxo["amount"]
raw_tx = self.nodes[0].createrawtransaction(inputs, outputs)
txns_to_send.append(self.nodes[0].signrawtransaction(raw_tx))
Expand Down

0 comments on commit 5760e8e

Please sign in to comment.