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

bug(test): sometimes tests fail with StringKey error. #1084

Closed
AgentSmithMatrix opened this issue Nov 25, 2022 · 1 comment · Fixed by NibiruChain/collections#10
Closed

Comments

@AgentSmithMatrix
Copy link
Contributor

Probably due to some Fuzzy test that touches some collections

@Unique-Divine
Copy link
Member

Unique-Divine commented Jan 5, 2023

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)
  })
})

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

Successfully merging a pull request may close this issue.

2 participants