@@ -11,8 +11,9 @@ use sp_consensus_aura::sr25519::AuthorityId as AuraId;
1111use sp_core:: U256 ;
1212use sp_core:: { ConstU64 , H256 } ;
1313use sp_runtime:: {
14+ testing:: TestXt ,
1415 traits:: { BlakeTwo256 , ConstU32 , IdentityLookup } ,
15- BuildStorage , Perbill ,
16+ BuildStorage , KeyTypeId , Perbill ,
1617} ;
1718use sp_std:: cmp:: Ordering ;
1819use sp_weights:: Weight ;
@@ -21,13 +22,13 @@ type Block = frame_system::mocking::MockBlock<Test>;
2122
2223// Configure a mock runtime to test the pallet.
2324frame_support:: construct_runtime!(
24- pub enum Test
25- {
25+ pub enum Test {
2626 System : frame_system = 1 ,
2727 Balances : pallet_balances = 2 ,
2828 AdminUtils : pallet_admin_utils = 3 ,
2929 SubtensorModule : pallet_subtensor:: { Pallet , Call , Storage , Event <T >, Error <T >} = 4 ,
3030 Scheduler : pallet_scheduler:: { Pallet , Call , Storage , Event <T >} = 5 ,
31+ Drand : pallet_drand:: { Pallet , Call , Storage , Event <T >} = 6 ,
3132 }
3233) ;
3334
@@ -63,6 +64,10 @@ pub type Balance = u64;
6364#[ allow( dead_code) ]
6465pub type BlockNumber = u64 ;
6566
67+ pub type TestAuthId = test_crypto:: TestAuthId ;
68+ pub type Index = u64 ;
69+ pub type UncheckedExtrinsic = TestXt < RuntimeCall , ( ) > ;
70+
6671parameter_types ! {
6772 pub const InitialMinAllowedWeights : u16 = 0 ;
6873 pub const InitialEmissionValue : u16 = 0 ;
@@ -272,6 +277,74 @@ impl pallet_scheduler::Config for Test {
272277 type Preimages = ( ) ;
273278}
274279
280+ impl pallet_drand:: Config for Test {
281+ type RuntimeEvent = RuntimeEvent ;
282+ type WeightInfo = pallet_drand:: weights:: SubstrateWeight < Test > ;
283+ type AuthorityId = TestAuthId ;
284+ type Verifier = pallet_drand:: verifier:: QuicknetVerifier ;
285+ type UnsignedPriority = ConstU64 < { 1 << 20 } > ;
286+ type HttpFetchTimeout = ConstU64 < 1_000 > ;
287+ }
288+
289+ impl frame_system:: offchain:: SigningTypes for Test {
290+ type Public = test_crypto:: Public ;
291+ type Signature = test_crypto:: Signature ;
292+ }
293+
294+ pub const KEY_TYPE : KeyTypeId = KeyTypeId ( * b"test" ) ;
295+
296+ mod test_crypto {
297+ use super :: KEY_TYPE ;
298+ use sp_core:: sr25519:: { Public as Sr25519Public , Signature as Sr25519Signature } ;
299+ use sp_core:: U256 ;
300+ use sp_runtime:: {
301+ app_crypto:: { app_crypto, sr25519} ,
302+ traits:: IdentifyAccount ,
303+ } ;
304+
305+ app_crypto ! ( sr25519, KEY_TYPE ) ;
306+
307+ pub struct TestAuthId ;
308+
309+ impl frame_system:: offchain:: AppCrypto < Public , Signature > for TestAuthId {
310+ type RuntimeAppPublic = Public ;
311+ type GenericSignature = Sr25519Signature ;
312+ type GenericPublic = Sr25519Public ;
313+ }
314+
315+ impl IdentifyAccount for Public {
316+ type AccountId = U256 ;
317+
318+ fn into_account ( self ) -> U256 {
319+ let mut bytes = [ 0u8 ; 32 ] ;
320+ bytes. copy_from_slice ( self . as_ref ( ) ) ;
321+ U256 :: from_big_endian ( & bytes)
322+ }
323+ }
324+ }
325+
326+ impl frame_system:: offchain:: CreateSignedTransaction < pallet_drand:: Call < Test > > for Test {
327+ fn create_transaction < C : frame_system:: offchain:: AppCrypto < Self :: Public , Self :: Signature > > (
328+ call : RuntimeCall ,
329+ _public : Self :: Public ,
330+ _account : Self :: AccountId ,
331+ nonce : Index ,
332+ ) -> Option < (
333+ RuntimeCall ,
334+ <UncheckedExtrinsic as sp_runtime:: traits:: Extrinsic >:: SignaturePayload ,
335+ ) > {
336+ Some ( ( call, ( nonce, ( ) ) ) )
337+ }
338+ }
339+
340+ impl < C > frame_system:: offchain:: SendTransactionTypes < C > for Test
341+ where
342+ RuntimeCall : From < C > ,
343+ {
344+ type Extrinsic = UncheckedExtrinsic ;
345+ type OverarchingCall = RuntimeCall ;
346+ }
347+
275348// Build genesis storage according to the mock runtime.
276349pub fn new_test_ext ( ) -> sp_io:: TestExternalities {
277350 sp_tracing:: try_init_simple ( ) ;
0 commit comments