Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
open-runtime-module-library
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
Noxim
open-runtime-module-library
Commits
2a874fc7
Unverified
Commit
2a874fc7
authored
3 years ago
by
zjb0807
Committed by
GitHub
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
fix module account ed (#549)
parent
3d64077e
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
tokens/src/lib.rs
+8
-17
8 additions, 17 deletions
tokens/src/lib.rs
tokens/src/mock.rs
+6
-1
6 additions, 1 deletion
tokens/src/mock.rs
tokens/src/tests.rs
+5
-13
5 additions, 13 deletions
tokens/src/tests.rs
with
19 additions
and
31 deletions
tokens/src/lib.rs
+
8
−
17
View file @
2a874fc7
...
...
@@ -48,7 +48,7 @@ use frame_support::{
LockableCurrency
as
PalletLockableCurrency
,
MaxEncodedLen
,
ReservableCurrency
as
PalletReservableCurrency
,
SignedImbalance
,
WithdrawReasons
,
},
transactional
,
BoundedVec
,
PalletId
,
transactional
,
BoundedVec
,
};
use
frame_system
::{
ensure_signed
,
pallet_prelude
::
*
};
use
orml_traits
::{
...
...
@@ -59,8 +59,8 @@ use orml_traits::{
};
use
sp_runtime
::{
traits
::{
AccountIdConversion
,
AtLeast32BitUnsigned
,
Bounded
,
CheckedAdd
,
CheckedSub
,
MaybeSerializeDeserialize
,
Member
,
Saturating
,
StaticLookup
,
Zero
,
AtLeast32BitUnsigned
,
Bounded
,
CheckedAdd
,
CheckedSub
,
MaybeSerializeDeserialize
,
Member
,
Saturating
,
StaticLookup
,
Zero
,
},
ArithmeticError
,
DispatchError
,
DispatchResult
,
RuntimeDebug
,
};
...
...
@@ -360,11 +360,6 @@ pub mod module {
}
impl
<
T
:
Config
>
Pallet
<
T
>
{
/// Check whether account_id is a module account
pub
(
crate
)
fn
is_module_account_id
(
account_id
:
&
T
::
AccountId
)
->
bool
{
PalletId
::
try_from_account
(
account_id
)
.is_some
()
}
pub
(
crate
)
fn
deposit_consequence
(
_who
:
&
T
::
AccountId
,
currency_id
:
T
::
CurrencyId
,
...
...
@@ -457,9 +452,8 @@ impl<T: Config> Pallet<T> {
*
maybe_account
=
if
total
.is_zero
()
{
None
}
else
{
// if non_zero total is below existential deposit and the account is not a
// module account, should handle the dust.
if
total
<
T
::
ExistentialDeposits
::
get
(
&
currency_id
)
&&
!
Self
::
is_module_account_id
(
who
)
{
// if non_zero total is below existential deposit, should handle the dust.
if
total
<
T
::
ExistentialDeposits
::
get
(
&
currency_id
)
{
maybe_dust
=
Some
(
total
);
}
Some
(
account
)
...
...
@@ -594,12 +588,9 @@ impl<T: Config> Pallet<T> {
to_account
.free
=
to_account
.free
.checked_add
(
&
amount
)
.ok_or
(
ArithmeticError
::
Overflow
)
?
;
let
ed
=
T
::
ExistentialDeposits
::
get
(
&
currency_id
);
// if to_account non_zero total is below existential deposit and the account is
// not a module account, would return an error.
ensure!
(
to_account
.total
()
>=
ed
||
Self
::
is_module_account_id
(
to
),
Error
::
<
T
>
::
ExistentialDeposit
);
// if to_account non_zero total is below existential deposit, would return an
// error.
ensure!
(
to_account
.total
()
>=
ed
,
Error
::
<
T
>
::
ExistentialDeposit
);
Self
::
ensure_can_withdraw
(
currency_id
,
from
,
amount
)
?
;
...
...
This diff is collapsed.
Click to expand it.
tokens/src/mock.rs
+
6
−
1
View file @
2a874fc7
...
...
@@ -6,10 +6,15 @@ use super::*;
use
frame_support
::{
construct_runtime
,
parameter_types
,
traits
::{
ChangeMembers
,
ContainsLengthBound
,
SaturatingCurrencyToVote
,
SortedMembers
},
PalletId
,
};
use
orml_traits
::
parameter_type_with_key
;
use
sp_core
::
H256
;
use
sp_runtime
::{
testing
::
Header
,
traits
::
IdentityLookup
,
AccountId32
,
Permill
};
use
sp_runtime
::{
testing
::
Header
,
traits
::{
AccountIdConversion
,
IdentityLookup
},
AccountId32
,
Permill
,
};
use
sp_std
::
cell
::
RefCell
;
pub
type
AccountId
=
AccountId32
;
...
...
This diff is collapsed.
Click to expand it.
tokens/src/tests.rs
+
5
−
13
View file @
2a874fc7
...
...
@@ -15,21 +15,10 @@ fn minimum_balance_work() {
});
}
#[test]
fn
is_module_account_id_work
()
{
ExtBuilder
::
default
()
.build
()
.execute_with
(||
{
assert_eq!
(
Tokens
::
is_module_account_id
(
&
ALICE
),
false
);
assert_eq!
(
Tokens
::
is_module_account_id
(
&
BOB
),
false
);
assert_eq!
(
Tokens
::
is_module_account_id
(
&
TREASURY_ACCOUNT
),
false
);
assert_eq!
(
Tokens
::
is_module_account_id
(
&
DustAccount
::
get
()),
true
);
});
}
#[test]
fn
remove_dust_work
()
{
ExtBuilder
::
default
()
.build
()
.execute_with
(||
{
System
::
set_block_number
(
1
);
assert_ok!
(
Tokens
::
deposit
(
DOT
,
&
ALICE
,
100
));
assert_eq!
(
Tokens
::
total_issuance
(
DOT
),
100
);
assert_eq!
(
Accounts
::
<
Runtime
>
::
contains_key
(
ALICE
,
DOT
),
true
);
...
...
@@ -49,17 +38,20 @@ fn remove_dust_work() {
assert_eq!
(
Tokens
::
free_balance
(
DOT
,
&
DustAccount
::
get
()),
0
);
assert_eq!
(
System
::
providers
(
&
DustAccount
::
get
()),
0
);
// ensure dust account balance gte ED
assert_ok!
(
Tokens
::
deposit
(
DOT
,
&
DustAccount
::
get
(),
Tokens
::
minimum_balance
(
DOT
)));
assert_ok!
(
Tokens
::
withdraw
(
DOT
,
&
ALICE
,
1
));
// total is lte ED, will handle dust
assert_eq!
(
Tokens
::
total_issuance
(
DOT
),
1
);
assert_eq!
(
Tokens
::
total_issuance
(
DOT
),
3
);
assert_eq!
(
Accounts
::
<
Runtime
>
::
contains_key
(
ALICE
,
DOT
),
false
);
assert_eq!
(
Tokens
::
free_balance
(
DOT
,
&
ALICE
),
0
);
assert_eq!
(
System
::
providers
(
&
ALICE
),
0
);
// will not handle dust for module account
assert_eq!
(
Accounts
::
<
Runtime
>
::
contains_key
(
DustAccount
::
get
(),
DOT
),
true
);
assert_eq!
(
Tokens
::
free_balance
(
DOT
,
&
DustAccount
::
get
()),
1
);
assert_eq!
(
Tokens
::
free_balance
(
DOT
,
&
DustAccount
::
get
()),
3
);
assert_eq!
(
System
::
providers
(
&
DustAccount
::
get
()),
1
);
System
::
assert_last_event
(
Event
::
Tokens
(
crate
::
Event
::
DustLost
(
DOT
,
ALICE
,
1
)));
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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