zombienet_sdk/
lib.rs

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