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>
pull/27445/head
Delweng 1 year ago committed by GitHub
parent dd25a4f5ab
commit b21ba668e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      internal/build/archive.go
  2. 26
      internal/ethapi/api.go
  3. 2
      internal/ethapi/transaction_args.go
  4. 16
      internal/ethapi/transaction_args_test.go
  5. 3
      tests/fuzzers/trie/trie-fuzzer.go
  6. 3
      tests/init_test.go
  7. 4
      tests/rlp_test_util.go
  8. 3
      tests/state_test_util.go

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

@ -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
// tx into the transaction pool, but right back to the user
if args.From == nil {
return nil, fmt.Errorf("sender not specified")
return nil, errors.New("sender not specified")
}
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) {
return nil, fmt.Errorf("missing gasPrice or maxFeePerGas/maxPriorityFeePerGas")
return nil, errors.New("missing gasPrice or maxFeePerGas/maxPriorityFeePerGas")
}
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.
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)
}
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
@ -582,7 +582,7 @@ func (s *PersonalAccountAPI) InitializeWallet(ctx context.Context, url string) (
case *scwallet.Wallet:
return mnemonic, wallet.Initialize(seed)
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:
return wallet.Unpair([]byte(pin))
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)
if err != nil {
return common.Hash{}, fmt.Errorf("hex string invalid")
return common.Hash{}, errors.New("hex string invalid")
}
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
}
@ -1833,13 +1833,13 @@ type SignTransactionResult struct {
// the given from address and it needs to be unlocked.
func (s *TransactionAPI) SignTransaction(ctx context.Context, args TransactionArgs) (*SignTransactionResult, error) {
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) {
return nil, fmt.Errorf("missing gasPrice or maxFeePerGas/maxPriorityFeePerGas")
return nil, errors.New("missing gasPrice or maxFeePerGas/maxPriorityFeePerGas")
}
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 {
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.
func (s *TransactionAPI) Resend(ctx context.Context, sendArgs TransactionArgs, gasPrice *hexutil.Big, gasLimit *hexutil.Uint64) (common.Hash, error) {
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 {
return common.Hash{}, err

@ -157,7 +157,7 @@ func (args *TransactionArgs) setFeeDefaults(ctx context.Context, b Backend) erro
}
} else {
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.
price, err := b.SuggestGasTipCap(ctx)

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

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

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

@ -59,7 +59,7 @@ func FromHex(s string) ([]byte, error) {
func (t *RLPTest) Run() error {
outb, err := FromHex(t.Out)
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.
@ -87,7 +87,7 @@ func checkDecodeInterface(b []byte, isValid bool) error {
case isValid && err != nil:
return fmt.Errorf("decoding failed: %v", err)
case !isValid && err == nil:
return fmt.Errorf("decoding of invalid value succeeded")
return errors.New("decoding of invalid value succeeded")
}
return nil
}

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

Loading…
Cancel
Save