#[cfg(test)]
use super::*;
use pezsp_core::{crypto::AccountId32, H256};
use pezsp_keyring::{Ed25519Keyring, Sr25519Keyring};
use crate::purchase;
use pezframe_support::{
derive_impl, ord_parameter_types, parameter_types,
traits::{Currency, WithdrawReasons},
};
use pezsp_runtime::{
traits::{BlakeTwo256, Identity, IdentityLookup},
BuildStorage,
};
type Block = pezframe_system::mocking::MockBlock<Test>;
pezframe_support::construct_runtime!(
pub enum Test
{
System: pezframe_system,
Balances: pezpallet_balances,
Vesting: pezpallet_vesting,
Purchase: purchase,
}
);
type AccountId = AccountId32;
#[derive_impl(pezframe_system::config_preludes::TestDefaultConfig)]
impl pezframe_system::Config for Test {
type BaseCallFilter = pezframe_support::traits::Everything;
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type Nonce = u64;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = AccountId;
type Lookup = IdentityLookup<AccountId>;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type Version = ();
type PalletInfo = PalletInfo;
type AccountData = pezpallet_balances::AccountData<u64>;
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
type MaxConsumers = pezframe_support::traits::ConstU32<16>;
}
#[derive_impl(pezpallet_balances::config_preludes::TestDefaultConfig)]
impl pezpallet_balances::Config for Test {
type AccountStore = System;
}
parameter_types! {
pub const MinVestedTransfer: u64 = 1;
pub UnvestedFundsAllowedWithdrawReasons: WithdrawReasons =
WithdrawReasons::except(WithdrawReasons::TRANSFER | WithdrawReasons::RESERVE);
}
impl pezpallet_vesting::Config for Test {
type RuntimeEvent = RuntimeEvent;
type Currency = Balances;
type BlockNumberToBalance = Identity;
type MinVestedTransfer = MinVestedTransfer;
type WeightInfo = ();
type UnvestedFundsAllowedWithdrawReasons = UnvestedFundsAllowedWithdrawReasons;
type BlockNumberProvider = System;
const MAX_VESTING_SCHEDULES: u32 = 28;
}
parameter_types! {
pub const MaxStatementLength: u32 = 1_000;
pub const UnlockedProportion: Permill = Permill::from_percent(10);
pub const MaxUnlocked: u64 = 10;
}
ord_parameter_types! {
pub const ValidityOrigin: AccountId = AccountId32::from([0u8; 32]);
pub const PaymentOrigin: AccountId = AccountId32::from([1u8; 32]);
pub const ConfigurationOrigin: AccountId = AccountId32::from([2u8; 32]);
}
impl Config for Test {
type RuntimeEvent = RuntimeEvent;
type Currency = Balances;
type VestingSchedule = Vesting;
type ValidityOrigin = pezframe_system::EnsureSignedBy<ValidityOrigin, AccountId>;
type ConfigurationOrigin = pezframe_system::EnsureSignedBy<ConfigurationOrigin, AccountId>;
type MaxStatementLength = MaxStatementLength;
type UnlockedProportion = UnlockedProportion;
type MaxUnlocked = MaxUnlocked;
}
pub fn new_test_ext() -> pezsp_io::TestExternalities {
let t = pezframe_system::GenesisConfig::<Test>::default().build_storage().unwrap();
let mut ext = pezsp_io::TestExternalities::new(t);
ext.execute_with(|| setup());
ext
}
pub fn setup() {
let statement = b"Hello, World".to_vec();
let unlock_block = 100;
Purchase::set_statement(RuntimeOrigin::signed(configuration_origin()), statement).unwrap();
Purchase::set_unlock_block(RuntimeOrigin::signed(configuration_origin()), unlock_block)
.unwrap();
Purchase::set_payment_account(RuntimeOrigin::signed(configuration_origin()), payment_account())
.unwrap();
Balances::make_free_balance_be(&payment_account(), 100_000);
}
pub fn alice() -> AccountId {
Sr25519Keyring::Alice.to_account_id()
}
pub fn alice_ed25519() -> AccountId {
Ed25519Keyring::Alice.to_account_id()
}
pub fn bob() -> AccountId {
Sr25519Keyring::Bob.to_account_id()
}
pub fn alice_signature() -> [u8; 64] {
hex_literal::hex!("20e0faffdf4dfe939f2faa560f73b1d01cde8472e2b690b7b40606a374244c3a2e9eb9c8107c10b605138374003af8819bd4387d7c24a66ee9253c2e688ab881")
}
pub fn bob_signature() -> [u8; 64] {
hex_literal::hex!("d6d460187ecf530f3ec2d6e3ac91b9d083c8fbd8f1112d92a82e4d84df552d18d338e6da8944eba6e84afaacf8a9850f54e7b53a84530d649be2e0119c7ce889")
}
pub fn alice_signature_ed25519() -> [u8; 64] {
hex_literal::hex!("ee3f5a6cbfc12a8f00c18b811dc921b550ddf272354cda4b9a57b1d06213fcd8509f5af18425d39a279d13622f14806c3e978e2163981f2ec1c06e9628460b0e")
}
pub fn validity_origin() -> AccountId {
ValidityOrigin::get()
}
pub fn configuration_origin() -> AccountId {
ConfigurationOrigin::get()
}
pub fn payment_account() -> AccountId {
[42u8; 32].into()
}