Skip to content

Commit

Permalink
Merge PR #2074: Reject duplicate storekey name
Browse files Browse the repository at this point in the history
  • Loading branch information
mossid authored and cwgoes committed Aug 21, 2018
1 parent 1eadb51 commit f0b3766
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions store/rootmultistore.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ func (rs *rootMultiStore) MountStoreWithDB(key StoreKey, typ StoreType, db dbm.D
if _, ok := rs.storesParams[key]; ok {
panic(fmt.Sprintf("rootMultiStore duplicate store key %v", key))
}
if _, ok := rs.keysByName[key.Name()]; ok {
panic(fmt.Sprintf("rootMultiStore duplicate store key name %v", key))
}
rs.storesParams[key] = storeParams{
key: key,
typ: typ,
Expand Down
15 changes: 15 additions & 0 deletions store/rootmultistore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,21 @@ func TestStoreType(t *testing.T) {

}

func TestStoreMount(t *testing.T) {
db := dbm.NewMemDB()
store := NewCommitMultiStore(db)

key1 := sdk.NewKVStoreKey("store1")
key2 := sdk.NewKVStoreKey("store2")
dup1 := sdk.NewKVStoreKey("store1")

require.NotPanics(t, func() { store.MountStoreWithDB(key1, sdk.StoreTypeIAVL, db) })
require.NotPanics(t, func() { store.MountStoreWithDB(key2, sdk.StoreTypeIAVL, db) })

require.Panics(t, func() { store.MountStoreWithDB(key1, sdk.StoreTypeIAVL, db) })
require.Panics(t, func() { store.MountStoreWithDB(dup1, sdk.StoreTypeIAVL, db) })
}

func TestMultistoreCommitLoad(t *testing.T) {
var db dbm.DB = dbm.NewMemDB()
if useDebugDB {
Expand Down

0 comments on commit f0b3766

Please sign in to comment.