File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -40,3 +40,12 @@ func (bi *BlockTreeEntry) Previous() *BlockTreeEntry {
4040 prevIndex := & BlockTreeEntry {ptr : ptr }
4141 return prevIndex
4242}
43+
44+ // Equals compares two block tree entries for equality.
45+ // Returns true if both entries point to the same block in the tree.
46+ func (bi * BlockTreeEntry ) Equals (other * BlockTreeEntry ) bool {
47+ if other == nil {
48+ return false
49+ }
50+ return C .btck_block_tree_entry_equals (bi .ptr , other .ptr ) != 0
51+ }
Original file line number Diff line number Diff line change @@ -36,3 +36,35 @@ func TestBlockTreeEntryGetPrevious(t *testing.T) {
3636 t .Error ("Genesis block should not have a previous block" )
3737 }
3838}
39+
40+ func TestBlockTreeEntryEquals (t * testing.T ) {
41+ suite := ChainstateManagerTestSuite {
42+ MaxBlockHeightToImport : 2 ,
43+ }
44+ suite .Setup (t )
45+
46+ chain := suite .Manager .GetActiveChain ()
47+
48+ // Same entry should equal itself
49+ entry1 := chain .GetByHeight (1 )
50+ if ! entry1 .Equals (entry1 ) {
51+ t .Error ("Entry should equal itself" )
52+ }
53+
54+ // Different retrievals of same height should be equal
55+ entry1Again := chain .GetByHeight (1 )
56+ if ! entry1 .Equals (entry1Again ) {
57+ t .Error ("Same height entries should be equal" )
58+ }
59+
60+ // Different heights should not be equal
61+ entry0 := chain .GetByHeight (0 )
62+ if entry1 .Equals (entry0 ) {
63+ t .Error ("Different height entries should not be equal" )
64+ }
65+
66+ // Nil comparison should return false
67+ if entry1 .Equals (nil ) {
68+ t .Error ("Entry should not equal nil" )
69+ }
70+ }
You can’t perform that action at this time.
0 commit comments