0g-chain/x/kavadist/simulation/decoder_test.go

53 lines
1.0 KiB
Go
Raw Normal View History

2020-04-04 22:42:35 +00:00
package simulation
import (
"fmt"
"testing"
"time"
"github.com/stretchr/testify/require"
"github.com/kava-labs/kava/x/kavadist/types"
"github.com/cosmos/cosmos-sdk/types/kv"
)
2020-04-04 22:42:35 +00:00
func TestDecodeDistributionStore(t *testing.T) {
prevBlockTime := time.Now().UTC()
bPrevBlockTime, err := prevBlockTime.MarshalBinary()
if err != nil {
panic(err)
}
kvPairs := kv.Pairs{
Pairs: []kv.Pair{
{
Key: []byte(types.PreviousBlockTimeKey),
Value: bPrevBlockTime,
},
{
Key: []byte{0x99},
Value: []byte{0x99},
},
},
2020-04-04 22:42:35 +00:00
}
tests := []struct {
name string
expectedLog string
}{
{"PreviousBlockTime", fmt.Sprintf("%s\n%s", prevBlockTime, prevBlockTime)},
{"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() { DecodeStore(kvPairs.GetPairs()[i], kvPairs.GetPairs()[i]) }, tt.name)
2020-04-04 22:42:35 +00:00
default:
require.Equal(t, tt.expectedLog, DecodeStore(kvPairs.GetPairs()[i], kvPairs.GetPairs()[i]), tt.name)
2020-04-04 22:42:35 +00:00
}
})
}
}