0g-chain/x/incentive/keeper/rewards_earn_proportional_test.go
Ruaridh 4b8e224f6a
Revert incentive refactor commits (#1433)
* Revert "Add incentive migrations for earn rewards (#1406)"

This reverts commit 937e5f339f.

* Revert "Use different accumulator for earn (#1395)"

This reverts commit cf009647e6.

* Revert "Add base earn incentive accumulator (#1393)"

This reverts commit 44a90a8ef9.

* Revert "Add generic incentive `AccumulateRewards` method (#1392)"

This reverts commit dce631d3de.

* Revert "Add GetSynchronizedClaim and swap adapter (#1386)"

This reverts commit f52a581ea9.

* Revert "Add Initialize/Synchronize Claim methods (#1383)"

This reverts commit c2061f626e.

* Revert "Add source adapter interface definition (#1377)"

This reverts commit 2abb2ce606.

* Revert "Add incentive RewardIndexes types and state methods (#1381)"

This reverts commit 4a3002b09c.

* Revert "Add AccrualTime type and state methods (#1379)"

This reverts commit df1c2ffc34.

* Revert "Add incentive claim state methods (#1375)"

This reverts commit 90735e29ed.

* Revert "Add generic Claim type (#1371)"

This reverts commit 45fc1a7643.

* Regerate protos and minor revert fixes
2022-12-22 01:08:16 +00:00

87 lines
1.8 KiB
Go

package keeper_test
import (
"testing"
"time"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/kava-labs/kava/x/incentive/keeper"
"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
giveTotalBkavaSupply sdk.Int
giveSingleBkavaSupply sdk.Int
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) {
rewardsPerSecond := keeper.GetProportionalRewardsPerSecond(
tt.giveRewardPeriod,
tt.giveTotalBkavaSupply,
tt.giveSingleBkavaSupply,
)
require.Equal(t, tt.wantRewardsPerSecond, rewardsPerSecond)
})
}
}