From f0b3766a465d2c833d05836c22a9ca7032a767a1 Mon Sep 17 00:00:00 2001 From: Joon Date: Tue, 21 Aug 2018 22:49:06 +0900 Subject: [PATCH] Merge PR #2074: Reject duplicate storekey name --- store/rootmultistore.go | 3 +++ store/rootmultistore_test.go | 15 +++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/store/rootmultistore.go b/store/rootmultistore.go index 8eb1c33dd..04f8e44e6 100644 --- a/store/rootmultistore.go +++ b/store/rootmultistore.go @@ -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, diff --git a/store/rootmultistore_test.go b/store/rootmultistore_test.go index 79760d869..d6a714c66 100644 --- a/store/rootmultistore_test.go +++ b/store/rootmultistore_test.go @@ -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 {