From 504710499acc8d64e6aed2d98cb48b912c3e6a87 Mon Sep 17 00:00:00 2001 From: Mateusz Nowakowski Date: Tue, 26 Sep 2023 11:01:12 +0200 Subject: [PATCH] valuate MGX rewards properly --- pallets/proof-of-stake/src/lib.rs | 9 ++++++--- pallets/proof-of-stake/src/tests.rs | 29 +++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/pallets/proof-of-stake/src/lib.rs b/pallets/proof-of-stake/src/lib.rs index d188f86523..b75a5a5800 100644 --- a/pallets/proof-of-stake/src/lib.rs +++ b/pallets/proof-of-stake/src/lib.rs @@ -188,7 +188,7 @@ pub mod pallet { impl PoSBenchmarkingConfig for T {} #[cfg(not(feature = "runtime-benchmarks"))] - pub trait ValutationApiTrait: + pub trait ValutationApiTrait: Valuate { } @@ -521,7 +521,9 @@ pub mod pallet { ensure!( ::ValuationApi::valuate_liquidity_token(liquidity_token_id, amount) >= - T::MinRewardsPerSession::get(), + T::MinRewardsPerSession::get() || + ((token_id == Into::::into(Self::native_token_id())) && + amount_per_session >= T::MinRewardsPerSession::get()), Error::::TooLittleRewardsPerSession ); @@ -1305,5 +1307,6 @@ impl LiquidityMiningApi for Pallet { } } -// TODO: valuate rewards in MGX // TODO: dedicated ensures for every activation kind +// TODO: clean up test setup +// TODO: test schedule rewards without liquidity mining rewards diff --git a/pallets/proof-of-stake/src/tests.rs b/pallets/proof-of-stake/src/tests.rs index 8fcd8aec11..0de86ee514 100644 --- a/pallets/proof-of-stake/src/tests.rs +++ b/pallets/proof-of-stake/src/tests.rs @@ -1387,6 +1387,35 @@ fn reject_schedule_with_too_little_rewards_per_session() { }); } +#[test] +#[serial] +fn accept_schedule_valuated_in_native_token() { + new_test_ext().execute_with(|| { + System::set_block_number(1); + let get_liquidity_asset_mock = MockValuationApi::get_liquidity_asset_context(); + get_liquidity_asset_mock.expect().return_const(Ok(10u32)); + let valuate_liquidity_token_mock = MockValuationApi::valuate_liquidity_token_context(); + valuate_liquidity_token_mock.expect().return_const(1u128); + + let token_id = TokensOf::::create(&ALICE, MILLION).unwrap(); + TokensOf::::mint(ProofOfStake::native_token_id(), &ALICE, 10).unwrap(); + let pair: (TokenId, TokenId) = (0u32.into(), 4u32.into()); + + roll_to_session(4); + + assert_ok!( + ProofOfStake::reward_pool( + RuntimeOrigin::signed(ALICE), + pair, + ProofOfStake::native_token_id(), + 10, + 5u32.into() + ), + // Error::::TooLittleRewardsPerSession + ); + }); +} + #[test] #[serial] fn user_can_claim_3rdparty_rewards() {