Skip to content

Commit

Permalink
add to tests
Browse files Browse the repository at this point in the history
Signed-off-by: Charles Ferrell <charlie@manta.network>
  • Loading branch information
ferrell-code committed Nov 17, 2023
1 parent 20e1813 commit b68658e
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 10 deletions.
40 changes: 32 additions & 8 deletions pallets/pallet-lottery/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ use pallet_parachain_staking::{InflationInfo, Range};
use sp_core::H256;

use sp_runtime::{
traits::{BlakeTwo256, Hash, IdentityLookup},
traits::{AccountIdConversion, BlakeTwo256, Hash, IdentityLookup},
Perbill, Percent,
};
use xcm::{
Expand All @@ -59,7 +59,9 @@ pub const ALICE: AccountId = 1;
pub const BOB: AccountId = 2;
pub const TREASURY_ACCOUNT: AccountId = 10;
pub const JUMBO: Balance = 1_000_000_000_000;
pub const JUMBO_ID: CalamariAssetId = 8;
pub const MANTA_ID: CalamariAssetId = 1;
pub const V_MANTA_ID: CalamariAssetId = 8;
pub const JUMBO_ID: CalamariAssetId = 9;

type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
Expand Down Expand Up @@ -485,7 +487,7 @@ parameter_types! {
/// Time in blocks until a collator is done unstaking
pub UnstakeLockTime: BlockNumber = LeaveDelayRounds::get() * DefaultBlocksPerRound::get();
/// JumboShrimp CurrencyId
pub JumboFarmingCurrencyID: CalamariAssetId = JUMBO_ID;
pub JumboFarmingCurrencyID: CalamariAssetId = V_MANTA_ID;
/// Farming PoolId for JUMBO token
pub JumboShrimpPoolId: PoolId = 0;
}
Expand Down Expand Up @@ -641,39 +643,61 @@ impl ExtBuilder {
ext.execute_with(|| System::set_block_number(1));

ext.execute_with(|| {
let v_manta_asset_metadata =
create_asset_metadata("vManta", "vMANTA", 12, 1u128, false, true);
let jumbo_asset_metadata =
create_asset_metadata("Jumbo", "JUMBO", 12, 1u128, false, true);
let v_manta_location = AssetLocation(VersionedMultiLocation::V1(MultiLocation::new(
1,
Junctions::Here,
)));
let native_location = AssetLocation(VersionedMultiLocation::V1(MultiLocation::new(
0,
Junctions::Here,
)));
// registering manta native asset should work.
// register vMANTA and JUMBO asset should work.
AssetManager::register_asset(
RuntimeOrigin::root(),
v_manta_location,
v_manta_asset_metadata,
)
.unwrap();
AssetManager::register_asset(
RuntimeOrigin::root(),
native_location,
jumbo_asset_metadata,
)
.unwrap();

assert_ok!(
<MantaAssetConfig as AssetConfig<Test>>::FungibleLedger::deposit_minting(
V_MANTA_ID,
&TREASURY_ACCOUNT,
1_000 * JUMBO
)
);

assert_ok!(
<MantaAssetConfig as AssetConfig<Test>>::FungibleLedger::deposit_minting(
JUMBO_ID,
&TREASURY_ACCOUNT,
1_000 * JUMBO
)
);

assert_ok!(
<MantaAssetConfig as AssetConfig<Test>>::FungibleLedger::deposit_minting(
JUMBO_ID,
&ALICE,
1_000 * JUMBO
)
);

assert_ok!(
<MantaAssetConfig as AssetConfig<Test>>::FungibleLedger::deposit_minting(
JUMBO_ID,
&BOB,
1_000_000 * JUMBO
V_MANTA_ID,
&ALICE,
1_000 * JUMBO
)
);

Expand All @@ -685,7 +709,7 @@ impl ExtBuilder {
}

fn init_jumbo_farming() {
let tokens_proportion = vec![(JUMBO_ID, Perbill::from_percent(100))];
let tokens_proportion = vec![(V_MANTA_ID, Perbill::from_percent(100))];
let tokens = JUMBO;
let basic_rewards = vec![(JUMBO_ID, JUMBO)];

Expand Down
23 changes: 21 additions & 2 deletions pallets/pallet-lottery/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use crate::{
roll_one_block, roll_to, roll_to_round_begin, roll_to_round_end, AccountId, Balance,
Balances, ExtBuilder, Lottery, ParachainStaking, RuntimeOrigin as Origin, System, Test,
},
Config, Error,
Config, DestroyFarmingToken, Error, MintFarmingToken,
};

use frame_support::{assert_noop, assert_ok, traits::Currency};
Expand Down Expand Up @@ -898,7 +898,6 @@ fn many_deposit_withdrawals_work() {
(*EVE, HIGH_BALANCE),
])
.with_funded_lottery_account(HIGH_BALANCE)
.with_farming()
.build()
.execute_with(|| {
assert!(HIGH_BALANCE > balance);
Expand Down Expand Up @@ -968,6 +967,26 @@ fn reward_collators_for_round(round: u32, collators: &[AccountId]) {
}
}

#[test]
fn enable_farming_works() {
ExtBuilder::default().build().execute_with(|| {
assert!(!MintFarmingToken::<Test>::get());
assert!(!DestroyFarmingToken::<Test>::get());
assert_noop!(
Lottery::set_farming_params(Origin::signed(*BOB), true, true),
sp_runtime::DispatchError::BadOrigin
);

assert_ok!(Lottery::set_farming_params(Origin::root(), true, false));
assert!(MintFarmingToken::<Test>::get());
assert!(!DestroyFarmingToken::<Test>::get());

assert_ok!(Lottery::set_farming_params(Origin::root(), false, true));
assert!(!MintFarmingToken::<Test>::get());
assert!(DestroyFarmingToken::<Test>::get());
});
}

#[test]
fn farming_deposit_withdraw() {
let balance = 500_000_000 * UNIT;
Expand Down

0 comments on commit b68658e

Please sign in to comment.