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

     1  package simulation_test
     2  
     3  import (
     4  	"encoding/json"
     5  	"math/rand"
     6  	"testing"
     7  
     8  	"github.com/stretchr/testify/require"
     9  
    10  	sdkmath "cosmossdk.io/math"
    11  
    12  	"github.com/cosmos/cosmos-sdk/codec"
    13  	codectypes "github.com/cosmos/cosmos-sdk/codec/types"
    14  	"github.com/cosmos/cosmos-sdk/types/module"
    15  	simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
    16  	"github.com/cosmos/cosmos-sdk/x/auth/simulation"
    17  	"github.com/cosmos/cosmos-sdk/x/auth/types"
    18  )
    19  
    20  // TestRandomizedGenState tests the normal scenario of applying RandomizedGenState.
    21  // Abonormal scenarios are not tested here.
    22  func TestRandomizedGenState(t *testing.T) {
    23  	registry := codectypes.NewInterfaceRegistry()
    24  	types.RegisterInterfaces(registry)
    25  	cdc := codec.NewProtoCodec(registry)
    26  
    27  	s := rand.NewSource(1)
    28  	r := rand.New(s)
    29  
    30  	simState := module.SimulationState{
    31  		AppParams:    make(simtypes.AppParams),
    32  		Cdc:          cdc,
    33  		Rand:         r,
    34  		NumBonded:    3,
    35  		Accounts:     simtypes.RandomAccounts(r, 3),
    36  		InitialStake: sdkmath.NewInt(1000),
    37  		GenState:     make(map[string]json.RawMessage),
    38  	}
    39  
    40  	simulation.RandomizedGenState(&simState, simulation.RandomGenesisAccounts)
    41  
    42  	var authGenesis types.GenesisState
    43  	simState.Cdc.MustUnmarshalJSON(simState.GenState[types.ModuleName], &authGenesis)
    44  
    45  	require.Equal(t, uint64(0x8c), authGenesis.Params.GetMaxMemoCharacters())
    46  	require.Equal(t, uint64(0x2b6), authGenesis.Params.GetSigVerifyCostED25519())
    47  	require.Equal(t, uint64(0x1ff), authGenesis.Params.GetSigVerifyCostSecp256k1())
    48  	require.Equal(t, uint64(9), authGenesis.Params.GetTxSigLimit())
    49  	require.Equal(t, uint64(5), authGenesis.Params.GetTxSizeCostPerByte())
    50  
    51  	genAccounts, err := types.UnpackAccounts(authGenesis.Accounts)
    52  	require.NoError(t, err)
    53  	require.Len(t, genAccounts, 3)
    54  	require.Equal(t, "cosmos1ghekyjucln7y67ntx7cf27m9dpuxxemn4c8g4r", genAccounts[2].GetAddress().String())
    55  	require.Equal(t, uint64(0), genAccounts[2].GetAccountNumber())
    56  	require.Equal(t, uint64(0), genAccounts[2].GetSequence())
    57  }