2018-08-13 22:21:21 +02:00
|
|
|
#!/usr/bin/env python3
|
2023-12-31 01:00:00 +01:00
|
|
|
# Copyright (c) 2018-2023 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
|
|
|
|
|
|
|
|
'''
|
|
|
|
'''
|
|
|
|
|
|
|
|
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
|
2024-08-30 09:47:15 +02:00
|
|
|
self.disable_mocktime = 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-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
|
2022-09-24 14:36:35 +02:00
|
|
|
self.connect_nodes(0, 1)
|
2018-08-13 22:21:21 +02:00
|
|
|
|
|
|
|
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
|
2022-06-18 18:52:45 +02:00
|
|
|
node.sporkupdate("SPORK_2_INSTANTSEND_ENABLED", value)
|
2018-08-13 22:21:21 +02:00
|
|
|
|
|
|
|
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
|
2021-08-27 21:03:02 +02:00
|
|
|
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)
|
2020-09-03 05:47:08 +02:00
|
|
|
self.wait_until(lambda: self.get_test_spork_state(self.nodes[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)
|
2021-08-27 21:03:02 +02: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
|
2024-10-01 21:22:56 +02:00
|
|
|
self.generate(self.nodes[1], 1, sync_fun=self.no_op)
|
2018-12-06 14:43:36 +01:00
|
|
|
|
2018-08-13 22:21:21 +02:00
|
|
|
# connect new node and check spork propagation after restoring from cache
|
2022-09-24 14:36:35 +02:00
|
|
|
self.connect_nodes(1, 2)
|
2020-09-03 05:47:08 +02:00
|
|
|
self.wait_until(lambda: self.get_test_spork_state(self.nodes[2]), timeout=10)
|
2018-08-13 22:21:21 +02:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
SporkTest().main()
|