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
+6 -5
View File
@@ -17,6 +17,7 @@ import (
bam "github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
sdk "github.com/cosmos/cosmos-sdk/types"
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
)
@@ -24,7 +25,7 @@ import (
// NewApp creates a simple mock kvstore app for testing. It should work
// similar to a real app. Make sure rootDir is empty before running the test,
// in order to guarantee consistent results.
func NewApp(rootDir string, logger log.Logger) (abci.Application, error) {
func NewApp(rootDir string, logger log.Logger) (servertypes.ABCI, error) {
db, err := db.NewGoLevelDB("mock", filepath.Join(rootDir, "data"), nil)
if err != nil {
return nil, err
@@ -96,21 +97,21 @@ type GenesisJSON struct {
// InitChainer returns a function that can initialize the chain
// with key/value pairs
func InitChainer(key storetypes.StoreKey) func(sdk.Context, abci.RequestInitChain) (abci.ResponseInitChain, error) {
return func(ctx sdk.Context, req abci.RequestInitChain) (abci.ResponseInitChain, error) {
func InitChainer(key storetypes.StoreKey) func(sdk.Context, *abci.RequestInitChain) (*abci.ResponseInitChain, error) {
return func(ctx sdk.Context, req *abci.RequestInitChain) (*abci.ResponseInitChain, error) {
stateJSON := req.AppStateBytes
genesisState := new(GenesisJSON)
err := json.Unmarshal(stateJSON, genesisState)
if err != nil {
return abci.ResponseInitChain{}, err
return &abci.ResponseInitChain{}, err
}
for _, val := range genesisState.Values {
store := ctx.KVStore(key)
store.Set([]byte(val.Key), []byte(val.Value))
}
return abci.ResponseInitChain{}, nil
return &abci.ResponseInitChain{}, nil
}
}
+22 -16
View File
@@ -1,22 +1,23 @@
package mock
import (
"context"
"math/rand"
"testing"
"time"
"cosmossdk.io/log"
abci "github.com/cometbft/cometbft/abci/types"
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
"github.com/stretchr/testify/require"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
)
// SetupApp initializes a new application,
// failing t if initialization fails.
func SetupApp(t *testing.T) abci.Application {
func SetupApp(t *testing.T) servertypes.ABCI {
t.Helper()
logger := log.NewTestLogger(t)
@@ -38,7 +39,12 @@ func TestInitApp(t *testing.T) {
req := abci.RequestInitChain{
AppStateBytes: appState,
}
app.InitChain(req)
res, err := app.InitChain(&req)
require.NoError(t, err)
app.FinalizeBlock(&abci.RequestFinalizeBlock{
Hash: res.AppHash,
Height: 1,
})
app.Commit()
// make sure we can query these values
@@ -47,7 +53,8 @@ func TestInitApp(t *testing.T) {
Data: []byte("foo"),
}
qres := app.Query(query)
qres, err := app.Query(context.Background(), &query)
require.NoError(t, err)
require.Equal(t, uint32(0), qres.Code, qres.Log)
require.Equal(t, []byte("bar"), qres.Value)
}
@@ -64,18 +71,16 @@ func TestDeliverTx(t *testing.T) {
tx := NewTx(key, value, randomAccounts[0].Address)
txBytes := tx.GetSignBytes()
app.BeginBlock(abci.RequestBeginBlock{Header: cmtproto.Header{
AppHash: []byte("apphash"),
Height: 1,
}})
res, err := app.FinalizeBlock(&abci.RequestFinalizeBlock{
Hash: []byte("apphash"),
Height: 1,
Txs: [][]byte{txBytes},
})
require.NoError(t, err)
require.NotEmpty(t, res.AppHash)
dres := app.DeliverTx(abci.RequestDeliverTx{Tx: txBytes})
require.Equal(t, uint32(0), dres.Code, dres.Log)
app.EndBlock(abci.RequestEndBlock{})
cres := app.Commit()
require.NotEmpty(t, cres.Data)
_, err = app.Commit()
require.NoError(t, err)
// make sure we can query these values
query := abci.RequestQuery{
@@ -83,7 +88,8 @@ func TestDeliverTx(t *testing.T) {
Data: []byte(key),
}
qres := app.Query(query)
qres, err := app.Query(context.Background(), &query)
require.NoError(t, err)
require.Equal(t, uint32(0), qres.Code, qres.Log)
require.Equal(t, []byte(value), qres.Value)
}