refactor(server)!: continue server v1 removal (#23238)

This commit is contained in:
Julien Robert
2025-01-08 12:18:19 +00:00
committed by GitHub
parent 597c176900
commit c5b3033b3a
50 changed files with 182 additions and 3217 deletions
+68
View File
@@ -0,0 +1,68 @@
package genutil
import (
"context"
abciproto "github.com/cometbft/cometbft/api/cometbft/abci/v1"
"github.com/cosmos/cosmos-sdk/runtime"
)
type cometABCIWrapper struct {
app *runtime.App
}
func (w cometABCIWrapper) Info(_ context.Context, req *abciproto.InfoRequest) (*abciproto.InfoResponse, error) {
return w.app.Info(req)
}
func (w cometABCIWrapper) Query(ctx context.Context, req *abciproto.QueryRequest) (*abciproto.QueryResponse, error) {
return w.app.Query(ctx, req)
}
func (w cometABCIWrapper) CheckTx(_ context.Context, req *abciproto.CheckTxRequest) (*abciproto.CheckTxResponse, error) {
return w.app.CheckTx(req)
}
func (w cometABCIWrapper) InitChain(_ context.Context, req *abciproto.InitChainRequest) (*abciproto.InitChainResponse, error) {
return w.app.InitChain(req)
}
func (w cometABCIWrapper) PrepareProposal(_ context.Context, req *abciproto.PrepareProposalRequest) (*abciproto.PrepareProposalResponse, error) {
return w.app.PrepareProposal(req)
}
func (w cometABCIWrapper) ProcessProposal(_ context.Context, req *abciproto.ProcessProposalRequest) (*abciproto.ProcessProposalResponse, error) {
return w.app.ProcessProposal(req)
}
func (w cometABCIWrapper) FinalizeBlock(_ context.Context, req *abciproto.FinalizeBlockRequest) (*abciproto.FinalizeBlockResponse, error) {
return w.app.FinalizeBlock(req)
}
func (w cometABCIWrapper) ExtendVote(ctx context.Context, req *abciproto.ExtendVoteRequest) (*abciproto.ExtendVoteResponse, error) {
return w.app.ExtendVote(ctx, req)
}
func (w cometABCIWrapper) VerifyVoteExtension(_ context.Context, req *abciproto.VerifyVoteExtensionRequest) (*abciproto.VerifyVoteExtensionResponse, error) {
return w.app.VerifyVoteExtension(req)
}
func (w cometABCIWrapper) Commit(_ context.Context, _ *abciproto.CommitRequest) (*abciproto.CommitResponse, error) {
return w.app.Commit()
}
func (w cometABCIWrapper) ListSnapshots(_ context.Context, req *abciproto.ListSnapshotsRequest) (*abciproto.ListSnapshotsResponse, error) {
return w.app.ListSnapshots(req)
}
func (w cometABCIWrapper) OfferSnapshot(_ context.Context, req *abciproto.OfferSnapshotRequest) (*abciproto.OfferSnapshotResponse, error) {
return w.app.OfferSnapshot(req)
}
func (w cometABCIWrapper) LoadSnapshotChunk(_ context.Context, req *abciproto.LoadSnapshotChunkRequest) (*abciproto.LoadSnapshotChunkResponse, error) {
return w.app.LoadSnapshotChunk(req)
}
func (w cometABCIWrapper) ApplySnapshotChunk(_ context.Context, req *abciproto.ApplySnapshotChunkRequest) (*abciproto.ApplySnapshotChunkResponse, error) {
return w.app.ApplySnapshotChunk(req)
}
+99 -84
View File
@@ -1,12 +1,9 @@
package genutil
import (
"bytes"
"context"
"fmt"
"io"
"net"
"os"
"testing"
"time"
@@ -15,7 +12,11 @@ import (
"github.com/stretchr/testify/require"
corectx "cosmossdk.io/core/context"
"cosmossdk.io/depinject"
"cosmossdk.io/log"
_ "cosmossdk.io/x/accounts"
_ "cosmossdk.io/x/bank"
_ "cosmossdk.io/x/consensus"
"cosmossdk.io/x/staking"
"github.com/cosmos/cosmos-sdk/client"
@@ -24,16 +25,16 @@ import (
"github.com/cosmos/cosmos-sdk/codec/types"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
"github.com/cosmos/cosmos-sdk/server"
servercmtlog "github.com/cosmos/cosmos-sdk/server/log"
"github.com/cosmos/cosmos-sdk/server/mock"
"github.com/cosmos/cosmos-sdk/testutil"
"github.com/cosmos/cosmos-sdk/testutil/configurator"
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
genutilhelpers "github.com/cosmos/cosmos-sdk/testutil/x/genutil"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/x/genutil"
genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli"
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
_ "github.com/cosmos/cosmos-sdk/x/validate"
)
var testMbm = module.NewManager(
@@ -159,76 +160,88 @@ func TestInitDefaultBondDenom(t *testing.T) {
}
func TestEmptyState(t *testing.T) {
home := t.TempDir()
logger := log.NewNopLogger()
viper := viper.New()
// TODO: rewrite for v2: https://github.com/cosmos/cosmos-sdk/issues/20799
err := writeAndTrackDefaultConfig(viper, home)
require.NoError(t, err)
interfaceRegistry := types.NewInterfaceRegistry()
marshaler := codec.NewProtoCodec(interfaceRegistry)
clientCtx := client.Context{}.
WithCodec(marshaler).
WithLegacyAmino(makeAminoCodec()).
WithHomeDir(home)
// home := t.TempDir()
// logger := log.NewNopLogger()
// viper := viper.New()
ctx := context.Background()
ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx)
ctx = context.WithValue(ctx, corectx.ViperContextKey, viper)
ctx = context.WithValue(ctx, corectx.LoggerContextKey, logger)
// err := writeAndTrackDefaultConfig(viper, home)
// require.NoError(t, err)
// interfaceRegistry := types.NewInterfaceRegistry()
// marshaler := codec.NewProtoCodec(interfaceRegistry)
// clientCtx := client.Context{}.
// WithCodec(marshaler).
// WithLegacyAmino(makeAminoCodec()).
// WithHomeDir(home)
cmd := genutilcli.InitCmd(testMbm)
cmd.SetArgs([]string{"appnode-test"})
// ctx := context.Background()
// ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx)
// ctx = context.WithValue(ctx, corectx.ViperContextKey, viper)
// ctx = context.WithValue(ctx, corectx.LoggerContextKey, logger)
require.NoError(t, cmd.ExecuteContext(ctx))
// cmd := genutilcli.InitCmd(testMbm)
// cmd.SetArgs([]string{"appnode-test"})
old := os.Stdout
r, w, _ := os.Pipe()
os.Stdout = w
// require.NoError(t, cmd.ExecuteContext(ctx))
cmd = genutilcli.ExportCmd(nil)
require.NoError(t, cmd.ExecuteContext(ctx))
// old := os.Stdout
// r, w, _ := os.Pipe()
// os.Stdout = w
outC := make(chan string)
go func() {
var buf bytes.Buffer
_, err := io.Copy(&buf, r)
require.NoError(t, err)
// cmd = genutilcli.ExportCmd(nil)
// require.NoError(t, cmd.ExecuteContext(ctx))
outC <- buf.String()
}()
// outC := make(chan string)
// go func() {
// var buf bytes.Buffer
// _, err := io.Copy(&buf, r)
// require.NoError(t, err)
w.Close()
os.Stdout = old
out := <-outC
// outC <- buf.String()
// }()
require.Contains(t, out, "genesis_time")
require.Contains(t, out, "chain_id")
require.Contains(t, out, "consensus")
require.Contains(t, out, "app_hash")
require.Contains(t, out, "app_state")
// w.Close()
// os.Stdout = old
// out := <-outC
// require.Contains(t, out, "genesis_time")
// require.Contains(t, out, "chain_id")
// require.Contains(t, out, "consensus")
// require.Contains(t, out, "app_hash")
// require.Contains(t, out, "app_state")
}
func TestStartStandAlone(t *testing.T) {
home := t.TempDir()
logger := log.NewNopLogger()
interfaceRegistry := types.NewInterfaceRegistry()
marshaler := codec.NewProtoCodec(interfaceRegistry)
err := genutilhelpers.ExecInitCmd(testMbm, home, marshaler)
require.NoError(t, err)
app, err := mock.NewApp(home, logger)
app, err := simtestutil.SetupWithConfiguration(
depinject.Configs(
configurator.NewAppConfig(
configurator.AccountsModule(),
configurator.AuthModule(),
configurator.StakingModule(),
configurator.TxModule(),
configurator.ValidateModule(),
configurator.ConsensusModule(),
configurator.BankModule(),
),
depinject.Supply(log.NewNopLogger()),
), simtestutil.DefaultStartUpConfig())
require.NoError(t, err)
svrAddr, _, closeFn, err := freeTCPAddr()
require.NoError(t, err)
require.NoError(t, closeFn())
cmtApp := server.NewCometABCIWrapper(app)
cmtApp := cometABCIWrapper{app}
svr, err := abci_server.NewServer(svrAddr, "socket", cmtApp)
require.NoError(t, err, "error creating listener")
svr.SetLogger(servercmtlog.CometLoggerWrapper{Logger: logger.With("module", "abci-server")})
err = svr.Start()
require.NoError(t, err)
@@ -253,51 +266,53 @@ func TestInitNodeValidatorFiles(t *testing.T) {
}
func TestInitConfig(t *testing.T) {
home := t.TempDir()
logger := log.NewNopLogger()
viper := viper.New()
// TODO: rewrite for v2: https://github.com/cosmos/cosmos-sdk/issues/20799
err := writeAndTrackDefaultConfig(viper, home)
require.NoError(t, err)
interfaceRegistry := types.NewInterfaceRegistry()
marshaler := codec.NewProtoCodec(interfaceRegistry)
clientCtx := client.Context{}.
WithCodec(marshaler).
WithLegacyAmino(makeAminoCodec()).
WithChainID("foo"). // add chain-id to clientCtx
WithHomeDir(home)
// home := t.TempDir()
// logger := log.NewNopLogger()
// viper := viper.New()
ctx := context.Background()
ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx)
ctx = context.WithValue(ctx, corectx.ViperContextKey, viper)
ctx = context.WithValue(ctx, corectx.LoggerContextKey, logger)
// err := writeAndTrackDefaultConfig(viper, home)
// require.NoError(t, err)
// interfaceRegistry := types.NewInterfaceRegistry()
// marshaler := codec.NewProtoCodec(interfaceRegistry)
// clientCtx := client.Context{}.
// WithCodec(marshaler).
// WithLegacyAmino(makeAminoCodec()).
// WithChainID("foo"). // add chain-id to clientCtx
// WithHomeDir(home)
cmd := genutilcli.InitCmd(testMbm)
cmd.SetArgs([]string{"testnode"})
// ctx := context.Background()
// ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx)
// ctx = context.WithValue(ctx, corectx.ViperContextKey, viper)
// ctx = context.WithValue(ctx, corectx.LoggerContextKey, logger)
err = cmd.ExecuteContext(ctx)
require.NoError(t, err)
// cmd := genutilcli.InitCmd(testMbm)
// cmd.SetArgs([]string{"testnode"})
old := os.Stdout
r, w, _ := os.Pipe()
os.Stdout = w
// err = cmd.ExecuteContext(ctx)
// require.NoError(t, err)
cmd = genutilcli.ExportCmd(nil)
require.NoError(t, cmd.ExecuteContext(ctx))
// old := os.Stdout
// r, w, _ := os.Pipe()
// os.Stdout = w
outC := make(chan string)
go func() {
var buf bytes.Buffer
_, err := io.Copy(&buf, r)
require.NoError(t, err)
outC <- buf.String()
}()
// cmd = genutilcli.ExportCmd(nil)
// require.NoError(t, cmd.ExecuteContext(ctx))
w.Close()
os.Stdout = old
out := <-outC
// outC := make(chan string)
// go func() {
// var buf bytes.Buffer
// _, err := io.Copy(&buf, r)
// require.NoError(t, err)
// outC <- buf.String()
// }()
require.Contains(t, out, "\"chain_id\": \"foo\"")
// w.Close()
// os.Stdout = old
// out := <-outC
// require.Contains(t, out, "\"chain_id\": \"foo\"")
}
func TestInitWithHeight(t *testing.T) {