Skip to content

Commit 9315754

Browse files
committed
test: assumeutxo: spend coin from snapshot chainstate after loading
Check that an UTXO that is only available in the snapshot chainstate is also visible to the mempool by submitting a spending transaction.
1 parent 063a8b8 commit 9315754

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

test/functional/feature_assumeutxo.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
1212
## Possible test improvements
1313
14-
- TODO: test submitting a transaction and verifying it appears in mempool
1514
- TODO: test what happens with -reindex and -reindex-chainstate before the
1615
snapshot is validated, and make sure it's deleted successfully.
1716
@@ -35,11 +34,14 @@
3534
"""
3635
from shutil import rmtree
3736

37+
from test_framework.messages import tx_from_hex
3838
from test_framework.test_framework import BitcoinTestFramework
3939
from test_framework.util import (
4040
assert_equal,
4141
assert_raises_rpc_error,
4242
)
43+
from test_framework.wallet import getnewdestination
44+
4345

4446
START_HEIGHT = 199
4547
SNAPSHOT_BASE_HEIGHT = 299
@@ -207,6 +209,22 @@ def run_test(self):
207209

208210
assert_equal(n1.getblockchaininfo()["blocks"], SNAPSHOT_BASE_HEIGHT)
209211

212+
self.log.info("Submit a spending transaction for a snapshot chainstate coin to the mempool")
213+
# spend the coinbase output of the first block that is not available on node1
214+
spend_coin_blockhash = n1.getblockhash(START_HEIGHT + 1)
215+
assert_raises_rpc_error(-1, "Block not found on disk", n1.getblock, spend_coin_blockhash)
216+
prev_tx = n0.getblock(spend_coin_blockhash, 3)['tx'][0]
217+
prevout = {"txid": prev_tx['txid'], "vout": 0, "scriptPubKey": prev_tx['vout'][0]['scriptPubKey']['hex']}
218+
privkey = n0.get_deterministic_priv_key().key
219+
raw_tx = n1.createrawtransaction([prevout], {getnewdestination()[2]: 24.99})
220+
signed_tx = n1.signrawtransactionwithkey(raw_tx, [privkey], [prevout])['hex']
221+
signed_txid = tx_from_hex(signed_tx).rehash()
222+
223+
assert n1.gettxout(prev_tx['txid'], 0) is not None
224+
n1.sendrawtransaction(signed_tx)
225+
assert signed_txid in n1.getrawmempool()
226+
assert not n1.gettxout(prev_tx['txid'], 0)
227+
210228
PAUSE_HEIGHT = FINAL_HEIGHT - 40
211229

212230
self.log.info("Restarting node to stop at height %d", PAUSE_HEIGHT)

0 commit comments

Comments
 (0)