2021-01-25 08:41:30 -08:00
|
|
|
package simulation_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
|
|
|
"github.com/cosmos/cosmos-sdk/simapp"
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
"github.com/cosmos/cosmos-sdk/types/kv"
|
2021-05-06 11:23:48 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/authz"
|
|
|
|
"github.com/cosmos/cosmos-sdk/x/authz/keeper"
|
2021-01-25 08:41:30 -08:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/authz/simulation"
|
2021-02-19 22:57:57 -08:00
|
|
|
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
2021-01-25 08:41:30 -08:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestDecodeStore(t *testing.T) {
|
2021-07-01 01:52:38 -07:00
|
|
|
cdc := simapp.MakeTestEncodingConfig().Codec
|
2021-01-25 08:41:30 -08:00
|
|
|
dec := simulation.NewDecodeStore(cdc)
|
|
|
|
|
2021-05-06 11:23:48 -07:00
|
|
|
grant, _ := authz.NewGrant(banktypes.NewSendAuthorization(sdk.NewCoins(sdk.NewInt64Coin("foo", 123))), time.Now().UTC())
|
2021-04-29 03:46:22 -07:00
|
|
|
grantBz, err := cdc.Marshal(&grant)
|
2021-01-25 08:41:30 -08:00
|
|
|
require.NoError(t, err)
|
|
|
|
kvPairs := kv.Pairs{
|
|
|
|
Pairs: []kv.Pair{
|
2021-05-06 11:23:48 -07:00
|
|
|
{Key: []byte(keeper.GrantKey), Value: grantBz},
|
2021-01-25 08:41:30 -08:00
|
|
|
{Key: []byte{0x99}, Value: []byte{0x99}},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
2021-05-11 08:33:33 -07:00
|
|
|
expectErr bool
|
2021-01-25 08:41:30 -08:00
|
|
|
expectedLog string
|
|
|
|
}{
|
2021-05-11 08:33:33 -07:00
|
|
|
{"Grant", false, fmt.Sprintf("%v\n%v", grant, grant)},
|
|
|
|
{"other", true, ""},
|
2021-01-25 08:41:30 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
for i, tt := range tests {
|
|
|
|
i, tt := i, tt
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
2021-05-11 08:33:33 -07:00
|
|
|
if tt.expectErr {
|
2021-01-25 08:41:30 -08:00
|
|
|
require.Panics(t, func() { dec(kvPairs.Pairs[i], kvPairs.Pairs[i]) }, tt.name)
|
2021-05-11 08:33:33 -07:00
|
|
|
} else {
|
2021-01-25 08:41:30 -08:00
|
|
|
require.Equal(t, tt.expectedLog, dec(kvPairs.Pairs[i], kvPairs.Pairs[i]), tt.name)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|