Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
burrow
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hang Yu
burrow
Commits
bccc4eaa
Commit
bccc4eaa
authored
8 years ago
by
zramsay
Browse files
Options
Downloads
Patches
Plain Diff
genesis test: refactor
parent
34688ac3
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
client/cmd/genesis.go
+4
-10
4 additions, 10 deletions
client/cmd/genesis.go
genesis/gen_test.go
+8
-79
8 additions, 79 deletions
genesis/gen_test.go
with
12 additions
and
89 deletions
client/cmd/genesis.go
+
4
−
10
View file @
bccc4eaa
...
...
@@ -10,23 +10,17 @@ import (
// TODO refactor these vars into a struct?
var
(
//DirFlag string
//AddrsFlag string
AccountsPathFlag
string
ValidatorsPathFlag
string
//CsvPathFlag string
//PubkeyFlag string
//RootFlag string
//NoValAccountsFlag bool
)
var
GenesisGenCmd
=
&
cobra
.
Command
{
Use
:
"genesis"
,
Short
:
"eris-client genesis creates a genesis.json with known inputs"
,
Long
:
"eris-client genesis creates a genesis.json with known inputs"
,
Use
:
"
make-
genesis"
,
Short
:
"eris-client
make-
genesis creates a genesis.json with known inputs"
,
Long
:
"eris-client
make-
genesis creates a genesis.json with known inputs"
,
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
// TODO refactor to not panic
genesisFile
,
err
:=
genesis
.
GenerateKnown
(
args
[
0
],
AccountsPathFlag
,
ValidatorsPathFlag
)
if
err
!=
nil
{
panic
(
err
)
...
...
This diff is collapsed.
Click to expand it.
genesis/gen_test.go
+
8
−
79
View file @
bccc4eaa
...
...
@@ -9,11 +9,14 @@ import (
"path"
"testing"
ptypes
"github.com/eris-ltd/mint-client/Godeps/_workspace/src/github.com/eris-ltd/tendermint/permission/types"
stypes
"github.com/eris-ltd/mint-client/Godeps/_workspace/src/github.com/eris-ltd/tendermint/state/types"
"github.com/eris-ltd/mint-client/Godeps/_workspace/src/github.com/eris-ltd/tendermint/types"
stypes
"github.com/eris-ltd/eris-db/manager/eris-mint/state/types"
ptypes
"github.com/eris-ltd/eris-db/permission/types"
// XXX
//"github.com/eris-ltd/mint-client/Godeps/_workspace/src/github.com/eris-ltd/tendermint/types"
)
var
DirFlag
string
func
MakeGenesisDocFromFile
(
genDocFile
string
)
*
stypes
.
GenesisDoc
{
jsonBlob
,
err
:=
ioutil
.
ReadFile
(
genDocFile
)
if
err
!=
nil
{
...
...
@@ -23,80 +26,6 @@ func MakeGenesisDocFromFile(genDocFile string) *stypes.GenesisDoc {
return
stypes
.
GenesisDocFromJSON
(
jsonBlob
)
}
func
testCoreRandom
(
N
int
)
error
{
chainID
:=
"test_chainID"
genBytes
,
privVals
,
err
:=
coreRandom
(
N
,
chainID
,
""
,
""
,
""
,
false
)
if
err
!=
nil
{
return
err
}
if
len
(
privVals
)
!=
N
{
return
fmt
.
Errorf
(
"len(privVals) != N"
)
}
// make sure each validator is in the genesis and all genesi are the same
for
i
,
v
:=
range
privVals
{
dirFlag
:=
DirFlag
if
N
>
1
{
dirFlag
=
path
.
Join
(
DirFlag
,
fmt
.
Sprintf
(
"%s_%d"
,
chainID
,
i
))
}
b
,
err
:=
ioutil
.
ReadFile
(
path
.
Join
(
dirFlag
,
"genesis.json"
))
if
err
!=
nil
{
return
err
}
if
!
bytes
.
Equal
(
b
,
genBytes
)
{
return
fmt
.
Errorf
(
"written genesis.json different from returned by coreRandom"
)
}
gDoc
:=
MakeGenesisDocFromFile
(
path
.
Join
(
dirFlag
,
"genesis.json"
))
if
len
(
gDoc
.
Validators
)
!=
N
{
return
fmt
.
Errorf
(
"Expected %d validators. Got %d"
,
N
,
len
(
gDoc
.
Validators
))
}
privVal
:=
types
.
LoadPrivValidator
(
path
.
Join
(
dirFlag
,
"priv_validator.json"
))
if
!
bytes
.
Equal
(
privVal
.
Address
,
v
.
Address
)
{
return
fmt
.
Errorf
(
"priv_validator file contents different than result of coreRandom"
)
}
var
found
bool
for
_
,
val
:=
range
gDoc
.
Validators
{
if
bytes
.
Equal
(
val
.
UnbondTo
[
0
]
.
Address
,
privVal
.
Address
)
{
found
=
true
}
}
if
!
found
{
return
fmt
.
Errorf
(
"failed to find validator %d:%X in genesis.json"
,
i
,
v
.
Address
)
}
}
return
nil
}
func
TestRandom
(
t
*
testing
.
T
)
{
// make temp dir
dir
,
err
:=
ioutil
.
TempDir
(
os
.
TempDir
(),
"mintgen-test"
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
DirFlag
=
dir
defer
func
()
{
// cleanup
os
.
RemoveAll
(
DirFlag
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
}()
if
err
=
testCoreRandom
(
1
);
err
!=
nil
{
return
}
if
err
=
testCoreRandom
(
3
);
err
!=
nil
{
return
}
}
type
GenDoc
struct
{
pubkeys
[]
string
amts
[]
int
...
...
@@ -126,7 +55,7 @@ func csv1String() string {
for
i
,
pub
:=
range
csv1
.
pubkeys
{
buf
.
WriteString
(
fmt
.
Sprintf
(
"%s,%d,%s,%d,%d
\n
"
,
pub
,
csv1
.
amts
[
i
],
csv1
.
names
[
i
],
csv1
.
perms
[
i
],
csv1
.
setbits
[
i
]))
}
return
s
tring
(
buf
.
Bytes
()
)
return
buf
.
S
tring
()
}
func
csv2String
()
string
{
...
...
@@ -134,7 +63,7 @@ func csv2String() string {
for
_
,
pub
:=
range
csv2
.
pubkeys
{
buf
.
WriteString
(
fmt
.
Sprintf
(
"%s,
\n
"
,
pub
))
}
return
s
tring
(
buf
.
Bytes
()
)
return
buf
.
S
tring
()
}
func
testKnownCSV
(
csvFile
string
,
csv
GenDoc
)
error
{
...
...
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