@cryptotaxi247 / kubo / commits / f2686965a

tests: Add test to RuntimeHashing option of blockstore

License: MIT Signed-off-by: Jakub Sztandera <kubuxu@protonmail.ch>

Jakub Sztandera committed Jun 24, 2016 at 22:03 UTC f2686965ac5e93f3c672308a0fa467a36f0e2b1a
1 file changed +16
blocks/blockstore/blockstore_test.go
+16
@@ -53,6 +53,22 @@ func TestPutThenGetBlock(t *testing.T) {
53 }
54 }
55
56 +func TestRuntimeHashing(t *testing.T) {
57 + bs := NewBlockstore(ds_sync.MutexWrap(ds.NewMapDatastore()))
58 + bl := blocks.NewBlock([]byte("some data"))
59 + blBad, err := blocks.NewBlockWithHash([]byte("some other data"), bl.Key().ToMultihash())
60 + if err != nil {
61 + t.Fatal("Debug is enabled")
62 + }
63 +
64 + bs.Put(blBad)
65 + bs.RuntimeHashing(true)
66 +
67 + if _, err := bs.Get(bl.Key()); err != ErrHashMismatch {
68 + t.Fatalf("Expected '%v' got '%v'\n", ErrHashMismatch, err)
69 + }
70 +}
71 +
72 func newBlockStoreWithKeys(t *testing.T, d ds.Datastore, N int) (Blockstore, []key.Key) {
73 if d == nil {
74 d = ds.NewMapDatastore()