mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-08 10:41:19 +00:00
6e10d9fa6d
Former-commit-id: 1fc773af9e07a79f63bf63a097526a7c3303cd14 [formerly 59b4763c8b101068eacd717caa757846a481c514] Former-commit-id: 6b8162c9c976f15e19e16fcdda7fd3d274b2e151
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 := NewShardKV()
|
|
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 := NewShardKV()
|
|
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 := NewShardKV()
|
|
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 := NewShardKV()
|
|
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)
|
|
}
|
|
}
|