zombienet_orchestrator/network/
chain_upgrade.rs

1use std::str::FromStr;
2
3use anyhow::anyhow;
4use async_trait::async_trait;
5use subxt_signer::{sr25519::Keypair, SecretUri};
6
7use super::node::NetworkNode;
8use crate::{shared::types::RuntimeUpgradeOptions, tx_helper};
9
10#[async_trait]
11pub trait ChainUpgrade {
12    /// Perform a runtime upgrade (with sudo)
13    ///
14    /// This call 'System.set_code_without_checks' wrapped in
15    /// 'Sudo.sudo_unchecked_weight'
16    async fn runtime_upgrade(&self, options: RuntimeUpgradeOptions) -> Result<(), anyhow::Error>;
17
18    /// Perform a runtime upgrade (with sudo), inner call with the node pass as arg.
19    ///
20    /// This call 'System.set_code_without_checks' wrapped in
21    /// 'Sudo.sudo_unchecked_weight'
22    async fn perform_runtime_upgrade(
23        &self,
24        node: &NetworkNode,
25        options: RuntimeUpgradeOptions,
26    ) -> Result<(), anyhow::Error> {
27        let sudo = if let Some(possible_seed) = options.seed {
28            Keypair::from_secret_key(possible_seed)
29                .map_err(|_| anyhow!("seed should return a Keypair"))?
30        } else {
31            let uri = SecretUri::from_str("//Alice")?;
32            Keypair::from_uri(&uri).map_err(|_| anyhow!("'//Alice' should return a Keypair"))?
33        };
34
35        let wasm_data = options.wasm.get_asset().await?;
36
37        tx_helper::runtime_upgrade::upgrade(node, &wasm_data, &sudo).await?;
38
39        Ok(())
40    }
41}