Skip to content

Commit 38429c4

Browse files
committed
Merge #15404: [test] Remove -txindex to start nodes
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
2 parents 3e4fd40 + 8e4b4f6 commit 38429c4

File tree

8 files changed

+42
-53
lines changed

8 files changed

+42
-53
lines changed

doc/REST-interface.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ Supported API
2020

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

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

2526
#### Blocks
2627
`GET /rest/block/<BLOCK-HASH>.<bin|hex|json>`

test/functional/feature_segwit.py

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,31 +38,29 @@ def find_spendable_utxo(node, min_value):
3838

3939
raise AssertionError("Unspent output equal or higher than %s not found" % min_value)
4040

41+
txs_mined = {} # txindex from txid to blockhash
42+
4143
class SegWitTest(BitcoinTestFramework):
4244
def set_test_params(self):
4345
self.setup_clean_chain = True
4446
self.num_nodes = 3
4547
# This test tests SegWit both pre and post-activation, so use the normal BIP9 activation.
46-
# TODO: remove -txindex. Currently required for getrawtransaction call.
4748
self.extra_args = [
4849
[
4950
"-rpcserialversion=0",
5051
"-vbparams=segwit:0:999999999999",
5152
"-addresstype=legacy",
52-
"-txindex"
5353
],
5454
[
5555
"-blockversion=4",
5656
"-rpcserialversion=1",
5757
"-vbparams=segwit:0:999999999999",
5858
"-addresstype=legacy",
59-
"-txindex"
6059
],
6160
[
6261
"-blockversion=536870915",
6362
"-vbparams=segwit:0:999999999999",
6463
"-addresstype=legacy",
65-
"-txindex"
6664
],
6765
]
6866

@@ -157,10 +155,10 @@ def run_test(self):
157155

158156
self.log.info("Verify previous witness txs skipped for mining can now be mined")
159157
assert_equal(len(self.nodes[2].getrawmempool()), 4)
160-
block = self.nodes[2].generate(1) # block 432 (first block with new rules; 432 = 144 * 3)
158+
blockhash = self.nodes[2].generate(1)[0] # block 432 (first block with new rules; 432 = 144 * 3)
161159
sync_blocks(self.nodes)
162160
assert_equal(len(self.nodes[2].getrawmempool()), 0)
163-
segwit_tx_list = self.nodes[2].getblock(block[0])["tx"]
161+
segwit_tx_list = self.nodes[2].getblock(blockhash)["tx"]
164162
assert_equal(len(segwit_tx_list), 5)
165163

166164
self.log.info("Verify default node can't accept txs with missing witness")
@@ -174,15 +172,16 @@ def run_test(self):
174172
self.fail_accept(self.nodes[0], "mandatory-script-verify-flag", p2sh_ids[NODE_0][WIT_V1][0], False, witness_script(True, self.pubkey[0]))
175173

176174
self.log.info("Verify block and transaction serialization rpcs return differing serializations depending on rpc serialization flag")
177-
assert(self.nodes[2].getblock(block[0], False) != self.nodes[0].getblock(block[0], False))
178-
assert(self.nodes[1].getblock(block[0], False) == self.nodes[2].getblock(block[0], False))
179-
for i in range(len(segwit_tx_list)):
180-
tx = FromHex(CTransaction(), self.nodes[2].gettransaction(segwit_tx_list[i])["hex"])
181-
assert(self.nodes[2].getrawtransaction(segwit_tx_list[i]) != self.nodes[0].getrawtransaction(segwit_tx_list[i]))
182-
assert(self.nodes[1].getrawtransaction(segwit_tx_list[i], 0) == self.nodes[2].getrawtransaction(segwit_tx_list[i]))
183-
assert(self.nodes[0].getrawtransaction(segwit_tx_list[i]) != self.nodes[2].gettransaction(segwit_tx_list[i])["hex"])
184-
assert(self.nodes[1].getrawtransaction(segwit_tx_list[i]) == self.nodes[2].gettransaction(segwit_tx_list[i])["hex"])
185-
assert(self.nodes[0].getrawtransaction(segwit_tx_list[i]) == bytes_to_hex_str(tx.serialize_without_witness()))
175+
assert(self.nodes[2].getblock(blockhash, False) != self.nodes[0].getblock(blockhash, False))
176+
assert(self.nodes[1].getblock(blockhash, False) == self.nodes[2].getblock(blockhash, False))
177+
178+
for tx_id in segwit_tx_list:
179+
tx = FromHex(CTransaction(), self.nodes[2].gettransaction(tx_id)["hex"])
180+
assert(self.nodes[2].getrawtransaction(tx_id, False, blockhash) != self.nodes[0].getrawtransaction(tx_id, False, blockhash))
181+
assert(self.nodes[1].getrawtransaction(tx_id, False, blockhash) == self.nodes[2].getrawtransaction(tx_id, False, blockhash))
182+
assert(self.nodes[0].getrawtransaction(tx_id, False, blockhash) != self.nodes[2].gettransaction(tx_id)["hex"])
183+
assert(self.nodes[1].getrawtransaction(tx_id, False, blockhash) == self.nodes[2].gettransaction(tx_id)["hex"])
184+
assert(self.nodes[0].getrawtransaction(tx_id, False, blockhash) == bytes_to_hex_str(tx.serialize_without_witness()))
186185

187186
self.log.info("Verify witness txs without witness data are invalid after the fork")
188187
self.fail_accept(self.nodes[2], 'non-mandatory-script-verify-flag (Witness program hash mismatch) (code 64)', wit_ids[NODE_2][WIT_V0][2], sign=False)
@@ -538,7 +537,7 @@ def mine_and_test_listunspent(self, script_list, ismine):
538537
tx.rehash()
539538
signresults = self.nodes[0].signrawtransactionwithwallet(bytes_to_hex_str(tx.serialize_without_witness()))['hex']
540539
txid = self.nodes[0].sendrawtransaction(signresults, True)
541-
self.nodes[0].generate(1)
540+
txs_mined[txid] = self.nodes[0].generate(1)[0]
542541
sync_blocks(self.nodes)
543542
watchcount = 0
544543
spendcount = 0
@@ -581,7 +580,7 @@ def create_and_mine_tx_from_txids(self, txids, success=True):
581580
tx = CTransaction()
582581
for i in txids:
583582
txtmp = CTransaction()
584-
txraw = self.nodes[0].getrawtransaction(i)
583+
txraw = self.nodes[0].getrawtransaction(i, 0, txs_mined[i])
585584
f = BytesIO(hex_str_to_bytes(txraw))
586585
txtmp.deserialize(f)
587586
for j in range(len(txtmp.vout)):

test/functional/interface_rest.py

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ class RESTTest (BitcoinTestFramework):
4343
def set_test_params(self):
4444
self.setup_clean_chain = True
4545
self.num_nodes = 2
46-
# TODO: remove -txindex. Currently required for getrawtransaction call.
47-
self.extra_args = [["-rest", "-txindex"], []]
46+
self.extra_args = [["-rest"], []]
4847

4948
def skip_test_if_missing_module(self):
5049
self.skip_if_no_wallet()
@@ -91,25 +90,32 @@ def run_test(self):
9190

9291
txid = self.nodes[0].sendtoaddress(self.nodes[1].getnewaddress(), 0.1)
9392
self.sync_all()
94-
self.nodes[1].generatetoaddress(1, not_related_address)
95-
self.sync_all()
96-
bb_hash = self.nodes[0].getbestblockhash()
9793

98-
assert_equal(self.nodes[1].getbalance(), Decimal("0.1"))
99-
100-
self.log.info("Load the transaction using the /tx URI")
94+
self.log.info("Test the /tx URI")
10195

10296
json_obj = self.test_rest_request("/tx/{}".format(txid))
97+
assert_equal(json_obj['txid'], txid)
98+
99+
# Check hex format response
100+
hex_response = self.test_rest_request("/tx/{}".format(txid), req_type=ReqType.HEX, ret_type=RetType.OBJ)
101+
assert_greater_than_or_equal(int(hex_response.getheader('content-length')),
102+
json_obj['size']*2)
103+
103104
spent = (json_obj['vin'][0]['txid'], json_obj['vin'][0]['vout']) # get the vin to later check for utxo (should be spent by then)
104105
# get n of 0.1 outpoint
105106
n, = filter_output_indices_by_value(json_obj['vout'], Decimal('0.1'))
106107
spending = (txid, n)
107108

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

110-
json_obj = self.test_rest_request("/getutxos/{}-{}".format(*spending))
111+
self.nodes[1].generatetoaddress(1, not_related_address)
112+
self.sync_all()
113+
bb_hash = self.nodes[0].getbestblockhash()
114+
115+
assert_equal(self.nodes[1].getbalance(), Decimal("0.1"))
111116

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

115121
# Make sure there is one utxo
@@ -274,17 +280,6 @@ def run_test(self):
274280
json_obj = self.test_rest_request("/headers/5/{}".format(bb_hash))
275281
assert_equal(len(json_obj), 5) # now we should have 5 header objects
276282

277-
self.log.info("Test the /tx URI")
278-
279-
tx_hash = block_json_obj['tx'][0]['txid']
280-
json_obj = self.test_rest_request("/tx/{}".format(tx_hash))
281-
assert_equal(json_obj['txid'], tx_hash)
282-
283-
# Check hex format response
284-
hex_response = self.test_rest_request("/tx/{}".format(tx_hash), req_type=ReqType.HEX, ret_type=RetType.OBJ)
285-
assert_greater_than_or_equal(int(hex_response.getheader('content-length')),
286-
json_obj['size']*2)
287-
288283
self.log.info("Test tx inclusion in the /mempool and /block URIs")
289284

290285
# Make 3 tx and mine them on node 1

test/functional/rpc_psbt.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ class PSBTTest(BitcoinTestFramework):
2020
def set_test_params(self):
2121
self.setup_clean_chain = False
2222
self.num_nodes = 3
23-
# TODO: remove -txindex. Currently required for getrawtransaction call.
24-
self.extra_args = [["-txindex"], ["-txindex"], ["-txindex"]]
2523

2624
def skip_test_if_missing_module(self):
2725
self.skip_if_no_wallet()
@@ -161,11 +159,11 @@ def run_test(self):
161159
node1_addr = self.nodes[1].getnewaddress()
162160
node2_addr = self.nodes[2].getnewaddress()
163161
txid1 = self.nodes[0].sendtoaddress(node1_addr, 13)
164-
txid2 =self.nodes[0].sendtoaddress(node2_addr, 13)
165-
self.nodes[0].generate(6)
162+
txid2 = self.nodes[0].sendtoaddress(node2_addr, 13)
163+
blockhash = self.nodes[0].generate(6)[0]
166164
self.sync_all()
167-
vout1 = find_output(self.nodes[1], txid1, 13)
168-
vout2 = find_output(self.nodes[2], txid2, 13)
165+
vout1 = find_output(self.nodes[1], txid1, 13, blockhash=blockhash)
166+
vout2 = find_output(self.nodes[2], txid2, 13, blockhash=blockhash)
169167

170168
# Create a psbt spending outputs from nodes 1 and 2
171169
psbt_orig = self.nodes[0].createpsbt([{"txid":txid1, "vout":vout1}, {"txid":txid2, "vout":vout2}], {self.nodes[0].getnewaddress():25.999})
@@ -344,9 +342,9 @@ def run_test(self):
344342
addr = self.nodes[1].getnewaddress("", "p2sh-segwit")
345343
txid = self.nodes[0].sendtoaddress(addr, 7)
346344
addrinfo = self.nodes[1].getaddressinfo(addr)
347-
self.nodes[0].generate(6)
345+
blockhash = self.nodes[0].generate(6)[0]
348346
self.sync_all()
349-
vout = find_output(self.nodes[0], txid, 7)
347+
vout = find_output(self.nodes[0], txid, 7, blockhash=blockhash)
350348
psbt = self.nodes[1].createpsbt([{"txid":txid, "vout":vout}], {self.nodes[0].getnewaddress("", "p2sh-segwit"):Decimal('6.999')})
351349
analyzed = self.nodes[0].analyzepsbt(psbt)
352350
assert not analyzed['inputs'][0]['has_utxo'] and not analyzed['inputs'][0]['is_final'] and analyzed['inputs'][0]['next'] == 'updater' and analyzed['next'] == 'updater'

test/functional/rpc_rawtransaction.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ class RawTransactionsTest(BitcoinTestFramework):
4242
def set_test_params(self):
4343
self.setup_clean_chain = True
4444
self.num_nodes = 3
45-
# TODO: remove -txindex. Currently required for getrawtransaction call.
4645
self.extra_args = [["-addresstype=legacy", "-txindex"], ["-addresstype=legacy", "-txindex"], ["-addresstype=legacy", "-txindex"]]
4746

4847
def skip_test_if_missing_module(self):

test/functional/test_framework/util.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,12 +410,12 @@ def sync_mempools(rpc_connections, *, wait=1, timeout=60, flush_scheduler=True):
410410
# Transaction/Block functions
411411
#############################
412412

413-
def find_output(node, txid, amount):
413+
def find_output(node, txid, amount, *, blockhash=None):
414414
"""
415415
Return index to output of txid with value amount
416416
Raises exception if there is none.
417417
"""
418-
txdata = node.getrawtransaction(txid, 1)
418+
txdata = node.getrawtransaction(txid, 1, blockhash)
419419
for i in range(len(txdata["vout"])):
420420
if txdata["vout"][i]["value"] == amount:
421421
return i

test/functional/wallet_abandonconflict.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@
2626
class AbandonConflictTest(BitcoinTestFramework):
2727
def set_test_params(self):
2828
self.num_nodes = 2
29-
# TODO: remove -txindex. Currently required for getrawtransaction call.
30-
self.extra_args = [["-minrelaytxfee=0.00001", "-txindex"], []]
29+
self.extra_args = [["-minrelaytxfee=0.00001"], []]
3130

3231
def skip_test_if_missing_module(self):
3332
self.skip_if_no_wallet()

test/functional/wallet_basic.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ class WalletTest(BitcoinTestFramework):
2424
def set_test_params(self):
2525
self.num_nodes = 4
2626
self.setup_clean_chain = True
27-
# TODO: remove -txindex. Currently required for getrawtransaction call.
28-
self.extra_args = [[], [], ["-txindex"], []]
2927

3028
def skip_test_if_missing_module(self):
3129
self.skip_if_no_wallet()

0 commit comments

Comments
 (0)