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
ca0fb0d9
Unverified
Commit
ca0fb0d9
authored
10 months ago
by
Bastian Köcher
Committed by
GitHub
10 months ago
Browse files
Options
Downloads
Patches
Plain Diff
pallet_balances: Add `try_state` for checking `Holds` and `Freezes` (#4490)
Co-authored-by: command-bot <>
parent
2c48b9dd
Branches
gh-readonly-queue/master/pr-4490-2c48b9ddb0a5de4499d4ed699b79eacc354f016a
Branches containing commit
No related merge requests found
Pipeline
#475726
waiting for manual action with stages
in 7 minutes and 10 seconds
Changes
2
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
substrate/frame/balances/src/lib.rs
+24
-1
24 additions, 1 deletion
substrate/frame/balances/src/lib.rs
substrate/frame/balances/src/tests/general_tests.rs
+32
-0
32 additions, 0 deletions
substrate/frame/balances/src/tests/general_tests.rs
with
56 additions
and
1 deletion
substrate/frame/balances/src/lib.rs
+
24
−
1
View file @
ca0fb0d9
...
...
@@ -542,8 +542,8 @@ pub mod pallet {
#[pallet::hooks]
impl
<
T
:
Config
<
I
>
,
I
:
'static
>
Hooks
<
BlockNumberFor
<
T
>>
for
Pallet
<
T
,
I
>
{
#[cfg(not(feature
=
"insecure_zero_ed"
))]
fn
integrity_test
()
{
#[cfg(not(feature
=
"insecure_zero_ed"
))]
assert!
(
!<
T
as
Config
<
I
>>
::
ExistentialDeposit
::
get
()
.is_zero
(),
"The existential deposit must be greater than zero!"
...
...
@@ -555,6 +555,29 @@ pub mod pallet {
T
::
MaxFreezes
::
get
(),
<
T
::
RuntimeFreezeReason
as
VariantCount
>
::
VARIANT_COUNT
,
);
}
#[cfg(feature
=
"try-runtime"
)]
fn
try_state
(
_n
:
BlockNumberFor
<
T
>
)
->
Result
<
(),
sp_runtime
::
TryRuntimeError
>
{
Holds
::
<
T
,
I
>
::
iter_keys
()
.try_for_each
(|
k
|
{
if
Holds
::
<
T
,
I
>
::
decode_len
(
k
)
.unwrap_or
(
0
)
>
T
::
RuntimeHoldReason
::
VARIANT_COUNT
as
usize
{
Err
(
"Found `Hold` with too many elements"
)
}
else
{
Ok
(())
}
})
?
;
Freezes
::
<
T
,
I
>
::
iter_keys
()
.try_for_each
(|
k
|
{
if
Freezes
::
<
T
,
I
>
::
decode_len
(
k
)
.unwrap_or
(
0
)
>
T
::
MaxFreezes
::
get
()
as
usize
{
Err
(
"Found `Freeze` with too many elements"
)
}
else
{
Ok
(())
}
})
?
;
Ok
(())
}
}
#[pallet::call(weight(
<
T
as
Config
<
I
>>
::WeightInfo))]
...
...
This diff is collapsed.
Click to expand it.
substrate/frame/balances/src/tests/general_tests.rs
+
32
−
0
View file @
ca0fb0d9
...
...
@@ -109,3 +109,35 @@ fn regression_historic_acc_does_not_evaporate_reserve() {
});
});
}
#[cfg(feature
=
"try-runtime"
)]
#[test]
fn
try_state_works
()
{
use
crate
::{
Config
,
Freezes
,
Holds
};
use
frame_support
::{
storage
,
traits
::{
Get
,
Hooks
,
VariantCount
},
};
ExtBuilder
::
default
()
.build_and_execute_with
(||
{
storage
::
unhashed
::
put
(
&
Holds
::
<
Test
>
::
hashed_key_for
(
1
),
&
vec!
[
0u8
;
<
Test
as
Config
>
::
RuntimeHoldReason
::
VARIANT_COUNT
as
usize
+
1
],
);
assert!
(
format!
(
"{:?}"
,
Balances
::
try_state
(
0
)
.unwrap_err
())
.contains
(
"Found `Hold` with too many elements"
));
});
ExtBuilder
::
default
()
.build_and_execute_with
(||
{
let
max_freezes
:
u32
=
<
Test
as
Config
>
::
MaxFreezes
::
get
();
storage
::
unhashed
::
put
(
&
Freezes
::
<
Test
>
::
hashed_key_for
(
1
),
&
vec!
[
0u8
;
max_freezes
as
usize
+
1
],
);
assert!
(
format!
(
"{:?}"
,
Balances
::
try_state
(
0
)
.unwrap_err
())
.contains
(
"Found `Freeze` with too many elements"
));
});
}
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