2018-08-13 22:21:21 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# Copyright (c) 2018 The Dash Core developers
|
|
|
|
# Distributed under the MIT software license, see the accompanying
|
|
|
|
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
2019-08-28 13:51:59 +02:00
|
|
|
import time
|
2018-08-13 22:21:21 +02:00
|
|
|
|
|
|
|
from test_framework.mininode import *
|
|
|
|
from test_framework.test_framework import BitcoinTestFramework
|
|
|
|
from test_framework.util import *
|
|
|
|
|
|
|
|
'''
|
|
|
|
'''
|
|
|
|
|
|
|
|
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):
|
|
|
|
# check test spork default state
|
2019-07-09 16:50:08 +02:00
|
|
|
assert(not self.get_test_spork_state(self.nodes[0]))
|
|
|
|
assert(not self.get_test_spork_state(self.nodes[1]))
|
|
|
|
assert(not self.get_test_spork_state(self.nodes[2]))
|
2018-08-13 22:21:21 +02:00
|
|
|
|
|
|
|
# check spork propagation for connected nodes
|
2019-07-09 16:50:08 +02:00
|
|
|
self.set_test_spork_state(self.nodes[0], True)
|
2019-08-28 13:51:59 +02:00
|
|
|
start = time.time()
|
2018-08-13 22:21:21 +02:00
|
|
|
sent = False
|
|
|
|
while True:
|
2019-07-09 16:50:08 +02:00
|
|
|
if self.get_test_spork_state(self.nodes[1]):
|
2018-08-13 22:21:21 +02:00
|
|
|
sent = True
|
|
|
|
break
|
2019-08-28 13:51:59 +02:00
|
|
|
if time.time() > start + 10:
|
2018-08-13 22:21:21 +02:00
|
|
|
break
|
2019-08-28 13:51:59 +02:00
|
|
|
time.sleep(0.1)
|
2018-08-13 22:21:21 +02:00
|
|
|
assert(sent)
|
|
|
|
|
|
|
|
# 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)
|
2019-07-09 16:50:08 +02:00
|
|
|
assert(self.get_test_spork_state(self.nodes[0]))
|
|
|
|
assert(self.get_test_spork_state(self.nodes[1]))
|
2018-08-13 22:21:21 +02:00
|
|
|
|
2018-12-06 14:43:36 +01:00
|
|
|
# Force finish mnsync node as otherwise it will never send out headers to other peers
|
|
|
|
wait_to_sync(self.nodes[1], fast_mnsync=True)
|
|
|
|
|
|
|
|
# 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-08-28 13:51:59 +02:00
|
|
|
start = time.time()
|
2018-08-13 22:21:21 +02:00
|
|
|
sent = False
|
|
|
|
while True:
|
2019-07-09 16:50:08 +02:00
|
|
|
if self.get_test_spork_state(self.nodes[2]):
|
2018-08-13 22:21:21 +02:00
|
|
|
sent = True
|
|
|
|
break
|
2019-08-28 13:51:59 +02:00
|
|
|
if time.time() > start + 10:
|
2018-08-13 22:21:21 +02:00
|
|
|
break
|
2019-08-28 13:51:59 +02:00
|
|
|
time.sleep(0.1)
|
2018-08-13 22:21:21 +02:00
|
|
|
assert(sent)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
SporkTest().main()
|