mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-06 01:32:18 +00:00
dfaf005229
Former-commit-id: 70fee9bf5816e9520fb927b84ab8b93d83014869 [formerly 523192e37e40878079d7981bd28ed25f618ab0a6] Former-commit-id: 604f33826c63ff42dd90d75bb517ed09f5d52b6a
75 lines
1.7 KiB
Go
75 lines
1.7 KiB
Go
package database
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/ethereum/go-ethereum/common"
|
|
"github.com/ethereum/go-ethereum/sharding"
|
|
)
|
|
|
|
// Verifies that ShardKV implements the ShardBackend interface.
|
|
var _ = sharding.ShardBackend(&ShardKV{})
|
|
|
|
func Test_ShardKVPut(t *testing.T) {
|
|
kv := NewShardKV()
|
|
hash := common.BytesToHash([]byte("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.BytesToHash([]byte("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.BytesToHash([]byte{})
|
|
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.BytesToHash([]byte("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.BytesToHash([]byte{})
|
|
val2, err := kv.Get(hash2)
|
|
if val2 != 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.BytesToHash([]byte("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)
|
|
}
|
|
}
|