* x/capability: simulations * update logs * validate genesis state * InitGenesis and ExportGenesis functions * update validation func * fix import-export sim * remove nondeterminism from capability genesis * Update x/capability/types/genesis.go * Update x/capability/types/genesis.go * fix tests * fix merge * consistency updates * try fix nondeterminism * fix conditional * Fix random index logic * lint * lint Co-authored-by: Aditya Sripal <adityasripal@gmail.com> Co-authored-by: Aleksandr Bezobchuk <aleks.bezobchuk@gmail.com> Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com>
60 lines
1.4 KiB
Go
60 lines
1.4 KiB
Go
package simulation_test
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
tmkv "github.com/tendermint/tendermint/libs/kv"
|
|
|
|
"github.com/cosmos/cosmos-sdk/simapp"
|
|
codecstd "github.com/cosmos/cosmos-sdk/std"
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
"github.com/cosmos/cosmos-sdk/x/capability/simulation"
|
|
"github.com/cosmos/cosmos-sdk/x/capability/types"
|
|
)
|
|
|
|
func TestDecodeStore(t *testing.T) {
|
|
cdc := codecstd.NewAppCodec(codecstd.MakeCodec(simapp.ModuleBasics))
|
|
dec := simulation.NewDecodeStore(cdc)
|
|
|
|
capOwners := types.CapabilityOwners{
|
|
Owners: []types.Owner{{Module: "transfer", Name: "ports/transfer"}},
|
|
}
|
|
|
|
kvPairs := tmkv.Pairs{
|
|
tmkv.Pair{
|
|
Key: types.KeyIndex,
|
|
Value: sdk.Uint64ToBigEndian(10),
|
|
},
|
|
tmkv.Pair{
|
|
Key: types.KeyPrefixIndexCapability,
|
|
Value: cdc.MustMarshalBinaryBare(&capOwners),
|
|
},
|
|
tmkv.Pair{
|
|
Key: []byte{0x99},
|
|
Value: []byte{0x99},
|
|
},
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
expectedLog string
|
|
}{
|
|
{"Index", "Index A: 10\nIndex B: 10\n"},
|
|
{"CapabilityOwners", fmt.Sprintf("CapabilityOwners A: %v\nCapabilityOwners B: %v\n", capOwners, capOwners)},
|
|
{"other", ""},
|
|
}
|
|
|
|
for i, tt := range tests {
|
|
i, tt := i, tt
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
switch i {
|
|
case len(tests) - 1:
|
|
require.Panics(t, func() { dec(kvPairs[i], kvPairs[i]) }, tt.name)
|
|
default:
|
|
require.Equal(t, tt.expectedLog, dec(kvPairs[i], kvPairs[i]), tt.name)
|
|
}
|
|
})
|
|
}
|
|
}
|