Skip to content

Commit

Permalink
types: add kv type (cosmos#6897)
Browse files Browse the repository at this point in the history
* add kv type

* add changelog entry

* fix build

* replace sdkkv with kv

* revert change

* fix some tests

* proto-gen

* fix tests

Co-authored-by: Aleksandr Bezobchuk <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Jul 30, 2020
1 parent 6392a7b commit b633179
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
4 changes: 2 additions & 2 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import (
"fmt"
"io/ioutil"

tmkv "github.com/tendermint/tendermint/libs/kv"
"github.com/tendermint/tendermint/libs/log"
dbm "github.com/tendermint/tm-db"

"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/simapp/helpers"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/kv"
"github.com/cosmos/cosmos-sdk/types/module"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
)
Expand Down Expand Up @@ -109,7 +109,7 @@ func PrintStats(db dbm.DB) {

// GetSimulationLog unmarshals the KVPair's Value to the corresponding type based on the
// each's module store key and the prefix bytes of the KVPair's key.
func GetSimulationLog(storeName string, sdr sdk.StoreDecoderRegistry, kvAs, kvBs []tmkv.Pair) (log string) {
func GetSimulationLog(storeName string, sdr sdk.StoreDecoderRegistry, kvAs, kvBs []kv.Pair) (log string) {
for i := 0; i < len(kvAs); i++ {
if len(kvAs[i].Value) == 0 && len(kvBs[i].Value) == 0 {
// skip if the value doesn't have any bytes
Expand Down
15 changes: 7 additions & 8 deletions utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,38 @@ import (
"fmt"
"testing"

"github.com/cosmos/cosmos-sdk/std"

"github.com/stretchr/testify/require"
tmkv "github.com/tendermint/tendermint/libs/kv"

"github.com/cosmos/cosmos-sdk/std"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/kv"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
)

func TestGetSimulationLog(t *testing.T) {
cdc := std.MakeCodec(ModuleBasics)

decoders := make(sdk.StoreDecoderRegistry)
decoders[authtypes.StoreKey] = func(kvAs, kvBs tmkv.Pair) string { return "10" }
decoders[authtypes.StoreKey] = func(kvAs, kvBs kv.Pair) string { return "10" }

tests := []struct {
store string
kvPairs []tmkv.Pair
kvPairs []kv.Pair
expectedLog string
}{
{
"Empty",
[]tmkv.Pair{{}},
[]kv.Pair{{}},
"",
},
{
authtypes.StoreKey,
[]tmkv.Pair{{Key: authtypes.GlobalAccountNumberKey, Value: cdc.MustMarshalBinaryBare(uint64(10))}},
[]kv.Pair{{Key: authtypes.GlobalAccountNumberKey, Value: cdc.MustMarshalBinaryBare(uint64(10))}},
"10",
},
{
"OtherStore",
[]tmkv.Pair{{Key: []byte("key"), Value: []byte("value")}},
[]kv.Pair{{Key: []byte("key"), Value: []byte("value")}},
fmt.Sprintf("store A %X => %X\nstore B %X => %X\n", []byte("key"), []byte("value"), []byte("key"), []byte("value")),
},
}
Expand Down

0 comments on commit b633179

Please sign in to comment.