From 8122fcbdbe215039d7f59be234f6b82b250284e3 Mon Sep 17 00:00:00 2001 From: wangjj9219 <183318287@qq.com> Date: Thu, 12 Dec 2024 17:57:47 +0800 Subject: [PATCH] init_poo_id should cover all PoolId items --- predeploy-contracts | 2 +- runtime/common/src/precompile/incentives.rs | 52 ++++++++++++++++++++- 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/predeploy-contracts b/predeploy-contracts index 2b2a8ba010..38f8576cf6 160000 --- a/predeploy-contracts +++ b/predeploy-contracts @@ -1 +1 @@ -Subproject commit 2b2a8ba010c315b9f3ee4b103cc42bfe0dd067b2 +Subproject commit 38f8576cf624f55c7bc941aaaf64ba9ad3b77ded diff --git a/runtime/common/src/precompile/incentives.rs b/runtime/common/src/precompile/incentives.rs index 2d343c4b20..0057f3fc7d 100644 --- a/runtime/common/src/precompile/incentives.rs +++ b/runtime/common/src/precompile/incentives.rs @@ -300,6 +300,8 @@ fn init_pool_id(pool_id_number: u32, pool_currency_id: CurrencyId) -> Result Ok(PoolId::Loans(pool_currency_id)), 1 => Ok(PoolId::Dex(pool_currency_id)), + 2 => Ok(PoolId::Earning(pool_currency_id)), + 3 => Ok(PoolId::NomineesElection), // Shouldn't happen as solidity compiler should not allow nonexistent enum value _ => Err(PrecompileFailure::Revert { exit_status: ExitRevert::Reverted, @@ -336,10 +338,14 @@ mod tests { assert_ok!(Incentives::update_incentive_rewards( RuntimeOrigin::signed(ALICE), - vec![(PoolId::Loans(DOT), vec![(DOT, 100)])] + vec![ + (PoolId::Loans(DOT), vec![(DOT, 100)]), + (PoolId::Earning(ACA), vec![(ACA, 101)]), + (PoolId::NomineesElection, vec![(ACA, 102)]), + ] )); - // getIncetiveRewardAmount(PoolId,address,address) => 0x7469000d + // getIncentiveRewardAmount(PoolId,address,address) => 0x7469000d // pool // pool_currency_id // reward_currency_id @@ -359,6 +365,48 @@ mod tests { IncentivesPrecompile::execute(&mut MockPrecompileHandle::new(&input, None, &context, false)).unwrap(); assert_eq!(res.exit_status, ExitSucceed::Returned); assert_eq!(res.output, expected_output.to_vec()); + + // getIncentiveRewardAmount(PoolId,address,address) => 0x7469000d + // pool + // pool_currency_id + // reward_currency_id + let input = hex! {" + 7469000d + 00000000000000000000000000000000 00000000000000000000000000000002 + 000000000000000000000000 0000000000000000000100000000000000000000 + 000000000000000000000000 0000000000000000000100000000000000000000 + "}; + + // value of 101 + let expected_output = hex! {" + 00000000000000000000000000000000 00000000000000000000000000000065 + "}; + + let res = + IncentivesPrecompile::execute(&mut MockPrecompileHandle::new(&input, None, &context, false)).unwrap(); + assert_eq!(res.exit_status, ExitSucceed::Returned); + assert_eq!(res.output, expected_output.to_vec()); + + // getIncentiveRewardAmount(PoolId,address,address) => 0x7469000d + // pool + // pool_currency_id + // reward_currency_id + let input = hex! {" + 7469000d + 00000000000000000000000000000000 00000000000000000000000000000003 + 000000000000000000000000 0000000000000000000100000000000000000003 + 000000000000000000000000 0000000000000000000100000000000000000000 + "}; + + // value of 102 + let expected_output = hex! {" + 00000000000000000000000000000000 00000000000000000000000000000066 + "}; + + let res = + IncentivesPrecompile::execute(&mut MockPrecompileHandle::new(&input, None, &context, false)).unwrap(); + assert_eq!(res.exit_status, ExitSucceed::Returned); + assert_eq!(res.output, expected_output.to_vec()); }); }