github.com/cosmos/cosmos-sdk@v0.50.10/x/params/simulation/proposals_test.go (about)

     1  package simulation_test
     2  
     3  import (
     4  	"math/rand"
     5  	"testing"
     6  
     7  	cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
     8  	"github.com/stretchr/testify/require"
     9  
    10  	sdk "github.com/cosmos/cosmos-sdk/types"
    11  	simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
    12  	"github.com/cosmos/cosmos-sdk/x/params/simulation"
    13  	"github.com/cosmos/cosmos-sdk/x/params/types/proposal"
    14  )
    15  
    16  func TestProposalContents(t *testing.T) {
    17  	// initialize parameters
    18  	s := rand.NewSource(1)
    19  	r := rand.New(s)
    20  
    21  	ctx := sdk.NewContext(nil, cmtproto.Header{}, true, nil)
    22  	accounts := simtypes.RandomAccounts(r, 3)
    23  
    24  	paramChangePool := []simtypes.LegacyParamChange{MockParamChange{1}, MockParamChange{2}, MockParamChange{3}}
    25  
    26  	// execute ProposalContents function
    27  	weightedProposalContent := simulation.ProposalContents(paramChangePool)
    28  	require.Len(t, weightedProposalContent, 1)
    29  
    30  	w0 := weightedProposalContent[0]
    31  
    32  	// tests w0 interface:
    33  	require.Equal(t, simulation.OpWeightSubmitParamChangeProposal, w0.AppParamsKey())
    34  	require.Equal(t, simulation.DefaultWeightParamChangeProposal, w0.DefaultWeight())
    35  
    36  	content := w0.ContentSimulatorFn()(r, ctx, accounts)
    37  
    38  	require.Equal(t, "desc from SimulateParamChangeProposalContent-0. Random short desc: IivHSlcxgdXhhuTSkuxK", content.GetDescription())
    39  	require.Equal(t, "title from SimulateParamChangeProposalContent-0", content.GetTitle())
    40  	require.Equal(t, "params", content.ProposalRoute())
    41  	require.Equal(t, "ParameterChange", content.ProposalType())
    42  
    43  	pcp, ok := content.(*proposal.ParameterChangeProposal)
    44  	require.True(t, ok)
    45  
    46  	require.Len(t, pcp.Changes, 1)
    47  	require.Equal(t, "test-Key2", pcp.Changes[0].GetKey())
    48  	require.Equal(t, "test-value 2791 ", pcp.Changes[0].GetValue())
    49  	require.Equal(t, "test-Subspace2", pcp.Changes[0].GetSubspace())
    50  }