Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds simnode for testing parachain runtime upgrades. #409

Merged
merged 15 commits into from
Jan 10, 2022
134 changes: 134 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ members = [
"utils/parachain-utils",
"frame/*",
"integration-tests",
"integration-tests/simnode",
"node",
"price-feed",
"runtime/picasso",
"runtime/composable",
"utils/subxt-clients",
# "utils/subxt-clients",
"utils/collator-sidecar"
]
39 changes: 39 additions & 0 deletions integration-tests/simnode/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
[package]
name = "simnode"
version = "0.1.0"
edition = "2021"

[dependencies]
substrate-simnode = { git = "https://github.com/polytope-labs/substrate-simnode", branch = "master" }

frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13" }
frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13" }
transaction-payment = { package = "pallet-transaction-payment", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13", default-features = false }

pallet-asset-tx-payment = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13" }

sc-consensus-manual-seal = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13" }
sc-service = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13" }
sc-cli = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13" }
sc-client-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13" }
sc-tracing = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13" }
sc-executor = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13" }
sc-consensus = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13" }
sp-consensus-aura = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13" }

sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13" }
sp-keyring = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13" }
sp-blockchain = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13" }
sproof-builder = { package = "cumulus-test-relay-sproof-builder", git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.13" }
picasso-runtime = { path = "../../runtime/picasso" }
common = { path = "../../runtime/common" }
node = { package = "composable", path = "../../node" }
parachain-inherent = { package = "cumulus-primitives-parachain-inherent", git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.13" }
parachain-system = { package = "cumulus-pallet-parachain-system", git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.13" }
cumulus-client-cli = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.13" }
polkadot-primitives = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.13" }
codec = { package = "parity-scale-codec", version = "2.0.0" }

sudo = { package = "pallet-sudo", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13" }

structopt = "0.3.25"
57 changes: 57 additions & 0 deletions integration-tests/simnode/src/chain_info.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
use parachain_inherent::ParachainInherentData;
use sc_consensus_manual_seal::consensus::timestamp::SlotTimestampProvider;
use sc_service::TFullBackend;
use sp_runtime::generic::Era;
use std::sync::Arc;
use substrate_simnode::{ChainInfo, FullClientFor, SignatureVerificationOverride};

/// A unit struct which implements `NativeExecutionDispatch` feeding in the
/// hard-coded runtime.
pub struct ExecutorDispatch;

impl sc_executor::NativeExecutionDispatch for ExecutorDispatch {
type ExtendHostFunctions =
(frame_benchmarking::benchmarking::HostFunctions, SignatureVerificationOverride);

fn dispatch(method: &str, data: &[u8]) -> Option<Vec<u8>> {
picasso_runtime::api::dispatch(method, data)
}

fn native_version() -> sc_executor::NativeVersion {
picasso_runtime::native_version()
}
}

/// ChainInfo implementation.
pub struct PicassoChainInfo;

impl ChainInfo for PicassoChainInfo {
type Block = common::OpaqueBlock;
type ExecutorDispatch = ExecutorDispatch;
type Runtime = picasso_runtime::Runtime;
type RuntimeApi = picasso_runtime::RuntimeApi;
type SelectChain = sc_consensus::LongestChain<TFullBackend<Self::Block>, Self::Block>;
type BlockImport = Arc<FullClientFor<Self>>;
type SignedExtras = picasso_runtime::SignedExtra;
type InherentDataProviders = (
SlotTimestampProvider,
sp_consensus_aura::inherents::InherentDataProvider,
ParachainInherentData,
);

fn signed_extras(
from: <Self::Runtime as frame_system::Config>::AccountId,
) -> Self::SignedExtras {
(
frame_system::CheckSpecVersion::<Self::Runtime>::new(),
frame_system::CheckTxVersion::<Self::Runtime>::new(),
frame_system::CheckGenesis::<Self::Runtime>::new(),
frame_system::CheckMortality::<Self::Runtime>::from(Era::Immortal),
frame_system::CheckNonce::<Self::Runtime>::from(
frame_system::Pallet::<Self::Runtime>::account_nonce(from),
),
frame_system::CheckWeight::<Self::Runtime>::new(),
transaction_payment::ChargeTransactionPayment::<Self::Runtime>::from(0),
seunlanlege marked this conversation as resolved.
Show resolved Hide resolved
)
}
}
80 changes: 80 additions & 0 deletions integration-tests/simnode/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#![deny(unused_extern_crates, missing_docs)]

//! Basic example of end to end runtime tests.
mod chain_info;
mod node;

pub use chain_info::*;
use picasso_runtime::Event;
use sc_client_api::{call_executor::ExecutorProvider, CallExecutor};
use sp_blockchain::HeaderBackend;
use sp_runtime::generic::BlockId;
use sp_runtime::AccountId32;
use std::error::Error;
use std::str::FromStr;

fn main() -> Result<(), Box<dyn Error>> {
node::run(|node| async move {
let from = AccountId32::from_str("5uAfQTqudXnnSgSMPVowwRjgNFxBDW2d5AQXP2vHDHy2yJ4w")?;

node.submit_extrinsic(
frame_system::Call::remark { remark: b"Hello World".to_vec() },
Some(from),
)
.await?;
node.seal_blocks(1).await;

let old_runtime_version = node
.client()
.executor()
.runtime_version(&BlockId::Hash(node.client().info().best_hash))?
.spec_version;
println!("\n\nold_runtime_version: {}\n\n", old_runtime_version);

let code = picasso_runtime::WASM_BINARY
.ok_or("Polkadot development wasm not available")?
.to_vec();

let call = sudo::Call::sudo_unchecked_weight {
call: Box::new(frame_system::Call::set_code { code }.into()),
weight: 0,
};
// let su = AccountId32::from_str("5z93WG1Lz47b8AjtVbMaLC4M8rohecXPMSjRDBaMUAbmeCi7")?;
let su = AccountId32::from_str("5uAfQTqudXnnSgSMPVowwRjgNFxBDW2d5AQXP2vHDHy2yJ4w")?;
seunlanlege marked this conversation as resolved.
Show resolved Hide resolved
node.submit_extrinsic(call, Some(su)).await?;
node.seal_blocks(2).await;
// assert that the runtime has been updated by looking at events
let events = node
.events()
.into_iter()
.filter(|event| match event.event {
Event::ParachainSystem(parachain_system::Event::ValidationFunctionApplied(_)) => {
true
}
_ => false,
})
.collect::<Vec<_>>();
// make sure event was emitted
assert_eq!(
events.len(),
1,
"system::Event::CodeUpdate not found in events: {:#?}",
node.events()
);
let new_runtime_version = node
.client()
.executor()
.runtime_version(&BlockId::Hash(node.client().info().best_hash))?
.spec_version;
println!("\n\nnew_runtime_version: {}\n\n", new_runtime_version);

// just confirming
assert!(
new_runtime_version > old_runtime_version,
seunlanlege marked this conversation as resolved.
Show resolved Hide resolved
"Invariant, spec_version of new runtime: {} not greater than spec_version of old runtime: {}",
new_runtime_version,
old_runtime_version,
);
Ok(())
})
}