1
1
#!/usr/bin/env python3
2
2
3
+ import json
3
4
import os
4
- import shutil
5
5
6
6
import pexpect
7
7
from test_base import TestBase
@@ -15,34 +15,65 @@ def __init__(self):
15
15
16
16
def run_test (self ):
17
17
try :
18
+ # cwd out of the git repo for remainder of script
19
+ os .chdir (self .tmpdir )
18
20
self .directory_not_exist ()
19
21
os .mkdir (NETWORKS_DIR )
20
22
self .directory_exists ()
21
-
23
+ self . run_created_network ()
22
24
finally :
23
- shutil . rmtree ( NETWORKS_DIR ) if os . path . exists ( NETWORKS_DIR ) else None
25
+ self . cleanup ()
24
26
25
27
def directory_not_exist (self ):
26
- self .sut = pexpect .spawn ("warnet create" )
27
- self .sut .expect ("init" , timeout = 50 )
28
+ try :
29
+ self .log .info ("testing warnet create, dir doesn't exist" )
30
+ self .sut = pexpect .spawn ("warnet create" )
31
+ self .sut .expect ("init" , timeout = 10 )
32
+ except Exception as e :
33
+ print (f"\n Received prompt text:\n { self .sut .before .decode ('utf-8' )} \n " )
34
+ raise e
28
35
29
36
def directory_exists (self ):
30
- self .sut = pexpect .spawn ("warnet create" )
31
- self .sut .expect ("name" , timeout = 10 )
32
- self .sut .sendline ("ANewNetwork" )
33
- self .sut .expect ("many" , timeout = 10 )
34
- self .sut .sendline ("" )
35
- self .sut .expect ("connections" , timeout = 10 )
36
- self .sut .sendline ("" )
37
- self .sut .expect ("version" , timeout = 10 )
38
- self .sut .sendline ("" )
39
- self .sut .expect ("enable fork-observer" , timeout = 10 )
40
- self .sut .sendline ("" )
41
- self .sut .expect ("seconds" , timeout = 10 )
42
- self .sut .sendline ("" )
43
- self .sut .expect ("enable grafana" , timeout = 10 )
44
- self .sut .sendline ("" )
45
- self .sut .expect ("successfully" , timeout = 50 )
37
+ try :
38
+ self .log .info ("testing warnet create, dir does exist" )
39
+ self .sut = pexpect .spawn ("warnet create" )
40
+ self .sut .expect ("name" , timeout = 10 )
41
+ self .sut .sendline ("ANewNetwork" )
42
+ self .sut .expect ("many" , timeout = 10 )
43
+ self .sut .sendline ("" )
44
+ self .sut .expect ("connections" , timeout = 10 )
45
+ self .sut .sendline ("" )
46
+ self .sut .expect ("version" , timeout = 10 )
47
+ self .sut .sendline ("" )
48
+ self .sut .expect ("enable fork-observer" , timeout = 10 )
49
+ self .sut .sendline ("" )
50
+ self .sut .expect ("seconds" , timeout = 10 )
51
+ self .sut .sendline ("" )
52
+ self .sut .expect ("enable grafana" , timeout = 10 )
53
+ self .sut .sendline ("" )
54
+ self .sut .expect ("successfully" , timeout = 50 )
55
+ except Exception as e :
56
+ print (f"\n Received prompt text:\n { self .sut .before .decode ('utf-8' )} \n " )
57
+ raise e
58
+
59
+ def run_created_network (self ):
60
+ self .log .info ("adding custom config to one tank" )
61
+ with open ("networks/ANewNetwork/network.yaml" ) as f :
62
+ s = f .read ()
63
+ s = s .replace (" name: tank-0000\n " , " name: tank-0000\n config: debug=mempool\n " )
64
+ with open ("networks/ANewNetwork/network.yaml" , "w" ) as f :
65
+ f .write (s )
66
+
67
+ self .log .info ("deploying new network" )
68
+ self .warnet ("deploy networks/ANewNetwork" )
69
+ self .wait_for_all_tanks_status (target = "running" )
70
+ debugs = json .loads (self .warnet ("bitcoin rpc tank-0000 logging" ))
71
+ # set in defaultConfig
72
+ assert debugs ["rpc" ]
73
+ # set in config just for this tank
74
+ assert debugs ["mempool" ]
75
+ # santy check
76
+ assert not debugs ["zmq" ]
46
77
47
78
48
79
if __name__ == "__main__" :
0 commit comments