Skip to content

Commit

Permalink
test: Added test coverage to listsinceblock rpc
Browse files Browse the repository at this point in the history
This change adds a test to add coverage to the rpc error that emmits the message "Can't
read block from disk"
  • Loading branch information
kevkevinpal committed Jun 6, 2024
1 parent f157785 commit 21bc4ff
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions test/functional/wallet_listsinceblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def run_test(self):
self.test_no_blockhash()
self.test_invalid_blockhash()
self.test_reorg()
self.test_cant_read_block()
self.test_double_spend()
self.test_double_send()
self.double_spends_filtered()
Expand Down Expand Up @@ -167,6 +168,28 @@ def test_reorg(self):
found = next(tx for tx in transactions if tx['txid'] == senttx)
assert_equal(found['blockheight'], self.nodes[0].getblockheader(nodes2_first_blockhash)['height'])

def test_cant_read_block(self):
self.log.info('Test the RPC error "Can\'t read block from disk"')

# Split network into two
self.split_network()

# generate on both sides
nodes1_last_blockhash = self.generate(self.nodes[1], 6, sync_fun=lambda: self.sync_all(self.nodes[:2]))[-1]
self.generate(self.nodes[2], 7, sync_fun=lambda: self.sync_all(self.nodes[2:]))[0]

self.join_network()

# Renaming the block file to induce unsuccessful block read
(self.nodes[0].blocks_path / "blk00000.dat").rename(self.nodes[0].blocks_path / "blk00000.dat.copy")

# listsinceblock(nodes1_last_blockhash) should now fail as blocks are not accessible
assert_raises_rpc_error(-32603, "Can't read block from disk",
self.nodes[0].listsinceblock, nodes1_last_blockhash)

# Restoring block file
(self.nodes[0].blocks_path / "blk00000.dat.copy").rename(self.nodes[0].blocks_path / "blk00000.dat")

def test_double_spend(self):
'''
This tests the case where the same UTXO is spent twice on two separate
Expand Down

0 comments on commit 21bc4ff

Please sign in to comment.