forked from bitcoin/bitcoin
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#!/usr/bin/env python3 | ||
# Copyright (c) 2018-2023 The Dash Core developers | ||
# 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): | ||
def set_test_params(self): | ||
self.num_nodes = 3 | ||
self.setup_clean_chain = True | ||
self.extra_args = [["-sporkkey=cP4EKFyJsHT39LDqgdcB43Y3YXjNyjb5Fuas1GQSeAtjnZWmZEQK"], [], []] | ||
|
||
def setup_network(self): | ||
self.disable_mocktime() | ||
self.setup_nodes() | ||
# connect only 2 first nodes at start | ||
self.connect_nodes(0, 1) | ||
|
||
def get_test_spork_value(self, node): | ||
# use InstantSend spork for tests | ||
return node.spork()['SPORK_2_INSTANTSEND_ENABLED'] | ||
|
||
def set_test_spork_value(self, node, value): | ||
# use InstantSend spork for tests | ||
node.sporkupdate("SPORK_2_INSTANTSEND_ENABLED", value) | ||
|
||
def run_test(self): | ||
spork_default_value = self.get_test_spork_value(self.nodes[0]) | ||
# check test spork default state matches on all nodes | ||
assert self.get_test_spork_value(self.nodes[1]) == spork_default_value | ||
assert self.get_test_spork_value(self.nodes[2]) == spork_default_value | ||
|
||
# check spork propagation for connected nodes | ||
spork_new_value = spork_default_value + 1 | ||
self.set_test_spork_value(self.nodes[0], spork_new_value) | ||
self.wait_until(lambda: self.get_test_spork_value(self.nodes[1]) == spork_new_value, timeout=10) | ||
|
||
# restart nodes to check spork persistence | ||
self.stop_node(0) | ||
self.stop_node(1) | ||
self.start_node(0) | ||
self.start_node(1) | ||
assert self.get_test_spork_value(self.nodes[0]) == spork_new_value | ||
assert self.get_test_spork_value(self.nodes[1]) == spork_new_value | ||
|
||
# Generate one block to kick off masternode sync, which also starts sporks syncing for node2 | ||
self.nodes[1].generate(1) | ||
|
||
# connect new node and check spork propagation after restoring from cache | ||
self.connect_nodes(1, 2) | ||
self.wait_until(lambda: self.get_test_spork_value(self.nodes[2]) == spork_new_value, timeout=10) | ||
|
||
if __name__ == '__main__': | ||
SporkTest().main() |