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
496dfedf
Unverified
Commit
496dfedf
authored
4 years ago
by
brettkolodny
Committed by
GitHub
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Migrated mock to construct_runtime macro (#369)
parent
15b38185
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
authority/src/mock.rs
+1
-1
1 addition, 1 deletion
authority/src/mock.rs
benchmarking/Cargo.toml
+2
-0
2 additions, 0 deletions
benchmarking/Cargo.toml
benchmarking/src/tests.rs
+54
-32
54 additions, 32 deletions
benchmarking/src/tests.rs
with
57 additions
and
33 deletions
authority/src/mock.rs
+
1
−
1
View file @
496dfedf
...
...
@@ -43,7 +43,7 @@ impl frame_system::Config for Runtime {
type
BlockWeights
=
();
type
BlockLength
=
();
type
Version
=
();
type
PalletInfo
=
()
;
type
PalletInfo
=
PalletInfo
;
type
AccountData
=
();
type
OnNewAccount
=
();
type
OnKilledAccount
=
();
...
...
This diff is collapsed.
Click to expand it.
benchmarking/Cargo.toml
+
2
−
0
View file @
496dfedf
...
...
@@ -8,6 +8,7 @@ authors = ["Laminar Developers <hello@laminar.one>"]
edition
=
"2018"
[dependencies]
serde
=
{
version
=
"1.0.111"
,
optional
=
true
}
paste
=
"0.1.16"
codec
=
{
package
=
"parity-scale-codec"
,
version
=
"2.0.0"
,
default-features
=
false
}
sp-api
=
{
version
=
"2.0.1"
,
default-features
=
false
}
...
...
@@ -25,6 +26,7 @@ hex-literal = "0.2.1"
[features]
default
=
[
"std"
]
std
=
[
"serde"
,
"codec/std"
,
"sp-runtime-interface/std"
,
"sp-runtime/std"
,
...
...
This diff is collapsed.
Click to expand it.
benchmarking/src/tests.rs
+
54
−
32
View file @
496dfedf
...
...
@@ -4,43 +4,48 @@
use
super
::
*
;
use
frame_benchmarking
::
account
;
use
frame_support
::{
assert_err
,
assert_ok
,
decl_module
,
decl_storage
,
dispatch
::
DispatchResult
,
ensure
,
impl_outer_origin
,
};
use
frame_system
::{
ensure_none
,
ensure_signed
,
RawOrigin
};
use
frame_support
::{
assert_err
,
assert_ok
,
construct_runtime
,
ensure
};
use
frame_system
::
RawOrigin
;
use
sp_runtime
::{
testing
::{
Header
,
H256
},
traits
::{
BlakeTwo256
,
IdentityLookup
},
};
use
sp_std
::
prelude
::
*
;
decl_storage!
{
trait
Store
for
Module
<
T
:
Config
>
as
Test
{
Value
get
(
fn
value
):
Option
<
u32
>
;
mod
test
{
use
frame_support
::{
decl_module
,
decl_storage
,
dispatch
::
DispatchResult
};
use
frame_system
::{
ensure_none
,
ensure_signed
};
use
sp_std
::
prelude
::
*
;
pub
trait
Config
:
frame_system
::
Config
{
type
Event
;
type
BlockNumber
;
}
}
decl_module!
{
pub
struct
Module
<
T
:
Config
>
for
enum
Call
where
origin
:
T
::
Origin
{
#[weight
=
0
]
fn
set_value
(
origin
,
n
:
u32
)
->
DispatchResult
{
let
_sender
=
ensure_signed
(
origin
)
?
;
Value
::
put
(
n
);
Ok
(())
decl_storage!
{
trait
Store
for
Module
<
T
:
Config
>
as
Test
{
pub
Value
get
(
fn
value
)
config
():
Option
<
u32
>
;
}
}
#[weight
=
0
]
fn
dummy
(
origin
,
_n
:
u32
)
->
DispatchResult
{
let
_sender
=
ensure_none
(
origin
)
?
;
Ok
(())
decl_module!
{
pub
struct
Module
<
T
:
Config
>
for
enum
Call
where
origin
:
T
::
Origin
{
#[weight
=
0
]
fn
set_value
(
origin
,
n
:
u32
)
->
DispatchResult
{
let
_sender
=
ensure_signed
(
origin
)
?
;
Value
::
put
(
n
);
Ok
(())
}
#[weight
=
0
]
fn
dummy
(
origin
,
_n
:
u32
)
->
DispatchResult
{
let
_sender
=
ensure_none
(
origin
)
?
;
Ok
(())
}
}
}
}
impl_outer_origin!
{
pub
enum
Origin
for
Test
{}
}
pub
trait
Config
:
frame_system
::
Config
{
type
Event
;
type
BlockNumber
;
...
...
@@ -48,26 +53,23 @@ pub trait Config: frame_system::Config {
type
AccountId
=
u128
;
#[derive(Clone,
Eq,
PartialEq)]
pub
struct
Test
;
impl
frame_system
::
Config
for
Test
{
type
Origin
=
Origin
;
type
Index
=
u64
;
type
BlockNumber
=
u64
;
type
Hash
=
H256
;
type
Call
=
()
;
type
Call
=
Call
;
type
Hashing
=
BlakeTwo256
;
type
AccountId
=
AccountId
;
type
Lookup
=
IdentityLookup
<
Self
::
AccountId
>
;
type
Header
=
Header
;
type
Event
=
()
;
type
Event
=
Event
;
type
BlockHashCount
=
();
type
DbWeight
=
();
type
BlockWeights
=
();
type
BlockLength
=
();
type
Version
=
();
type
PalletInfo
=
()
;
type
PalletInfo
=
PalletInfo
;
type
AccountData
=
();
type
OnNewAccount
=
();
type
OnKilledAccount
=
();
...
...
@@ -76,11 +78,31 @@ impl frame_system::Config for Test {
type
SS58Prefix
=
();
}
impl
tests
::
test
::
Config
for
Test
{
type
Event
=
Event
;
type
BlockNumber
=
u32
;
}
impl
Config
for
Test
{
type
Event
=
()
;
type
Event
=
Event
;
type
BlockNumber
=
u32
;
}
pub
type
Block
=
sp_runtime
::
generic
::
Block
<
Header
,
UncheckedExtrinsic
>
;
pub
type
UncheckedExtrinsic
=
sp_runtime
::
generic
::
UncheckedExtrinsic
<
u32
,
Call
,
u32
,
()
>
;
construct_runtime!
(
pub
enum
Test
where
Block
=
Block
,
NodeBlock
=
Block
,
UncheckedExtrinsic
=
UncheckedExtrinsic
,
{
System
:
frame_system
::{
Module
,
Call
,
Storage
,
Config
,
Event
<
T
>
},
Pallet
:
test
::{
Module
,
Call
,
Storage
,
Config
},
}
);
// This function basically just builds a genesis storage key/value store
// according to our desired mockup.
fn
new_test_ext
()
->
sp_io
::
TestExternalities
{
...
...
@@ -91,7 +113,7 @@ fn new_test_ext() -> sp_io::TestExternalities {
}
runtime_benchmarks!
{
{
Test
,
self
}
{
Test
,
test
}
_
{
// Define a common range for `b`.
...
...
@@ -103,7 +125,7 @@ runtime_benchmarks! {
let
caller
=
account
::
<
AccountId
>
(
"caller"
,
0
,
0
);
}:
_
(
RawOrigin
::
Signed
(
caller
),
b
.into
())
verify
{
assert_eq!
(
V
al
ue
::
get
(),
Some
(
b
));
assert_eq!
(
P
al
let
::
value
(),
Some
(
b
));
}
other_name
{
...
...
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