/// Deserializes a new `NiDkgTestEnvironment` from disk.
///
/// Note that this only works if the environment was originally serialized
/// using `save_to_dir`.
Deserializes a new `NiDkgTestEnvironment` from disk.
Note that this only works if the environment was originally serialized
using `save_to_dir`.
Deserializes a new ` NiDkgTestEnvironment ` from disk . Note that this only works if the environment was originally serialized using ` save_to_dir ` .
pub fn new_from_dir(toplevel_path: &Path) -> Self {
        fn node_ids_from_dir_names(toplevel_path: &Path) -> BTreeMap<NodeId, PathBuf> {
            std::fs::read_dir(toplevel_path)
                .expect("crypto_root directory doesn't exist")
                .into_iter()
                .map(|e| e.unwrap().path())
                .filter(|e| e.is_dir())
                .map(|p| {
                    (
                        NodeId::from(
                            PrincipalId::from_str(p.file_name().unwrap().to_str().unwrap())
                                .expect("directory name is not a node ID"),
                        ),
                        p,
                    )
                })
                .collect()
        }
        let registry_data = Arc::new(ProtoRegistryDataProvider::load_from_file(
            toplevel_path.join("registry_data.pb"),
        ));
        let registry = Arc::new(FakeRegistryClient::new(Arc::clone(&registry_data) as Arc<_>));
        let mut ret = NiDkgTestEnvironment {
            crypto_components: BTreeMap::new(),
            registry_data,
            registry,
        };
        for (node_id, crypto_root) in node_ids_from_dir_names(toplevel_path) {
            let (config, temp_dir) = CryptoConfig::new_in_temp_dir();
            Self::copy_crypto_root(&crypto_root, temp_dir.path());
            let registry = Arc::clone(&ret.registry) as Arc<_>;
            let crypto_component =
                TempCryptoComponent::new_with(registry, node_id, &config, temp_dir);
            ret.crypto_components.insert(node_id, crypto_component);
        }
        ret.registry.update_to_latest_version();
        ret
    }
pub fn new_from_dir ( toplevel_path : & Path ) -> Self { fn node_ids_from_dir_names ( toplevel_path : & Path ) -> BTreeMap < NodeId , PathBuf > { std :: fs :: read_dir ( toplevel_path ) . expect ( " " ) . into_iter ( ) . map ( | e | e . unwrap ( ) . path ( ) ) . filter ( | e | e . is_dir ( ) ) . map ( | p | { ( NodeId :: from ( PrincipalId :: from_str ( p . file_name ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) ) . expect ( " " ) , ) , p , ) } ) . collect ( ) } let registry_data = Arc :: new ( ProtoRegistryDataProvider :: load_from_file ( toplevel_path . join ( " " ) , ) ) ; let registry = Arc :: new ( FakeRegistryClient :: new ( Arc :: clone ( & registry_data ) as Arc < _ > ) ) ; let mut ret = NiDkgTestEnvironment { crypto_components : BTreeMap :: new ( ) , registry_data , registry , } ; for ( node_id , crypto_root ) in node_ids_from_dir_names ( toplevel_path ) { let ( config , temp_dir ) = CryptoConfig :: new_in_temp_dir ( ) ; Self :: copy_crypto_root ( & crypto_root , temp_dir . path ( ) ) ; let registry = Arc :: clone ( & ret . registry ) as Arc < _ > ; let crypto_component = TempCryptoComponent :: new_with ( registry , node_id , & config , temp_dir ) ; ret . crypto_components . insert ( node_id , crypto_component ) ; } ret . registry . update_to_latest_version ( ) ; ret }
Deserializes a new `NiDkgTestEnvironment` from disk.
Deserializes a new ` NiDkgTestEnvironment ` from disk .
toplevel_path
&Path