Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 42 additions & 13 deletions pallets/ipfs/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@ use frame_system::offchain::{
};
use pallet_session::{ SessionHandler, ShouldEndSession };
use pallet_staking::TestBenchmarkingConfig;
use sp_core::{ sr25519::{ Public, Signature }, ConstU16, ConstU32, ConstU64, Get, H256, ConstU128 };
use sp_core::{ sr25519::{ Public, Signature }, ConstU16, ConstU32, ConstU64, Get, H256, ConstU128, ConstBool };

use crate::Call as IpfsCall;

use sp_runtime::{
curve::PiecewiseLinear,
testing::{ TestXt, UintAuthorityId },
traits::{ BlakeTwo256, IdentityLookup },
generic::UncheckedExtrinsic,
BuildStorage,
KeyTypeId,
Perbill,
Expand Down Expand Up @@ -164,10 +167,10 @@ impl SigningTypes for Test {
// STAKING
impl pallet_staking::Config for Test {
type NominationsQuota = pallet_staking::FixedNominationsQuota<16>;
type OldCurrency = Balances;
type Currency = Balances;
type CurrencyBalance = Balance;
type UnixTime = Timestamp;
type OffendingValidatorsThreshold = OffendingValidatorsThreshold;
type CurrencyToVote = SaturatingCurrencyToVote;
type ElectionProvider = onchain::OnChainExecution<OnChainSeqPhragmen>;
type GenesisElectionProvider = Self::ElectionProvider;
Expand All @@ -191,6 +194,9 @@ impl pallet_staking::Config for Test {
type EventListeners = ();
type BenchmarkingConfig = TestBenchmarkingConfig;
type WeightInfo = ();
type RuntimeHoldReason = RuntimeHoldReason;
type MaxValidatorSet = ConstU32<1000>;
type Filter = frame_support::traits::Nothing;
}

// REQUIRED BY type ElectionProvider = onchain::OnChainExecution<OnChainSeqPhragmen>;
Expand All @@ -199,21 +205,42 @@ impl onchain::Config for OnChainSeqPhragmen {
type Solver = SequentialPhragmen<AccountId, Perbill>;
type DataProvider = Staking;
type WeightInfo = ();
type MaxWinners = ConstU32<100>;
type Bounds = ElectionsBounds;
type Sort = ConstBool<true>;
type MaxBackersPerWinner = ConstU32<{ u32::MAX }>;
type MaxWinnersPerPage = ConstU32<{ u32::MAX }>;

}


impl CreateSignedTransaction<crate::Call<Test>> for Test {
fn create_transaction<C: AppCrypto<Self::Public, Self::Signature>>(
call: crate::Call<Test>,
_public: Self::Public,
_account: <Test as frame_system::Config>::AccountId,
nonce: <Test as frame_system::Config>::Nonce
) -> Option<(crate::Call<Test>, (u64, (u64, ())))> {
Some((call, (nonce, (nonce, ()))))
fn create_signed_transaction<C: AppCrypto<Self::Public, Self::Signature>>(
call: <Self as frame_system::offchain::CreateTransactionBase<IpfsCall<Test>>>::RuntimeCall,
_public: <Self as SigningTypes>::Public,
account: <Self as frame_system::Config>::AccountId,
nonce: <Self as frame_system::Config>::Nonce,
) -> Option<<Self as frame_system::offchain::CreateTransactionBase<IpfsCall<Test>>>::Extrinsic> {
Some(UncheckedExtrinsic::new_signed(call, account.into(), (), ()))
}
}
impl<C> frame_system::offchain::CreateTransactionBase<C> for Test
where
RuntimeCall: From<C>,
{
type Extrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type RuntimeCall = RuntimeCall;
}


impl<C> frame_system::offchain::CreateBare<C> for Test
where
RuntimeCall: From<C>,
{
fn create_bare(call: Self::RuntimeCall) -> Self::Extrinsic {
frame_system::mocking::MockUncheckedExtrinsic::<Test>::new_bare(call)
}
}


// BALANCES
impl pallet_balances::Config for Test {
Expand All @@ -228,20 +255,22 @@ impl pallet_balances::Config for Test {
type WeightInfo = ();
type FreezeIdentifier = ();
type MaxFreezes = ();
type RuntimeHoldReason = ();
type RuntimeHoldReason = RuntimeHoldReason;
type RuntimeFreezeReason = ();
type DoneSlashHandler = ();
}
// SESSION
impl pallet_session::Config for Test {
type RuntimeEvent = RuntimeEvent;
type ValidatorId = AccountId;
type ValidatorIdOf = pallet_staking::StashOf<Self>;
type ValidatorIdOf = sp_runtime::traits::ConvertInto;
type ShouldEndSession = TestShouldEndSession;
type NextSessionRotation = TestNextSessionRotation;
type SessionManager = ();
type SessionHandler = TestSessionHandler;
type Keys = UintAuthorityId;
type WeightInfo = ();
type DisablingStrategy = ();
}

impl EstimateNextSessionRotation<BlockNumber> for TestNextSessionRotation {
Expand Down Expand Up @@ -286,7 +315,7 @@ impl pallet_timestamp::Config for Test {
pub fn new_test_ext() -> sp_io::TestExternalities {
let mut t = frame_system::GenesisConfig::<Test>::default().build_storage().unwrap();

(pallet_balances::GenesisConfig::<Test> { balances: vec![] })
(pallet_balances::GenesisConfig::<Test> { balances: vec![], dev_accounts: None })
.assimilate_storage(&mut t)
.unwrap();

Expand Down
83 changes: 53 additions & 30 deletions pallets/tss/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use frame_support::{
construct_runtime, derive_impl, dispatch::DispatchResult, parameter_types,
traits::EstimateNextSessionRotation, weights::Weight,
};
use frame_system::offchain::{CreateSignedTransaction, SigningTypes};
use frame_system::offchain::{AppCrypto, CreateSignedTransaction, SigningTypes};
use pallet_babe;
use pallet_ipfs::{
self,
Expand All @@ -29,6 +29,7 @@ use sp_runtime::{
curve::PiecewiseLinear,
testing::{TestXt, UintAuthorityId},
traits::{BlakeTwo256, IdentityLookup},
generic::UncheckedExtrinsic,
BuildStorage, DispatchError, KeyTypeId, Perbill, Permill, RuntimeAppPublic,
};
use sp_staking::currency_to_vote::SaturatingCurrencyToVote;
Expand Down Expand Up @@ -94,13 +95,14 @@ construct_runtime!(
impl pallet_session::Config for Test {
type RuntimeEvent = RuntimeEvent;
type ValidatorId = AccountId;
type ValidatorIdOf = pallet_staking::StashOf<Self>;
type ValidatorIdOf = sp_runtime::traits::ConvertInto;
type ShouldEndSession = TestShouldEndSession;
type NextSessionRotation = TestNextSessionRotation;
type SessionManager = ();
type SessionHandler = TestSessionHandler;
type Keys = UintAuthorityId;
type WeightInfo = ();
type DisablingStrategy = ();
}

// Provide an identity converter (AccountId -> Option<AccountId>) for historical session pallet
Expand All @@ -110,6 +112,7 @@ impl Convert<AccountId, Option<AccountId>> for IdentityOf {
}

impl pallet_session::historical::Config for Test {
type RuntimeEvent = RuntimeEvent;
type FullIdentification = AccountId; // minimal
type FullIdentificationOf = IdentityOf; // simple identity mapping
}
Expand Down Expand Up @@ -148,13 +151,13 @@ impl frame_system::Config for Test {


impl CreateSignedTransaction<UomiCall<Test>> for Test {
fn create_transaction<C: frame_system::offchain::AppCrypto<Self::Public, Self::Signature>>(
call: UomiCall<Test>,
_public: Self::Public,
_account: <Test as frame_system::Config>::AccountId,
nonce: <Test as frame_system::Config>::Nonce,
) -> Option<(UomiCall<Test>, (u64, (u64, ())))> {
Some((call, (nonce, (nonce, ()))))
fn create_signed_transaction<C: AppCrypto<Self::Public, Self::Signature>>(
call: <Self as frame_system::offchain::CreateTransactionBase<UomiCall<Test>>>::RuntimeCall,
_public: <Self as SigningTypes>::Public,
account: <Self as frame_system::Config>::AccountId,
nonce: <Self as frame_system::Config>::Nonce,
) -> Option<<Self as frame_system::offchain::CreateTransactionBase<UomiCall<Test>>>::Extrinsic> {
Some(UncheckedExtrinsic::new_signed(call, account.into(), (), ()))
}
}

Expand Down Expand Up @@ -190,16 +193,13 @@ impl<Reporter, Offender, Off: sp_staking::offence::Offence<Offender>> sp_staking
}

impl CreateSignedTransaction<crate::pallet::Call<Test>> for Test {
fn create_transaction<C: frame_system::offchain::AppCrypto<Self::Public, Self::Signature>>(
call: Self::OverarchingCall,
_public: Self::Public,
_account: Self::AccountId,
nonce: Self::Nonce,
) -> Option<(
Self::OverarchingCall,
<Self::Extrinsic as sp_runtime::traits::Extrinsic>::SignaturePayload,
)> {
Some((call, (nonce, (nonce, ()))))
fn create_signed_transaction<C: AppCrypto<Self::Public, Self::Signature>>(
call: <Self as frame_system::offchain::CreateTransactionBase<crate::pallet::Call<Test>>>::RuntimeCall,
_public: <Self as SigningTypes>::Public,
account: <Self as frame_system::Config>::AccountId,
nonce: <Self as frame_system::Config>::Nonce,
) -> Option<<Self as frame_system::offchain::CreateTransactionBase<crate::pallet::Call<Test>>>::Extrinsic> {
Some(UncheckedExtrinsic::new_signed(call, account.into(), (), ()))
}
}

Expand Down Expand Up @@ -279,6 +279,23 @@ impl SigningTypes for Test {
type Signature = Signature;
}

impl<C> frame_system::offchain::CreateTransactionBase<C> for Test
where
RuntimeCall: From<C>,
{
type Extrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type RuntimeCall = RuntimeCall;
}

impl<C> frame_system::offchain::CreateBare<C> for Test
where
RuntimeCall: From<C>,
{
fn create_bare(call: Self::RuntimeCall) -> Self::Extrinsic {
frame_system::mocking::MockUncheckedExtrinsic::<Test>::new_bare(call)
}
}

impl pallet_timestamp::Config for Test {
type Moment = u64;
type OnTimestampSet = ();
Expand Down Expand Up @@ -308,13 +325,13 @@ parameter_types! {


impl CreateSignedTransaction<pallet_ipfs::Call<Test>> for Test {
fn create_transaction<C: frame_system::offchain::AppCrypto<Self::Public, Self::Signature>>(
call: pallet_ipfs::Call<Test>,
_public: Self::Public,
_account: <Test as frame_system::Config>::AccountId,
nonce: <Test as frame_system::Config>::Nonce,
) -> Option<(pallet_ipfs::Call<Test>, (u64, (u64, ())))> {
Some((call, (nonce, (nonce, ()))))
fn create_signed_transaction<C: AppCrypto<Self::Public, Self::Signature>>(
call: <Self as frame_system::offchain::CreateTransactionBase<pallet_ipfs::Call<Test>>>::RuntimeCall,
_public: <Self as SigningTypes>::Public,
account: <Self as frame_system::Config>::AccountId,
nonce: <Self as frame_system::Config>::Nonce,
) -> Option<<Self as frame_system::offchain::CreateTransactionBase<pallet_ipfs::Call<Test>>>::Extrinsic> {
Some(UncheckedExtrinsic::new_signed(call, account.into(), (), ()))
}
}

Expand All @@ -324,16 +341,18 @@ impl onchain::Config for OnChainSeqPhragmen {
type Solver = SequentialPhragmen<AccountId, Perbill>;
type DataProvider = Staking;
type WeightInfo = ();
type MaxWinners = ConstU32<100>;
type Bounds = ElectionsBounds;
type Sort = sp_core::ConstBool<true>;
type MaxBackersPerWinner = ConstU32<{ u32::MAX }>;
type MaxWinnersPerPage = ConstU32<{ u32::MAX }>;
}

impl pallet_staking::Config for Test {
type NominationsQuota = pallet_staking::FixedNominationsQuota<16>;
type OldCurrency = Balances;
type Currency = Balances;
type CurrencyBalance = Balance;
type UnixTime = Timestamp;
type OffendingValidatorsThreshold = OffendingValidatorsThreshold;
type CurrencyToVote = SaturatingCurrencyToVote;
type ElectionProvider = onchain::OnChainExecution<OnChainSeqPhragmen>;
type GenesisElectionProvider = Self::ElectionProvider;
Expand All @@ -357,6 +376,9 @@ impl pallet_staking::Config for Test {
type EventListeners = ();
type BenchmarkingConfig = TestBenchmarkingConfig;
type WeightInfo = ();
type RuntimeHoldReason = RuntimeHoldReason;
type MaxValidatorSet = ConstU32<1000>;
type Filter = frame_support::traits::Nothing;
}

impl pallet_balances::Config for Test {
Expand All @@ -371,16 +393,17 @@ impl pallet_balances::Config for Test {
type WeightInfo = ();
type FreezeIdentifier = ();
type MaxFreezes = ();
type RuntimeHoldReason = ();
type RuntimeHoldReason = RuntimeHoldReason;
type RuntimeFreezeReason = ();
type DoneSlashHandler = ();
}

pub fn new_test_ext() -> sp_io::TestExternalities {
let mut t = frame_system::GenesisConfig::<Test>::default()
.build_storage()
.unwrap();

pallet_balances::GenesisConfig::<Test> { balances: vec![] }
pallet_balances::GenesisConfig::<Test> { balances: vec![], dev_accounts: None }
.assimilate_storage(&mut t)
.unwrap();

Expand Down
Loading