cosmos-sdk/x/auth/simulation/genesis_test.go
Marie 7f59723d88
Make JSONMarshaler methods require proto.Message (#7054)
* Make JSONMarshaler require proto.Message

* Use &msg with MarshalJSON

* Use *LegacyAmino in queriers instead of JSONMarshaler

* Revert ABCIMessageLogs String() and coins tests

* Use LegacyAmino in client/debug and fix subspace tests

* Use LegacyAmino in all legacy queriers and adapt simulation

* Make AminoCodec implement Marshaler and some godoc fixes

* Test fixes

* Remove unrelevant comment

* Use TxConfig.TxJSONEncoder

* Use encoding/json in genutil cli migrate/validate genesis cmds

* Address simulation related comments

* Use JSONMarshaler in cli tests

* Use proto.Message as respType in cli tests

* Use tmjson for tm GenesisDoc

* Update types/module/simulation.go

Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com>

* Update types/module/module_test.go

Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com>

* Add godoc comments

* Remove unused InsertKeyJSON

* Fix tests

Co-authored-by: Aaron Craelius <aaronc@users.noreply.github.com>
Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com>
2020-08-26 09:39:38 +00:00

56 lines
1.9 KiB
Go

package simulation_test
import (
"encoding/json"
"math/rand"
"testing"
"github.com/stretchr/testify/require"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/types/module"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
"github.com/cosmos/cosmos-sdk/x/auth/simulation"
"github.com/cosmos/cosmos-sdk/x/auth/types"
)
// TestRandomizedGenState tests the normal scenario of applying RandomizedGenState.
// Abonormal scenarios are not tested here.
func TestRandomizedGenState(t *testing.T) {
registry := codectypes.NewInterfaceRegistry()
types.RegisterInterfaces(registry)
cdc := codec.NewProtoCodec(registry)
s := rand.NewSource(1)
r := rand.New(s)
simState := module.SimulationState{
AppParams: make(simtypes.AppParams),
Cdc: cdc,
Rand: r,
NumBonded: 3,
Accounts: simtypes.RandomAccounts(r, 3),
InitialStake: 1000,
GenState: make(map[string]json.RawMessage),
}
simulation.RandomizedGenState(&simState, simulation.RandomGenesisAccounts)
var authGenesis types.GenesisState
simState.Cdc.MustUnmarshalJSON(simState.GenState[types.ModuleName], &authGenesis)
require.Equal(t, uint64(0x8c), authGenesis.Params.GetMaxMemoCharacters())
require.Equal(t, uint64(0x2b6), authGenesis.Params.GetSigVerifyCostED25519())
require.Equal(t, uint64(0x1ff), authGenesis.Params.GetSigVerifyCostSecp256k1())
require.Equal(t, uint64(9), authGenesis.Params.GetTxSigLimit())
require.Equal(t, uint64(5), authGenesis.Params.GetTxSizeCostPerByte())
genAccounts, err := types.UnpackAccounts(authGenesis.Accounts)
require.NoError(t, err)
require.Len(t, genAccounts, 3)
require.Equal(t, "cosmos1ghekyjucln7y67ntx7cf27m9dpuxxemn4c8g4r", genAccounts[2].GetAddress().String())
require.Equal(t, uint64(0), genAccounts[2].GetAccountNumber())
require.Equal(t, uint64(0), genAccounts[2].GetSequence())
}