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"
|
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/types/kv"
|
|
|
|
)
|
2020-04-04 22:42:35 +00:00
|
|
|
|
|
|
|
func TestDecodeDistributionStore(t *testing.T) {
|
|
|
|
prevBlockTime := time.Now().UTC()
|
2022-01-08 00:39:27 +00:00
|
|
|
bPrevBlockTime, err := prevBlockTime.MarshalBinary()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2020-04-23 16:35:58 +00:00
|
|
|
kvPairs := kv.Pairs{
|
2022-01-08 00:39:27 +00:00
|
|
|
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:
|
2022-01-08 00:39:27 +00:00
|
|
|
require.Panics(t, func() { DecodeStore(kvPairs.GetPairs()[i], kvPairs.GetPairs()[i]) }, tt.name)
|
2020-04-04 22:42:35 +00:00
|
|
|
default:
|
2022-01-08 00:39:27 +00:00
|
|
|
require.Equal(t, tt.expectedLog, DecodeStore(kvPairs.GetPairs()[i], kvPairs.GetPairs()[i]), tt.name)
|
2020-04-04 22:42:35 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|