From 11ed343deac8cf1d1ba9c47dc0f2117fd3294fa3 Mon Sep 17 00:00:00 2001 From: Federico Kunze Date: Wed, 1 Apr 2020 12:27:38 -0300 Subject: [PATCH 1/7] simulation decoders for kava modules --- go.mod | 5 +++ go.sum | 11 +++++++ x/bep3/simulation/decoder.go | 29 +++++++++++++++-- x/cdp/simulation/decoder.go | 52 +++++++++++++++++++++++++++++-- x/kavadist/simulation/decoder.go | 18 +++++++++-- x/pricefeed/simulation/decoder.go | 23 ++++++++++++-- 6 files changed, 130 insertions(+), 8 deletions(-) diff --git a/go.mod b/go.mod index 10583537..d763e103 100644 --- a/go.mod +++ b/go.mod @@ -12,9 +12,14 @@ require ( github.com/spf13/cobra v0.0.5 github.com/spf13/viper v1.4.0 github.com/stretchr/testify v1.4.0 + github.com/tendermint/ed25519 v0.0.0-20171027050219-d8387025d2b9 // indirect github.com/tendermint/go-amino v0.15.0 + github.com/tendermint/go-crypto v0.9.0 github.com/tendermint/tendermint v0.32.7 github.com/tendermint/tm-db v0.2.0 + github.com/tendermint/tmlibs v0.9.0 // indirect + github.com/zondax/ledger-go v0.11.0 // indirect + github.com/zondax/ledger-goclient v0.9.9 // indirect golang.org/x/net v0.0.0-20190930134127-c5a3c61f89f3 // indirect gopkg.in/yaml.v2 v2.2.4 ) diff --git a/go.sum b/go.sum index 4a1f0603..70d5658a 100644 --- a/go.sum +++ b/go.sum @@ -40,6 +40,7 @@ github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7 github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= github.com/cosmos/cosmos-sdk v0.34.4-0.20191010193331-18de630d0ae1 h1:yb+E8HGzFnO0YwLS6OCBIAVWtN8KfCYoKeO9mgAmQN0= github.com/cosmos/cosmos-sdk v0.34.4-0.20191010193331-18de630d0ae1/go.mod h1:IGBhkbOK1ebLqMWjtgo99zUxWHsA5IOb6N9CI8nHs0Y= +github.com/cosmos/cosmos-sdk v0.38.2 h1:IeDZxxTgTMGJRZsV4s482O2gxjhLzToX5Zy1uwyasDs= github.com/cosmos/go-bip39 v0.0.0-20180618194314-52158e4697b8/go.mod h1:tSxLoYXyBmiFeKpvmq4dzayMdCjCnu8uqmCysIGBT2Y= github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d h1:49RLWk1j44Xu4fjHb6JFYmeUnDORVwHNkDxaQ0ctCVU= github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d/go.mod h1:tSxLoYXyBmiFeKpvmq4dzayMdCjCnu8uqmCysIGBT2Y= @@ -234,9 +235,13 @@ github.com/tendermint/btcd v0.1.1 h1:0VcxPfflS2zZ3RiOAHkBiFUcPvbtRj5O7zHmcJWHV7s github.com/tendermint/btcd v0.1.1/go.mod h1:DC6/m53jtQzr/NFmMNEu0rxf18/ktVoVtMrnDD5pN+U= github.com/tendermint/crypto v0.0.0-20190823183015-45b1026d81ae h1:AOXNM7c2Vvo45SjAgeWF8Wy+NS7/NCqzRNpUc+HPAec= github.com/tendermint/crypto v0.0.0-20190823183015-45b1026d81ae/go.mod h1:z4YtwM70uOnk8h0pjJYlj3zdYwi9l03By6iAIF5j/Pk= +github.com/tendermint/ed25519 v0.0.0-20171027050219-d8387025d2b9 h1:zccWau0P8FELSb4HTDJ88hRo+WVNMbIbg27rFqDrhCE= +github.com/tendermint/ed25519 v0.0.0-20171027050219-d8387025d2b9/go.mod h1:nt45hbhDkWVdMBkr2TOgOzCrpBccXdN09WOiOYTHVEk= github.com/tendermint/go-amino v0.14.1/go.mod h1:i/UKE5Uocn+argJJBb12qTZsCDBcAYMbR92AaJVmKso= github.com/tendermint/go-amino v0.15.0 h1:TC4e66P59W7ML9+bxio17CPKnxW3nKIRAYskntMAoRk= github.com/tendermint/go-amino v0.15.0/go.mod h1:TQU0M1i/ImAo+tYpZi73AU3V/dKeCoMC9Sphe2ZwGME= +github.com/tendermint/go-crypto v0.9.0 h1:knZL34Ccy6BDjsPXwBslVTtyUpvOVAGbZMHcQriXulM= +github.com/tendermint/go-crypto v0.9.0/go.mod h1:bL+jG0FvO892QRYHtA/lEIQSMMq7anlRPTGbsWzQntU= github.com/tendermint/iavl v0.12.4 h1:hd1woxUGISKkfUWBA4mmmTwOua6PQZTJM/F0FDrmMV8= github.com/tendermint/iavl v0.12.4/go.mod h1:8LHakzt8/0G3/I8FUU0ReNx98S/EP6eyPJkAUvEXT/o= github.com/tendermint/tendermint v0.32.1/go.mod h1:jmPDAKuNkev9793/ivn/fTBnfpA9mGBww8MPRNPNxnU= @@ -246,6 +251,8 @@ github.com/tendermint/tendermint v0.32.7/go.mod h1:D2+A3pNjY+Po72X0mTfaXorFhiVI8 github.com/tendermint/tm-db v0.1.1/go.mod h1:0cPKWu2Mou3IlxecH+MEUSYc1Ch537alLe6CpFrKzgw= github.com/tendermint/tm-db v0.2.0 h1:rJxgdqn6fIiVJZy4zLpY1qVlyD0TU6vhkT4kEf71TQQ= github.com/tendermint/tm-db v0.2.0/go.mod h1:0cPKWu2Mou3IlxecH+MEUSYc1Ch537alLe6CpFrKzgw= +github.com/tendermint/tmlibs v0.9.0 h1:3aU/D2v3aecqpODOuBXCfi950bHTefD5Pps5X3XuJDc= +github.com/tendermint/tmlibs v0.9.0/go.mod h1:4L0tAKpLTioy14VnmbXYTLIJN0pCMiehxDMdN6zZfM8= github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc= github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0= @@ -253,6 +260,10 @@ github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= github.com/zondax/hid v0.9.0 h1:eiT3P6vNxAEVxXMw66eZUAAnU2zD33JBkfG/EnfAKl8= github.com/zondax/hid v0.9.0/go.mod h1:l5wttcP0jwtdLjqjMMWFVEE7d1zO0jvSPA9OPZxWpEM= +github.com/zondax/ledger-go v0.11.0 h1:EEqUh6eaZucWAaGo87G7sJiqRNJpzBZr+I9PpGgjjPg= +github.com/zondax/ledger-go v0.11.0/go.mod h1:NI6JDs8VWwgh+9Bf1vPZMm9Xufp2Q7Iwm2IzxJWzmus= +github.com/zondax/ledger-goclient v0.9.9 h1:XBvqkjluVda8dTYwPh2DPnlSGVEeoH1a1OprEAn8C98= +github.com/zondax/ledger-goclient v0.9.9/go.mod h1:ILyu7qO5zsod0bzyxY9NCMlFTb8AXZzJAJf0T85b2jA= go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.etcd.io/bbolt v1.3.3 h1:MUGmc65QhB3pIlaQ5bB4LwqSj6GIonVJXpZiaKNyaKk= go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= diff --git a/x/bep3/simulation/decoder.go b/x/bep3/simulation/decoder.go index 6c35c157..b5ff6001 100644 --- a/x/bep3/simulation/decoder.go +++ b/x/bep3/simulation/decoder.go @@ -1,12 +1,37 @@ package simulation import ( + "bytes" + "fmt" + "github.com/cosmos/cosmos-sdk/codec" cmn "github.com/tendermint/tendermint/libs/common" + + "github.com/kava-labs/kava/x/bep3/types" ) // DecodeStore unmarshals the KVPair's Value to the module's corresponding type func DecodeStore(cdc *codec.Codec, kvA, kvB cmn.KVPair) string { - // TODO implement this - return "" + switch { + case bytes.Equal(kvA.Key[:1], types.AtomicSwapKeyPrefix): + var swapA, swapB *types.AtomicSwap + cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &swapA) + cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &swapB) + return fmt.Sprintf("%v\n%v", swapA, swapB) + + case bytes.Equal(kvA.Key[:1], types.AssetSupplyKeyPrefix): + var supplyA, supplyB types.AssetSupply + cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &supplyA) + cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &supplyB) + return fmt.Sprintf("%s\n%s", supplyA, supplyB) + + case bytes.Equal(kvA.Key[:1], types.AtomicSwapByBlockPrefix), + bytes.Equal(kvA.Key[:1], types.AtomicSwapLongtermStoragePrefix): + var bytesA cmn.HexBytes = kvA.Value + var bytesB cmn.HexBytes = kvA.Value + return fmt.Sprintf("%s\n%s", bytesA.String(), bytesB.String()) + + default: + panic(fmt.Sprintf("invalid %s key prefix %X", types.ModuleName, kvA.Key[:1])) + } } diff --git a/x/cdp/simulation/decoder.go b/x/cdp/simulation/decoder.go index edef9051..202838a8 100644 --- a/x/cdp/simulation/decoder.go +++ b/x/cdp/simulation/decoder.go @@ -1,12 +1,60 @@ package simulation import ( + "bytes" + "encoding/binary" + "fmt" + "time" + "github.com/cosmos/cosmos-sdk/codec" + sdk "github.com/cosmos/cosmos-sdk/types" cmn "github.com/tendermint/tendermint/libs/common" + + "github.com/kava-labs/kava/x/cdp/types" ) // DecodeStore unmarshals the KVPair's Value to the corresponding cdp type func DecodeStore(cdc *codec.Codec, kvA, kvB cmn.KVPair) string { - // TODO implement this - return "" + switch { + case bytes.Equal(kvA.Key[:1], types.CdpIDKeyPrefix): + var cdpIDsA, cdpIDsB []uint64 + cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &cdpIDsA) + cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &cdpIDsB) + return fmt.Sprintf("%v\n%v", cdpIDsA, cdpIDsB) + + case bytes.Equal(kvA.Key[:1], types.CdpIDKey), + bytes.Equal(kvA.Key[:1], types.CollateralRatioIndexPrefix): + idA := binary.BigEndian.Uint64(kvA.Value) + idB := binary.BigEndian.Uint64(kvB.Value) + return fmt.Sprintf("%d\n%d", idA, idB) + + case bytes.Equal(kvA.Key[:1], types.DebtDenomKey), + bytes.Equal(kvA.Key[:1], types.GovDenomKey): + var denomA, denomB string + cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &denomA) + cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &denomB) + return fmt.Sprintf("%s\n%s", denomA, denomB) + + case bytes.Equal(kvA.Key[:1], types.DepositKeyPrefix): + var depositA, depositB types.Deposit + cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &depositA) + cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &depositB) + return fmt.Sprintf("%s\n%s", depositA, depositB) + + case bytes.Equal(kvA.Key[:1], types.PrincipalKeyPrefix): + var totalA, totalB sdk.Int + cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &totalA) + cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &totalB) + return fmt.Sprintf("%s\n%s", totalA, totalB) + + case bytes.Equal(kvA.Key[:1], types.PreviousBlockTimeKey), + bytes.Equal(kvA.Key[:1], types.PreviousDistributionTimeKey): + var timeA, timeB time.Time + cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &timeA) + cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &timeB) + return fmt.Sprintf("%s\n%s", timeA, timeB) + + default: + panic(fmt.Sprintf("invalid %s key prefix %X", types.ModuleName, kvA.Key[:1])) + } } diff --git a/x/kavadist/simulation/decoder.go b/x/kavadist/simulation/decoder.go index edef9051..d28aed07 100644 --- a/x/kavadist/simulation/decoder.go +++ b/x/kavadist/simulation/decoder.go @@ -1,12 +1,26 @@ package simulation import ( + "bytes" + "fmt" + "time" + "github.com/cosmos/cosmos-sdk/codec" cmn "github.com/tendermint/tendermint/libs/common" + + "github.com/kava-labs/kava/x/kavadist/types" ) // DecodeStore unmarshals the KVPair's Value to the corresponding cdp type func DecodeStore(cdc *codec.Codec, kvA, kvB cmn.KVPair) string { - // TODO implement this - return "" + switch { + case bytes.Equal(kvA.Key[:1], types.PreviousBlockTimeKey): + var timeA, timeB time.Time + cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &timeA) + cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &timeB) + return fmt.Sprintf("%s\n%s", timeA, timeB) + + default: + panic(fmt.Sprintf("invalid %s key prefix %X", types.ModuleName, kvA.Key[:1])) + } } diff --git a/x/pricefeed/simulation/decoder.go b/x/pricefeed/simulation/decoder.go index 115565b3..f0c27dee 100644 --- a/x/pricefeed/simulation/decoder.go +++ b/x/pricefeed/simulation/decoder.go @@ -1,12 +1,31 @@ package simulation import ( + "bytes" + "fmt" + "github.com/cosmos/cosmos-sdk/codec" cmn "github.com/tendermint/tendermint/libs/common" + + "github.com/kava-labs/kava/x/pricefeed/types" ) // DecodeStore unmarshals the KVPair's Value to the corresponding pricefeed type func DecodeStore(cdc *codec.Codec, kvA, kvB cmn.KVPair) string { - // TODO implement this - return "" + switch { + case bytes.Contains(kvA.Key[:1], []byte(types.CurrentPricePrefix)): + var priceA, priceB types.CurrentPrice + cdc.MustUnmarshalBinaryBare(kvA.Value, &priceA) + cdc.MustUnmarshalBinaryBare(kvB.Value, &priceB) + return fmt.Sprintf("%s\n%s", priceA, priceB) + + case bytes.Contains(kvA.Key[:1], []byte(types.RawPriceFeedPrefix)): + var postedPriceA, postedPriceB types.PostedPrice + cdc.MustUnmarshalBinaryBare(kvA.Value, &postedPriceA) + cdc.MustUnmarshalBinaryBare(kvB.Value, &postedPriceB) + return fmt.Sprintf("%s\n%s", postedPriceA, postedPriceB) + + default: + panic(fmt.Sprintf("invalid %s key prefix %X", types.ModuleName, kvA.Key[:1])) + } } From b473625b098b2361ac64ad6d7f250fc008e3d3c5 Mon Sep 17 00:00:00 2001 From: Federico Kunze Date: Wed, 1 Apr 2020 13:26:05 -0300 Subject: [PATCH 2/7] go mod verify and tidy --- go.mod | 7 ------- go.sum | 11 ----------- 2 files changed, 18 deletions(-) diff --git a/go.mod b/go.mod index d763e103..aa784d25 100644 --- a/go.mod +++ b/go.mod @@ -6,20 +6,13 @@ require ( github.com/btcsuite/btcd v0.20.1-beta // indirect github.com/cosmos/cosmos-sdk v0.34.4-0.20191010193331-18de630d0ae1 github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d // indirect - github.com/gogo/protobuf v1.3.0 github.com/gorilla/mux v1.7.3 - github.com/snikch/goodman v0.0.0-20171125024755-10e37e294daa github.com/spf13/cobra v0.0.5 github.com/spf13/viper v1.4.0 github.com/stretchr/testify v1.4.0 - github.com/tendermint/ed25519 v0.0.0-20171027050219-d8387025d2b9 // indirect github.com/tendermint/go-amino v0.15.0 - github.com/tendermint/go-crypto v0.9.0 github.com/tendermint/tendermint v0.32.7 github.com/tendermint/tm-db v0.2.0 - github.com/tendermint/tmlibs v0.9.0 // indirect - github.com/zondax/ledger-go v0.11.0 // indirect - github.com/zondax/ledger-goclient v0.9.9 // indirect golang.org/x/net v0.0.0-20190930134127-c5a3c61f89f3 // indirect gopkg.in/yaml.v2 v2.2.4 ) diff --git a/go.sum b/go.sum index 70d5658a..4a1f0603 100644 --- a/go.sum +++ b/go.sum @@ -40,7 +40,6 @@ github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7 github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= github.com/cosmos/cosmos-sdk v0.34.4-0.20191010193331-18de630d0ae1 h1:yb+E8HGzFnO0YwLS6OCBIAVWtN8KfCYoKeO9mgAmQN0= github.com/cosmos/cosmos-sdk v0.34.4-0.20191010193331-18de630d0ae1/go.mod h1:IGBhkbOK1ebLqMWjtgo99zUxWHsA5IOb6N9CI8nHs0Y= -github.com/cosmos/cosmos-sdk v0.38.2 h1:IeDZxxTgTMGJRZsV4s482O2gxjhLzToX5Zy1uwyasDs= github.com/cosmos/go-bip39 v0.0.0-20180618194314-52158e4697b8/go.mod h1:tSxLoYXyBmiFeKpvmq4dzayMdCjCnu8uqmCysIGBT2Y= github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d h1:49RLWk1j44Xu4fjHb6JFYmeUnDORVwHNkDxaQ0ctCVU= github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d/go.mod h1:tSxLoYXyBmiFeKpvmq4dzayMdCjCnu8uqmCysIGBT2Y= @@ -235,13 +234,9 @@ github.com/tendermint/btcd v0.1.1 h1:0VcxPfflS2zZ3RiOAHkBiFUcPvbtRj5O7zHmcJWHV7s github.com/tendermint/btcd v0.1.1/go.mod h1:DC6/m53jtQzr/NFmMNEu0rxf18/ktVoVtMrnDD5pN+U= github.com/tendermint/crypto v0.0.0-20190823183015-45b1026d81ae h1:AOXNM7c2Vvo45SjAgeWF8Wy+NS7/NCqzRNpUc+HPAec= github.com/tendermint/crypto v0.0.0-20190823183015-45b1026d81ae/go.mod h1:z4YtwM70uOnk8h0pjJYlj3zdYwi9l03By6iAIF5j/Pk= -github.com/tendermint/ed25519 v0.0.0-20171027050219-d8387025d2b9 h1:zccWau0P8FELSb4HTDJ88hRo+WVNMbIbg27rFqDrhCE= -github.com/tendermint/ed25519 v0.0.0-20171027050219-d8387025d2b9/go.mod h1:nt45hbhDkWVdMBkr2TOgOzCrpBccXdN09WOiOYTHVEk= github.com/tendermint/go-amino v0.14.1/go.mod h1:i/UKE5Uocn+argJJBb12qTZsCDBcAYMbR92AaJVmKso= github.com/tendermint/go-amino v0.15.0 h1:TC4e66P59W7ML9+bxio17CPKnxW3nKIRAYskntMAoRk= github.com/tendermint/go-amino v0.15.0/go.mod h1:TQU0M1i/ImAo+tYpZi73AU3V/dKeCoMC9Sphe2ZwGME= -github.com/tendermint/go-crypto v0.9.0 h1:knZL34Ccy6BDjsPXwBslVTtyUpvOVAGbZMHcQriXulM= -github.com/tendermint/go-crypto v0.9.0/go.mod h1:bL+jG0FvO892QRYHtA/lEIQSMMq7anlRPTGbsWzQntU= github.com/tendermint/iavl v0.12.4 h1:hd1woxUGISKkfUWBA4mmmTwOua6PQZTJM/F0FDrmMV8= github.com/tendermint/iavl v0.12.4/go.mod h1:8LHakzt8/0G3/I8FUU0ReNx98S/EP6eyPJkAUvEXT/o= github.com/tendermint/tendermint v0.32.1/go.mod h1:jmPDAKuNkev9793/ivn/fTBnfpA9mGBww8MPRNPNxnU= @@ -251,8 +246,6 @@ github.com/tendermint/tendermint v0.32.7/go.mod h1:D2+A3pNjY+Po72X0mTfaXorFhiVI8 github.com/tendermint/tm-db v0.1.1/go.mod h1:0cPKWu2Mou3IlxecH+MEUSYc1Ch537alLe6CpFrKzgw= github.com/tendermint/tm-db v0.2.0 h1:rJxgdqn6fIiVJZy4zLpY1qVlyD0TU6vhkT4kEf71TQQ= github.com/tendermint/tm-db v0.2.0/go.mod h1:0cPKWu2Mou3IlxecH+MEUSYc1Ch537alLe6CpFrKzgw= -github.com/tendermint/tmlibs v0.9.0 h1:3aU/D2v3aecqpODOuBXCfi950bHTefD5Pps5X3XuJDc= -github.com/tendermint/tmlibs v0.9.0/go.mod h1:4L0tAKpLTioy14VnmbXYTLIJN0pCMiehxDMdN6zZfM8= github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc= github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0= @@ -260,10 +253,6 @@ github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= github.com/zondax/hid v0.9.0 h1:eiT3P6vNxAEVxXMw66eZUAAnU2zD33JBkfG/EnfAKl8= github.com/zondax/hid v0.9.0/go.mod h1:l5wttcP0jwtdLjqjMMWFVEE7d1zO0jvSPA9OPZxWpEM= -github.com/zondax/ledger-go v0.11.0 h1:EEqUh6eaZucWAaGo87G7sJiqRNJpzBZr+I9PpGgjjPg= -github.com/zondax/ledger-go v0.11.0/go.mod h1:NI6JDs8VWwgh+9Bf1vPZMm9Xufp2Q7Iwm2IzxJWzmus= -github.com/zondax/ledger-goclient v0.9.9 h1:XBvqkjluVda8dTYwPh2DPnlSGVEeoH1a1OprEAn8C98= -github.com/zondax/ledger-goclient v0.9.9/go.mod h1:ILyu7qO5zsod0bzyxY9NCMlFTb8AXZzJAJf0T85b2jA= go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.etcd.io/bbolt v1.3.3 h1:MUGmc65QhB3pIlaQ5bB4LwqSj6GIonVJXpZiaKNyaKk= go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= From e02766bff36211fcf7f73735bfbfd8aa4c322617 Mon Sep 17 00:00:00 2001 From: Federico Kunze Date: Wed, 1 Apr 2020 13:33:18 -0300 Subject: [PATCH 3/7] x/auction: simulation decoder --- x/auction/simulation/decoder.go | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/x/auction/simulation/decoder.go b/x/auction/simulation/decoder.go index a64f8744..232fc005 100644 --- a/x/auction/simulation/decoder.go +++ b/x/auction/simulation/decoder.go @@ -1,12 +1,32 @@ package simulation import ( + "bytes" + "encoding/binary" + "fmt" + "github.com/cosmos/cosmos-sdk/codec" cmn "github.com/tendermint/tendermint/libs/common" + + "github.com/kava-labs/kava/x/auction/types" ) // DecodeStore unmarshals the KVPair's Value to the corresponding auction type func DecodeStore(cdc *codec.Codec, kvA, kvB cmn.KVPair) string { - // TODO implement this - return "" + switch { + case bytes.Equal(kvA.Key[:1], types.AuctionKeyPrefix): + var auctionA, auctionB types.Auction + cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &auctionA) + cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &auctionB) + return fmt.Sprintf("%v\n%v", auctionA, auctionB) + + case bytes.Equal(kvA.Key[:1], types.AuctionByTimeKeyPrefix), + bytes.Equal(kvA.Key[:1], types.NextAuctionIDKey): + auctionIDA := binary.BigEndian.Uint64(kvA.Value) + auctionIDB := binary.BigEndian.Uint64(kvB.Value) + return fmt.Sprintf("%d\n%d", auctionIDA, auctionIDB) + + default: + panic(fmt.Sprintf("invalid %s key prefix %X", types.ModuleName, kvA.Key[:1])) + } } From 9817a10ca6ecf14f001345db62fcfa5c4afbb26a Mon Sep 17 00:00:00 2001 From: Federico Kunze Date: Wed, 1 Apr 2020 15:36:46 -0300 Subject: [PATCH 4/7] validator-vesting: decoder_test --- x/validator-vesting/simulation/decoder.go | 2 +- .../simulation/decoder_test.go | 60 +++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 x/validator-vesting/simulation/decoder_test.go diff --git a/x/validator-vesting/simulation/decoder.go b/x/validator-vesting/simulation/decoder.go index f6c052f5..a09bbd81 100644 --- a/x/validator-vesting/simulation/decoder.go +++ b/x/validator-vesting/simulation/decoder.go @@ -26,6 +26,6 @@ func DecodeStore(cdc *codec.Codec, kvA, kvB cmn.KVPair) string { cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &btB) return fmt.Sprintf("%v\n%v", btA, btB) default: - panic(fmt.Sprintf("invalid account key %X", kvA.Key)) + panic(fmt.Sprintf("invalid %s key %X", types.ModuleName, kvA.Key)) } } diff --git a/x/validator-vesting/simulation/decoder_test.go b/x/validator-vesting/simulation/decoder_test.go new file mode 100644 index 00000000..fee10265 --- /dev/null +++ b/x/validator-vesting/simulation/decoder_test.go @@ -0,0 +1,60 @@ +package simulation + +import ( + "fmt" + "testing" + "time" + + "github.com/stretchr/testify/require" + + cmn "github.com/tendermint/tendermint/libs/common" + + "github.com/cosmos/cosmos-sdk/codec" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/auth" + + "github.com/kava-labs/kava/x/validator-vesting/internal/types" +) + +func makeTestCodec() (cdc *codec.Codec) { + cdc = codec.New() + sdk.RegisterCodec(cdc) + auth.RegisterCodec(cdc) + codec.RegisterCrypto(cdc) + types.RegisterCodec(cdc) + codec.RegisterEvidences(cdc) + return +} + +func TestDecodeDistributionStore(t *testing.T) { + cdc := makeTestCodec() + + acc := types.ValidatorVestingAccount{SigningThreshold: 1} + now := time.Now().UTC() + + kvPairs := cmn.KVPairs{ + cmn.KVPair{Key: types.ValidatorVestingAccountPrefix, Value: cdc.MustMarshalBinaryBare(acc)}, + cmn.KVPair{Key: types.BlocktimeKey, Value: cdc.MustMarshalBinaryLengthPrefixed(now)}, + cmn.KVPair{Key: []byte{0x99}, Value: []byte{0x99}}, + } + + tests := []struct { + name string + expectedLog string + }{ + {"ValidatorVestingAccount", fmt.Sprintf("%v\n%v", acc, acc)}, + {"BlockTime", fmt.Sprintf("%s\n%s", now, now)}, + {"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(cdc, kvPairs[i], kvPairs[i]) }, tt.name) + default: + require.Equal(t, tt.expectedLog, DecodeStore(cdc, kvPairs[i], kvPairs[i]), tt.name) + } + }) + } +} From 3f4aba1c7f16274497a621d01da8a5ef61ecdc7f Mon Sep 17 00:00:00 2001 From: Federico Kunze Date: Sat, 4 Apr 2020 19:42:35 -0300 Subject: [PATCH 5/7] decoder tests --- x/auction/simulation/decoder_test.go | 58 +++++++++++++++++++++ x/bep3/simulation/decoder_test.go | 61 ++++++++++++++++++++++ x/cdp/simulation/decoder_test.go | 72 ++++++++++++++++++++++++++ x/kavadist/simulation/decoder_test.go | 54 +++++++++++++++++++ x/pricefeed/simulation/decoder.go | 4 +- x/pricefeed/simulation/decoder_test.go | 57 ++++++++++++++++++++ 6 files changed, 304 insertions(+), 2 deletions(-) create mode 100644 x/auction/simulation/decoder_test.go create mode 100644 x/bep3/simulation/decoder_test.go create mode 100644 x/cdp/simulation/decoder_test.go create mode 100644 x/kavadist/simulation/decoder_test.go create mode 100644 x/pricefeed/simulation/decoder_test.go diff --git a/x/auction/simulation/decoder_test.go b/x/auction/simulation/decoder_test.go new file mode 100644 index 00000000..1aa5f749 --- /dev/null +++ b/x/auction/simulation/decoder_test.go @@ -0,0 +1,58 @@ +package simulation + +import ( + "fmt" + "testing" + "time" + + "github.com/stretchr/testify/require" + + cmn "github.com/tendermint/tendermint/libs/common" + + "github.com/cosmos/cosmos-sdk/codec" + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/kava-labs/kava/x/auction/types" +) + +func makeTestCodec() (cdc *codec.Codec) { + cdc = codec.New() + sdk.RegisterCodec(cdc) + types.RegisterCodec(cdc) + return +} + +func TestDecodeDistributionStore(t *testing.T) { + cdc := makeTestCodec() + + oneCoin := sdk.NewCoin("coin", sdk.OneInt()) + auction := types.NewSurplusAuction("me", oneCoin, "coin", time.Now().UTC()) + + kvPairs := cmn.KVPairs{ + cmn.KVPair{Key: types.AuctionKeyPrefix, Value: cdc.MustMarshalBinaryLengthPrefixed(&auction)}, + cmn.KVPair{Key: types.AuctionByTimeKeyPrefix, Value: sdk.Uint64ToBigEndian(2)}, + cmn.KVPair{Key: types.NextAuctionIDKey, Value: sdk.Uint64ToBigEndian(10)}, + cmn.KVPair{Key: []byte{0x99}, Value: []byte{0x99}}, + } + + tests := []struct { + name string + expectedLog string + }{ + {"Auction", fmt.Sprintf("%v\n%v", auction, auction)}, + {"AuctionByTime", "2\n2"}, + {"NextAuctionI", "10\n10"}, + {"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(cdc, kvPairs[i], kvPairs[i]) }, tt.name) + default: + require.Equal(t, tt.expectedLog, DecodeStore(cdc, kvPairs[i], kvPairs[i]), tt.name) + } + }) + } +} diff --git a/x/bep3/simulation/decoder_test.go b/x/bep3/simulation/decoder_test.go new file mode 100644 index 00000000..e9fc0a75 --- /dev/null +++ b/x/bep3/simulation/decoder_test.go @@ -0,0 +1,61 @@ +package simulation + +import ( + "fmt" + "testing" + + "github.com/stretchr/testify/require" + + cmn "github.com/tendermint/tendermint/libs/common" + + "github.com/cosmos/cosmos-sdk/codec" + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/kava-labs/kava/x/bep3/types" +) + +func makeTestCodec() (cdc *codec.Codec) { + cdc = codec.New() + sdk.RegisterCodec(cdc) + types.RegisterCodec(cdc) + return +} + +func TestDecodeDistributionStore(t *testing.T) { + cdc := makeTestCodec() + + oneCoin := sdk.NewCoin("coin", sdk.OneInt()) + swap := types.NewAtomicSwap(sdk.Coins{oneCoin}, nil, 10, 100, nil, nil, "otherChainSender", "otherChainRec", 200, types.Completed, true, types.Outgoing) + supply := types.AssetSupply{Denom: "coin", IncomingSupply: oneCoin, OutgoingSupply: oneCoin, CurrentSupply: oneCoin, Limit: oneCoin} + bz := cmn.HexBytes([]byte{1, 2}) + + kvPairs := cmn.KVPairs{ + cmn.KVPair{Key: types.AtomicSwapKeyPrefix, Value: cdc.MustMarshalBinaryLengthPrefixed(swap)}, + cmn.KVPair{Key: types.AssetSupplyKeyPrefix, Value: cdc.MustMarshalBinaryLengthPrefixed(supply)}, + cmn.KVPair{Key: types.AtomicSwapByBlockPrefix, Value: bz}, + cmn.KVPair{Key: types.AtomicSwapByBlockPrefix, Value: bz}, + cmn.KVPair{Key: []byte{0x99}, Value: []byte{0x99}}, + } + + tests := []struct { + name string + expectedLog string + }{ + {"AtomicSwap", fmt.Sprintf("%v\n%v", swap, swap)}, + {"AssetSupply", fmt.Sprintf("%v\n%v", supply, supply)}, + {"AtomicSwapByBlock", fmt.Sprintf("%s\n%s", bz, bz)}, + {"AtomicSwapLongtermStorage", fmt.Sprintf("%s\n%s", bz, bz)}, + {"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(cdc, kvPairs[i], kvPairs[i]) }, tt.name) + default: + require.Equal(t, tt.expectedLog, DecodeStore(cdc, kvPairs[i], kvPairs[i]), tt.name) + } + }) + } +} diff --git a/x/cdp/simulation/decoder_test.go b/x/cdp/simulation/decoder_test.go new file mode 100644 index 00000000..5790ea6d --- /dev/null +++ b/x/cdp/simulation/decoder_test.go @@ -0,0 +1,72 @@ +package simulation + +import ( + "fmt" + "testing" + "time" + + "github.com/stretchr/testify/require" + + cmn "github.com/tendermint/tendermint/libs/common" + + "github.com/cosmos/cosmos-sdk/codec" + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/kava-labs/kava/x/cdp/types" +) + +func makeTestCodec() (cdc *codec.Codec) { + cdc = codec.New() + sdk.RegisterCodec(cdc) + codec.RegisterCrypto(cdc) + types.RegisterCodec(cdc) + return +} + +func TestDecodeDistributionStore(t *testing.T) { + cdc := makeTestCodec() + + cdpIds := []uint64{1, 2, 3, 4, 5} + denom := "denom" + deposit := types.Deposit{CdpID: 1, Amount: sdk.NewCoins(sdk.NewCoin(denom, sdk.OneInt()))} + principal := sdk.OneInt() + prevDistTime := time.Now().UTC() + + kvPairs := cmn.KVPairs{ + cmn.KVPair{Key: types.CdpIDKeyPrefix, Value: cdc.MustMarshalBinaryLengthPrefixed(cdpIds)}, + cmn.KVPair{Key: types.CdpIDKey, Value: sdk.Uint64ToBigEndian(2)}, + cmn.KVPair{Key: types.CollateralRatioIndexPrefix, Value: sdk.Uint64ToBigEndian(10)}, + cmn.KVPair{Key: []byte(types.DebtDenomKey), Value: cdc.MustMarshalBinaryLengthPrefixed(denom)}, + cmn.KVPair{Key: []byte(types.GovDenomKey), Value: cdc.MustMarshalBinaryLengthPrefixed(denom)}, + cmn.KVPair{Key: []byte(types.DepositKeyPrefix), Value: cdc.MustMarshalBinaryLengthPrefixed(deposit)}, + cmn.KVPair{Key: []byte(types.PrincipalKeyPrefix), Value: cdc.MustMarshalBinaryLengthPrefixed(principal)}, + cmn.KVPair{Key: []byte(types.PreviousBlockTimeKey), Value: cdc.MustMarshalBinaryLengthPrefixed(prevDistTime)}, + cmn.KVPair{Key: []byte{0x99}, Value: []byte{0x99}}, + } + + tests := []struct { + name string + expectedLog string + }{ + {"CdpIDs", fmt.Sprintf("%v\n%v", cdpIds, cdpIds)}, + {"CdpID", "2\n2"}, + {"CollateralRatioIndex", "10\n10"}, + {"DebtDenom", fmt.Sprintf("%s\n%s", denom, denom)}, + {"GovDenom", fmt.Sprintf("%s\n%s", denom, denom)}, + {"DepositKeyPrefix", fmt.Sprintf("%v\n%v", deposit, deposit)}, + {"Principal", fmt.Sprintf("%v\n%v", principal, principal)}, + {"PreviousDistributionTime", fmt.Sprintf("%s\n%s", prevDistTime, prevDistTime)}, + {"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(cdc, kvPairs[i], kvPairs[i]) }, tt.name) + default: + require.Equal(t, tt.expectedLog, DecodeStore(cdc, kvPairs[i], kvPairs[i]), tt.name) + } + }) + } +} diff --git a/x/kavadist/simulation/decoder_test.go b/x/kavadist/simulation/decoder_test.go new file mode 100644 index 00000000..235b22ff --- /dev/null +++ b/x/kavadist/simulation/decoder_test.go @@ -0,0 +1,54 @@ +package simulation + +import ( + "fmt" + "testing" + "time" + + "github.com/stretchr/testify/require" + + cmn "github.com/tendermint/tendermint/libs/common" + + "github.com/cosmos/cosmos-sdk/codec" + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/kava-labs/kava/x/kavadist/types" +) + +func makeTestCodec() (cdc *codec.Codec) { + cdc = codec.New() + sdk.RegisterCodec(cdc) + codec.RegisterCrypto(cdc) + types.RegisterCodec(cdc) + return +} + +func TestDecodeDistributionStore(t *testing.T) { + cdc := makeTestCodec() + + prevBlockTime := time.Now().UTC() + + kvPairs := cmn.KVPairs{ + cmn.KVPair{Key: []byte(types.PreviousBlockTimeKey), Value: cdc.MustMarshalBinaryLengthPrefixed(prevBlockTime)}, + cmn.KVPair{Key: []byte{0x99}, Value: []byte{0x99}}, + } + + 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(cdc, kvPairs[i], kvPairs[i]) }, tt.name) + default: + require.Equal(t, tt.expectedLog, DecodeStore(cdc, kvPairs[i], kvPairs[i]), tt.name) + } + }) + } +} diff --git a/x/pricefeed/simulation/decoder.go b/x/pricefeed/simulation/decoder.go index f0c27dee..aaa01e9e 100644 --- a/x/pricefeed/simulation/decoder.go +++ b/x/pricefeed/simulation/decoder.go @@ -13,13 +13,13 @@ import ( // DecodeStore unmarshals the KVPair's Value to the corresponding pricefeed type func DecodeStore(cdc *codec.Codec, kvA, kvB cmn.KVPair) string { switch { - case bytes.Contains(kvA.Key[:1], []byte(types.CurrentPricePrefix)): + case bytes.Contains(kvA.Key, []byte(types.CurrentPricePrefix)): var priceA, priceB types.CurrentPrice cdc.MustUnmarshalBinaryBare(kvA.Value, &priceA) cdc.MustUnmarshalBinaryBare(kvB.Value, &priceB) return fmt.Sprintf("%s\n%s", priceA, priceB) - case bytes.Contains(kvA.Key[:1], []byte(types.RawPriceFeedPrefix)): + case bytes.Contains(kvA.Key, []byte(types.RawPriceFeedPrefix)): var postedPriceA, postedPriceB types.PostedPrice cdc.MustUnmarshalBinaryBare(kvA.Value, &postedPriceA) cdc.MustUnmarshalBinaryBare(kvB.Value, &postedPriceB) diff --git a/x/pricefeed/simulation/decoder_test.go b/x/pricefeed/simulation/decoder_test.go new file mode 100644 index 00000000..2cc846ec --- /dev/null +++ b/x/pricefeed/simulation/decoder_test.go @@ -0,0 +1,57 @@ +package simulation + +import ( + "fmt" + "testing" + "time" + + "github.com/stretchr/testify/require" + + cmn "github.com/tendermint/tendermint/libs/common" + + "github.com/cosmos/cosmos-sdk/codec" + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/kava-labs/kava/x/pricefeed/types" +) + +func makeTestCodec() (cdc *codec.Codec) { + cdc = codec.New() + sdk.RegisterCodec(cdc) + codec.RegisterCrypto(cdc) + types.RegisterCodec(cdc) + return +} + +func TestDecodeDistributionStore(t *testing.T) { + cdc := makeTestCodec() + + currentPrice := types.CurrentPrice{MarketID: "current", Price: sdk.OneDec()} + postedPrice := types.PostedPrice{MarketID: "posted", Price: sdk.OneDec(), Expiry: time.Now().UTC()} + + kvPairs := cmn.KVPairs{ + cmn.KVPair{Key: []byte(types.CurrentPricePrefix), Value: cdc.MustMarshalBinaryBare(currentPrice)}, + cmn.KVPair{Key: []byte(types.RawPriceFeedPrefix), Value: cdc.MustMarshalBinaryBare(postedPrice)}, + cmn.KVPair{Key: []byte{0x99}, Value: []byte{0x99}}, + } + + tests := []struct { + name string + expectedLog string + }{ + {"CurrentPrice", fmt.Sprintf("%v\n%v", currentPrice, currentPrice)}, + {"PostedPrice", fmt.Sprintf("%s\n%s", postedPrice, postedPrice)}, + {"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(cdc, kvPairs[i], kvPairs[i]) }, tt.name) + default: + require.Equal(t, tt.expectedLog, DecodeStore(cdc, kvPairs[i], kvPairs[i]), tt.name) + } + }) + } +} From 66c73362c84b80781147536aae0bd62316cbf99e Mon Sep 17 00:00:00 2001 From: Federico Kunze Date: Mon, 6 Apr 2020 18:43:43 -0400 Subject: [PATCH 6/7] address comments from review --- x/cdp/simulation/decoder.go | 6 ++++++ x/cdp/simulation/decoder_test.go | 6 +++++- x/pricefeed/simulation/decoder.go | 2 +- x/pricefeed/simulation/decoder_test.go | 2 +- x/validator-vesting/simulation/decoder_test.go | 2 +- 5 files changed, 14 insertions(+), 4 deletions(-) diff --git a/x/cdp/simulation/decoder.go b/x/cdp/simulation/decoder.go index 202838a8..b2bc1fd0 100644 --- a/x/cdp/simulation/decoder.go +++ b/x/cdp/simulation/decoder.go @@ -22,6 +22,12 @@ func DecodeStore(cdc *codec.Codec, kvA, kvB cmn.KVPair) string { cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &cdpIDsB) return fmt.Sprintf("%v\n%v", cdpIDsA, cdpIDsB) + case bytes.Equal(kvA.Key[:1], types.CdpKeyPrefix): + var cdpA, cdpB types.CDP + cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &cdpA) + cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &cdpB) + return fmt.Sprintf("%v\n%v", cdpA, cdpB) + case bytes.Equal(kvA.Key[:1], types.CdpIDKey), bytes.Equal(kvA.Key[:1], types.CollateralRatioIndexPrefix): idA := binary.BigEndian.Uint64(kvA.Value) diff --git a/x/cdp/simulation/decoder_test.go b/x/cdp/simulation/decoder_test.go index 5790ea6d..52927624 100644 --- a/x/cdp/simulation/decoder_test.go +++ b/x/cdp/simulation/decoder_test.go @@ -28,12 +28,15 @@ func TestDecodeDistributionStore(t *testing.T) { cdpIds := []uint64{1, 2, 3, 4, 5} denom := "denom" - deposit := types.Deposit{CdpID: 1, Amount: sdk.NewCoins(sdk.NewCoin(denom, sdk.OneInt()))} + oneCoins := sdk.NewCoins(sdk.NewCoin(denom, sdk.OneInt())) + deposit := types.Deposit{CdpID: 1, Amount: oneCoins} principal := sdk.OneInt() prevDistTime := time.Now().UTC() + cdp := types.CDP{ID: 1, FeesUpdated: prevDistTime, Collateral: oneCoins, Principal: oneCoins, AccumulatedFees: oneCoins} kvPairs := cmn.KVPairs{ cmn.KVPair{Key: types.CdpIDKeyPrefix, Value: cdc.MustMarshalBinaryLengthPrefixed(cdpIds)}, + cmn.KVPair{Key: types.CdpKeyPrefix, Value: cdc.MustMarshalBinaryLengthPrefixed(cdp)}, cmn.KVPair{Key: types.CdpIDKey, Value: sdk.Uint64ToBigEndian(2)}, cmn.KVPair{Key: types.CollateralRatioIndexPrefix, Value: sdk.Uint64ToBigEndian(10)}, cmn.KVPair{Key: []byte(types.DebtDenomKey), Value: cdc.MustMarshalBinaryLengthPrefixed(denom)}, @@ -49,6 +52,7 @@ func TestDecodeDistributionStore(t *testing.T) { expectedLog string }{ {"CdpIDs", fmt.Sprintf("%v\n%v", cdpIds, cdpIds)}, + {"CDP", fmt.Sprintf("%v\n%v", cdp, cdp)}, {"CdpID", "2\n2"}, {"CollateralRatioIndex", "10\n10"}, {"DebtDenom", fmt.Sprintf("%s\n%s", denom, denom)}, diff --git a/x/pricefeed/simulation/decoder.go b/x/pricefeed/simulation/decoder.go index aaa01e9e..9693b6e3 100644 --- a/x/pricefeed/simulation/decoder.go +++ b/x/pricefeed/simulation/decoder.go @@ -20,7 +20,7 @@ func DecodeStore(cdc *codec.Codec, kvA, kvB cmn.KVPair) string { return fmt.Sprintf("%s\n%s", priceA, priceB) case bytes.Contains(kvA.Key, []byte(types.RawPriceFeedPrefix)): - var postedPriceA, postedPriceB types.PostedPrice + var postedPriceA, postedPriceB []types.PostedPrice cdc.MustUnmarshalBinaryBare(kvA.Value, &postedPriceA) cdc.MustUnmarshalBinaryBare(kvB.Value, &postedPriceB) return fmt.Sprintf("%s\n%s", postedPriceA, postedPriceB) diff --git a/x/pricefeed/simulation/decoder_test.go b/x/pricefeed/simulation/decoder_test.go index 2cc846ec..bc886819 100644 --- a/x/pricefeed/simulation/decoder_test.go +++ b/x/pricefeed/simulation/decoder_test.go @@ -27,7 +27,7 @@ func TestDecodeDistributionStore(t *testing.T) { cdc := makeTestCodec() currentPrice := types.CurrentPrice{MarketID: "current", Price: sdk.OneDec()} - postedPrice := types.PostedPrice{MarketID: "posted", Price: sdk.OneDec(), Expiry: time.Now().UTC()} + postedPrice := []types.PostedPrice{{MarketID: "posted", Price: sdk.OneDec(), Expiry: time.Now().UTC()}} kvPairs := cmn.KVPairs{ cmn.KVPair{Key: []byte(types.CurrentPricePrefix), Value: cdc.MustMarshalBinaryBare(currentPrice)}, diff --git a/x/validator-vesting/simulation/decoder_test.go b/x/validator-vesting/simulation/decoder_test.go index fee10265..7cb532ca 100644 --- a/x/validator-vesting/simulation/decoder_test.go +++ b/x/validator-vesting/simulation/decoder_test.go @@ -13,7 +13,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth" - "github.com/kava-labs/kava/x/validator-vesting/internal/types" + "github.com/kava-labs/kava/x/validator-vesting/types" ) func makeTestCodec() (cdc *codec.Codec) { From 71d862300d86d6b9d9dcb6401fcda4e7cf119bbd Mon Sep 17 00:00:00 2001 From: Federico Kunze Date: Mon, 6 Apr 2020 18:45:46 -0400 Subject: [PATCH 7/7] remove pointer from AtomicSwap --- x/bep3/simulation/decoder.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/bep3/simulation/decoder.go b/x/bep3/simulation/decoder.go index b5ff6001..351b0b00 100644 --- a/x/bep3/simulation/decoder.go +++ b/x/bep3/simulation/decoder.go @@ -14,7 +14,7 @@ import ( func DecodeStore(cdc *codec.Codec, kvA, kvB cmn.KVPair) string { switch { case bytes.Equal(kvA.Key[:1], types.AtomicSwapKeyPrefix): - var swapA, swapB *types.AtomicSwap + var swapA, swapB types.AtomicSwap cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &swapA) cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &swapB) return fmt.Sprintf("%v\n%v", swapA, swapB)