Skip to content

Commit

Permalink
address comment
Browse files Browse the repository at this point in the history
  • Loading branch information
likhita-809 committed Dec 11, 2023
1 parent b7bd994 commit 6685fb6
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 112 deletions.
14 changes: 7 additions & 7 deletions x/gov/keeper/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ import (
)

var (
_, _, addr = testdata.KeyTestPubAddr()
govAcct = authtypes.NewModuleAddress(types.ModuleName)
poolAcct = authtypes.NewModuleAddress(pooltypes.ModuleName)
TestProposal, _ = getTestProposal()
_, _, addr = testdata.KeyTestPubAddr()
govAcct = authtypes.NewModuleAddress(types.ModuleName)
poolAcct = authtypes.NewModuleAddress(pooltypes.ModuleName)
TestProposal = getTestProposal()
)

// mintModuleName duplicates the mint module's name to avoid a cyclic dependency with x/mint.
Expand All @@ -43,16 +43,16 @@ var (
const mintModuleName = "mint"

// getTestProposal creates and returns a test proposal message.
func getTestProposal() ([]sdk.Msg, error) {
func getTestProposal() []sdk.Msg {
legacyProposalMsg, err := v1.NewLegacyContent(v1beta1.NewTextProposal("Title", "description"), authtypes.NewModuleAddress(types.ModuleName).String())
if err != nil {
return nil, err
panic(err)
}

return []sdk.Msg{
banktypes.NewMsgSend(govAcct, addr, sdk.NewCoins(sdk.NewCoin("stake", math.NewInt(1000)))),
legacyProposalMsg,
}, nil
}
}

type mocks struct {
Expand Down
16 changes: 3 additions & 13 deletions x/gov/keeper/deposit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"testing"

"github.com/cosmos/gogoproto/proto"
"github.com/stretchr/testify/require"

"cosmossdk.io/collections"
Expand Down Expand Up @@ -54,10 +53,7 @@ func TestDeposits(t *testing.T) {
TestAddrs := simtestutil.AddTestAddrsIncremental(bankKeeper, stakingKeeper, ctx, 2, sdkmath.NewInt(10000000*depositMultiplier))
authKeeper.EXPECT().AddressCodec().Return(address.NewBech32Codec("cosmos")).AnyTimes()

var tp []proto.Message
if TestProposal != nil {
tp = TestProposal
}
tp := TestProposal
proposal, err := govKeeper.SubmitProposal(ctx, tp, "", "title", "summary", TestAddrs[0], tc.expedited)
require.NoError(t, err)
proposalID := proposal.Id
Expand Down Expand Up @@ -229,10 +225,7 @@ func TestDepositAmount(t *testing.T) {
err := govKeeper.Params.Set(ctx, params)
require.NoError(t, err)

var tp []proto.Message
if TestProposal != nil {
tp = TestProposal
}
tp := TestProposal
proposal, err := govKeeper.SubmitProposal(ctx, tp, "", "title", "summary", testAddrs[0], false)
require.NoError(t, err)
proposalID := proposal.Id
Expand Down Expand Up @@ -422,10 +415,7 @@ func TestChargeDeposit(t *testing.T) {
err := govKeeper.Params.Set(ctx, params)
require.NoError(t, err)

var tp []proto.Message
if TestProposal != nil {
tp = TestProposal
}
tp := TestProposal
proposal, err := govKeeper.SubmitProposal(ctx, tp, "", "title", "summary", TestAddrs[0], false)
require.NoError(t, err)
proposalID := proposal.Id
Expand Down
51 changes: 9 additions & 42 deletions x/gov/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import (
"fmt"
"time"

"github.com/cosmos/gogoproto/proto"

"cosmossdk.io/math"
v3 "cosmossdk.io/x/gov/migrations/v3"
v1 "cosmossdk.io/x/gov/types/v1"
Expand Down Expand Up @@ -445,10 +443,6 @@ func (suite *KeeperTestSuite) TestLegacyGRPCQueryProposals() {

func (suite *KeeperTestSuite) TestGRPCQueryVote() {
ctx, queryClient, addrs := suite.ctx, suite.queryClient, suite.addrs
var tp []proto.Message
if TestProposal != nil {
tp = TestProposal
}

var (
req *v1.QueryVoteRequest
Expand Down Expand Up @@ -502,7 +496,7 @@ func (suite *KeeperTestSuite) TestGRPCQueryVote() {
"no votes present",
func() {
var err error
proposal, err = suite.govKeeper.SubmitProposal(ctx, tp, "", "title", "summary", addrs[0], false)
proposal, err = suite.govKeeper.SubmitProposal(ctx, TestProposal, "", "title", "summary", addrs[0], false)
suite.Require().NoError(err)

req = &v1.QueryVoteRequest{
Expand Down Expand Up @@ -564,10 +558,7 @@ func (suite *KeeperTestSuite) TestGRPCQueryVote() {

func (suite *KeeperTestSuite) TestLegacyGRPCQueryVote() {
ctx, queryClient, addrs := suite.ctx, suite.legacyQueryClient, suite.addrs
var tp []proto.Message
if TestProposal != nil {
tp = TestProposal
}

var (
req *v1beta1.QueryVoteRequest
expRes *v1beta1.QueryVoteResponse
Expand Down Expand Up @@ -620,7 +611,7 @@ func (suite *KeeperTestSuite) TestLegacyGRPCQueryVote() {
"no votes present",
func() {
var err error
proposal, err = suite.govKeeper.SubmitProposal(ctx, tp, "", "title", "summary", addrs[0], false)
proposal, err = suite.govKeeper.SubmitProposal(ctx, TestProposal, "", "title", "summary", addrs[0], false)
suite.Require().NoError(err)

req = &v1beta1.QueryVoteRequest{
Expand Down Expand Up @@ -683,10 +674,6 @@ func (suite *KeeperTestSuite) TestLegacyGRPCQueryVote() {
func (suite *KeeperTestSuite) TestGRPCQueryVotes() {
suite.reset()
ctx, queryClient := suite.ctx, suite.queryClient
var tp []proto.Message
if TestProposal != nil {
tp = TestProposal
}

addrs := simtestutil.AddTestAddrsIncremental(suite.bankKeeper, suite.stakingKeeper, ctx, 2, math.NewInt(30000000))

Expand Down Expand Up @@ -731,7 +718,7 @@ func (suite *KeeperTestSuite) TestGRPCQueryVotes() {
"create a proposal and get votes",
func() {
var err error
proposal, err = suite.govKeeper.SubmitProposal(ctx, tp, "", "title", "summary", addrs[0], false)
proposal, err = suite.govKeeper.SubmitProposal(ctx, TestProposal, "", "title", "summary", addrs[0], false)
suite.Require().NoError(err)

req = &v1.QueryVotesRequest{
Expand Down Expand Up @@ -791,10 +778,6 @@ func (suite *KeeperTestSuite) TestGRPCQueryVotes() {
func (suite *KeeperTestSuite) TestLegacyGRPCQueryVotes() {
suite.reset()
ctx, queryClient := suite.ctx, suite.legacyQueryClient
var tp []proto.Message
if TestProposal != nil {
tp = TestProposal
}

addrs := simtestutil.AddTestAddrsIncremental(suite.bankKeeper, suite.stakingKeeper, ctx, 2, math.NewInt(30000000))

Expand Down Expand Up @@ -839,7 +822,7 @@ func (suite *KeeperTestSuite) TestLegacyGRPCQueryVotes() {
"create a proposal and get votes",
func() {
var err error
proposal, err = suite.govKeeper.SubmitProposal(ctx, tp, "", "title", "summary", addrs[0], false)
proposal, err = suite.govKeeper.SubmitProposal(ctx, TestProposal, "", "title", "summary", addrs[0], false)
suite.Require().NoError(err)

req = &v1beta1.QueryVotesRequest{
Expand Down Expand Up @@ -1074,10 +1057,6 @@ func (suite *KeeperTestSuite) TestLegacyGRPCQueryParams() {
func (suite *KeeperTestSuite) TestGRPCQueryDeposit() {
suite.reset()
ctx, queryClient, addrs := suite.ctx, suite.queryClient, suite.addrs
var tp []proto.Message
if TestProposal != nil {
tp = TestProposal
}

var (
req *v1.QueryDepositRequest
Expand Down Expand Up @@ -1131,7 +1110,7 @@ func (suite *KeeperTestSuite) TestGRPCQueryDeposit() {
"no deposits proposal",
func() {
var err error
proposal, err = suite.govKeeper.SubmitProposal(ctx, tp, "", "title", "summary", addrs[0], false)
proposal, err = suite.govKeeper.SubmitProposal(ctx, TestProposal, "", "title", "summary", addrs[0], false)
suite.Require().NoError(err)
suite.Require().NotNil(proposal)

Expand Down Expand Up @@ -1180,10 +1159,6 @@ func (suite *KeeperTestSuite) TestGRPCQueryDeposit() {

func (suite *KeeperTestSuite) TestLegacyGRPCQueryDeposit() {
ctx, queryClient, addrs := suite.ctx, suite.legacyQueryClient, suite.addrs
var tp []proto.Message
if TestProposal != nil {
tp = TestProposal
}

var (
req *v1beta1.QueryDepositRequest
Expand Down Expand Up @@ -1237,7 +1212,7 @@ func (suite *KeeperTestSuite) TestLegacyGRPCQueryDeposit() {
"no deposits proposal",
func() {
var err error
proposal, err = suite.govKeeper.SubmitProposal(ctx, tp, "", "title", "summary", addrs[0], false)
proposal, err = suite.govKeeper.SubmitProposal(ctx, TestProposal, "", "title", "summary", addrs[0], false)
suite.Require().NoError(err)
suite.Require().NotNil(proposal)

Expand Down Expand Up @@ -1287,10 +1262,6 @@ func (suite *KeeperTestSuite) TestLegacyGRPCQueryDeposit() {

func (suite *KeeperTestSuite) TestGRPCQueryDeposits() {
ctx, queryClient, addrs := suite.ctx, suite.queryClient, suite.addrs
var tp []proto.Message
if TestProposal != nil {
tp = TestProposal
}

var (
req *v1.QueryDepositsRequest
Expand Down Expand Up @@ -1332,7 +1303,7 @@ func (suite *KeeperTestSuite) TestGRPCQueryDeposits() {
"create a proposal and get deposits",
func() {
var err error
proposal, err = suite.govKeeper.SubmitProposal(ctx, tp, "", "title", "summary", addrs[0], true)
proposal, err = suite.govKeeper.SubmitProposal(ctx, TestProposal, "", "title", "summary", addrs[0], true)
suite.Require().NoError(err)

req = &v1.QueryDepositsRequest{
Expand Down Expand Up @@ -1388,10 +1359,6 @@ func (suite *KeeperTestSuite) TestGRPCQueryDeposits() {
func (suite *KeeperTestSuite) TestLegacyGRPCQueryDeposits() {
suite.reset()
ctx, queryClient, addrs := suite.ctx, suite.legacyQueryClient, suite.addrs
var tp []proto.Message
if TestProposal != nil {
tp = TestProposal
}

var (
req *v1beta1.QueryDepositsRequest
Expand Down Expand Up @@ -1433,7 +1400,7 @@ func (suite *KeeperTestSuite) TestLegacyGRPCQueryDeposits() {
"create a proposal and get deposits",
func() {
var err error
proposal, err = suite.govKeeper.SubmitProposal(ctx, tp, "", "title", "summary", addrs[0], false)
proposal, err = suite.govKeeper.SubmitProposal(ctx, TestProposal, "", "title", "summary", addrs[0], false)
suite.Require().NoError(err)

req = &v1beta1.QueryDepositsRequest{
Expand Down
6 changes: 1 addition & 5 deletions x/gov/keeper/hooks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"testing"
"time"

"github.com/cosmos/gogoproto/proto"
"github.com/stretchr/testify/require"

"cosmossdk.io/x/gov"
Expand Down Expand Up @@ -75,10 +74,7 @@ func TestHooks(t *testing.T) {
require.False(t, govHooksReceiver.AfterProposalFailedMinDepositValid)
require.False(t, govHooksReceiver.AfterProposalVotingPeriodEndedValid)

var tp []proto.Message
if TestProposal != nil {
tp = TestProposal
}
tp := TestProposal
_, err := govKeeper.SubmitProposal(ctx, tp, "", "test", "summary", sdk.AccAddress("cosmos1ghekyjucln7y67ntx7cf27m9dpuxxemn4c8g4r"), false)
require.NoError(t, err)
require.True(t, govHooksReceiver.AfterProposalSubmissionValid)
Expand Down
11 changes: 2 additions & 9 deletions x/gov/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package keeper_test
import (
"testing"

"github.com/cosmos/gogoproto/proto"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"

Expand Down Expand Up @@ -89,10 +88,7 @@ func TestIncrementProposalNumber(t *testing.T) {
addrBz, err := ac.StringToBytes(address1)
require.NoError(t, err)

var tp []proto.Message
if TestProposal != nil {
tp = TestProposal
}
tp := TestProposal
_, err = govKeeper.SubmitProposal(ctx, tp, "", "test", "summary", addrBz, false)
require.NoError(t, err)
_, err = govKeeper.SubmitProposal(ctx, tp, "", "test", "summary", addrBz, false)
Expand All @@ -119,10 +115,7 @@ func TestProposalQueues(t *testing.T) {
authKeeper.EXPECT().AddressCodec().Return(address.NewBech32Codec("cosmos")).AnyTimes()

// create test proposals
var tp []proto.Message
if TestProposal != nil {
tp = TestProposal
}
tp := TestProposal
proposal, err := govKeeper.SubmitProposal(ctx, tp, "", "test", "summary", addrBz, false)
require.NoError(t, err)

Expand Down
9 changes: 1 addition & 8 deletions x/gov/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import (
"strings"
"time"

"github.com/cosmos/gogoproto/proto"

sdkmath "cosmossdk.io/math"
banktypes "cosmossdk.io/x/bank/types"
v1 "cosmossdk.io/x/gov/types/v1"
Expand Down Expand Up @@ -1783,12 +1781,7 @@ func (suite *KeeperTestSuite) TestSubmitProposal_InitialDeposit() {
err := govKeeper.Params.Set(ctx, params)
suite.Require().NoError(err)

var tp []proto.Message
if TestProposal != nil {
tp = TestProposal
}

msg, err := v1.NewMsgSubmitProposal(tp, tc.initialDeposit, address.String(), "test", "Proposal", "description of proposal", false)
msg, err := v1.NewMsgSubmitProposal(TestProposal, tc.initialDeposit, address.String(), "test", "Proposal", "description of proposal", false)
suite.Require().NoError(err)

// System under test
Expand Down
21 changes: 4 additions & 17 deletions x/gov/keeper/proposal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"strings"
"testing"

"github.com/cosmos/gogoproto/proto"
"github.com/stretchr/testify/require"

"cosmossdk.io/collections"
Expand All @@ -30,10 +29,7 @@ func (suite *KeeperTestSuite) TestGetSetProposal() {
}

for _, tc := range testCases {
var tp []proto.Message
if TestProposal != nil {
tp = TestProposal
}
tp := TestProposal
proposal, err := suite.govKeeper.SubmitProposal(suite.ctx, tp, "", "test", "summary", suite.addrs[0], tc.expedited)
suite.Require().NoError(err)
proposalID := proposal.Id
Expand Down Expand Up @@ -61,10 +57,7 @@ func (suite *KeeperTestSuite) TestDeleteProposal() {
// delete non-existing proposal
suite.Require().ErrorIs(suite.govKeeper.DeleteProposal(suite.ctx, 10), collections.ErrNotFound)

var tp []proto.Message
if TestProposal != nil {
tp = TestProposal
}
tp := TestProposal
proposal, err := suite.govKeeper.SubmitProposal(suite.ctx, tp, "", "test", "summary", suite.addrs[0], tc.expedited)
suite.Require().NoError(err)
proposalID := proposal.Id
Expand All @@ -88,10 +81,7 @@ func (suite *KeeperTestSuite) TestActivateVotingPeriod() {
}

for _, tc := range testCases {
var tp []proto.Message
if TestProposal != nil {
tp = TestProposal
}
tp := TestProposal
proposal, err := suite.govKeeper.SubmitProposal(suite.ctx, tp, "", "test", "summary", suite.addrs[0], tc.expedited)
suite.Require().NoError(err)

Expand Down Expand Up @@ -122,10 +112,7 @@ func (suite *KeeperTestSuite) TestDeleteProposalInVotingPeriod() {

for _, tc := range testCases {
suite.reset()
var tp []proto.Message
if TestProposal != nil {
tp = TestProposal
}
tp := TestProposal
proposal, err := suite.govKeeper.SubmitProposal(suite.ctx, tp, "", "test", "summary", suite.addrs[0], tc.expedited)
suite.Require().NoError(err)
suite.Require().Nil(proposal.VotingStartTime)
Expand Down
Loading

0 comments on commit 6685fb6

Please sign in to comment.