@@ -26,7 +26,7 @@ class Network:
26
26
def __init__ (self , args : argparse .Namespace ):
27
27
logging .info ("Setting up test environment..." )
28
28
peers_dir = args .out_dir .joinpath ("peers" )
29
- os .mkdir (peers_dir )
29
+ os .makedirs (peers_dir , exist_ok = True )
30
30
try :
31
31
shutil .copy2 (f"{ args .root_dir } /configs/peer/config.json" , peers_dir )
32
32
shutil .copy2 (f"{ args .root_dir } /configs/peer/genesis.json" , peers_dir )
@@ -57,7 +57,7 @@ def wait_for_genesis(self, n_tries: int):
57
57
try :
58
58
with urllib .request .urlopen (f"http://{ self .peers [0 ].host_ip } :{ self .peers [0 ].telemetry_port } /status/blocks" ) as response :
59
59
block_count = int (response .read ())
60
- if block_count == 1 :
60
+ if block_count > 1 :
61
61
logging .info (f"Genesis block created. Block count: { block_count } " )
62
62
return
63
63
else :
@@ -93,8 +93,10 @@ def __init__(self, args: argparse.Namespace, nth: int):
93
93
94
94
logging .info (f"Peer { self .name } generating key pair..." )
95
95
96
- kagami = subprocess .run ([f"{ self .out_dir } /kagami" ,"crypto" , "-j" ],
97
- capture_output = True )
96
+ command = [f"{ self .out_dir } /kagami" , "crypto" , "-j" ]
97
+ if args .peer_name_as_seed :
98
+ command .extend (["-s" , self .name ])
99
+ kagami = subprocess .run (command , capture_output = True )
98
100
if kagami .returncode :
99
101
logging .error ("Kagami failed to generate a key pair." )
100
102
sys .exit (3 )
@@ -109,8 +111,8 @@ def __init__(self, args: argparse.Namespace, nth: int):
109
111
def run (self , is_genesis : bool = False ):
110
112
logging .info (f"Running peer { self .name } ..." )
111
113
peer_dir = self .out_dir .joinpath (f"peers/{ self .name } " )
112
- os .mkdir (peer_dir )
113
- os .mkdir (peer_dir .joinpath ("storage" ))
114
+ os .makedirs (peer_dir , exist_ok = True )
115
+ os .makedirs (peer_dir .joinpath ("storage" ), exist_ok = True )
114
116
115
117
os .environ ["KURA_BLOCK_STORE_PATH" ] = str (peer_dir .joinpath ("storage" ))
116
118
os .environ ["SNAPSHOT_DIR_PATH" ] = str (peer_dir .joinpath ("storage" ))
@@ -177,11 +179,7 @@ def main(args):
177
179
178
180
def setup (args ):
179
181
logging .info (f"Starting iroha network with { args .n_peers } peers..." )
180
- try :
181
- os .mkdir (args .out_dir )
182
- except FileExistsError :
183
- logging .error (f"Test directory `{ args .out_dir } ` already exists" )
184
- sys .exit (5 )
182
+ os .makedirs (args .out_dir , exist_ok = True )
185
183
copy_or_prompt_build_bin ("iroha_client_cli" , args .root_dir , args .out_dir )
186
184
with open (os .path .join (args .out_dir , "metadata.json" ), "w" ) as f :
187
185
f .write ('{"comment":{"String": "Hello Meta!"}}' )
@@ -227,6 +225,9 @@ def cleanup(args):
227
225
help = "Directory containing Iroha project root. \
228
226
Defaults to `.`, i.e. the directory script is being run from. \
229
227
This is used to locate the `iroha` binary and config files" )
228
+ parser .add_argument ("--peer-name-as-seed" , action = "store_true" ,
229
+ help = "Use peer name as seed for key generation. \
230
+ This option could be useful to preserve the same peer keys between script invocations" )
230
231
231
232
parser .add_argument ("--verbose" , "-v" , action = "store_true" ,
232
233
help = "Enable verbose output" )
0 commit comments