difftreelog
Substrate 2
in: master
4 files changed
Cargo.lockdiffbeforeafterboth--- a/Cargo.lock
+++ b/Cargo.lock
@@ -2859,6 +2859,7 @@
"sp-core",
"sp-io",
"sp-runtime",
+ "sp-std",
]
[[package]]
pallets/template/Cargo.tomldiffbeforeafterboth--- a/pallets/template/Cargo.toml
+++ b/pallets/template/Cargo.toml
@@ -17,6 +17,14 @@
package = 'parity-scale-codec'
version = '1.3.0'
+[dependencies.sp-std]
+default-features = false
+version = '2.0.0-alpha.6'
+
+[dependencies.sp-runtime]
+default-features = false
+version = '2.0.0-alpha.6'
+
[dependencies.frame-support]
default-features = false
version = '2.0.0-alpha.6'
@@ -32,14 +40,15 @@
default-features = false
version = '2.0.0-alpha.6'
-[dev-dependencies.sp-runtime]
-default-features = false
-version = '2.0.0-alpha.6'
+
[features]
default = ['std']
std = [
'codec/std',
'frame-support/std',
'frame-system/std',
+ "sp-io/std",
+ "sp-runtime/std",
+ 'sp-std/std',
]
pallets/template/src/lib.rsdiffbeforeafterboth1#![cfg_attr(not(feature = "std"), no_std)]23/// A FRAME pallet template with necessary imports45/// Feel free to remove or edit this file as needed.6/// If you change the name of this file, make sure to update its references in runtime/src/lib.rs7/// If you remove this file, you can remove those references89/// For more guidance on Substrate FRAME, see the example pallet10/// https://github.com/paritytech/substrate/blob/master/frame/example/src/lib.rs1112use frame_support::{decl_module, decl_storage, decl_event, decl_error, dispatch};13use frame_system::{self as system, ensure_signed};1415#[cfg(test)]16mod mock;1718#[cfg(test)]19mod tests;2021/// The pallet's configuration trait.22pub trait Trait: system::Trait {23 // Add other types and constants required to configure this pallet.2425 /// The overarching event type.26 type Event: From<Event<Self>> + Into<<Self as system::Trait>::Event>;27}2829// This pallet's storage items.30decl_storage! {31 // It is important to update your storage name so that your pallet's32 // storage items are isolated from other pallets.33 // ---------------------------------vvvvvvvvvvvvvv34 trait Store for Module<T: Trait> as TemplateModule {35 // Just a dummy storage item.36 // Here we are declaring a StorageValue, `Something` as a Option<u32>37 // `get(fn something)` is the default getter which returns either the stored `u32` or `None` if nothing stored38 Something get(fn something): Option<u32>;39 }40}4142// The pallet's events43decl_event!(44 pub enum Event<T> where AccountId = <T as system::Trait>::AccountId {45 /// Just a dummy event.46 /// Event `Something` is declared with a parameter of the type `u32` and `AccountId`47 /// To emit this event, we call the deposit function, from our runtime functions48 SomethingStored(u32, AccountId),49 }50);5152// The pallet's errors53decl_error! {54 pub enum Error for Module<T: Trait> {55 /// Value was None56 NoneValue,57 /// Value reached maximum and cannot be incremented further58 StorageOverflow,59 }60}6162// The pallet's dispatchable functions.63decl_module! {64 /// The module declaration.65 pub struct Module<T: Trait> for enum Call where origin: T::Origin {66 // Initializing errors67 // this includes information about your errors in the node's metadata.68 // it is needed only if you are using errors in your pallet69 type Error = Error<T>;7071 // Initializing events72 // this is needed only if you are using events in your pallet73 fn deposit_event() = default;7475 /// Just a dummy entry point.76 /// function that can be called by the external world as an extrinsics call77 /// takes a parameter of the type `AccountId`, stores it, and emits an event78 #[weight = frame_support::weights::SimpleDispatchInfo::default()]79 pub fn do_something(origin, something: u32) -> dispatch::DispatchResult {80 // Check it was signed and get the signer. See also: ensure_root and ensure_none81 let who = ensure_signed(origin)?;8283 // Code to execute when something calls this.84 // For example: the following line stores the passed in u32 in the storage85 Something::put(something);8687 // Here we are raising the Something event88 Self::deposit_event(RawEvent::SomethingStored(something, who));89 Ok(())90 }9192 /// Another dummy entry point.93 /// takes no parameters, attempts to increment storage value, and possibly throws an error94 #[weight = frame_support::weights::SimpleDispatchInfo::default()]95 pub fn cause_error(origin) -> dispatch::DispatchResult {96 // Check it was signed and get the signer. See also: ensure_root and ensure_none97 let _who = ensure_signed(origin)?;9899 match Something::get() {100 None => Err(Error::<T>::NoneValue)?,101 Some(old) => {102 let new = old.checked_add(1).ok_or(Error::<T>::StorageOverflow)?;103 Something::put(new);104 Ok(())105 },106 }107 }108 }109}pallets/template/src/tests.rsdiffbeforeafterboth--- a/pallets/template/src/tests.rs
+++ b/pallets/template/src/tests.rs
@@ -1,26 +1,24 @@
// Tests to be written here
-
-use crate::{Error, mock::*};
use frame_support::{assert_ok, assert_noop};
-#[test]
-fn it_works_for_default_value() {
- new_test_ext().execute_with(|| {
- // Just a dummy test for the dummy function `do_something`
- // calling the `do_something` function with a value 42
- assert_ok!(TemplateModule::do_something(Origin::signed(1), 42));
- // asserting that the stored value is equal to what we stored
- assert_eq!(TemplateModule::something(), Some(42));
- });
-}
+// #[test]
+// fn it_works_for_default_value() {
+// new_test_ext().execute_with(|| {
+// // Just a dummy test for the dummy function `do_something`
+// // calling the `do_something` function with a value 42
+// assert_ok!(TemplateModule::do_something(Origin::signed(1), 42));
+// // asserting that the stored value is equal to what we stored
+// assert_eq!(TemplateModule::something(), Some(42));
+// });
+// }
-#[test]
-fn correct_error_for_none_value() {
- new_test_ext().execute_with(|| {
- // Ensure the correct error is thrown on None value
- assert_noop!(
- TemplateModule::cause_error(Origin::signed(1)),
- Error::<Test>::NoneValue
- );
- });
-}
+// #[test]
+// fn correct_error_for_none_value() {
+// new_test_ext().execute_with(|| {
+// // Ensure the correct error is thrown on None value
+// assert_noop!(
+// TemplateModule::cause_error(Origin::signed(1)),
+// Error::<Test>::NoneValue
+// );
+// });
+// }