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

Function TestAncestor

sqlchain/blockindex_test.go:95–126  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

93}
94
95func TestAncestor(t *testing.T) {
96 index := newBlockIndex()
97 parent := (*blockNode)(nil)
98
99 for h, b := range testBlocks {
100 bn := newBlockNode(int32(h), b, parent)
101 index.addBlock(bn)
102 parent = bn
103 }
104
105 for i, b := range testBlocks {
106 bn := index.lookupNode(b.BlockHash())
107
108 if bn == nil {
109 t.Fatalf("unexpected loopup result: %v", bn)
110 }
111
112 for j := int32(i - 1); j < int32(i+1); j++ {
113 a := bn.ancestor(j)
114
115 if j < 0 || j > bn.count {
116 if a != nil {
117 t.Fatalf("unexpected ancestor: %v", a)
118 }
119 } else {
120 if a.count != j {
121 t.Fatalf("unexpected ancestor height: got %d while expecting %d", a.count, j)
122 }
123 }
124 }
125 }
126}
127
128func TestIndex(t *testing.T) {
129 index := newBlockIndex()

Callers

nothing calls this directly

Calls 7

newBlockIndexFunction · 0.85
lookupNodeMethod · 0.80
FatalfMethod · 0.80
newBlockNodeFunction · 0.70
addBlockMethod · 0.45
BlockHashMethod · 0.45
ancestorMethod · 0.45

Tested by

no test coverage detected