mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 01:47:55 +00:00
removed pallet::getter from example pallets (#3371)
part of #3326 @ggwpez @kianenigma @shawntabrizi --------- Signed-off-by: Matteo Muraca <mmuraca247@gmail.com> Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
This commit is contained in:
@@ -48,7 +48,7 @@ mod benchmarks {
|
||||
set_dummy(RawOrigin::Root, value); // The execution phase is just running `set_dummy` extrinsic call
|
||||
|
||||
// This is the optional benchmark verification phase, asserting certain states.
|
||||
assert_eq!(Pallet::<T>::dummy(), Some(value))
|
||||
assert_eq!(Dummy::<T>::get(), Some(value))
|
||||
}
|
||||
|
||||
// An example method that returns a Result that can be called within a benchmark
|
||||
|
||||
@@ -286,9 +286,7 @@ pub mod pallet {
|
||||
let _sender = ensure_signed(origin)?;
|
||||
|
||||
// Read the value of dummy from storage.
|
||||
// let dummy = Self::dummy();
|
||||
// Will also work using the `::get` on the storage item type itself:
|
||||
// let dummy = <Dummy<T>>::get();
|
||||
// let dummy = Dummy::<T>::get();
|
||||
|
||||
// Calculate the new value.
|
||||
// let new_dummy = dummy.map_or(increase_by, |dummy| dummy + increase_by);
|
||||
@@ -381,20 +379,14 @@ pub mod pallet {
|
||||
// - `Foo::put(1); Foo::get()` returns `1`;
|
||||
// - `Foo::kill(); Foo::get()` returns `0` (u32::default()).
|
||||
#[pallet::storage]
|
||||
// The getter attribute generate a function on `Pallet` placeholder:
|
||||
// `fn getter_name() -> Type` for basic value items or
|
||||
// `fn getter_name(key: KeyType) -> ValueType` for map items.
|
||||
#[pallet::getter(fn dummy)]
|
||||
pub(super) type Dummy<T: Config> = StorageValue<_, T::Balance>;
|
||||
|
||||
// A map that has enumerable entries.
|
||||
#[pallet::storage]
|
||||
#[pallet::getter(fn bar)]
|
||||
pub(super) type Bar<T: Config> = StorageMap<_, Blake2_128Concat, T::AccountId, T::Balance>;
|
||||
|
||||
// this one uses the query kind: `ValueQuery`, we'll demonstrate the usage of 'mutate' API.
|
||||
#[pallet::storage]
|
||||
#[pallet::getter(fn foo)]
|
||||
pub(super) type Foo<T: Config> = StorageValue<_, T::Balance, ValueQuery>;
|
||||
|
||||
#[pallet::storage]
|
||||
@@ -433,10 +425,10 @@ impl<T: Config> Pallet<T> {
|
||||
fn accumulate_foo(origin: T::RuntimeOrigin, increase_by: T::Balance) -> DispatchResult {
|
||||
let _sender = ensure_signed(origin)?;
|
||||
|
||||
let prev = <Foo<T>>::get();
|
||||
let prev = Foo::<T>::get();
|
||||
// Because Foo has 'default', the type of 'foo' in closure is the raw type instead of an
|
||||
// Option<> type.
|
||||
let result = <Foo<T>>::mutate(|foo| {
|
||||
let result = Foo::<T>::mutate(|foo| {
|
||||
*foo = foo.saturating_add(increase_by);
|
||||
*foo
|
||||
});
|
||||
|
||||
@@ -119,25 +119,25 @@ fn it_works_for_optional_value() {
|
||||
// Check that GenesisBuilder works properly.
|
||||
let val1 = 42;
|
||||
let val2 = 27;
|
||||
assert_eq!(Example::dummy(), Some(val1));
|
||||
assert_eq!(Dummy::<Test>::get(), Some(val1));
|
||||
|
||||
// Check that accumulate works when we have Some value in Dummy already.
|
||||
assert_ok!(Example::accumulate_dummy(RuntimeOrigin::signed(1), val2));
|
||||
assert_eq!(Example::dummy(), Some(val1 + val2));
|
||||
assert_eq!(Dummy::<Test>::get(), Some(val1 + val2));
|
||||
|
||||
// Check that accumulate works when we Dummy has None in it.
|
||||
<Example as OnInitialize<u64>>::on_initialize(2);
|
||||
assert_ok!(Example::accumulate_dummy(RuntimeOrigin::signed(1), val1));
|
||||
assert_eq!(Example::dummy(), Some(val1 + val2 + val1));
|
||||
assert_eq!(Dummy::<Test>::get(), Some(val1 + val2 + val1));
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn it_works_for_default_value() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_eq!(Example::foo(), 24);
|
||||
assert_eq!(Foo::<Test>::get(), 24);
|
||||
assert_ok!(Example::accumulate_foo(RuntimeOrigin::signed(1), 1));
|
||||
assert_eq!(Example::foo(), 25);
|
||||
assert_eq!(Foo::<Test>::get(), 25);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -146,7 +146,7 @@ fn set_dummy_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let test_val = 133;
|
||||
assert_ok!(Example::set_dummy(RuntimeOrigin::root(), test_val.into()));
|
||||
assert_eq!(Example::dummy(), Some(test_val));
|
||||
assert_eq!(Dummy::<Test>::get(), Some(test_val));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user