Skip to content

Commit 5e99a0b

Browse files
brunopgalvaodawnkelly09nhussein11
authored
Add mock your runtime (#1167)
* add mock your runtime * add mock your runtime code * Fix: proper usage of #[derive(DefaultNoBound)] * llms * Grammarly pass * Apply suggestions from code review Co-authored-by: Nicolás Hussein <[email protected]> * removes outdated snippets * update snippets * add back section per feedback --------- Co-authored-by: DAWN KELLY <[email protected]> Co-authored-by: Dawn Kelly <[email protected]> Co-authored-by: Nicolás Hussein <[email protected]>
1 parent 08ce26c commit 5e99a0b

31 files changed

+1258
-953
lines changed

.ai/categories/parachains.md

Lines changed: 282 additions & 108 deletions
Large diffs are not rendered by default.

.ai/pages/parachains-customize-runtime-pallet-development-create-a-pallet.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ Add the [`#[pallet::genesis_config]`](https://paritytech.github.io/polkadot-sdk/
291291
292292
```rust title="src/lib.rs"
293293
#[pallet::genesis_config]
294-
#[derive(frame_support::DefaultNoBound)]
294+
#[derive(DefaultNoBound)]
295295
pub struct GenesisConfig<T: Config> {
296296
/// Initial value for the counter
297297
pub initial_counter_value: u32,
@@ -510,7 +510,7 @@ If you encounter errors, carefully review the code against this guide. Once the
510510
pub type UserInteractions<T: Config> = StorageMap<_, Blake2_128Concat, T::AccountId, u32, ValueQuery>;
511511
512512
#[pallet::genesis_config]
513-
#[derive(frame_support::DefaultNoBound)]
513+
#[derive(DefaultNoBound)]
514514
pub struct GenesisConfig<T: Config> {
515515
pub initial_counter_value: u32,
516516
pub initial_user_interactions: Vec<(T::AccountId, u32)>,

.ai/pages/parachains-customize-runtime-pallet-development-mock-runtime.md

Lines changed: 284 additions & 110 deletions
Large diffs are not rendered by default.

.ai/site-index.json

Lines changed: 55 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5024,24 +5024,24 @@
50245024
}
50255025
],
50265026
"stats": {
5027-
"chars": 26836,
5028-
"words": 3071,
5027+
"chars": 26806,
5028+
"words": 3069,
50295029
"headings": 26,
5030-
"estimated_token_count_total": 6178
5030+
"estimated_token_count_total": 6172
50315031
},
5032-
"hash": "sha256:0fbcdee68f2ae1ec848cb600ceb91c5738083944ad74b4a39f82bd19c9d7dc29",
5032+
"hash": "sha256:0746676ba45f623d2c9cb71bf24162bc1dcf687f3f1ec74d02a19732d3bc7161",
50335033
"token_estimator": "heuristic-v1"
50345034
},
50355035
{
50365036
"id": "parachains-customize-runtime-pallet-development-mock-runtime",
5037-
"title": "Mock Runtime for Pallet Testing",
5037+
"title": "Mock Your Runtime",
50385038
"slug": "parachains-customize-runtime-pallet-development-mock-runtime",
50395039
"categories": [
50405040
"Parachains"
50415041
],
50425042
"raw_md_url": "https://raw.githubusercontent.com/polkadot-developers/polkadot-docs/master/.ai/pages/parachains-customize-runtime-pallet-development-mock-runtime.md",
50435043
"html_url": "https://docs.polkadot.com/parachains/customize-runtime/pallet-development/mock-runtime/",
5044-
"preview": "Testing is essential in Polkadot SDK development to ensure your blockchain operates as intended and effectively handles various potential scenarios. This guide walks you through setting up an environment to test pallets within the [runtime](/polkadot-protocol/glossary#runtime){target=_blank}, allowing you to evaluate how different pallets, their configurations, and system components interact to ensure reliable blockchain functionality.",
5044+
"preview": "Testing is a critical part of pallet development. Before integrating your pallet into a full runtime, you need a way to test its functionality in isolation. A mock runtime provides a minimal, simulated blockchain environment where you can verify your pallet's logic without the overhead of running a full node.",
50455045
"outline": [
50465046
{
50475047
"depth": 2,
@@ -5050,23 +5050,58 @@
50505050
},
50515051
{
50525052
"depth": 2,
5053-
"title": "Configuring a Mock Runtime",
5054-
"anchor": "configuring-a-mock-runtime"
5053+
"title": "Prerequisites",
5054+
"anchor": "prerequisites"
50555055
},
50565056
{
5057-
"depth": 3,
5058-
"title": "Testing Module",
5059-
"anchor": "testing-module"
5057+
"depth": 2,
5058+
"title": "Understanding Mock Runtimes",
5059+
"anchor": "understanding-mock-runtimes"
5060+
},
5061+
{
5062+
"depth": 2,
5063+
"title": "Create the Mock Runtime Module",
5064+
"anchor": "create-the-mock-runtime-module"
5065+
},
5066+
{
5067+
"depth": 2,
5068+
"title": "Set Up Basic Mock Infrastructure",
5069+
"anchor": "set-up-basic-mock-infrastructure"
5070+
},
5071+
{
5072+
"depth": 2,
5073+
"title": "Implement frame_system Configuration",
5074+
"anchor": "implement-frame_system-configuration"
5075+
},
5076+
{
5077+
"depth": 2,
5078+
"title": "Implement Your Pallet's Configuration",
5079+
"anchor": "implement-your-pallets-configuration"
5080+
},
5081+
{
5082+
"depth": 2,
5083+
"title": "Configure Genesis Storage",
5084+
"anchor": "configure-genesis-storage"
50605085
},
50615086
{
50625087
"depth": 3,
5063-
"title": "Genesis Storage",
5064-
"anchor": "genesis-storage"
5088+
"title": "Basic Test Environment",
5089+
"anchor": "basic-test-environment"
50655090
},
50665091
{
50675092
"depth": 3,
5068-
"title": "Pallet Configuration",
5069-
"anchor": "pallet-configuration"
5093+
"title": "Custom Genesis Configurations",
5094+
"anchor": "custom-genesis-configurations"
5095+
},
5096+
{
5097+
"depth": 2,
5098+
"title": "Verify Mock Compilation",
5099+
"anchor": "verify-mock-compilation"
5100+
},
5101+
{
5102+
"depth": 2,
5103+
"title": "Key Takeaways",
5104+
"anchor": "key-takeaways"
50705105
},
50715106
{
50725107
"depth": 2,
@@ -5075,12 +5110,12 @@
50755110
}
50765111
],
50775112
"stats": {
5078-
"chars": 7514,
5079-
"words": 906,
5080-
"headings": 6,
5081-
"estimated_token_count_total": 1576
5113+
"chars": 11634,
5114+
"words": 1317,
5115+
"headings": 13,
5116+
"estimated_token_count_total": 2434
50825117
},
5083-
"hash": "sha256:733652ec4eff9b11efd858a7fd7f1094e7a2e8e7deed4c60c5805f986d877df4",
5118+
"hash": "sha256:01fef3706d6e8e162d7faaf15599311a5cb104793b924379f55e0d3d9b827869",
50845119
"token_estimator": "heuristic-v1"
50855120
},
50865121
{
Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,33 @@
11
[package]
2-
name = "custom-pallet"
3-
version = "0.1.0"
4-
edition = "2021"
2+
name = "pallet-custom"
3+
description = "A custom counter pallet for demonstration purposes."
4+
version = "0.1.0"
5+
license = "Unlicense"
6+
authors.workspace = true
7+
homepage.workspace = true
8+
repository.workspace = true
9+
edition.workspace = true
10+
publish = false
511

6-
[dependencies]
7-
frame-support = { version = "37.0.0", default-features = false }
8-
frame-system = { version = "37.0.0", default-features = false }
9-
codec = { version = "3.6.12", default-features = false, package = "parity-scale-codec", features = [
10-
"derive",
11-
] }
12-
scale-info = { version = "2.11.1", default-features = false, features = [
13-
"derive",
14-
] }
15-
sp-runtime = { version = "39.0.0", default-features = false }
12+
[package.metadata.docs.rs]
13+
targets = ["x86_64-unknown-linux-gnu"]
1614

17-
[features]
18-
default = ["std"]
19-
std = [
20-
"frame-support/std",
21-
"frame-system/std",
22-
"codec/std",
23-
"scale-info/std",
24-
"sp-runtime/std",
25-
]
15+
[dependencies]
16+
codec = { features = ["derive"], workspace = true }
17+
scale-info = { features = ["derive"], workspace = true }
18+
frame = { features = ["experimental", "runtime"], workspace = true }
19+
20+
[features]
21+
default = ["std"]
22+
std = [
23+
"codec/std",
24+
"scale-info/std",
25+
"frame/std",
26+
]
27+
28+
[workspace.members]
29+
members = [
30+
"node",
31+
"pallets/*",
32+
"runtime",
33+
]

.snippets/code/parachains/customize-runtime/pallet-development/create-a-pallet/barebone-pallet-template.rs

Lines changed: 0 additions & 16 deletions
This file was deleted.

.snippets/code/parachains/customize-runtime/pallet-development/create-a-pallet/full-pallet.rs

Lines changed: 0 additions & 80 deletions
This file was deleted.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#![cfg_attr(not(feature = "std"), no_std)]
2+
3+
pub use pallet::*;
4+
5+
#[frame::pallet]
6+
pub mod pallet {
7+
use frame::prelude::*;
8+
9+
#[pallet::pallet]
10+
pub struct Pallet<T>(_);
11+
12+
#[pallet::config]
13+
pub trait Config: frame_system::Config {
14+
// Configuration will be added here
15+
}
16+
17+
#[pallet::storage]
18+
pub type CounterValue<T> = StorageValue<_, u32, ValueQuery>;
19+
20+
#[pallet::call]
21+
impl<T: Config> Pallet<T> {
22+
// Dispatchable functions will be added here
23+
}
24+
}

.snippets/code/parachains/customize-runtime/pallet-development/create-a-pallet/lib-02.rs

Whitespace-only changes.
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
pub trait Config: frame_system::Config {
33
/// The overarching runtime event type.
44
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
5-
/// A type representing the weights required by the dispatchables of this pallet.
6-
type WeightInfo;
7-
}
5+
6+
/// Maximum value the counter can reach.
7+
#[pallet::constant]
8+
type CounterMaxValue: Get<u32>;
9+
}

0 commit comments

Comments
 (0)