Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unit tests and more SDK v0.47 upgrade changes #304

Merged
merged 6 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (

"github.com/cosmos/cosmos-sdk/runtime"

autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1"
dbm "github.com/cometbft/cometbft-db"
abci "github.com/cometbft/cometbft/abci/types"
tmjson "github.com/cometbft/cometbft/libs/json"
Expand All @@ -20,6 +22,7 @@ import (
"github.com/cosmos/cosmos-sdk/client/grpc/tmservice"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/types"
runtimeservices "github.com/cosmos/cosmos-sdk/runtime/services"
"github.com/cosmos/cosmos-sdk/server/api"
"github.com/cosmos/cosmos-sdk/server/config"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
Expand Down Expand Up @@ -63,7 +66,6 @@ import (
govclient "github.com/cosmos/cosmos-sdk/x/gov/client"
govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
govtypesv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
govtypesv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
"github.com/cosmos/cosmos-sdk/x/mint"
mintkeeper "github.com/cosmos/cosmos-sdk/x/mint/keeper"
Expand Down Expand Up @@ -744,6 +746,14 @@ func NewSommelierApp(
app.MountTransientStores(tkeys)
app.MountMemoryStores(memKeys)

autocliv1.RegisterQueryServer(app.GRPCQueryRouter(), runtimeservices.NewAutoCLIQueryService(app.mm.Modules))

reflectionSvc, err := runtimeservices.NewReflectionService()
if err != nil {
panic(err)
}
reflectionv1.RegisterReflectionServiceServer(app.GRPCQueryRouter(), reflectionSvc)
Comment on lines +751 to +755
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider handling the error without panicking, perhaps by logging the error and continuing with a degraded service mode if possible.

- panic(err)
+ log.Errorf("Failed to create reflection service: %v", err)
+ // Continue with degraded service mode or other error handling strategy

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
reflectionSvc, err := runtimeservices.NewReflectionService()
if err != nil {
panic(err)
}
reflectionv1.RegisterReflectionServiceServer(app.GRPCQueryRouter(), reflectionSvc)
reflectionSvc, err := runtimeservices.NewReflectionService()
if err != nil {
log.Errorf("Failed to create reflection service: %v", err)
// Continue with degraded service mode or other error handling strategy
}
reflectionv1.RegisterReflectionServiceServer(app.GRPCQueryRouter(), reflectionSvc)


// initialize BaseApp
app.SetInitChainer(app.InitChainer)
app.SetBeginBlocker(app.BeginBlocker)
Expand Down Expand Up @@ -966,7 +976,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(minttypes.ModuleName)
paramsKeeper.Subspace(distrtypes.ModuleName)
paramsKeeper.Subspace(slashingtypes.ModuleName)
paramsKeeper.Subspace(govtypes.ModuleName).WithKeyTable(govtypesv1.ParamKeyTable())
paramsKeeper.Subspace(govtypes.ModuleName)
paramsKeeper.Subspace(crisistypes.ModuleName)
paramsKeeper.Subspace(ibctransfertypes.ModuleName)
paramsKeeper.Subspace(icaexported.ModuleName)
Expand Down
6 changes: 0 additions & 6 deletions integration_tests/auction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,12 +276,6 @@ func (s *IntegrationTestSuite) TestAuction() {
endedAuctionResponse, err := auctionQueryClient.QueryEndedAuction(context.Background(), &types.QueryEndedAuctionRequest{AuctionId: uint32(1)})
s.Require().NoError(err)

node, err = orchClientCtx.GetNode()
s.Require().NoError(err)
status, err = node.Status(context.Background())
s.Require().NoError(err)
currentBlockHeight = status.SyncInfo.LatestBlockHeight

expectedEndedAuction := types.Auction{
Id: uint32(1),
StartingTokensForSale: sdk.NewCoin("gravity0x3506424f91fd33084466f402d5d97f05f8e3b4af", sdk.NewInt(5000000000)),
Expand Down
23 changes: 16 additions & 7 deletions integration_tests/incentives_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,23 +210,32 @@ func (s *IntegrationTestSuite) queryValidatorRewards(ctx context.Context, valOpe
return rewardsRes.Rewards.Rewards.AmountOf(params.BaseCoinUnit)
}

func (s *IntegrationTestSuite) getCurrentHeight(clientCtx *client.Context) int64 {
func (s *IntegrationTestSuite) getCurrentHeight(clientCtx *client.Context) (int64, error) {
node, err := clientCtx.GetNode()
s.Require().NoError(err)
if err != nil {
return 0, err
}
status, err := node.Status(context.Background())
s.Require().NoError(err)

return status.SyncInfo.LatestBlockHeight
if err != nil {
return 0, err
}
return status.SyncInfo.LatestBlockHeight, nil
}

func (s *IntegrationTestSuite) getRewardAmountAndHeight(ctx context.Context, distQueryClient disttypes.QueryClient, operatorAddress string, clientCtx *client.Context) (sdk.Dec, int64) {
var amount sdk.Dec
var height int64

s.Require().Eventually(func() bool {
initialHeight := s.getCurrentHeight(clientCtx)
initialHeight, err := s.getCurrentHeight(clientCtx)
if err != nil {
return false
}
amount = s.queryValidatorRewards(ctx, operatorAddress, distQueryClient)
height = s.getCurrentHeight(clientCtx)
height, err = s.getCurrentHeight(clientCtx)
if err != nil {
return false
}
return initialHeight == height
}, time.Second*30, time.Second*1, "failed to reliably determine height of reward sample")

Expand Down
2 changes: 0 additions & 2 deletions integration_tests/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,8 +403,6 @@ func (s *IntegrationTestSuite) initGenesis() {
distGenState := disttypes.DefaultGenesisState()
s.Require().NoError(cdc.UnmarshalJSON(appGenState[minttypes.ModuleName], &mintGenState))
distGenState.Params.CommunityTax = sdk.ZeroDec()
distGenState.Params.BaseProposerReward = sdk.ZeroDec()
distGenState.Params.BonusProposerReward = sdk.ZeroDec()
distGenState.FeePool.CommunityPool = sdk.NewDecCoins(sdk.NewDecCoin(params.BaseCoinUnit, sdk.NewInt(1000000000)))
bz, err = cdc.MarshalJSON(distGenState)
s.Require().NoError(err)
Expand Down
6 changes: 3 additions & 3 deletions x/auction/client/cli/tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import (
"os"
"testing"

"github.com/cosmos/cosmos-sdk/testutil"
"github.com/peggyjv/sommelier/v7/x/auction/types"

"github.com/cosmos/cosmos-sdk/testutil"
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
"github.com/stretchr/testify/require"
)

func TestParseSetTokenPricesProposal(t *testing.T) {
encodingConfig := testutil.TestEncodingConfig()
encodingConfig := moduletestutil.MakeTestEncodingConfig()

okJSON := testutil.WriteToNewTempFile(t, `
{
Expand All @@ -33,7 +33,7 @@ func TestParseSetTokenPricesProposal(t *testing.T) {

require.Equal(t, "My token proposal", proposal.Title)
require.Equal(t, "Contains a usomm price update", proposal.Description)
require.Equal(t, "denom:\"usomm\" exponent:\"6\" usd_price:\"4200000000000000000\" ", proposal.TokenPrices[0].String())
require.Equal(t, "denom:\"usomm\" exponent:6 usd_price:\"4200000000000000000\" ", proposal.TokenPrices[0].String())
require.Equal(t, "10000usomm", proposal.Deposit)
}

Expand Down
2 changes: 1 addition & 1 deletion x/auction/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func (AppModule) GenerateGenesisState(simState *module.SimulationState) {

// ProposalContents returns all the distribution content functions used to
// simulate governance proposals.
func (am AppModule) ProposalContents(_ module.SimulationState) []sim.WeightedProposalContent {
func (am AppModule) ProposalContents(_ module.SimulationState) []sim.WeightedProposalMsg {
return nil
}

Expand Down
17 changes: 9 additions & 8 deletions x/axelarcork/client/cli/tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ import (
"github.com/peggyjv/sommelier/v7/x/axelarcork/types"

"github.com/cosmos/cosmos-sdk/testutil"
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
"github.com/stretchr/testify/require"
)

func TestParseAddManagedCellarsProposal(t *testing.T) {
encodingConfig := testutil.TestEncodingConfig()
encodingConfig := moduletestutil.MakeTestEncodingConfig()

okJSON := testutil.WriteToNewTempFile(t, `
{
Expand Down Expand Up @@ -42,7 +43,7 @@ func TestParseAddManagedCellarsProposal(t *testing.T) {
}

func TestParseRemoveManagedCellarsProposal(t *testing.T) {
encodingConfig := testutil.TestEncodingConfig()
encodingConfig := moduletestutil.MakeTestEncodingConfig()

okJSON := testutil.WriteToNewTempFile(t, `
{
Expand Down Expand Up @@ -70,7 +71,7 @@ func TestParseRemoveManagedCellarsProposal(t *testing.T) {
}

func TestParseSubmitScheduledCorkProposal(t *testing.T) {
encodingConfig := testutil.TestEncodingConfig()
encodingConfig := moduletestutil.MakeTestEncodingConfig()

okJSON := testutil.WriteToNewTempFile(t, `
{
Expand Down Expand Up @@ -103,7 +104,7 @@ func TestParseSubmitScheduledCorkProposal(t *testing.T) {
}

func TestParseAxelarCommunityPoolSpendProposal(t *testing.T) {
encodingConfig := testutil.TestEncodingConfig()
encodingConfig := moduletestutil.MakeTestEncodingConfig()

okJSON := testutil.WriteToNewTempFile(t, `
{
Expand Down Expand Up @@ -132,7 +133,7 @@ func TestParseAxelarCommunityPoolSpendProposal(t *testing.T) {
}

func TestParseAddChainConfigurationProposal(t *testing.T) {
encodingConfig := testutil.TestEncodingConfig()
encodingConfig := moduletestutil.MakeTestEncodingConfig()

okJSON := testutil.WriteToNewTempFile(t, `
{
Expand Down Expand Up @@ -171,7 +172,7 @@ func TestParseAddChainConfigurationProposal(t *testing.T) {
}

func TestParseRemoveChainConfigurationProposal(t *testing.T) {
encodingConfig := testutil.TestEncodingConfig()
encodingConfig := moduletestutil.MakeTestEncodingConfig()

okJSON := testutil.WriteToNewTempFile(t, `
{
Expand All @@ -196,7 +197,7 @@ func TestParseRemoveChainConfigurationProposal(t *testing.T) {
}

func TestParseUpgradeAxelarProxyContractProposal(t *testing.T) {
encodingConfig := testutil.TestEncodingConfig()
encodingConfig := moduletestutil.MakeTestEncodingConfig()

okJSON := testutil.WriteToNewTempFile(t, `
{
Expand All @@ -223,7 +224,7 @@ func TestParseUpgradeAxelarProxyContractProposal(t *testing.T) {
}

func TestParseCancelAxelarProxyContractUpgradeProposal(t *testing.T) {
encodingConfig := testutil.TestEncodingConfig()
encodingConfig := moduletestutil.MakeTestEncodingConfig()

okJSON := testutil.WriteToNewTempFile(t, `
{
Expand Down
2 changes: 1 addition & 1 deletion x/axelarcork/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func (AppModule) GenerateGenesisState(simState *module.SimulationState) {

// ProposalContents returns all the cork content functions used to
// simulate governance proposals.
func (am AppModule) ProposalContents(_ module.SimulationState) []sim.WeightedProposalContent {
func (am AppModule) ProposalContents(_ module.SimulationState) []sim.WeightedProposalMsg {
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion x/cellarfees/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func (AppModule) GenerateGenesisState(simState *module.SimulationState) {}

// ProposalContents returns all the cellarfees content functions used to
// simulate governance proposals.
func (am AppModule) ProposalContents(_ module.SimulationState) []sim.WeightedProposalContent {
func (am AppModule) ProposalContents(_ module.SimulationState) []sim.WeightedProposalMsg {
return nil
}

Expand Down
7 changes: 4 additions & 3 deletions x/cork/client/cli/tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import (
types "github.com/peggyjv/sommelier/v7/x/cork/types/v2"

"github.com/cosmos/cosmos-sdk/testutil"
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
"github.com/stretchr/testify/require"
)

func TestParseAddManagedCellarsProposal(t *testing.T) {
encodingConfig := testutil.TestEncodingConfig()
encodingConfig := moduletestutil.MakeTestEncodingConfig()

okJSON := testutil.WriteToNewTempFile(t, `
{
Expand Down Expand Up @@ -39,7 +40,7 @@ func TestParseAddManagedCellarsProposal(t *testing.T) {
}

func TestParseRemoveManagedCellarsProposal(t *testing.T) {
encodingConfig := testutil.TestEncodingConfig()
encodingConfig := moduletestutil.MakeTestEncodingConfig()

okJSON := testutil.WriteToNewTempFile(t, `
{
Expand All @@ -65,7 +66,7 @@ func TestParseRemoveManagedCellarsProposal(t *testing.T) {
}

func TestParseSubmitScheduledCorkProposal(t *testing.T) {
encodingConfig := testutil.TestEncodingConfig()
encodingConfig := moduletestutil.MakeTestEncodingConfig()

okJSON := testutil.WriteToNewTempFile(t, `
{
Expand Down
2 changes: 1 addition & 1 deletion x/cork/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func (AppModule) GenerateGenesisState(simState *module.SimulationState) {

// ProposalContents returns all the cork content functions used to
// simulate governance proposals.
func (am AppModule) ProposalContents(_ module.SimulationState) []sim.WeightedProposalContent {
func (am AppModule) ProposalContents(_ module.SimulationState) []sim.WeightedProposalMsg {
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion x/incentives/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func (AppModule) GenerateGenesisState(simState *module.SimulationState) {

// ProposalContents returns all the distribution content functions used to
// simulate governance proposals.
func (am AppModule) ProposalContents(_ module.SimulationState) []sim.WeightedProposalContent {
func (am AppModule) ProposalContents(_ module.SimulationState) []sim.WeightedProposalMsg {
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion x/pubsub/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func (AppModule) GenerateGenesisState(simState *module.SimulationState) {}

// ProposalContents returns all the content functions used to
// simulate governance proposals.
func (am AppModule) ProposalContents(_ module.SimulationState) []sim.WeightedProposalContent {
func (am AppModule) ProposalContents(_ module.SimulationState) []sim.WeightedProposalMsg {
return nil
}

Expand Down
Loading