66 lines
1.4 KiB
Go
66 lines
1.4 KiB
Go
package simulation_test
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/cosmos/cosmos-sdk/std"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
"github.com/tendermint/tendermint/crypto/ed25519"
|
|
tmkv "github.com/tendermint/tendermint/libs/kv"
|
|
|
|
"github.com/cosmos/cosmos-sdk/simapp"
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
"github.com/cosmos/cosmos-sdk/x/evidence/simulation"
|
|
"github.com/cosmos/cosmos-sdk/x/evidence/types"
|
|
)
|
|
|
|
func TestDecodeStore(t *testing.T) {
|
|
cdc := std.NewAppCodec(std.MakeCodec(simapp.ModuleBasics))
|
|
dec := simulation.NewDecodeStore(cdc)
|
|
|
|
delPk1 := ed25519.GenPrivKey().PubKey()
|
|
|
|
ev := types.Equivocation{
|
|
Height: 10,
|
|
Time: time.Now().UTC(),
|
|
Power: 1000,
|
|
ConsensusAddress: sdk.ConsAddress(delPk1.Address()),
|
|
}
|
|
|
|
evBz, err := cdc.MarshalEvidence(&ev)
|
|
require.NoError(t, err)
|
|
|
|
kvPairs := tmkv.Pairs{
|
|
tmkv.Pair{
|
|
Key: types.KeyPrefixEvidence,
|
|
Value: evBz,
|
|
},
|
|
tmkv.Pair{
|
|
Key: []byte{0x99},
|
|
Value: []byte{0x99},
|
|
},
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
expectedLog string
|
|
}{
|
|
{"Evidence", fmt.Sprintf("%v\n%v", ev, ev)},
|
|
{"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() { dec(kvPairs[i], kvPairs[i]) }, tt.name)
|
|
default:
|
|
require.Equal(t, tt.expectedLog, dec(kvPairs[i], kvPairs[i]), tt.name)
|
|
}
|
|
})
|
|
}
|
|
}
|