Update testcases for TM 0.24.0-rc0
This commit is contained in:
parent
8f6c9e1b9a
commit
06adc691d2
@ -30,6 +30,10 @@ BREAKING CHANGES
|
||||
addresses, `cosmosconspub` and `cosmoscons` respectively.
|
||||
|
||||
* SDK
|
||||
* [core] \#2219 Update to Tendermint 0.24.0
|
||||
* Validator set updates delayed by one block
|
||||
* BFT timestamp that can safely be used by applications
|
||||
* Fixed maximum block size enforcement
|
||||
* [core] \#1807 Switch from use of rational to decimal
|
||||
* [types] \#1901 Validator interface's GetOwner() renamed to GetOperator()
|
||||
* [x/slashing] [#2122](https://github.com/cosmos/cosmos-sdk/pull/2122) - Implement slashing period
|
||||
|
||||
@ -31,7 +31,7 @@ func setGenesis(gapp *GaiaApp, accs ...*auth.BaseAccount) error {
|
||||
}
|
||||
|
||||
// Initialize the chain
|
||||
vals := []abci.Validator{}
|
||||
vals := []abci.ValidatorUpdate{}
|
||||
gapp.InitChain(abci.RequestInitChain{Validators: vals, AppStateBytes: stateBytes})
|
||||
gapp.Commit()
|
||||
|
||||
|
||||
@ -29,7 +29,7 @@ func setGenesis(baseApp *BasecoinApp, accounts ...*types.AppAccount) (types.Gene
|
||||
|
||||
// initialize and commit the chain
|
||||
baseApp.InitChain(abci.RequestInitChain{
|
||||
Validators: []abci.Validator{}, AppStateBytes: stateBytes,
|
||||
Validators: []abci.ValidatorUpdate{}, AppStateBytes: stateBytes,
|
||||
})
|
||||
baseApp.Commit()
|
||||
|
||||
@ -72,7 +72,7 @@ func TestGenesis(t *testing.T) {
|
||||
|
||||
// initialize the chain with the expected genesis state
|
||||
baseApp.InitChain(abci.RequestInitChain{
|
||||
Validators: []abci.Validator{}, AppStateBytes: stateBytes,
|
||||
Validators: []abci.ValidatorUpdate{}, AppStateBytes: stateBytes,
|
||||
})
|
||||
|
||||
ctx = baseApp.BaseApp.NewContext(true, abci.Header{})
|
||||
|
||||
@ -33,7 +33,7 @@ func setGenesis(bapp *DemocoinApp, trend string, accs ...auth.BaseAccount) error
|
||||
}
|
||||
|
||||
// Initialize the chain
|
||||
vals := []abci.Validator{}
|
||||
vals := []abci.ValidatorUpdate{}
|
||||
bapp.InitChain(abci.RequestInitChain{Validators: vals, AppStateBytes: stateBytes})
|
||||
bapp.Commit()
|
||||
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
@ -13,8 +14,8 @@ func newCacheKVStore() CacheKVStore {
|
||||
return NewCacheKVStore(mem)
|
||||
}
|
||||
|
||||
func keyFmt(i int) []byte { return bz(cmn.Fmt("key%0.8d", i)) }
|
||||
func valFmt(i int) []byte { return bz(cmn.Fmt("value%0.8d", i)) }
|
||||
func keyFmt(i int) []byte { return bz(fmt.Sprintf("key%0.8d", i)) }
|
||||
func valFmt(i int) []byte { return bz(fmt.Sprintf("value%0.8d", i)) }
|
||||
|
||||
func TestCacheKVStore(t *testing.T) {
|
||||
mem := dbStoreAdapter{dbm.NewMemDB()}
|
||||
|
||||
@ -387,12 +387,12 @@ func TestIAVLStoreQuery(t *testing.T) {
|
||||
ksub := []byte("key")
|
||||
KVs0 := []KVPair{}
|
||||
KVs1 := []KVPair{
|
||||
{k1, v1},
|
||||
{k2, v2},
|
||||
{Key: k1, Value: v1},
|
||||
{Key: k2, Value: v2},
|
||||
}
|
||||
KVs2 := []KVPair{
|
||||
{k1, v3},
|
||||
{k2, v2},
|
||||
{Key: k1, Value: v3},
|
||||
{Key: k2, Value: v2},
|
||||
}
|
||||
valExpSubEmpty := cdc.MustMarshalBinary(KVs0)
|
||||
valExpSub1 := cdc.MustMarshalBinary(KVs1)
|
||||
|
||||
@ -33,7 +33,12 @@ func initChain(r *rand.Rand, keys []crypto.PrivKey, accs []sdk.AccAddress, setup
|
||||
res := app.InitChain(abci.RequestInitChain{AppStateBytes: appStateFn(r, keys, accs)})
|
||||
validators = make(map[string]mockValidator)
|
||||
for _, validator := range res.Validators {
|
||||
validators[string(validator.Address)] = mockValidator{validator, GetMemberOfInitialState(r, initialLivenessWeightings)}
|
||||
pubkey, err := tmtypes.PB2TM.PubKey(validator.PubKey)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
address := pubkey.Address()
|
||||
validators[string(address)] = mockValidator{validator, GetMemberOfInitialState(r, initialLivenessWeightings)}
|
||||
}
|
||||
|
||||
for i := 0; i < len(setups); i++ {
|
||||
@ -91,7 +96,7 @@ func SimulateFromSeed(
|
||||
for i := 0; i < numBlocks; i++ {
|
||||
// Log the header time for future lookup
|
||||
pastTimes = append(pastTimes, header.Time)
|
||||
pastVoteInfos = append(pastVoteInfos, request.LastCommitInfo.Validators)
|
||||
pastVoteInfos = append(pastVoteInfos, request.LastCommitInfo.Votes)
|
||||
|
||||
// Run the BeginBlock handler
|
||||
app.BeginBlock(request)
|
||||
@ -271,8 +276,14 @@ func RandomRequestBeginBlock(r *rand.Rand, validators map[string]mockValidator,
|
||||
} else {
|
||||
event("beginblock/signing/missed")
|
||||
}
|
||||
pubkey, err := tmtypes.PB2TM.PubKey(mVal.val.PubKey)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
voteInfos[i] = abci.VoteInfo{
|
||||
Validator: mVal.val,
|
||||
Validator: abci.Validator{
|
||||
Address: pubkey.Address(),
|
||||
},
|
||||
SignedLastBlock: signed,
|
||||
}
|
||||
i++
|
||||
@ -308,7 +319,7 @@ func RandomRequestBeginBlock(r *rand.Rand, validators map[string]mockValidator,
|
||||
return abci.RequestBeginBlock{
|
||||
Header: header,
|
||||
LastCommitInfo: abci.LastCommitInfo{
|
||||
Validators: voteInfos,
|
||||
Votes: voteInfos,
|
||||
},
|
||||
ByzantineValidators: evidence,
|
||||
}
|
||||
@ -323,7 +334,7 @@ func AssertAllInvariants(t *testing.T, app *baseapp.BaseApp, tests []Invariant,
|
||||
|
||||
// updateValidators mimicks Tendermint's update logic
|
||||
// nolint: unparam
|
||||
func updateValidators(tb testing.TB, r *rand.Rand, current map[string]mockValidator, updates []abci.Validator, event func(string)) map[string]mockValidator {
|
||||
func updateValidators(tb testing.TB, r *rand.Rand, current map[string]mockValidator, updates []abci.ValidatorUpdate, event func(string)) map[string]mockValidator {
|
||||
for _, update := range updates {
|
||||
switch {
|
||||
case update.Power == 0:
|
||||
|
||||
@ -36,7 +36,7 @@ type (
|
||||
Invariant func(t *testing.T, app *baseapp.BaseApp, log string)
|
||||
|
||||
mockValidator struct {
|
||||
val abci.Validator
|
||||
val abci.ValidatorUpdate
|
||||
livenessState int
|
||||
}
|
||||
|
||||
|
||||
@ -32,7 +32,7 @@ func TestBeginBlocker(t *testing.T) {
|
||||
// mark the validator as having signed
|
||||
req := abci.RequestBeginBlock{
|
||||
LastCommitInfo: abci.LastCommitInfo{
|
||||
Validators: []abci.VoteInfo{{
|
||||
Votes: []abci.VoteInfo{{
|
||||
Validator: val,
|
||||
SignedLastBlock: true,
|
||||
}},
|
||||
@ -54,7 +54,7 @@ func TestBeginBlocker(t *testing.T) {
|
||||
ctx = ctx.WithBlockHeight(height)
|
||||
req = abci.RequestBeginBlock{
|
||||
LastCommitInfo: abci.LastCommitInfo{
|
||||
Validators: []abci.VoteInfo{{
|
||||
Votes: []abci.VoteInfo{{
|
||||
Validator: val,
|
||||
SignedLastBlock: true,
|
||||
}},
|
||||
@ -68,7 +68,7 @@ func TestBeginBlocker(t *testing.T) {
|
||||
ctx = ctx.WithBlockHeight(height)
|
||||
req = abci.RequestBeginBlock{
|
||||
LastCommitInfo: abci.LastCommitInfo{
|
||||
Validators: []abci.VoteInfo{{
|
||||
Votes: []abci.VoteInfo{{
|
||||
Validator: val,
|
||||
SignedLastBlock: false,
|
||||
}},
|
||||
|
||||
@ -47,7 +47,7 @@ func TestSetValidator(t *testing.T) {
|
||||
|
||||
updates := keeper.GetTendermintUpdates(ctx)
|
||||
require.Equal(t, 1, len(updates))
|
||||
require.Equal(t, validator.ABCIValidator(), updates[0])
|
||||
require.Equal(t, validator.ABCIValidatorUpdate(), updates[0])
|
||||
}
|
||||
|
||||
func TestUpdateValidatorByPowerIndex(t *testing.T) {
|
||||
@ -674,8 +674,8 @@ func TestGetTendermintUpdatesAllNone(t *testing.T) {
|
||||
|
||||
updates := keeper.GetTendermintUpdates(ctx)
|
||||
assert.Equal(t, 2, len(updates))
|
||||
assert.Equal(t, validators[0].ABCIValidator(), updates[0])
|
||||
assert.Equal(t, validators[1].ABCIValidator(), updates[1])
|
||||
assert.Equal(t, validators[0].ABCIValidatorUpdate(), updates[0])
|
||||
assert.Equal(t, validators[1].ABCIValidatorUpdate(), updates[1])
|
||||
|
||||
// test from something to nothing
|
||||
// tendermintUpdate set: {} -> {c1, c2, c3, c4}
|
||||
@ -741,7 +741,7 @@ func TestGetTendermintUpdatesSingleValueChange(t *testing.T) {
|
||||
updates := keeper.GetTendermintUpdates(ctx)
|
||||
|
||||
require.Equal(t, 1, len(updates))
|
||||
require.Equal(t, validators[0].ABCIValidator(), updates[0])
|
||||
require.Equal(t, validators[0].ABCIValidatorUpdate(), updates[0])
|
||||
}
|
||||
|
||||
func TestGetTendermintUpdatesMultipleValueChange(t *testing.T) {
|
||||
@ -771,8 +771,8 @@ func TestGetTendermintUpdatesMultipleValueChange(t *testing.T) {
|
||||
|
||||
updates := keeper.GetTendermintUpdates(ctx)
|
||||
require.Equal(t, 2, len(updates))
|
||||
require.Equal(t, validators[0].ABCIValidator(), updates[0])
|
||||
require.Equal(t, validators[1].ABCIValidator(), updates[1])
|
||||
require.Equal(t, validators[0].ABCIValidatorUpdate(), updates[0])
|
||||
require.Equal(t, validators[1].ABCIValidatorUpdate(), updates[1])
|
||||
}
|
||||
|
||||
func TestGetTendermintUpdatesInserted(t *testing.T) {
|
||||
@ -796,7 +796,7 @@ func TestGetTendermintUpdatesInserted(t *testing.T) {
|
||||
validators[2] = keeper.UpdateValidator(ctx, validators[2])
|
||||
updates := keeper.GetTendermintUpdates(ctx)
|
||||
require.Equal(t, 1, len(updates))
|
||||
require.Equal(t, validators[2].ABCIValidator(), updates[0])
|
||||
require.Equal(t, validators[2].ABCIValidatorUpdate(), updates[0])
|
||||
|
||||
// test validtor added at the beginning
|
||||
// tendermintUpdate set: {} -> {c0}
|
||||
@ -804,7 +804,7 @@ func TestGetTendermintUpdatesInserted(t *testing.T) {
|
||||
validators[3] = keeper.UpdateValidator(ctx, validators[3])
|
||||
updates = keeper.GetTendermintUpdates(ctx)
|
||||
require.Equal(t, 1, len(updates))
|
||||
require.Equal(t, validators[3].ABCIValidator(), updates[0])
|
||||
require.Equal(t, validators[3].ABCIValidatorUpdate(), updates[0])
|
||||
|
||||
// test validtor added at the end
|
||||
// tendermintUpdate set: {} -> {c0}
|
||||
@ -812,7 +812,7 @@ func TestGetTendermintUpdatesInserted(t *testing.T) {
|
||||
validators[4] = keeper.UpdateValidator(ctx, validators[4])
|
||||
updates = keeper.GetTendermintUpdates(ctx)
|
||||
require.Equal(t, 1, len(updates))
|
||||
require.Equal(t, validators[4].ABCIValidator(), updates[0])
|
||||
require.Equal(t, validators[4].ABCIValidatorUpdate(), updates[0])
|
||||
}
|
||||
|
||||
func TestGetTendermintUpdatesWithCliffValidator(t *testing.T) {
|
||||
@ -852,8 +852,8 @@ func TestGetTendermintUpdatesWithCliffValidator(t *testing.T) {
|
||||
|
||||
updates = keeper.GetTendermintUpdates(ctx)
|
||||
require.Equal(t, 2, len(updates), "%v", updates)
|
||||
require.Equal(t, validators[0].ABCIValidatorZero(), updates[0])
|
||||
require.Equal(t, validators[2].ABCIValidator(), updates[1])
|
||||
require.Equal(t, validators[0].ABCIValidatorUpdateZero(), updates[0])
|
||||
require.Equal(t, validators[2].ABCIValidatorUpdate(), updates[1])
|
||||
}
|
||||
|
||||
func TestGetTendermintUpdatesPowerDecrease(t *testing.T) {
|
||||
@ -892,6 +892,6 @@ func TestGetTendermintUpdatesPowerDecrease(t *testing.T) {
|
||||
// Tendermint updates should reflect power change
|
||||
updates := keeper.GetTendermintUpdates(ctx)
|
||||
require.Equal(t, 2, len(updates))
|
||||
require.Equal(t, validators[0].ABCIValidator(), updates[0])
|
||||
require.Equal(t, validators[1].ABCIValidator(), updates[1])
|
||||
require.Equal(t, validators[0].ABCIValidatorUpdate(), updates[0])
|
||||
require.Equal(t, validators[1].ABCIValidatorUpdate(), updates[1])
|
||||
}
|
||||
|
||||
@ -317,8 +317,17 @@ func (v Validator) ABCIValidator() abci.Validator {
|
||||
}
|
||||
}
|
||||
|
||||
// ABCIValidatorUpdate returns an abci.ValidatorUpdate from a staked validator type
|
||||
// with the full validator power
|
||||
func (v Validator) ABCIValidatorUpdate() abci.ValidatorUpdate {
|
||||
return abci.ValidatorUpdate{
|
||||
PubKey: tmtypes.TM2PB.PubKey(v.PubKey),
|
||||
Power: v.BondedTokens().RoundInt64(),
|
||||
}
|
||||
}
|
||||
|
||||
// ABCIValidatorUpdateZero returns an abci.ValidatorUpdate from a staked validator type
|
||||
// with with zero power used for validator updates.
|
||||
// with zero power used for validator updates.
|
||||
func (v Validator) ABCIValidatorUpdateZero() abci.ValidatorUpdate {
|
||||
return abci.ValidatorUpdate{
|
||||
PubKey: tmtypes.TM2PB.PubKey(v.PubKey),
|
||||
|
||||
@ -57,14 +57,14 @@ func TestABCIValidator(t *testing.T) {
|
||||
validator := NewValidator(addr1, pk1, Description{})
|
||||
|
||||
abciVal := validator.ABCIValidator()
|
||||
require.Equal(t, tmtypes.TM2PB.PubKey(validator.PubKey), abciVal.PubKey)
|
||||
require.Equal(t, addr1, sdk.ValAddress(abciVal.Address))
|
||||
require.Equal(t, validator.BondedTokens().RoundInt64(), abciVal.Power)
|
||||
}
|
||||
|
||||
func TestABCIValidatorZero(t *testing.T) {
|
||||
func TestABCIValidatorUpdateZero(t *testing.T) {
|
||||
validator := NewValidator(addr1, pk1, Description{})
|
||||
|
||||
abciVal := validator.ABCIValidatorZero()
|
||||
abciVal := validator.ABCIValidatorUpdateZero()
|
||||
require.Equal(t, tmtypes.TM2PB.PubKey(validator.PubKey), abciVal.PubKey)
|
||||
require.Equal(t, int64(0), abciVal.Power)
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user