Skip to content

Commit

Permalink
Use the #[runtime] macro (#195)
Browse files Browse the repository at this point in the history
* switch to runtime macro

* adjust a little

* fix words

* better runtime description

* more comments

* can -> find
  • Loading branch information
shawntabrizi authored Nov 29, 2024
1 parent aafe8ad commit de4d70e
Show file tree
Hide file tree
Showing 54 changed files with 1,620 additions and 540 deletions.
40 changes: 30 additions & 10 deletions steps/1/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use crate as pallet_kitties;
use crate::*;
use frame::deps::frame_support::runtime;
use frame::deps::sp_io;
use frame::runtime::prelude::*;
use frame::testing_prelude::*;
Expand All @@ -28,16 +29,35 @@ type Block = frame_system::mocking::MockBlock<TestRuntime>;
const ALICE: u64 = 1;
const BOB: u64 = 2;

// Our blockchain tests only need 3 Pallets:
// 1. System: Which is included with every FRAME runtime.
// 2. PalletBalances: Which is manages your blockchain's native currency. (i.e. DOT on Polkadot)
// 3. PalletKitties: The pallet you are building in this tutorial!
construct_runtime! {
pub struct TestRuntime {
System: frame_system,
PalletBalances: pallet_balances,
PalletKitties: pallet_kitties,
}
#[runtime]
mod runtime {
#[runtime::derive(
RuntimeCall,
RuntimeEvent,
RuntimeError,
RuntimeOrigin,
RuntimeTask,
RuntimeHoldReason,
RuntimeFreezeReason
)]
#[runtime::runtime]
/// The "test runtime" that represents the state transition function for our blockchain.
///
/// The runtime is composed of individual modules called "pallets", which you find see below.
/// Each pallet has its own logic and storage, all of which can be combined together.
pub struct TestRuntime;

/// System: Mandatory system pallet that should always be included in a FRAME runtime.
#[runtime::pallet_index(0)]
pub type System = frame_system::Pallet<Runtime>;

/// PalletBalances: Manages your blockchain's native currency. (i.e. DOT on Polkadot)
#[runtime::pallet_index(1)]
pub type PalletBalances = pallet_balances::Pallet<Runtime>;

/// PalletKitties: The pallet you are building in this tutorial!
#[runtime::pallet_index(2)]
pub type PalletKitties = pallet_kitties::Pallet<Runtime>;
}

// Normally `System` would have many more configurations, but you can see that we use some macro
Expand Down
40 changes: 30 additions & 10 deletions steps/10/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use crate as pallet_kitties;
use crate::*;
use frame::deps::frame_support::runtime;
use frame::deps::sp_io;
use frame::runtime::prelude::*;
use frame::testing_prelude::*;
Expand All @@ -28,16 +29,35 @@ type Block = frame_system::mocking::MockBlock<TestRuntime>;
const ALICE: u64 = 1;
const BOB: u64 = 2;

// Our blockchain tests only need 3 Pallets:
// 1. System: Which is included with every FRAME runtime.
// 2. PalletBalances: Which is manages your blockchain's native currency. (i.e. DOT on Polkadot)
// 3. PalletKitties: The pallet you are building in this tutorial!
construct_runtime! {
pub struct TestRuntime {
System: frame_system,
PalletBalances: pallet_balances,
PalletKitties: pallet_kitties,
}
#[runtime]
mod runtime {
#[runtime::derive(
RuntimeCall,
RuntimeEvent,
RuntimeError,
RuntimeOrigin,
RuntimeTask,
RuntimeHoldReason,
RuntimeFreezeReason
)]
#[runtime::runtime]
/// The "test runtime" that represents the state transition function for our blockchain.
///
/// The runtime is composed of individual modules called "pallets", which you find see below.
/// Each pallet has its own logic and storage, all of which can be combined together.
pub struct TestRuntime;

/// System: Mandatory system pallet that should always be included in a FRAME runtime.
#[runtime::pallet_index(0)]
pub type System = frame_system::Pallet<Runtime>;

/// PalletBalances: Manages your blockchain's native currency. (i.e. DOT on Polkadot)
#[runtime::pallet_index(1)]
pub type PalletBalances = pallet_balances::Pallet<Runtime>;

/// PalletKitties: The pallet you are building in this tutorial!
#[runtime::pallet_index(2)]
pub type PalletKitties = pallet_kitties::Pallet<Runtime>;
}

// Normally `System` would have many more configurations, but you can see that we use some macro
Expand Down
40 changes: 30 additions & 10 deletions steps/11/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use crate as pallet_kitties;
use crate::*;
use frame::deps::frame_support::runtime;
use frame::deps::sp_io;
use frame::runtime::prelude::*;
use frame::testing_prelude::*;
Expand All @@ -28,16 +29,35 @@ type Block = frame_system::mocking::MockBlock<TestRuntime>;
const ALICE: u64 = 1;
const BOB: u64 = 2;

// Our blockchain tests only need 3 Pallets:
// 1. System: Which is included with every FRAME runtime.
// 2. PalletBalances: Which is manages your blockchain's native currency. (i.e. DOT on Polkadot)
// 3. PalletKitties: The pallet you are building in this tutorial!
construct_runtime! {
pub struct TestRuntime {
System: frame_system,
PalletBalances: pallet_balances,
PalletKitties: pallet_kitties,
}
#[runtime]
mod runtime {
#[runtime::derive(
RuntimeCall,
RuntimeEvent,
RuntimeError,
RuntimeOrigin,
RuntimeTask,
RuntimeHoldReason,
RuntimeFreezeReason
)]
#[runtime::runtime]
/// The "test runtime" that represents the state transition function for our blockchain.
///
/// The runtime is composed of individual modules called "pallets", which you find see below.
/// Each pallet has its own logic and storage, all of which can be combined together.
pub struct TestRuntime;

/// System: Mandatory system pallet that should always be included in a FRAME runtime.
#[runtime::pallet_index(0)]
pub type System = frame_system::Pallet<Runtime>;

/// PalletBalances: Manages your blockchain's native currency. (i.e. DOT on Polkadot)
#[runtime::pallet_index(1)]
pub type PalletBalances = pallet_balances::Pallet<Runtime>;

/// PalletKitties: The pallet you are building in this tutorial!
#[runtime::pallet_index(2)]
pub type PalletKitties = pallet_kitties::Pallet<Runtime>;
}

// Normally `System` would have many more configurations, but you can see that we use some macro
Expand Down
40 changes: 30 additions & 10 deletions steps/12/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use crate as pallet_kitties;
use crate::*;
use frame::deps::frame_support::runtime;
use frame::deps::sp_io;
use frame::runtime::prelude::*;
use frame::testing_prelude::*;
Expand All @@ -28,16 +29,35 @@ type Block = frame_system::mocking::MockBlock<TestRuntime>;
const ALICE: u64 = 1;
const BOB: u64 = 2;

// Our blockchain tests only need 3 Pallets:
// 1. System: Which is included with every FRAME runtime.
// 2. PalletBalances: Which is manages your blockchain's native currency. (i.e. DOT on Polkadot)
// 3. PalletKitties: The pallet you are building in this tutorial!
construct_runtime! {
pub struct TestRuntime {
System: frame_system,
PalletBalances: pallet_balances,
PalletKitties: pallet_kitties,
}
#[runtime]
mod runtime {
#[runtime::derive(
RuntimeCall,
RuntimeEvent,
RuntimeError,
RuntimeOrigin,
RuntimeTask,
RuntimeHoldReason,
RuntimeFreezeReason
)]
#[runtime::runtime]
/// The "test runtime" that represents the state transition function for our blockchain.
///
/// The runtime is composed of individual modules called "pallets", which you find see below.
/// Each pallet has its own logic and storage, all of which can be combined together.
pub struct TestRuntime;

/// System: Mandatory system pallet that should always be included in a FRAME runtime.
#[runtime::pallet_index(0)]
pub type System = frame_system::Pallet<Runtime>;

/// PalletBalances: Manages your blockchain's native currency. (i.e. DOT on Polkadot)
#[runtime::pallet_index(1)]
pub type PalletBalances = pallet_balances::Pallet<Runtime>;

/// PalletKitties: The pallet you are building in this tutorial!
#[runtime::pallet_index(2)]
pub type PalletKitties = pallet_kitties::Pallet<Runtime>;
}

// Normally `System` would have many more configurations, but you can see that we use some macro
Expand Down
40 changes: 30 additions & 10 deletions steps/13/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use crate as pallet_kitties;
use crate::*;
use frame::deps::frame_support::runtime;
use frame::deps::sp_io;
use frame::runtime::prelude::*;
use frame::testing_prelude::*;
Expand All @@ -28,16 +29,35 @@ type Block = frame_system::mocking::MockBlock<TestRuntime>;
const ALICE: u64 = 1;
const BOB: u64 = 2;

// Our blockchain tests only need 3 Pallets:
// 1. System: Which is included with every FRAME runtime.
// 2. PalletBalances: Which is manages your blockchain's native currency. (i.e. DOT on Polkadot)
// 3. PalletKitties: The pallet you are building in this tutorial!
construct_runtime! {
pub struct TestRuntime {
System: frame_system,
PalletBalances: pallet_balances,
PalletKitties: pallet_kitties,
}
#[runtime]
mod runtime {
#[runtime::derive(
RuntimeCall,
RuntimeEvent,
RuntimeError,
RuntimeOrigin,
RuntimeTask,
RuntimeHoldReason,
RuntimeFreezeReason
)]
#[runtime::runtime]
/// The "test runtime" that represents the state transition function for our blockchain.
///
/// The runtime is composed of individual modules called "pallets", which you find see below.
/// Each pallet has its own logic and storage, all of which can be combined together.
pub struct TestRuntime;

/// System: Mandatory system pallet that should always be included in a FRAME runtime.
#[runtime::pallet_index(0)]
pub type System = frame_system::Pallet<Runtime>;

/// PalletBalances: Manages your blockchain's native currency. (i.e. DOT on Polkadot)
#[runtime::pallet_index(1)]
pub type PalletBalances = pallet_balances::Pallet<Runtime>;

/// PalletKitties: The pallet you are building in this tutorial!
#[runtime::pallet_index(2)]
pub type PalletKitties = pallet_kitties::Pallet<Runtime>;
}

// Normally `System` would have many more configurations, but you can see that we use some macro
Expand Down
40 changes: 30 additions & 10 deletions steps/14/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use crate as pallet_kitties;
use crate::*;
use frame::deps::frame_support::runtime;
use frame::deps::sp_io;
use frame::runtime::prelude::*;
use frame::testing_prelude::*;
Expand All @@ -28,16 +29,35 @@ type Block = frame_system::mocking::MockBlock<TestRuntime>;
const ALICE: u64 = 1;
const BOB: u64 = 2;

// Our blockchain tests only need 3 Pallets:
// 1. System: Which is included with every FRAME runtime.
// 2. PalletBalances: Which is manages your blockchain's native currency. (i.e. DOT on Polkadot)
// 3. PalletKitties: The pallet you are building in this tutorial!
construct_runtime! {
pub struct TestRuntime {
System: frame_system,
PalletBalances: pallet_balances,
PalletKitties: pallet_kitties,
}
#[runtime]
mod runtime {
#[runtime::derive(
RuntimeCall,
RuntimeEvent,
RuntimeError,
RuntimeOrigin,
RuntimeTask,
RuntimeHoldReason,
RuntimeFreezeReason
)]
#[runtime::runtime]
/// The "test runtime" that represents the state transition function for our blockchain.
///
/// The runtime is composed of individual modules called "pallets", which you find see below.
/// Each pallet has its own logic and storage, all of which can be combined together.
pub struct TestRuntime;

/// System: Mandatory system pallet that should always be included in a FRAME runtime.
#[runtime::pallet_index(0)]
pub type System = frame_system::Pallet<Runtime>;

/// PalletBalances: Manages your blockchain's native currency. (i.e. DOT on Polkadot)
#[runtime::pallet_index(1)]
pub type PalletBalances = pallet_balances::Pallet<Runtime>;

/// PalletKitties: The pallet you are building in this tutorial!
#[runtime::pallet_index(2)]
pub type PalletKitties = pallet_kitties::Pallet<Runtime>;
}

// Normally `System` would have many more configurations, but you can see that we use some macro
Expand Down
40 changes: 30 additions & 10 deletions steps/15/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use crate as pallet_kitties;
use crate::*;
use frame::deps::frame_support::runtime;
use frame::deps::sp_io;
use frame::runtime::prelude::*;
use frame::testing_prelude::*;
Expand All @@ -28,16 +29,35 @@ type Block = frame_system::mocking::MockBlock<TestRuntime>;
const ALICE: u64 = 1;
const BOB: u64 = 2;

// Our blockchain tests only need 3 Pallets:
// 1. System: Which is included with every FRAME runtime.
// 2. PalletBalances: Which is manages your blockchain's native currency. (i.e. DOT on Polkadot)
// 3. PalletKitties: The pallet you are building in this tutorial!
construct_runtime! {
pub struct TestRuntime {
System: frame_system,
PalletBalances: pallet_balances,
PalletKitties: pallet_kitties,
}
#[runtime]
mod runtime {
#[runtime::derive(
RuntimeCall,
RuntimeEvent,
RuntimeError,
RuntimeOrigin,
RuntimeTask,
RuntimeHoldReason,
RuntimeFreezeReason
)]
#[runtime::runtime]
/// The "test runtime" that represents the state transition function for our blockchain.
///
/// The runtime is composed of individual modules called "pallets", which you find see below.
/// Each pallet has its own logic and storage, all of which can be combined together.
pub struct TestRuntime;

/// System: Mandatory system pallet that should always be included in a FRAME runtime.
#[runtime::pallet_index(0)]
pub type System = frame_system::Pallet<Runtime>;

/// PalletBalances: Manages your blockchain's native currency. (i.e. DOT on Polkadot)
#[runtime::pallet_index(1)]
pub type PalletBalances = pallet_balances::Pallet<Runtime>;

/// PalletKitties: The pallet you are building in this tutorial!
#[runtime::pallet_index(2)]
pub type PalletKitties = pallet_kitties::Pallet<Runtime>;
}

// Normally `System` would have many more configurations, but you can see that we use some macro
Expand Down
Loading

0 comments on commit de4d70e

Please sign in to comment.