Skip to content

Commit

Permalink
fix runtime upgrade examples
Browse files Browse the repository at this point in the history
  • Loading branch information
haerdib committed Sep 12, 2024
1 parent 260ef93 commit dd1d9a8
Show file tree
Hide file tree
Showing 9 changed files with 7 additions and 17 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,9 @@ jobs:
compose_extrinsic,
custom_nonce,
check_extrinsic_events,
get_account_identity,
get_blocks,
get_storage,
print_metadata,
staking_batch_payout,
subscribe_events,
sudo,
new_json_rpc_api_calls,
Expand Down
Binary file not shown.
Binary file not shown.
4 changes: 2 additions & 2 deletions examples/async/examples/runtime_update_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@ async fn main() {
};
println!("Detected runtime update: {runtime_update_detected}");
println!("New spec_version: {}", api.spec_version());
assert!(api.spec_version() == 1268);
assert!(api.spec_version() == 111111111);
assert!(runtime_update_detected);
}

pub async fn send_code_update_extrinsic(
api: &substrate_api_client::Api<WestendRuntimeConfig, JsonrpseeClient>,
) {
let new_wasm: &[u8] = include_bytes!("kitchensink_runtime.compact.compressed.wasm");
let new_wasm: &[u8] = include_bytes!("minimal_template_runtime.compact.compressed.wasm");

// this call can only be called by sudo
let call = compose_call!(api.metadata(), "System", "set_code", new_wasm.to_vec()).unwrap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@ use substrate_api_client::{

const MAX_BATCHED_TRANSACTION: u32 = 9;

// To test this example with CI we run it against the Substrate kitchensink node, which uses the asset pallet.
// Therefore, we need to use the `AssetRuntimeConfig` in this example.
// ! However, most Substrate runtimes do not use the asset pallet at all. So if you run an example against your own node
// you most likely should use `WestendRuntimeConfig` instead.
// This example is currently not tested because the polkadot chain (rococo runtime) we run our example against
// does not include the staking pallet. But it still provides a good example for possible stake payouts.

pub type EraIndex = u32;

Expand Down Expand Up @@ -68,17 +66,14 @@ async fn main() {
println!("{:?}", active_era);
let current_era_index = active_era.index;

// Test if payout staker extrinsic works. Careful: In CI, this extrinsic will fail to be executed, because
// Test if payout staker extrinsic works. Careful: If tested with CI, this extrinsic will fail to be executed, because
// one can not payout the current era (= 0 on the freshly started node). But this is okay, because we know if this
// error is returned from the node, the extrinsic has been created correctly.
// Sidenote: We could theoretically force a new era with sudo, but this takes at least 10 minutes ( = 1 epoch) in the
// kitchensink rutime. We don't want to wait that long.
let payout_staker_xt = api.payout_stakers(0, validator_stash).await.unwrap();
let result = api.submit_and_watch_extrinsic_until(payout_staker_xt, XtStatus::InBlock).await;
assert!(result.is_err());
assert!(format!("{result:?}").contains("InvalidEraToReward"));

// From here on, this is not CI tested, but it serves as a nice example nonetheless.
if let Some(mut last_reward_received_at_era) =
get_last_reward_received_for(&validator_account, current_era_index, &api).await
{
Expand Down
Binary file not shown.
Binary file not shown.
4 changes: 2 additions & 2 deletions examples/sync/examples/runtime_update_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ fn main() {
handler.join().unwrap();
api.update_runtime().unwrap();
println!("New spec_version: {}", api.spec_version());
assert!(api.spec_version() == 1268);
assert!(api.spec_version() == 111111111);
}

pub fn send_code_update_extrinsic(
api: &substrate_api_client::Api<WestendRuntimeConfig, TungsteniteRpcClient>,
) {
let new_wasm: &[u8] = include_bytes!("kitchensink_runtime.compact.compressed.wasm");
let new_wasm: &[u8] = include_bytes!("minimal_template_runtime.compact.compressed.wasm");

// Create a sudo `set_code` call.
let call = compose_call!(api.metadata(), "System", "set_code", new_wasm.to_vec()).unwrap();
Expand Down
3 changes: 0 additions & 3 deletions testing/async/examples/author_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,6 @@ fn assert_associated_events_match_expected(events: Vec<RawEventDetails<Hash>>) {
assert_eq!(events[2].pallet_name(), "Balances");
assert_eq!(events[2].variant_name(), "Deposit");

assert_eq!(events[3].pallet_name(), "Treasury");
assert_eq!(events[3].variant_name(), "Deposit");

assert_eq!(events[4].pallet_name(), "Balances");
assert_eq!(events[4].variant_name(), "Deposit");

Expand Down

0 comments on commit dd1d9a8

Please sign in to comment.