Skip to content
This repository was archived by the owner on Feb 21, 2024. It is now read-only.

Commit 9421866

Browse files
shaunxwnazar-pc
authored andcommitted
Migrate pallet-lottery to pallet attribute macro (paritytech#8762)
* Migrate pallet-lottery to pallet attribute macro. * Fix metadata inconsistency. * fix * Use DispatchResult in call returns.
1 parent 0b6c674 commit 9421866

5 files changed

Lines changed: 198 additions & 176 deletions

File tree

bin/node/runtime/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1019,7 +1019,7 @@ impl pallet_mmr::Config for Runtime {
10191019

10201020
parameter_types! {
10211021
pub const LotteryPalletId: PalletId = PalletId(*b"py/lotto");
1022-
pub const MaxCalls: usize = 10;
1022+
pub const MaxCalls: u32 = 10;
10231023
pub const MaxGenerateRandom: u32 = 10;
10241024
}
10251025

frame/lottery/src/benchmarking.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@
2222
use super::*;
2323

2424
use frame_system::RawOrigin;
25-
use frame_support::traits::{OnInitialize, UnfilteredDispatchable};
25+
use frame_support::traits::{EnsureOrigin, OnInitialize, UnfilteredDispatchable};
2626
use frame_benchmarking::{benchmarks, account, whitelisted_caller, impl_benchmark_test_suite};
2727
use sp_runtime::traits::{Bounded, Zero};
2828

29-
use crate::Module as Lottery;
29+
use crate::Pallet as Lottery;
3030

3131
// Set up and start a lottery
3232
fn setup_lottery<T: Config>(repeat: bool) -> Result<(), &'static str> {
@@ -36,7 +36,7 @@ fn setup_lottery<T: Config>(repeat: bool) -> Result<(), &'static str> {
3636
// Calls will be maximum length...
3737
let mut calls = vec![
3838
frame_system::Call::<T>::set_code(vec![]).into();
39-
T::MaxCalls::get().saturating_sub(1)
39+
T::MaxCalls::get().saturating_sub(1) as usize
4040
];
4141
// Last call will be the match for worst case scenario.
4242
calls.push(frame_system::Call::<T>::remark(vec![]).into());
@@ -56,18 +56,18 @@ benchmarks! {
5656
&frame_system::Call::<T>::set_code(vec![]).into()
5757
)?;
5858
let already_called: (u32, Vec<CallIndex>) = (
59-
LotteryIndex::get(),
59+
LotteryIndex::<T>::get(),
6060
vec![
6161
set_code_index;
62-
T::MaxCalls::get().saturating_sub(1)
62+
T::MaxCalls::get().saturating_sub(1) as usize
6363
],
6464
);
6565
Participants::<T>::insert(&caller, already_called);
6666

6767
let call = frame_system::Call::<T>::remark(vec![]);
6868
}: _(RawOrigin::Signed(caller), Box::new(call.into()))
6969
verify {
70-
assert_eq!(TicketsCount::get(), 1);
70+
assert_eq!(TicketsCount::<T>::get(), 1);
7171
}
7272

7373
set_calls {
@@ -76,11 +76,11 @@ benchmarks! {
7676

7777
let call = Call::<T>::set_calls(calls);
7878
let origin = T::ManagerOrigin::successful_origin();
79-
assert!(CallIndices::get().is_empty());
79+
assert!(CallIndices::<T>::get().is_empty());
8080
}: { call.dispatch_bypass_filter(origin)? }
8181
verify {
8282
if !n.is_zero() {
83-
assert!(!CallIndices::get().is_empty());
83+
assert!(!CallIndices::<T>::get().is_empty());
8484
}
8585
}
8686

@@ -120,7 +120,7 @@ benchmarks! {
120120
// Kill user account for worst case
121121
T::Currency::make_free_balance_be(&winner, 0u32.into());
122122
// Assert that lotto is set up for winner
123-
assert_eq!(TicketsCount::get(), 1);
123+
assert_eq!(TicketsCount::<T>::get(), 1);
124124
assert!(!Lottery::<T>::pot().1.is_zero());
125125
}: {
126126
// Generate `MaxGenerateRandom` numbers for worst case scenario
@@ -132,7 +132,7 @@ benchmarks! {
132132
}
133133
verify {
134134
assert!(crate::Lottery::<T>::get().is_none());
135-
assert_eq!(TicketsCount::get(), 0);
135+
assert_eq!(TicketsCount::<T>::get(), 0);
136136
assert_eq!(Lottery::<T>::pot().1, 0u32.into());
137137
assert!(!T::Currency::free_balance(&winner).is_zero())
138138
}
@@ -151,7 +151,7 @@ benchmarks! {
151151
// Kill user account for worst case
152152
T::Currency::make_free_balance_be(&winner, 0u32.into());
153153
// Assert that lotto is set up for winner
154-
assert_eq!(TicketsCount::get(), 1);
154+
assert_eq!(TicketsCount::<T>::get(), 1);
155155
assert!(!Lottery::<T>::pot().1.is_zero());
156156
}: {
157157
// Generate `MaxGenerateRandom` numbers for worst case scenario
@@ -163,8 +163,8 @@ benchmarks! {
163163
}
164164
verify {
165165
assert!(crate::Lottery::<T>::get().is_some());
166-
assert_eq!(LotteryIndex::get(), 2);
167-
assert_eq!(TicketsCount::get(), 0);
166+
assert_eq!(LotteryIndex::<T>::get(), 2);
167+
assert_eq!(TicketsCount::<T>::get(), 0);
168168
assert_eq!(Lottery::<T>::pot().1, 0u32.into());
169169
assert!(!T::Currency::free_balance(&winner).is_zero())
170170
}

0 commit comments

Comments
 (0)