2018-08-13 22:21:21 +02:00
|
|
|
#!/usr/bin/env python3
|
2020-01-17 15:42:55 +01:00
|
|
|
# Copyright (c) 2018-2020 The Dash Core developers
|
2018-08-13 22:21:21 +02:00
|
|
|
# Distributed under the MIT software license, see the accompanying
|
|
|
|
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
|
|
|
from test_framework.test_framework import BitcoinTestFramework
|
2019-10-10 13:52:35 +02:00
|
|
|
from test_framework.util import connect_nodes, wait_until
|
2018-08-13 22:21:21 +02:00
|
|
|
|
|
|
|
'''
|
|
|
|
'''
|
|
|
|
|
|
|
|
class SporkTest(BitcoinTestFramework):
|
2019-09-24 00:56:31 +02:00
|
|
|
def set_test_params(self):
|
2018-08-13 22:21:21 +02:00
|
|
|
self.num_nodes = 3
|
|
|
|
self.setup_clean_chain = True
|
2019-06-19 20:01:39 +02:00
|
|
|
self.extra_args = [["-sporkkey=cP4EKFyJsHT39LDqgdcB43Y3YXjNyjb5Fuas1GQSeAtjnZWmZEQK"], [], []]
|
2018-08-13 22:21:21 +02:00
|
|
|
|
|
|
|
def setup_network(self):
|
2019-08-09 01:14:11 +02:00
|
|
|
self.disable_mocktime()
|
2019-06-19 14:55:08 +02:00
|
|
|
self.setup_nodes()
|
2018-08-13 22:21:21 +02:00
|
|
|
# connect only 2 first nodes at start
|
|
|
|
connect_nodes(self.nodes[0], 1)
|
|
|
|
|
|
|
|
def get_test_spork_state(self, node):
|
|
|
|
info = node.spork('active')
|
|
|
|
# use InstantSend spork for tests
|
|
|
|
return info['SPORK_2_INSTANTSEND_ENABLED']
|
|
|
|
|
|
|
|
def set_test_spork_state(self, node, state):
|
|
|
|
if state:
|
|
|
|
value = 0
|
|
|
|
else:
|
|
|
|
value = 4070908800
|
|
|
|
# use InstantSend spork for tests
|
|
|
|
node.spork('SPORK_2_INSTANTSEND_ENABLED', value)
|
|
|
|
|
|
|
|
def run_test(self):
|
2020-12-01 18:48:35 +01:00
|
|
|
spork_default_state = self.get_test_spork_state(self.nodes[0])
|
|
|
|
# check test spork default state matches on all nodes
|
|
|
|
assert(self.get_test_spork_state(self.nodes[1]) == spork_default_state)
|
|
|
|
assert(self.get_test_spork_state(self.nodes[2]) == spork_default_state)
|
2018-08-13 22:21:21 +02:00
|
|
|
|
|
|
|
# check spork propagation for connected nodes
|
2020-12-01 18:48:35 +01:00
|
|
|
spork_new_state = not spork_default_state
|
|
|
|
self.set_test_spork_state(self.nodes[0], spork_new_state)
|
2019-10-10 13:52:35 +02:00
|
|
|
wait_until(lambda: self.get_test_spork_state(self.nodes[1]), sleep=0.1, timeout=10)
|
2018-08-13 22:21:21 +02:00
|
|
|
|
|
|
|
# restart nodes to check spork persistence
|
2019-07-04 16:48:01 +02:00
|
|
|
self.stop_node(0)
|
|
|
|
self.stop_node(1)
|
2019-09-24 00:56:31 +02:00
|
|
|
self.start_node(0)
|
|
|
|
self.start_node(1)
|
2020-12-01 18:48:35 +01:00
|
|
|
assert(self.get_test_spork_state(self.nodes[0]) == spork_new_state)
|
|
|
|
assert(self.get_test_spork_state(self.nodes[1]) == spork_new_state)
|
2018-08-13 22:21:21 +02:00
|
|
|
|
2018-12-06 14:43:36 +01:00
|
|
|
# Generate one block to kick off masternode sync, which also starts sporks syncing for node2
|
|
|
|
self.nodes[1].generate(1)
|
|
|
|
|
2018-08-13 22:21:21 +02:00
|
|
|
# connect new node and check spork propagation after restoring from cache
|
|
|
|
connect_nodes(self.nodes[1], 2)
|
2019-10-10 13:52:35 +02:00
|
|
|
wait_until(lambda: self.get_test_spork_state(self.nodes[2]), sleep=0.1, timeout=10)
|
2018-08-13 22:21:21 +02:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
SporkTest().main()
|