-
Notifications
You must be signed in to change notification settings - Fork 4k
Staking pool tests #744
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 pool tests #744
Conversation
Random integration tests are currently failing; somehow @rigelrozanski Anything unusual here - https://github.com/cosmos/cosmos-sdk/blob/cwgoes/staking-pool-tests/x/stake/pool_test.go#L221 ? Tests pass when the |
nice! hot tip: whenever there are a whole whack ton of error messages - it's better practice to use |
Tests now display helpful messages about what operation caused the error |
174b50a
to
cb8f666
Compare
cb8f666
to
8699394
Compare
x/stake/pool_test.go
Outdated
for _, candidate := range cA { | ||
|
||
// nonnegative ex rate | ||
require.Equal(t, false, candidate.delegatorShareExRate().LT(sdk.ZeroRat), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
require.False
x/stake/pool_test.go
Outdated
|
||
// run random operations in a random order on a random state, assert invariants hold | ||
func TestIntegrationInvariants(t *testing.T) { | ||
r := rand.New(rand.NewSource(int64(42))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is generating one deterministic number each time and reusing it everywhere... what you want is two instances of rand within each loop: rand.New(rand.NewSource(time.Now().UnixNano()))
.... making this fix now
Codecov Report
@@ Coverage Diff @@
## rigel/tick-tests #744 +/- ##
====================================================
+ Coverage 61.01% 61.93% +0.92%
====================================================
Files 62 62
Lines 3255 3255
====================================================
+ Hits 1986 2016 +30
+ Misses 1128 1098 -30
Partials 141 141 |
@cwgoes fyi - just overhauled the negative operations test... passing now, had nothing to do with rational overflows - there were a series of logical errors in the way which the random tests were constructed - I ended up pairing it down to a single candidate scenario to remove a lot of the obfuscation. We should continue to make these random tests more clear - I think there is a better way of constructing the "random operation" among other structure which will make these tests more maintainable. - if you want to get on that as an additional PR to refactor these tests further that would be useful. Although I really like the idea behind fuzz testing/ random testing as we've here we need to put extra work into code clarity |
Main changes which were implemented in my commits here:
|
I don't think it was reusing the same random number, e.g. package main
import (
"fmt"
"math/rand"
)
func main() {
r := rand.New(rand.NewSource(42))
for i := 0; i < 10; i++ {
fmt.Printf("Random number: %d\n", r.Int31n(1000))
}
} go run test.go Random number: 305
Random number: 987
Random number: 668
Random number: 750
Random number: 423
Random number: 345
Random number: 357
Random number: 176
Random number: 128
Random number: 643 Each time the |
thanks.. I stand corrected! |
* Problem: tx executor can't do dependency analysis Solution: - change the api to allow static analysis on tx body * fix * changelog * cleanup * Update CHANGELOG.md Signed-off-by: yihuang <[email protected]> --------- Signed-off-by: yihuang <[email protected]>
* Problem: tx executor can't do dependency analysis Solution: - change the api to allow static analysis on tx body * fix * changelog * cleanup * Update CHANGELOG.md Signed-off-by: yihuang <[email protected]> --------- Signed-off-by: yihuang <[email protected]>
* Problem: tx executor can't do dependency analysis Solution: - change the api to allow static analysis on tx body * fix * changelog * cleanup * Update CHANGELOG.md Signed-off-by: yihuang <[email protected]> --------- Signed-off-by: yihuang <[email protected]>
* Problem: tx executor can't do dependency analysis Solution: - change the api to allow static analysis on tx body * fix * changelog * cleanup * Update CHANGELOG.md Signed-off-by: yihuang <[email protected]> --------- Signed-off-by: yihuang <[email protected]>
* Problem: tx executor can't do dependency analysis Solution: - change the api to allow static analysis on tx body * fix * changelog * cleanup * Update CHANGELOG.md Signed-off-by: yihuang <[email protected]> --------- Signed-off-by: yihuang <[email protected]>
* Problem: tx executor can't do dependency analysis Solution: - change the api to allow static analysis on tx body * fix * changelog * cleanup * Update CHANGELOG.md Signed-off-by: yihuang <[email protected]> --------- Signed-off-by: yihuang <[email protected]>
* Problem: tx executor can't do dependency analysis Solution: - change the api to allow static analysis on tx body * fix * changelog * cleanup * Update CHANGELOG.md Signed-off-by: yihuang <[email protected]> --------- Signed-off-by: yihuang <[email protected]>
* Problem: tx executor can't do dependency analysis Solution: - change the api to allow static analysis on tx body * fix * changelog * cleanup * Update CHANGELOG.md Signed-off-by: yihuang <[email protected]> --------- Signed-off-by: yihuang <[email protected]>
* Problem: tx executor can't do dependency analysis Solution: - change the api to allow static analysis on tx body * fix * changelog * cleanup * Update CHANGELOG.md Signed-off-by: yihuang <[email protected]> --------- Signed-off-by: yihuang <[email protected]>
* Problem: tx executor can't do dependency analysis Solution: - change the api to allow static analysis on tx body * fix * changelog * cleanup * Update CHANGELOG.md Signed-off-by: yihuang <[email protected]> --------- Signed-off-by: yihuang <[email protected]>
* Problem: tx executor can't do dependency analysis Solution: - change the api to allow static analysis on tx body * fix * changelog * cleanup * Update CHANGELOG.md Signed-off-by: yihuang <[email protected]> --------- Signed-off-by: yihuang <[email protected]>
Includes basic tests and integration tests with random state / random operations.
Ref #731