|
| 1 | +use super::*; |
| 2 | +use bridge_types::GenericNetworkId; |
| 3 | +use codec::{Decode, Encode, MaxEncodedLen}; |
| 4 | +use currencies::BasicCurrencyAdapter; |
| 5 | + |
| 6 | +use bridge_types::traits::TimepointProvider; |
| 7 | +use frame_support::traits::{Everything, GenesisBuild}; |
| 8 | +use frame_support::{parameter_types, Deserialize, Serialize}; |
| 9 | +use scale_info::TypeInfo; |
| 10 | +use sp_core::H256; |
| 11 | +use sp_keyring::AccountKeyring as Keyring; |
| 12 | +use sp_runtime::testing::Header; |
| 13 | +use sp_runtime::traits::{BlakeTwo256, IdentifyAccount, IdentityLookup, Verify}; |
| 14 | +use sp_runtime::{AccountId32, MultiSignature}; |
| 15 | +use sp_std::convert::From; |
| 16 | +use traits::parameter_type_with_key; |
| 17 | + |
| 18 | +use crate::outbound as bridge_outbound_channel; |
| 19 | + |
| 20 | +type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>; |
| 21 | +type Block = frame_system::mocking::MockBlock<Test>; |
| 22 | + |
| 23 | +pub const BASE_NETWORK_ID: SubNetworkId = SubNetworkId::Mainnet; |
| 24 | + |
| 25 | +frame_support::construct_runtime!( |
| 26 | + pub enum Test where |
| 27 | + Block = Block, |
| 28 | + NodeBlock = Block, |
| 29 | + UncheckedExtrinsic = UncheckedExtrinsic, |
| 30 | + { |
| 31 | + System: frame_system::{Pallet, Call, Storage, Event<T>}, |
| 32 | + Timestamp: pallet_timestamp::{Pallet, Call, Storage}, |
| 33 | + Tokens: tokens::{Pallet, Call, Config<T>, Storage, Event<T>}, |
| 34 | + Currencies: currencies::{Pallet, Call, Storage}, |
| 35 | + Balances: pallet_balances::{Pallet, Call, Storage, Event<T>}, |
| 36 | + BridgeOutboundChannel: bridge_outbound_channel::{Pallet, Config<T>, Storage, Event<T>}, |
| 37 | + } |
| 38 | +); |
| 39 | + |
| 40 | +pub type Signature = MultiSignature; |
| 41 | +pub type AccountId = <<Signature as Verify>::Signer as IdentifyAccount>::AccountId; |
| 42 | + |
| 43 | +#[derive( |
| 44 | + Encode, |
| 45 | + Decode, |
| 46 | + PartialEq, |
| 47 | + Eq, |
| 48 | + Debug, |
| 49 | + Clone, |
| 50 | + Copy, |
| 51 | + MaxEncodedLen, |
| 52 | + TypeInfo, |
| 53 | + PartialOrd, |
| 54 | + Ord, |
| 55 | + Serialize, |
| 56 | + Deserialize, |
| 57 | +)] |
| 58 | +pub enum AssetId { |
| 59 | + XOR, |
| 60 | + ETH, |
| 61 | + DAI, |
| 62 | +} |
| 63 | + |
| 64 | +pub type Balance = u128; |
| 65 | +pub type Amount = i128; |
| 66 | + |
| 67 | +parameter_types! { |
| 68 | + pub const BlockHashCount: u64 = 250; |
| 69 | +} |
| 70 | + |
| 71 | +impl frame_system::Config for Test { |
| 72 | + type BaseCallFilter = Everything; |
| 73 | + type BlockWeights = (); |
| 74 | + type BlockLength = (); |
| 75 | + type RuntimeOrigin = RuntimeOrigin; |
| 76 | + type RuntimeCall = RuntimeCall; |
| 77 | + type Index = u64; |
| 78 | + type BlockNumber = u64; |
| 79 | + type Hash = H256; |
| 80 | + type Hashing = BlakeTwo256; |
| 81 | + type AccountId = AccountId; |
| 82 | + type Lookup = IdentityLookup<Self::AccountId>; |
| 83 | + type Header = Header; |
| 84 | + type RuntimeEvent = RuntimeEvent; |
| 85 | + type BlockHashCount = BlockHashCount; |
| 86 | + type DbWeight = (); |
| 87 | + type Version = (); |
| 88 | + type PalletInfo = PalletInfo; |
| 89 | + type AccountData = pallet_balances::AccountData<Balance>; |
| 90 | + type OnNewAccount = (); |
| 91 | + type OnKilledAccount = (); |
| 92 | + type SystemWeightInfo = (); |
| 93 | + type SS58Prefix = (); |
| 94 | + type OnSetCode = (); |
| 95 | + type MaxConsumers = frame_support::traits::ConstU32<65536>; |
| 96 | +} |
| 97 | + |
| 98 | +parameter_types! { |
| 99 | + pub const ExistentialDeposit: u128 = 0; |
| 100 | +} |
| 101 | + |
| 102 | +parameter_type_with_key! { |
| 103 | + pub ExistentialDeposits: |_currency_id: AssetId| -> Balance { |
| 104 | + 0 |
| 105 | + }; |
| 106 | +} |
| 107 | + |
| 108 | +impl pallet_balances::Config for Test { |
| 109 | + type Balance = Balance; |
| 110 | + type RuntimeEvent = RuntimeEvent; |
| 111 | + type DustRemoval = (); |
| 112 | + type ExistentialDeposit = ExistentialDeposit; |
| 113 | + type AccountStore = System; |
| 114 | + type WeightInfo = (); |
| 115 | + type MaxLocks = (); |
| 116 | + type MaxReserves = (); |
| 117 | + type ReserveIdentifier = (); |
| 118 | +} |
| 119 | + |
| 120 | +impl tokens::Config for Test { |
| 121 | + type RuntimeEvent = RuntimeEvent; |
| 122 | + type Balance = Balance; |
| 123 | + type Amount = Amount; |
| 124 | + type CurrencyId = AssetId; |
| 125 | + type WeightInfo = (); |
| 126 | + type ExistentialDeposits = ExistentialDeposits; |
| 127 | + type CurrencyHooks = (); |
| 128 | + type MaxLocks = (); |
| 129 | + type MaxReserves = (); |
| 130 | + type ReserveIdentifier = (); |
| 131 | + type DustRemovalWhitelist = Everything; |
| 132 | +} |
| 133 | + |
| 134 | +impl currencies::Config for Test { |
| 135 | + type MultiCurrency = Tokens; |
| 136 | + type NativeCurrency = BasicCurrencyAdapter<Test, Balances, Amount, u64>; |
| 137 | + type GetNativeCurrencyId = GetBaseAssetId; |
| 138 | + type WeightInfo = (); |
| 139 | +} |
| 140 | +parameter_types! { |
| 141 | + pub const GetBaseAssetId: AssetId = AssetId::XOR; |
| 142 | + pub GetTeamReservesAccountId: AccountId = AccountId32::from([0; 32]); |
| 143 | + pub GetFeeAccountId: AccountId = AccountId32::from([1; 32]); |
| 144 | + pub GetTreasuryAccountId: AccountId = AccountId32::from([2; 32]); |
| 145 | +} |
| 146 | + |
| 147 | +parameter_types! { |
| 148 | + pub const MaxMessagePayloadSize: u32 = 128; |
| 149 | + pub const MaxMessagesPerCommit: u32 = 5; |
| 150 | + pub const ThisNetworkId: GenericNetworkId = GenericNetworkId::Sub(SubNetworkId::Mainnet); |
| 151 | +} |
| 152 | + |
| 153 | +pub struct GenericTimepointProvider; |
| 154 | + |
| 155 | +impl TimepointProvider for GenericTimepointProvider { |
| 156 | + fn get_timepoint() -> bridge_types::GenericTimepoint { |
| 157 | + bridge_types::GenericTimepoint::Sora(System::block_number() as u32) |
| 158 | + } |
| 159 | +} |
| 160 | + |
| 161 | +impl bridge_outbound_channel::Config for Test { |
| 162 | + type RuntimeEvent = RuntimeEvent; |
| 163 | + type MaxMessagePayloadSize = MaxMessagePayloadSize; |
| 164 | + type MaxMessagesPerCommit = MaxMessagesPerCommit; |
| 165 | + type MessageStatusNotifier = (); |
| 166 | + type AuxiliaryDigestHandler = (); |
| 167 | + type AssetId = (); |
| 168 | + type Balance = u128; |
| 169 | + type WeightInfo = (); |
| 170 | + type TimepointProvider = GenericTimepointProvider; |
| 171 | + type ThisNetworkId = ThisNetworkId; |
| 172 | +} |
| 173 | + |
| 174 | +impl pallet_timestamp::Config for Test { |
| 175 | + type Moment = u64; |
| 176 | + type OnTimestampSet = (); |
| 177 | + type MinimumPeriod = (); |
| 178 | + type WeightInfo = (); |
| 179 | +} |
| 180 | + |
| 181 | +pub fn new_tester() -> sp_io::TestExternalities { |
| 182 | + let mut storage = frame_system::GenesisConfig::default() |
| 183 | + .build_storage::<Test>() |
| 184 | + .unwrap(); |
| 185 | + |
| 186 | + let config: bridge_outbound_channel::GenesisConfig<Test> = |
| 187 | + bridge_outbound_channel::GenesisConfig { |
| 188 | + interval: 10u32.into(), |
| 189 | + }; |
| 190 | + config.assimilate_storage(&mut storage).unwrap(); |
| 191 | + |
| 192 | + let bob: AccountId = Keyring::Bob.into(); |
| 193 | + |
| 194 | + pallet_balances::GenesisConfig::<Test> { |
| 195 | + balances: vec![(bob, 1u32.into())], |
| 196 | + } |
| 197 | + .assimilate_storage(&mut storage) |
| 198 | + .unwrap(); |
| 199 | + |
| 200 | + let mut ext: sp_io::TestExternalities = storage.into(); |
| 201 | + |
| 202 | + ext.execute_with(|| System::set_block_number(1)); |
| 203 | + ext |
| 204 | +} |
0 commit comments