diff --git a/x/pairing/keeper/delegator_rewards_test.go b/x/pairing/keeper/delegator_rewards_test.go index 25cc71cf2d..34bdfb3efb 100644 --- a/x/pairing/keeper/delegator_rewards_test.go +++ b/x/pairing/keeper/delegator_rewards_test.go @@ -14,6 +14,10 @@ import ( "github.com/stretchr/testify/require" ) +const ( + exactConst = "exact" +) + // TestProviderDelegatorsRewards tests that the provider's reward (considering delegations) is as expected // Also, it checks that the delegator reward map is updated as expected func TestProviderDelegatorsRewards(t *testing.T) { @@ -184,7 +188,7 @@ func TestPartialMonthDelegation(t *testing.T) { _, err := ts.TxSubscriptionBuy(client, client, "free", 1, false, false) // extend by a month so the sub won't expire require.NoError(t, err) - ts.AdvanceTimeHours(time.Hour * 24 * 15) // 15 days passed form the subs timer + ts.AdvanceTimeHours(time.Hour*24*15 + time.Hour*41) // results in 15 days of the provider being active (41 hours until subscription triggers payout) // add another provider after 15 days err = ts.addProvider(1) @@ -196,7 +200,7 @@ func TestPartialMonthDelegation(t *testing.T) { metadata.DelegateCommission = 50 // 50% commission ts.Keepers.Epochstorage.SetMetadata(ts.Ctx, metadata) - ts.AdvanceTimeHours(time.Hour * 24 * 15) // 5 days passed from the provider stake, total 20 days + ts.AdvanceTimeHours(time.Hour * 24 * 5) // 5 days passed from the provider stake, total 20 days stakeEntryResp, err := ts.Keepers.Pairing.Provider(ts.Ctx, &types.QueryProviderRequest{ Address: provider, @@ -215,6 +219,7 @@ func TestPartialMonthDelegation(t *testing.T) { require.Equal(t, stakeEntry.DelegateCommission, metadata.DelegateCommission) relayPaymentMessage := sendRelay(ts, provider, clientAcc, []string{ts.spec.Index}) + relayPaymentMessage.DescriptionString = exactConst // we have a provider that staked after 15/30 days, and a delegator that staked after 20/30 days // provider has 100k stake for 15 days, delegator has 150k stake for 10 days so they should divide half half, and the provider commission is 50% ts.payAndVerifyBalance(relayPaymentMessage, clientAcc.Addr, providerAcc.Vault.Addr, true, true, 75) diff --git a/x/pairing/keeper/helpers_test.go b/x/pairing/keeper/helpers_test.go index 8485d5f2ae..c95d600625 100644 --- a/x/pairing/keeper/helpers_test.go +++ b/x/pairing/keeper/helpers_test.go @@ -231,15 +231,24 @@ func (ts *tester) payAndVerifyBalance( require.NotNil(ts.T, sub.Sub) require.Equal(ts.T, originalSubCuLeft-totalCuUsed, sub.Sub.MonthCuLeft) timeToExpiry := time.Unix(int64(sub.Sub.MonthExpiryTime), 0) - if timeToExpiry.After(ts.Ctx.BlockTime()) { + durLeft := sub.Sub.DurationLeft + if timeToExpiry.After(ts.Ctx.BlockTime()) && relayPayment.DescriptionString == exactConst { ts.AdvanceTimeHours(timeToExpiry.Sub(ts.Ctx.BlockTime())) + // subs only pays after blocks to save + ts.AdvanceEpoch() + ts.AdvanceBlocks(ts.BlocksToSave() + 1) } else { // advance month + blocksToSave + 1 to trigger the provider monthly payment ts.AdvanceMonths(1) ts.AdvanceEpoch() ts.AdvanceBlocks(ts.BlocksToSave() + 1) } - + if durLeft > 0 { + sub, err = ts.QuerySubscriptionCurrent(proj.Project.Subscription) + require.Nil(ts.T, err) + require.NotNil(ts.T, sub.Sub) + require.Equal(ts.T, durLeft-1, sub.Sub.DurationLeft, "month expiry time: %s current time: %s", time.Unix(int64(sub.Sub.MonthExpiryTime), 0).UTC(), ts.BlockTime().UTC()) + } // verify provider's balance credit := sub.Sub.Credit.Amount.QuoRaw(int64(sub.Sub.DurationLeft)) want := sdk.ZeroInt()