11#!/usr/bin/env python3
22
3+ import json
34import os
4- import shutil
55
66import pexpect
77from test_base import TestBase
@@ -15,34 +15,65 @@ def __init__(self):
1515
1616 def run_test (self ):
1717 try :
18+ # cwd out of the git repo for remainder of script
19+ os .chdir (self .tmpdir )
1820 self .directory_not_exist ()
1921 os .mkdir (NETWORKS_DIR )
2022 self .directory_exists ()
21-
23+ self . run_created_network ()
2224 finally :
23- shutil . rmtree ( NETWORKS_DIR ) if os . path . exists ( NETWORKS_DIR ) else None
25+ self . cleanup ()
2426
2527 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
2835
2936 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" ]
4677
4778
4879if __name__ == "__main__" :
0 commit comments