precommit power tests

This commit is contained in:
rigelrozanski 2018-05-04 00:02:45 -04:00
parent 750cbc53ec
commit 28e4ec8336
3 changed files with 18 additions and 9 deletions

View File

@ -9,11 +9,12 @@ func (k Keeper) FeeHandler(ctx sdk.Context, collectedFees sdk.Coins) {
pool := k.GetPool(ctx)
params := k.GetParams(ctx)
// XXX calculate
sumOfVotingPowerOfPrecommitValidators := sdk.NewRat(67, 100)
// XXX determine
candidate := NewCandidate(addrs[0], pks[0], Description{})
toProposer := coinsMulRat(collectedFees, (sdk.NewRat(1, 100).Add(sdk.NewRat(4, 100).Mul(sumOfVotingPowerOfPrecommitValidators).Quo(pool.BondedShares))))
// calculate the proposer reward
precommitPower := k.GetTotalPrecommitVotingPower(ctx)
toProposer := coinsMulRat(collectedFees, (sdk.NewRat(1, 100).Add(sdk.NewRat(4, 100).Mul(precommitPower).Quo(pool.BondedShares))))
candidate.ProposerRewardPool = candidate.ProposerRewardPool.Plus(toProposer)
toReservePool := coinsMulRat(collectedFees, params.ReservePoolFee)

View File

@ -285,7 +285,7 @@ func (k Keeper) IsRecentValidator(ctx sdk.Context, pk crypto.PubKey) bool {
return true
}
// Is the power of non-absent prevotes
// cummulative power of the non-absent prevotes
func (k Keeper) GetTotalPrecommitVotingPower(ctx sdk.Context) sdk.Rat {
store := ctx.KVStore(k.storeKey)
@ -311,7 +311,7 @@ func (k Keeper) GetTotalPrecommitVotingPower(ctx sdk.Context) sdk.Rat {
}
}
if skip {
break
continue
}
bz := iterator.Value()

View File

@ -638,10 +638,7 @@ func TestIsRecentValidator(t *testing.T) {
func TestGetTotalPrecommitVotingPower(t *testing.T) {
ctx, _, keeper := createTestInput(t, false, 0)
// set absent validators to be the 1st and 3rd record sorted by pubKey address
ctx = ctx.WithAbsentValidators([]int32{1, 3})
amts := []int64{9, 8, 7, 10, 6}
amts := []int64{10000, 1000, 100, 10, 1}
var candidatesIn [5]Candidate
for i, amt := range amts {
candidatesIn[i] = NewCandidate(addrVals[i], pks[i], Description{})
@ -653,6 +650,17 @@ func TestGetTotalPrecommitVotingPower(t *testing.T) {
// test that an empty validator set doesn't have any validators
validators := keeper.GetValidators(ctx)
assert.Equal(t, 5, len(validators))
totPow := keeper.GetTotalPrecommitVotingPower(ctx)
exp := sdk.NewRat(11111)
assert.True(t, exp.Equal(totPow), "exp %v, got %v", exp, totPow)
// set absent validators to be the 1st and 3rd record sorted by pubKey address
ctx = ctx.WithAbsentValidators([]int32{1, 3})
totPow = keeper.GetTotalPrecommitVotingPower(ctx)
// XXX verify that this order should infact exclude these two records
exp = sdk.NewRat(11100)
assert.True(t, exp.Equal(totPow), "exp %v, got %v", exp, totPow)
}
func TestParams(t *testing.T) {