Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Hotfix] treasury empty epoch data #445

Merged
merged 2 commits into from
Feb 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions x/treasury/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,43 @@ func TestUpdate(t *testing.T) {
newRewardWeight := input.TreasuryKeeper.GetRewardWeight(input.Ctx)
require.Equal(t, rewardWeight.Add(input.TreasuryKeeper.RewardPolicy(input.Ctx).ChangeRateMax), newRewardWeight)
}

func TestEmptyIndicator(t *testing.T) {
input := keeper.CreateTestInput(t)

windowProbation := input.TreasuryKeeper.WindowProbation(input.Ctx)

// Set total staked luna to prevent divide by zero error when computing TRL
bondedModuleAcc := input.SupplyKeeper.GetModuleAccount(input.Ctx, stakingtypes.BondedPoolName)
err := bondedModuleAcc.SetCoins(sdk.NewCoins(sdk.NewInt64Coin(core.MicroLunaDenom, 100000000000)))
require.NoError(t, err)
input.SupplyKeeper.SetModuleAccount(input.Ctx, bondedModuleAcc)

targetEpoch := windowProbation + 1
for epoch := int64(0); epoch < targetEpoch; epoch++ {
// skip last epoch end blocker
// to make indicators empty
if epoch == targetEpoch-1 {
continue
}

input.Ctx = input.Ctx.WithBlockHeight(core.BlocksPerWeek*epoch - 1)
EndBlocker(input.Ctx, input.TreasuryKeeper)
}

// Must result in the same output as normal zero tax & mining rewards
// load old tax rate & reward weight
taxRate := input.TreasuryKeeper.GetTaxRate(input.Ctx)
rewardWeight := input.TreasuryKeeper.GetRewardWeight(input.Ctx)

input.Ctx = input.Ctx.WithBlockHeight(core.BlocksPerWeek*targetEpoch - 1)
EndBlocker(input.Ctx, input.TreasuryKeeper)

// zero tax proceeds will increase tax rate with change max amount
newTaxRate := input.TreasuryKeeper.GetTaxRate(input.Ctx)
require.Equal(t, taxRate.Add(input.TreasuryKeeper.TaxPolicy(input.Ctx).ChangeRateMax), newTaxRate)

// zero mining rewards will increase reward weight with change max amount
newRewardWeight := input.TreasuryKeeper.GetRewardWeight(input.Ctx)
require.Equal(t, rewardWeight.Add(input.TreasuryKeeper.RewardPolicy(input.Ctx).ChangeRateMax), newRewardWeight)
}
2 changes: 1 addition & 1 deletion x/treasury/internal/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ func (k Keeper) GetTSL(ctx sdk.Context, epoch int64) (res sdk.Int) {
bz := store.Get(types.GetTSLKey(epoch))

if bz == nil {
res = sdk.ZeroInt()
res = sdk.OneInt()
} else {
k.cdc.MustUnmarshalBinaryLengthPrefixed(bz, &res)
}
Expand Down
2 changes: 1 addition & 1 deletion x/treasury/internal/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func TestIndicatorGetterSetter(t *testing.T) {
for e := int64(0); e < 10; e++ {
require.Equal(t, sdk.ZeroDec(), input.TreasuryKeeper.GetTR(input.Ctx, e))
require.Equal(t, sdk.ZeroDec(), input.TreasuryKeeper.GetSR(input.Ctx, e))
require.Equal(t, sdk.ZeroInt(), input.TreasuryKeeper.GetTSL(input.Ctx, e))
require.Equal(t, sdk.OneInt(), input.TreasuryKeeper.GetTSL(input.Ctx, e))
}
}

Expand Down