2019-06-28 11:20:36 -07:00
|
|
|
package simapp
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
2020-08-24 07:41:08 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/codec"
|
2020-07-30 07:53:02 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/std"
|
2019-06-28 11:20:36 -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-08-24 07:41:08 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/types/module"
|
2020-06-17 11:42:27 -07:00
|
|
|
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
2019-06-28 11:20:36 -07:00
|
|
|
)
|
|
|
|
|
2020-08-24 07:41:08 -07:00
|
|
|
func makeCodec(bm module.BasicManager) *codec.LegacyAmino {
|
2020-09-07 07:47:12 -07:00
|
|
|
cdc := codec.NewLegacyAmino()
|
2020-08-24 07:41:08 -07:00
|
|
|
|
2020-09-07 07:47:12 -07:00
|
|
|
bm.RegisterLegacyAminoCodec(cdc)
|
|
|
|
std.RegisterLegacyAminoCodec(cdc)
|
2020-08-24 07:41:08 -07:00
|
|
|
|
|
|
|
return cdc
|
|
|
|
}
|
|
|
|
|
2019-06-28 11:20:36 -07:00
|
|
|
func TestGetSimulationLog(t *testing.T) {
|
2020-08-24 07:41:08 -07:00
|
|
|
cdc := makeCodec(ModuleBasics)
|
2019-06-28 11:20:36 -07:00
|
|
|
|
2019-08-13 15:16:03 -07:00
|
|
|
decoders := make(sdk.StoreDecoderRegistry)
|
2020-07-30 07:53:02 -07:00
|
|
|
decoders[authtypes.StoreKey] = func(kvAs, kvBs kv.Pair) string { return "10" }
|
2019-06-28 13:11:27 -07:00
|
|
|
|
|
|
|
tests := []struct {
|
2019-08-13 15:16:03 -07:00
|
|
|
store string
|
2020-07-30 07:53:02 -07:00
|
|
|
kvPairs []kv.Pair
|
2019-06-28 13:11:27 -07:00
|
|
|
expectedLog string
|
|
|
|
}{
|
2019-08-13 15:16:03 -07:00
|
|
|
{
|
|
|
|
"Empty",
|
2020-07-30 07:53:02 -07:00
|
|
|
[]kv.Pair{{}},
|
2019-08-13 15:16:03 -07:00
|
|
|
"",
|
|
|
|
},
|
|
|
|
{
|
2020-06-17 11:42:27 -07:00
|
|
|
authtypes.StoreKey,
|
2020-07-30 07:53:02 -07:00
|
|
|
[]kv.Pair{{Key: authtypes.GlobalAccountNumberKey, Value: cdc.MustMarshalBinaryBare(uint64(10))}},
|
2019-08-13 15:16:03 -07:00
|
|
|
"10",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"OtherStore",
|
2020-07-30 07:53:02 -07:00
|
|
|
[]kv.Pair{{Key: []byte("key"), Value: []byte("value")}},
|
2019-08-13 15:16:03 -07:00
|
|
|
fmt.Sprintf("store A %X => %X\nstore B %X => %X\n", []byte("key"), []byte("value"), []byte("key"), []byte("value")),
|
|
|
|
},
|
2019-06-28 13:11:27 -07:00
|
|
|
}
|
|
|
|
|
2019-08-13 15:16:03 -07:00
|
|
|
for _, tt := range tests {
|
2019-10-17 06:47:35 -07:00
|
|
|
tt := tt
|
2019-08-13 15:16:03 -07:00
|
|
|
t.Run(tt.store, func(t *testing.T) {
|
2020-04-21 14:33:56 -07:00
|
|
|
require.Equal(t, tt.expectedLog, GetSimulationLog(tt.store, decoders, tt.kvPairs, tt.kvPairs), tt.store)
|
2019-06-28 13:11:27 -07:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|