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

Function TestIndexKey

sqlchain/chain_test.go:58–88  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

56}
57
58func TestIndexKey(t *testing.T) {
59 for i := 0; i < 10; i++ {
60 b1, err := createRandomBlock(genesisHash, false)
61
62 if err != nil {
63 t.Fatalf("error occurred: %v", err)
64 }
65
66 b2, err := createRandomBlock(genesisHash, false)
67
68 if err != nil {
69 t.Fatalf("error occurred: %v", err)
70 }
71
72 // Test partial order
73 bi1 := newBlockNode(rand.Int31(), b1, nil)
74 bi2 := newBlockNode(rand.Int31(), b2, nil)
75 k1 := bi1.indexKey()
76 k2 := bi2.indexKey()
77
78 if c1, c2 := bytes.Compare(k1, k2) < 0, bi1.height < bi2.height; c1 != c2 {
79 t.Fatalf("unexpected compare result: heights=%d,%d keys=%s,%s",
80 bi1.height, bi2.height, hex.EncodeToString(k1), hex.EncodeToString(k2))
81 }
82
83 if c1, c2 := bytes.Compare(k1, k2) > 0, bi1.height > bi2.height; c1 != c2 {
84 t.Fatalf("unexpected compare result: heights=%d,%d keys=%s,%s",
85 bi1.height, bi2.height, hex.EncodeToString(k1), hex.EncodeToString(k2))
86 }
87 }
88}
89
90func TestMultiChain(t *testing.T) {
91 //log.SetLevel(log.InfoLevel)

Callers

nothing calls this directly

Calls 4

createRandomBlockFunction · 0.85
FatalfMethod · 0.80
indexKeyMethod · 0.80
newBlockNodeFunction · 0.70

Tested by

no test coverage detected