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

test: more incentive test flows #2124

Closed
wants to merge 30 commits into from
Closed
Changes from 3 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
994d52d
scenario test: no bonded users at program end
toteki Jun 30, 2023
85fbc77
Merge branch 'main' into adam/test
toteki Jun 30, 2023
101eba9
additional scenario tests
toteki Jun 30, 2023
166ba4b
add test flow 3
Jul 6, 2023
ce9773e
add TestPartialWithdraw and TestUserSupplyBeforeAndDuring test scenarios
Jul 6, 2023
e893041
Merge branch 'main' into adam/test
toteki Jul 6, 2023
190161a
suggestion for TestZeroBondedAtProgramEnd
toteki Jul 6, 2023
70bcd4b
Update x/incentive/keeper/scenario_test.go
toteki Jul 6, 2023
a6a5204
spacing
toteki Jul 6, 2023
1810126
suggestions implemented for TestZeroBonded
toteki Jul 6, 2023
9d18203
adjust whitespace and shorted sdk.Coins vars
toteki Jul 7, 2023
18e9a5d
godoc all test scenarios
toteki Jul 7, 2023
0178c9e
Merge branch 'main' into adam/test
toteki Jul 7, 2023
98500d0
Update util/coin/fixtures.go
toteki Jul 7, 2023
fe35840
comment++
toteki Jul 7, 2023
1bc86a0
Update x/incentive/keeper/scenario_test.go
toteki Jul 7, 2023
65efef3
final scenario
toteki Jul 7, 2023
6b8394c
readme++
toteki Jul 7, 2023
afc5b5d
Merge branch 'main' into adam/test
toteki Jul 7, 2023
234c0d7
Merge branch 'main' into adam/test
toteki Jul 11, 2023
5c70b20
zeroCoins
toteki Jul 11, 2023
0c0cf21
readme
toteki Jul 11, 2023
85c5406
suggestions lines 283-344 and test fix
toteki Jul 11, 2023
091e060
defaultSetup
toteki Jul 11, 2023
b571459
move function
toteki Jul 11, 2023
647b38a
comment++
toteki Jul 11, 2023
92a1c57
Update x/incentive/keeper/scenario_test.go
toteki Jul 11, 2023
a8b175b
fix
toteki Jul 11, 2023
d1dddf5
check bob rewards
toteki Jul 11, 2023
866ad31
calculations
toteki Jul 11, 2023
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
123 changes: 120 additions & 3 deletions x/incentive/keeper/scenario_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,23 +216,140 @@ func TestZeroBonded(t *testing.T) {
)

// In this test case, an incentive program is started but no uTokens of the incentivized denom are
// bonded during its first half of runtime. during this time, it must not distribute rewards.
// bonded during its first half of runtime. During this time, it must not distribute rewards.
// During the remaining half of the program, all rewards must be distributed (spread evenly over
// the remaining time.)
robert-zaremba marked this conversation as resolved.
Show resolved Hide resolved

programStart := int64(100)
k.addIncentiveProgram(uUmee, programStart, 100, sdk.NewInt64Coin(umee, 10_000000), true)
k.advanceTimeTo(programStart) // starts program, but does not attempt rewards. Do not combine with next line.
k.advanceTimeTo(programStart + 50)
require.Equal(t, incentive.ProgramStatusOngoing, k.programStatus(1), "program 1 status (time 150)")
program := k.getProgram(1)
require.Equal(t, incentive.ProgramStatusOngoing, k.programStatus(1), "program 1 status (time 150)")
require.Equal(t, program.TotalRewards, program.RemainingRewards, "all of program's rewards remain (no bonds)")

// now create a supplier with bonded tokens, halfway through the program
k.newBondedAccount(
alice := k.newBondedAccount(
coin.New(uUmee, 100_000000),
)
k.advanceTimeTo(programStart + 75)
program = k.getProgram(1)
require.Equal(t, incentive.ProgramStatusOngoing, k.programStatus(1), "program 1 status (time 175)")
require.Equal(t, sdk.NewInt(5_000000), program.RemainingRewards.Amount, "half of program rewards distributed")

// finish the program with user still bonded
k.advanceTimeTo(programStart + 100)
program = k.getProgram(1)
require.Equal(t, incentive.ProgramStatusCompleted, k.programStatus(1), "program 1 status (time 200)")
require.Equal(t, sdk.ZeroInt(), program.RemainingRewards.Amount, "all of program rewards distributed")

// measure pending rewards (even though program has ended, user has not yet claimed)
rewards, err := k.calculateRewards(k.ctx, alice)
require.NoError(t, err)
require.Equal(
t,
sdk.NewCoins(sdk.NewInt64Coin(umee, 10_000000)),
rewards,
"alice pending rewards at time 200",
)

// advance time further past program end
k.advanceTimeTo(programStart + 120)

// measure pending rewards (unchanged, as user has not yet claimed)
rewards, err = k.calculateRewards(k.ctx, alice)
require.NoError(t, err)
require.Equal(
t,
sdk.NewCoins(sdk.NewInt64Coin(umee, 10_000000)),
rewards,
"alice pending rewards at time 220",
)
toteki marked this conversation as resolved.
Show resolved Hide resolved
// actually claim the rewards (same amount)
rewards, err = k.UpdateAccount(k.ctx, alice)
require.NoError(k.t, err)
require.Equal(
k.t,
sdk.NewCoins(sdk.NewInt64Coin(umee, 10_000000)),
rewards,
"alice claimed rewards at time 220",
)
toteki marked this conversation as resolved.
Show resolved Hide resolved
}
toteki marked this conversation as resolved.
Show resolved Hide resolved

func TestZeroBondedAtProgramEnd(t *testing.T) {
t.Parallel()
k := newTestKeeper(t)
k.initCommunityFund(
coin.New(umee, 1000_000000),
)

// In this test case, an incentive program is started but no uTokens of the incentivized denom are
// bonded during its first quarter or last quarter of runtime. During this time, it must not distribute rewards.
toteki marked this conversation as resolved.
Show resolved Hide resolved
// During the remaining half of the program, 2/3 rewards must be distributed (spread evenly over
// the remaining time.) It is 2/3 instead of 3/4 because upon reaching 25% duration with no bonds, the
// program can adapt to award 1/3 rewards every remaining 25% duration. However, once all users unbond
// after 75% duration and never return, the program is left with some rewards it cannot distribute.

programStart := int64(100)
k.addIncentiveProgram(uUmee, programStart, 100, sdk.NewInt64Coin(umee, 10_000000), true)
k.advanceTimeTo(programStart) // starts program, but does not attempt rewards. Do not combine with next line.
k.advanceTimeTo(programStart + 25) // 25% duration
program := k.getProgram(1)
require.Equal(t, incentive.ProgramStatusOngoing, k.programStatus(1), "program 1 status ongoing (time 125)")
require.Equal(t, program.TotalRewards, program.RemainingRewards, "all of program's rewards remain (no bonds)")

// now create a supplier with bonded tokens, halfway through the program
alice := k.newBondedAccount(
coin.New(uUmee, 100_000000),
)
toteki marked this conversation as resolved.
Show resolved Hide resolved
k.advanceTimeTo(programStart + 75) // 75% duration
program = k.getProgram(1)
require.Equal(t, incentive.ProgramStatusOngoing, k.programStatus(1), "program 1 status ongoing (time 175)")
require.Equal(t, sdk.NewInt(3_333334), program.RemainingRewards.Amount, "two thirds of program rewards distributed")

// measure pending rewards
rewards, err := k.calculateRewards(k.ctx, alice)
require.NoError(t, err)
require.Equal(
t,
sdk.NewCoins(sdk.NewInt64Coin(umee, 6_666666)),
rewards,
"alice pending rewards at time 175",
)
toteki marked this conversation as resolved.
Show resolved Hide resolved
// actually claim the rewards (same amount)
rewards, err = k.UpdateAccount(k.ctx, alice)
require.NoError(k.t, err)
require.Equal(
k.t,
sdk.NewCoins(sdk.NewInt64Coin(umee, 6_666666)),
rewards,
"alice claimed rewards at time 175",
)
// begin unbonding user at 75%, making her ineligible future rewards unless she bonds again
k.mustBeginUnbond(alice, coin.New(uUmee, 100_000000))
toteki marked this conversation as resolved.
Show resolved Hide resolved

// complete the program
k.advanceTimeTo(programStart + 100) // 100% duration
toteki marked this conversation as resolved.
Show resolved Hide resolved
program = k.getProgram(1)
require.Equal(t, incentive.ProgramStatusCompleted, k.programStatus(1), "program 1 status completed (time 200)")
require.Equal(t, sdk.NewInt(3_333334), program.RemainingRewards.Amount, "two thirds of program rewards distributed")

// measure pending rewards (zero)
rewards, err = k.calculateRewards(k.ctx, alice)
require.NoError(t, err)
require.Equal(
t,
sdk.NewCoins(),
rewards,
"alice pending rewards at time 200",
)
// actually claim the rewards (same amount)
rewards, err = k.UpdateAccount(k.ctx, alice)
require.NoError(k.t, err)
require.Equal(
k.t,
sdk.NewCoins(),
toteki marked this conversation as resolved.
Show resolved Hide resolved
rewards,
"alice claimed rewards at time 200",
)
}