package utxostore import ( "testing" "git.smesh.lol/btcd-lite/internal/utxo" "git.smesh.lol/btcd-lite/internal/wire" ) // TestComparisonIsOneOrder: every pair of outpoints in the base and the // creations of the node fixture orders the same way under the merge's // comparison and the set's. // // The merge's comparison used to or a hash comparison with an index // comparison, and -1 or -1 is -1, so two outpoints differing in both could // order one way there and the other way in the set. 26 of 225 pairs disagreed // over the node's own base; 0 do now. func TestComparisonIsOneOrder(t *testing.T) { base := nodeEntriesAt4(t) ts, _ := nodeSecondRange(t, base) var ops []wire.OutPoint for _, e := range base { ops = append(ops, e.OutPoint) } for _, tc := range ts { ops = append(ops, tc.OutPoint) } sign := func(x int) int { switch { case x < 0: return -1 case x > 0: return 1 } return 0 } for i := range ops { for j := range ops { byMerge := sign(cmpOp(ops[i], ops[j])) bySet := sign(utxo.CompareOutPoints(ops[i], ops[j])) byLess := 0 if utxo.LessEntry(utxo.Entry{OutPoint: ops[i]}, utxo.Entry{OutPoint: ops[j]}) { byLess = -1 } else if utxo.LessEntry(utxo.Entry{OutPoint: ops[j]}, utxo.Entry{OutPoint: ops[i]}) { byLess = 1 } if byMerge != bySet || bySet != byLess { t.Fatalf("%x:%d vs %x:%d: merge %d, set %d, less %d", ops[i].Hash[:2], ops[i].Index, ops[j].Hash[:2], ops[j].Index, byMerge, bySet, byLess) } } } t.Logf("%d outpoints, %d pairs, one order", len(ops), len(ops)*len(ops)) }