mirror of
https://github.com/planetmint/planetmint-go.git
synced 2025-11-24 22:45:45 +00:00
test: add additonal validatorPopReward reallocation test
Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>
This commit is contained in:
parent
5d84ae6806
commit
cc7af11974
@ -70,7 +70,7 @@ func (k Keeper) GetChallenges(ctx sdk.Context) (challenges []types.Challenge, er
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (k Keeper) storeChallangeInitiatorReward(ctx sdk.Context, height int64, amount uint64) {
|
func (k Keeper) StoreChallangeInitiatorReward(ctx sdk.Context, height int64, amount uint64) {
|
||||||
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.PoPInitiatorReward))
|
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.PoPInitiatorReward))
|
||||||
appendValue := util.SerializeUint64(amount)
|
appendValue := util.SerializeUint64(amount)
|
||||||
store.Set(util.SerializeInt64(height), appendValue)
|
store.Set(util.SerializeInt64(height), appendValue)
|
||||||
|
|||||||
@ -25,6 +25,7 @@ func createNChallenge(keeper *keeper.Keeper, ctx sdk.Context, n int, popEpochs i
|
|||||||
items[i].Success = false
|
items[i].Success = false
|
||||||
items[i].Finished = false
|
items[i].Finished = false
|
||||||
keeper.StoreChallenge(ctx, items[i])
|
keeper.StoreChallenge(ctx, items[i])
|
||||||
|
keeper.StoreChallangeInitiatorReward(ctx, blockHeight, types.DefaultParams().ValidatorPopReward)
|
||||||
}
|
}
|
||||||
return items
|
return items
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,6 +6,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
keepertest "github.com/planetmint/planetmint-go/testutil/keeper"
|
keepertest "github.com/planetmint/planetmint-go/testutil/keeper"
|
||||||
|
"github.com/planetmint/planetmint-go/util"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
@ -91,3 +92,40 @@ func TestTokenDistribution(t *testing.T) {
|
|||||||
assert.True(t, expSum-sum < 0.000001)
|
assert.True(t, expSum-sum < 0.000001)
|
||||||
assert.Equal(t, float64(reissuances), Amount1stBatch+Amount2ndBatch)
|
assert.Equal(t, float64(reissuances), Amount1stBatch+Amount2ndBatch)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestValidatorRewardReallocation(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
k, ctx := keepertest.DaoKeeper(t)
|
||||||
|
|
||||||
|
// create reissuances
|
||||||
|
_ = createNReissuances(k, ctx, 1000, types.DefaultParams().PopEpochs)
|
||||||
|
distribution, err := k.GetDistributionForReissuedTokens(ctx, 780)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
// create challenges
|
||||||
|
_ = createNChallenge(k, ctx, 250, types.DefaultParams().PopEpochs)
|
||||||
|
distributionWithPopReallocation, err := k.GetDistributionForReissuedTokens(ctx, 780)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
// compare
|
||||||
|
pops := 780 / types.DefaultParams().PopEpochs
|
||||||
|
distributionDaoAmount, err := util.RDDLTokenStringToFloat(distribution.DaoAmount)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
distributionPopAmount, err := util.RDDLTokenStringToFloat(distribution.PopAmount)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
distributionWithValidatorPopRewardDao, err := util.RDDLTokenStringToFloat(distributionWithPopReallocation.DaoAmount)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
distributionWithValidatorPopRewardPop, err := util.RDDLTokenStringToFloat(distributionWithPopReallocation.PopAmount)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
// Some of DaoAmount is transferred to PopAmount
|
||||||
|
assert.Greater(t, distributionDaoAmount, distributionWithValidatorPopRewardDao)
|
||||||
|
assert.Greater(t, distributionWithValidatorPopRewardPop, distributionPopAmount)
|
||||||
|
|
||||||
|
diffPopAmount := distributionWithValidatorPopRewardPop - distributionPopAmount
|
||||||
|
diffDaoAmount := distributionDaoAmount - distributionWithValidatorPopRewardDao
|
||||||
|
assert.Equal(t, diffPopAmount, diffDaoAmount)
|
||||||
|
assert.Equal(t, pops, int64(diffPopAmount))
|
||||||
|
assert.Equal(t, pops, int64(diffDaoAmount))
|
||||||
|
}
|
||||||
|
|||||||
@ -25,7 +25,7 @@ func (k msgServer) InitPop(goCtx context.Context, msg *types.MsgInitPop) (*types
|
|||||||
k.StoreChallenge(ctx, challenge)
|
k.StoreChallenge(ctx, challenge)
|
||||||
|
|
||||||
amount := k.GetValidatorPoPReward(ctx)
|
amount := k.GetValidatorPoPReward(ctx)
|
||||||
k.storeChallangeInitiatorReward(ctx, msg.GetHeight(), amount)
|
k.StoreChallangeInitiatorReward(ctx, msg.GetHeight(), amount)
|
||||||
|
|
||||||
validatorIdentity, err := util.GetValidatorCometBFTIdentity(ctx, k.RootDir)
|
validatorIdentity, err := util.GetValidatorCometBFTIdentity(ctx, k.RootDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user