mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-08 10:41:19 +00:00
6edde106ac
Former-commit-id: b95783af1808209e492107fbb1c9cb318d04c899 [formerly 17c0946e769872d3f21b17996d73cffe6c8263b6] Former-commit-id: 334deee870bcfef7107a3e4feeb2a275d9e9580c
71 lines
1.5 KiB
Go
71 lines
1.5 KiB
Go
package database
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/ethereum/go-ethereum/common"
|
|
)
|
|
|
|
func Test_ShardKVPut(t *testing.T) {
|
|
kv := MakeShardKV()
|
|
hash := common.StringToHash("ralph merkle")
|
|
|
|
if err := kv.Put(hash, []byte{1, 2, 3}); err != nil {
|
|
t.Errorf("could not save value in kv store: %v", err)
|
|
}
|
|
}
|
|
|
|
func Test_ShardKVHas(t *testing.T) {
|
|
kv := MakeShardKV()
|
|
hash := common.StringToHash("ralph merkle")
|
|
|
|
if err := kv.Put(hash, []byte{1, 2, 3}); err != nil {
|
|
t.Fatalf("could not save value in kv store: %v", err)
|
|
}
|
|
|
|
if !kv.Has(hash) {
|
|
t.Errorf("kv store does not have hash: %v", hash)
|
|
}
|
|
|
|
hash2 := common.StringToHash("")
|
|
if kv.Has(hash2) {
|
|
t.Errorf("kv store should not contain unset key: %v", hash2)
|
|
}
|
|
}
|
|
|
|
func Test_ShardKVGet(t *testing.T) {
|
|
kv := MakeShardKV()
|
|
hash := common.StringToHash("ralph merkle")
|
|
|
|
if err := kv.Put(hash, []byte{1, 2, 3}); err != nil {
|
|
t.Fatalf("could not save value in kv store: %v", err)
|
|
}
|
|
|
|
val, err := kv.Get(hash)
|
|
if err != nil {
|
|
t.Errorf("get failed: %v", err)
|
|
}
|
|
if val == nil {
|
|
t.Errorf("no value stored for key")
|
|
}
|
|
|
|
hash2 := common.StringToHash("")
|
|
val2, err := kv.Get(hash2)
|
|
if err == nil {
|
|
t.Errorf("non-existent key should not have a value. key=%v, value=%v", hash2, val2)
|
|
}
|
|
}
|
|
|
|
func Test_ShardKVDelete(t *testing.T) {
|
|
kv := MakeShardKV()
|
|
hash := common.StringToHash("ralph merkle")
|
|
|
|
if err := kv.Put(hash, []byte{1, 2, 3}); err != nil {
|
|
t.Fatalf("could not save value in kv store: %v", err)
|
|
}
|
|
|
|
if err := kv.Delete(hash); err != nil {
|
|
t.Errorf("could not delete key: %v", hash)
|
|
}
|
|
}
|