mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 12:02:48 +01:00
test: Optimize feature_block_reward_reallocation.py (#3743)
* test: Optimize feature_block_reward_reallocation.py Signed-off-by: pasta <pasta@dashboost.org> * use submitblock instead of p2p.send_blocks_and_test in one more place * drop empty line * make sure all nodes are synced after reallocation is done Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
This commit is contained in:
parent
24dfb64c9f
commit
7058fd7dfc
@ -3,7 +3,8 @@
|
||||
# Distributed under the MIT software license, see the accompanying
|
||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
from test_framework.blocktools import create_block, create_coinbase, get_masternode_payment
|
||||
from test_framework.mininode import *
|
||||
from test_framework.mininode import P2PDataStore, network_thread_start
|
||||
from test_framework.messages import CTxOut, FromHex, CCbTx, CTransaction, ToHex
|
||||
from test_framework.script import CScript
|
||||
from test_framework.test_framework import DashTestFramework
|
||||
from test_framework.util import assert_equal, get_bip9_status, hex_str_to_bytes
|
||||
@ -15,9 +16,10 @@ Checks block reward reallocation correctness
|
||||
|
||||
'''
|
||||
|
||||
|
||||
class BlockRewardReallocationTest(DashTestFramework):
|
||||
def set_test_params(self):
|
||||
self.set_dash_test_params(4, 3, fast_dip3_enforcement=True)
|
||||
self.set_dash_test_params(2, 1, fast_dip3_enforcement=True)
|
||||
self.set_dash_dip8_activation(450)
|
||||
|
||||
# 536870912 == 0x20000000, i.e. not signalling for anything
|
||||
@ -56,18 +58,15 @@ class BlockRewardReallocationTest(DashTestFramework):
|
||||
# create and send non-signalling blocks
|
||||
for i in range(500 - num_blocks):
|
||||
test_block = self.create_test_block()
|
||||
self.nodes[0].p2p.send_blocks_and_test([test_block], self.nodes[0], timeout=5)
|
||||
self.nodes[0].submitblock(ToHex(test_block))
|
||||
# generate at most 10 signaling blocks at a time
|
||||
if num_blocks > 0:
|
||||
for i in range((num_blocks - 1) // 10):
|
||||
self.bump_mocktime(10)
|
||||
self.nodes[0].generate(10)
|
||||
self.sync_blocks()
|
||||
self.nodes[0].generate((num_blocks - 1) % 10)
|
||||
self.sync_blocks()
|
||||
assert_equal(get_bip9_status(self.nodes[0], 'realloc')['status'], 'started')
|
||||
self.nodes[0].generate(1)
|
||||
self.sync_blocks()
|
||||
if expected_lockin:
|
||||
assert_equal(get_bip9_status(self.nodes[0], 'realloc')['status'], 'locked_in')
|
||||
else:
|
||||
@ -84,7 +83,6 @@ class BlockRewardReallocationTest(DashTestFramework):
|
||||
while get_bip9_status(self.nodes[0], 'dip0003')['status'] != 'active':
|
||||
self.bump_mocktime(10)
|
||||
self.nodes[0].generate(10)
|
||||
self.sync_blocks()
|
||||
|
||||
self.nodes[0].add_p2p_connection(P2PDataStore())
|
||||
network_thread_start()
|
||||
@ -95,7 +93,6 @@ class BlockRewardReallocationTest(DashTestFramework):
|
||||
for i in range(498 - bi['blocks']):
|
||||
self.bump_mocktime(1)
|
||||
self.nodes[0].generate(1)
|
||||
self.sync_blocks()
|
||||
|
||||
self.log.info("Initial state is DEFINED")
|
||||
bi = self.nodes[0].getblockchaininfo()
|
||||
@ -130,9 +127,7 @@ class BlockRewardReallocationTest(DashTestFramework):
|
||||
for i in range(49):
|
||||
self.bump_mocktime(10)
|
||||
self.nodes[0].generate(10)
|
||||
self.sync_blocks()
|
||||
self.nodes[0].generate(9)
|
||||
self.sync_blocks()
|
||||
|
||||
self.log.info("Still LOCKED_IN at height = 2498")
|
||||
bi = self.nodes[0].getblockchaininfo()
|
||||
@ -152,7 +147,6 @@ class BlockRewardReallocationTest(DashTestFramework):
|
||||
assert_equal(bt['height'], 2500)
|
||||
assert_equal(bt['masternode'][0]['amount'], get_masternode_payment(bt['height'], bt['coinbasevalue'], 2500))
|
||||
self.nodes[0].generate(9)
|
||||
self.sync_blocks()
|
||||
bt = self.nodes[0].getblocktemplate()
|
||||
assert_equal(bt['masternode'][0]['amount'], get_masternode_payment(bt['height'], bt['coinbasevalue'], 2500))
|
||||
assert_equal(bt['coinbasevalue'], 13748571607)
|
||||
@ -163,7 +157,6 @@ class BlockRewardReallocationTest(DashTestFramework):
|
||||
for i in range(3):
|
||||
self.bump_mocktime(10)
|
||||
self.nodes[0].generate(10)
|
||||
self.sync_blocks()
|
||||
bt = self.nodes[0].getblocktemplate()
|
||||
assert_equal(bt['masternode'][0]['amount'], get_masternode_payment(bt['height'], bt['coinbasevalue'], 2500))
|
||||
|
||||
@ -175,20 +168,21 @@ class BlockRewardReallocationTest(DashTestFramework):
|
||||
for period in range(10): # check 10 next superblocks
|
||||
self.bump_mocktime(10)
|
||||
self.nodes[0].generate(10)
|
||||
self.sync_blocks()
|
||||
bt = self.nodes[0].getblocktemplate()
|
||||
assert_equal(bt['masternode'][0]['amount'], get_masternode_payment(bt['height'], bt['coinbasevalue'], 2500))
|
||||
assert_equal(bt['coinbasevalue'], 9491484944)
|
||||
assert_equal(bt['masternode'][0]['amount'], 5694890966) # 0.6
|
||||
|
||||
# make sure all nodes are still synced
|
||||
self.sync_all()
|
||||
|
||||
self.log.info("Rollback the chain back to the STARTED state")
|
||||
self.mocktime = self.nodes[0].getblock(pre_locked_in_blockhash, 1)['time']
|
||||
for node in self.nodes:
|
||||
node.invalidateblock(pre_locked_in_blockhash)
|
||||
self.sync_all()
|
||||
# create and send non-signalling block
|
||||
test_block = self.create_test_block()
|
||||
self.nodes[0].p2p.send_blocks_and_test([test_block], self.nodes[0], timeout=5)
|
||||
self.nodes[0].submitblock(ToHex(test_block))
|
||||
bi = self.nodes[0].getblockchaininfo()
|
||||
assert_equal(bi['blocks'], 1499)
|
||||
assert_equal(bi['bip9_softforks']['realloc']['status'], 'started')
|
||||
@ -203,5 +197,6 @@ class BlockRewardReallocationTest(DashTestFramework):
|
||||
assert_equal(bi['bip9_softforks']['realloc']['statistics']['threshold'], self.threshold(i + 3))
|
||||
assert_equal(bi['bip9_softforks']['realloc']['statistics']['threshold'], 300)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
BlockRewardReallocationTest().main()
|
||||
|
Loading…
Reference in New Issue
Block a user