address comments from review

This commit is contained in:
Federico Kunze 2020-04-06 18:43:43 -04:00
parent f827d896ba
commit 66c73362c8
No known key found for this signature in database
GPG Key ID: 655F93A970080A30
5 changed files with 14 additions and 4 deletions

View File

@ -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)

View File

@ -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)},

View File

@ -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)

View File

@ -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)},

View File

@ -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) {