-
Notifications
You must be signed in to change notification settings - Fork 193
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
bug(test): sometimes tests fail with StringKey error. #1084
Comments
There are now tests coverage in vote_target_test.go for this bug and a correction to what was causing problems in tally_fuzzy_test.go. The panic comes from setting a store key to have an empty string and then trying to iterate over that store. Setting the key as "" is fine, but iterating causes a panic. This should probably be changed to return an error in collections instead. Here's the snippet that verifies the fix: type TestCase struct {
name string
in []string
panic bool
}
panicCases:= []TestCase{
{ name: "blank pair", in: []string{ "" }, panic: true },
{ name: "blank pair and others", in: []string{ "", "x", "abc", "defafask" }, panic: true },
}
happyCases:= []TestCase{
{ name: "happy", in: []string{ "bar", "foo", "whoowhoo" } },
{ name: "short len 1 pair", in: []string{ "x" } },
{ name: "short len 2 pair", in: []string{ "xx" } },
}
for _, testCase := range append(panicCases, happyCases...) {
tc:= testCase
t.Run(tc.name, func(t * testing.T) {
input:= CreateTestInput(t)
for _, p:= range input.OracleKeeper.Pairs.Iterate(input.Ctx, collections.Range[string]{}).Keys() {
input.OracleKeeper.Pairs.Delete(input.Ctx, p)
}
expectedTargets := tc.in
for _, target := range expectedTargets {
input.OracleKeeper.Pairs.Insert(input.Ctx, target)
}
var panicAssertFn func(t assert.TestingT, f assert.PanicTestFunc, msgAndArgs ...interface{ }) bool
switch tc.panic {
case true:
panicAssertFn = assert.Panics
default:
panicAssertFn = assert.NotPanics
}
panicAssertFn(t, func() {
targets:= input.OracleKeeper.GetWhitelistedPairs(input.Ctx)
assert.Equal(t, expectedTargets, targets)
})
}) |
Probably due to some Fuzzy test that touches some collections
The text was updated successfully, but these errors were encountered: