Merge PR #2074: Reject duplicate storekey name

This commit is contained in:
Joon 2018-08-21 22:49:06 +09:00 committed by Christopher Goes
parent 1eadb510b8
commit f0b3766a46
2 changed files with 18 additions and 0 deletions

View File

@ -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,

View File

@ -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 {