sharding: remaining tests for kv store

Former-commit-id: b95783af1808209e492107fbb1c9cb318d04c899 [formerly 17c0946e769872d3f21b17996d73cffe6c8263b6]
Former-commit-id: 334deee870bcfef7107a3e4feeb2a275d9e9580c
This commit is contained in:
Raul Jordan 2018-05-11 11:43:24 -04:00
parent 5dc498f402
commit 6edde106ac

View File

@ -6,10 +6,40 @@ import (
"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")
kv.Put(hash, []byte{1, 2, 3})
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 {
@ -25,3 +55,16 @@ func Test_ShardKVGet(t *testing.T) {
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)
}
}