Skip to content

Commit

Permalink
init_poo_id should cover all PoolId items
Browse files Browse the repository at this point in the history
  • Loading branch information
wangjj9219 committed Dec 12, 2024
1 parent f91f004 commit 8122fcb
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 3 deletions.
52 changes: 50 additions & 2 deletions runtime/common/src/precompile/incentives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,8 @@ fn init_pool_id(pool_id_number: u32, pool_currency_id: CurrencyId) -> Result<Poo
match pool_id_number {
0 => 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,
Expand Down Expand Up @@ -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
Expand All @@ -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());
});
}

Expand Down

0 comments on commit 8122fcb

Please sign in to comment.