@@ -3,10 +3,6 @@ use crate::send_eth_tx::SendTxErrorRule;
3
3
use crate :: send_eth_tx:: UnderPriced ;
4
4
use crate :: send_eth_tx:: VerifyRule ;
5
5
use crate :: { CommitmentStream , McrSettlementClientOperations } ;
6
- use mcr_settlement_config:: Config ;
7
- use movement_types:: BlockCommitment ;
8
- use movement_types:: { Commitment , Id } ;
9
-
10
6
use alloy:: pubsub:: PubSubFrontend ;
11
7
use alloy_network:: Ethereum ;
12
8
use alloy_network:: EthereumSigner ;
@@ -24,13 +20,17 @@ use alloy_signer_wallet::LocalWallet;
24
20
use alloy_sol_types:: sol;
25
21
use alloy_transport:: BoxTransport ;
26
22
use alloy_transport_ws:: WsConnect ;
27
-
28
23
use anyhow:: Context ;
24
+ use mcr_settlement_config:: Config ;
25
+ use movement_types:: BlockCommitment ;
26
+ use movement_types:: { Commitment , Id } ;
27
+ use serde_json:: Value as JsonValue ;
28
+ use std:: array:: TryFromSliceError ;
29
+ use std:: fs;
30
+ use std:: path:: Path ;
29
31
use thiserror:: Error ;
30
32
use tokio_stream:: StreamExt ;
31
33
32
- use std:: array:: TryFromSliceError ;
33
-
34
34
#[ derive( Error , Debug ) ]
35
35
pub enum McrEthConnectorError {
36
36
#[ error(
@@ -252,6 +252,45 @@ where
252
252
}
253
253
}
254
254
255
+ pub struct AnvilAddressEntry {
256
+ pub address : String ,
257
+ pub private_key : String ,
258
+ }
259
+
260
+ /// Read the Anvil config file keys and return all address/private key.
261
+ pub fn read_anvil_json_file_addresses < P : AsRef < Path > > (
262
+ anvil_conf_path : P ,
263
+ ) -> Result < Vec < AnvilAddressEntry > , anyhow:: Error > {
264
+ let file_content = fs:: read_to_string ( anvil_conf_path) ?;
265
+
266
+ let json_value: JsonValue = serde_json:: from_str ( & file_content) ?;
267
+
268
+ // Extract the available_accounts and private_keys fields
269
+ let available_accounts_iter = json_value[ "available_accounts" ]
270
+ . as_array ( )
271
+ . expect ( "available_accounts should be an array" )
272
+ . iter ( )
273
+ . map ( |v| {
274
+ let s = v. as_str ( ) . expect ( "available_accounts elements should be strings" ) ;
275
+ s. to_owned ( )
276
+ } ) ;
277
+
278
+ let private_keys_iter = json_value[ "private_keys" ]
279
+ . as_array ( )
280
+ . expect ( "private_keys should be an array" )
281
+ . iter ( )
282
+ . map ( |v| {
283
+ let s = v. as_str ( ) . expect ( "private_keys elements should be strings" ) ;
284
+ s. to_owned ( )
285
+ } ) ;
286
+
287
+ let res = available_accounts_iter
288
+ . zip ( private_keys_iter)
289
+ . map ( |( address, private_key) | AnvilAddressEntry { address, private_key } )
290
+ . collect :: < Vec < _ > > ( ) ;
291
+ Ok ( res)
292
+ }
293
+
255
294
#[ cfg( test) ]
256
295
#[ cfg( feature = "integration-tests" ) ]
257
296
mod tests {
@@ -265,8 +304,6 @@ mod tests {
265
304
use movement_types:: Commitment ;
266
305
267
306
use anyhow:: Context ;
268
- use serde_json:: Value as JsonValue ;
269
-
270
307
use std:: env;
271
308
use std:: fs;
272
309
@@ -290,7 +327,10 @@ mod tests {
290
327
let rpc_url = format ! ( "http://localhost:{rpc_port}" ) ;
291
328
let ws_url = format ! ( "ws://localhost:{rpc_port}" ) ;
292
329
293
- let anvil_addresses = read_anvil_json_file_addresses ( ) ?;
330
+ let anvil_conf_file = env:: var ( "ANVIL_JSON_PATH" ) . context (
331
+ "ANVIL_JSON_PATH env var is not defined. It should point to the anvil json file" ,
332
+ ) ?;
333
+ let anvil_addresses = crate :: eth:: utils:: read_anvil_json_file_addresses ( & anvil_conf_file) ?;
294
334
295
335
//Do SC ceremony init stake calls.
296
336
do_genesis_ceremonial ( & anvil_addresses, & rpc_url) . await ?;
@@ -400,45 +440,6 @@ mod tests {
400
440
Ok ( ( ) )
401
441
}
402
442
403
- struct AnvilAddressEntry {
404
- address : String ,
405
- private_key : String ,
406
- }
407
-
408
- fn read_anvil_json_file_addresses ( ) -> Result < Vec < AnvilAddressEntry > , anyhow:: Error > {
409
- let anvil_conf_file = env:: var ( "ANVIL_JSON_PATH" ) . context (
410
- "ANVIL_JSON_PATH env var is not defined. It should point to the anvil json file" ,
411
- ) ?;
412
- let file_content = fs:: read_to_string ( anvil_conf_file) ?;
413
-
414
- let json_value: JsonValue = serde_json:: from_str ( & file_content) ?;
415
-
416
- // Extract the available_accounts and private_keys fields
417
- let available_accounts_iter = json_value[ "available_accounts" ]
418
- . as_array ( )
419
- . expect ( "available_accounts should be an array" )
420
- . iter ( )
421
- . map ( |v| {
422
- let s = v. as_str ( ) . expect ( "available_accounts elements should be strings" ) ;
423
- s. to_owned ( )
424
- } ) ;
425
-
426
- let private_keys_iter = json_value[ "private_keys" ]
427
- . as_array ( )
428
- . expect ( "private_keys should be an array" )
429
- . iter ( )
430
- . map ( |v| {
431
- let s = v. as_str ( ) . expect ( "private_keys elements should be strings" ) ;
432
- s. to_owned ( )
433
- } ) ;
434
-
435
- let res = available_accounts_iter
436
- . zip ( private_keys_iter)
437
- . map ( |( address, private_key) | AnvilAddressEntry { address, private_key } )
438
- . collect :: < Vec < _ > > ( ) ;
439
- Ok ( res)
440
- }
441
-
442
443
fn read_mcr_sc_adress ( ) -> Result < Address , anyhow:: Error > {
443
444
let file_path = env:: var ( "MCR_SC_ADDRESS_FILE" ) ?;
444
445
let addr_str = fs:: read_to_string ( file_path) ?;
0 commit comments