|
17 | 17 | package txpool
|
18 | 18 |
|
19 | 19 | import (
|
| 20 | + "container/heap" |
20 | 21 | "math/rand"
|
21 | 22 | "testing"
|
22 | 23 |
|
@@ -48,6 +49,7 @@ func initLists() (heads TipList, tails map[common.Address][]*LazyTransaction) {
|
48 | 49 | heads = append(heads, &TxTips{
|
49 | 50 | From: addr,
|
50 | 51 | Tips: lazyTx.Fees,
|
| 52 | + Time: 0, |
51 | 53 | })
|
52 | 54 | }
|
53 | 55 | tail = append(tail, lazyTx)
|
@@ -126,17 +128,24 @@ func TestPendingSortAndPop(t *testing.T) {
|
126 | 128 | // Tests that if multiple transactions have the same price, the ones seen earlier
|
127 | 129 | // are prioritized to avoid network spam attacks aiming for a specific ordering.
|
128 | 130 | func TestSortingByTime(t *testing.T) {
|
129 |
| - t.Skip("The TipList does not take time into account. Should it? ") |
130 |
| - //var heads TipList |
131 |
| - //for i := 0; i < 25; i++ { |
132 |
| - // addr := common.Address{byte(i)} |
133 |
| - // heads = append(heads, &TxTips{ |
134 |
| - // From: addr, |
135 |
| - // Tips: uint256.NewInt(uint64(100)), |
136 |
| - // }) |
137 |
| - //} |
138 |
| - //// un-sort the heads |
139 |
| - //rand.Shuffle(len(heads), func(i, j int) { |
140 |
| - // heads[i], heads[j] = heads[j], heads[i] |
141 |
| - //}) |
| 131 | + var heads TipList |
| 132 | + for i := 0; i < 25; i++ { |
| 133 | + addr := common.Address{byte(i)} |
| 134 | + heads = append(heads, &TxTips{ |
| 135 | + From: addr, |
| 136 | + Tips: *(uint256.NewInt(uint64(100))), |
| 137 | + Time: int64(i), |
| 138 | + }) |
| 139 | + } |
| 140 | + // un-sort the heads |
| 141 | + rand.Shuffle(len(heads), func(i, j int) { |
| 142 | + heads[i], heads[j] = heads[j], heads[i] |
| 143 | + }) |
| 144 | + heap.Init(&heads) |
| 145 | + for want := int64(0); want < 25; want++ { |
| 146 | + obj := heap.Pop(&heads).(*TxTips) |
| 147 | + if have := obj.Time; have != want { |
| 148 | + t.Fatalf("have %d want %d", have, want) |
| 149 | + } |
| 150 | + } |
142 | 151 | }
|
0 commit comments