forked from decenomy/DSW
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrpc_spork.py
More file actions
executable file
·74 lines (57 loc) · 2.73 KB
/
rpc_spork.py
File metadata and controls
executable file
·74 lines (57 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env python3
# Copyright (c) 2019-2020 The PIVX developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
# -*- coding: utf-8 -*-
from time import sleep
from test_framework.test_framework import PivxTestFramework
from test_framework.util import set_node_times, assert_equal
class PIVX_RPCSporkTest(PivxTestFramework):
def set_test_params(self):
self.setup_clean_chain = True
self.num_nodes = 2
self.extra_args = [[]] * self.num_nodes
self.extra_args[0].append('-sporkkey=932HEevBSujW2ud7RfB1YF91AFygbBRQj3de3LyaCRqNzKKgWXi')
def setup_chain(self):
# Start with clean chain
self._initialize_chain_clean()
self.enable_mocktime()
def log_title(self):
title = "*** Starting %s ***" % self.__class__.__name__
underline = "-" * len(title)
description = "Performs tests on the Spork RPC"
self.log.info("\n\n%s\n%s\n%s\n", title, underline, description)
def run_test(self):
self.log_title()
set_node_times(self.nodes, self.mocktime)
sporkName = "SPORK_8_MASTERNODE_PAYMENT_ENFORCEMENT"
# 0 - check SPORK 8 status from node 1 (must be inactive)
assert_equal(False, self.is_spork_active(1, sporkName))
# 1 - activate SPORK 8 with nodes[0]
assert_equal("success", self.activate_spork(0, sporkName))
sleep(1)
# check SPORK 8 status from nodes[1] (must be active)
assert_equal(True, self.is_spork_active(1, sporkName))
# 2 - Adjust time to 1 sec in the future and deactivate SPORK 8 with node[0]
self.mocktime += 1
set_node_times(self.nodes, self.mocktime)
assert_equal("success", self.deactivate_spork(0, sporkName))
sleep(1)
# check SPORK 8 value from nodes[1] (must be inactive again)
assert_equal(False, self.is_spork_active(1, sporkName))
# 3 - Adjust time to 1 sec in the future and set new value (mocktime) for SPORK 8 with node[0]
self.mocktime += 1
set_node_times(self.nodes, self.mocktime)
assert_equal("success", self.set_spork(0, sporkName, self.mocktime))
sleep(1)
# check SPORK 8 value from nodes[1] (must be equal to mocktime)
assert_equal(self.mocktime, self.get_spork(1, sporkName))
# 4 - Stop nodes and check value again after restart
self.log.info("Stopping nodes...")
self.stop_nodes()
self.log.info("Restarting node 1...")
self.start_node(1, [])
assert_equal(self.mocktime, self.get_spork(1, sporkName))
self.log.info("%s: TEST PASSED" % self.__class__.__name__)
if __name__ == '__main__':
PIVX_RPCSporkTest().main()