Merge remote-tracking branch 'origin/develop' into rigel/fee-distribution
This commit is contained in:
commit
83c2781c1c
|
@ -136,6 +136,7 @@ IMPROVEMENTS
|
|||
* [genesis] \#2229 Ensure that there are no duplicate accounts or validators in the genesis state.
|
||||
* Add SDK validation to `config.toml` (namely disabling `create_empty_blocks`) \#1571
|
||||
* \#1941(https://github.com/cosmos/cosmos-sdk/issues/1941) Version is now inferred via `git describe --tags`.
|
||||
* [x/distribution] \#1671 add distribution types and tests
|
||||
|
||||
* SDK
|
||||
* [tools] Make get_vendor_deps deletes `.vendor-new` directories, in case scratch files are present.
|
||||
|
|
|
@ -177,28 +177,28 @@ func GetREDByValDstIndexKey(delAddr sdk.AccAddress, valSrcAddr, valDstAddr sdk.V
|
|||
return key
|
||||
}
|
||||
|
||||
// rearranges the ValSrcIndexKey to get the REDKey
|
||||
func GetREDKeyFromValSrcIndexKey(IndexKey []byte) []byte {
|
||||
addrs := IndexKey[1:] // remove prefix bytes
|
||||
if len(addrs) != 3*sdk.AddrLen {
|
||||
// GetREDKeyFromValSrcIndexKey rearranges the ValSrcIndexKey to get the REDKey
|
||||
func GetREDKeyFromValSrcIndexKey(indexKey []byte) []byte {
|
||||
// note that first byte is prefix byte
|
||||
if len(indexKey) != 3*sdk.AddrLen+1 {
|
||||
panic("unexpected key length")
|
||||
}
|
||||
valSrcAddr := addrs[:sdk.AddrLen]
|
||||
delAddr := addrs[sdk.AddrLen : 2*sdk.AddrLen]
|
||||
valDstAddr := addrs[2*sdk.AddrLen:]
|
||||
valSrcAddr := indexKey[1 : sdk.AddrLen+1]
|
||||
delAddr := indexKey[sdk.AddrLen+1 : 2*sdk.AddrLen+1]
|
||||
valDstAddr := indexKey[2*sdk.AddrLen+1 : 3*sdk.AddrLen+1]
|
||||
|
||||
return GetREDKey(delAddr, valSrcAddr, valDstAddr)
|
||||
}
|
||||
|
||||
// rearranges the ValDstIndexKey to get the REDKey
|
||||
func GetREDKeyFromValDstIndexKey(IndexKey []byte) []byte {
|
||||
addrs := IndexKey[1:] // remove prefix bytes
|
||||
if len(addrs) != 3*sdk.AddrLen {
|
||||
// GetREDKeyFromValDstIndexKey rearranges the ValDstIndexKey to get the REDKey
|
||||
func GetREDKeyFromValDstIndexKey(indexKey []byte) []byte {
|
||||
// note that first byte is prefix byte
|
||||
if len(indexKey) != 3*sdk.AddrLen+1 {
|
||||
panic("unexpected key length")
|
||||
}
|
||||
valDstAddr := addrs[:sdk.AddrLen]
|
||||
delAddr := addrs[sdk.AddrLen : 2*sdk.AddrLen]
|
||||
valSrcAddr := addrs[2*sdk.AddrLen:]
|
||||
valDstAddr := indexKey[1 : sdk.AddrLen+1]
|
||||
delAddr := indexKey[sdk.AddrLen+1 : 2*sdk.AddrLen+1]
|
||||
valSrcAddr := indexKey[2*sdk.AddrLen+1 : 3*sdk.AddrLen+1]
|
||||
return GetREDKey(delAddr, valSrcAddr, valDstAddr)
|
||||
}
|
||||
|
||||
|
|
|
@ -2,30 +2,43 @@ package keeper
|
|||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"math/big"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/stake/types"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||
)
|
||||
|
||||
var (
|
||||
pk1 = ed25519.GenPrivKey().PubKey()
|
||||
pk1 = ed25519.GenPrivKeyFromSecret([]byte{1}).PubKey()
|
||||
pk2 = ed25519.GenPrivKeyFromSecret([]byte{2}).PubKey()
|
||||
pk3 = ed25519.GenPrivKeyFromSecret([]byte{3}).PubKey()
|
||||
addr1 = pk1.Address()
|
||||
addr2 = pk2.Address()
|
||||
addr3 = pk3.Address()
|
||||
)
|
||||
|
||||
func TestGetValidatorPowerRank(t *testing.T) {
|
||||
valAddr1 := sdk.ValAddress(pk1.Bytes())
|
||||
valAddr1 := sdk.ValAddress(addr1)
|
||||
emptyDesc := types.Description{}
|
||||
val1 := types.NewValidator(valAddr1, pk1, emptyDesc)
|
||||
val1.Tokens = sdk.NewDec(12)
|
||||
val1.Tokens = sdk.NewDec(0)
|
||||
val2, val3, val4 := val1, val1, val1
|
||||
val2.Tokens = sdk.NewDec(1)
|
||||
val3.Tokens = sdk.NewDec(10)
|
||||
x := new(big.Int).Exp(big.NewInt(2), big.NewInt(40), big.NewInt(0))
|
||||
val4.Tokens = sdk.NewDecFromBigInt(x)
|
||||
|
||||
tests := []struct {
|
||||
validator types.Validator
|
||||
wantHex string
|
||||
}{
|
||||
{val1, "05303030303030303030303132ffffffffffffffffffff"},
|
||||
{val1, "05303030303030303030303030ffffffffffffffffffff"},
|
||||
{val2, "05303030303030303030303031ffffffffffffffffffff"},
|
||||
{val3, "05303030303030303030303130ffffffffffffffffffff"},
|
||||
{val4, "0531303939353131363237373736ffffffffffffffffffff"},
|
||||
}
|
||||
for i, tt := range tests {
|
||||
got := hex.EncodeToString(getValidatorPowerRank(tt.validator))
|
||||
|
@ -33,3 +46,45 @@ func TestGetValidatorPowerRank(t *testing.T) {
|
|||
assert.Equal(t, tt.wantHex, got, "Keys did not match on test case %d", i)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetREDByValDstIndexKey(t *testing.T) {
|
||||
tests := []struct {
|
||||
delAddr sdk.AccAddress
|
||||
valSrcAddr sdk.ValAddress
|
||||
valDstAddr sdk.ValAddress
|
||||
wantHex string
|
||||
}{
|
||||
{sdk.AccAddress(addr1), sdk.ValAddress(addr1), sdk.ValAddress(addr1),
|
||||
"0c63d771218209d8bd03c482f69dfba57310f0860963d771218209d8bd03c482f69dfba57310f0860963d771218209d8bd03c482f69dfba57310f08609"},
|
||||
{sdk.AccAddress(addr1), sdk.ValAddress(addr2), sdk.ValAddress(addr3),
|
||||
"0c3ab62f0d93849be495e21e3e9013a517038f45bd63d771218209d8bd03c482f69dfba57310f086095ef3b5f25c54946d4a89fc0d09d2f126614540f2"},
|
||||
{sdk.AccAddress(addr2), sdk.ValAddress(addr1), sdk.ValAddress(addr3),
|
||||
"0c3ab62f0d93849be495e21e3e9013a517038f45bd5ef3b5f25c54946d4a89fc0d09d2f126614540f263d771218209d8bd03c482f69dfba57310f08609"},
|
||||
}
|
||||
for i, tt := range tests {
|
||||
got := hex.EncodeToString(GetREDByValDstIndexKey(tt.delAddr, tt.valSrcAddr, tt.valDstAddr))
|
||||
|
||||
assert.Equal(t, tt.wantHex, got, "Keys did not match on test case %d", i)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetREDByValSrcIndexKey(t *testing.T) {
|
||||
tests := []struct {
|
||||
delAddr sdk.AccAddress
|
||||
valSrcAddr sdk.ValAddress
|
||||
valDstAddr sdk.ValAddress
|
||||
wantHex string
|
||||
}{
|
||||
{sdk.AccAddress(addr1), sdk.ValAddress(addr1), sdk.ValAddress(addr1),
|
||||
"0b63d771218209d8bd03c482f69dfba57310f0860963d771218209d8bd03c482f69dfba57310f0860963d771218209d8bd03c482f69dfba57310f08609"},
|
||||
{sdk.AccAddress(addr1), sdk.ValAddress(addr2), sdk.ValAddress(addr3),
|
||||
"0b5ef3b5f25c54946d4a89fc0d09d2f126614540f263d771218209d8bd03c482f69dfba57310f086093ab62f0d93849be495e21e3e9013a517038f45bd"},
|
||||
{sdk.AccAddress(addr2), sdk.ValAddress(addr1), sdk.ValAddress(addr3),
|
||||
"0b63d771218209d8bd03c482f69dfba57310f086095ef3b5f25c54946d4a89fc0d09d2f126614540f23ab62f0d93849be495e21e3e9013a517038f45bd"},
|
||||
}
|
||||
for i, tt := range tests {
|
||||
got := hex.EncodeToString(GetREDByValSrcIndexKey(tt.delAddr, tt.valSrcAddr, tt.valDstAddr))
|
||||
|
||||
assert.Equal(t, tt.wantHex, got, "Keys did not match on test case %d", i)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue