2020-04-21 14:33:56 -07:00
|
|
|
package simulation_test
|
2019-08-13 15:16:03 -07:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
2020-04-21 14:33:56 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/simapp"
|
2019-08-13 15:16:03 -07:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2020-07-30 07:53:02 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/types/kv"
|
2020-04-21 14:33:56 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/mint/simulation"
|
2020-02-24 08:05:21 -08:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/mint/types"
|
2019-08-13 15:16:03 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestDecodeStore(t *testing.T) {
|
2021-07-01 01:52:38 -07:00
|
|
|
cdc := simapp.MakeTestEncodingConfig().Codec
|
2020-04-21 14:33:56 -07:00
|
|
|
dec := simulation.NewDecodeStore(cdc)
|
|
|
|
|
2019-08-13 15:16:03 -07:00
|
|
|
minter := types.NewMinter(sdk.OneDec(), sdk.NewDec(15))
|
|
|
|
|
2020-07-30 07:53:02 -07:00
|
|
|
kvPairs := kv.Pairs{
|
2020-08-11 03:09:16 -07:00
|
|
|
Pairs: []kv.Pair{
|
2021-04-29 03:46:22 -07:00
|
|
|
{Key: types.MinterKey, Value: cdc.MustMarshal(&minter)},
|
2020-08-11 03:09:16 -07:00
|
|
|
{Key: []byte{0x99}, Value: []byte{0x99}},
|
|
|
|
},
|
2019-08-13 15:16:03 -07:00
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
expectedLog string
|
|
|
|
}{
|
|
|
|
{"Minter", fmt.Sprintf("%v\n%v", minter, minter)},
|
|
|
|
{"other", ""},
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, tt := range tests {
|
2019-10-17 06:47:35 -07:00
|
|
|
i, tt := i, tt
|
2019-08-13 15:16:03 -07:00
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
switch i {
|
|
|
|
case len(tests) - 1:
|
2020-08-11 03:09:16 -07:00
|
|
|
require.Panics(t, func() { dec(kvPairs.Pairs[i], kvPairs.Pairs[i]) }, tt.name)
|
2019-08-13 15:16:03 -07:00
|
|
|
default:
|
2020-08-11 03:09:16 -07:00
|
|
|
require.Equal(t, tt.expectedLog, dec(kvPairs.Pairs[i], kvPairs.Pairs[i]), tt.name)
|
2019-08-13 15:16:03 -07:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|