-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add global keys prefix for the current epoch days * test: add test for key store prefixes * chore: fix broken store prefix test, rename EpochDays to NextEpochDays * test: add more tests and update address to have 20 bytes * test: remove comments * test: update epoch days to next epoch days * test: add handler tests * refactor: add comment for global current epoch days * test: apply module testing suit * test: remove tests for deprecated PlansByFarmerIndex * feat: move mustParseRFC3339 function to utils #109 * docs: update spec docs * feat: adding test for end blocker * chore: rename GlobalCurrentEpochDays to CurrentEpochDays and refactor codes * test: improve code coverage * chore: apply code review feedbacks and suggestions * feat: add gRPC query and cli for current epoch days * fix: apply code review feedbacks and suggestions * fix: resolve conflicts * fix: panic when unstake due to total stakings is not set
- Loading branch information
Showing
44 changed files
with
1,747 additions
and
1,791 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package farming_test | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/tendermint/farming/x/farming" | ||
"github.com/tendermint/farming/x/farming/types" | ||
|
||
_ "github.com/stretchr/testify/suite" | ||
) | ||
|
||
func (suite *ModuleTestSuite) TestEndBlockerEpochDaysTest() { | ||
epochDaysTest := func(formerEpochDays, targetNextEpochDays uint32) { | ||
suite.SetupTest() | ||
|
||
params := suite.keeper.GetParams(suite.ctx) | ||
params.NextEpochDays = formerEpochDays | ||
suite.keeper.SetParams(suite.ctx, params) | ||
suite.keeper.SetCurrentEpochDays(suite.ctx, formerEpochDays) | ||
|
||
t := types.ParseTime("2021-08-01T00:00:00Z") | ||
suite.ctx = suite.ctx.WithBlockTime(t) | ||
farming.EndBlocker(suite.ctx, suite.keeper) | ||
|
||
lastEpochTime, _ := suite.keeper.GetLastEpochTime(suite.ctx) | ||
|
||
for i := 1; i < 200; i++ { | ||
t = t.Add(1 * time.Hour) | ||
suite.ctx = suite.ctx.WithBlockTime(t) | ||
farming.EndBlocker(suite.ctx, suite.keeper) | ||
|
||
if i == 10 { // 10 hours passed | ||
params := suite.keeper.GetParams(suite.ctx) | ||
params.NextEpochDays = targetNextEpochDays | ||
suite.keeper.SetParams(suite.ctx, params) | ||
} | ||
|
||
currentEpochDays := suite.keeper.GetCurrentEpochDays(suite.ctx) | ||
t2, _ := suite.keeper.GetLastEpochTime(suite.ctx) | ||
|
||
if uint32(i) == formerEpochDays*24 { | ||
suite.Require().True(t2.After(lastEpochTime)) | ||
suite.Require().Equal(t2.Sub(lastEpochTime).Hours(), float64(formerEpochDays*24)) | ||
suite.Require().Equal(targetNextEpochDays, currentEpochDays) | ||
} | ||
|
||
if uint32(i) == formerEpochDays*24+targetNextEpochDays*24 { | ||
suite.Require().Equal(t2.Sub(lastEpochTime).Hours(), float64(currentEpochDays*24)) | ||
suite.Require().Equal(targetNextEpochDays, currentEpochDays) | ||
} | ||
|
||
lastEpochTime = t2 | ||
} | ||
} | ||
|
||
// increasing case | ||
epochDaysTest(1, 7) | ||
|
||
// decreasing case | ||
epochDaysTest(7, 1) | ||
|
||
// stay case | ||
epochDaysTest(1, 1) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.