func testFetchHeightRange(t *testing.T, db database.Db, blocks []*coinutil.Block) { var testincrement int32 = 50 var testcnt int32 = 100 shanames := make([]*wire.ShaHash, len(blocks)) nBlocks := int32(len(blocks)) for i := range blocks { shanames[i] = blocks[i].Sha() } for startheight := int32(0); startheight < nBlocks; startheight += testincrement { endheight := startheight + testcnt if endheight > nBlocks { endheight = database.AllShas } shalist, err := db.FetchHeightRange(startheight, endheight) if err != nil { t.Errorf("FetchHeightRange: unexpected failure looking up shas %v", err) } if endheight == database.AllShas { if int32(len(shalist)) != nBlocks-startheight { t.Errorf("FetchHeightRange: expected A %v shas, got %v", nBlocks-startheight, len(shalist)) } } else { if int32(len(shalist)) != testcnt { t.Errorf("FetchHeightRange: expected %v shas, got %v", testcnt, len(shalist)) } } for i := range shalist { sha0 := *shanames[int32(i)+startheight] sha1 := shalist[i] if sha0 != sha1 { t.Errorf("FetchHeightRange: mismatch sha at %v requested range %v %v: %v %v ", int32(i)+startheight, startheight, endheight, sha0, sha1) } } } }