From 6edde106ac52e16bf2c30a5e2ee4617337e8cb8f Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Fri, 11 May 2018 11:43:24 -0400 Subject: [PATCH] sharding: remaining tests for kv store Former-commit-id: b95783af1808209e492107fbb1c9cb318d04c899 [formerly 17c0946e769872d3f21b17996d73cffe6c8263b6] Former-commit-id: 334deee870bcfef7107a3e4feeb2a275d9e9580c --- sharding/database/inmemory_test.go | 45 +++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/sharding/database/inmemory_test.go b/sharding/database/inmemory_test.go index b994a6550..d98a93711 100644 --- a/sharding/database/inmemory_test.go +++ b/sharding/database/inmemory_test.go @@ -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) + } +}