Skip to content
Merged
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
15 changes: 15 additions & 0 deletions pallets/alias-accounts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,21 @@ pub mod pallet {
}
}

// ========== View Functions ==========

#[pallet::view_functions]
impl<T: Config> Pallet<T> {
/// Returns the current value of [`Config::AliasFee`].
pub fn get_alias_fee() -> Option<BalanceOf<T>> {
T::AliasFee::get()
}

/// Returns the current value of [`Config::OffchainWorkerInterval`].
pub fn get_offchain_worker_interval() -> BlockNumberFor<T> {
T::OffchainWorkerInterval::get()
}
}

// ========== Extra Constants ==========

#[pallet::extra_constants]
Expand Down
19 changes: 19 additions & 0 deletions pallets/alias-accounts/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1676,3 +1676,22 @@ mod integrity {
});
}
}

// ========== View function tests ==========

mod view_functions {
use super::*;

#[test]
fn parameter_view_functions_follow_their_parameters() {
new_test_ext().execute_with(|| {
assert_eq!(crate::Pallet::<Test>::get_alias_fee(), None);

AliasFee::set(&Some(7));
OffchainWorkerInterval::set(&9);

assert_eq!(crate::Pallet::<Test>::get_alias_fee(), Some(7));
assert_eq!(crate::Pallet::<Test>::get_offchain_worker_interval(), 9);
});
}
}
8 changes: 8 additions & 0 deletions pallets/people-airdrops/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,14 @@ pub mod pallet {
}
}

#[pallet::view_functions]
impl<T: Config> Pallet<T> {
/// Returns the current value of [`Config::PrizeSource`].
pub fn get_prize_source() -> T::AccountId {
T::PrizeSource::get()
}
}

impl<T: Config> Pallet<T> {
/// The personhood product name every draw is scheduled under.
pub fn product_name() -> ProductName {
Expand Down
7 changes: 7 additions & 0 deletions pallets/people-airdrops/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,13 @@ fn offchain_worker_cleans_up_stale_salts() {
});
}

#[test]
fn prize_source_view_function_returns_the_configured_account() {
new_test_ext().execute_with(|| {
assert_eq!(crate::Pallet::<Test>::get_prize_source(), 7);
});
}

#[test]
fn slot_depends_on_event_salt_and_alias() {
let event_a = [1u8; 32];
Expand Down
28 changes: 28 additions & 0 deletions pallets/people-lite/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,34 @@ pub mod pallet {
}
}

#[pallet::view_functions]
impl<T: Config> Pallet<T> {
/// Returns the current value of [`Config::RegistrationFee`].
pub fn get_registration_fee() -> BalanceOf<T> {
T::RegistrationFee::get()
}

/// Returns the current value of [`Config::MaxLitePeople`].
pub fn get_max_lite_people() -> u32 {
T::MaxLitePeople::get()
}

/// Returns the current value of [`Config::PaidRegistrationThreshold`].
pub fn get_paid_registration_threshold() -> u32 {
T::PaidRegistrationThreshold::get()
}

/// Returns the current value of [`Config::PaidRegistrationPeriod`].
pub fn get_paid_registration_period() -> u32 {
T::PaidRegistrationPeriod::get()
}

/// Returns the current value of [`Config::PaidRegistrationsPerPeriod`].
pub fn get_paid_registrations_per_period() -> u32 {
T::PaidRegistrationsPerPeriod::get()
}
}

impl<T: Config> Pallet<T> {
/// Returns the bytes an account signs for `msg`: the personhood signing context followed by
/// `msg`.
Expand Down
25 changes: 25 additions & 0 deletions pallets/people-lite/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2081,3 +2081,28 @@ mod lite_people_cap {
});
}
}

mod view_functions {
use super::*;
use crate::mock::{
MaxLitePeople, PaidRegistrationPeriod, PaidRegistrationThreshold,
PaidRegistrationsPerPeriod,
};

#[test]
fn parameter_view_functions_follow_their_parameters() {
new_test_ext().execute_with(|| {
LitePersonRegistrationFee::set(&11);
MaxLitePeople::set(&12);
PaidRegistrationThreshold::set(&13);
PaidRegistrationPeriod::set(&14);
PaidRegistrationsPerPeriod::set(&15);

assert_eq!(PeopleLitePallet::<Test>::get_registration_fee(), 11);
assert_eq!(PeopleLitePallet::<Test>::get_max_lite_people(), 12);
assert_eq!(PeopleLitePallet::<Test>::get_paid_registration_threshold(), 13);
assert_eq!(PeopleLitePallet::<Test>::get_paid_registration_period(), 14);
assert_eq!(PeopleLitePallet::<Test>::get_paid_registrations_per_period(), 15);
});
}
}
32 changes: 32 additions & 0 deletions pallets/resources/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1277,11 +1277,43 @@ pub mod pallet {
T::LiteNotificationSlotsPerPeriod::get()
}

/// Returns the current value of [`Config::AccountsApiAllowance`].
pub fn get_accounts_api_allowance() -> StatementAllowance {
T::AccountsApiAllowance::get()
}

/// Returns the current value of [`Config::NotificationAllowance`].
pub fn get_notification_allowance() -> StatementAllowance {
T::NotificationAllowance::get()
}

/// Returns the current value of [`Config::LitePersonStatementLimit`].
pub fn get_lite_person_statement_limit() -> StatementAllowance {
T::LitePersonStatementLimit::get()
}

/// Returns the current value of [`Config::PersonStatementLimit`].
///
/// The value is the whole limit of a person. It includes the lite person limit.
pub fn get_person_statement_limit() -> StatementAllowance {
T::PersonStatementLimit::get()
}

/// Returns the current value of [`Config::LongTermStorageClaimsPerPeriod`].
pub fn get_long_term_storage_claims_per_period() -> u8 {
T::LongTermStorageClaimsPerPeriod::get()
}

/// Returns the current value of [`Config::LongTermStorageAllowanceForPeople`].
pub fn get_long_term_storage_allowance_for_people() -> LongTermStorageAllocation {
T::LongTermStorageAllowanceForPeople::get()
}

/// Returns the current value of [`Config::LongTermStorageAllowanceForLitePeople`].
pub fn get_long_term_storage_allowance_for_lite_people() -> LongTermStorageAllocation {
T::LongTermStorageAllowanceForLitePeople::get()
}

/// Returns the current value of [`Config::LongTermStorageCleanupLimit`].
pub fn get_long_term_storage_cleanup_limit() -> u32 {
T::LongTermStorageCleanupLimit::get()
Expand Down
35 changes: 35 additions & 0 deletions pallets/resources/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5409,6 +5409,41 @@ mod dynamic_parameters {
);
});
}

#[test]
fn allowance_view_functions_follow_their_parameters() {
new_test_ext().execute_with(|| {
let accounts_api = StatementAllowance { max_size: 2048, max_count: 3 };
let notification = StatementAllowance { max_size: 256, max_count: 5 };
AccountsApiAllowance::set(&accounts_api);
NotificationAllowance::set(&notification);

assert_eq!(Resources::get_accounts_api_allowance(), accounts_api);
assert_eq!(Resources::get_notification_allowance(), notification);
});
}

#[test]
fn statement_limit_and_long_term_storage_view_functions_return_their_parameters() {
new_test_ext().execute_with(|| {
assert_eq!(
Resources::get_lite_person_statement_limit(),
StatementAllowance { max_size: 4 * 1024, max_count: 10 }
);
assert_eq!(
Resources::get_person_statement_limit(),
StatementAllowance { max_size: 16 * 1024, max_count: 50 }
);
assert_eq!(
Resources::get_long_term_storage_allowance_for_people(),
LongTermStorageAllocation { transactions: 32, bytes: 64 * 1024 * 1024 }
);
assert_eq!(
Resources::get_long_term_storage_allowance_for_lite_people(),
LongTermStorageAllocation { transactions: 8, bytes: 2 * 1024 * 1024 }
);
});
}
}

/// Verify that the default mock configuration passes all integrity checks,
Expand Down
60 changes: 60 additions & 0 deletions runtimes/next-asset-hub-paseo/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2620,3 +2620,63 @@ mod credit_tree_removal {
});
}
}

/// The alias-accounts view functions return the values that governance sets through
/// `pallet_parameters`.
mod alias_accounts_view_functions {
use super::*;
use frame_support::view_functions::ViewFunction;
use indiv_pallet_alias_accounts::{
GetAliasFeeViewFunction, GetOffchainWorkerIntervalViewFunction,
};
use next_asset_hub_paseo_runtime::{
dynamic_params::alias_accounts::{AliasFee, Parameters, StaleAliasSweepInterval},
RuntimeParameters,
};
use parachains_common::BlockNumber;

fn set_parameter(parameter: Parameters) {
assert_ok!(pallet_parameters::Pallet::<Runtime>::set_parameter(
RuntimeOrigin::root(),
RuntimeParameters::AliasAccounts(parameter)
));
}

/// Runs a view function without arguments through the runtime dispatch that clients call.
fn execute_view_function<Query: ViewFunction>() -> Query::ReturnType
where
Query::ReturnType: Decode,
{
let output = Runtime::execute_view_function(Query::id(), Vec::new())
.expect("the runtime dispatches the view function");
Decode::decode(&mut &output[..]).expect("the output decodes as the return type")
}

#[test]
fn alias_fee_view_function_returns_the_updated_parameter() {
sp_io::TestExternalities::default().execute_with(|| {
assert_eq!(execute_view_function::<GetAliasFeeViewFunction<Runtime>>(), None);

set_parameter(Parameters::AliasFee(AliasFee, Some(Some(7))));

assert_eq!(execute_view_function::<GetAliasFeeViewFunction<Runtime>>(), Some(7));
});
}

#[test]
fn offchain_worker_interval_view_function_returns_the_interval_that_the_sweep_uses() {
sp_io::TestExternalities::default().execute_with(|| {
let interval = |blocks: BlockNumber| {
set_parameter(Parameters::StaleAliasSweepInterval(
StaleAliasSweepInterval,
Some(blocks),
));
execute_view_function::<GetOffchainWorkerIntervalViewFunction<Runtime>>()
};

assert_eq!(interval(9), 9);
// The runtime keeps the interval non-zero whatever governance stores.
assert_eq!(interval(0), 1);
});
}
}
Loading
Loading