mukan-ibc/modules/apps/transfer/simulation/genesis_test.go
Mukan Erkin Törük 88dd97a9f8
Some checks failed
CodeQL / Analyze (push) Waiting to run
golangci-lint / lint (push) Waiting to run
Tests / Code Coverage / build (amd64) (push) Waiting to run
Tests / Code Coverage / build (arm64) (push) Waiting to run
Tests / Code Coverage / unit-tests (map[additional-args:-tags="test_e2e" name:e2e path:./e2e]) (push) Waiting to run
Tests / Code Coverage / unit-tests (map[name:08-wasm path:./modules/light-clients/08-wasm]) (push) Waiting to run
Tests / Code Coverage / unit-tests (map[name:ibc-go path:.]) (push) Waiting to run
Docker Build & Push Simapp (main) / docker-build (push) Has been cancelled
refactor: replace all github.com upstream refs with git.cw.tr/mukan-network
2026-05-11 03:36:22 +03:00

87 lines
2.6 KiB
Go

package simulation_test
import (
"encoding/json"
"math/rand"
"testing"
"github.com/stretchr/testify/require"
sdkmath "cosmossdk.io/math"
"git.cw.tr/mukan-network/mukan-sdk/codec"
codectypes "git.cw.tr/mukan-network/mukan-sdk/codec/types"
cryptocodec "git.cw.tr/mukan-network/mukan-sdk/crypto/codec"
"git.cw.tr/mukan-network/mukan-sdk/types/module"
simtypes "git.cw.tr/mukan-network/mukan-sdk/types/simulation"
"git.cw.tr/mukan-network/mukan-ibc/modules/apps/transfer/simulation"
"git.cw.tr/mukan-network/mukan-ibc/modules/apps/transfer/types"
)
// TestRandomizedGenState tests the normal scenario of applying RandomizedGenState.
// Abonormal scenarios are not tested here.
func TestRandomizedGenState(t *testing.T) {
interfaceRegistry := codectypes.NewInterfaceRegistry()
cryptocodec.RegisterInterfaces(interfaceRegistry)
cdc := codec.NewProtoCodec(interfaceRegistry)
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: sdkmath.NewInt(1000),
GenState: make(map[string]json.RawMessage),
}
simulation.RandomizedGenState(&simState)
var ibcTransferGenesis types.GenesisState
simState.Cdc.MustUnmarshalJSON(simState.GenState[types.ModuleName], &ibcTransferGenesis)
require.Equal(t, "euzxpfgkqegqiqwixnku", ibcTransferGenesis.PortId)
require.True(t, ibcTransferGenesis.Params.SendEnabled)
require.True(t, ibcTransferGenesis.Params.ReceiveEnabled)
require.Len(t, ibcTransferGenesis.Denoms, 0)
}
// TestRandomizedGenState tests abnormal scenarios of applying RandomizedGenState.
func TestRandomizedGenState1(t *testing.T) {
interfaceRegistry := codectypes.NewInterfaceRegistry()
cdc := codec.NewProtoCodec(interfaceRegistry)
s := rand.NewSource(1)
r := rand.New(s)
// all these tests will panic
tests := []struct {
name string
simState module.SimulationState
panicMsg string
}{
{ // panic => reason: incomplete initialization of the simState
"nil pointer dereference",
module.SimulationState{},
"invalid memory address or nil pointer dereference",
},
{ // panic => reason: incomplete initialization of the simState
"assignment to entry in nil map",
module.SimulationState{
AppParams: make(simtypes.AppParams),
Cdc: cdc,
Rand: r,
},
"assignment to entry in nil map",
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
require.Panicsf(t, func() { simulation.RandomizedGenState(&tc.simState) }, tc.panicMsg)
})
}
}