forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: store key uniqueness (cosmos#9363)
* fix: store key uniqueness * gosimple: use copy instead of for loop * Update types/store.go Co-authored-by: Tyler <[email protected]> * fix import Co-authored-by: Tyler <[email protected]>
- Loading branch information
1 parent
b1201f8
commit 8161b3a
Showing
3 changed files
with
90 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package types | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/suite" | ||
) | ||
|
||
type storeIntSuite struct { | ||
suite.Suite | ||
} | ||
|
||
func TestStoreIntSuite(t *testing.T) { | ||
suite.Run(t, new(storeIntSuite)) | ||
} | ||
|
||
func (s *storeIntSuite) TestAssertNoPrefix() { | ||
var testCases = []struct { | ||
keys []string | ||
expectPanic bool | ||
}{ | ||
{[]string{""}, false}, | ||
{[]string{"a"}, false}, | ||
{[]string{"a", "b"}, false}, | ||
{[]string{"a", "b1"}, false}, | ||
{[]string{"b2", "b1"}, false}, | ||
{[]string{"b1", "bb", "b2"}, false}, | ||
|
||
{[]string{"a", ""}, true}, | ||
{[]string{"a", "b", "a"}, true}, | ||
{[]string{"a", "b", "aa"}, true}, | ||
{[]string{"a", "b", "ab"}, true}, | ||
{[]string{"a", "b1", "bb", "b12"}, true}, | ||
} | ||
|
||
require := s.Require() | ||
for _, tc := range testCases { | ||
if tc.expectPanic { | ||
require.Panics(func() { assertNoPrefix(tc.keys) }) | ||
} else { | ||
assertNoPrefix(tc.keys) | ||
} | ||
} | ||
} | ||
|
||
func (s *storeIntSuite) TestNewKVStoreKeys() { | ||
require := s.Require() | ||
require.Panics(func() { NewKVStoreKeys("a1", "a") }, "should fail one key is a prefix of another one") | ||
|
||
require.Equal(map[string]*KVStoreKey{}, NewKVStoreKeys()) | ||
require.Equal(1, len(NewKVStoreKeys("one"))) | ||
|
||
key := "baca" | ||
stores := NewKVStoreKeys(key, "a") | ||
require.Len(stores, 2) | ||
require.Equal(key, stores[key].Name()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters