diff options
-rw-r--r-- | common/types.go | 8 | ||||
-rw-r--r-- | core/blocklattice_test.go | 8 |
2 files changed, 14 insertions, 2 deletions
diff --git a/common/types.go b/common/types.go index 495b10d..0a78111 100644 --- a/common/types.go +++ b/common/types.go @@ -18,6 +18,7 @@ package common import ( + "bytes" "encoding/hex" ) @@ -50,3 +51,10 @@ func (h *Hash) UnmarshalText(text []byte) error { _, err := hex.Decode(h[:], text) return err } + +// Hashes is for sorting hashes. +type Hashes []Hash + +func (hs Hashes) Len() int { return len(hs) } +func (hs Hashes) Less(i, j int) bool { return bytes.Compare(hs[i][:], hs[j][:]) < 0 } +func (hs Hashes) Swap(i, j int) { hs[i], hs[j] = hs[j], hs[i] } diff --git a/core/blocklattice_test.go b/core/blocklattice_test.go index f43d645..be332db 100644 --- a/core/blocklattice_test.go +++ b/core/blocklattice_test.go @@ -18,6 +18,7 @@ package core import ( + "sort" "testing" "github.com/stretchr/testify/suite" @@ -480,8 +481,11 @@ func (s *BlockLatticeTest) TesttotalOrdering() { s.app.Clear() lattice.ProcessBlock(b13, true) s.Require().Equal(2, len(s.app.Outputs)) - s.Require().Equal(b21.Hash, s.app.Outputs[0].Hash) - s.Require().Equal(b11.Hash, s.app.Outputs[1].Hash) + expected := common.Hashes{b21.Hash, b11.Hash} + sort.Sort(expected) + got := common.Hashes{s.app.Outputs[0].Hash, s.app.Outputs[1].Hash} + sort.Sort(got) + s.Require().Equal(expected, got) s.Require().Equal(false, s.app.Early) s.Require().Equal(1, len(lattice.candidateSet)) |