mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-10-13 16:49:24 +00:00
[DEV-226] Fix sorting of hashes in blockset.hashes() (#98)
* [DEV-226] Fix sorting of hashes in blockset.hashes() * [DEV-226] add TestHashes
This commit is contained in:
parent
3deaea6c15
commit
201d7e0207
@ -130,7 +130,7 @@ func (bs blockSet) hashes() []daghash.Hash {
|
||||
hashes = append(hashes, hash)
|
||||
}
|
||||
sort.Slice(hashes, func(i, j int) bool {
|
||||
return daghash.Less(&hashes[j], &hashes[i])
|
||||
return daghash.Less(&hashes[i], &hashes[j])
|
||||
})
|
||||
return hashes
|
||||
}
|
||||
|
35
blockdag/blockset_test.go
Normal file
35
blockdag/blockset_test.go
Normal file
@ -0,0 +1,35 @@
|
||||
package blockdag
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/daglabs/btcd/dagconfig/daghash"
|
||||
)
|
||||
|
||||
func TestHashes(t *testing.T) {
|
||||
bs := setFromSlice(
|
||||
&blockNode{
|
||||
hash: daghash.Hash{3},
|
||||
},
|
||||
&blockNode{
|
||||
hash: daghash.Hash{1},
|
||||
},
|
||||
&blockNode{
|
||||
hash: daghash.Hash{0},
|
||||
},
|
||||
&blockNode{
|
||||
hash: daghash.Hash{2},
|
||||
},
|
||||
)
|
||||
|
||||
expected := []daghash.Hash{
|
||||
daghash.Hash{0},
|
||||
daghash.Hash{1},
|
||||
daghash.Hash{2},
|
||||
daghash.Hash{3},
|
||||
}
|
||||
|
||||
if !daghash.AreEqual(bs.hashes(), expected) {
|
||||
t.Errorf("TestHashes: hashes are not ordered as expected")
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user