mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-11 20:31:20 +00:00
fixes post merge
This commit is contained in:
@ -6,11 +6,11 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
amino "github.com/tendermint/go-amino"
|
amino "github.com/tendermint/go-amino"
|
||||||
crypto "github.com/tendermint/tendermint/crypto"
|
cryptoAmino "github.com/tendermint/tendermint/crypto/encoding/amino"
|
||||||
lerr "github.com/tendermint/tendermint/lite/errors"
|
|
||||||
"github.com/tendermint/tendermint/types"
|
|
||||||
dbm "github.com/tendermint/tendermint/libs/db"
|
dbm "github.com/tendermint/tendermint/libs/db"
|
||||||
log "github.com/tendermint/tendermint/libs/log"
|
log "github.com/tendermint/tendermint/libs/log"
|
||||||
|
lerr "github.com/tendermint/tendermint/lite/errors"
|
||||||
|
"github.com/tendermint/tendermint/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
type DBProvider struct {
|
type DBProvider struct {
|
||||||
@ -24,7 +24,7 @@ type DBProvider struct {
|
|||||||
func NewDBProvider(label string, db dbm.DB) *DBProvider {
|
func NewDBProvider(label string, db dbm.DB) *DBProvider {
|
||||||
//db = dbm.NewDebugDB("db provider "+cmn.RandStr(4), db)
|
//db = dbm.NewDebugDB("db provider "+cmn.RandStr(4), db)
|
||||||
cdc := amino.NewCodec()
|
cdc := amino.NewCodec()
|
||||||
crypto.RegisterAmino(cdc)
|
cryptoAmino.RegisterAmino(cdc)
|
||||||
dbp := &DBProvider{
|
dbp := &DBProvider{
|
||||||
logger: log.NewNopLogger(),
|
logger: log.NewNopLogger(),
|
||||||
label: label,
|
label: label,
|
||||||
|
@ -44,7 +44,7 @@ func (pkz privKeys) Extend(n int) privKeys {
|
|||||||
|
|
||||||
// GenSecpPrivKeys produces an array of secp256k1 private keys to generate commits.
|
// GenSecpPrivKeys produces an array of secp256k1 private keys to generate commits.
|
||||||
func GenSecpPrivKeys(n int) privKeys {
|
func GenSecpPrivKeys(n int) privKeys {
|
||||||
res := make(privKey, n)
|
res := make(privKeys, n)
|
||||||
for i := range res {
|
for i := range res {
|
||||||
res[i] = secp256k1.GenPrivKey()
|
res[i] = secp256k1.GenPrivKey()
|
||||||
}
|
}
|
||||||
@ -54,7 +54,7 @@ func GenSecpPrivKeys(n int) privKeys {
|
|||||||
// ExtendSecp adds n more secp256k1 keys (to remove, just take a slice).
|
// ExtendSecp adds n more secp256k1 keys (to remove, just take a slice).
|
||||||
func (pkz privKeys) ExtendSecp(n int) privKeys {
|
func (pkz privKeys) ExtendSecp(n int) privKeys {
|
||||||
extra := GenSecpPrivKeys(n)
|
extra := GenSecpPrivKeys(n)
|
||||||
return append(v, extra...)
|
return append(pkz, extra...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ToValidators produces a valset from the set of keys.
|
// ToValidators produces a valset from the set of keys.
|
||||||
|
@ -33,10 +33,7 @@ func TestValidateBlock(t *testing.T) {
|
|||||||
block: nil, wantErr: "non-nil Block",
|
block: nil, wantErr: "non-nil Block",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
block: &types.Block{}, wantErr: "nil Header",
|
block: &types.Block{}, wantErr: "unexpected empty SignedHeader",
|
||||||
},
|
|
||||||
{
|
|
||||||
block: &types.Block{Header: new(types.Header)}, wantErr: "unexpected empty SignedHeader",
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// Start Header.Height mismatch test
|
// Start Header.Height mismatch test
|
||||||
@ -115,11 +112,7 @@ func TestValidateBlockMeta(t *testing.T) {
|
|||||||
meta: nil, wantErr: "non-nil BlockMeta",
|
meta: nil, wantErr: "non-nil BlockMeta",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
meta: &types.BlockMeta{}, wantErr: "non-nil Header",
|
meta: &types.BlockMeta{}, wantErr: "unexpected empty SignedHeader",
|
||||||
},
|
|
||||||
{
|
|
||||||
meta: &types.BlockMeta{Header: new(types.Header)}, wantErr: "unexpected empty SignedHeader",
|
|
||||||
// meta: &types.BlockMeta{},
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// Start Header.Height mismatch test
|
// Start Header.Height mismatch test
|
||||||
|
@ -16,57 +16,58 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestValidatorSetBasic(t *testing.T) {
|
func TestValidatorSetBasic(t *testing.T) {
|
||||||
for _, vset := range []*ValidatorSet{NewValidatorSet([]*Validator{}), NewValidatorSet(nil)} {
|
assert.Panics(t, func() { NewValidatorSet([]*Validator{}) })
|
||||||
assert.Panics(t, func() { vset.IncrementAccum(1) })
|
|
||||||
|
|
||||||
assert.EqualValues(t, vset, vset.Copy())
|
vset := NewValidatorSet(nil)
|
||||||
assert.False(t, vset.HasAddress([]byte("some val")))
|
assert.Panics(t, func() { vset.IncrementAccum(1) })
|
||||||
idx, val := vset.GetByAddress([]byte("some val"))
|
|
||||||
assert.Equal(t, -1, idx)
|
|
||||||
assert.Nil(t, val)
|
|
||||||
addr, val := vset.GetByIndex(-100)
|
|
||||||
assert.Nil(t, addr)
|
|
||||||
assert.Nil(t, val)
|
|
||||||
addr, val = vset.GetByIndex(0)
|
|
||||||
assert.Nil(t, addr)
|
|
||||||
assert.Nil(t, val)
|
|
||||||
addr, val = vset.GetByIndex(100)
|
|
||||||
assert.Nil(t, addr)
|
|
||||||
assert.Nil(t, val)
|
|
||||||
assert.Zero(t, vset.Size())
|
|
||||||
assert.Equal(t, int64(0), vset.TotalVotingPower())
|
|
||||||
assert.Nil(t, vset.GetProposer())
|
|
||||||
assert.Nil(t, vset.Hash())
|
|
||||||
|
|
||||||
// add
|
assert.EqualValues(t, vset, vset.Copy())
|
||||||
val = randValidator_()
|
assert.False(t, vset.HasAddress([]byte("some val")))
|
||||||
assert.True(t, vset.Add(val))
|
idx, val := vset.GetByAddress([]byte("some val"))
|
||||||
assert.True(t, vset.HasAddress(val.Address))
|
assert.Equal(t, -1, idx)
|
||||||
idx, val2 := vset.GetByAddress(val.Address)
|
assert.Nil(t, val)
|
||||||
assert.Equal(t, 0, idx)
|
addr, val := vset.GetByIndex(-100)
|
||||||
assert.Equal(t, val, val2)
|
assert.Nil(t, addr)
|
||||||
addr, val2 = vset.GetByIndex(0)
|
assert.Nil(t, val)
|
||||||
assert.Equal(t, []byte(val.Address), addr)
|
addr, val = vset.GetByIndex(0)
|
||||||
assert.Equal(t, val, val2)
|
assert.Nil(t, addr)
|
||||||
assert.Equal(t, 1, vset.Size())
|
assert.Nil(t, val)
|
||||||
assert.Equal(t, val.VotingPower, vset.TotalVotingPower())
|
addr, val = vset.GetByIndex(100)
|
||||||
assert.Equal(t, val, vset.GetProposer())
|
assert.Nil(t, addr)
|
||||||
assert.NotNil(t, vset.Hash())
|
assert.Nil(t, val)
|
||||||
assert.NotPanics(t, func() { vset.IncrementAccum(1) })
|
assert.Zero(t, vset.Size())
|
||||||
|
assert.Equal(t, int64(0), vset.TotalVotingPower())
|
||||||
|
assert.Nil(t, vset.GetProposer())
|
||||||
|
assert.Nil(t, vset.Hash())
|
||||||
|
|
||||||
// update
|
// add
|
||||||
assert.False(t, vset.Update(randValidator_()))
|
val = randValidator_()
|
||||||
val.VotingPower = 100
|
assert.True(t, vset.Add(val))
|
||||||
assert.True(t, vset.Update(val))
|
assert.True(t, vset.HasAddress(val.Address))
|
||||||
|
idx, val2 := vset.GetByAddress(val.Address)
|
||||||
|
assert.Equal(t, 0, idx)
|
||||||
|
assert.Equal(t, val, val2)
|
||||||
|
addr, val2 = vset.GetByIndex(0)
|
||||||
|
assert.Equal(t, []byte(val.Address), addr)
|
||||||
|
assert.Equal(t, val, val2)
|
||||||
|
assert.Equal(t, 1, vset.Size())
|
||||||
|
assert.Equal(t, val.VotingPower, vset.TotalVotingPower())
|
||||||
|
assert.Equal(t, val, vset.GetProposer())
|
||||||
|
assert.NotNil(t, vset.Hash())
|
||||||
|
assert.NotPanics(t, func() { vset.IncrementAccum(1) })
|
||||||
|
|
||||||
// remove
|
// update
|
||||||
val2, removed := vset.Remove(randValidator_().Address)
|
assert.False(t, vset.Update(randValidator_()))
|
||||||
assert.Nil(t, val2)
|
val.VotingPower = 100
|
||||||
assert.False(t, removed)
|
assert.True(t, vset.Update(val))
|
||||||
val2, removed = vset.Remove(val.Address)
|
|
||||||
assert.Equal(t, val.Address, val2.Address)
|
// remove
|
||||||
assert.True(t, removed)
|
val2, removed := vset.Remove(randValidator_().Address)
|
||||||
}
|
assert.Nil(t, val2)
|
||||||
|
assert.False(t, removed)
|
||||||
|
val2, removed = vset.Remove(val.Address)
|
||||||
|
assert.Equal(t, val.Address, val2.Address)
|
||||||
|
assert.True(t, removed)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCopy(t *testing.T) {
|
func TestCopy(t *testing.T) {
|
||||||
|
Reference in New Issue
Block a user