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

Joon/732 stake keeper #745

Merged
merged 9 commits into from
Apr 2, 2018
Merged

Conversation

mossid
Copy link
Contributor

@mossid mossid commented Mar 29, 2018

Closes: #732

@mossid mossid requested a review from rigelrozanski March 29, 2018 18:28
@mossid mossid requested a review from ebuchman as a code owner March 29, 2018 18:28
@codecov
Copy link

codecov bot commented Mar 29, 2018

Codecov Report

❗ No coverage uploaded for pull request base (rigel/tick-tests@7d67d00). Click here to learn what that means.
The diff coverage is 91.83%.

@@                 Coverage Diff                 @@
##             rigel/tick-tests     #745   +/-   ##
===================================================
  Coverage                    ?   60.52%           
===================================================
  Files                       ?       62           
  Lines                       ?     3298           
  Branches                    ?        0           
===================================================
  Hits                        ?     1996           
  Misses                      ?     1157           
  Partials                    ?      145

@@ -141,7 +152,7 @@ func (k Keeper) GetValidators(ctx sdk.Context) (validators []Validator) {

// add the actual validator power sorted store
maxVal := k.GetParams(ctx).MaxValidators
iterator := store.ReverseIterator(subspace(ValidatorsKey)) //smallest to largest
iterator := store.ReverseIterator(subspace(ValidatorsKey)) // largest to smallest
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:D

}
}

genValidators := func(candidates []Candidate) []Validator {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not use this at all the point of these tests was not to create the group of validators arbitrarily from the candidate list but to GET the validators from using the keeper functionality! this doesn't really provide us much value to just generate the validator set from this function

return validators
}

candidates := []Candidate{candidatesIn[1], candidatesIn[4]}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay so I added some function named candidatesIN but this is really confusing generating the candidate group this way - ideally we don't simple "compile" the list as we've done here but retrieve the list from the keeper using "keeper.GetCandidates"

// test validator added at the beginning
// test validator added in the middle
candidates = append([]Candidate{candidatesIn[0]}, candidates...)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per my previous comment we should not be adding to a list, but retrieving from the state

keeper.setCandidate(ctx, candidates[3])
keeper.setCandidate(ctx, candidates[4])
acc = keeper.getAccUpdateValidators(ctx)
validatorsEqual(t, validators, acc)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I broke this test >:) - lol but yeah again we need to reconfigure what we are even testing here!

Copy link
Contributor

@rigelrozanski rigelrozanski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a few comments... TestGetAccUpdateValidators isn't really actually testing what I had intended each of those comments to test... like we should not be compiling our own lists we should be retrieving lists... like "add a validator to the middle" in this sense means set a candidate to the state using the keeper which is somewhere in the middle for voting power compared to the others!

-> also we need to really check these 4 core cases as I described in person, I don't think we've explicitly and clearly done this

  1. new validator moves into the validator set, it is accumulated as so
  2. existing validator already in the validator set changes its voting power
  3. existing validator moves out of the validator set (aka acc will be {0, addr}
  4. a candidate which was never in the validator set changes its power but remains still not in the validator set (should not enter the acc changes)

@mossid
Copy link
Contributor Author

mossid commented Mar 30, 2018

Shouldn't the insertion tests be placed in TestGetValidators? Adding candidates that have medium voting power doesn't need to be in TestGetAccUpdateValidators since it has more relationship with Validators store and AccUpdateValidators depends only on the candidates' address. @rigelrozanski

Also, I think the case 1, 2, 3 is implemented? Currently working on 4 (and removing genValidators)

@rigelrozanski
Copy link
Contributor

yes 1/2/3 may very well be implemented maybe we just need better organization/comments

@rigelrozanski
Copy link
Contributor

Let's squash commits before merge which don't particularly useful information such as like "in progress" and "done"

@rigelrozanski rigelrozanski force-pushed the joon/732-stake-keeper branch from 7815fdf to a6d587b Compare April 2, 2018 22:16
@rigelrozanski rigelrozanski changed the base branch from develop to rigel/tick-tests April 2, 2018 22:17
@rigelrozanski rigelrozanski merged commit d880262 into rigel/tick-tests Apr 2, 2018
@rigelrozanski rigelrozanski deleted the joon/732-stake-keeper branch April 2, 2018 22:22
@rigelrozanski
Copy link
Contributor

Great work Joon! I reorganized the tests a bit made a few fixes to functionality which your tests revealed as I was reworking them a bit.... check out the two final commits I added on

(also I squashed a few of your commits)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants