Skip to content

Commit

Permalink
Merge branch 'main' of github.com:cosmos/cosmos-sdk into aaronc/schem…
Browse files Browse the repository at this point in the history
…a-appdata-updates
  • Loading branch information
aaronc committed Jul 3, 2024
2 parents 812c6ee + 1bbb499 commit 77ec7e7
Show file tree
Hide file tree
Showing 37 changed files with 175 additions and 221 deletions.
18 changes: 2 additions & 16 deletions baseapp/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -817,22 +817,8 @@ func (app *BaseApp) internalFinalizeBlock(ctx context.Context, req *abci.Finaliz
// vote extensions, so skip those.
txResults := make([]*abci.ExecTxResult, 0, len(req.Txs))
for _, rawTx := range req.Txs {
var response *abci.ExecTxResult

if _, err := app.txDecoder(rawTx); err == nil {
response = app.deliverTx(rawTx)
} else {
// In the case where a transaction included in a block proposal is malformed,
// we still want to return a default response to comet. This is because comet
// expects a response for each transaction included in a block proposal.
response = responseExecTxResultWithEvents(
sdkerrors.ErrTxDecode,
0,
0,
nil,
false,
)
}

response := app.deliverTx(rawTx)

// check after every tx if we should abort
select {
Expand Down
2 changes: 1 addition & 1 deletion baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,7 @@ func (app *BaseApp) runTx(mode execMode, txBytes []byte) (gInfo sdk.GasInfo, res

tx, err := app.txDecoder(txBytes)
if err != nil {
return sdk.GasInfo{}, nil, nil, err
return sdk.GasInfo{GasUsed: 0, GasWanted: 0}, nil, nil, sdkerrors.ErrTxDecode.Wrap(err.Error())
}

msgs := tx.GetMsgs()
Expand Down
21 changes: 21 additions & 0 deletions baseapp/baseapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -893,3 +893,24 @@ func TestLoadVersionPruning(t *testing.T) {
require.Nil(t, err)
testLoadVersionHelper(t, app, int64(7), lastCommitID)
}

func TestABCI_FinalizeWithInvalidTX(t *testing.T) {
suite := NewBaseAppSuite(t)
baseapptestutil.RegisterCounterServer(suite.baseApp.MsgServiceRouter(), CounterServerImplGasMeterOnly{})

_, err := suite.baseApp.InitChain(&abci.InitChainRequest{ConsensusParams: &cmtproto.ConsensusParams{}})
require.NoError(t, err)

tx := newTxCounter(t, suite.txConfig, 0, 0)
bz, err := suite.txConfig.TxEncoder()(tx)
require.NoError(t, err)

// when
gotRsp, gotErr := suite.baseApp.FinalizeBlock(&abci.FinalizeBlockRequest{
Height: 1,
Txs: [][]byte{bz[0 : len(bz)-5]},
})
require.NoError(t, gotErr)
require.Len(t, gotRsp.TxResults, 1)
require.Equal(t, uint32(2), gotRsp.TxResults[0].Code)
}
4 changes: 3 additions & 1 deletion client/grpc/cmtservice/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (

"github.com/stretchr/testify/require"

"cosmossdk.io/depinject"

"github.com/cosmos/cosmos-sdk/server"
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
"github.com/cosmos/cosmos-sdk/testutil/network"
Expand All @@ -14,7 +16,7 @@ import (
func TestStatusCommand(t *testing.T) {
t.Skip() // https://github.com/cosmos/cosmos-sdk/issues/17446

cfg, err := network.DefaultConfigWithAppConfig(network.MinimumAppConfig())
cfg, err := network.DefaultConfigWithAppConfig(depinject.Configs() /* TODO, test skipped anyway */)
require.NoError(t, err)

network, err := network.New(t, t.TempDir(), cfg)
Expand Down
73 changes: 20 additions & 53 deletions client/rpc/rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,59 +6,34 @@ import (
"testing"

abci "github.com/cometbft/cometbft/api/cometbft/abci/v1"
"github.com/stretchr/testify/suite"
"github.com/stretchr/testify/require"
"google.golang.org/grpc"
"google.golang.org/grpc/metadata"

_ "cosmossdk.io/x/accounts"

"github.com/cosmos/cosmos-sdk/testutil/network"
"github.com/cosmos/cosmos-sdk/client"
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
"github.com/cosmos/cosmos-sdk/types/address"
grpctypes "github.com/cosmos/cosmos-sdk/types/grpc"
)

type IntegrationTestSuite struct {
suite.Suite

network network.NetworkI
}

func (s *IntegrationTestSuite) SetupSuite() {
s.T().Log("setting up integration test suite")

cfg, err := network.DefaultConfigWithAppConfig(network.MinimumAppConfig())
func TestCLIQueryConn(t *testing.T) {
t.Skip("data race in comet is causing this to fail")

s.NoError(err)

s.network, err = network.New(s.T(), s.T().TempDir(), cfg)
s.Require().NoError(err)

s.Require().NoError(s.network.WaitForNextBlock())
}

func (s *IntegrationTestSuite) TearDownSuite() {
s.T().Log("tearing down integration test suite")
s.network.Cleanup()
}

func (s *IntegrationTestSuite) TestCLIQueryConn() {
s.T().Skip("data race in comet is causing this to fail")
var header metadata.MD

testClient := testdata.NewQueryClient(s.network.GetValidators()[0].GetClientCtx())
testClient := testdata.NewQueryClient(client.Context{})
res, err := testClient.Echo(context.Background(), &testdata.EchoRequest{Message: "hello"}, grpc.Header(&header))
s.NoError(err)
require.NoError(t, err)

blockHeight := header.Get(grpctypes.GRPCBlockHeightHeader)
height, err := strconv.Atoi(blockHeight[0])
s.Require().NoError(err)
s.Require().GreaterOrEqual(height, 1) // at least the 1st block

s.Equal("hello", res.Message)
require.NoError(t, err)
require.GreaterOrEqual(t, height, 1) // at least the 1st block
require.Equal(t, "hello", res.Message)
}

func (s *IntegrationTestSuite) TestQueryABCIHeight() {
func TestQueryABCIHeight(t *testing.T) {
testCases := []struct {
name string
reqHeight int64
Expand Down Expand Up @@ -86,30 +61,22 @@ func (s *IntegrationTestSuite) TestQueryABCIHeight() {
}

for _, tc := range testCases {
s.Run(tc.name, func() {
_, err := s.network.WaitForHeight(tc.expHeight)
s.Require().NoError(err)

val := s.network.GetValidators()[0]

clientCtx := val.GetClientCtx()
clientCtx = clientCtx.WithHeight(tc.ctxHeight)

t.Run(tc.name, func(t *testing.T) {
req := abci.QueryRequest{
Path: "store/bank/key",
Height: tc.reqHeight,
Data: address.MustLengthPrefix(val.GetAddress()),
Data: address.MustLengthPrefix([]byte{}),
Prove: true,
}

res, err := clientCtx.QueryABCI(req)
s.Require().NoError(err)
clientCtx := client.Context{}.WithHeight(tc.ctxHeight).
WithClient(clitestutil.NewMockCometRPC(abci.QueryResponse{
Height: tc.expHeight,
}))

s.Require().Equal(tc.expHeight, res.Height)
res, err := clientCtx.QueryABCI(req)
require.NoError(t, err)
require.Equal(t, tc.expHeight, res.Height)
})
}
}

func TestIntegrationTestSuite(t *testing.T) {
suite.Run(t, new(IntegrationTestSuite))
}
2 changes: 0 additions & 2 deletions client/v2/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ cosmossdk.io/errors v1.0.1 h1:bzu+Kcr0kS/1DuPBtUFdWjzLqyUuCiyHjyJB6srBV/0=
cosmossdk.io/errors v1.0.1/go.mod h1:MeelVSZThMi4bEakzhhhE/CKqVv3nOJDA25bIqRDu/U=
cosmossdk.io/math v1.3.0 h1:RC+jryuKeytIiictDslBP9i1fhkVm6ZDmZEoNP316zE=
cosmossdk.io/math v1.3.0/go.mod h1:vnRTxewy+M7BtXBNFybkuhSH4WfedVAAnERHgVFhp3k=
cosmossdk.io/x/accounts/defaults/lockup v0.0.0-20240417181816-5e7aae0db1f5 h1:eb0kcGyaYHSS0do7+MIWg7UKlskSH01biRNENbm/zDA=
cosmossdk.io/x/accounts/defaults/lockup v0.0.0-20240417181816-5e7aae0db1f5/go.mod h1:drzY4oVisyWvSgpsM7ccQ7IX3efMuVIvd9Eij1Gm/6o=
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 h1:/vQbFIOMbk2FiG/kXiLl8BRyzTWDw7gX/Hz7Dd5eDMs=
Expand Down
74 changes: 74 additions & 0 deletions codec/depinject_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package codec_test

import (
"testing"

"github.com/stretchr/testify/require"

authmodulev1 "cosmossdk.io/api/cosmos/auth/module/v1"
"cosmossdk.io/core/address"
"cosmossdk.io/depinject"
"cosmossdk.io/log"

"github.com/cosmos/cosmos-sdk/codec"
)

var _ address.Codec = (*customAddressCodec)(nil)

type customAddressCodec struct{}

func (c customAddressCodec) StringToBytes(text string) ([]byte, error) {
return []byte(text), nil
}

func (c customAddressCodec) BytesToString(bz []byte) (string, error) {
return string(bz), nil
}

func AuthConfig() *authmodulev1.Module { return &authmodulev1.Module{Bech32Prefix: "cosmos"} }

func TestProvideAddressCodec(t *testing.T) {
var addrCodec address.Codec
var valAddressCodec address.ValidatorAddressCodec
var consAddressCodec address.ConsensusAddressCodec

err := depinject.Inject(
depinject.Provide(
AuthConfig,
codec.ProvideAddressCodec,
),
&addrCodec, &valAddressCodec, &consAddressCodec)
require.NoError(t, err)
require.NotNil(t, addrCodec)
_, ok := addrCodec.(customAddressCodec)
require.False(t, ok)
require.NotNil(t, valAddressCodec)
_, ok = valAddressCodec.(customAddressCodec)
require.False(t, ok)
require.NotNil(t, consAddressCodec)
_, ok = consAddressCodec.(customAddressCodec)
require.False(t, ok)

// Set the address codec to the custom one
err = depinject.Inject(
depinject.Configs(
depinject.Provide(AuthConfig, codec.ProvideAddressCodec),
depinject.Supply(
log.NewNopLogger(),
func() address.Codec { return customAddressCodec{} },
func() address.ValidatorAddressCodec { return customAddressCodec{} },
func() address.ConsensusAddressCodec { return customAddressCodec{} },
),
),
&addrCodec, &valAddressCodec, &consAddressCodec)
require.NoError(t, err)
require.NotNil(t, addrCodec)
_, ok = addrCodec.(customAddressCodec)
require.True(t, ok)
require.NotNil(t, valAddressCodec)
_, ok = valAddressCodec.(customAddressCodec)
require.True(t, ok)
require.NotNil(t, consAddressCodec)
_, ok = consAddressCodec.(customAddressCodec)
require.True(t, ok)
}
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ require (
cosmossdk.io/log v1.3.1
cosmossdk.io/math v1.3.0
cosmossdk.io/store v1.1.1-0.20240418092142-896cdf1971bc
cosmossdk.io/x/accounts v0.0.0-20240226161501-23359a0b6d91
cosmossdk.io/x/auth v0.0.0-00010101000000-000000000000
cosmossdk.io/x/bank v0.0.0-20240226161501-23359a0b6d91
cosmossdk.io/x/consensus v0.0.0-00010101000000-000000000000
Expand Down Expand Up @@ -70,7 +69,7 @@ require (
require (
buf.build/gen/go/cometbft/cometbft/protocolbuffers/go v1.34.2-20240701160653-fedbb9acfd2f.2 // indirect
buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.34.2-20240130113600-88ef6483f90f.2 // indirect
cosmossdk.io/x/accounts/defaults/lockup v0.0.0-20240417181816-5e7aae0db1f5 // indirect
cosmossdk.io/x/accounts v0.0.0-20240226161501-23359a0b6d91 // indirect
filippo.io/edwards25519 v1.1.0 // indirect
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
github.com/DataDog/datadog-go v4.8.3+incompatible // indirect
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ cosmossdk.io/errors v1.0.1 h1:bzu+Kcr0kS/1DuPBtUFdWjzLqyUuCiyHjyJB6srBV/0=
cosmossdk.io/errors v1.0.1/go.mod h1:MeelVSZThMi4bEakzhhhE/CKqVv3nOJDA25bIqRDu/U=
cosmossdk.io/math v1.3.0 h1:RC+jryuKeytIiictDslBP9i1fhkVm6ZDmZEoNP316zE=
cosmossdk.io/math v1.3.0/go.mod h1:vnRTxewy+M7BtXBNFybkuhSH4WfedVAAnERHgVFhp3k=
cosmossdk.io/x/accounts/defaults/lockup v0.0.0-20240417181816-5e7aae0db1f5 h1:eb0kcGyaYHSS0do7+MIWg7UKlskSH01biRNENbm/zDA=
cosmossdk.io/x/accounts/defaults/lockup v0.0.0-20240417181816-5e7aae0db1f5/go.mod h1:drzY4oVisyWvSgpsM7ccQ7IX3efMuVIvd9Eij1Gm/6o=
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 h1:/vQbFIOMbk2FiG/kXiLl8BRyzTWDw7gX/Hz7Dd5eDMs=
Expand Down
2 changes: 0 additions & 2 deletions server/v2/cometbft/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ cosmossdk.io/errors v1.0.1 h1:bzu+Kcr0kS/1DuPBtUFdWjzLqyUuCiyHjyJB6srBV/0=
cosmossdk.io/errors v1.0.1/go.mod h1:MeelVSZThMi4bEakzhhhE/CKqVv3nOJDA25bIqRDu/U=
cosmossdk.io/math v1.3.0 h1:RC+jryuKeytIiictDslBP9i1fhkVm6ZDmZEoNP316zE=
cosmossdk.io/math v1.3.0/go.mod h1:vnRTxewy+M7BtXBNFybkuhSH4WfedVAAnERHgVFhp3k=
cosmossdk.io/x/accounts/defaults/lockup v0.0.0-20240417181816-5e7aae0db1f5 h1:eb0kcGyaYHSS0do7+MIWg7UKlskSH01biRNENbm/zDA=
cosmossdk.io/x/accounts/defaults/lockup v0.0.0-20240417181816-5e7aae0db1f5/go.mod h1:drzY4oVisyWvSgpsM7ccQ7IX3efMuVIvd9Eij1Gm/6o=
cosmossdk.io/x/tx v0.13.3 h1:Ha4mNaHmxBc6RMun9aKuqul8yHiL78EKJQ8g23Zf73g=
cosmossdk.io/x/tx v0.13.3/go.mod h1:I8xaHv0rhUdIvIdptKIqzYy27+n2+zBVaxO6fscFhys=
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
Expand Down
61 changes: 0 additions & 61 deletions simapp/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ import (
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/require"

"cosmossdk.io/core/address"
"cosmossdk.io/core/appmodule"
"cosmossdk.io/depinject"
"cosmossdk.io/log"
"cosmossdk.io/x/accounts"
"cosmossdk.io/x/auth"
Expand All @@ -36,7 +34,6 @@ import (

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/testutil/mock"
"github.com/cosmos/cosmos-sdk/testutil/network"
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
Expand Down Expand Up @@ -299,61 +296,3 @@ func TestProtoAnnotations(t *testing.T) {
err = msgservice.ValidateProtoAnnotations(r)
require.NoError(t, err)
}

var _ address.Codec = (*customAddressCodec)(nil)

type customAddressCodec struct{}

func (c customAddressCodec) StringToBytes(text string) ([]byte, error) {
return []byte(text), nil
}

func (c customAddressCodec) BytesToString(bz []byte) (string, error) {
return string(bz), nil
}

func TestAddressCodecFactory(t *testing.T) {
var addrCodec address.Codec
var valAddressCodec address.ValidatorAddressCodec
var consAddressCodec address.ConsensusAddressCodec

err := depinject.Inject(
depinject.Configs(
network.MinimumAppConfig(),
depinject.Supply(log.NewNopLogger()),
),
&addrCodec, &valAddressCodec, &consAddressCodec)
require.NoError(t, err)
require.NotNil(t, addrCodec)
_, ok := addrCodec.(customAddressCodec)
require.False(t, ok)
require.NotNil(t, valAddressCodec)
_, ok = valAddressCodec.(customAddressCodec)
require.False(t, ok)
require.NotNil(t, consAddressCodec)
_, ok = consAddressCodec.(customAddressCodec)
require.False(t, ok)

// Set the address codec to the custom one
err = depinject.Inject(
depinject.Configs(
network.MinimumAppConfig(),
depinject.Supply(
log.NewNopLogger(),
func() address.Codec { return customAddressCodec{} },
func() address.ValidatorAddressCodec { return customAddressCodec{} },
func() address.ConsensusAddressCodec { return customAddressCodec{} },
),
),
&addrCodec, &valAddressCodec, &consAddressCodec)
require.NoError(t, err)
require.NotNil(t, addrCodec)
_, ok = addrCodec.(customAddressCodec)
require.True(t, ok)
require.NotNil(t, valAddressCodec)
_, ok = valAddressCodec.(customAddressCodec)
require.True(t, ok)
require.NotNil(t, consAddressCodec)
_, ok = consAddressCodec.(customAddressCodec)
require.True(t, ok)
}
Loading

0 comments on commit 77ec7e7

Please sign in to comment.