use crate as pallet_hookpoints;
use frame_support::{
parameter_types,
traits::{ConstBool, ConstU128, ConstU32, ConstU64},
};
use frame_system as system;
use sp_core::H256;
use sp_runtime::{
traits::{BlakeTwo256, IdentityLookup},
AccountId32, BuildStorage,
};
type Block = frame_system::mocking::MockBlock<Test>;
pub(crate) type Balance = u128;
pub type Nonce = u32;
pub type AccountId = AccountId32;
parameter_types! {
pub const ExistentialDeposit: Balance = 1;
}
frame_support::construct_runtime!(
pub struct Test {
System: frame_system,
Timestamp: pallet_timestamp,
Balances: pallet_balances,
Contracts: pallet_contracts,
HookPoints: pallet_hookpoints,
}
);
impl system::Config for Test {
type BaseCallFilter = frame_support::traits::Everything;
type Block = Block;
type BlockWeights = ();
type BlockLength = ();
type RuntimeCall = RuntimeCall;
type Lookup = IdentityLookup<Self::AccountId>;
type Nonce = Nonce;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = AccountId;
type RuntimeEvent = RuntimeEvent;
type RuntimeOrigin = RuntimeOrigin;
type BlockHashCount = ConstU64<250>;
type DbWeight = ();
type Version = ();
type PalletInfo = PalletInfo;
type AccountData = pallet_balances::AccountData<Balance>;
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
type MaxConsumers = ConstU32<2>;
}
impl pallet_timestamp::Config for Test {
type Moment = u64;
type OnTimestampSet = ();
type MinimumPeriod = ConstU64<0>;
type WeightInfo = ();
}
impl pallet_balances::Config for Test {
type MaxLocks = ConstU32<50>;
type MaxReserves = ();
type ReserveIdentifier = [u8; 8];
type Balance = Balance;
type RuntimeEvent = RuntimeEvent;
type DustRemoval = ();
type ExistentialDeposit = ConstU128<1>;
type AccountStore = System;
type WeightInfo = ();
type FreezeIdentifier = ();
type MaxFreezes = ();
type RuntimeHoldReason = ();
type MaxHolds = ();
}
fn schedule<T: pallet_contracts::Config>() -> pallet_contracts::Schedule<T> {
pallet_contracts::Schedule {
limits: pallet_contracts::Limits {
runtime_memory: 1024 * 1024 * 1024,
..Default::default()
},
..Default::default()
}
}
parameter_types! {
pub const DepositPerItem: Balance = 0;
pub const DepositPerByte: Balance = 0;
pub Schedule: pallet_contracts::Schedule<Test> = schedule::<Test>();
pub const DefaultDepositLimit: Balance = 0;
}
pub struct FakeRandom;
impl<Output, BlockNumber> frame_support::traits::Randomness<Output, BlockNumber> for FakeRandom {
fn random(_: &[u8]) -> (Output, BlockNumber) {
panic!("Pallet contracts promised not to call me");
}
fn random_seed() -> (Output, BlockNumber) {
panic!("Pallet contracts promised not to call me");
}
}
impl pallet_contracts::Config for Test {
type Time = Timestamp;
type Randomness = FakeRandom;
type Currency = Balances;
type RuntimeEvent = RuntimeEvent;
type RuntimeCall = RuntimeCall;
type CallFilter = frame_support::traits::Nothing;
type DepositPerItem = DepositPerItem;
type DepositPerByte = DepositPerByte;
type CallStack = [pallet_contracts::Frame<Self>; 31];
type WeightPrice = ();
type WeightInfo = pallet_contracts::weights::SubstrateWeight<Self>;
type ChainExtension = ();
type Schedule = Schedule;
type AddressGenerator = pallet_contracts::DefaultAddressGenerator;
type MaxCodeLen = ConstU32<{ 128 * 1024 }>;
type DefaultDepositLimit = DefaultDepositLimit;
type MaxStorageKeyLen = ConstU32<128>;
type MaxDebugBufferLen = ConstU32<{ 2 * 1024 * 1024 }>;
type UnsafeUnstableInterface = ConstBool<false>;
type Migrations = ();
}
impl pallet_hookpoints::Config for Test {
type RuntimeEvent = RuntimeEvent;
type MaxLengthId = ConstU32<64>;
type WeightInfo = ();
}
pub const ALICE: AccountId32 = AccountId32::new([1u8; 32]);
pub const BOB: AccountId32 = AccountId32::new([2u8; 32]);
pub const CONTRACT: AccountId32 = AccountId32::new([3u8; 32]);
pub const CALLBACK_NAME: &str = "test_callback";
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![(ALICE, 1_000_000_000_000), (BOB, 1_000_000_000_000)],
}
.assimilate_storage(&mut t)
.unwrap();
let mut ext = sp_io::TestExternalities::new(t);
ext.execute_with(|| System::set_block_number(1));
ext
}