diff options
Diffstat (limited to 'test/blockinfodatabase_test.go')
-rw-r--r-- | test/blockinfodatabase_test.go | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/test/blockinfodatabase_test.go b/test/blockinfodatabase_test.go new file mode 100644 index 0000000..5205c99 --- /dev/null +++ b/test/blockinfodatabase_test.go @@ -0,0 +1,40 @@ +package test + +import ( + "Chain/pkg/blockchain/blockinfodatabase" + "reflect" + "testing" +) + +func TestStoreBlockRecord(t *testing.T) { + defer cleanUp() + blockinfo := blockinfodatabase.New(blockinfodatabase.DefaultConfig()) + br := MockedBlockRecord() + blockinfo.StoreBlockRecord("hash", br) +} + +func TestGetSameRecord(t *testing.T) { + defer cleanUp() + blockinfo := blockinfodatabase.New(blockinfodatabase.DefaultConfig()) + br := MockedBlockRecord() + blockinfo.StoreBlockRecord("hash", br) + br2 := blockinfo.GetBlockRecord("hash") + if !reflect.DeepEqual(br, br2) { + t.Errorf("Block records not equal") + } +} + +func TestGetDifferentRecords(t *testing.T) { + defer cleanUp() + blockinfo := blockinfodatabase.New(blockinfodatabase.DefaultConfig()) + br := MockedBlockRecord() + br2 := MockedBlockRecord() + br2.UndoEndOffset = 20 + blockinfo.StoreBlockRecord("hash", br) + blockinfo.StoreBlockRecord("hash2", br2) + rbr := blockinfo.GetBlockRecord("hash") + rbr2 := blockinfo.GetBlockRecord("hash2") + if reflect.DeepEqual(rbr, rbr2) { + t.Errorf("Block records should not be equal") + } +} |