...
This commit is contained in:
parent
ab4661f88b
commit
b3d6a59c61
|
@ -154,26 +154,24 @@ func (k Keeper) GetRedelegation(ctx sdk.Context,
|
||||||
func (k Keeper) GetRedelegationsFromValidator(ctx sdk.Context, valAddr sdk.Address) (redelegations []types.Redelegation) {
|
func (k Keeper) GetRedelegationsFromValidator(ctx sdk.Context, valAddr sdk.Address) (redelegations []types.Redelegation) {
|
||||||
store := ctx.KVStore(k.storeKey)
|
store := ctx.KVStore(k.storeKey)
|
||||||
iterator := sdk.KVStorePrefixIterator(store, GetREDsFromValSrcIndexKey(valAddr))
|
iterator := sdk.KVStorePrefixIterator(store, GetREDsFromValSrcIndexKey(valAddr))
|
||||||
i := 0
|
for {
|
||||||
for ; ; i++ {
|
|
||||||
fmt.Printf("debug i: %v\n", i)
|
|
||||||
if !iterator.Valid() {
|
if !iterator.Valid() {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
redelegationKeyOrig := iterator.Value()
|
|
||||||
redelegationBytes2 := store.Get(redelegationKeyOrig)
|
|
||||||
var redelegation2 types.Redelegation
|
|
||||||
k.cdc.MustUnmarshalBinary(redelegationBytes2, &redelegation2)
|
|
||||||
fmt.Printf("debug orig redelegation2: %v\n", redelegation2)
|
|
||||||
|
|
||||||
redelegationKey := GetREDKeyFromValSrcIndexKey(iterator.Key())
|
fmt.Println("called")
|
||||||
fmt.Printf("debug orig redelegationKey: %v\n", redelegationKeyOrig)
|
//redelegationKey := iterator.Value()
|
||||||
|
iKey := iterator.Key()
|
||||||
|
redelegationKey := GetREDKeyFromValSrcIndexKey(iKey)
|
||||||
|
fmt.Printf("debug iteratorValue: %v\n", iterator.Value())
|
||||||
|
fmt.Printf("debug iteratorKey: %v\n", iKey)
|
||||||
fmt.Printf("debug redelegationKey: %v\n", redelegationKey)
|
fmt.Printf("debug redelegationKey: %v\n", redelegationKey)
|
||||||
fmt.Printf("debug iteratorKey: %v\n", iterator.Key())
|
|
||||||
redelegationBytes := store.Get(redelegationKey)
|
redelegationBytes := store.Get(redelegationKey)
|
||||||
var redelegation types.Redelegation
|
var redelegation types.Redelegation
|
||||||
k.cdc.MustUnmarshalBinary(redelegationBytes, &redelegation)
|
k.cdc.MustUnmarshalBinary(redelegationBytes, &redelegation)
|
||||||
redelegations = append(redelegations, redelegation)
|
redelegations = append(redelegations, redelegation)
|
||||||
|
|
||||||
iterator.Next()
|
iterator.Next()
|
||||||
}
|
}
|
||||||
iterator.Close()
|
iterator.Close()
|
||||||
|
|
|
@ -180,6 +180,40 @@ func TestUnbondDelegation(t *testing.T) {
|
||||||
require.Equal(t, int64(4), pool.BondedTokens)
|
require.Equal(t, int64(4), pool.BondedTokens)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// tests Get/Set/Remove/Has UnbondingDelegation
|
||||||
|
func TestGetRedelegationsFromValidator(t *testing.T) {
|
||||||
|
ctx, _, keeper := CreateTestInput(t, false, 0)
|
||||||
|
|
||||||
|
rd := types.Redelegation{
|
||||||
|
DelegatorAddr: addrDels[0],
|
||||||
|
ValidatorSrcAddr: addrVals[0],
|
||||||
|
ValidatorDstAddr: addrVals[1],
|
||||||
|
CreationHeight: 0,
|
||||||
|
MinTime: 0,
|
||||||
|
SharesSrc: sdk.NewRat(5),
|
||||||
|
SharesDst: sdk.NewRat(5),
|
||||||
|
}
|
||||||
|
|
||||||
|
// set and retrieve a record
|
||||||
|
keeper.SetRedelegation(ctx, rd)
|
||||||
|
resBond, found := keeper.GetRedelegation(ctx, addrDels[0], addrVals[0], addrVals[1])
|
||||||
|
require.True(t, found)
|
||||||
|
fmt.Printf("debug addrDels[0]: %v\n", addrDels[0])
|
||||||
|
fmt.Printf("debug addrVals[0]: %v\n", addrVals[0])
|
||||||
|
fmt.Printf("debug addrVals[1]: %v\n", addrVals[1])
|
||||||
|
|
||||||
|
fmt.Println("zoo0")
|
||||||
|
redelegations := keeper.GetRedelegationsFromValidator(ctx, addrVals[0])
|
||||||
|
require.Equal(t, 1, len(redelegations))
|
||||||
|
require.True(t, redelegations[0].Equal(resBond))
|
||||||
|
|
||||||
|
fmt.Println("zoo1")
|
||||||
|
redelegations = keeper.GetRedelegationsFromValidator(ctx, addrVals[0])
|
||||||
|
require.Equal(t, 1, len(redelegations))
|
||||||
|
require.True(t, redelegations[0].Equal(resBond))
|
||||||
|
fmt.Println("zoo2")
|
||||||
|
}
|
||||||
|
|
||||||
// tests Get/Set/Remove/Has UnbondingDelegation
|
// tests Get/Set/Remove/Has UnbondingDelegation
|
||||||
func TestRedelegation(t *testing.T) {
|
func TestRedelegation(t *testing.T) {
|
||||||
ctx, _, keeper := CreateTestInput(t, false, 0)
|
ctx, _, keeper := CreateTestInput(t, false, 0)
|
||||||
|
@ -203,21 +237,13 @@ func TestRedelegation(t *testing.T) {
|
||||||
resBond, found := keeper.GetRedelegation(ctx, addrDels[0], addrVals[0], addrVals[1])
|
resBond, found := keeper.GetRedelegation(ctx, addrDels[0], addrVals[0], addrVals[1])
|
||||||
require.True(t, found)
|
require.True(t, found)
|
||||||
|
|
||||||
fmt.Println("zoo0")
|
|
||||||
redelegations := keeper.GetRedelegationsFromValidator(ctx, addrVals[0])
|
redelegations := keeper.GetRedelegationsFromValidator(ctx, addrVals[0])
|
||||||
require.Equal(t, 1, len(redelegations))
|
require.Equal(t, 1, len(redelegations))
|
||||||
require.True(t, redelegations[0].Equal(resBond))
|
require.True(t, redelegations[0].Equal(resBond))
|
||||||
|
|
||||||
fmt.Println("zoo1")
|
|
||||||
redelegations = keeper.GetRedelegationsFromValidator(ctx, addrVals[0])
|
|
||||||
require.Equal(t, 1, len(redelegations))
|
|
||||||
require.True(t, redelegations[0].Equal(resBond))
|
|
||||||
fmt.Println("zoo2")
|
|
||||||
|
|
||||||
// check if has the redelegation
|
// check if has the redelegation
|
||||||
has = keeper.HasReceivingRedelegation(ctx, addrDels[0], addrVals[1])
|
has = keeper.HasReceivingRedelegation(ctx, addrDels[0], addrVals[1])
|
||||||
require.True(t, has)
|
require.True(t, has)
|
||||||
fmt.Println("hoolahoop")
|
|
||||||
|
|
||||||
// modify a records, save, and retrieve
|
// modify a records, save, and retrieve
|
||||||
rd.SharesSrc = sdk.NewRat(21)
|
rd.SharesSrc = sdk.NewRat(21)
|
||||||
|
@ -228,12 +254,10 @@ func TestRedelegation(t *testing.T) {
|
||||||
resBond, found = keeper.GetRedelegation(ctx, addrDels[0], addrVals[0], addrVals[1])
|
resBond, found = keeper.GetRedelegation(ctx, addrDels[0], addrVals[0], addrVals[1])
|
||||||
require.True(t, found)
|
require.True(t, found)
|
||||||
require.True(t, rd.Equal(resBond))
|
require.True(t, rd.Equal(resBond))
|
||||||
fmt.Println("hippo2")
|
|
||||||
|
|
||||||
redelegations = keeper.GetRedelegationsFromValidator(ctx, addrVals[0])
|
redelegations = keeper.GetRedelegationsFromValidator(ctx, addrVals[0])
|
||||||
require.Equal(t, 1, len(redelegations))
|
require.Equal(t, 1, len(redelegations))
|
||||||
require.True(t, redelegations[0].Equal(resBond))
|
require.True(t, redelegations[0].Equal(resBond))
|
||||||
fmt.Println("zzzzzzzzzzzzzzzzzzebra")
|
|
||||||
|
|
||||||
// delete a record
|
// delete a record
|
||||||
keeper.RemoveRedelegation(ctx, rd)
|
keeper.RemoveRedelegation(ctx, rd)
|
||||||
|
|
|
@ -2,6 +2,7 @@ package keeper
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/tendermint/tendermint/crypto"
|
"github.com/tendermint/tendermint/crypto"
|
||||||
|
|
||||||
|
@ -205,6 +206,9 @@ func GetREDKeyFromValSrcIndexKey(IndexKey []byte) []byte {
|
||||||
valSrcAddr := addrs[:split]
|
valSrcAddr := addrs[:split]
|
||||||
delAddr := addrs[split : 2*split]
|
delAddr := addrs[split : 2*split]
|
||||||
valDstAddr := addrs[2*split:]
|
valDstAddr := addrs[2*split:]
|
||||||
|
fmt.Printf("debug delAddr: %v\n", delAddr)
|
||||||
|
fmt.Printf("debug valSrcAddr: %v\n", valSrcAddr)
|
||||||
|
fmt.Printf("debug valDstAddr: %v\n", valDstAddr)
|
||||||
return GetREDKey(delAddr, valSrcAddr, valDstAddr)
|
return GetREDKey(delAddr, valSrcAddr, valDstAddr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue