go-ethereum/core/txpool
Daniel Liu 835579e304
core/txpool: add validation and comprehensive tests for SetGasPrice (#1876)
This commit adds robust input validation to the SetGasPrice method and
implements comprehensive table-driven tests to ensure correct behavior.

Changes in core/txpool/txpool.go:
- Add nil gas price validation with graceful error handling
- Add validation to reject negative gas prices
- Add validation to reject gas prices exceeding 1000 GWei maximum
- Return detailed error messages for each validation failure
- Log warnings when invalid gas prices are rejected

Changes in eth/api_miner.go:
- Update MinerAPI.SetGasPrice to check error return from txPool.SetGasPrice
- Return false when validation fails (when SetGasPrice returns error)
- Return true when validation succeeds (when SetGasPrice returns nil)

New tests in core/txpool/txpool_test.go:
- Implement TestSetGasPrice using table-driven test pattern
- Test 4 invalid cases: nil, negative, exceed max+1, exceed 10000 GWei
- Test 7 valid cases: 0, 1 wei, 1 GWei, 100 GWei, 500 GWei, max-1, max
- Each test case includes expected error value for precise validation
- All 11 test cases verify both error returns and gas price state
- Tests use isolated pool instances to ensure independence
2025-12-23 15:40:24 +05:30
..
journal.go all: fix typos, close XFN-23 (#1725) 2025-11-14 20:02:34 +05:30
lending_pool.go core/txpool: remove unused function GetSender (#1886) 2025-12-23 11:56:34 +05:30
lending_pool_test.go all: fix whitespace error of golangci-lint, remove extra empty lines (#1676) 2025-11-17 11:16:09 +05:30
lending_tx_journal.go all: fix typos, close XFN-23 (#1725) 2025-11-14 20:02:34 +05:30
lending_tx_list.go core/txpool: remove a redundant heap.Init #28910 (#1706) 2025-12-07 15:47:20 +05:30
list.go core/txpool: disallow future churn by remote txs #26907 (#1860) 2025-12-16 11:05:39 +04:00
list_test.go core/txpool: remove a redundant heap.Init #28910 (#1706) 2025-12-07 15:47:20 +05:30
noncer.go all: refactor txpool into it's own package in prep for 4844 (#26038) 2024-11-01 11:36:53 +08:00
order_pool.go core/txpool: remove unused function GetSender (#1886) 2025-12-23 11:56:34 +05:30
order_tx_journal.go all: fix typos, close XFN-23 (#1725) 2025-11-14 20:02:34 +05:30
order_tx_list.go core/txpool: remove a redundant heap.Init #28910 (#1706) 2025-12-07 15:47:20 +05:30
txpool.go core/txpool: add validation and comprehensive tests for SetGasPrice (#1876) 2025-12-23 15:40:24 +05:30
txpool2_test.go core/txpool: disallow future churn by remote txs #26907 (#1860) 2025-12-16 11:05:39 +04:00
txpool_test.go core/txpool: add validation and comprehensive tests for SetGasPrice (#1876) 2025-12-23 15:40:24 +05:30