github.com/Finschia/finschia-sdk@v0.48.1/types/store_internal_test.go (about) 1 package types 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/suite" 7 ) 8 9 type storeIntSuite struct { 10 suite.Suite 11 } 12 13 func TestStoreIntSuite(t *testing.T) { 14 suite.Run(t, new(storeIntSuite)) 15 } 16 17 func (s *storeIntSuite) TestAssertNoPrefix() { 18 testCases := []struct { 19 keys []string 20 expectPanic bool 21 }{ 22 {[]string{""}, false}, 23 {[]string{"a"}, false}, 24 {[]string{"a", "b"}, false}, 25 {[]string{"a", "b1"}, false}, 26 {[]string{"b2", "b1"}, false}, 27 {[]string{"b1", "bb", "b2"}, false}, 28 29 {[]string{"a", ""}, true}, 30 {[]string{"a", "b", "a"}, true}, 31 {[]string{"a", "b", "aa"}, true}, 32 {[]string{"a", "b", "ab"}, true}, 33 {[]string{"a", "b1", "bb", "b12"}, true}, 34 } 35 36 require := s.Require() 37 for _, tc := range testCases { 38 if tc.expectPanic { 39 require.Panics(func() { assertNoPrefix(tc.keys) }) 40 } else { 41 assertNoPrefix(tc.keys) 42 } 43 } 44 } 45 46 func (s *storeIntSuite) TestNewKVStoreKeys() { 47 require := s.Require() 48 require.Panics(func() { NewKVStoreKeys("a1", "a") }, "should fail one key is a prefix of another one") 49 50 require.Equal(map[string]*KVStoreKey{}, NewKVStoreKeys()) 51 require.Equal(1, len(NewKVStoreKeys("one"))) 52 53 key := "baca" 54 stores := NewKVStoreKeys(key, "a") 55 require.Len(stores, 2) 56 require.Equal(key, stores[key].Name()) 57 }