feat!: Comet v0.38 Integration (#15519)

Co-authored-by: marbar3778 <marbar3778@yahoo.com>
Co-authored-by: cool-developer <51834436+cool-develope@users.noreply.github.com>
Co-authored-by: Aaron Craelius <aaron@regen.network>
Co-authored-by: Matt Kocubinski <mkocubinski@gmail.com>
Co-authored-by: Julien Robert <julien@rbrt.fr>
This commit is contained in:
Aleksandr Bezobchuk
2023-05-24 16:09:19 +00:00
committed by GitHub
co-authored by marbar3778 cool-developer Aaron Craelius Matt Kocubinski Julien Robert
parent 166be3766b
commit 6cee22df52
148 changed files with 14747 additions and 15262 deletions
@@ -116,7 +116,7 @@ func initFixture(t testing.TB) *fixture {
Address: valAddr,
Power: 100,
},
SignedLastBlock: true,
BlockIdFlag: types.BlockIDFlagCommit,
},
})
@@ -268,7 +268,7 @@ func TestMsgWithdrawDelegatorReward(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
res, err := f.app.RunMsg(
tc.msg,
integration.WithAutomaticBeginEndBlock(),
integration.WithAutomaticFinalizeBlock(),
integration.WithAutomaticCommit(),
)
@@ -417,7 +417,7 @@ func TestMsgSetWithdrawAddress(t *testing.T) {
tc.preRun()
res, err := f.app.RunMsg(
tc.msg,
integration.WithAutomaticBeginEndBlock(),
integration.WithAutomaticFinalizeBlock(),
integration.WithAutomaticCommit(),
)
if tc.expErr {
@@ -510,7 +510,7 @@ func TestMsgWithdrawValidatorCommission(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
res, err := f.app.RunMsg(
tc.msg,
integration.WithAutomaticBeginEndBlock(),
integration.WithAutomaticFinalizeBlock(),
integration.WithAutomaticCommit(),
)
if tc.expErr {
@@ -612,7 +612,7 @@ func TestMsgFundCommunityPool(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
res, err := f.app.RunMsg(
tc.msg,
integration.WithAutomaticBeginEndBlock(),
integration.WithAutomaticFinalizeBlock(),
integration.WithAutomaticCommit(),
)
if tc.expErr {
@@ -739,7 +739,7 @@ func TestMsgUpdateParams(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
res, err := f.app.RunMsg(
tc.msg,
integration.WithAutomaticBeginEndBlock(),
integration.WithAutomaticFinalizeBlock(),
integration.WithAutomaticCommit(),
)
if tc.expErr {
@@ -817,7 +817,7 @@ func TestMsgCommunityPoolSpend(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
res, err := f.app.RunMsg(
tc.msg,
integration.WithAutomaticBeginEndBlock(),
integration.WithAutomaticFinalizeBlock(),
integration.WithAutomaticCommit(),
)
if tc.expErr {
@@ -914,7 +914,7 @@ func TestMsgDepositValidatorRewardsPool(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
res, err := f.app.RunMsg(
tc.msg,
integration.WithAutomaticBeginEndBlock(),
integration.WithAutomaticFinalizeBlock(),
integration.WithAutomaticCommit(),
)
if tc.expErr {
@@ -184,13 +184,13 @@ func TestHandleDoubleSign(t *testing.T) {
f.slashingKeeper.SetValidatorSigningInfo(f.sdkCtx, sdk.ConsAddress(val.Address()), info)
// handle a signature to set signing info
f.slashingKeeper.HandleValidatorSignature(ctx, val.Address(), selfDelegation.Int64(), true)
f.slashingKeeper.HandleValidatorSignature(ctx, val.Address(), selfDelegation.Int64(), comet.BlockIDFlagCommit)
// double sign less than max age
oldTokens := f.stakingKeeper.Validator(ctx, operatorAddr).GetTokens()
nci := NewCometInfo(abci.RequestBeginBlock{
ByzantineValidators: []abci.Misbehavior{{
nci := NewCometInfo(abci.RequestFinalizeBlock{
Misbehavior: []abci.Misbehavior{{
Validator: abci.Validator{Address: val.Address(), Power: power},
Type: abci.MisbehaviorType_DUPLICATE_VOTE,
Time: time.Now().UTC(),
@@ -259,8 +259,8 @@ func TestHandleDoubleSign_TooOld(t *testing.T) {
)
assert.DeepEqual(t, amt, f.stakingKeeper.Validator(ctx, operatorAddr).GetBondedTokens())
nci := NewCometInfo(abci.RequestBeginBlock{
ByzantineValidators: []abci.Misbehavior{{
nci := NewCometInfo(abci.RequestFinalizeBlock{
Misbehavior: []abci.Misbehavior{{
Validator: abci.Validator{Address: val.Address(), Power: power},
Type: abci.MisbehaviorType_DUPLICATE_VOTE,
Time: ctx.BlockTime(),
@@ -326,9 +326,9 @@ type CometService struct {
Evidence []abci.Misbehavior
}
func NewCometInfo(bg abci.RequestBeginBlock) comet.BlockInfo {
func NewCometInfo(bg abci.RequestFinalizeBlock) comet.BlockInfo {
return CometService{
Evidence: bg.ByzantineValidators,
Evidence: bg.Misbehavior,
}
}
+14 -13
View File
@@ -75,8 +75,9 @@ func TestImportExportQueues(t *testing.T) {
ctx := s1.app.BaseApp.NewContext(false, cmtproto.Header{})
addrs := simtestutil.AddTestAddrs(s1.BankKeeper, s1.StakingKeeper, ctx, 1, valTokens)
header := cmtproto.Header{Height: s1.app.LastBlockHeight() + 1}
s1.app.BeginBlock(abci.RequestBeginBlock{Header: header})
s1.app.FinalizeBlock(&abci.RequestFinalizeBlock{
Height: s1.app.LastBlockHeight() + 1,
})
ctx = s1.app.BaseApp.NewContext(false, cmtproto.Header{})
// Create two proposals, put the second into the voting period
@@ -130,19 +131,19 @@ func TestImportExportQueues(t *testing.T) {
)
assert.NilError(t, err)
s2.app.InitChain(
abci.RequestInitChain{
Validators: []abci.ValidatorUpdate{},
ConsensusParams: simtestutil.DefaultConsensusParams,
AppStateBytes: stateBytes,
},
)
s2.app.InitChain(&abci.RequestInitChain{
Validators: []abci.ValidatorUpdate{},
ConsensusParams: simtestutil.DefaultConsensusParams,
AppStateBytes: stateBytes,
})
s2.app.Commit()
s2.app.BeginBlock(abci.RequestBeginBlock{Header: cmtproto.Header{Height: s2.app.LastBlockHeight() + 1}})
s2.app.FinalizeBlock(&abci.RequestFinalizeBlock{
Height: s2.app.LastBlockHeight() + 1,
})
header = cmtproto.Header{Height: s2.app.LastBlockHeight() + 1}
s2.app.BeginBlock(abci.RequestBeginBlock{Header: header})
s2.app.FinalizeBlock(&abci.RequestFinalizeBlock{
Height: s2.app.LastBlockHeight() + 1,
})
ctx2 := s2.app.BaseApp.NewContext(false, cmtproto.Header{})
@@ -4,6 +4,7 @@ import (
"testing"
"time"
"cosmossdk.io/core/comet"
"cosmossdk.io/log"
storetypes "cosmossdk.io/store/types"
@@ -179,7 +180,7 @@ func TestUnJailNotBonded(t *testing.T) {
}
_, err = f.app.RunMsg(
&msgUnjail,
integration.WithAutomaticBeginEndBlock(),
integration.WithAutomaticFinalizeBlock(),
integration.WithAutomaticCommit(),
)
assert.ErrorContains(t, err, "cannot be unjailed")
@@ -195,7 +196,7 @@ func TestUnJailNotBonded(t *testing.T) {
// verify we can immediately unjail
_, err = f.app.RunMsg(
&msgUnjail,
integration.WithAutomaticBeginEndBlock(),
integration.WithAutomaticFinalizeBlock(),
integration.WithAutomaticCommit(),
)
assert.NilError(t, err)
@@ -231,9 +232,9 @@ func TestHandleNewValidator(t *testing.T) {
assert.DeepEqual(t, amt, f.stakingKeeper.Validator(f.ctx, addr).GetBondedTokens())
// Now a validator, for two blocks
f.slashingKeeper.HandleValidatorSignature(f.ctx, val.Address(), 100, true)
f.slashingKeeper.HandleValidatorSignature(f.ctx, val.Address(), 100, comet.BlockIDFlagCommit)
f.ctx = f.ctx.WithBlockHeight(f.slashingKeeper.SignedBlocksWindow(f.ctx) + 2)
f.slashingKeeper.HandleValidatorSignature(f.ctx, val.Address(), 100, false)
f.slashingKeeper.HandleValidatorSignature(f.ctx, val.Address(), 100, comet.BlockIDFlagAbsent)
info, found := f.slashingKeeper.GetValidatorSigningInfo(f.ctx, sdk.ConsAddress(val.Address()))
assert.Assert(t, found)
@@ -274,13 +275,13 @@ func TestHandleAlreadyJailed(t *testing.T) {
height := int64(0)
for ; height < f.slashingKeeper.SignedBlocksWindow(f.ctx); height++ {
f.ctx = f.ctx.WithBlockHeight(height)
f.slashingKeeper.HandleValidatorSignature(f.ctx, val.Address(), power, true)
f.slashingKeeper.HandleValidatorSignature(f.ctx, val.Address(), power, comet.BlockIDFlagCommit)
}
// 501 blocks missed
for ; height < f.slashingKeeper.SignedBlocksWindow(f.ctx)+(f.slashingKeeper.SignedBlocksWindow(f.ctx)-f.slashingKeeper.MinSignedPerWindow(f.ctx))+1; height++ {
f.ctx = f.ctx.WithBlockHeight(height)
f.slashingKeeper.HandleValidatorSignature(f.ctx, val.Address(), power, false)
f.slashingKeeper.HandleValidatorSignature(f.ctx, val.Address(), power, comet.BlockIDFlagAbsent)
}
// end block
@@ -296,7 +297,7 @@ func TestHandleAlreadyJailed(t *testing.T) {
// another block missed
f.ctx = f.ctx.WithBlockHeight(height)
f.slashingKeeper.HandleValidatorSignature(f.ctx, val.Address(), power, false)
f.slashingKeeper.HandleValidatorSignature(f.ctx, val.Address(), power, comet.BlockIDFlagAbsent)
// validator should not have been slashed twice
validator, _ = f.stakingKeeper.GetValidatorByConsAddr(f.ctx, sdk.GetConsAddress(val))
@@ -338,7 +339,7 @@ func TestValidatorDippingInAndOut(t *testing.T) {
height := int64(0)
for ; height < int64(100); height++ {
f.ctx = f.ctx.WithBlockHeight(height)
f.slashingKeeper.HandleValidatorSignature(f.ctx, val.Address(), power, true)
f.slashingKeeper.HandleValidatorSignature(f.ctx, val.Address(), power, comet.BlockIDFlagCommit)
}
// kick first validator out of validator set
@@ -363,7 +364,7 @@ func TestValidatorDippingInAndOut(t *testing.T) {
newPower := power + 50
// validator misses a block
f.slashingKeeper.HandleValidatorSignature(f.ctx, val.Address(), newPower, false)
f.slashingKeeper.HandleValidatorSignature(f.ctx, val.Address(), newPower, comet.BlockIDFlagAbsent)
height++
// shouldn't be jailed/kicked yet
@@ -374,7 +375,7 @@ func TestValidatorDippingInAndOut(t *testing.T) {
// misses 500 blocks + within the signing windows i.e. 700-1700
// validators misses all 1000 blocks of a SignedBlockWindows
for ; height < latest+1; height++ {
f.slashingKeeper.HandleValidatorSignature(f.ctx.WithBlockHeight(height), val.Address(), newPower, false)
f.slashingKeeper.HandleValidatorSignature(f.ctx.WithBlockHeight(height), val.Address(), newPower, comet.BlockIDFlagAbsent)
}
// should now be jailed & kicked
@@ -401,7 +402,7 @@ func TestValidatorDippingInAndOut(t *testing.T) {
// validator rejoins and starts signing again
f.stakingKeeper.Unjail(f.ctx, consAddr)
f.slashingKeeper.HandleValidatorSignature(f.ctx, val.Address(), newPower, true)
f.slashingKeeper.HandleValidatorSignature(f.ctx, val.Address(), newPower, comet.BlockIDFlagCommit)
// validator should not be kicked since we reset counter/array when it was jailed
f.stakingKeeper.EndBlocker(f.ctx)
@@ -416,7 +417,7 @@ func TestValidatorDippingInAndOut(t *testing.T) {
latest = f.slashingKeeper.SignedBlocksWindow(f.ctx) + height
for ; height < latest+f.slashingKeeper.MinSignedPerWindow(f.ctx); height++ {
f.ctx = f.ctx.WithBlockHeight(height)
f.slashingKeeper.HandleValidatorSignature(f.ctx, val.Address(), newPower, false)
f.slashingKeeper.HandleValidatorSignature(f.ctx, val.Address(), newPower, comet.BlockIDFlagAbsent)
}
// validator should now be jailed & kicked
@@ -22,7 +22,6 @@ func TestRollback(t *testing.T) {
AppOpts: simtestutil.NewAppOptionsWithFlagHome(t.TempDir()),
}
app := simapp.NewSimappWithCustomOptions(t, false, options)
app.Commit()
ver0 := app.LastBlockHeight()
// commit 10 blocks
for i := int64(1); i <= 10; i++ {
@@ -30,10 +29,16 @@ func TestRollback(t *testing.T) {
Height: ver0 + i,
AppHash: app.LastCommitID().Hash,
}
app.BeginBlock(abci.RequestBeginBlock{Header: header})
app.FinalizeBlock(&abci.RequestFinalizeBlock{
Height: header.Height,
})
ctx := app.NewContext(false, header)
store := ctx.KVStore(app.GetKey("bank"))
store.Set([]byte("key"), []byte(fmt.Sprintf("value%d", i)))
app.FinalizeBlock(&abci.RequestFinalizeBlock{
Height: header.Height,
})
app.Commit()
}
@@ -57,10 +62,13 @@ func TestRollback(t *testing.T) {
Height: ver0 + i,
AppHash: app.LastCommitID().Hash,
}
app.BeginBlock(abci.RequestBeginBlock{Header: header})
app.FinalizeBlock(&abci.RequestFinalizeBlock{Height: header.Height})
ctx := app.NewContext(false, header)
store := ctx.KVStore(app.GetKey("bank"))
store.Set([]byte("key"), []byte(fmt.Sprintf("VALUE%d", i)))
app.FinalizeBlock(&abci.RequestFinalizeBlock{
Height: header.Height,
})
app.Commit()
}