mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-14 13:51:21 +00:00
Moved RandVal into test helper functions, as needed in other repos for testing
This commit is contained in:
@ -10,7 +10,6 @@ import (
|
|||||||
abcicli "github.com/tendermint/abci/client"
|
abcicli "github.com/tendermint/abci/client"
|
||||||
"github.com/tendermint/abci/server"
|
"github.com/tendermint/abci/server"
|
||||||
"github.com/tendermint/abci/types"
|
"github.com/tendermint/abci/types"
|
||||||
crypto "github.com/tendermint/go-crypto"
|
|
||||||
"github.com/tendermint/iavl"
|
"github.com/tendermint/iavl"
|
||||||
cmn "github.com/tendermint/tmlibs/common"
|
cmn "github.com/tendermint/tmlibs/common"
|
||||||
"github.com/tendermint/tmlibs/log"
|
"github.com/tendermint/tmlibs/log"
|
||||||
@ -79,10 +78,9 @@ func TestPersistentDummyInfo(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
dummy := NewPersistentDummyApplication(dir)
|
dummy := NewPersistentDummyApplication(dir)
|
||||||
|
InitDummy(dummy)
|
||||||
height := uint64(0)
|
height := uint64(0)
|
||||||
|
|
||||||
dummy.InitChain(types.RequestInitChain{[]*types.Validator{randVal(0)}})
|
|
||||||
|
|
||||||
resInfo := dummy.Info(types.RequestInfo{})
|
resInfo := dummy.Info(types.RequestInfo{})
|
||||||
if resInfo.LastBlockHeight != height {
|
if resInfo.LastBlockHeight != height {
|
||||||
t.Fatalf("expected height of %d, got %d", height, resInfo.LastBlockHeight)
|
t.Fatalf("expected height of %d, got %d", height, resInfo.LastBlockHeight)
|
||||||
@ -105,12 +103,6 @@ func TestPersistentDummyInfo(t *testing.T) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func randVal(i int) *types.Validator {
|
|
||||||
pubkey := crypto.GenPrivKeyEd25519FromSecret([]byte(cmn.Fmt("test%d", i))).PubKey().Bytes()
|
|
||||||
power := cmn.RandInt()
|
|
||||||
return &types.Validator{pubkey, uint64(power)}
|
|
||||||
}
|
|
||||||
|
|
||||||
// add a validator, remove a validator, update a validator
|
// add a validator, remove a validator, update a validator
|
||||||
func TestValSetChanges(t *testing.T) {
|
func TestValSetChanges(t *testing.T) {
|
||||||
dir, err := ioutil.TempDir("/tmp", "abci-dummy-test") // TODO
|
dir, err := ioutil.TempDir("/tmp", "abci-dummy-test") // TODO
|
||||||
@ -122,10 +114,7 @@ func TestValSetChanges(t *testing.T) {
|
|||||||
// init with some validators
|
// init with some validators
|
||||||
total := 10
|
total := 10
|
||||||
nInit := 5
|
nInit := 5
|
||||||
vals := make([]*types.Validator, total)
|
vals := RandVals(total)
|
||||||
for i := 0; i < total; i++ {
|
|
||||||
vals[i] = randVal(i)
|
|
||||||
}
|
|
||||||
// iniitalize with the first nInit
|
// iniitalize with the first nInit
|
||||||
dummy.InitChain(types.RequestInitChain{vals[:nInit]})
|
dummy.InitChain(types.RequestInitChain{vals[:nInit]})
|
||||||
|
|
||||||
|
34
example/dummy/helpers.go
Normal file
34
example/dummy/helpers.go
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
package dummy
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/tendermint/abci/types"
|
||||||
|
crypto "github.com/tendermint/go-crypto"
|
||||||
|
cmn "github.com/tendermint/tmlibs/common"
|
||||||
|
)
|
||||||
|
|
||||||
|
// RandVal creates one random validator, with a key derived
|
||||||
|
// from the input value
|
||||||
|
func RandVal(i int) *types.Validator {
|
||||||
|
pubkey := crypto.GenPrivKeyEd25519FromSecret([]byte(cmn.Fmt("test%d", i))).PubKey().Bytes()
|
||||||
|
power := cmn.RandUint16() + 1
|
||||||
|
return &types.Validator{pubkey, uint64(power)}
|
||||||
|
}
|
||||||
|
|
||||||
|
// RandVals returns a list of cnt validators for initializing
|
||||||
|
// the application. Note that the keys are deterministically
|
||||||
|
// derived from the index in the array, while the power is
|
||||||
|
// random (Change this if not desired)
|
||||||
|
func RandVals(cnt int) []*types.Validator {
|
||||||
|
res := make([]*types.Validator, cnt)
|
||||||
|
for i := 0; i < cnt; i++ {
|
||||||
|
res[i] = RandVal(i)
|
||||||
|
}
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
|
// InitDummy initializes the dummy app with some data,
|
||||||
|
// which allows tests to pass and is fine as long as you
|
||||||
|
// don't make any tx that modify the validator state
|
||||||
|
func InitDummy(app *PersistentDummyApplication) {
|
||||||
|
app.InitChain(types.RequestInitChain{RandVals(1)})
|
||||||
|
}
|
Reference in New Issue
Block a user