github.com/Finschia/finschia-sdk@v0.48.1/x/simulation/params_test.go (about)

     1  package simulation
     2  
     3  import (
     4  	"fmt"
     5  	"math/rand"
     6  	"testing"
     7  
     8  	"github.com/stretchr/testify/require"
     9  	tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
    10  
    11  	sdk "github.com/Finschia/finschia-sdk/types"
    12  	simtypes "github.com/Finschia/finschia-sdk/types/simulation"
    13  )
    14  
    15  func TestParamChange(t *testing.T) {
    16  	subspace, key := "theSubspace", "key"
    17  	f := func(r *rand.Rand) string {
    18  		return "theResult"
    19  	}
    20  
    21  	pChange := NewSimParamChange(subspace, key, f)
    22  
    23  	require.Equal(t, subspace, pChange.Subspace())
    24  	require.Equal(t, key, pChange.Key())
    25  	require.Equal(t, f(nil), pChange.SimValue()(nil))
    26  	require.Equal(t, fmt.Sprintf("%s/%s", subspace, key), pChange.ComposedKey())
    27  }
    28  
    29  func TestNewWeightedProposalContent(t *testing.T) {
    30  	key := "theKey"
    31  	weight := 1
    32  	content := &testContent{}
    33  	f := func(r *rand.Rand, ctx sdk.Context, accs []simtypes.Account) simtypes.Content {
    34  		return content
    35  	}
    36  
    37  	pContent := NewWeightedProposalContent(key, weight, f)
    38  
    39  	require.Equal(t, key, pContent.AppParamsKey())
    40  	require.Equal(t, weight, pContent.DefaultWeight())
    41  
    42  	ctx := sdk.NewContext(nil, tmproto.Header{}, true, nil)
    43  	require.Equal(t, content, pContent.ContentSimulatorFn()(nil, ctx, nil))
    44  }
    45  
    46  type testContent struct{}
    47  
    48  func (t testContent) GetTitle() string       { return "" }
    49  func (t testContent) GetDescription() string { return "" }
    50  func (t testContent) ProposalRoute() string  { return "" }
    51  func (t testContent) ProposalType() string   { return "" }
    52  func (t testContent) ValidateBasic() error   { return nil }
    53  func (t testContent) String() string         { return "" }