Skip to content

Commit 881724d

Browse files
committed
test: Added test coverage to listsinceblock rpc
This change adds a test to add coverage to the rpc error that emmits the message "Can't read block from disk"
1 parent f157785 commit 881724d

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

test/functional/wallet_listsinceblock.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ def run_test(self):
4040
self.test_no_blockhash()
4141
self.test_invalid_blockhash()
4242
self.test_reorg()
43+
self.test_cant_read_block()
4344
self.test_double_spend()
4445
self.test_double_send()
4546
self.double_spends_filtered()
@@ -167,6 +168,31 @@ def test_reorg(self):
167168
found = next(tx for tx in transactions if tx['txid'] == senttx)
168169
assert_equal(found['blockheight'], self.nodes[0].getblockheader(nodes2_first_blockhash)['height'])
169170

171+
def test_cant_read_block(self):
172+
self.log.info('Test the RPC error "Can\'t read block from disk"')
173+
174+
# Split network into two
175+
self.split_network()
176+
177+
# generate on both sides
178+
nodes1_last_blockhash = self.generate(self.nodes[1], 6, sync_fun=lambda: self.sync_all(self.nodes[:2]))[-1]
179+
self.generate(self.nodes[2], 7, sync_fun=lambda: self.sync_all(self.nodes[2:]))[0]
180+
181+
self.join_network()
182+
183+
# Renaming the block file to induce unsuccessful block read
184+
blk_dat = (self.nodes[0].blocks_path / "blk00000.dat")
185+
blk_dat_moved = blk_dat.rename(self.nodes[0].blocks_path / "blk00000.dat.moved")
186+
assert not blk_dat.exists()
187+
188+
# listsinceblock(nodes1_last_blockhash) should now fail as blocks are not accessible
189+
assert_raises_rpc_error(-32603, "Can't read block from disk",
190+
self.nodes[0].listsinceblock, nodes1_last_blockhash)
191+
192+
# Restoring block file
193+
blk_dat_moved.rename(self.nodes[0].blocks_path / "blk00000.dat")
194+
assert blk_dat.exists()
195+
170196
def test_double_spend(self):
171197
'''
172198
This tests the case where the same UTXO is spent twice on two separate

0 commit comments

Comments
 (0)