internal,tests: replace noarg fmt.Errorf with errors.New (#27335)

* internal: replace noarg fmt.Errorf with errors.New

Signed-off-by: jsvisa <delweng@gmail.com>

* tests: replace noarg fmt.Errorf with errors.New

Signed-off-by: jsvisa <delweng@gmail.com>

* tests: go autoimport

Signed-off-by: jsvisa <delweng@gmail.com>

* tests: go autoimport

Signed-off-by: jsvisa <delweng@gmail.com>

---------

Signed-off-by: jsvisa <delweng@gmail.com>
This commit is contained in:
Delweng 2023-05-25 14:54:28 +08:00 committed by GitHub
parent dd25a4f5ab
commit b21ba668e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 32 additions and 28 deletions

View File

@ -20,6 +20,7 @@ import (
"archive/tar" "archive/tar"
"archive/zip" "archive/zip"
"compress/gzip" "compress/gzip"
"errors"
"fmt" "fmt"
"io" "io"
"os" "os"
@ -90,7 +91,7 @@ func WriteArchive(name string, files []string) (err error) {
}() }()
archive, basename := NewArchive(archfd) archive, basename := NewArchive(archfd)
if archive == nil { if archive == nil {
return fmt.Errorf("unknown archive extension") return errors.New("unknown archive extension")
} }
fmt.Println(name) fmt.Println(name)
if err := archive.Directory(basename); err != nil { if err := archive.Directory(basename); err != nil {

View File

@ -478,16 +478,16 @@ func (s *PersonalAccountAPI) SignTransaction(ctx context.Context, args Transacti
// No need to obtain the noncelock mutex, since we won't be sending this // No need to obtain the noncelock mutex, since we won't be sending this
// tx into the transaction pool, but right back to the user // tx into the transaction pool, but right back to the user
if args.From == nil { if args.From == nil {
return nil, fmt.Errorf("sender not specified") return nil, errors.New("sender not specified")
} }
if args.Gas == nil { if args.Gas == nil {
return nil, fmt.Errorf("gas not specified") return nil, errors.New("gas not specified")
} }
if args.GasPrice == nil && (args.MaxFeePerGas == nil || args.MaxPriorityFeePerGas == nil) { if args.GasPrice == nil && (args.MaxFeePerGas == nil || args.MaxPriorityFeePerGas == nil) {
return nil, fmt.Errorf("missing gasPrice or maxFeePerGas/maxPriorityFeePerGas") return nil, errors.New("missing gasPrice or maxFeePerGas/maxPriorityFeePerGas")
} }
if args.Nonce == nil { if args.Nonce == nil {
return nil, fmt.Errorf("nonce not specified") return nil, errors.New("nonce not specified")
} }
// Before actually signing the transaction, ensure the transaction fee is reasonable. // Before actually signing the transaction, ensure the transaction fee is reasonable.
tx := args.toTransaction() tx := args.toTransaction()
@ -548,7 +548,7 @@ func (s *PersonalAccountAPI) EcRecover(ctx context.Context, data, sig hexutil.By
return common.Address{}, fmt.Errorf("signature must be %d bytes long", crypto.SignatureLength) return common.Address{}, fmt.Errorf("signature must be %d bytes long", crypto.SignatureLength)
} }
if sig[crypto.RecoveryIDOffset] != 27 && sig[crypto.RecoveryIDOffset] != 28 { if sig[crypto.RecoveryIDOffset] != 27 && sig[crypto.RecoveryIDOffset] != 28 {
return common.Address{}, fmt.Errorf("invalid Ethereum signature (V is not 27 or 28)") return common.Address{}, errors.New("invalid Ethereum signature (V is not 27 or 28)")
} }
sig[crypto.RecoveryIDOffset] -= 27 // Transform yellow paper V from 27/28 to 0/1 sig[crypto.RecoveryIDOffset] -= 27 // Transform yellow paper V from 27/28 to 0/1
@ -582,7 +582,7 @@ func (s *PersonalAccountAPI) InitializeWallet(ctx context.Context, url string) (
case *scwallet.Wallet: case *scwallet.Wallet:
return mnemonic, wallet.Initialize(seed) return mnemonic, wallet.Initialize(seed)
default: default:
return "", fmt.Errorf("specified wallet does not support initialization") return "", errors.New("specified wallet does not support initialization")
} }
} }
@ -597,7 +597,7 @@ func (s *PersonalAccountAPI) Unpair(ctx context.Context, url string, pin string)
case *scwallet.Wallet: case *scwallet.Wallet:
return wallet.Unpair([]byte(pin)) return wallet.Unpair([]byte(pin))
default: default:
return fmt.Errorf("specified wallet does not support pairing") return errors.New("specified wallet does not support pairing")
} }
} }
@ -722,10 +722,10 @@ func decodeHash(s string) (common.Hash, error) {
} }
b, err := hex.DecodeString(s) b, err := hex.DecodeString(s)
if err != nil { if err != nil {
return common.Hash{}, fmt.Errorf("hex string invalid") return common.Hash{}, errors.New("hex string invalid")
} }
if len(b) > 32 { if len(b) > 32 {
return common.Hash{}, fmt.Errorf("hex string too long, want at most 32 bytes") return common.Hash{}, errors.New("hex string too long, want at most 32 bytes")
} }
return common.BytesToHash(b), nil return common.BytesToHash(b), nil
} }
@ -1833,13 +1833,13 @@ type SignTransactionResult struct {
// the given from address and it needs to be unlocked. // the given from address and it needs to be unlocked.
func (s *TransactionAPI) SignTransaction(ctx context.Context, args TransactionArgs) (*SignTransactionResult, error) { func (s *TransactionAPI) SignTransaction(ctx context.Context, args TransactionArgs) (*SignTransactionResult, error) {
if args.Gas == nil { if args.Gas == nil {
return nil, fmt.Errorf("gas not specified") return nil, errors.New("gas not specified")
} }
if args.GasPrice == nil && (args.MaxPriorityFeePerGas == nil || args.MaxFeePerGas == nil) { if args.GasPrice == nil && (args.MaxPriorityFeePerGas == nil || args.MaxFeePerGas == nil) {
return nil, fmt.Errorf("missing gasPrice or maxFeePerGas/maxPriorityFeePerGas") return nil, errors.New("missing gasPrice or maxFeePerGas/maxPriorityFeePerGas")
} }
if args.Nonce == nil { if args.Nonce == nil {
return nil, fmt.Errorf("nonce not specified") return nil, errors.New("nonce not specified")
} }
if err := args.setDefaults(ctx, s.b); err != nil { if err := args.setDefaults(ctx, s.b); err != nil {
return nil, err return nil, err
@ -1888,7 +1888,7 @@ func (s *TransactionAPI) PendingTransactions() ([]*RPCTransaction, error) {
// the given transaction from the pool and reinsert it with the new gas price and limit. // the given transaction from the pool and reinsert it with the new gas price and limit.
func (s *TransactionAPI) Resend(ctx context.Context, sendArgs TransactionArgs, gasPrice *hexutil.Big, gasLimit *hexutil.Uint64) (common.Hash, error) { func (s *TransactionAPI) Resend(ctx context.Context, sendArgs TransactionArgs, gasPrice *hexutil.Big, gasLimit *hexutil.Uint64) (common.Hash, error) {
if sendArgs.Nonce == nil { if sendArgs.Nonce == nil {
return common.Hash{}, fmt.Errorf("missing transaction nonce in transaction spec") return common.Hash{}, errors.New("missing transaction nonce in transaction spec")
} }
if err := sendArgs.setDefaults(ctx, s.b); err != nil { if err := sendArgs.setDefaults(ctx, s.b); err != nil {
return common.Hash{}, err return common.Hash{}, err

View File

@ -157,7 +157,7 @@ func (args *TransactionArgs) setFeeDefaults(ctx context.Context, b Backend) erro
} }
} else { } else {
if args.MaxFeePerGas != nil || args.MaxPriorityFeePerGas != nil { if args.MaxFeePerGas != nil || args.MaxPriorityFeePerGas != nil {
return fmt.Errorf("maxFeePerGas and maxPriorityFeePerGas are not valid before London is active") return errors.New("maxFeePerGas and maxPriorityFeePerGas are not valid before London is active")
} }
// London not active, set gas price. // London not active, set gas price.
price, err := b.SuggestGasTipCap(ctx) price, err := b.SuggestGasTipCap(ctx)

View File

@ -18,7 +18,7 @@ package ethapi
import ( import (
"context" "context"
"fmt" "errors"
"math/big" "math/big"
"reflect" "reflect"
"testing" "testing"
@ -138,28 +138,28 @@ func TestSetFeeDefaults(t *testing.T) {
false, false,
&TransactionArgs{MaxFeePerGas: maxFee}, &TransactionArgs{MaxFeePerGas: maxFee},
nil, nil,
fmt.Errorf("maxFeePerGas and maxPriorityFeePerGas are not valid before London is active"), errors.New("maxFeePerGas and maxPriorityFeePerGas are not valid before London is active"),
}, },
{ {
"dynamic fee tx pre-London, priorityFee set", "dynamic fee tx pre-London, priorityFee set",
false, false,
&TransactionArgs{MaxPriorityFeePerGas: fortytwo}, &TransactionArgs{MaxPriorityFeePerGas: fortytwo},
nil, nil,
fmt.Errorf("maxFeePerGas and maxPriorityFeePerGas are not valid before London is active"), errors.New("maxFeePerGas and maxPriorityFeePerGas are not valid before London is active"),
}, },
{ {
"dynamic fee tx, maxFee < priorityFee", "dynamic fee tx, maxFee < priorityFee",
true, true,
&TransactionArgs{MaxFeePerGas: maxFee, MaxPriorityFeePerGas: (*hexutil.Big)(big.NewInt(1000))}, &TransactionArgs{MaxFeePerGas: maxFee, MaxPriorityFeePerGas: (*hexutil.Big)(big.NewInt(1000))},
nil, nil,
fmt.Errorf("maxFeePerGas (0x3e) < maxPriorityFeePerGas (0x3e8)"), errors.New("maxFeePerGas (0x3e) < maxPriorityFeePerGas (0x3e8)"),
}, },
{ {
"dynamic fee tx, maxFee < priorityFee while setting default", "dynamic fee tx, maxFee < priorityFee while setting default",
true, true,
&TransactionArgs{MaxFeePerGas: (*hexutil.Big)(big.NewInt(7))}, &TransactionArgs{MaxFeePerGas: (*hexutil.Big)(big.NewInt(7))},
nil, nil,
fmt.Errorf("maxFeePerGas (0x7) < maxPriorityFeePerGas (0x2a)"), errors.New("maxFeePerGas (0x7) < maxPriorityFeePerGas (0x2a)"),
}, },
// Misc // Misc
@ -168,21 +168,21 @@ func TestSetFeeDefaults(t *testing.T) {
false, false,
&TransactionArgs{GasPrice: fortytwo, MaxFeePerGas: maxFee, MaxPriorityFeePerGas: fortytwo}, &TransactionArgs{GasPrice: fortytwo, MaxFeePerGas: maxFee, MaxPriorityFeePerGas: fortytwo},
nil, nil,
fmt.Errorf("both gasPrice and (maxFeePerGas or maxPriorityFeePerGas) specified"), errors.New("both gasPrice and (maxFeePerGas or maxPriorityFeePerGas) specified"),
}, },
{ {
"set gas price and maxPriorityFee", "set gas price and maxPriorityFee",
false, false,
&TransactionArgs{GasPrice: fortytwo, MaxPriorityFeePerGas: fortytwo}, &TransactionArgs{GasPrice: fortytwo, MaxPriorityFeePerGas: fortytwo},
nil, nil,
fmt.Errorf("both gasPrice and (maxFeePerGas or maxPriorityFeePerGas) specified"), errors.New("both gasPrice and (maxFeePerGas or maxPriorityFeePerGas) specified"),
}, },
{ {
"set gas price and maxFee", "set gas price and maxFee",
true, true,
&TransactionArgs{GasPrice: fortytwo, MaxFeePerGas: maxFee}, &TransactionArgs{GasPrice: fortytwo, MaxFeePerGas: maxFee},
nil, nil,
fmt.Errorf("both gasPrice and (maxFeePerGas or maxPriorityFeePerGas) specified"), errors.New("both gasPrice and (maxFeePerGas or maxPriorityFeePerGas) specified"),
}, },
} }

View File

@ -19,6 +19,7 @@ package trie
import ( import (
"bytes" "bytes"
"encoding/binary" "encoding/binary"
"errors"
"fmt" "fmt"
"github.com/ethereum/go-ethereum/core/rawdb" "github.com/ethereum/go-ethereum/core/rawdb"
@ -183,7 +184,7 @@ func runRandTest(rt randTest) error {
checktr.MustUpdate(it.Key, it.Value) checktr.MustUpdate(it.Key, it.Value)
} }
if tr.Hash() != checktr.Hash() { if tr.Hash() != checktr.Hash() {
return fmt.Errorf("hash mismatch in opItercheckhash") return errors.New("hash mismatch in opItercheckhash")
} }
case opProve: case opProve:
rt[i].err = tr.Prove(step.key, 0, proofDb{}) rt[i].err = tr.Prove(step.key, 0, proofDb{})

View File

@ -18,6 +18,7 @@ package tests
import ( import (
"encoding/json" "encoding/json"
"errors"
"fmt" "fmt"
"io" "io"
"os" "os"
@ -180,7 +181,7 @@ func (tm *testMatcher) checkFailure(t *testing.T, err error) error {
t.Logf("error: %v", err) t.Logf("error: %v", err)
return nil return nil
} }
return fmt.Errorf("test succeeded unexpectedly") return errors.New("test succeeded unexpectedly")
} }
return err return err
} }

View File

@ -59,7 +59,7 @@ func FromHex(s string) ([]byte, error) {
func (t *RLPTest) Run() error { func (t *RLPTest) Run() error {
outb, err := FromHex(t.Out) outb, err := FromHex(t.Out)
if err != nil { if err != nil {
return fmt.Errorf("invalid hex in Out") return errors.New("invalid hex in Out")
} }
// Handle simple decoding tests with no actual In value. // Handle simple decoding tests with no actual In value.
@ -87,7 +87,7 @@ func checkDecodeInterface(b []byte, isValid bool) error {
case isValid && err != nil: case isValid && err != nil:
return fmt.Errorf("decoding failed: %v", err) return fmt.Errorf("decoding failed: %v", err)
case !isValid && err == nil: case !isValid && err == nil:
return fmt.Errorf("decoding of invalid value succeeded") return errors.New("decoding of invalid value succeeded")
} }
return nil return nil
} }

View File

@ -19,6 +19,7 @@ package tests
import ( import (
"encoding/hex" "encoding/hex"
"encoding/json" "encoding/json"
"errors"
"fmt" "fmt"
"math/big" "math/big"
"strconv" "strconv"
@ -395,7 +396,7 @@ func (tx *stTransaction) toMessage(ps stPostState, baseFee *big.Int) (*core.Mess
tx.MaxFeePerGas) tx.MaxFeePerGas)
} }
if gasPrice == nil { if gasPrice == nil {
return nil, fmt.Errorf("no gas price provided") return nil, errors.New("no gas price provided")
} }
msg := &core.Message{ msg := &core.Message{