Skip to content

Commit

Permalink
wip: trying to use GovGenSimApp
Browse files Browse the repository at this point in the history
  • Loading branch information
tbruyelle committed Feb 9, 2024
1 parent b12eb1a commit 8dba5e6
Show file tree
Hide file tree
Showing 25 changed files with 98 additions and 67 deletions.
2 changes: 1 addition & 1 deletion ante/fee_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/tx"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/simapp"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/tx/signing"
Expand All @@ -19,7 +20,6 @@ import (
"github.com/atomone-hub/govgen/v1/ante"
govgenapp "github.com/atomone-hub/govgen/v1/app"
govgenhelpers "github.com/atomone-hub/govgen/v1/app/helpers"
"github.com/atomone-hub/govgen/v1/simapp"
)

type FeeIntegrationTestSuite struct {
Expand Down
2 changes: 1 addition & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/cosmos/cosmos-sdk/server/api"
"github.com/cosmos/cosmos-sdk/server/config"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
"github.com/cosmos/cosmos-sdk/simapp"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/version"
Expand All @@ -45,7 +46,6 @@ import (
"github.com/atomone-hub/govgen/v1/app/keepers"
govgenappparams "github.com/atomone-hub/govgen/v1/app/params"
"github.com/atomone-hub/govgen/v1/app/upgrades"
"github.com/atomone-hub/govgen/v1/simapp"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion app/sim/sim_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
simappparams "github.com/cosmos/cosmos-sdk/simapp/params"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
Expand All @@ -21,7 +22,6 @@ import (
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"

govgen "github.com/atomone-hub/govgen/v1/app"
simappparams "github.com/atomone-hub/govgen/v1/simapp/params"
)

// AppStateFn returns the initial application state using a genesis or the simulation parameters.
Expand Down
2 changes: 1 addition & 1 deletion app/sim/sim_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import (
dbm "github.com/tendermint/tm-db"

"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/simapp/helpers"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/kv"
"github.com/cosmos/cosmos-sdk/types/module"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"

govgen "github.com/atomone-hub/govgen/v1/app"
"github.com/atomone-hub/govgen/v1/simapp/helpers"
)

// SetupSimulation creates the config, db (levelDB), temporary directory and logger for
Expand Down
2 changes: 1 addition & 1 deletion app/sim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
dbm "github.com/tendermint/tm-db"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/simapp"
"github.com/cosmos/cosmos-sdk/store"
simulation2 "github.com/cosmos/cosmos-sdk/types/simulation"
"github.com/cosmos/cosmos-sdk/x/simulation"
Expand All @@ -20,7 +21,6 @@ import (
"github.com/atomone-hub/govgen/v1/app/helpers"
"github.com/atomone-hub/govgen/v1/app/params"
"github.com/atomone-hub/govgen/v1/app/sim"
"github.com/atomone-hub/govgen/v1/simapp"
)

func init() {
Expand Down
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ require (
github.com/armon/go-metrics v0.4.1
github.com/cosmos/cosmos-sdk v0.45.16
github.com/gogo/protobuf v1.3.3
github.com/golang/mock v1.6.0
github.com/golang/protobuf v1.5.3
github.com/google/gofuzz v1.2.0
github.com/gorilla/mux v1.8.1
Expand All @@ -16,7 +15,6 @@ require (
github.com/spf13/cast v1.5.1
github.com/spf13/cobra v1.8.0
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.17.0
github.com/stretchr/testify v1.8.4
github.com/tendermint/tendermint v0.34.27
github.com/tendermint/tm-db v0.6.7
Expand Down Expand Up @@ -124,6 +122,7 @@ require (
github.com/sasha-s/go-deadlock v0.3.1 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.10.0 // indirect
github.com/spf13/viper v1.17.0 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 // indirect
github.com/tecbot/gorocksdb v0.0.0-20191217155057-f0fad39f321c // indirect
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,6 @@ github.com/golang/mock v1.4.1/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt
github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw=
github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4=
github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.0/go.mod h1:Qd/q+1AKNOZr9uGQzbzCmRO6sUih6GTPZv6a1/R87v0=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
Expand Down Expand Up @@ -1403,7 +1402,6 @@ golang.org/x/tools v0.0.0-20210105154028-b0ab187a4818/go.mod h1:emZCQorbCU4vsT4f
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.0.0-20210108195828-e2f9c7f1fc8e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0=
golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.3/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.13.0 h1:Iey4qkscZuv0VvIt8E0neZjtPVQFSc870HQ448QgEmQ=
Expand Down
27 changes: 14 additions & 13 deletions x/gov/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,19 @@ import (
abci "github.com/tendermint/tendermint/abci/types"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"

"github.com/atomone-hub/govgen/v1/simapp"
"github.com/atomone-hub/govgen/v1/x/gov"
"github.com/atomone-hub/govgen/v1/x/gov/client/testutil"

"github.com/cosmos/cosmos-sdk/simapp"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/gov/types"
"github.com/cosmos/cosmos-sdk/x/staking"
)

func TestTickExpiredDepositPeriod(t *testing.T) {
app := simapp.Setup(false)
app := testutil.SimAppSetup(false)
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
addrs := simapp.AddTestAddrs(app, ctx, 10, valTokens)
addrs := simapp.AddTestAddrs(app.SimApp, ctx, 10, valTokens)

header := tmproto.Header{Height: app.LastBlockHeight() + 1}
app.BeginBlock(abci.RequestBeginBlock{Header: header})
Expand Down Expand Up @@ -70,9 +71,9 @@ func TestTickExpiredDepositPeriod(t *testing.T) {
}

func TestTickMultipleExpiredDepositPeriod(t *testing.T) {
app := simapp.Setup(false)
app := testutil.SimAppSetup(false)
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
addrs := simapp.AddTestAddrs(app, ctx, 10, valTokens)
addrs := simapp.AddTestAddrs(app.SimApp, ctx, 10, valTokens)

header := tmproto.Header{Height: app.LastBlockHeight() + 1}
app.BeginBlock(abci.RequestBeginBlock{Header: header})
Expand Down Expand Up @@ -147,9 +148,9 @@ func TestTickMultipleExpiredDepositPeriod(t *testing.T) {
}

func TestTickPassedDepositPeriod(t *testing.T) {
app := simapp.Setup(false)
app := testutil.SimAppSetup(false)
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
addrs := simapp.AddTestAddrs(app, ctx, 10, valTokens)
addrs := simapp.AddTestAddrs(app.SimApp, ctx, 10, valTokens)

header := tmproto.Header{Height: app.LastBlockHeight() + 1}
app.BeginBlock(abci.RequestBeginBlock{Header: header})
Expand Down Expand Up @@ -204,9 +205,9 @@ func TestTickPassedDepositPeriod(t *testing.T) {
}

func TestTickPassedVotingPeriod(t *testing.T) {
app := simapp.Setup(false)
app := testutil.SimAppSetup(false)
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
addrs := simapp.AddTestAddrs(app, ctx, 10, valTokens)
addrs := simapp.AddTestAddrs(app.SimApp, ctx, 10, valTokens)

SortAddresses(addrs)

Expand Down Expand Up @@ -272,9 +273,9 @@ func TestTickPassedVotingPeriod(t *testing.T) {
}

func TestProposalPassedEndblocker(t *testing.T) {
app := simapp.Setup(false)
app := testutil.SimAppSetup(false)
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
addrs := simapp.AddTestAddrs(app, ctx, 10, valTokens)
addrs := simapp.AddTestAddrs(app.SimApp, ctx, 10, valTokens)

SortAddresses(addrs)

Expand Down Expand Up @@ -323,9 +324,9 @@ func TestProposalPassedEndblocker(t *testing.T) {
}

func TestEndBlockerProposalHandlerFailed(t *testing.T) {
app := simapp.Setup(false)
app := testutil.SimAppSetup(false)
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
addrs := simapp.AddTestAddrs(app, ctx, 1, valTokens)
addrs := simapp.AddTestAddrs(app.SimApp, ctx, 1, valTokens)

SortAddresses(addrs)

Expand Down
36 changes: 36 additions & 0 deletions x/gov/client/testutil/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,50 @@ import (
"fmt"

govcli "github.com/atomone-hub/govgen/v1/x/gov/client/cli"
"github.com/atomone-hub/govgen/v1/x/gov/keeper"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/simapp"
"github.com/cosmos/cosmos-sdk/testutil"
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
sdk "github.com/cosmos/cosmos-sdk/types"
distr "github.com/cosmos/cosmos-sdk/x/distribution"
distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
"github.com/cosmos/cosmos-sdk/x/params"
paramproposal "github.com/cosmos/cosmos-sdk/x/params/types/proposal"
"github.com/cosmos/cosmos-sdk/x/upgrade"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
)

type GovGenSimApp struct {
*simapp.SimApp
GovKeeper keeper.Keeper
}

func SimAppSetup(isCheckTx bool) GovGenSimApp {
app := simapp.Setup(isCheckTx)
govRouter := govtypes.NewRouter()
govRouter.AddRoute(govtypes.RouterKey, govtypes.ProposalHandler).
AddRoute(paramproposal.RouterKey, params.NewParamChangeProposalHandler(app.ParamsKeeper)).
AddRoute(distrtypes.RouterKey, distr.NewCommunityPoolSpendProposalHandler(app.DistrKeeper)).
AddRoute(upgradetypes.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(app.UpgradeKeeper))
keeper := keeper.NewKeeper(
app.AppCodec(), app.GetKey(govtypes.StoreKey), app.GetSubspace(govtypes.ModuleName), app.AccountKeeper, app.BankKeeper,
app.StakingKeeper, govRouter,
)
keeper = *keeper.SetHooks(
govtypes.NewMultiGovHooks(
// register the governance hooks
),
)
return GovGenSimApp{
SimApp: app,
GovKeeper: keeper,
}
}

var commonArgs = []string{
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),
Expand Down
2 changes: 1 addition & 1 deletion x/gov/client/utils/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import (
ctypes "github.com/tendermint/tendermint/rpc/core/types"
tmtypes "github.com/tendermint/tendermint/types"

"github.com/atomone-hub/govgen/v1/simapp"
"github.com/atomone-hub/govgen/v1/x/gov/client/utils"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/simapp"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth/legacy/legacytx"
"github.com/cosmos/cosmos-sdk/x/gov/types"
Expand Down
17 changes: 10 additions & 7 deletions x/gov/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ import (
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
dbm "github.com/tendermint/tm-db"

"github.com/atomone-hub/govgen/v1/simapp"
"github.com/atomone-hub/govgen/v1/x/gov"
"github.com/atomone-hub/govgen/v1/x/gov/client/testutil"

"github.com/cosmos/cosmos-sdk/simapp"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
Expand All @@ -21,9 +22,9 @@ import (
)

func TestImportExportQueues(t *testing.T) {
app := simapp.Setup(false)
app := testutil.SimAppSetup(false)
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
addrs := simapp.AddTestAddrs(app, ctx, 2, valTokens)
addrs := simapp.AddTestAddrs(app.SimApp, ctx, 2, valTokens)

SortAddresses(addrs)

Expand Down Expand Up @@ -70,7 +71,9 @@ func TestImportExportQueues(t *testing.T) {
}

db := dbm.NewMemDB()
app2 := simapp.NewSimApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, simapp.DefaultNodeHome, 0, simapp.MakeTestEncodingConfig(), simapp.EmptyAppOptions{})
app2 := testutil.GovGenSimApp{
SimApp: simapp.NewSimApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, simapp.DefaultNodeHome, 0, simapp.MakeTestEncodingConfig(), simapp.EmptyAppOptions{}),
}

app2.InitChain(
abci.RequestInitChain{
Expand Down Expand Up @@ -114,7 +117,7 @@ func TestImportExportQueues(t *testing.T) {
}

func TestImportExportQueues_ErrorUnconsistentState(t *testing.T) {
app := simapp.Setup(false)
app := testutil.SimAppSetup(false)
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
require.Panics(t, func() {
gov.InitGenesis(ctx, app.AccountKeeper, app.BankKeeper, app.GovKeeper, &types.GenesisState{
Expand All @@ -135,9 +138,9 @@ func TestImportExportQueues_ErrorUnconsistentState(t *testing.T) {
}

func TestEqualProposals(t *testing.T) {
app := simapp.Setup(false)
app := testutil.SimAppSetup(false)
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
addrs := simapp.AddTestAddrs(app, ctx, 2, valTokens)
addrs := simapp.AddTestAddrs(app.SimApp, ctx, 2, valTokens)

SortAddresses(addrs)

Expand Down
3 changes: 1 addition & 2 deletions x/gov/keeper/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import (

"github.com/stretchr/testify/require"

"github.com/atomone-hub/govgen/v1/simapp"

"github.com/cosmos/cosmos-sdk/simapp"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/gov/types"
"github.com/cosmos/cosmos-sdk/x/staking"
Expand Down
3 changes: 1 addition & 2 deletions x/gov/keeper/deposit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import (
"github.com/stretchr/testify/require"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"

"github.com/atomone-hub/govgen/v1/simapp"

"github.com/cosmos/cosmos-sdk/simapp"
sdk "github.com/cosmos/cosmos-sdk/types"
)

Expand Down
3 changes: 1 addition & 2 deletions x/gov/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import (
"fmt"
"strconv"

"github.com/atomone-hub/govgen/v1/simapp"

"github.com/cosmos/cosmos-sdk/simapp"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/query"
"github.com/cosmos/cosmos-sdk/x/gov/types"
Expand Down
7 changes: 4 additions & 3 deletions x/gov/keeper/hooks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import (
"github.com/stretchr/testify/require"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"

"github.com/atomone-hub/govgen/v1/simapp"
"github.com/atomone-hub/govgen/v1/x/gov"
"github.com/atomone-hub/govgen/v1/x/gov/client/testutil"
"github.com/atomone-hub/govgen/v1/x/gov/keeper"

"github.com/cosmos/cosmos-sdk/simapp"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/gov/types"
)
Expand Down Expand Up @@ -47,11 +48,11 @@ func (h *MockGovHooksReceiver) AfterProposalVotingPeriodEnded(ctx sdk.Context, p
}

func TestHooks(t *testing.T) {
app := simapp.Setup(false)
app := testutil.SimAppSetup(false)
ctx := app.BaseApp.NewContext(false, tmproto.Header{})

minDeposit := app.GovKeeper.GetDepositParams(ctx).MinDeposit
addrs := simapp.AddTestAddrs(app, ctx, 1, minDeposit[0].Amount)
addrs := simapp.AddTestAddrs(app.SimApp, ctx, 1, minDeposit[0].Amount)

govHooksReceiver := MockGovHooksReceiver{}

Expand Down
3 changes: 1 addition & 2 deletions x/gov/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ import (
"github.com/stretchr/testify/suite"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"

"github.com/atomone-hub/govgen/v1/simapp"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/simapp"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/gov/types"
)
Expand Down
Loading

0 comments on commit 8dba5e6

Please sign in to comment.