Skip to content

Commit

Permalink
Merge bitcoin#15404: [test] Remove -txindex to start nodes
Browse files Browse the repository at this point in the history
8e4b4f6 Address test todos by removing -txindex to nodes. Originally added when updating getrawtransaction to stop searching unspent utxos. (Amiti Uttarwar)

Pull request description:

  Original todos added when removing getrawtransaction default behavior of searching unspent utxos.

Tree-SHA512: d080953c3b0d2e5dca2265a15966dc25985a614c9cc86271ecd6276178ce428c85e262c24df92501695c32fed7beec0339b989f03cce91b57fb2efba201b7809
  • Loading branch information
laanwj authored and Munkybooty committed Sep 13, 2021
1 parent 06925a1 commit 7006a38
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 32 deletions.
3 changes: 2 additions & 1 deletion doc/REST-interface.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ Supported API

Given a transaction hash: returns a transaction in binary, hex-encoded binary, or JSON formats.

For full TX query capability, one must enable the transaction index via "txindex=1" command line / configuration option.
By default, this endpoint will only search the mempool.
To query for a confirmed transaction, enable the transaction index via "txindex=1" command line / configuration option.

#### Blocks
`GET /rest/block/<BLOCK-HASH>.<bin|hex|json>`
Expand Down
35 changes: 15 additions & 20 deletions test/functional/interface_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ class RESTTest (BitcoinTestFramework):
def set_test_params(self):
self.setup_clean_chain = True
self.num_nodes = 2
# TODO: remove -txindex. Currently required for getrawtransaction call.
self.extra_args = [["-rest", "-txindex"], []]
self.extra_args = [["-rest"], []]

def test_rest_request(self, uri, http_method='GET', req_type=ReqType.JSON, body='', status=200, ret_type=RetType.JSON):
rest_uri = '/rest' + uri
Expand Down Expand Up @@ -86,25 +85,32 @@ def run_test(self):

txid = self.nodes[0].sendtoaddress(self.nodes[1].getnewaddress(), 0.1)
self.sync_all()
self.nodes[1].generatetoaddress(1, not_related_address)
self.sync_all()
bb_hash = self.nodes[0].getbestblockhash()

assert_equal(self.nodes[1].getbalance(), Decimal("0.1"))

self.log.info("Load the transaction using the /tx URI")
self.log.info("Test the /tx URI")

json_obj = self.test_rest_request("/tx/{}".format(txid))
assert_equal(json_obj['txid'], txid)

# Check hex format response
hex_response = self.test_rest_request("/tx/{}".format(txid), req_type=ReqType.HEX, ret_type=RetType.OBJ)
assert_greater_than_or_equal(int(hex_response.getheader('content-length')),
json_obj['size']*2)

spent = (json_obj['vin'][0]['txid'], json_obj['vin'][0]['vout']) # get the vin to later check for utxo (should be spent by then)
# get n of 0.1 outpoint
n, = filter_output_indices_by_value(json_obj['vout'], Decimal('0.1'))
spending = (txid, n)

self.log.info("Query an unspent TXO using the /getutxos URI")

json_obj = self.test_rest_request("/getutxos/{}-{}".format(*spending))
self.nodes[1].generatetoaddress(1, not_related_address)
self.sync_all()
bb_hash = self.nodes[0].getbestblockhash()

assert_equal(self.nodes[1].getbalance(), Decimal("0.1"))

# Check chainTip response
json_obj = self.test_rest_request("/getutxos/{}-{}".format(*spending))
assert_equal(json_obj['chaintipHash'], bb_hash)

# Make sure there is one utxo
Expand Down Expand Up @@ -269,17 +275,6 @@ def run_test(self):
json_obj = self.test_rest_request("/headers/5/{}".format(bb_hash))
assert_equal(len(json_obj), 5) # now we should have 5 header objects

self.log.info("Test the /tx URI")

tx_hash = block_json_obj['tx'][0]['txid']
json_obj = self.test_rest_request("/tx/{}".format(tx_hash))
assert_equal(json_obj['txid'], tx_hash)

# Check hex format response
hex_response = self.test_rest_request("/tx/{}".format(tx_hash), req_type=ReqType.HEX, ret_type=RetType.OBJ)
assert_greater_than_or_equal(int(hex_response.getheader('content-length')),
json_obj['size']*2)

self.log.info("Test tx inclusion in the /mempool and /block URIs")

# Make 3 tx and mine them on node 1
Expand Down
8 changes: 4 additions & 4 deletions test/functional/rpc_psbt.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@ def run_test(self):
node1_addr = self.nodes[1].getnewaddress()
node2_addr = self.nodes[2].getnewaddress()
txid1 = self.nodes[0].sendtoaddress(node1_addr, 13)
txid2 =self.nodes[0].sendtoaddress(node2_addr, 13)
self.nodes[0].generate(6)
txid2 = self.nodes[0].sendtoaddress(node2_addr, 13)
blockhash = self.nodes[0].generate(6)[0]
self.sync_all()
vout1 = find_output(self.nodes[1], txid1, 13)
vout2 = find_output(self.nodes[2], txid2, 13)
vout1 = find_output(self.nodes[1], txid1, 13, blockhash=blockhash)
vout2 = find_output(self.nodes[2], txid2, 13, blockhash=blockhash)

# Create a psbt spending outputs from nodes 1 and 2
psbt_orig = self.nodes[0].createpsbt([{"txid":txid1, "vout":vout1}, {"txid":txid2, "vout":vout2}], {self.nodes[0].getnewaddress():25.999})
Expand Down
1 change: 0 additions & 1 deletion test/functional/rpc_rawtransaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ class RawTransactionsTest(BitcoinTestFramework):
def set_test_params(self):
self.setup_clean_chain = True
self.num_nodes = 3
# TODO: remove -txindex. Currently required for getrawtransaction call.
self.extra_args = [["-txindex"], ["-txindex"], ["-txindex"]]

def setup_network(self):
Expand Down
4 changes: 2 additions & 2 deletions test/functional/test_framework/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,12 +505,12 @@ def force_finish_mnsync(node):
# Transaction/Block functions
#############################

def find_output(node, txid, amount):
def find_output(node, txid, amount, *, blockhash=None):
"""
Return index to output of txid with value amount
Raises exception if there is none.
"""
txdata = node.getrawtransaction(txid, 1)
txdata = node.getrawtransaction(txid, 1, blockhash)
for i in range(len(txdata["vout"])):
if txdata["vout"][i]["value"] == amount:
return i
Expand Down
3 changes: 1 addition & 2 deletions test/functional/wallet_abandonconflict.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
class AbandonConflictTest(BitcoinTestFramework):
def set_test_params(self):
self.num_nodes = 2
# TODO: remove -txindex. Currently required for getrawtransaction call.
self.extra_args = [["-minrelaytxfee=0.00001", "-txindex"], []]
self.extra_args = [["-minrelaytxfee=0.00001"], []]

def run_test(self):
self.nodes[1].generate(100)
Expand Down
3 changes: 1 addition & 2 deletions test/functional/wallet_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ class WalletTest(BitcoinTestFramework):
def set_test_params(self):
self.num_nodes = 4
self.setup_clean_chain = True
# TODO: remove -txindex. Currently required for getrawtransaction call.
self.extra_args = [['-txindex', '-usehd={:d}'.format(i%2==0)] for i in range(4)]
self.extra_args = [['-usehd={:d}'.format(i%2==0)] for i in range(4)]

def setup_network(self):
self.add_nodes(4, self.extra_args)
Expand Down

0 comments on commit 7006a38

Please sign in to comment.