Skip to content

Commit 3be6b14

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 0235312 commit 3be6b14

12 files changed

+41
-35
lines changed

divi/qa/rpc-tests/BadBlockTests.py

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def build_bad_sig_spend (self):
4949
amountToSend = int ((Decimal (inp["amount"]) - Decimal ('0.1')) * COIN)
5050
tx = CTransaction ()
5151
tx.vout.append( CTxOut(amountToSend, scriptToSendTo ) )
52-
tx.vin.append (CTxIn (COutPoint (txid=inp["txid"], n=inp["vout"])))
52+
tx.vin.append (CTxIn (COutPoint (txid=inp["outputhash"], n=inp["vout"])))
5353

5454

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

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/TxInputsStandardness.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def generateOutput (self, addr, amount):
2828
tx = self.node.getrawtransaction (txid, 1)
2929
for i in range (len (tx["vout"])):
3030
if tx["vout"][i]["scriptPubKey"]["addresses"] == [addr]:
31-
return (txid, i)
31+
return (tx["txid"], i)
3232

3333
raise AssertionError ("failed to find destination address")
3434

divi/qa/rpc-tests/mnvaults.py

Lines changed: 7 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,7 +26,7 @@
2626
class MnVaultsTest (MnTestFramework):
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
self.number_of_nodes=7
@@ -94,6 +94,7 @@ def fund_vault (self):
9494
amount = 100
9595
txid = self.nodes[0].sendtoaddress (addr, amount)
9696
raw = self.nodes[0].getrawtransaction (txid, 1)
97+
outputId = raw["txid"]
9798
vout = None
9899
for i in range (len (raw["vout"])):
99100
o = raw["vout"][i]
@@ -112,19 +113,19 @@ def fund_vault (self):
112113
data = self.nodes[0].validateaddress (unvaultAddr)
113114

114115
tx = CTransaction ()
115-
tx.vin.append (CTxIn (COutPoint (txid=txid, n=vout)))
116+
tx.vin.append (CTxIn (COutPoint (txid=outputId, n=vout)))
116117
tx.vout.append (CTxOut (amount * COIN, unhexlify (data["scriptPubKey"])))
117118
unsigned = ToHex (tx)
118119

119120
validated = self.nodes[0].validateaddress (addr)
120121
script = validated["scriptPubKey"]
121-
prevtx = [{"txid": txid, "vout": vout, "scriptPubKey": script}]
122+
prevtx = [{"txid": outputId, "vout": vout, "scriptPubKey": script}]
122123
signed = self.nodes[0].signrawtransaction (unsigned, prevtx, [privkey],
123124
"SINGLE|ANYONECANPAY")
124125
assert_equal (signed["complete"], True)
125126
self.unvaultTx = signed["hex"]
126127

127-
self.setup_masternode(2,1,"mn","copper",{"txhash":txid,"vout":vout})
128+
self.setup_masternode(2,1,"mn","copper",{"txhash":outputId,"vout":vout})
128129
self.cfg = self.setup[1].cfg
129130
# FIXME: Use reward address from node 0.
130131
self.cfg.rewardAddr = addr
@@ -231,7 +232,7 @@ def unvault (self):
231232
data = self.nodes[0].validateaddress (changeAddr)
232233

233234
tx = FromHex (CTransaction (), self.unvaultTx)
234-
tx.vin.append (CTxIn (COutPoint (txid=inp["txid"], n=inp["vout"])))
235+
tx.vin.append (CTxIn (COutPoint (txid=inp["outputhash"], n=inp["vout"])))
235236
tx.vout.append (CTxOut (change, unhexlify (data["scriptPubKey"])))
236237
partial = ToHex (tx)
237238

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/txn_doublespend.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def create_doublespend_for_later(self,sender, node1_address):
5151
utxos_by_account = self.collect_utxos_by_account(sender,["foo","bar"])
5252
inputs = []
5353
for utxo in utxos_by_account["foo"]:
54-
inputs.append({ "txid" : utxo["txid"], "vout" : utxo["vout"]} )
54+
inputs.append({ "txid" : utxo["outputhash"], "vout" : utxo["vout"]} )
5555

5656
outputs = {}
5757
outputs[self.foo_address] = 9.999
@@ -65,9 +65,9 @@ def create_daisy_chain_transactions(self,sender,node1_address):
6565
utxos_by_account = self.collect_utxos_by_account(sender,["foo","bar"])
6666
inputs = []
6767
for utxo in utxos_by_account["foo"]:
68-
inputs.append({ "txid" : utxo["txid"], "vout" : utxo["vout"], "address" : utxo["address"] } )
68+
inputs.append({ "txid" : utxo["outputhash"], "vout" : utxo["vout"], "address" : utxo["address"] } )
6969
for utxo in utxos_by_account["bar"]:
70-
inputs.append({ "txid" : utxo["txid"], "vout" : utxo["vout"], "address" : utxo["address"] } )
70+
inputs.append({ "txid" : utxo["outputhash"], "vout" : utxo["vout"], "address" : utxo["address"] } )
7171

7272
outputs = {}
7373
outputs[self.bar_address] = 29.999

divi/qa/rpc-tests/util.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -216,17 +216,6 @@ def connect_nodes_bi(nodes, a, b):
216216
connect_nodes(nodes[a], b)
217217
connect_nodes(nodes[b], a)
218218

219-
def find_output(node, txid, amount):
220-
"""
221-
Return index to output of txid with value amount
222-
Raises exception if there is none.
223-
"""
224-
txdata = node.getrawtransaction(txid, 1)
225-
for i in range(len(txdata["vout"])):
226-
if txdata["vout"][i]["value"] == amount:
227-
return i
228-
raise RuntimeError("find_output txid %s : %s not found"%(txid,str(amount)))
229-
230219
def gather_inputs(from_node, amount_needed, confirmations_required=1):
231220
"""
232221
Return a random set of unspent txouts that are enough to pay amount_needed
@@ -239,7 +228,7 @@ def gather_inputs(from_node, amount_needed, confirmations_required=1):
239228
while total_in < amount_needed and len(utxo) > 0:
240229
t = utxo.pop()
241230
total_in += t["amount"]
242-
inputs.append({ "txid" : t["txid"], "vout" : t["vout"], "address" : t["address"] } )
231+
inputs.append({ "txid" : t["outputhash"], "vout" : t["vout"], "address" : t["address"] } )
243232
if total_in < amount_needed:
244233
raise RuntimeError("Insufficient funds: need %d, have %d"%(amount_needed, total_in))
245234
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))

divi/qa/rpc-tests/wallet_sends.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def ensure_complex_spends_resolve_balances_correctly(self,accountName=""):
9292

9393
sender_utxo = sender.listunspent()[0]
9494
tx = CTransaction ()
95-
tx.vin.append (CTxIn (COutPoint (txid=sender_utxo["txid"], n=sender_utxo["vout"])))
95+
tx.vin.append (CTxIn (COutPoint (txid=sender_utxo["outputhash"], n=sender_utxo["vout"])))
9696
tx.vin.append (CTxIn (COutPoint (txid=receiver_utxo[0], n=receiver_utxo[1])))
9797
tx.vin.append (CTxIn (COutPoint (txid=multisigTxID, n=multisigOutputIndex)))
9898

@@ -154,7 +154,7 @@ def join_sends_compute_balance_correctly(self):
154154

155155
sender_utxo = sender.listunspent()[0]
156156
tx = CTransaction ()
157-
tx.vin.append (CTxIn (COutPoint (txid=sender_utxo["txid"], n=sender_utxo["vout"])))
157+
tx.vin.append (CTxIn (COutPoint (txid=sender_utxo["outputhash"], n=sender_utxo["vout"])))
158158
tx.vin.append (CTxIn (COutPoint (txid=receiver_utxo[0], n=receiver_utxo[1])))
159159

160160
amountToSend = int ((Decimal (2500.0) - Decimal ('0.1')) * COIN)

0 commit comments

Comments
 (0)