forked from cerc-io/plugeth
ethdb: return copied value from MemDatabase.Get (#14958)
This commit is contained in:
parent
17ce0a37de
commit
73c5aba21f
@ -94,6 +94,21 @@ func testPutGet(db ethdb.Database, t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _, v := range test_values {
|
||||||
|
orig, err := db.Get([]byte(v))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("get failed: %v", err)
|
||||||
|
}
|
||||||
|
orig[0] = byte(0xff)
|
||||||
|
data, err := db.Get([]byte(v))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("get failed: %v", err)
|
||||||
|
}
|
||||||
|
if !bytes.Equal(data, []byte("?")) {
|
||||||
|
t.Fatalf("get returned wrong result, got %q expected ?", string(data))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for _, v := range test_values {
|
for _, v := range test_values {
|
||||||
err := db.Delete([]byte(v))
|
err := db.Delete([]byte(v))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -50,7 +50,7 @@ func (db *MemDatabase) Get(key []byte) ([]byte, error) {
|
|||||||
defer db.lock.RUnlock()
|
defer db.lock.RUnlock()
|
||||||
|
|
||||||
if entry, ok := db.db[string(key)]; ok {
|
if entry, ok := db.db[string(key)]; ok {
|
||||||
return entry, nil
|
return common.CopyBytes(entry), nil
|
||||||
}
|
}
|
||||||
return nil, errors.New("not found")
|
return nil, errors.New("not found")
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user