From 3b56ccaff7748219a695a12570c34f57badd253b Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Tue, 15 Oct 2013 10:22:08 -0500 Subject: [PATCH] Add interface test for NewestSha. --- interface_test.go | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/interface_test.go b/interface_test.go index 7bbcd781..029c1604 100644 --- a/interface_test.go +++ b/interface_test.go @@ -51,6 +51,36 @@ func testInsertBlock(tc *testContext) bool { return true } +// testNewestSha ensures the NewestSha returns the values expected by the +// interface contract. +func testNewestSha(tc *testContext) bool { + // The news block hash and height must be returned without any errors. + sha, height, err := tc.db.NewestSha() + if err != nil { + tc.t.Errorf("NewestSha (%s): block #%d (%s) error %v", + tc.dbType, tc.blockHeight, tc.blockHash, err) + return false + } + + // The returned hash must be the expected value. + if !sha.IsEqual(tc.blockHash) { + tc.t.Errorf("NewestSha (%s): block #%d (%s) wrong hash got: %s", + tc.dbType, tc.blockHeight, tc.blockHash, sha) + return false + + } + + // The returned height must be the expected value. + if height != tc.blockHeight { + tc.t.Errorf("NewestSha (%s): block #%d (%s) wrong height "+ + "got: %d", tc.dbType, tc.blockHeight, tc.blockHash, + height) + return false + } + + return true +} + // testExistsSha ensures ExistsSha conforms to the interface contract. func testExistsSha(tc *testContext) bool { // The block must exist in the database. @@ -453,6 +483,12 @@ func testInterface(t *testing.T, dbType string) { return } + // The NewestSha function must return the correct information + // about the block that was just inserted. + if !testNewestSha(&context) { + return + } + // The block must pass all data integrity tests which involve // invoking all and testing the result of all interface // functions which deal with fetch and checking for data