Skip to content

Commit

Permalink
Merge branch 'main' into bez/18276-store-v2-upgrades
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderbez authored Oct 30, 2023
2 parents 8d36583 + 88b7666 commit f5c7285
Show file tree
Hide file tree
Showing 80 changed files with 792 additions and 715 deletions.
60 changes: 30 additions & 30 deletions .github/workflows/test.yml

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (rpc) [#17470](https://github.com/cosmos/cosmos-sdk/pull/17470) Avoid open 0.0.0.0 to public by default and add `listen-ip-address` argument for `testnet init-files` cmd.
* (types) [#17670](https://github.com/cosmos/cosmos-sdk/pull/17670) Use `ctx.CometInfo` in place of `ctx.VoteInfos`
* [#17733](https://github.com/cosmos/cosmos-sdk/pull/17733) Ensure `buf export` exports all proto dependencies
* (version) [#18063](https://github.com/cosmos/cosmos-sdk/pull/18063) Include additional information in the Info struct. This change enhances the Info struct by adding support for additional information through the ExtraInfo field
* [#18204](https://github.com/cosmos/cosmos-sdk/pull/18204) Use streaming json parser to parse chain-id from genesis file.

### Bug Fixes
Expand Down Expand Up @@ -185,6 +186,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (x/mint) [#18283](https://github.com/cosmos/cosmos-sdk/pull/18283) Mint module was moved to its own go.mod `cosmossdk.io/x/mint`
* (x/consensus) [#18041](https://github.com/cosmos/cosmos-sdk/pull/18041) `ToProtoConsensusParams()` returns an error
* (x/slashing) [#18115](https://github.com/cosmos/cosmos-sdk/pull/18115) `NewValidatorSigningInfo` takes strings instead of `sdk.AccAddress`
* (types) [#18268](https://github.com/cosmos/cosmos-sdk/pull/18268) Remove global setting of basedenom. Use the staking module parameter instead

### CLI Breaking Changes

Expand Down
64 changes: 34 additions & 30 deletions api/cosmos/counter/v1/tx.pulsar.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 7 additions & 12 deletions client/fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,15 @@ import (
"google.golang.org/grpc"
"google.golang.org/grpc/metadata"

"cosmossdk.io/x/bank/types"

"github.com/cosmos/cosmos-sdk/testutil/testdata"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/counter/types"
)

type fuzzSuite struct {
IntegrationTestSuite
}

func (fz *fuzzSuite) FuzzQueryBalance(f *testing.F) {
func (fz *fuzzSuite) FuzzQuery(f *testing.F) {
if testing.Short() {
f.Skip("In -short mode")
}
Expand All @@ -28,34 +26,31 @@ func (fz *fuzzSuite) FuzzQueryBalance(f *testing.F) {
fz.Require().Equal("hello", testRes.Message)

// 1. Generate some seeds.
bz, err := fz.cdc.Marshal(&types.QueryBalanceRequest{
Address: fz.genesisAccount.GetAddress().String(),
Denom: sdk.DefaultBondDenom,
})
bz, err := fz.cdc.Marshal(&types.QueryGetCountRequest{})
fz.Require().NoError(err)
f.Add(bz)

// 2. Now fuzz it and ensure that we don't get any panics.
ctx := context.Background()
f.Fuzz(func(t *testing.T, in []byte) {
qbReq := new(types.QueryBalanceRequest)
qbReq := new(types.QueryGetCountRequest)
if err := fz.cdc.Unmarshal(in, qbReq); err != nil {
return
}

// gRPC query to bank service should work
var header metadata.MD
_, _ = fz.bankClient.Balance(
_, _ = fz.counterClient.GetCount(
ctx,
qbReq,
grpc.Header(&header),
)
})
}

func FuzzQueryBalance(f *testing.F) {
func FuzzQuery(f *testing.F) {
fzs := new(fuzzSuite)
fzs.SetT(new(testing.T))
fzs.SetupSuite()
fzs.FuzzQueryBalance(f)
fzs.FuzzQuery(f)
}
114 changes: 24 additions & 90 deletions client/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,134 +4,68 @@ import (
"context"
"testing"

abci "github.com/cometbft/cometbft/abci/types"
cmtjson "github.com/cometbft/cometbft/libs/json"
dbm "github.com/cosmos/cosmos-db"
"github.com/stretchr/testify/suite"
"google.golang.org/grpc"
"google.golang.org/grpc/metadata"

"cosmossdk.io/depinject"
"cosmossdk.io/log"
"cosmossdk.io/math"
bankkeeper "cosmossdk.io/x/bank/keeper"
"cosmossdk.io/x/bank/types"
storetypes "cosmossdk.io/store/types"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
"github.com/cosmos/cosmos-sdk/runtime"
"github.com/cosmos/cosmos-sdk/testutil/sims"
"github.com/cosmos/cosmos-sdk/testutil/integration"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth/testutil"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
"github.com/cosmos/cosmos-sdk/x/counter"
counterkeeper "github.com/cosmos/cosmos-sdk/x/counter/keeper"
countertypes "github.com/cosmos/cosmos-sdk/x/counter/types"
)

type IntegrationTestSuite struct {
suite.Suite

ctx sdk.Context
cdc codec.Codec
genesisAccount *authtypes.BaseAccount
bankClient types.QueryClient
testClient testdata.QueryClient
genesisAccountBalance int64
ctx sdk.Context
cdc codec.Codec
counterClient countertypes.QueryClient
testClient testdata.QueryClient
}

func (s *IntegrationTestSuite) SetupSuite() {
s.T().Log("setting up integration test suite")
var (
interfaceRegistry codectypes.InterfaceRegistry
bankKeeper bankkeeper.BaseKeeper
appBuilder *runtime.AppBuilder
cdc codec.Codec
)

// TODO duplicated from testutils/sims/app_helpers.go
// need more composable startup options for simapp, this test needed a handle to the closed over genesis account
// to query balances
err := depinject.Inject(
depinject.Configs(
testutil.AppConfig,
depinject.Supply(log.NewNopLogger()),
),
&interfaceRegistry, &bankKeeper, &appBuilder, &cdc)
s.NoError(err)
logger := log.NewNopLogger()
keys := storetypes.NewKVStoreKeys(countertypes.StoreKey)
cms := integration.CreateMultiStore(keys, logger)
s.ctx = sdk.NewContext(cms, true, logger)
cfg := moduletestutil.MakeTestEncodingConfig(counter.AppModuleBasic{})
s.cdc = cfg.Codec

app := appBuilder.Build(dbm.NewMemDB(), nil)
err = app.Load(true)
s.NoError(err)

valSet, err := sims.CreateRandomValidatorSet()
s.NoError(err)

// generate genesis account
s.genesisAccountBalance = 100000000000000
senderPrivKey := secp256k1.GenPrivKey()
acc := authtypes.NewBaseAccount(senderPrivKey.PubKey().Address().Bytes(), senderPrivKey.PubKey(), 0, 0)
balance := types.Balance{
Address: acc.GetAddress().String(),
Coins: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, math.NewInt(s.genesisAccountBalance))),
}

genesisState, err := sims.GenesisStateWithValSet(cdc, app.DefaultGenesis(), valSet, []authtypes.GenesisAccount{acc}, balance)
s.NoError(err)

stateBytes, err := cmtjson.MarshalIndent(genesisState, "", " ")
s.NoError(err)

// init chain will set the validator set and initialize the genesis accounts
_, err = app.InitChain(&abci.RequestInitChain{
Validators: []abci.ValidatorUpdate{},
ConsensusParams: sims.DefaultConsensusParams,
AppStateBytes: stateBytes,
},
)
s.NoError(err)

_, err = app.FinalizeBlock(&abci.RequestFinalizeBlock{
Height: app.LastBlockHeight() + 1,
Hash: app.LastCommitID().Hash,
NextValidatorsHash: valSet.Hash(),
})
s.NoError(err)

// end of app init

s.ctx = app.BaseApp.NewContext(false)
s.cdc = cdc
queryHelper := baseapp.NewQueryServerTestHelper(s.ctx, interfaceRegistry)
types.RegisterQueryServer(queryHelper, bankKeeper)
queryHelper := baseapp.NewQueryServerTestHelper(s.ctx, cfg.InterfaceRegistry)
testdata.RegisterQueryServer(queryHelper, testdata.QueryImpl{})
s.bankClient = types.NewQueryClient(queryHelper)
s.testClient = testdata.NewQueryClient(queryHelper)
s.genesisAccount = acc

kvs := runtime.NewKVStoreService(keys[countertypes.StoreKey])
counterKeeper := counterkeeper.NewKeeper(kvs, runtime.EventService{})
countertypes.RegisterQueryServer(queryHelper, counterKeeper)
s.counterClient = countertypes.NewQueryClient(queryHelper)
}

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

func (s *IntegrationTestSuite) TestGRPCQuery() {
denom := sdk.DefaultBondDenom

// gRPC query to test service should work
testRes, err := s.testClient.Echo(context.Background(), &testdata.EchoRequest{Message: "hello"})
s.Require().NoError(err)
s.Require().Equal("hello", testRes.Message)

// gRPC query to bank service should work
var header metadata.MD
res, err := s.bankClient.Balance(
context.Background(),
&types.QueryBalanceRequest{Address: s.genesisAccount.GetAddress().String(), Denom: denom},
grpc.Header(&header), // Also fetch grpc header
)
res, err := s.counterClient.GetCount(s.ctx, &countertypes.QueryGetCountRequest{}, grpc.Header(&header))
s.Require().NoError(err)
bal := res.GetBalance()
s.Equal(sdk.NewCoin(denom, math.NewInt(s.genesisAccountBalance)), *bal)
s.Require().Equal(int64(0), res.TotalCount)
}

func TestIntegrationTestSuite(t *testing.T) {
Expand Down
9 changes: 4 additions & 5 deletions client/tx/aux_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import (

"github.com/stretchr/testify/require"

"cosmossdk.io/x/bank"

"github.com/cosmos/cosmos-sdk/client/tx"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
Expand All @@ -16,16 +14,17 @@ import (
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
typestx "github.com/cosmos/cosmos-sdk/types/tx"
"github.com/cosmos/cosmos-sdk/types/tx/signing"
"github.com/cosmos/cosmos-sdk/x/counter"
)

func TestAuxTxBuilder(t *testing.T) {
bankModule := bank.AppModuleBasic{}
cdc := moduletestutil.MakeTestEncodingConfig(bankModule).Codec
counterModule := counter.AppModuleBasic{}
cdc := moduletestutil.MakeTestEncodingConfig(counterModule).Codec
reg := codectypes.NewInterfaceRegistry()

testdata.RegisterInterfaces(reg)
// required for test case: "GetAuxSignerData works for DIRECT_AUX"
bankModule.RegisterInterfaces(reg)
counterModule.RegisterInterfaces(reg)

var b tx.AuxTxBuilder

Expand Down
6 changes: 2 additions & 4 deletions client/tx/legacy_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package tx_test

import (
banktypes "cosmossdk.io/x/bank/types"

"github.com/cosmos/cosmos-sdk/testutil/testdata"
"github.com/cosmos/cosmos-sdk/types"
countertypes "github.com/cosmos/cosmos-sdk/x/counter/types"
)

const (
Expand All @@ -16,7 +14,7 @@ var (
_, pub1, addr1 = testdata.KeyTestPubAddr()
_, _, addr2 = testdata.KeyTestPubAddr()
rawSig = []byte("dummy")
msg1 = banktypes.NewMsgSend(addr1, addr2, types.NewCoins(types.NewInt64Coin("wack", 2)))
msg1 = &countertypes.MsgIncreaseCounter{Signer: addr1.String(), Count: 1}

chainID = "test-chain"
)
Loading

0 comments on commit f5c7285

Please sign in to comment.