Skip to content

Commit

Permalink
fix simulation err
Browse files Browse the repository at this point in the history
  • Loading branch information
skyargos committed Jul 19, 2024
1 parent 6d65360 commit 0a1e85f
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 1,073 deletions.
10 changes: 4 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ module github.com/shentufoundation/shentu/v2
go 1.21.1

require (
cosmossdk.io/api v0.3.1
cosmossdk.io/core v0.5.1
cosmossdk.io/errors v1.0.1
cosmossdk.io/math v1.3.0
cosmossdk.io/tools/rosetta v0.2.1
github.com/cometbft/cometbft v0.37.6
github.com/cometbft/cometbft-db v0.11.0
github.com/cosmos/cosmos-proto v1.0.0-beta.5
Expand All @@ -27,7 +28,6 @@ require (
github.com/spf13/cobra v1.8.0
github.com/spf13/viper v1.18.2
github.com/stretchr/testify v1.9.0
github.com/tendermint/tendermint v0.35.9
github.com/test-go/testify v1.1.4
google.golang.org/genproto/googleapis/api v0.0.0-20240227224415-6ceb2ff114de
google.golang.org/protobuf v1.33.0
Expand All @@ -50,10 +50,9 @@ require (

require (
4d63.com/gochecknoglobals v0.1.0 // indirect
cosmossdk.io/api v0.3.1 // indirect
cosmossdk.io/core v0.5.1 // indirect
cosmossdk.io/depinject v1.0.0-alpha.4 // indirect
cosmossdk.io/log v1.3.1 // indirect
cosmossdk.io/tools/rosetta v0.2.1 // indirect
filippo.io/edwards25519 v1.0.0 // indirect
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
github.com/99designs/keyring v1.2.1 // indirect
Expand All @@ -76,6 +75,7 @@ require (
github.com/ashanbrown/forbidigo v1.3.0 // indirect
github.com/ashanbrown/makezero v1.1.1 // indirect
github.com/aws/aws-sdk-go v1.44.203 // indirect
github.com/benbjohnson/clock v1.3.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect
github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816 // indirect
Expand All @@ -85,7 +85,6 @@ require (
github.com/bradleyfalzon/ghinstallation v0.1.2 // indirect
github.com/breml/bidichk v0.2.3 // indirect
github.com/breml/errchkjson v0.3.0 // indirect
github.com/btcsuite/btcd v0.22.1 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect
github.com/butuzov/ireturn v0.1.1 // indirect
github.com/cenkalti/backoff/v4 v4.1.3 // indirect
Expand Down Expand Up @@ -253,7 +252,6 @@ require (
github.com/nishanths/exhaustive v0.8.3 // indirect
github.com/nishanths/predeclared v0.2.2 // indirect
github.com/nlopes/slack v0.6.0 // indirect
github.com/oasisprotocol/curve25519-voi v0.0.0-20210609091139-0a56a4bca00b // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/onsi/ginkgo/v2 v2.7.0 // indirect
github.com/onsi/gomega v1.26.0 // indirect
Expand Down
470 changes: 0 additions & 470 deletions go.sum

Large diffs are not rendered by default.

134 changes: 0 additions & 134 deletions x/gov/genesis_test.go

This file was deleted.

12 changes: 3 additions & 9 deletions x/gov/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (

"github.com/shentufoundation/shentu/v2/x/gov/client/cli"
"github.com/shentufoundation/shentu/v2/x/gov/keeper"
"github.com/shentufoundation/shentu/v2/x/gov/simulation"
typesv1 "github.com/shentufoundation/shentu/v2/x/gov/types/v1"
)

Expand Down Expand Up @@ -225,13 +226,7 @@ func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.Val

// GenerateGenesisState creates a randomized GenState of this module.
func (AppModule) GenerateGenesisState(simState *module.SimulationState) {
//simulation.RandomizedGenState(simState)
}

// ProposalContents returns all the gov content functions used to
// simulate governance proposals.
func (AppModule) ProposalContents(_ module.SimulationState) []simtypes.WeightedProposalContent {
return govsim.ProposalContents()
simulation.RandomizedGenState(simState)
}

// RegisterStoreDecoder registers a decoder for gov module.
Expand All @@ -241,6 +236,5 @@ func (am AppModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) {

// WeightedOperations returns the all the gov module operations with their respective weights.
func (am AppModule) WeightedOperations(simState module.SimulationState) []simtypes.WeightedOperation {
//return simulation.WeightedOperations(simState.AppParams, simState.Cdc, am.accountKeeper, am.bankKeeper, am.keeper.CertKeeper, am.keeper, simState.Contents)
return []simtypes.WeightedOperation{}
return nil
}
151 changes: 86 additions & 65 deletions x/gov/simulation/genesis.go
Original file line number Diff line number Diff line change
@@ -1,67 +1,88 @@
package simulation

//
//import (
// "math/rand"
// "time"
//
// sdk "github.com/cosmos/cosmos-sdk/types"
// "github.com/cosmos/cosmos-sdk/types/module"
// sim "github.com/cosmos/cosmos-sdk/types/simulation"
// govTypes "github.com/cosmos/cosmos-sdk/x/gov/types"
// govtypesv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
// stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
//
// typesv1 "github.com/shentufoundation/shentu/v2/x/gov/types/v1"
//)
//
//// RandomizedGenState creates a randomGenesis state for module simulation.
//func RandomizedGenState(simState *module.SimulationState) {
// r := simState.Rand
// gs := typesv1.GenesisState{}
// gs.StartingProposalId = uint64(simState.Rand.Intn(100))
//
// a := GenerateADepositParams(r)
// gs.DepositParams = &a
// b := GenerateAVotingParams(r)
// gs.VotingParams = &b
// tallyParams := GenerateTallyParams(r)
// gs.TallyParams = &tallyParams
// gs.CustomParams = &typesv1.CustomParams{
// CertifierUpdateSecurityVoteTally: &tallyParams,
// CertifierUpdateStakeVoteTally: &tallyParams,
// }
//
// // For the shield module, locking period should be shorter than unbonding period.
// stakingGenStatebz := simState.GenState[stakingtypes.ModuleName]
// var stakingGenState stakingtypes.GenesisState
// simState.Cdc.MustUnmarshalJSON(stakingGenStatebz, &stakingGenState)
// ubdTime := stakingGenState.Params.UnbondingTime
// if *gs.VotingParams.VotingPeriod*2 >= ubdTime {
// votingPeriod := time.Duration(sim.RandIntBetween(r, int(ubdTime)/10, int(ubdTime)/2))
// gs.VotingParams.VotingPeriod = &votingPeriod
// }
//
// simState.GenState[govTypes.ModuleName] = simState.Cdc.MustMarshalJSON(&gs)
//}
//
//// GenerateADepositParams returns a DepositParams object with all of its fields randomized.
//func GenerateADepositParams(r *rand.Rand) govtypesv1.DepositParams {
// minDeposit := sdk.NewCoins(sdk.NewInt64Coin(sdk.DefaultBondDenom, int64(sim.RandIntBetween(r, 1, 10))))
// maxDepositPeriod := sim.RandIntBetween(r, 1, 2*60*60*24*2)
// return govtypesv1.NewDepositParams(minDeposit, time.Duration(maxDepositPeriod)*time.Second)
//}
//
//// GenerateAVotingParams returns a VotingParams object with all of its fields randomized.
//func GenerateAVotingParams(r *rand.Rand) govtypesv1.VotingParams {
// votingPeriod := sim.RandIntBetween(r, 1, 2*60*60*24*2)
// return govtypesv1.NewVotingParams(time.Duration(votingPeriod) * time.Second)
//}
//
//// GenerateTallyParams returns a TallyParams object with all of its fields randomized.
//func GenerateTallyParams(r *rand.Rand) govtypesv1.TallyParams {
// quorum := sdk.NewDecWithPrec(int64(sim.RandIntBetween(r, 334, 500)), 3)
// threshold := sdk.NewDecWithPrec(int64(sim.RandIntBetween(r, 450, 550)), 3)
// veto := sdk.NewDecWithPrec(int64(sim.RandIntBetween(r, 250, 334)), 3)
// return govtypesv1.NewTallyParams(quorum, threshold, veto)
//}
import (
"encoding/json"
"fmt"
"math/rand"
"time"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
govsim "github.com/cosmos/cosmos-sdk/x/gov/simulation"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
govtypesv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"

typesv1 "github.com/shentufoundation/shentu/v2/x/gov/types/v1"
)

// RandomizedGenState generates a random GenesisState for gov
func RandomizedGenState(simState *module.SimulationState) {
startingProposalID := uint64(simState.Rand.Intn(100))

var minDeposit sdk.Coins
simState.AppParams.GetOrGenerate(
simState.Cdc, govsim.DepositParamsMinDeposit, &minDeposit, simState.Rand,
func(r *rand.Rand) { minDeposit = govsim.GenDepositParamsMinDeposit(r) },
)

var depositPeriod time.Duration
simState.AppParams.GetOrGenerate(
simState.Cdc, govsim.DepositParamsDepositPeriod, &depositPeriod, simState.Rand,
func(r *rand.Rand) { depositPeriod = govsim.GenDepositParamsDepositPeriod(r) },
)

var minInitialDepositRatio sdk.Dec
simState.AppParams.GetOrGenerate(
simState.Cdc, govsim.DepositMinInitialRatio, &minInitialDepositRatio, simState.Rand,
func(r *rand.Rand) { minInitialDepositRatio = govsim.GenDepositMinInitialDepositRatio(r) },
)

var votingPeriod time.Duration
simState.AppParams.GetOrGenerate(
simState.Cdc, govsim.VotingParamsVotingPeriod, &votingPeriod, simState.Rand,
func(r *rand.Rand) { votingPeriod = govsim.GenVotingParamsVotingPeriod(r) },
)

var quorum sdk.Dec
simState.AppParams.GetOrGenerate(
simState.Cdc, govsim.TallyParamsQuorum, &quorum, simState.Rand,
func(r *rand.Rand) { quorum = govsim.GenTallyParamsQuorum(r) },
)

var threshold sdk.Dec
simState.AppParams.GetOrGenerate(
simState.Cdc, govsim.TallyParamsThreshold, &threshold, simState.Rand,
func(r *rand.Rand) { threshold = govsim.GenTallyParamsThreshold(r) },
)

var veto sdk.Dec
simState.AppParams.GetOrGenerate(
simState.Cdc, govsim.TallyParamsVeto, &veto, simState.Rand,
func(r *rand.Rand) { veto = govsim.GenTallyParamsVeto(r) },
)

tally := &govtypesv1.TallyParams{
Quorum: quorum.String(),
Threshold: threshold.String(),
VetoThreshold: veto.String(),
}

customParam := typesv1.CustomParams{
CertifierUpdateSecurityVoteTally: tally,
CertifierUpdateStakeVoteTally: tally,
}

govGenesis := typesv1.NewGenesisState(
startingProposalID,
govtypesv1.NewParams(minDeposit, depositPeriod, votingPeriod, quorum.String(), threshold.String(), veto.String(), minInitialDepositRatio.String(), simState.Rand.Intn(2) == 0, simState.Rand.Intn(2) == 0, simState.Rand.Intn(2) == 0),
customParam,
)

bz, err := json.MarshalIndent(&govGenesis, "", " ")
if err != nil {
panic(err)
}
fmt.Printf("Selected randomly generated governance parameters:\n%s\n", bz)
simState.GenState[govtypes.ModuleName] = simState.Cdc.MustMarshalJSON(govGenesis)
}

Loading

0 comments on commit 0a1e85f

Please sign in to comment.