MCPcopy Index your code
hub / github.com/CovenantSQL/CovenantSQL / TestGetNextPuzzle

Function TestGetNextPuzzle

sqlchain/storageproof_test.go:51–80  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

49}
50
51func TestGetNextPuzzle(t *testing.T) {
52 var totalRecordsInSQLChain int32 = 10
53 index, err := getNextPuzzle(answers, previousBlock)
54 if err != nil {
55 t.Error(err)
56 }
57 var wantedIndex int32
58 for _, answer := range answers {
59 wantedIndex += int32(hash.FNVHash32uint(answer.Answer[:]))
60 }
61 wantedIndex += int32(hash.FNVHash32uint([]byte(previousBlock.ID)))
62 wantedIndex %= totalRecordsInSQLChain
63 if index != wantedIndex {
64 t.Errorf("the next sql index is %+v, should be %+v. "+
65 "Answers are %+v, and the previous block is %+v",
66 index, wantedIndex, answers, previousBlock)
67 }
68
69 // void answer
70 index, err = getNextPuzzle(voidAnswer, previousBlock)
71 if err == nil {
72 t.Errorf("index is %d, but should be failed", index)
73 }
74
75 // void block
76 index, err = getNextPuzzle(answers, voidBlock)
77 if err == nil {
78 t.Errorf("index is %d, but should be failed", index)
79 }
80}
81
82func TestGetNextVerifier(t *testing.T) {
83 verifier, err := getNextVerifier(previousBlock, currentBlock)

Callers

nothing calls this directly

Calls 4

FNVHash32uintFunction · 0.92
getNextPuzzleFunction · 0.85
ErrorMethod · 0.80
ErrorfMethod · 0.80

Tested by

no test coverage detected