func TestPostTagTagBlob(t *testing.T) { testhkid := objects.HkidFromDString("46298148238932964800164113348087"+ "9383618612455972320097996217675372497646408870646300138355611242"+ "4820911870650421151988906751710824965155500230480521264034469", 10) domain1Hkid := objects.HkidFromDString("32076859881811206392323279987831"+ "3732334949433938278619036381396945204532895319697233476900342324"+ "1692155627674142765782672165943417419038514237233188152538761", 10) domain2Hkid := objects.HkidFromDString("49220288257701056900010210884990"+ "0714973444364727181180850528073586453638681999434006549298762097"+ "4197649255374796716934112121800838847071661501215957753532505", 10) err := services.InsertDomain(testhkid, "testTag1", domain1Hkid) if err != nil { t.Errorf("InsertDomain with error: %s", err) } err = services.InsertDomain(testhkid, "testTag1/testTag2", domain2Hkid) if err != nil { t.Errorf("InsertDomain with error: %s", err) } indata := objects.Blob([]byte("TestTagTagBlobData")) testpath := "testTag1/testTag2/testBlob" _, err = services.Post(testhkid, testpath, indata) outdata, err := services.Get(testhkid, testpath) if err != nil { log.Printf("[TestPostTagTagBlob] testhkid %s", testhkid) log.Printf("[TestPostTagTagBlob] domain1Hkid %s", domain1Hkid) log.Printf("[TestPostTagTagBlob] domain2Hkid %s", domain2Hkid) t.Errorf("Retreved with error: %s", err) } else if !bytes.Equal(indata, outdata) { t.Errorf("Expected:\n\t%s\nGot:\n\t%s", indata, outdata) } }
func init() { //Open|Create Log File logFileName := "bin/log.txt" logFile, err := os.OpenFile(logFileName, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0664) if err != nil { log.Println("Unable to Create/Open log file. No output will be captured.") } else { log.SetOutput(logFile) log.Println("Benchmark Started:") } log.SetFlags(log.Lshortfile | log.Ltime | log.Ldate) objects.RegisterGeterPoster( services.GetPublicKeyForHkid, services.GetPrivateKeyForHkid, services.PostKey, services.PostBlob, ) localfile.Start() //Post(benchmarkRepo, "BlobFound", blob("blob found")) //Post(benchmarkRepo, "listFound/BlobFound", blob("list found")) benchmarkRepo = objects.HkidFromDString("44089867384569081480066871308647"+ "4832666868594293316444099156169623352946493325312681245061254048"+ "6538169821270508889792789331438131875225590398664679212538621", 10) log.Printf("Benchmark Repository HKID: %s\n", benchmarkRepo) benchmarkCommitHkid = objects.HkidFromDString("36288652923287342545336063204999"+ "9357791979761632757400493952327434464825857894440491353330036559"+ "1539025688752776406270441884985963379175226110071953813093104", 10) log.Printf("Benchmark Commit HKID: %s\n", benchmarkCommitHkid) benchmarkTagHkid = objects.HkidFromDString("54430439211086161065670118078952"+ "6855263811485554809970416168964497131310494084201908881724207840"+ "2305843436117034888111308798569392135240661266075941854101839", 10) log.Printf("Benchmark Tag HKID: %s\n", benchmarkTagHkid) }
func TestLowLevel(t *testing.T) { indata := objects.Blob([]byte("TestPostData")) services.PostBlob(indata) blobhcid, err := objects.HcidFromHex( "ca4c4244cee2bd8b8a35feddcd0ba36d775d68637b7f0b4d2558728d0752a2a2", ) b, err := services.GetBlob(blobhcid) if !bytes.Equal(b.Hash(), blobhcid) { t.Fatalf("GetBlob Fail\nExpected: %s\nGot: %s\n", blobhcid, b.Hash()) //Changed } //6dedf7e580671bd90bc9d1f735c75a4f3692b697f8979a147e8edd64fab56e85 testhkid := objects.HkidFromDString( "6523237356270560228617783789728329416595512649112249373497830592"+ "0722414168936112160694238047304378604753005642729767620850685191"+ "88612732562106886379081213385", 10) testCommit := objects.NewCommit(b.Hash(), testhkid) services.PostCommit(testCommit) c, err := services.GetCommit(testhkid) if err != nil { t.Fatalf("Get Commit Fail: %s", err) } else if !bytes.Equal(c.Hkid, testhkid) { t.Fatalf("Expected: %s Got: %s", testhkid, c.Hkid) } else if !c.Verify() { t.Fatalf("Commit Signature Invalid.") } //ede7bec713c93929751f18b1db46d4be3c95286bd5f2d92b9759ff02115dc312 taghkid := objects.HkidFromDString( "4813315537186321970719165779488475377688633084782731170482174374"+ "7256947679650787426167575073363006751150073195493002048627629373"+ "76227751462258339344895829332", 10) lowlvlTag := objects.NewTag( objects.HID(b.Hash()), "blob", "testBlob", nil, taghkid, ) //gen test tag services.PostTag(lowlvlTag) testtag, err := services.GetTag(taghkid, lowlvlTag.NameSegment) if err != nil { t.Fatalf("GetTag Fail. error: %s", err) } else if !bytes.Equal(testtag.Hkid, taghkid) { t.Fatalf("GetTag Fail.\n\t expected: %v\n\t got: %v", taghkid, testtag.Hkid) } else if !testtag.Verify() { t.Fatalf("GetTag Verify Fail") } prikey, err := services.GetKey(taghkid) if err != nil || !bytes.Equal(prikey.Hkid(), taghkid) || !prikey.Verify() { t.Logf("GetKey Fail") t.Fail() } }
func TestMulticastservice_GetTag(t *testing.T) { //t.Skipf("Come back to this test") //log.Printf("The key generated is, %d", KeyGen().D) //hkid := HKID{} hkid := objects.HkidFromDString("6450698573071574057685373503239926609554390924514830851922442833127942726436428023022500281659846836919706975681006884631876585143520956760217923400876937896", 10) b := objects.Blob([]byte("blob found")) tagT := objects.NewTag(b.Hash(), "blob", "BlobinTag", hkid) localfile.Instance.PostTag(tagT) go func() { time.Sleep(1 * time.Millisecond) mcaddr, _ := net.ResolveUDPAddr("udp", "127.0.0.1:8000") Instance.receivemessage(fmt.Sprintf("{\"type\":\"tag\", \"hkid\": \"%s\", \"namesegment\": \"%s\", \"URL\": \"/t/%s/%s/%d\"}", hkid, tagT.NameSegment, hkid, tagT.NameSegment, tagT.Version), mcaddr) }() output, err := Instance.GetTag(tagT.Hkid(), tagT.NameSegment) if err != nil { t.Errorf("Get Tag Failed \nError:%s", err) } else if !output.Verify() { //!bytes.Equal(output.Hash(), tag_t.Hash()) { t.Errorf("Get Tag Failed \nExpected:%s \nGot: %s", tagT, output) } if output.Version != tagT.Version { log.Printf("Tag is stale %d", tagT.Version-output.Version) } }
func TestPostTagBlob(t *testing.T) { testhkid := objects.HkidFromDString("65232373562705602286177837897283"+ "2941659551264911224937349783059207224141689361121606942380473043"+ "7860475300564272976762085068519188612732562106886379081213385", 10) testDomainHkid := objects.HkidFromDString("48133155371863219707191657794884"+ "7537768863308478273117048217437472569476796507874261675750733630"+ "0675115007319549300204862762937376227751462258339344895829332", 10) services.InsertDomain(testhkid, "TestPostTag", testDomainHkid) testpath := "TestPostTag/TestPostBlob" indata := []byte("TestPostTagBlobData") services.Post(testhkid, testpath, objects.Blob(indata)) outdata, err := services.Get(testhkid, testpath) if !bytes.Equal(indata, outdata) || err != nil { t.Fail() } }
func init() { benchmarkRepo = objects.HkidFromDString("44089867384569081480066871308647"+ "4832666868594293316444099156169623352946493325312681245061254048"+ "6538169821270508889792789331438131875225590398664679212538621", 10) services.Registerblobgeter(Instance) services.Registerblobgeter(timeout.Instance) }
func TestPostCommitBlob(t *testing.T) { testhkid := objects.HkidFromDString("65232373562705602286177837897283"+ "2941659551264911224937349783059207224141689361121606942380473043"+ "7860475300564272976762085068519188612732562106886379081213385", 10) testRepoHkid := objects.HkidFromDString("22371143209450593169269383669277"+ "1410459232098247632372342448006863927240156318431751613873181811"+ "3842641285036340692759591635625837820111726090732747634977413", 10) services.InsertRepo(testhkid, "TestPostCommit", testRepoHkid) testpath := "TestPostCommit/TestPostBlob" indata := []byte("TestPostCommitBlobData") services.Post(testhkid, testpath, objects.Blob(indata)) outdata, err := services.Get(testhkid, testpath) if !bytes.Equal(indata, outdata) || err != nil { t.Fail() } }
func TestMulticastservice_GetCommit(t *testing.T) { //t.Skipf("Come back to this test") hkid := objects.HkidFromDString("5198719439877464148627795433286736285873678110640040333794349799294848737858561643942881983506066042818105864129178593001327423646717446545633525002218361750", 10) b := objects.Blob([]byte("blob found")) l := objects.NewList(b.Hash(), "blob", "Blobinlist") c := objects.NewCommit(l.Hash(), hkid) localfile.Instance.PostCommit(c) go func() { time.Sleep(1 * time.Millisecond) mcaddr, _ := net.ResolveUDPAddr("udp", "127.0.0.1:8000") Instance.receivemessage(fmt.Sprintf("{\"type\":\"commit\", \"hkid\": \"9bd1b3c9aeda7025068319c0a4af1d2b7b644066c9820d247b19f1b9bf40840c\", \"URL\": \"/c/9bd1b3c9aeda7025068319c0a4af1d2b7b644066c9820d247b19f1b9bf40840c/%d\"}", c.Version), mcaddr) }() output, err := Instance.GetCommit(c.Hkid()) if err != nil { t.Errorf("Get Commit Failed \nError:%s", err) } else if !output.Verify() { //else if !bytes.Equal(output.Hash(), c.Hash()) { t.Errorf("Get Commit Failed \nExpected:%s \nGot: %s", c, output) } if output.Version() != c.Version() { log.Printf("Commit is stale %d", c.Version()-output.Version()) } }
func setupForGets() { hkidT := objects.HkidFromDString("39968110670682397993178679825250942322686997267223"+ "4437068973021071131498376777586055610149840018574420844767320660902612889"+ "4016152514163591905578729891874833", 10) //key for commit hkidC := objects.HkidFromDString("4629814823893296480016411334808793836186124559723200"+ "9799621767537249764640887064630013835561124248209118706504211519889067517"+ "10824965155500230480521264034469", 10) //Post blob testBlob := objects.Blob([]byte("testing")) //gen test blob err := services.PostBlob(testBlob) //store test blob if err != nil { log.Println(err) } //post tag testTagPointingToTestBlob := objects.NewTag( objects.HID(testBlob.Hash()), "blob", "testBlob", nil, hkidT, ) //gen test tag err = services.PostTag(testTagPointingToTestBlob) //post test tag if err != nil { log.Println(err) } //post list testListPiontingToTestTag := objects.NewList(testTagPointingToTestBlob.Hkid, "tag", "testTag") //gen test list err = services.PostBlob(testListPiontingToTestTag.Bytes()) //store test list if err != nil { log.Println(err) } // post commit testCommitPointingToTestList := objects.NewCommit(testListPiontingToTestTag.Hash(), hkidC) //gen test commit err = services.PostCommit(testCommitPointingToTestList) //post test commit if err != nil { log.Println(err) } }
func TestPostListTagBlob(t *testing.T) { testhkid := objects.HkidFromDString("46298148238932964800164113348087"+ "9383618612455972320097996217675372497646408870646300138355611242"+ "4820911870650421151988906751710824965155500230480521264034469", 10) domainHkid := objects.HkidFromDString("12796633883654089746486670711069"+ "9781359720828332046318301886846633714179790444071153863702142701"+ "146332294245448463914286494124849121460550667767568731696934", 10) err := services.InsertDomain(testhkid, "testList/testTag", domainHkid) indata := objects.Blob([]byte("TestListTagBlobData")) testpath := "testList/testTag/testBlob" _, err = services.Post(testhkid, testpath, indata) outdata, err := services.Get(testhkid, testpath) if err != nil { t.Errorf("Retreved with error: %s", err) } else if !bytes.Equal(indata, outdata) { t.Errorf("Expected:\n\t%s\nGot:\n\t%s", indata, outdata) } }
func TestPostTagListBlob(t *testing.T) { testhkid := objects.HkidFromDString("46298148238932964800164113348087"+ "9383618612455972320097996217675372497646408870646300138355611242"+ "4820911870650421151988906751710824965155500230480521264034469", 10) domainHkid := objects.HkidFromDString("62089221762245310704629142682144"+ "1944826557905230450143203631438168806532495876980559885034903315"+ "4294997505754401230560960060918213268981906409591978967796584", 10) err := services.InsertDomain(testhkid, "testTag", domainHkid) if err != nil { t.Errorf("InsertDomain with error: %s", err) } indata := objects.Blob([]byte("TestTagListBlobData")) testpath := "testTag/testList/testBlob" _, err = services.Post(testhkid, testpath, indata) outdata, err := services.Get(testhkid, testpath) if !bytes.Equal(indata, outdata) || err != nil { t.Fail() } }
func TestGetTag(t *testing.T) { //think about what it means to get a domain with no path testhkid := objects.HkidFromDString("65232373562705602286177837897283294165955126"+ "49112249373497830592072241416893611216069423804730437860475300564272"+ "976762085068519188612732562106886379081213385", 10) outdata, err := services.Get(testhkid, "TestPostTag") truthdata := []byte("") if !bytes.Equal(truthdata, outdata) { log.Printf("\n\tTestGetList:\n\t%s\n\terror: %s\n", outdata, err) t.Fail() } }
func TestPostListListBlob(t *testing.T) { testhkid := objects.HkidFromDString("65232373562705602286177837897283294165955126"+ "49112249373497830592072241416893611216069423804730437860475300564272"+ "976762085068519188612732562106886379081213385", 10) testpath := "TestPostList1/TestPostList2/TestPostBlob" indata := []byte("TestPostListListBlobData") services.Post(testhkid, testpath, objects.Blob(indata)) outdata, err := services.Get(testhkid, testpath) if !bytes.Equal(indata, outdata) || err != nil { t.Fail() } }
func TestPostTagCommitBlob(t *testing.T) { testhkid := objects.HkidFromDString("46298148238932964800164113348087"+ "9383618612455972320097996217675372497646408870646300138355611242"+ "4820911870650421151988906751710824965155500230480521264034469", 10) domainHkid := objects.HkidFromDString("39968110670682397993178679825250"+ "9423226869972672234437068973021071131498376777586055610149840018"+ "5744208447673206609026128894016152514163591905578729891874833", 10) repoHkid := objects.HkidFromDString("94522678075182002377842140271746"+ "1502019766737301062946423046280258817349516439546479625226895211"+ "80808353215150536034481206091147220911087792299373183736254", 10) err := services.InsertDomain(testhkid, "testTag", domainHkid) if err != nil { t.Errorf("InsertDomain with error: %s", err) } err = services.InsertRepo(testhkid, "testTag/testCommit", repoHkid) indata := objects.Blob([]byte("TestTagCommitBlobData")) testpath := "testTag/testCommit/testBlob" _, err = services.Post(testhkid, testpath, indata) outdata, err := services.Get(testhkid, testpath) if !bytes.Equal(indata, outdata) || err != nil { t.Fail() } }
func KeyLocalSeed() { HKIDstring := GetLocalSeed() h, er := objects.HkidFromHex(HKIDstring) if er != nil { log.Printf("local seed not valid hex /n") } _, err := services.GetKey(h) if err != nil { objects.HkidFromDString("65232373562705602286177837897283294165955126"+ "49112249373497830592072241416893611216069423804730437860475300564272"+ "976762085068519188612732562106886379081213385", 10) } return }
func TestPostListCommitBlob(t *testing.T) { testhkid := objects.HkidFromDString("46298148238932964800164113348087"+ "9383618612455972320097996217675372497646408870646300138355611242"+ "4820911870650421151988906751710824965155500230480521264034469", 10) repoHkid := objects.HkidFromDString("59803288656043806807393139191118"+ "0777289273091938777159029927847596771500408478956278378281366717"+ "7487960901581583946753338859223459810645621124266443931192097", 10) err := services.InsertDomain(testhkid, "testList/testCommit", repoHkid) if err != nil { t.Errorf("InsertDomain with error: %s", err) } indata := objects.Blob([]byte("TestListCommitBlobData")) testpath := "testList/testCommit/testBlob" _, err = services.Post(testhkid, testpath, indata) outdata, err := services.Get(testhkid, testpath) if err != nil { log.Printf("[TestPostListCommitBlob] testhkid %s", testhkid) log.Printf("[TestPostListCommitBlob] repoHkid %s", repoHkid) t.Errorf("Retreved with error: %s", err) } else if !bytes.Equal(indata, outdata) { t.Errorf("Expected:\n\t%s\nGot:\n\t%s", indata, outdata) } }
func TestCLInsertRepo(t *testing.T) { t.Skip("skip insert repo") wd, _ := os.Getwd() path := filepath.Join(wd, mountpoint) os.MkdirAll(fmt.Sprintf("%s/TestPostCommit", path), 0777) list, _ := ioutil.ReadDir(fmt.Sprintf("%s/TestPostCommit", path)) if len(list) != 0 { t.Errorf("Folder not empty") } repoHKID := objects.HkidFromDString("5824205648082772934729637225579799788842383870921308642349398134394915270944497186356984254449560747108115423811117570014383411154383531617434061770576416540", 10) cmd := exec.Command("./src", "-insertRepository=true", fmt.Sprintf("-path=%s/TestPostCommit", path), fmt.Sprintf("-hkid=\"%s\"", repoHKID)) b, err := cmd.CombinedOutput() fmt.Printf("%s", b) if err != nil { t.Errorf("Insert Repository Errored - %s \n", err) } }
func TestGetCommit(t *testing.T) { testhkid := objects.HkidFromDString("65232373562705602286177837897283294165955126"+ "49112249373497830592072241416893611216069423804730437860475300564272"+ "976762085068519188612732562106886379081213385", 10) outdata, err := services.Get(testhkid, "TestPostCommit") outlist, err := objects.ListFromBytes(outdata) typeString, hash := outlist.HashForNamesegment("TestPostBlob") //truthdata := []byte("90014ae279fa5034a51def77132457cd" + // "66403facc3d88b54bd3e84ecade8f633,blob,TestPostBlob") if typeString != "blob" || hash.Hex() != "90014ae279fa5034a51def77132457cd"+ "66403facc3d88b54bd3e84ecade8f633" || err != nil { log.Printf("\n\tTestGetList:\n\t%s\n", outdata) t.Fail() } }
func TestCLInsertDomain(t *testing.T) { t.Skip("skip insert domain") wd, _ := os.Getwd() path := filepath.Join(wd, mountpoint) os.MkdirAll(fmt.Sprintf("%s/TestPostTag", path), 0777) list, _ := ioutil.ReadDir(fmt.Sprintf("%s/TestPostTag", path)) if len(list) != 0 { t.Errorf("Folder not empty") } domainHKID := objects.HkidFromDString("2990018983336786774600773215435487572040278176087795322342464389288172846099779527029312056191767811453586805184323598252008160483472900619326359336945638850", 10) cmd := exec.Command("./src", "-insertDomain=true", fmt.Sprintf("-path=%s/TestPostTag", path), fmt.Sprintf("-hkid=\"%s\"", domainHKID)) b, err := cmd.CombinedOutput() fmt.Printf("%s", b) if err != nil { t.Errorf("Insert Domain Errored - %s \n", err) } }
func BenchmarkHighLevelPath(b *testing.B) { testhkid := objects.HkidFromDString("46298148238932964800164113348087"+ "9383618612455972320097996217675372497646408870646300138355611242"+ "4820911870650421151988906751710824965155500230480521264034469", 10) indata := objects.Blob([]byte("testing")) testpath := "testTag/testBlob" //_, err = Post(testhkid, testpath, indata) for i := 0; i < b.N; i++ { outdata, err := services.Get(testhkid, testpath) if err != nil { b.Fatalf("Failed to retrieve Blob: %s", err) } if !bytes.Equal(indata, outdata) { b.Fatalf("\tExpected: %s\n\tActual: %s\n\t", indata, outdata) } } }
func BenchmarkLowLevelRemoveBlob(b *testing.B) { //Generate HKID from Private Key String commitHkid := objects.HkidFromDString("25237284271696152257500017172738061121437774519248"+ "4973944393756241918592441392745192478415977843322020140748800825891925253"+ "1173359792875255431921541368062567", 10) for i := 0; i < b.N; i++ { //Create Blob and add it to Commit List testBlob := objects.Blob([]byte("BlobToBeDeleted")) _ = services.PostBlob(testBlob) testList := objects.NewList(testBlob.Hash(), "blob", "blobToBeDeleted") services.PostList(testList) testCommit := objects.NewCommit(testList.Hash(), commitHkid) services.PostCommit(testCommit) //Check to make sure Blob was added to Commit List commitFromHkid, err := services.GetCommit(commitHkid) _, err = services.GetList(commitFromHkid.ListHash) listEntry, found := testList["blobToBeDeleted"] if !found { b.Fatalf("Error: Blob could not be found in list") } _, err = services.GetBlob(listEntry.Hash.(objects.HCID)) if err != nil { b.Fatalf("Error: Blob could not be retrieved using HID from list") } //Remove Blob from Commit List testListDelete := testList.Remove("blobToBeDeleted") testCommitDelete := testCommit.Update(testListDelete.Hash()) services.PostCommit(testCommitDelete) //Check to make sure blob Does Not Exist in Commit List dneCommit, _ := services.GetCommit(commitHkid) dneList, _ := services.GetList(dneCommit.ListHash) _, found = dneList["blobToBeDeleted"] if found { b.Fatalf("Error: Blob incorrectly found in list") } } }
func BenchmarkLowLevelRemoveTag(b *testing.B) { //Generate HKID from Private Key String hkidT := objects.HkidFromDString("19161720602889299965155738268484539070322612877960367"+ "6430690841377095800236259476217638708086844263509012365665750826156"+ "6766981217762072709507121631102726282", 10) //2c0b96cd9cd53349b7733f6f3c1b0993c350fa29ae9c9e05706f616fbf66a98a for i := 0; i < b.N; i++ { //Create Blob Object testBlob := objects.Blob([]byte("BlobToBeDeletedFromTag")) //Create Tag Object postTag(testBlob.Hash(), hkidT) //Retrieve Tag Object testTag, err := services.GetTag(hkidT, "testBlob") if err != nil { b.Fatalf("Error: Could Not retrieve tag: %s", err) } //Remove Blob from Tag Object emptyTag := testTag.Delete() //Publish empty Tag services.PostTag(emptyTag) //Retrieve Empty Tag newEmptyTag, err := services.GetTag(hkidT, "testBlob") if err != nil { b.Fatalf("Error: Could not retrieve Tag: %s", err) } //Check Tag to ensure it is empty if newEmptyTag.TypeString != "nab" { b.Fatalf("Error: Incorrect Tag Retrieved%s", newEmptyTag.TypeString) } } }
func TestKademliaserviceTag(t *testing.T) { b := objects.Blob("TestPostData") domainHkid := objects.HkidFromDString("36353776900433612923412235249557"+ "5547801975514185453610009798109590341135752484880821676711220739"+ "4029990114056594565164287698180880449563881968956877896844137", 10) intag := objects.NewTag( b.Hash(), "blob", "TestPostBlob", []objects.HCID{}, domainHkid, ) Instance.PostTag(intag) outtag, err := Instance.GetTag( domainHkid, "TestPostBlob", ) if err != nil { t.Errorf("Get Tag Err: %s", err) } if !outtag.Verify() /*|| !bytes.Equal(outtag.Hkid(), domainHkid)*/ { t.Errorf( "\nVerify:%v", outtag.Verify(), ) } if !bytes.Equal(intag.Bytes(), outtag.Bytes()) { t.Errorf( "\nExpected:%s\nGot:%s", intag, outtag, ) } }
func TestKademliaserviceCommit(t *testing.T) { b := objects.Blob("TestPostData") l := objects.NewList( b.Hash(), "blob", "TestPostBlob", ) repoHkid := objects.HkidFromDString("64171129167204289916774847858432"+ "1039643124642934014944704416438487015947986633802511102841255411"+ "2620702113155684804978643917650455537680636225253952875765474", 10) incommit := objects.NewCommit(l.Hash(), repoHkid) Instance.PostCommit(incommit) outcommit, err := Instance.GetCommit(repoHkid) if err != nil { t.Fatalf("\nGet Commit Err:%s\n", err) } if !outcommit.Verify() { t.Fatalf("\nVerify:%t", outcommit.Verify()) } if !bytes.Equal(incommit.Bytes(), outcommit.Bytes()) { t.Fatalf("\nExpected:%v\nGot:%v", incommit, outcommit) } }
func BenchmarkLowLevelPath(b *testing.B) { //key for tag hkidT := objects.HkidFromDString("39968110670682397993178679825250942322686997267223"+ "4437068973021071131498376777586055610149840018574420844767320660902612889"+ "4016152514163591905578729891874833", 10) //key for commit hkidC := objects.HkidFromDString("4629814823893296480016411334808793836186124559723200"+ "9799621767537249764640887064630013835561124248209118706504211519889067517"+ "10824965155500230480521264034469", 10) for i := 0; i < b.N; i++ { blobHcid := postBlob("testing") postTag(blobHcid, hkidT) tagHcid := postList(hkidT) postCommit(tagHcid, hkidC) //get commit hkid, _ := hex.DecodeString( "1312ac161875b270da2ae4e1471ba94a9883419250caa4c2f1fd80a91b37907e", ) testcommit, err := services.GetCommit(hkid) if err != nil { log.Panic(err) } //log.Printf("authentic commit:%v\n", testcommit.Verify()) if !testcommit.Verify() { b.FailNow() } //get list listbytes, err := services.GetBlob(testcommit.ListHash) if err != nil { log.Panic(err) } testlist, err := objects.ListFromBytes(listbytes) //log.Printf("authentic list:%v\n", ) if !bytes.Equal(testcommit.ListHash, testlist.Hash()) { b.FailNow() } //get tag _, testTagHash := testlist.HashForNamesegment("testTag") testTag, err := services.GetTag(testTagHash.Bytes(), "testBlob") //log.Printf("authentic tag:%v\n", testTag.Verify()) if !testTag.Verify() { b.FailNow() } //get blob testBlob, err := services.GetBlob(testTag.HashBytes.(objects.HCID)) //log.Printf("authentic blob:%v\n", bytes.Equal(testTag.HashBytes, // testBlob.Hash())) if err != nil { b.Fatalf("Get Blob Error: %s\n", err) } if !bytes.Equal(testTag.HashBytes.(objects.HCID), testBlob.Hash()) { b.FailNow() } } }