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
2a55e07b
Unverified
Commit
2a55e07b
authored
4 years ago
by
Shaopeng Wang
Committed by
GitHub
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Add VestedTransferOrigin. (#287)
parent
b1311575
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
vesting/src/lib.rs
+5
-2
5 additions, 2 deletions
vesting/src/lib.rs
vesting/src/mock.rs
+20
-0
20 additions, 0 deletions
vesting/src/mock.rs
vesting/src/tests.rs
+17
-1
17 additions, 1 deletion
vesting/src/tests.rs
with
42 additions
and
3 deletions
vesting/src/lib.rs
+
5
−
2
View file @
2a55e07b
...
...
@@ -29,7 +29,7 @@
use
codec
::{
Decode
,
Encode
,
HasCompact
};
use
frame_support
::{
decl_error
,
decl_event
,
decl_module
,
decl_storage
,
ensure
,
traits
::{
Currency
,
ExistenceRequirement
,
Get
,
LockIdentifier
,
LockableCurrency
,
WithdrawReasons
},
traits
::{
Currency
,
EnsureOrigin
,
ExistenceRequirement
,
Get
,
LockIdentifier
,
LockableCurrency
,
WithdrawReasons
},
weights
::
Weight
,
};
use
frame_system
::{
ensure_root
,
ensure_signed
};
...
...
@@ -122,6 +122,9 @@ pub trait Trait: frame_system::Trait {
/// The minimum amount transferred to call `vested_transfer`.
type
MinVestedTransfer
:
Get
<
BalanceOf
<
Self
>>
;
/// Required origin for vested transfer.
type
VestedTransferOrigin
:
EnsureOrigin
<
Self
::
Origin
,
Success
=
Self
::
AccountId
>
;
/// Weight information for extrinsics in this module.
type
WeightInfo
:
WeightInfo
;
}
...
...
@@ -220,7 +223,7 @@ decl_module! {
dest
:
<
T
::
Lookup
as
StaticLookup
>
::
Source
,
schedule
:
VestingScheduleOf
<
T
>
,
)
{
let
from
=
ensure_
signed
(
origin
)
?
;
let
from
=
T
::
VestedTransferOrigin
::
ensure_
origin
(
origin
)
?
;
let
to
=
T
::
Lookup
::
lookup
(
dest
)
?
;
Self
::
do_vested_transfer
(
&
from
,
&
to
,
schedule
.clone
())
?
;
...
...
This diff is collapsed.
Click to expand it.
vesting/src/mock.rs
+
20
−
0
View file @
2a55e07b
...
...
@@ -3,6 +3,7 @@
#![cfg(test)]
use
frame_support
::{
impl_outer_event
,
impl_outer_origin
,
parameter_types
};
use
frame_system
::
RawOrigin
;
use
pallet_balances
;
use
sp_core
::
H256
;
use
sp_runtime
::{
testing
::
Header
,
traits
::
IdentityLookup
,
Perbill
};
...
...
@@ -81,10 +82,29 @@ impl pallet_balances::Trait for Runtime {
}
pub
type
PalletBalances
=
pallet_balances
::
Module
<
Runtime
>
;
pub
struct
EnsureAliceOrBob
;
impl
EnsureOrigin
<
Origin
>
for
EnsureAliceOrBob
{
type
Success
=
AccountId
;
fn
try_origin
(
o
:
Origin
)
->
Result
<
Self
::
Success
,
Origin
>
{
Into
::
<
Result
<
RawOrigin
<
AccountId
>
,
Origin
>>
::
into
(
o
)
.and_then
(|
o
|
match
o
{
RawOrigin
::
Signed
(
ALICE
)
=>
Ok
(
ALICE
),
RawOrigin
::
Signed
(
BOB
)
=>
Ok
(
BOB
),
r
=>
Err
(
Origin
::
from
(
r
)),
})
}
#[cfg(feature
=
"runtime-benchmarks"
)]
fn
successful_origin
()
->
Origin
{
Origin
::
from
(
RawOrigin
::
Signed
(
Default
::
default
()))
}
}
impl
Trait
for
Runtime
{
type
Event
=
TestEvent
;
type
Currency
=
PalletBalances
;
type
MinVestedTransfer
=
MinVestedTransfer
;
type
VestedTransferOrigin
=
EnsureAliceOrBob
;
type
WeightInfo
=
();
}
pub
type
Vesting
=
Module
<
Runtime
>
;
...
...
This diff is collapsed.
Click to expand it.
vesting/src/tests.rs
+
17
−
1
View file @
2a55e07b
...
...
@@ -3,7 +3,7 @@
#![cfg(test)]
use
super
::
*
;
use
frame_support
::{
assert_err
,
assert_
ok
,
traits
::
WithdrawReason
};
use
frame_support
::{
assert_err
,
assert_
noop
,
assert_ok
,
error
::
BadOrigin
,
traits
::
WithdrawReason
};
use
mock
::{
ExtBuilder
,
Origin
,
PalletBalances
,
Runtime
,
System
,
TestEvent
,
Vesting
,
ALICE
,
BOB
,
CHARLIE
};
use
pallet_balances
::{
BalanceLock
,
Reasons
};
...
...
@@ -188,6 +188,22 @@ fn vested_transfer_fails_if_overflow() {
});
}
#[test]
fn
vested_transfer_fails_if_bad_origin
()
{
ExtBuilder
::
build
()
.execute_with
(||
{
let
schedule
=
VestingSchedule
{
start
:
0u64
,
period
:
10u64
,
period_count
:
1u32
,
per_period
:
100u64
,
};
assert_noop!
(
Vesting
::
vested_transfer
(
Origin
::
signed
(
CHARLIE
),
BOB
,
schedule
.clone
()),
BadOrigin
);
});
}
#[test]
fn
claim_works
()
{
ExtBuilder
::
build
()
.execute_with
(||
{
...
...
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