Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
polkadot-sdk
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
parity
Mirrored projects
polkadot-sdk
Commits
aef1b4b8
Unverified
Commit
aef1b4b8
authored
11 months ago
by
Liam Aharon
Browse files
Options
Downloads
Patches
Plain Diff
add deposit extrinsic tests
parent
3b47813d
Branches
Branches containing commit
No related merge requests found
Pipeline
#461789
failed with stages
in 4 minutes and 7 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
substrate/frame/asset-rewards/src/tests.rs
+57
-1
57 additions, 1 deletion
substrate/frame/asset-rewards/src/tests.rs
with
57 additions
and
1 deletion
substrate/frame/asset-rewards/src/tests.rs
+
57
−
1
View file @
aef1b4b8
...
...
@@ -17,7 +17,7 @@
use
crate
::{
mock
::
*
,
*
};
use
frame_support
::{
assert_err
,
assert_ok
,
hypothetically
,
traits
::
fungible
::
NativeOrWithId
};
use
sp_runtime
::
traits
::
BadOrigin
;
use
sp_runtime
::
{
traits
::
BadOrigin
,
ArithmeticError
}
;
/// Creates a basic pool with values:
/// - Staking asset: 1
...
...
@@ -865,6 +865,62 @@ mod set_pool_reward_rate_per_block {
}
}
mod
deposit_reward_tokens
{
use
super
::
*
;
#[test]
fn
success
()
{
new_test_ext
()
.execute_with
(||
{
let
depositor
=
1
;
let
pool_id
=
0
;
let
amount
=
1000
;
let
reward_asset_id
=
NativeOrWithId
::
<
u32
>
::
Native
;
create_default_pool
();
let
pool_account_id
=
StakingRewards
::
pool_account_id
(
&
pool_id
)
.unwrap
();
let
depositor_balance_before
=
<<
MockRuntime
as
Config
>
::
Assets
>
::
balance
(
reward_asset_id
.clone
(),
&
depositor
);
let
pool_balance_before
=
<<
MockRuntime
as
Config
>
::
Assets
>
::
balance
(
reward_asset_id
.clone
(),
&
pool_account_id
,
);
assert_ok!
(
StakingRewards
::
deposit_reward_tokens
(
RuntimeOrigin
::
signed
(
depositor
),
pool_id
,
amount
));
let
depositor_balance_after
=
<<
MockRuntime
as
Config
>
::
Assets
>
::
balance
(
reward_asset_id
.clone
(),
&
depositor
);
let
pool_balance_after
=
<<
MockRuntime
as
Config
>
::
Assets
>
::
balance
(
reward_asset_id
,
&
pool_account_id
);
assert_eq!
(
pool_balance_after
-
pool_balance_before
,
amount
);
assert_eq!
(
depositor_balance_before
-
depositor_balance_after
,
amount
);
});
}
#[test]
fn
fails_for_non_existent_pool
()
{
new_test_ext
()
.execute_with
(||
{
assert_err!
(
StakingRewards
::
deposit_reward_tokens
(
RuntimeOrigin
::
signed
(
1
),
999
,
100
),
Error
::
<
MockRuntime
>
::
NonExistentPool
);
});
}
#[test]
fn
fails_for_insufficient_balance
()
{
new_test_ext
()
.execute_with
(||
{
create_default_pool
();
assert_err!
(
StakingRewards
::
deposit_reward_tokens
(
RuntimeOrigin
::
signed
(
1
),
0
,
100_000_000
),
ArithmeticError
::
Underflow
);
});
}
}
/// This integration test
/// 1. Considers 2 stakers each staking and unstaking at different intervals, asserts their
/// claimable rewards are adjusted as expected, and that harvesting works.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment