Skip to content

Commit 88e0dc6

Browse files
random-zebrafurszy
authored andcommitted
pivx_fake_stake Test05 - more blocks fix
1 parent bf3b732 commit 88e0dc6

File tree

1 file changed

+26
-13
lines changed

1 file changed

+26
-13
lines changed

test/functional/fake_stake/test05.py

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python3
22
# -*- coding: utf-8 -*-
3-
3+
from random import randint
44
import time
55

66
from test_framework.authproxy import JSONRPCException
@@ -19,7 +19,7 @@ class Test_05(PIVX_FakeStakeTest):
1919
def run_test(self):
2020
self.init_test()
2121
INITAL_MINED_BLOCKS = 300
22-
self.NUM_BLOCKS = 10
22+
self.NUM_BLOCKS = 3
2323

2424
# 1) Starting mining blocks
2525
self.log.info("Mining %d blocks.." % INITAL_MINED_BLOCKS)
@@ -38,38 +38,51 @@ def run_test(self):
3838
block_count = self.node.getblockcount()
3939
pastBlockHash = self.node.getblockhash(block_count)
4040
block = self.create_spam_block(pastBlockHash, stakingPrevOuts, block_count + 1, True)
41-
self.log.info("Sending block %d", block_count + 1)
41+
self.log.info("Sending block %d [%s...]", block_count + 1, block.hash[:7])
4242
var = self.node.submitblock(bytes_to_hex_str(block.serialize()))
4343
assert_equal(var, None)
44-
self.log_data_dir_size()
4544

4645
try:
4746
block_ret = self.node.getblock(block.hash)
4847
if block_ret is not None:
4948
raise AssertionError("Error, block stored in main chain")
50-
except JSONRPCException as error:
51-
self.log.info(error)
49+
except JSONRPCException as e:
50+
err_msg = str(e)
51+
if err_msg == "Can't read block from disk (-32603)":
52+
err_msg = "Good. Block was not stored on disk."
53+
self.log.info(err_msg)
54+
55+
# remove a random prevout from the list (to randomize block creation)
56+
stakingPrevOuts.popitem()
5257

5358
self.log.info("Sent all %s blocks." % str(self.NUM_BLOCKS))
59+
self.log_data_dir_size()
5460
time.sleep(3)
5561

5662
# 4) Spam Blocks on a forked chain
63+
# regenerate prevouts
64+
self.log.info("Mining %d more blocks as buffer..." % 31)
65+
self.node.generate(31)
66+
stakingPrevOuts = self.get_prevouts(utxo_list)
5767
for i in range(0, self.NUM_BLOCKS):
5868
if i !=0:
5969
self.log.info("Sent %s blocks out of %s" % (str(i), str(self.NUM_BLOCKS)))
60-
block_count = self.node.getblockcount() - 20
61-
pastBlockHash = self.node.getblockhash(block_count)
62-
block = self.create_spam_block(pastBlockHash, stakingPrevOuts, block_count + 1, True)
63-
self.log.info("Sending block %d", block_count + 1)
70+
randomCount = randint(block_count - 30, block_count)
71+
pastBlockHash = self.node.getblockhash(randomCount)
72+
block = self.create_spam_block(pastBlockHash, stakingPrevOuts, randomCount + 1, True)
73+
self.log.info("Sending block %d [%s...]", randomCount + 1, block.hash[:7])
6474
var = self.node.submitblock(bytes_to_hex_str(block.serialize()))
6575
assert_equal(var, None)
66-
self.log_data_dir_size()
6776

6877
try:
6978
block_ret = self.node.getblock(block.hash)
7079
if block_ret is not None:
7180
raise AssertionError("Error, block stored in forked chain")
72-
except JSONRPCException as error:
73-
self.log.info(error)
81+
except JSONRPCException as e:
82+
err_msg = str(e)
83+
if err_msg == "Can't read block from disk (-32603)":
84+
err_msg = "Good. Block was not stored on disk."
85+
self.log.info(err_msg)
7486

7587
self.log.info("Sent all %s blocks." % str(self.NUM_BLOCKS))
88+
self.log_data_dir_size()

0 commit comments

Comments
 (0)