generated from Juma-creator/Juma-creator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClean and fix
100 lines (78 loc) · 3.04 KB
/
Clean and fix
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
server=1
rpcuser=Ariel369369
rpcpassword=securepassword
import logging
import time
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__Ariel369369__)
from bitcoin.test_framework.test_framework import TestFramework
from bitcoin.test_framework.test_node import TestNode
class FeatureFrameworkRPCFailure(TestFramework):
def __init__(self, test_name):
super().__init__(test_name)
self.nodes = []
def setup_nodes(self):
configs = [{'rpcuser': 'user', 'rpcpassword': 'pass'} for _ in range(3)]
self.nodes = [TestNode(i, config) for i, config in enumerate(configs)]
for node in self.nodes:
node.start()
time.sleep(5) # Allow nodes time to start
for node in self.nodes:
self.wait_for_rpc(node)
def wait_for_rpc(self, node, retries=30):
for attempt in range(retries):
try:
if node.rpc.getblockchaininfo():
logger.info(f"Node {node.index} RPC connection established.")
return
except ValueError:
logger.debug(f"Node {node.index} not responding, retrying... ({attempt+1}/{retries})")
time.sleep(1)
logger.error(f"Node {node.index} failed to establish RPC connection.")
raise AssertionError(f"Unable to establish RPC connection for node {node.index}")
def shutdown(self):
for node in self.nodes:
logger.info(f"Stopping node {node.index}")
node.stop()
logger.info("All nodes stopped.")
if __name__ == "__main__":
test = FeatureFrameworkRPCFailure(__file__)
try:
test.setup()
test.setup_nodes()
except AssertionError as e:
logger.error(f"Setup failed: {str(e)}")
finally:
test.shutdown()
import logging
import time
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)
class FeatureFrameworkRPCFailure(TestFramework):
def __init__(self, test_name):
super().__init__(test_name)
self.nodes = []
def setup_nodes(self):
configs = [{'rpcuser': 'user', 'rpcpassword': 'pass'} for _ in range(3)]
self.nodes = [TestNode(i, config) for i, config in enumerate(configs)]
for node in self.nodes:
node.start()
time.sleep(5) # Allow nodes time to start
for node in self.nodes:
self.wait_for_rpc(node)
def wait_for_rpc(self, node, retries=30):
for attempt in range(retries):
try:
if node.rpc.getblockchaininfo():
logger.info(f"Node {node.index} RPC connection established.")
return
except ValueError:
logger.debug(f"Node {node.index} not responding, retrying... ({attempt+1}/{retries})")
time.sleep(1)
logger.error(f"Node {node.index} failed to establish RPC connection.")
raise AssertionError(f"Unable to establish RPC connection for node {node.index}")
def shutdown(self):
for node in self.nodes:
logger.info(f"Stopping node {node.index}")
node.stop()
logger.info("All nodes stopped.")