Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

init_poo_id should cover all PoolId items #2837

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading