github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/libs/ibc-go/modules/apps/transfer/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 // "github.com/cosmos/cosmos-sdk/codec" 11 // codectypes "github.com/cosmos/cosmos-sdk/codec/types" 12 // "github.com/cosmos/cosmos-sdk/types/module" 13 // simtypes "github.com/cosmos/cosmos-sdk/types/simulation" 14 "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/codec" 15 "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types/module" 16 simtypes "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/x/simulation" 17 "github.com/fibonacci-chain/fbc/libs/ibc-go/modules/apps/transfer/simulation" 18 "github.com/fibonacci-chain/fbc/libs/ibc-go/modules/apps/transfer/types" 19 ) 20 21 // TestRandomizedGenState tests the normal scenario of applying RandomizedGenState. 22 // Abonormal scenarios are not tested here. 23 func TestRandomizedGenState(t *testing.T) { 24 //interfaceRegistry := codectypes.NewInterfaceRegistry() 25 // cdc := codec.NewProtoCodec(interfaceRegistry) 26 cdc := codec.New() 27 28 s := rand.NewSource(1) 29 r := rand.New(s) 30 31 simState := module.SimulationState{ 32 AppParams: make(simtypes.AppParams), 33 Cdc: cdc, 34 Rand: r, 35 NumBonded: 3, 36 Accounts: simtypes.RandomAccounts(r, 3), 37 InitialStake: 1000, 38 GenState: make(map[string]json.RawMessage), 39 } 40 41 simulation.RandomizedGenState(&simState) 42 43 var ibcTransferGenesis types.GenesisState 44 simState.Cdc.MustUnmarshalJSON(simState.GenState[types.ModuleName], &ibcTransferGenesis) 45 46 require.Equal(t, "euzxpfgkqegqiqwixnku", ibcTransferGenesis.PortId) 47 require.True(t, ibcTransferGenesis.Params.SendEnabled) 48 require.True(t, ibcTransferGenesis.Params.ReceiveEnabled) 49 require.Len(t, ibcTransferGenesis.DenomTraces, 0) 50 51 } 52 53 // TestRandomizedGenState tests abnormal scenarios of applying RandomizedGenState. 54 func TestRandomizedGenState1(t *testing.T) { 55 // interfaceRegistry := codectypes.NewInterfaceRegistry() 56 // cdc := codec.NewProtoCodec(interfaceRegistry) 57 cdc := codec.New() 58 59 s := rand.NewSource(1) 60 r := rand.New(s) 61 // all these tests will panic 62 tests := []struct { 63 simState module.SimulationState 64 panicMsg string 65 }{ 66 { // panic => reason: incomplete initialization of the simState 67 module.SimulationState{}, "invalid memory address or nil pointer dereference"}, 68 { // panic => reason: incomplete initialization of the simState 69 module.SimulationState{ 70 AppParams: make(simtypes.AppParams), 71 Cdc: cdc, 72 Rand: r, 73 }, "assignment to entry in nil map"}, 74 } 75 76 for _, tt := range tests { 77 require.Panicsf(t, func() { simulation.RandomizedGenState(&tt.simState) }, tt.panicMsg) 78 } 79 }