mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-07-28 13:22:43 +02:00
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.
This commit is contained in:
@@ -11,7 +11,6 @@ The assumeutxo value generated and used here is committed to in
|
|||||||
|
|
||||||
## Possible test improvements
|
## Possible test improvements
|
||||||
|
|
||||||
- TODO: test submitting a transaction and verifying it appears in mempool
|
|
||||||
- TODO: test what happens with -reindex and -reindex-chainstate before the
|
- TODO: test what happens with -reindex and -reindex-chainstate before the
|
||||||
snapshot is validated, and make sure it's deleted successfully.
|
snapshot is validated, and make sure it's deleted successfully.
|
||||||
|
|
||||||
@@ -35,11 +34,14 @@ Interesting starting states could be loading a snapshot when the current chain t
|
|||||||
"""
|
"""
|
||||||
from shutil import rmtree
|
from shutil import rmtree
|
||||||
|
|
||||||
|
from test_framework.messages import tx_from_hex
|
||||||
from test_framework.test_framework import BitcoinTestFramework
|
from test_framework.test_framework import BitcoinTestFramework
|
||||||
from test_framework.util import (
|
from test_framework.util import (
|
||||||
assert_equal,
|
assert_equal,
|
||||||
assert_raises_rpc_error,
|
assert_raises_rpc_error,
|
||||||
)
|
)
|
||||||
|
from test_framework.wallet import getnewdestination
|
||||||
|
|
||||||
|
|
||||||
START_HEIGHT = 199
|
START_HEIGHT = 199
|
||||||
SNAPSHOT_BASE_HEIGHT = 299
|
SNAPSHOT_BASE_HEIGHT = 299
|
||||||
@@ -207,6 +209,22 @@ class AssumeutxoTest(BitcoinTestFramework):
|
|||||||
|
|
||||||
assert_equal(n1.getblockchaininfo()["blocks"], SNAPSHOT_BASE_HEIGHT)
|
assert_equal(n1.getblockchaininfo()["blocks"], SNAPSHOT_BASE_HEIGHT)
|
||||||
|
|
||||||
|
self.log.info("Submit a spending transaction for a snapshot chainstate coin to the mempool")
|
||||||
|
# spend the coinbase output of the first block that is not available on node1
|
||||||
|
spend_coin_blockhash = n1.getblockhash(START_HEIGHT + 1)
|
||||||
|
assert_raises_rpc_error(-1, "Block not found on disk", n1.getblock, spend_coin_blockhash)
|
||||||
|
prev_tx = n0.getblock(spend_coin_blockhash, 3)['tx'][0]
|
||||||
|
prevout = {"txid": prev_tx['txid'], "vout": 0, "scriptPubKey": prev_tx['vout'][0]['scriptPubKey']['hex']}
|
||||||
|
privkey = n0.get_deterministic_priv_key().key
|
||||||
|
raw_tx = n1.createrawtransaction([prevout], {getnewdestination()[2]: 24.99})
|
||||||
|
signed_tx = n1.signrawtransactionwithkey(raw_tx, [privkey], [prevout])['hex']
|
||||||
|
signed_txid = tx_from_hex(signed_tx).rehash()
|
||||||
|
|
||||||
|
assert n1.gettxout(prev_tx['txid'], 0) is not None
|
||||||
|
n1.sendrawtransaction(signed_tx)
|
||||||
|
assert signed_txid in n1.getrawmempool()
|
||||||
|
assert not n1.gettxout(prev_tx['txid'], 0)
|
||||||
|
|
||||||
PAUSE_HEIGHT = FINAL_HEIGHT - 40
|
PAUSE_HEIGHT = FINAL_HEIGHT - 40
|
||||||
|
|
||||||
self.log.info("Restarting node to stop at height %d", PAUSE_HEIGHT)
|
self.log.info("Restarting node to stop at height %d", PAUSE_HEIGHT)
|
||||||
|
Reference in New Issue
Block a user