aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkimmylin <30611210+kimmylin@users.noreply.github.com>2018-05-29 20:21:04 +0800
committerFelix Lange <fjl@users.noreply.github.com>2018-05-29 20:21:04 +0800
commit426f62f1a8f25c10dbf17efe99242b4e1a44b83c (patch)
treef5a12467cef1b078b3511ee793ceb61e07469ec2
parent7677ec1f3414c1e3712bf33598f8780c3b76742b (diff)
downloaddexon-426f62f1a8f25c10dbf17efe99242b4e1a44b83c.tar.gz
dexon-426f62f1a8f25c10dbf17efe99242b4e1a44b83c.tar.zst
dexon-426f62f1a8f25c10dbf17efe99242b4e1a44b83c.zip
core: improve test for TransactionPriceNonceSort (#16413)
-rw-r--r--core/types/transaction_test.go29
1 files changed, 7 insertions, 22 deletions
diff --git a/core/types/transaction_test.go b/core/types/transaction_test.go
index d1861b14c..b390f45c6 100644
--- a/core/types/transaction_test.go
+++ b/core/types/transaction_test.go
@@ -165,28 +165,13 @@ func TestTransactionPriceNonceSort(t *testing.T) {
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())
}
}
- // Find the previous and next nonce of this account
- prev, next := i-1, i+1
- for j := i - 1; j >= 0; j-- {
- if fromj, _ := Sender(signer, txs[j]); fromi == fromj {
- prev = j
- break
- }
- }
- for j := i + 1; j < len(txs); j++ {
- if fromj, _ := Sender(signer, txs[j]); fromi == fromj {
- next = j
- break
- }
- }
- // Make sure that in between the neighbor nonces, the transaction is correctly positioned price wise
- for j := prev + 1; j < next; j++ {
- fromj, _ := Sender(signer, txs[j])
- if j < i && txs[j].GasPrice().Cmp(txi.GasPrice()) < 0 {
- 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())
- }
- if j > i && txs[j].GasPrice().Cmp(txi.GasPrice()) > 0 {
- 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())
+
+ // If the next tx has different from account, the price must be lower than the current one
+ if i+1 < len(txs) {
+ next := txs[i+1]
+ fromNext, _ := Sender(signer, next)
+ if fromi != fromNext && txi.GasPrice().Cmp(next.GasPrice()) < 0 {
+ 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())
}
}
}