Skip to content

Commit 426f62f

Browse files
countvonzerofjl
authored andcommitted
core: improve test for TransactionPriceNonceSort (#16413)
1 parent 7677ec1 commit 426f62f

File tree

1 file changed

+7
-22
lines changed

1 file changed

+7
-22
lines changed

core/types/transaction_test.go

+7-22
Original file line numberDiff line numberDiff line change
@@ -165,28 +165,13 @@ func TestTransactionPriceNonceSort(t *testing.T) {
165165
t.Errorf("invalid nonce ordering: tx #%d (A=%x N=%v) < tx #%d (A=%x N=%v)", i, fromi[:4], txi.Nonce(), i+j, fromj[:4], txj.Nonce())
166166
}
167167
}
168-
// Find the previous and next nonce of this account
169-
prev, next := i-1, i+1
170-
for j := i - 1; j >= 0; j-- {
171-
if fromj, _ := Sender(signer, txs[j]); fromi == fromj {
172-
prev = j
173-
break
174-
}
175-
}
176-
for j := i + 1; j < len(txs); j++ {
177-
if fromj, _ := Sender(signer, txs[j]); fromi == fromj {
178-
next = j
179-
break
180-
}
181-
}
182-
// Make sure that in between the neighbor nonces, the transaction is correctly positioned price wise
183-
for j := prev + 1; j < next; j++ {
184-
fromj, _ := Sender(signer, txs[j])
185-
if j < i && txs[j].GasPrice().Cmp(txi.GasPrice()) < 0 {
186-
t.Errorf("invalid gasprice ordering: tx #%d (A=%x P=%v) < tx #%d (A=%x P=%v)", j, fromj[:4], txs[j].GasPrice(), i, fromi[:4], txi.GasPrice())
187-
}
188-
if j > i && txs[j].GasPrice().Cmp(txi.GasPrice()) > 0 {
189-
t.Errorf("invalid gasprice ordering: tx #%d (A=%x P=%v) > tx #%d (A=%x P=%v)", j, fromj[:4], txs[j].GasPrice(), i, fromi[:4], txi.GasPrice())
168+
169+
// If the next tx has different from account, the price must be lower than the current one
170+
if i+1 < len(txs) {
171+
next := txs[i+1]
172+
fromNext, _ := Sender(signer, next)
173+
if fromi != fromNext && txi.GasPrice().Cmp(next.GasPrice()) < 0 {
174+
t.Errorf("invalid gasprice ordering: tx #%d (A=%x P=%v) < tx #%d (A=%x P=%v)", i, fromi[:4], txi.GasPrice(), i+1, fromNext[:4], next.GasPrice())
190175
}
191176
}
192177
}

0 commit comments

Comments
 (0)