Skip to content

Commit b23efb2

Browse files
committed
Improve coinbase and issuance tx testing for txindex
1 parent 91ad748 commit b23efb2

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

test/functional/feature_connect_genesis_outputs.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def set_test_params(self):
1616
self.num_nodes = 2
1717
self.setup_clean_chain = True
1818
# First node doesn't connect coinbase output to db, second does
19-
self.extra_args = [["-con_connect_genesis_outputs=0", "-initialfreecoins={}".format(NUM_INITIAL_COINS * COIN)],
19+
self.extra_args = [["-con_connect_genesis_outputs=0", "-initialfreecoins={}".format(NUM_INITIAL_COINS * COIN), '-txindex=1'],
2020
["-con_connect_genesis_outputs=1", "-initialfreecoins={}".format(NUM_INITIAL_COINS * COIN), '-anyonecanspendaremine=1']]
2121

2222
def skip_test_if_missing_module(self):
@@ -49,15 +49,22 @@ def run_test(self):
4949
assert_equal(unspent[0]["amount"], NUM_INITIAL_COINS)
5050
assert_equal(unspent[0]["confirmations"], 1)
5151

52-
# Test rpc getraw functionality
52+
# Test rpc getraw functionality.
5353

54-
# Coinbase transaction is provably unspendable (OP_RETURN), so even AddCoin won't add it
55-
assert_raises_rpc_error(-5, "No such mempool transaction. Use -txindex to enable blockchain transaction queries. Use gettransaction for wallet transactions.", self.nodes[0].getrawtransaction, coinbase_tx)
56-
assert_raises_rpc_error(-5, "No such mempool transaction. Use -txindex to enable blockchain transaction queries. Use gettransaction for wallet transactions.", self.nodes[1].getrawtransaction, coinbase_tx)
54+
# Node 0 has txindex.
55+
self.nodes[0].getrawtransaction(coinbase_tx, False)
56+
self.nodes[0].getrawtransaction(issuance_tx, False)
5757

58-
# Issuance transaction is an OP_TRUE, so will be available to second node
59-
assert_raises_rpc_error(-5, "No such mempool transaction. Use -txindex to enable blockchain transaction queries. Use gettransaction for wallet transactions.", self.nodes[0].getrawtransaction, issuance_tx)
58+
# Node 1 doesn't.
59+
assert_raises_rpc_error(-5, "No such mempool transaction. Use -txindex to enable blockchain transaction queries. Use gettransaction for wallet transactions.", self.nodes[1].getrawtransaction, coinbase_tx)
60+
assert_raises_rpc_error(-5, "No such mempool transaction. Use -txindex to enable blockchain transaction queries. Use gettransaction for wallet transactions.", self.nodes[1].getrawtransaction, issuance_tx)
61+
# But it can still access them by providing the genesis block hash.
62+
self.nodes[1].getrawtransaction(coinbase_tx, False, self.nodes[0].getblockhash(0))
6063
self.nodes[1].getrawtransaction(issuance_tx, False, self.nodes[0].getblockhash(0))
6164

65+
# Because the issuance tx is OP_TRUE, node 1 (with anyonecanspendaremine) has them in the wallet.
66+
assert_raises_rpc_error(-5, "Invalid or non-wallet transaction id", self.nodes[0].gettransaction, issuance_tx)
67+
self.nodes[1].gettransaction(issuance_tx)
68+
6269
if __name__ == '__main__':
6370
ConnectGenesisTest().main()

0 commit comments

Comments
 (0)