Skip to content

Commit

Permalink
harvest-fix: check for status other than bonded, add staking tests (#677
Browse files Browse the repository at this point in the history
)

* fix: check for any status other than bonded

* Add harvest staking tests (#680)

* refactor config initialization

* refactor delegator rewards test, add tests

* fix share to token calculation, add unbonding test

* remove dead link

Co-authored-by: Ruaridh <[email protected]>
  • Loading branch information
karzak and rhuairahrighairidh authored Oct 5, 2020
1 parent e0771cc commit 69512d5
Show file tree
Hide file tree
Showing 7 changed files with 375 additions and 106 deletions.
1 change: 0 additions & 1 deletion docs/communitytools.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ Listed in alphabetical order.
- [OKEx Pool](https://www.okex.com/pool)
- [P2P](https://p2p.org/)
- [SNZ Pool](https://snzholding.com/pool.html)
- [Sikka](https://www.sikka.tech/)
- [StakeWith.Us](https://www.stakewith.us/)
- [Staked](https://staked.us/)
- [stake.fish](https://stake.fish/en/)
3 changes: 1 addition & 2 deletions x/harvest/keeper/claim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,7 @@ func (suite *KeeperTestSuite) TestClaim() {
for _, tc := range testCases {
suite.Run(tc.name, func() {
// create new app with one funded account
config := sdk.GetConfig()
app.SetBech32AddressPrefixes(config)

// Initialize test app and set context
tApp := app.NewTestApp()
ctx := tApp.NewContext(true, abci.Header{Height: 1, Time: tc.args.blockTime})
Expand Down
6 changes: 2 additions & 4 deletions x/harvest/keeper/deposit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,7 @@ func (suite *KeeperTestSuite) TestDeposit() {
for _, tc := range testCases {
suite.Run(tc.name, func() {
// create new app with one funded account
config := sdk.GetConfig()
app.SetBech32AddressPrefixes(config)

// Initialize test app and set context
tApp := app.NewTestApp()
ctx := tApp.NewContext(true, abci.Header{Height: 1, Time: tmtime.Now()})
Expand Down Expand Up @@ -279,8 +278,7 @@ func (suite *KeeperTestSuite) TestWithdraw() {
for _, tc := range testCases {
suite.Run(tc.name, func() {
// create new app with one funded account
config := sdk.GetConfig()
app.SetBech32AddressPrefixes(config)

// Initialize test app and set context
tApp := app.NewTestApp()
ctx := tApp.NewContext(true, abci.Header{Height: 1, Time: tmtime.Now()})
Expand Down
3 changes: 3 additions & 0 deletions x/harvest/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ type KeeperTestSuite struct {

// The default state used by each test
func (suite *KeeperTestSuite) SetupTest() {
config := sdk.GetConfig()
app.SetBech32AddressPrefixes(config)

tApp := app.NewTestApp()
ctx := tApp.NewContext(true, abci.Header{Height: 1, Time: tmtime.Now()})
tApp.InitializeFromGenesisStates()
Expand Down
6 changes: 3 additions & 3 deletions x/harvest/keeper/rewards.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,11 @@ func (k Keeper) ApplyDelegationRewards(ctx sdk.Context, denom string) {
if validator.GetTokens().IsZero() {
return false
}
// don't include a validator if it's unbonded - ie delegators don't accumulate rewards when delegated to an unbonded validator
if validator.GetStatus() == sdk.Unbonded {
// don't include a validator if it's unbonded or unbonding- ie delegators don't accumulate rewards when delegated to an unbonded/slashed validator
if validator.GetStatus() != sdk.Bonded {
return false
}
sharesToTokens[validator.GetOperator().String()] = (validator.GetDelegatorShares()).Quo(sdk.NewDecFromInt(validator.GetTokens()))
sharesToTokens[validator.GetOperator().String()] = sdk.NewDecFromInt(validator.GetTokens()).Quo(validator.GetDelegatorShares())
return false
})

Expand Down
Loading

0 comments on commit 69512d5

Please sign in to comment.