OSDN Git Service

new repo
[bytom/vapor.git] / vendor / github.com / tendermint / abci / example / dummy / helpers.go
1 package dummy
2
3 import (
4         "github.com/tendermint/abci/types"
5         crypto "github.com/tendermint/go-crypto"
6         cmn "github.com/tendermint/tmlibs/common"
7 )
8
9 // RandVal creates one random validator, with a key derived
10 // from the input value
11 func RandVal(i int) *types.Validator {
12         pubkey := crypto.GenPrivKeyEd25519FromSecret([]byte(cmn.Fmt("test%d", i))).PubKey().Bytes()
13         power := cmn.RandUint16() + 1
14         return &types.Validator{pubkey, uint64(power)}
15 }
16
17 // RandVals returns a list of cnt validators for initializing
18 // the application. Note that the keys are deterministically
19 // derived from the index in the array, while the power is
20 // random (Change this if not desired)
21 func RandVals(cnt int) []*types.Validator {
22         res := make([]*types.Validator, cnt)
23         for i := 0; i < cnt; i++ {
24                 res[i] = RandVal(i)
25         }
26         return res
27 }
28
29 // InitDummy initializes the dummy app with some data,
30 // which allows tests to pass and is fine as long as you
31 // don't make any tx that modify the validator state
32 func InitDummy(app *PersistentDummyApplication) {
33         app.InitChain(types.RequestInitChain{RandVals(1)})
34 }