Skip to content

Commit

Permalink
Update txindex.py test for bare txid lookups.
Browse files Browse the repository at this point in the history
This extends the txindex.py test, to check lookups also by bare txid
where this is possible (mempool and txindex).  Lookups by UTXO set only
work on whatever hash is used for the UTXO before/after segwit light.
  • Loading branch information
domob1812 committed Apr 1, 2021
1 parent a2a090e commit f86d40f
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions divi/qa/rpc-tests/txindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ def setup_network (self):
self.is_network_split = False
self.sync_all ()

def expect_found (self, node, txid):
data = node.getrawtransaction (txid, 1)
assert_equal (data["txid"], txid)
def expect_found (self, node, key, value):
data = node.getrawtransaction (value, 1)
assert_equal (data[key], value)

def expect_not_found (self, node, txid):
assert_raises (JSONRPCException, node.getrawtransaction, txid)
def expect_not_found (self, node, value):
assert_raises (JSONRPCException, node.getrawtransaction, value)

def run_test (self):
self.nodes[0].setgenerate (True, 30)
Expand All @@ -46,21 +46,25 @@ def run_test (self):
tx = self.nodes[0].createrawtransaction (inputs, {addr: value - 1})
signed = self.nodes[0].signrawtransaction (tx)
assert_equal (signed["complete"], True)
txid = self.nodes[0].sendrawtransaction (signed["hex"])
self.nodes[0].sendrawtransaction (signed["hex"])
data = self.nodes[0].decoderawtransaction (signed["hex"])
txid = data["txid"]
bareTxid = data["baretxid"]
sync_mempools (self.nodes)

print ("Lookup through mempool...")
for n in self.nodes:
assert_equal (n.getrawmempool (), [txid])
self.expect_found (n, txid)
self.expect_found (n, "txid", txid)
self.expect_found (n, "baretxid", bareTxid)

print ("Lookup through UTXO set...")
self.nodes[0].setgenerate (True, 1)
sync_blocks (self.nodes)
for n in self.nodes:
assert_equal (n.getrawmempool (), [])
assert n.gettxout (txid, 0) is not None
self.expect_found (n, txid)
self.expect_found (n, "txid", txid)

print ("Spending test output...")
tx = self.nodes[0].createrawtransaction ([{"txid": txid, "vout": 0}], {addr: value - 2})
Expand All @@ -74,8 +78,10 @@ def run_test (self):
for n in self.nodes:
assert_equal (n.getrawmempool (), [])
assert_equal (n.gettxout (txid, 0), None)
self.expect_found (self.nodes[0], txid)
self.expect_found (self.nodes[0], "txid", txid)
self.expect_found (self.nodes[0], "baretxid", bareTxid)
self.expect_not_found (self.nodes[1], txid)
self.expect_not_found (self.nodes[1], bareTxid)


if __name__ == '__main__':
Expand Down

0 comments on commit f86d40f

Please sign in to comment.