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
d1bf78f6
Unverified
Commit
d1bf78f6
authored
1 year ago
by
Liam Aharon
Browse files
Options
Downloads
Patches
Plain Diff
add check for asset existence
parent
b0cd8318
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
substrate/frame/staking-rewards/src/lib.rs
+12
-0
12 additions, 0 deletions
substrate/frame/staking-rewards/src/lib.rs
substrate/frame/staking-rewards/src/tests.rs
+42
-1
42 additions, 1 deletion
substrate/frame/staking-rewards/src/tests.rs
with
54 additions
and
1 deletion
substrate/frame/staking-rewards/src/lib.rs
+
12
−
0
View file @
d1bf78f6
...
...
@@ -230,6 +230,8 @@ pub mod pallet {
pub
enum
Error
<
T
>
{
/// An operation was attempted on a non-existent pool.
NonExistentPool
,
/// An operation was attempted using a non-existent asset.
NonExistentAsset
,
}
#[pallet::hooks]
...
...
@@ -256,6 +258,16 @@ pub mod pallet {
// Ensure Origin is allowed to create pools.
T
::
PermissionedPoolCreator
::
ensure_origin
(
origin
.clone
())
?
;
// Ensure the assets exist.
ensure!
(
T
::
Assets
::
asset_exists
(
*
staked_asset_id
.clone
()),
Error
::
<
T
>
::
NonExistentAsset
);
ensure!
(
T
::
Assets
::
asset_exists
(
*
reward_asset_id
.clone
()),
Error
::
<
T
>
::
NonExistentAsset
);
// Get the admin, or try to use the origin as admin.
let
origin_acc_id
=
ensure_signed
(
origin
)
?
;
let
admin
=
match
admin
{
...
...
This diff is collapsed.
Click to expand it.
substrate/frame/staking-rewards/src/tests.rs
+
42
−
1
View file @
d1bf78f6
...
...
@@ -16,7 +16,7 @@
// limitations under the License.
use
crate
::{
mock
::
*
,
*
};
use
frame_support
::{
assert_ok
,
traits
::
fungible
::
NativeOrWithId
};
use
frame_support
::{
assert_err
,
assert_ok
,
traits
::
fungible
::
NativeOrWithId
};
fn
create_tokens
(
owner
:
u128
,
tokens
:
Vec
<
NativeOrWithId
<
u32
>>
)
{
create_tokens_with_ed
(
owner
,
tokens
,
1
)
...
...
@@ -163,3 +163,44 @@ fn create_pool_works() {
);
});
}
#[test]
fn
create_pool_with_non_existent_asset_fails
()
{
new_test_ext
()
.execute_with
(||
{
let
valid_asset
=
NativeOrWithId
::
<
u32
>
::
WithId
(
1
);
let
invalid_asset
=
NativeOrWithId
::
<
u32
>
::
WithId
(
200
);
assert_err!
(
StakingRewards
::
create_pool
(
RuntimeOrigin
::
signed
(
1
),
Box
::
new
(
valid_asset
.clone
()),
Box
::
new
(
invalid_asset
.clone
()),
10
,
None
),
Error
::
<
MockRuntime
>
::
NonExistentAsset
);
assert_err!
(
StakingRewards
::
create_pool
(
RuntimeOrigin
::
signed
(
1
),
Box
::
new
(
invalid_asset
.clone
()),
Box
::
new
(
valid_asset
.clone
()),
10
,
None
),
Error
::
<
MockRuntime
>
::
NonExistentAsset
);
assert_err!
(
StakingRewards
::
create_pool
(
RuntimeOrigin
::
signed
(
1
),
Box
::
new
(
invalid_asset
.clone
()),
Box
::
new
(
invalid_asset
.clone
()),
10
,
None
),
Error
::
<
MockRuntime
>
::
NonExistentAsset
);
})
}
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