zombienet_sdk/
lib.rs

1use async_trait::async_trait;
2pub use configuration::{
3    GlobalSettings, GlobalSettingsBuilder, NetworkConfig, NetworkConfigBuilder,
4    RegistrationStrategy, WithRelaychain,
5};
6#[cfg(feature = "pjs")]
7pub use orchestrator::pjs_helper::PjsResult;
8pub use orchestrator::{
9    errors::OrchestratorError,
10    network::{node::NetworkNode, Network},
11    AddCollatorOptions, AddNodeOptions, Orchestrator,
12};
13
14// Helpers used for interact with the network
15pub mod tx_helper {
16    pub use orchestrator::{
17        network::chain_upgrade::ChainUpgrade, shared::types::RuntimeUpgradeOptions,
18    };
19}
20
21use provider::{DockerProvider, KubernetesProvider, NativeProvider};
22pub use support::fs::local::LocalFileSystem;
23
24pub mod environment;
25pub const PROVIDERS: [&str; 3] = ["k8s", "native", "docker"];
26
27// re-export subxt
28pub use subxt;
29pub use subxt_signer;
30
31#[async_trait]
32pub trait NetworkConfigExt {
33    /// Spawns a network using the native or k8s provider.
34    ///
35    /// # Example:
36    /// ```rust
37    /// # use zombienet_sdk::{NetworkConfig, NetworkConfigExt};
38    /// # async fn example() -> Result<(), zombienet_sdk::OrchestratorError> {
39    /// let network = NetworkConfig::load_from_toml("config.toml")?
40    ///     .spawn_native()
41    ///     .await?;
42    /// # Ok(())
43    /// # }
44    /// ```
45    async fn spawn_native(self) -> Result<Network<LocalFileSystem>, OrchestratorError>;
46    async fn spawn_k8s(self) -> Result<Network<LocalFileSystem>, OrchestratorError>;
47    async fn spawn_docker(self) -> Result<Network<LocalFileSystem>, OrchestratorError>;
48}
49
50#[async_trait]
51impl NetworkConfigExt for NetworkConfig {
52    async fn spawn_native(self) -> Result<Network<LocalFileSystem>, OrchestratorError> {
53        let filesystem = LocalFileSystem;
54        let provider = NativeProvider::new(filesystem.clone());
55        let orchestrator = Orchestrator::new(filesystem, provider);
56        orchestrator.spawn(self).await
57    }
58
59    async fn spawn_k8s(self) -> Result<Network<LocalFileSystem>, OrchestratorError> {
60        let filesystem = LocalFileSystem;
61        let provider = KubernetesProvider::new(filesystem.clone()).await;
62        let orchestrator = Orchestrator::new(filesystem, provider);
63        orchestrator.spawn(self).await
64    }
65
66    async fn spawn_docker(self) -> Result<Network<LocalFileSystem>, OrchestratorError> {
67        let filesystem = LocalFileSystem;
68        let provider = DockerProvider::new(filesystem.clone()).await;
69        let orchestrator = Orchestrator::new(filesystem, provider);
70        orchestrator.spawn(self).await
71    }
72}