forked from celestiaorg/smt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mapstore_test.go
49 lines (43 loc) · 976 Bytes
/
mapstore_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package smt
import (
"bytes"
"crypto/sha256"
"testing"
)
func TestSimpleMap(t *testing.T) {
sm := NewSimpleMap()
h := sha256.New()
var value []byte
var err error
h.Write([]byte("test"))
// Tests for Get.
_, err = sm.Get(h.Sum(nil))
if err == nil {
t.Error("did not return an error when getting a non-existent key")
}
// Tests for Put.
err = sm.Set(h.Sum(nil), []byte("hello"))
if err != nil {
t.Error("updating a key returned an error")
}
value, err = sm.Get(h.Sum(nil))
if err != nil {
t.Error("getting a key returned an error")
}
if !bytes.Equal(value, []byte("hello")) {
t.Error("failed to update key")
}
// Tests for Del.
err = sm.Delete(h.Sum(nil))
if err != nil {
t.Error("deleting a key returned an error")
}
_, err = sm.Get(h.Sum(nil))
if err == nil {
t.Error("failed to delete key")
}
err = sm.Delete([]byte("nonexistent"))
if err == nil {
t.Error("deleting a key did not return an error on a non-existent key")
}
}