Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Duniter v2S
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Monitor
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
nodes
rust
Duniter v2S
Commits
9fde3d3c
Commit
9fde3d3c
authored
2 years ago
by
Éloïs
Browse files
Options
Downloads
Patches
Plain Diff
fix(gtest): fix local chain spec generation
parent
f01c8fe1
No related branches found
No related tags found
No related merge requests found
Pipeline
#17807
passed
2 years ago
Stage: build
Stage: tests
Stage: deploy
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
node/src/chain_spec/gtest.rs
+63
-27
63 additions, 27 deletions
node/src/chain_spec/gtest.rs
node/src/command.rs
+3
-3
3 additions, 3 deletions
node/src/command.rs
with
66 additions
and
30 deletions
node/src/chain_spec/gtest.rs
+
63
−
27
View file @
9fde3d3c
...
@@ -16,17 +16,18 @@
...
@@ -16,17 +16,18 @@
use
super
::
*
;
use
super
::
*
;
use
common_runtime
::
constants
::
*
;
use
common_runtime
::
constants
::
*
;
use
common_runtime
::
entities
::
IdtyName
;
use
common_runtime
::
entities
::
IdtyData
;
use
common_runtime
::
*
;
use
gtest_runtime
::{
use
gtest_runtime
::{
opaque
::
SessionKeys
,
AccountId
,
AuthorityMembersConfig
,
BabeConfig
,
BalancesConfig
,
CertConfig
,
opaque
::
SessionKeys
,
AccountConfig
,
AccountId
,
AuthorityMembersConfig
,
BabeConfig
,
GenesisConfig
,
IdentityConfig
,
IdtyValue
,
ImOnlineId
,
MembershipConfig
,
SessionConfig
,
BalancesConfig
,
CertConfig
,
GenesisConfig
,
IdentityConfig
,
IdtyValue
,
ImOnlineId
,
SmithsCertConfig
,
SmithsMembershipConfig
,
SudoConfig
,
SystemConfig
,
UdAccountsStorageConfig
,
MembershipConfig
,
SessionConfig
,
SmithsCertConfig
,
SmithsMembershipConfig
,
SudoConfig
,
UniversalDividendConfig
,
WASM_BINARY
,
SystemConfig
,
TechnicalCommitteeConfig
,
UniversalDividendConfig
,
WASM_BINARY
,
};
};
use
sc_service
::
ChainType
;
use
sc_service
::
ChainType
;
use
sp_authority_discovery
::
AuthorityId
as
AuthorityDiscoveryId
;
use
sp_authority_discovery
::
AuthorityId
as
AuthorityDiscoveryId
;
use
sp_consensus_babe
::
AuthorityId
as
BabeId
;
use
sp_consensus_babe
::
AuthorityId
as
BabeId
;
use
sp_core
::
sr25519
;
use
sp_core
::
{
blake2_256
,
sr25519
,
Encode
,
H256
}
;
use
sp_finality_grandpa
::
AuthorityId
as
GrandpaId
;
use
sp_finality_grandpa
::
AuthorityId
as
GrandpaId
;
use
sp_membership
::
MembershipData
;
use
sp_membership
::
MembershipData
;
use
std
::
collections
::
BTreeMap
;
use
std
::
collections
::
BTreeMap
;
...
@@ -69,10 +70,12 @@ pub fn development_chain_spec() -> Result<ChainSpec, String> {
...
@@ -69,10 +70,12 @@ pub fn development_chain_spec() -> Result<ChainSpec, String> {
move
||
{
move
||
{
gen_genesis_for_local_chain
(
gen_genesis_for_local_chain
(
wasm_binary
,
wasm_binary
,
// Initial authorities
// Initial authorities
len
1
,
1
,
// Inital
identities
// Init
i
al
smiths members len
3
,
3
,
// Inital identities len
4
,
// Sudo account
// Sudo account
get_account_id_from_seed
::
<
sr25519
::
Public
>
(
"Alice"
),
get_account_id_from_seed
::
<
sr25519
::
Public
>
(
"Alice"
),
true
,
true
,
...
@@ -103,6 +106,7 @@ pub fn development_chain_spec() -> Result<ChainSpec, String> {
...
@@ -103,6 +106,7 @@ pub fn development_chain_spec() -> Result<ChainSpec, String> {
pub
fn
local_testnet_config
(
pub
fn
local_testnet_config
(
initial_authorities_len
:
usize
,
initial_authorities_len
:
usize
,
initial_smiths_len
:
usize
,
initial_identities_len
:
usize
,
initial_identities_len
:
usize
,
)
->
Result
<
ChainSpec
,
String
>
{
)
->
Result
<
ChainSpec
,
String
>
{
let
wasm_binary
=
WASM_BINARY
.ok_or_else
(||
"wasm not available"
.to_string
())
?
;
let
wasm_binary
=
WASM_BINARY
.ok_or_else
(||
"wasm not available"
.to_string
())
?
;
...
@@ -118,6 +122,8 @@ pub fn local_testnet_config(
...
@@ -118,6 +122,8 @@ pub fn local_testnet_config(
wasm_binary
,
wasm_binary
,
// Initial authorities len
// Initial authorities len
initial_authorities_len
,
initial_authorities_len
,
// Initial smiths len,
initial_smiths_len
,
// Initial identities len
// Initial identities len
initial_identities_len
,
initial_identities_len
,
// Sudo account
// Sudo account
...
@@ -151,11 +157,18 @@ pub fn local_testnet_config(
...
@@ -151,11 +157,18 @@ pub fn local_testnet_config(
fn
gen_genesis_for_local_chain
(
fn
gen_genesis_for_local_chain
(
wasm_binary
:
&
[
u8
],
wasm_binary
:
&
[
u8
],
initial_authorities_len
:
usize
,
initial_authorities_len
:
usize
,
initial_smiths_len
:
usize
,
initial_identities_len
:
usize
,
initial_identities_len
:
usize
,
root_key
:
AccountId
,
root_key
:
AccountId
,
_enable_println
:
bool
,
_enable_println
:
bool
,
)
->
GenesisConfig
{
)
->
GenesisConfig
{
let
initial_authorities
=
(
0
..
initial_authorities_len
)
assert!
(
initial_identities_len
<=
6
);
assert!
(
initial_smiths_len
<=
initial_identities_len
);
assert!
(
initial_authorities_len
<=
initial_smiths_len
);
let
first_ud
=
1_000
;
let
initial_smiths
=
(
0
..
initial_smiths_len
)
.map
(|
i
|
get_authority_keys_from_seed
(
NAMES
[
i
]))
.map
(|
i
|
get_authority_keys_from_seed
(
NAMES
[
i
]))
.collect
::
<
Vec
<
AuthorityKeys
>>
();
.collect
::
<
Vec
<
AuthorityKeys
>>
();
let
initial_identities
=
(
0
..
initial_identities_len
)
let
initial_identities
=
(
0
..
initial_identities_len
)
...
@@ -172,9 +185,25 @@ fn gen_genesis_for_local_chain(
...
@@ -172,9 +185,25 @@ fn gen_genesis_for_local_chain(
// Add Wasm runtime to storage.
// Add Wasm runtime to storage.
code
:
wasm_binary
.to_vec
(),
code
:
wasm_binary
.to_vec
(),
},
},
account
:
AccountConfig
{
accounts
:
initial_identities
.iter
()
.enumerate
()
.map
(|(
i
,
(
_
,
owner_key
))|
{
(
owner_key
.clone
(),
GenesisAccountData
{
random_id
:
H256
(
blake2_256
(
&
(
i
as
u32
,
owner_key
)
.encode
())),
balance
:
first_ud
,
is_identity
:
true
,
},
)
})
.collect
(),
},
authority_discovery
:
Default
::
default
(),
authority_discovery
:
Default
::
default
(),
authority_members
:
AuthorityMembersConfig
{
authority_members
:
AuthorityMembersConfig
{
initial_authorities
:
initial_
authoritie
s
initial_authorities
:
initial_
smith
s
.iter
()
.iter
()
.enumerate
()
.enumerate
()
.map
(|(
i
,
keys
)|
(
i
as
u32
+
1
,
(
keys
.0
.clone
(),
true
)))
.map
(|(
i
,
keys
)|
(
i
as
u32
+
1
,
(
keys
.0
.clone
(),
true
)))
...
@@ -190,7 +219,7 @@ fn gen_genesis_for_local_chain(
...
@@ -190,7 +219,7 @@ fn gen_genesis_for_local_chain(
grandpa
:
Default
::
default
(),
grandpa
:
Default
::
default
(),
im_online
:
Default
::
default
(),
im_online
:
Default
::
default
(),
session
:
SessionConfig
{
session
:
SessionConfig
{
keys
:
initial_
authoritie
s
keys
:
initial_
smith
s
.iter
()
.iter
()
.map
(|
x
|
{
.map
(|
x
|
{
(
(
...
@@ -205,14 +234,28 @@ fn gen_genesis_for_local_chain(
...
@@ -205,14 +234,28 @@ fn gen_genesis_for_local_chain(
// Assign network admin rights.
// Assign network admin rights.
key
:
Some
(
root_key
),
key
:
Some
(
root_key
),
},
},
technical_committee
:
TechnicalCommitteeConfig
{
members
:
initial_smiths
.iter
()
.map
(|
x
|
x
.0
.clone
())
.collect
::
<
Vec
<
_
>>
(),
..
Default
::
default
()
},
identity
:
IdentityConfig
{
identity
:
IdentityConfig
{
identities
:
initial_identities
identities
:
initial_identities
.iter
()
.iter
()
.map
(|(
name
,
account
)|
IdtyValue
{
.enumerate
()
.map
(|(
i
,
(
name
,
owner_key
))|
common_runtime
::
GenesisIdty
{
index
:
i
as
u32
+
1
,
name
:
name
.clone
(),
name
:
name
.clone
(),
next_creatable_identity_on
:
Default
::
default
(),
value
:
IdtyValue
{
removable_on
:
0
,
data
:
IdtyData
::
new
(),
status
:
gtest_runtime
::
IdtyStatus
::
Validated
,
next_creatable_identity_on
:
Default
::
default
(),
old_owner_key
:
None
,
owner_key
:
owner_key
.clone
(),
removable_on
:
0
,
status
:
IdtyStatus
::
Validated
,
},
})
})
.collect
(),
.collect
(),
},
},
...
@@ -230,13 +273,10 @@ fn gen_genesis_for_local_chain(
...
@@ -230,13 +273,10 @@ fn gen_genesis_for_local_chain(
},
},
cert
:
CertConfig
{
cert
:
CertConfig
{
apply_cert_period_at_genesis
:
false
,
apply_cert_period_at_genesis
:
false
,
certs_by_issuer
:
clique_wot
(
certs_by_receiver
:
clique_wot
(
initial_identities
.len
()),
initial_identities
.len
(),
gtest_runtime
::
parameters
::
ValidityPeriod
::
get
(),
),
},
},
smiths_membership
:
SmithsMembershipConfig
{
smiths_membership
:
SmithsMembershipConfig
{
memberships
:
(
1
..=
initial_
authoritie
s_len
)
memberships
:
(
1
..=
initial_
smith
s_len
)
.map
(|
i
|
{
.map
(|
i
|
{
(
(
i
as
u32
,
i
as
u32
,
...
@@ -249,18 +289,14 @@ fn gen_genesis_for_local_chain(
...
@@ -249,18 +289,14 @@ fn gen_genesis_for_local_chain(
},
},
smiths_cert
:
SmithsCertConfig
{
smiths_cert
:
SmithsCertConfig
{
apply_cert_period_at_genesis
:
false
,
apply_cert_period_at_genesis
:
false
,
certs_by_issuer
:
clique_wot
(
certs_by_receiver
:
clique_wot
(
initial_smiths_len
),
initial_authorities_len
,
gtest_runtime
::
parameters
::
SmithValidityPeriod
::
get
(),
),
},
ud_accounts_storage
:
UdAccountsStorageConfig
{
ud_accounts
:
initial_identities
.values
()
.cloned
()
.collect
(),
},
},
universal_dividend
:
UniversalDividendConfig
{
universal_dividend
:
UniversalDividendConfig
{
first_reeval
:
100
,
first_ud
:
1_000
,
first_ud
:
1_000
,
initial_monetary_mass
:
0
,
initial_monetary_mass
:
0
,
},
},
treasury
:
Default
::
default
(),
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
node/src/command.rs
+
3
−
3
View file @
9fde3d3c
...
@@ -106,11 +106,11 @@ impl SubstrateCli for Cli {
...
@@ -106,11 +106,11 @@ impl SubstrateCli for Cli {
#[cfg(feature
=
"gtest"
)]
#[cfg(feature
=
"gtest"
)]
"gtest_dev"
=>
Box
::
new
(
chain_spec
::
gtest
::
development_chain_spec
()
?
),
"gtest_dev"
=>
Box
::
new
(
chain_spec
::
gtest
::
development_chain_spec
()
?
),
#[cfg(feature
=
"gtest"
)]
#[cfg(feature
=
"gtest"
)]
"gtest_local"
=>
Box
::
new
(
chain_spec
::
gtest
::
local_testnet_config
(
2
,
3
)
?
),
"gtest_local"
=>
Box
::
new
(
chain_spec
::
gtest
::
local_testnet_config
(
2
,
3
,
4
)
?
),
#[cfg(feature
=
"gtest"
)]
#[cfg(feature
=
"gtest"
)]
"gtest_local3"
=>
Box
::
new
(
chain_spec
::
gtest
::
local_testnet_config
(
3
,
4
)
?
),
"gtest_local3"
=>
Box
::
new
(
chain_spec
::
gtest
::
local_testnet_config
(
3
,
3
,
4
)
?
),
#[cfg(feature
=
"gtest"
)]
#[cfg(feature
=
"gtest"
)]
"gtest_local4"
=>
Box
::
new
(
chain_spec
::
gtest
::
local_testnet_config
(
4
,
5
)
?
),
"gtest_local4"
=>
Box
::
new
(
chain_spec
::
gtest
::
local_testnet_config
(
4
,
4
,
5
)
?
),
#[cfg(feature
=
"gtest"
)]
#[cfg(feature
=
"gtest"
)]
"gtest"
=>
{
"gtest"
=>
{
unimplemented!
()
unimplemented!
()
...
...
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