diff --git a/db/rocksdb.go b/db/rocksdb.go index e1dc2238..300f9c63 100644 --- a/db/rocksdb.go +++ b/db/rocksdb.go @@ -927,7 +927,7 @@ func (d *RocksDB) packBlockInfo(block *BlockInfo) ([]byte, error) { func (d *RocksDB) unpackBlockInfo(buf []byte) (*BlockInfo, error) { pl := d.chainParser.PackedTxidLen() - // minimum length is PackedTxidLen+4 bytes time + 1 byte txs + 1 byte size + // minimum length is PackedTxidLen + 4 bytes time + 1 byte txs + 1 byte size if len(buf) < pl+4+2 { return nil, nil } @@ -986,12 +986,8 @@ func (d *RocksDB) GetBlockInfo(height uint32) (*BlockInfo, error) { return nil, err } defer val.Free() - if val.Size() == 0 { - // block not found - return nil, nil - } bi, err := d.unpackBlockInfo(val.Data()) - if err != nil { + if err != nil || bi == nil { return nil, err } bi.Height = height diff --git a/server/public_test.go b/server/public_test.go index 5a6c8c4b..eae1d2ff 100644 --- a/server/public_test.go +++ b/server/public_test.go @@ -39,7 +39,7 @@ func setupRocksDB(t *testing.T, parser bchain.BlockChainParser) (*db.RocksDB, *c if err != nil { t.Fatal(err) } - is, err := d.LoadInternalState("btc-testnet") + is, err := d.LoadInternalState("fakecoin") if err != nil { t.Fatal(err) } @@ -60,11 +60,11 @@ func setupPublicHTTPServer(t *testing.T) (*PublicServer, string) { &btc.Configuration{BlockAddressesToKeep: 1}) d, is, path := setupRocksDB(t, parser) - is.Coin = "Testnet" - is.CoinLabel = "Bitcoin Testnet" - is.CoinShortcut = "TEST" + is.Coin = "Fakecoin" + is.CoinLabel = "Fake Coin" + is.CoinShortcut = "FAKE" - metrics, err := common.GetMetrics("Testnet") + metrics, err := common.GetMetrics("Fakecoin") if err != nil { glog.Fatal("metrics: ", err) } @@ -103,14 +103,7 @@ func newGetRequest(url string, body io.Reader) *http.Request { return r } -func Test_PublicServer_UTXO(t *testing.T) { - s, dbpath := setupPublicHTTPServer(t) - defer closeAndDestroyPublicServer(t, s, dbpath) - s.ConnectFullPublicInterface() - // take the handler of the public server and pass it to the test server - ts := httptest.NewServer(s.https.Handler) - defer ts.Close() - +func httpTests(t *testing.T, ts *httptest.Server) { tests := []struct { name string r *http.Request @@ -124,12 +117,12 @@ func Test_PublicServer_UTXO(t *testing.T) { status: http.StatusOK, contentType: "text/html; charset=utf-8", body: []string{ - `Bitcoin Testnet Explorer`, + `Fake Coin Explorer`, `