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

staking tests #754

Merged
merged 27 commits into from
Apr 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
4b0c367
keeper bugfixes, bit a pair programin w joon
mossid Mar 28, 2018
67a943d
write test for keeper
mossid Mar 29, 2018
77e7333
add test for inserting validator at the beginning/middle
mossid Mar 29, 2018
1c07919
remove some TODO tags
mossid Mar 29, 2018
daf5fb9
change use of global candidates
rigelrozanski Mar 30, 2018
0fa0491
remove some unnecessary setCandidates
mossid Mar 31, 2018
7565ba4
fix kicking validators logic
rigelrozanski Apr 2, 2018
a6d587b
fix remove candidate keeper logic
rigelrozanski Apr 2, 2018
d0db8b4
pool.go to be functions on pool
rigelrozanski Mar 28, 2018
55c5bf8
pool compiles
rigelrozanski Mar 29, 2018
5486d6a
compiling
rigelrozanski Mar 29, 2018
c1a8f2c
fix tick tests
rigelrozanski Mar 29, 2018
4b9bd0e
handler tests beginning
rigelrozanski Mar 29, 2018
3827b34
...
rigelrozanski Mar 30, 2018
48ae300
comment out handler_test.go
rigelrozanski Mar 30, 2018
dd0712c
move rounding into nextInflation
rigelrozanski Mar 30, 2018
765e065
Staking pool tests (closes #731)
cwgoes Mar 28, 2018
ff0fefa
Use require.Equal instead of assert.Equal, add diagnostic messages
cwgoes Mar 29, 2018
3023f30
Enable share removal test, additional diagnostics
cwgoes Mar 30, 2018
3441bc3
visual cleanup
rigelrozanski Mar 30, 2018
c017256
remove pool_test dep on other test declations
rigelrozanski Mar 30, 2018
34278f5
fix in candidateAddTokens
rigelrozanski Mar 30, 2018
6c2eda6
adrian pr comment
rigelrozanski Mar 30, 2018
bac8183
random test overhaul
rigelrozanski Mar 30, 2018
7d67d00
pool test correct in AssertInvariance
rigelrozanski Apr 2, 2018
47aaae8
Merge branch 'rigel/tick-tests' into joon/732-stake-keeper
rigelrozanski Apr 2, 2018
d880262
Merge pull request #745 from cosmos/joon/732-stake-keeper
rigelrozanski Apr 2, 2018
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
29 changes: 14 additions & 15 deletions x/stake/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,6 @@ func NewHandler(k Keeper, ck bank.CoinKeeper) sdk.Handler {

//_____________________________________________________________________

// XXX should be send in the msg (init in CLI)
//func getSender() sdk.Address {
//signers := msg.GetSigners()
//if len(signers) != 1 {
//return sdk.ErrUnauthorized("there can only be one signer for staking transaction").Result()
//}
//sender := signers[0]
//}

//_____________________________________________________________________

// These functions assume everything has been authenticated,
// now we just perform action and save

Expand Down Expand Up @@ -187,8 +176,11 @@ func BondCoins(ctx sdk.Context, k Keeper, bond DelegatorBond, candidate Candidat
if err != nil {
return err
}
newShares := k.candidateAddTokens(ctx, candidate, amount.Amount)
p := k.GetPool(ctx)
p, candidate, newShares := p.candidateAddTokens(candidate, amount.Amount)
bond.Shares = bond.Shares.Add(newShares)
k.setPool(ctx, p)
k.setCandidate(ctx, candidate)
k.setDelegatorBond(ctx, bond)
return nil
}
Expand Down Expand Up @@ -258,7 +250,9 @@ func handleMsgUnbond(ctx sdk.Context, msg MsgUnbond, k Keeper) sdk.Result {
}

// Add the coins
returnAmount := k.candidateRemoveShares(ctx, candidate, shares)
p := k.GetPool(ctx)
var returnAmount int64
p, candidate, returnAmount = p.candidateRemoveShares(candidate, shares)
returnCoins := sdk.Coins{{k.GetParams(ctx).BondDenom, returnAmount}}
k.coinKeeper.AddCoins(ctx, bond.DelegatorAddr, returnCoins)

Expand All @@ -267,7 +261,7 @@ func handleMsgUnbond(ctx sdk.Context, msg MsgUnbond, k Keeper) sdk.Result {

// change the share types to unbonded if they were not already
if candidate.Status == Bonded {
k.bondedToUnbondedPool(ctx, candidate)
p, candidate = p.bondedToUnbondedPool(candidate)
}

// lastly update the status
Expand All @@ -280,6 +274,7 @@ func handleMsgUnbond(ctx sdk.Context, msg MsgUnbond, k Keeper) sdk.Result {
} else {
k.setCandidate(ctx, candidate)
}
k.setPool(ctx, p)
return sdk.Result{}
}

Expand All @@ -293,12 +288,16 @@ func UnbondCoins(ctx sdk.Context, k Keeper, bond DelegatorBond, candidate Candid
}
bond.Shares = bond.Shares.Sub(shares)

returnAmount := k.candidateRemoveShares(ctx, candidate, shares)
p := k.GetPool(ctx)
var returnAmount int64
p, candidate, returnAmount = p.candidateRemoveShares(candidate, shares)
returnCoins := sdk.Coins{{k.GetParams(ctx).BondDenom, returnAmount}}

_, err := k.coinKeeper.AddCoins(ctx, candidate.Address, returnCoins)
if err != nil {
return err
}
k.setPool(ctx, p)
k.setCandidate(ctx, candidate)
return nil
}
Loading