2022-12-22 01:08:16 +00:00
|
|
|
package keeper_test
|
2022-09-23 16:38:22 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2023-04-05 23:21:59 +00:00
|
|
|
sdkmath "cosmossdk.io/math"
|
2022-09-23 16:38:22 +00:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2022-12-22 01:08:16 +00:00
|
|
|
"github.com/kava-labs/kava/x/incentive/keeper"
|
2022-09-23 16:38:22 +00:00
|
|
|
"github.com/kava-labs/kava/x/incentive/types"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestGetProportionalRewardPeriod(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
giveRewardPeriod types.MultiRewardPeriod
|
2023-04-05 23:21:59 +00:00
|
|
|
giveTotalBkavaSupply sdkmath.Int
|
|
|
|
giveSingleBkavaSupply sdkmath.Int
|
2022-09-23 16:38:22 +00:00
|
|
|
wantRewardsPerSecond sdk.DecCoins
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
"full amount",
|
|
|
|
types.NewMultiRewardPeriod(
|
|
|
|
true,
|
|
|
|
"",
|
|
|
|
time.Time{},
|
|
|
|
time.Time{},
|
|
|
|
cs(c("ukava", 100), c("hard", 200)),
|
|
|
|
),
|
|
|
|
i(100),
|
|
|
|
i(100),
|
|
|
|
toDcs(c("ukava", 100), c("hard", 200)),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"3/4 amount",
|
|
|
|
types.NewMultiRewardPeriod(
|
|
|
|
true,
|
|
|
|
"",
|
|
|
|
time.Time{},
|
|
|
|
time.Time{},
|
|
|
|
cs(c("ukava", 100), c("hard", 200)),
|
|
|
|
),
|
|
|
|
i(10_000000),
|
|
|
|
i(7_500000),
|
|
|
|
toDcs(c("ukava", 75), c("hard", 150)),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"half amount",
|
|
|
|
types.NewMultiRewardPeriod(
|
|
|
|
true,
|
|
|
|
"",
|
|
|
|
time.Time{},
|
|
|
|
time.Time{},
|
|
|
|
cs(c("ukava", 100), c("hard", 200)),
|
|
|
|
),
|
|
|
|
i(100),
|
|
|
|
i(50),
|
|
|
|
toDcs(c("ukava", 50), c("hard", 100)),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"under 1 unit",
|
|
|
|
types.NewMultiRewardPeriod(
|
|
|
|
true,
|
|
|
|
"",
|
|
|
|
time.Time{},
|
|
|
|
time.Time{},
|
|
|
|
cs(c("ukava", 100), c("hard", 200)),
|
|
|
|
),
|
|
|
|
i(1000), // total bkava
|
|
|
|
i(1), // bkava supply of this specific vault
|
|
|
|
dcs(dc("ukava", "0.1"), dc("hard", "0.2")), // rewards per second rounded to 0 if under 1ukava/1hard
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
2022-12-22 01:08:16 +00:00
|
|
|
rewardsPerSecond := keeper.GetProportionalRewardsPerSecond(
|
2022-09-23 16:38:22 +00:00
|
|
|
tt.giveRewardPeriod,
|
|
|
|
tt.giveTotalBkavaSupply,
|
|
|
|
tt.giveSingleBkavaSupply,
|
|
|
|
)
|
|
|
|
|
|
|
|
require.Equal(t, tt.wantRewardsPerSecond, rewardsPerSecond)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|