Skip to content
Snippets Groups Projects
Unverified Commit 155fde78 authored by Liam Aharon's avatar Liam Aharon
Browse files

add assets to mock

parent cd65a375
No related merge requests found
Pipeline #461713 failed with stages
in 3 minutes and 2 seconds
......@@ -142,19 +142,26 @@ impl Config for MockRuntime {
pub(crate) fn new_test_ext() -> sp_io::TestExternalities {
let mut t = frame_system::GenesisConfig::<MockRuntime>::default().build_storage().unwrap();
// pallet_assets::GenesisConfig::<MockRuntime, Instance1> {
// // Genesis assets: id, owner, is_sufficient, min_balance
// // pub assets: Vec<(T::AssetId, T::AccountId, bool, T::Balance)>,
// assets: vec![(1, 1, true, 10000)],
// // Genesis metadata: id, name, symbol, decimals
// // pub metadata: Vec<(T::AssetId, Vec<u8>, Vec<u8>, u8)>,
// metadata: vec![(1, b"test".to_vec(), b"TST".to_vec(), 18)],
// // Genesis accounts: id, account_id, balance
// // pub accounts: Vec<(T::AssetId, T::AccountId, T::Balance)>,
// accounts: vec![(1, 1, 10000)],
// }
// .assimilate_storage(&mut t)
// .unwrap();
pallet_assets::GenesisConfig::<MockRuntime, Instance1> {
// Genesis assets: id, owner, is_sufficient, min_balance
// pub assets: Vec<(T::AssetId, T::AccountId, bool, T::Balance)>,
assets: vec![(1, 1, true, 10000)],
// Genesis metadata: id, name, symbol, decimals
// pub metadata: Vec<(T::AssetId, Vec<u8>, Vec<u8>, u8)>,
metadata: vec![(1, b"test".to_vec(), b"TST".to_vec(), 18)],
// Genesis accounts: id, account_id, balance
// pub accounts: Vec<(T::AssetId, T::AccountId, T::Balance)>,
accounts: vec![
(1, 1, 10000),
(1, 2, 20000),
(1, 3, 30000),
(1, 4, 40000),
(1, 10, 40000),
(1, 20, 40000),
],
}
.assimilate_storage(&mut t)
.unwrap();
pallet_balances::GenesisConfig::<MockRuntime> {
balances: vec![(1, 10000), (2, 20000), (3, 30000), (4, 40000), (10, 40000), (20, 40000)],
......
......@@ -29,7 +29,6 @@ use sp_runtime::traits::BadOrigin;
/// Useful for tests when you don't care about customising, or reusing the pool params.
fn create_default_pool() {
let staking_asset_id = NativeOrWithId::<u32>::WithId(1);
create_tokens(1, vec![staking_asset_id.clone()]);
assert_ok!(StakingRewards::create_pool(
RuntimeOrigin::signed(1),
Box::new(staking_asset_id),
......@@ -40,17 +39,6 @@ fn create_default_pool() {
));
}
fn create_tokens(owner: u128, tokens: Vec<NativeOrWithId<u32>>) {
let ed = 1;
for token_id in tokens {
let asset_id = match token_id {
NativeOrWithId::WithId(id) => id,
_ => unreachable!("invalid token"),
};
assert_ok!(Assets::force_create(RuntimeOrigin::root(), asset_id, owner, false, ed));
}
}
fn events() -> Vec<Event<MockRuntime>> {
let result = System::events()
.into_iter()
......@@ -85,8 +73,6 @@ mod create_pool {
let reward_rate_per_block = 100;
let expiry_block = 200u64;
create_tokens(user, vec![reward_asset_id.clone()]);
assert_eq!(NextPoolId::<MockRuntime>::get(), 0);
assert_ok!(StakingRewards::create_pool(
RuntimeOrigin::signed(user),
......@@ -243,7 +229,6 @@ mod create_pool {
let reward_asset_id = NativeOrWithId::<u32>::WithId(1);
let reward_rate_per_block = 100;
let expiry_block = 100u64;
create_tokens(user, vec![reward_asset_id.clone()]);
assert_err!(
StakingRewards::create_pool(
RuntimeOrigin::signed(user),
......@@ -266,7 +251,6 @@ mod create_pool {
let reward_asset_id = NativeOrWithId::<u32>::WithId(1);
let reward_rate_per_block = 100;
let expiry_block = 100u64;
create_tokens(user, vec![reward_asset_id.clone()]);
System::set_block_number(expiry_block + 1u64);
assert_err!(
StakingRewards::create_pool(
......@@ -326,6 +310,9 @@ mod stake {
assert_eq!(Pools::<MockRuntime>::get(pool_id).unwrap().total_tokens_staked, 1500);
// TODO: Check user's frozen balance is updated
// Event is emitted.
assert_eq!(events(), []);
});
}
......@@ -334,12 +321,9 @@ mod stake {
new_test_ext().execute_with(|| {
let user = 1;
let staking_asset_id = NativeOrWithId::<u32>::WithId(1);
create_tokens(user, vec![staking_asset_id.clone()]);
let non_existent_pool_id = 999;
assert_err!(
StakingRewards::stake(RuntimeOrigin::signed(user), non_existent_pool_id, 1000),
StakingRewards::stake(RuntimeOrigin::signed(user), 999, 1000),
Error::<MockRuntime>::NonExistentPool
);
});
......@@ -616,7 +600,6 @@ fn integration() {
let reward_asset_id = NativeOrWithId::<u32>::Native;
let reward_rate_per_block = 100;
let expiry_block = 25u64.into();
create_tokens(admin, vec![staking_asset_id.clone()]);
assert_ok!(StakingRewards::create_pool(
RuntimeOrigin::signed(admin),
Box::new(staking_asset_id.clone()),
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment