mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 02:42:27 +00:00
refactor: use errors.Is to check for equality of errors
This commit is contained in:
parent
304879da20
commit
1267019bb0
29 changed files with 76 additions and 60 deletions
|
|
@ -17,6 +17,7 @@
|
|||
package keystore
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"math/rand"
|
||||
"os"
|
||||
"runtime"
|
||||
|
|
@ -127,7 +128,7 @@ func TestTimedUnlock(t *testing.T) {
|
|||
|
||||
// Signing without passphrase fails because account is locked
|
||||
_, err = ks.SignHash(accounts.Account{Address: a1.Address}, testSigData)
|
||||
if err != ErrLocked {
|
||||
if !errors.Is(err, ErrLocked) {
|
||||
t.Fatal("Signing should've failed with ErrLocked before unlocking, got ", err)
|
||||
}
|
||||
|
||||
|
|
@ -145,7 +146,7 @@ func TestTimedUnlock(t *testing.T) {
|
|||
// Signing fails again after automatic locking
|
||||
time.Sleep(250 * time.Millisecond)
|
||||
_, err = ks.SignHash(accounts.Account{Address: a1.Address}, testSigData)
|
||||
if err != ErrLocked {
|
||||
if !errors.Is(err, ErrLocked) {
|
||||
t.Fatal("Signing should've failed with ErrLocked timeout expired, got ", err)
|
||||
}
|
||||
}
|
||||
|
|
@ -185,7 +186,7 @@ func TestOverrideUnlock(t *testing.T) {
|
|||
// Signing fails again after automatic locking
|
||||
time.Sleep(250 * time.Millisecond)
|
||||
_, err = ks.SignHash(accounts.Account{Address: a1.Address}, testSigData)
|
||||
if err != ErrLocked {
|
||||
if !errors.Is(err, ErrLocked) {
|
||||
t.Fatal("Signing should've failed with ErrLocked timeout expired, got ", err)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ package keystore
|
|||
import (
|
||||
"crypto/rand"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
|
|
@ -90,7 +91,7 @@ func TestKeyStorePassphraseDecryptionFail(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err = ks.GetKey(k1.Address, account.URL.Path, "bar"); err != ErrDecrypt {
|
||||
if _, err = ks.GetKey(k1.Address, account.URL.Path, "bar"); !errors.Is(err, ErrDecrypt) {
|
||||
t.Fatalf("wrong error for invalid password\ngot %q\nwant %q", err, ErrDecrypt)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -141,7 +141,7 @@ func (w *ledgerDriver) Close() error {
|
|||
// Heartbeat implements usbwallet.driver, performing a sanity check against the
|
||||
// Ledger to see if it's still online.
|
||||
func (w *ledgerDriver) Heartbeat() error {
|
||||
if _, err := w.ledgerVersion(); err != nil && err != errLedgerInvalidVersionReply {
|
||||
if _, err := w.ledgerVersion(); err != nil && !errors.Is(err, errLedgerInvalidVersionReply) {
|
||||
w.failure = err
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ package bitutil
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"testing"
|
||||
|
|
@ -143,7 +144,7 @@ func TestCompression(t *testing.T) {
|
|||
t.Errorf("decoding mismatch for dense data: have %x, want %x, error %v", data, in, err)
|
||||
}
|
||||
// Check that decompressing a longer input than the target fails
|
||||
if _, err := DecompressBytes([]byte{0xc0, 0x01, 0x01}, 2); err != errExceededTarget {
|
||||
if _, err := DecompressBytes([]byte{0xc0, 0x01, 0x01}, 2); !errors.Is(err, errExceededTarget) {
|
||||
t.Errorf("decoding error mismatch for long data: have %v, want %v", err, errExceededTarget)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ package rawdb
|
|||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"os"
|
||||
|
|
@ -68,7 +69,7 @@ func TestFreezerBasics(t *testing.T) {
|
|||
}
|
||||
// Check that we cannot read too far
|
||||
_, err = f.Retrieve(uint64(255))
|
||||
if err != errOutOfBounds {
|
||||
if !errors.Is(err, errOutOfBounds) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -374,7 +374,7 @@ func checkAncientCount(t *testing.T, f *Freezer, kind string, n uint64) {
|
|||
}
|
||||
if _, err := f.Ancient(kind, index); err == nil {
|
||||
t.Errorf("Ancient(%q, %d) didn't return expected error", kind, index)
|
||||
} else if err != errOutOfBounds {
|
||||
} else if !errors.Is(err, errOutOfBounds) {
|
||||
t.Errorf("Ancient(%q, %d) returned unexpected error %q", kind, index, err)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ package snapshot
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"github.com/VictoriaMetrics/fastcache"
|
||||
|
|
@ -311,7 +312,7 @@ func TestDiskPartialMerge(t *testing.T) {
|
|||
assertAccount := func(account common.Hash, data []byte) {
|
||||
t.Helper()
|
||||
blob, err := base.AccountRLP(account)
|
||||
if bytes.Compare(account[:], genMarker) > 0 && err != ErrNotCoveredYet {
|
||||
if bytes.Compare(account[:], genMarker) > 0 && !errors.Is(err, ErrNotCoveredYet) {
|
||||
t.Fatalf("test %d: post-marker (%x) account access (%x) succeeded: %x", i, genMarker, account, blob)
|
||||
}
|
||||
if bytes.Compare(account[:], genMarker) <= 0 && !bytes.Equal(blob, data) {
|
||||
|
|
@ -327,7 +328,7 @@ func TestDiskPartialMerge(t *testing.T) {
|
|||
assertStorage := func(account common.Hash, slot common.Hash, data []byte) {
|
||||
t.Helper()
|
||||
blob, err := base.Storage(account, slot)
|
||||
if bytes.Compare(append(account[:], slot[:]...), genMarker) > 0 && err != ErrNotCoveredYet {
|
||||
if bytes.Compare(append(account[:], slot[:]...), genMarker) > 0 && !errors.Is(err, ErrNotCoveredYet) {
|
||||
t.Fatalf("test %d: post-marker (%x) storage access (%x:%x) succeeded: %x", i, genMarker, account, slot, blob)
|
||||
}
|
||||
if bytes.Compare(append(account[:], slot[:]...), genMarker) <= 0 && !bytes.Equal(blob, data) {
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ package snapshot
|
|||
import (
|
||||
crand "crypto/rand"
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"testing"
|
||||
|
|
@ -118,10 +119,10 @@ func TestDiskLayerExternalInvalidationFullFlatten(t *testing.T) {
|
|||
t.Fatalf("failed to merge diff layer onto disk: %v", err)
|
||||
}
|
||||
// Since the base layer was modified, ensure that data retrievals on the external reference fail
|
||||
if acc, err := ref.Account(common.HexToHash("0x01")); err != ErrSnapshotStale {
|
||||
if acc, err := ref.Account(common.HexToHash("0x01")); !errors.Is(err, ErrSnapshotStale) {
|
||||
t.Errorf("stale reference returned account: %#x (err: %v)", acc, err)
|
||||
}
|
||||
if slot, err := ref.Storage(common.HexToHash("0xa1"), common.HexToHash("0xb1")); err != ErrSnapshotStale {
|
||||
if slot, err := ref.Storage(common.HexToHash("0xa1"), common.HexToHash("0xb1")); !errors.Is(err, ErrSnapshotStale) {
|
||||
t.Errorf("stale reference returned storage slot: %#x (err: %v)", slot, err)
|
||||
}
|
||||
if n := len(snaps.layers); n != 1 {
|
||||
|
|
@ -168,10 +169,10 @@ func TestDiskLayerExternalInvalidationPartialFlatten(t *testing.T) {
|
|||
t.Fatalf("failed to merge accumulator onto disk: %v", err)
|
||||
}
|
||||
// Since the base layer was modified, ensure that data retrievals on the external reference fail
|
||||
if acc, err := ref.Account(common.HexToHash("0x01")); err != ErrSnapshotStale {
|
||||
if acc, err := ref.Account(common.HexToHash("0x01")); !errors.Is(err, ErrSnapshotStale) {
|
||||
t.Errorf("stale reference returned account: %#x (err: %v)", acc, err)
|
||||
}
|
||||
if slot, err := ref.Storage(common.HexToHash("0xa1"), common.HexToHash("0xb1")); err != ErrSnapshotStale {
|
||||
if slot, err := ref.Storage(common.HexToHash("0xa1"), common.HexToHash("0xb1")); !errors.Is(err, ErrSnapshotStale) {
|
||||
t.Errorf("stale reference returned storage slot: %#x (err: %v)", slot, err)
|
||||
}
|
||||
if n := len(snaps.layers); n != 2 {
|
||||
|
|
@ -230,10 +231,10 @@ func TestDiffLayerExternalInvalidationPartialFlatten(t *testing.T) {
|
|||
t.Fatalf("failed to flatten diff layer into accumulator: %v", err)
|
||||
}
|
||||
// Since the accumulator diff layer was modified, ensure that data retrievals on the external reference fail
|
||||
if acc, err := ref.Account(common.HexToHash("0x01")); err != ErrSnapshotStale {
|
||||
if acc, err := ref.Account(common.HexToHash("0x01")); !errors.Is(err, ErrSnapshotStale) {
|
||||
t.Errorf("stale reference returned account: %#x (err: %v)", acc, err)
|
||||
}
|
||||
if slot, err := ref.Storage(common.HexToHash("0xa1"), common.HexToHash("0xb1")); err != ErrSnapshotStale {
|
||||
if slot, err := ref.Storage(common.HexToHash("0xa1"), common.HexToHash("0xb1")); !errors.Is(err, ErrSnapshotStale) {
|
||||
t.Errorf("stale reference returned storage slot: %#x (err: %v)", slot, err)
|
||||
}
|
||||
if n := len(snaps.layers); n != 3 {
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ package types
|
|||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"math"
|
||||
"math/big"
|
||||
"reflect"
|
||||
|
|
@ -300,7 +301,7 @@ func TestDecodeEmptyTypedReceipt(t *testing.T) {
|
|||
input := []byte{0x80}
|
||||
var r Receipt
|
||||
err := rlp.DecodeBytes(input, &r)
|
||||
if err != errShortTypedReceipt {
|
||||
if !errors.Is(err, errShortTypedReceipt) {
|
||||
t.Fatal("wrong error:", err)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ func TestDecodeEmptyTypedTx(t *testing.T) {
|
|||
input := []byte{0x80}
|
||||
var tx Transaction
|
||||
err := rlp.DecodeBytes(input, &tx)
|
||||
if err != errShortTypedTx {
|
||||
if !errors.Is(err, errShortTypedTx) {
|
||||
t.Fatal("wrong error:", err)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -229,7 +229,7 @@ func (evm *EVM) Call(caller ContractRef, addr common.Address, input []byte, gas
|
|||
// when we're in homestead this also counts for code storage gas errors.
|
||||
if err != nil {
|
||||
evm.StateDB.RevertToSnapshot(snapshot)
|
||||
if err != ErrExecutionReverted {
|
||||
if !errors.Is(err, ErrExecutionReverted) {
|
||||
if evm.Config.Tracer != nil && evm.Config.Tracer.OnGasChange != nil {
|
||||
evm.Config.Tracer.OnGasChange(gas, 0, tracing.GasChangeCallFailedExecution)
|
||||
}
|
||||
|
|
@ -285,7 +285,7 @@ func (evm *EVM) CallCode(caller ContractRef, addr common.Address, input []byte,
|
|||
}
|
||||
if err != nil {
|
||||
evm.StateDB.RevertToSnapshot(snapshot)
|
||||
if err != ErrExecutionReverted {
|
||||
if !errors.Is(err, ErrExecutionReverted) {
|
||||
if evm.Config.Tracer != nil && evm.Config.Tracer.OnGasChange != nil {
|
||||
evm.Config.Tracer.OnGasChange(gas, 0, tracing.GasChangeCallFailedExecution)
|
||||
}
|
||||
|
|
@ -332,7 +332,7 @@ func (evm *EVM) DelegateCall(caller ContractRef, addr common.Address, input []by
|
|||
}
|
||||
if err != nil {
|
||||
evm.StateDB.RevertToSnapshot(snapshot)
|
||||
if err != ErrExecutionReverted {
|
||||
if !errors.Is(err, ErrExecutionReverted) {
|
||||
if evm.Config.Tracer != nil && evm.Config.Tracer.OnGasChange != nil {
|
||||
evm.Config.Tracer.OnGasChange(gas, 0, tracing.GasChangeCallFailedExecution)
|
||||
}
|
||||
|
|
@ -390,7 +390,7 @@ func (evm *EVM) StaticCall(caller ContractRef, addr common.Address, input []byte
|
|||
}
|
||||
if err != nil {
|
||||
evm.StateDB.RevertToSnapshot(snapshot)
|
||||
if err != ErrExecutionReverted {
|
||||
if !errors.Is(err, ErrExecutionReverted) {
|
||||
if evm.Config.Tracer != nil && evm.Config.Tracer.OnGasChange != nil {
|
||||
evm.Config.Tracer.OnGasChange(gas, 0, tracing.GasChangeCallFailedExecution)
|
||||
}
|
||||
|
|
@ -489,9 +489,9 @@ func (evm *EVM) create(caller ContractRef, codeAndHash *codeAndHash, gas uint64,
|
|||
// When an error was returned by the EVM or when setting the creation code
|
||||
// above we revert to the snapshot and consume any gas remaining. Additionally,
|
||||
// when we're in homestead this also counts for code storage gas errors.
|
||||
if err != nil && (evm.chainRules.IsHomestead || err != ErrCodeStoreOutOfGas) {
|
||||
if err != nil && (evm.chainRules.IsHomestead || !errors.Is(err, ErrCodeStoreOutOfGas)) {
|
||||
evm.StateDB.RevertToSnapshot(snapshot)
|
||||
if err != ErrExecutionReverted {
|
||||
if !errors.Is(err, ErrExecutionReverted) {
|
||||
contract.UseGas(contract.Gas, evm.Config.Tracer, tracing.GasChangeCallFailedExecution)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
package vm
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"math"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
|
|
@ -599,7 +600,7 @@ func opCreate(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]b
|
|||
// ignore this error and pretend the operation was successful.
|
||||
if interpreter.evm.chainRules.IsHomestead && suberr == ErrCodeStoreOutOfGas {
|
||||
stackvalue.Clear()
|
||||
} else if suberr != nil && suberr != ErrCodeStoreOutOfGas {
|
||||
} else if suberr != nil && !errors.Is(suberr, ErrCodeStoreOutOfGas) {
|
||||
stackvalue.Clear()
|
||||
} else {
|
||||
stackvalue.SetBytes(addr.Bytes())
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ import (
|
|||
"bytes"
|
||||
"crypto/ecdsa"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"math/big"
|
||||
"os"
|
||||
"reflect"
|
||||
|
|
@ -66,11 +67,11 @@ func BenchmarkSha3(b *testing.B) {
|
|||
|
||||
func TestUnmarshalPubkey(t *testing.T) {
|
||||
key, err := UnmarshalPubkey(nil)
|
||||
if err != errInvalidPubkey || key != nil {
|
||||
if !errors.Is(err, errInvalidPubkey) || key != nil {
|
||||
t.Fatalf("expected error, got %v, %v", err, key)
|
||||
}
|
||||
key, err = UnmarshalPubkey([]byte{1, 2, 3})
|
||||
if err != errInvalidPubkey || key != nil {
|
||||
if !errors.Is(err, errInvalidPubkey) || key != nil {
|
||||
t.Fatalf("expected error, got %v, %v", err, key)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -152,12 +152,12 @@ func TestTooBigSharedKey(t *testing.T) {
|
|||
}
|
||||
|
||||
_, err = prv1.GenerateShared(&prv2.PublicKey, 32, 32)
|
||||
if err != ErrSharedKeyTooBig {
|
||||
if !errors.Is(err, ErrSharedKeyTooBig) {
|
||||
t.Fatal("ecdh: shared key should be too large for curve")
|
||||
}
|
||||
|
||||
_, err = prv2.GenerateShared(&prv1.PublicKey, 32, 32)
|
||||
if err != ErrSharedKeyTooBig {
|
||||
if !errors.Is(err, ErrSharedKeyTooBig) {
|
||||
t.Fatal("ecdh: shared key should be too large for curve")
|
||||
}
|
||||
}
|
||||
|
|
@ -355,7 +355,7 @@ func TestBasicKeyValidation(t *testing.T) {
|
|||
for _, b := range badBytes {
|
||||
ct[0] = b
|
||||
_, err := prv.Decrypt(ct, nil, nil)
|
||||
if err != ErrInvalidPublicKey {
|
||||
if !errors.Is(err, ErrInvalidPublicKey) {
|
||||
t.Fatal("ecies: validated an invalid key")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ import (
|
|||
"crypto/ecdsa"
|
||||
"crypto/rand"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"io"
|
||||
"testing"
|
||||
)
|
||||
|
|
@ -91,7 +92,7 @@ func TestInvalidRecoveryID(t *testing.T) {
|
|||
sig, _ := Sign(msg, seckey)
|
||||
sig[64] = 99
|
||||
_, err := RecoverPubkey(msg, sig)
|
||||
if err != ErrInvalidRecoveryID {
|
||||
if !errors.Is(err, ErrInvalidRecoveryID) {
|
||||
t.Fatalf("got %q, want %q", err, ErrInvalidRecoveryID)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1547,7 +1547,7 @@ func (d *Downloader) processSnapSyncContent() error {
|
|||
}()
|
||||
|
||||
closeOnErr := func(s *stateSync) {
|
||||
if err := s.Wait(); err != nil && err != errCancelStateFetch && err != errCanceled && err != snap.ErrCancelled {
|
||||
if err := s.Wait(); err != nil && !errors.Is(err, errCancelStateFetch) && !errors.Is(err, errCanceled) && !errors.Is(err, snap.ErrCancelled) {
|
||||
d.queue.Close() // wake up Results
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
package downloader
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"math/big"
|
||||
"os"
|
||||
|
|
@ -614,7 +615,7 @@ func testBoundedForkedSync(t *testing.T, protocol uint, mode SyncMode) {
|
|||
assertOwnChain(t, tester, len(chainA.blocks))
|
||||
|
||||
// Synchronise with the second peer and ensure that the fork is rejected to being too old
|
||||
if err := tester.sync("rewriter", nil, mode); err != errInvalidAncestor {
|
||||
if err := tester.sync("rewriter", nil, mode); !errors.Is(err, errInvalidAncestor) {
|
||||
t.Fatalf("sync failure mismatch: have %v, want %v", err, errInvalidAncestor)
|
||||
}
|
||||
}
|
||||
|
|
@ -649,7 +650,7 @@ func testBoundedHeavyForkedSync(t *testing.T, protocol uint, mode SyncMode) {
|
|||
|
||||
tester.newPeer("heavy-rewriter", protocol, chainB.blocks[1:])
|
||||
// Synchronise with the second peer and ensure that the fork is rejected to being too old
|
||||
if err := tester.sync("heavy-rewriter", nil, mode); err != errInvalidAncestor {
|
||||
if err := tester.sync("heavy-rewriter", nil, mode); !errors.Is(err, errInvalidAncestor) {
|
||||
t.Fatalf("sync failure mismatch: have %v, want %v", err, errInvalidAncestor)
|
||||
}
|
||||
}
|
||||
|
|
@ -854,7 +855,7 @@ func testHighTDStarvationAttack(t *testing.T, protocol uint, mode SyncMode) {
|
|||
|
||||
chain := testChainBase.shorten(1)
|
||||
tester.newPeer("attack", protocol, chain.blocks[1:])
|
||||
if err := tester.sync("attack", big.NewInt(1000000), mode); err != errStallingPeer {
|
||||
if err := tester.sync("attack", big.NewInt(1000000), mode); !errors.Is(err, errStallingPeer) {
|
||||
t.Fatalf("synchronisation error mismatch: have %v, want %v", err, errStallingPeer)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -478,7 +478,7 @@ func TestInvalidGetRangeLogsRequest(t *testing.T) {
|
|||
api = NewFilterAPI(sys, false)
|
||||
)
|
||||
|
||||
if _, err := api.GetLogs(context.Background(), FilterCriteria{FromBlock: big.NewInt(2), ToBlock: big.NewInt(1)}); err != errInvalidBlockRange {
|
||||
if _, err := api.GetLogs(context.Background(), FilterCriteria{FromBlock: big.NewInt(2), ToBlock: big.NewInt(1)}); !errors.Is(err, errInvalidBlockRange) {
|
||||
t.Errorf("Expected Logs for invalid range return error, but got: %v", err)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
package event
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"math/rand"
|
||||
"sync"
|
||||
"testing"
|
||||
|
|
@ -59,7 +60,7 @@ func TestMuxErrorAfterStop(t *testing.T) {
|
|||
if _, isopen := <-sub.Chan(); isopen {
|
||||
t.Errorf("subscription channel was not closed")
|
||||
}
|
||||
if err := mux.Post(testEvent(0)); err != ErrMuxClosed {
|
||||
if err := mux.Post(testEvent(0)); !errors.Is(err, ErrMuxClosed) {
|
||||
t.Errorf("Post error mismatch, got: %s, expected: %s", err, ErrMuxClosed)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ loop:
|
|||
t.Fatalf("wrong int %d, want %d", got, want)
|
||||
}
|
||||
case err := <-sub.Err():
|
||||
if err != errInts {
|
||||
if !errors.Is(err, errInts) {
|
||||
t.Fatalf("wrong error: got %q, want %q", err, errInts)
|
||||
}
|
||||
if want != 2 {
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ func TestNodeCloseMultipleTimes(t *testing.T) {
|
|||
|
||||
// Ensure that a stopped node can be stopped again
|
||||
for i := 0; i < 3; i++ {
|
||||
if err := stack.Close(); err != ErrNodeStopped {
|
||||
if err := stack.Close(); !errors.Is(err, ErrNodeStopped) {
|
||||
t.Fatalf("iter %d: stop failure mismatch: have %v, want %v", i, err, ErrNodeStopped)
|
||||
}
|
||||
}
|
||||
|
|
@ -71,14 +71,14 @@ func TestNodeStartMultipleTimes(t *testing.T) {
|
|||
if err := stack.Start(); err != nil {
|
||||
t.Fatalf("failed to start node: %v", err)
|
||||
}
|
||||
if err := stack.Start(); err != ErrNodeRunning {
|
||||
if err := stack.Start(); !errors.Is(err, ErrNodeRunning) {
|
||||
t.Fatalf("start failure mismatch: have %v, want %v ", err, ErrNodeRunning)
|
||||
}
|
||||
// Ensure that a node can be stopped, but only once
|
||||
if err := stack.Close(); err != nil {
|
||||
t.Fatalf("failed to stop node: %v", err)
|
||||
}
|
||||
if err := stack.Close(); err != ErrNodeStopped {
|
||||
if err := stack.Close(); !errors.Is(err, ErrNodeStopped) {
|
||||
t.Fatalf("stop failure mismatch: have %v, want %v ", err, ErrNodeStopped)
|
||||
}
|
||||
}
|
||||
|
|
@ -100,7 +100,7 @@ func TestNodeUsedDataDir(t *testing.T) {
|
|||
|
||||
// Create a second node based on the same data directory and ensure failure
|
||||
_, err = New(&Config{DataDir: dir})
|
||||
if err != ErrDatadirUsed {
|
||||
if !errors.Is(err, ErrDatadirUsed) {
|
||||
t.Fatalf("duplicate datadir failure mismatch: have %v, want %v", err, ErrDatadirUsed)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -150,7 +150,7 @@ func TestUDPv4_pingTimeout(t *testing.T) {
|
|||
key := newkey()
|
||||
toaddr := &net.UDPAddr{IP: net.ParseIP("1.2.3.4"), Port: 2222}
|
||||
node := enode.NewV4(&key.PublicKey, toaddr.IP, 0, toaddr.Port)
|
||||
if _, err := test.udp.ping(node); err != errTimeout {
|
||||
if _, err := test.udp.ping(node); !errors.Is(err, errTimeout) {
|
||||
t.Error("expected timeout error, got", err)
|
||||
}
|
||||
}
|
||||
|
|
@ -210,7 +210,7 @@ func TestUDPv4_responseTimeouts(t *testing.T) {
|
|||
for i := 0; i < nReqs; i++ {
|
||||
select {
|
||||
case err := <-timeoutErr:
|
||||
if err != errTimeout {
|
||||
if !errors.Is(err, errTimeout) {
|
||||
t.Fatalf("got non-timeout error on timeoutErr %d: %v", i, err)
|
||||
}
|
||||
nTimeoutsRecv++
|
||||
|
|
@ -240,7 +240,7 @@ func TestUDPv4_findnodeTimeout(t *testing.T) {
|
|||
toid := enode.ID{1, 2, 3, 4}
|
||||
target := v4wire.Pubkey{4, 5, 6, 7}
|
||||
result, err := test.udp.findnode(toid, toaddr, target)
|
||||
if err != errTimeout {
|
||||
if !errors.Is(err, errTimeout) {
|
||||
t.Error("expected timeout error, got", err)
|
||||
}
|
||||
if len(result) > 0 {
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ import (
|
|||
"bytes"
|
||||
"crypto/ecdsa"
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"net"
|
||||
|
|
@ -239,7 +240,7 @@ func TestUDPv5_pingCall(t *testing.T) {
|
|||
done <- err
|
||||
}()
|
||||
test.waitPacketOut(func(p *v5wire.Ping, addr *net.UDPAddr, _ v5wire.Nonce) {})
|
||||
if err := <-done; err != errTimeout {
|
||||
if err := <-done; !errors.Is(err, errTimeout) {
|
||||
t.Fatalf("want errTimeout, got %q", err)
|
||||
}
|
||||
|
||||
|
|
@ -264,7 +265,7 @@ func TestUDPv5_pingCall(t *testing.T) {
|
|||
wrongAddr := &net.UDPAddr{IP: net.IP{33, 44, 55, 22}, Port: 10101}
|
||||
test.packetInFrom(test.remotekey, wrongAddr, &v5wire.Pong{ReqID: p.ReqID})
|
||||
})
|
||||
if err := <-done; err != errTimeout {
|
||||
if err := <-done; !errors.Is(err, errTimeout) {
|
||||
t.Fatalf("want errTimeout for reply from wrong IP, got %q", err)
|
||||
}
|
||||
}
|
||||
|
|
@ -377,7 +378,7 @@ func TestUDPv5_multipleHandshakeRounds(t *testing.T) {
|
|||
test.waitPacketOut(func(p *v5wire.Ping, addr *net.UDPAddr, nonce v5wire.Nonce) {
|
||||
test.packetIn(&v5wire.Whoareyou{Nonce: nonce})
|
||||
})
|
||||
if err := <-done; err != errTimeout {
|
||||
if err := <-done; !errors.Is(err, errTimeout) {
|
||||
t.Fatalf("unexpected ping error: %q", err)
|
||||
}
|
||||
}
|
||||
|
|
@ -486,7 +487,7 @@ func TestUDPv5_talkRequest(t *testing.T) {
|
|||
done <- err
|
||||
}()
|
||||
test.waitPacketOut(func(p *v5wire.TalkRequest, addr *net.UDPAddr, _ v5wire.Nonce) {})
|
||||
if err := <-done; err != errTimeout {
|
||||
if err := <-done; !errors.Is(err, errTimeout) {
|
||||
t.Fatalf("want errTimeout, got %q", err)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ package enr
|
|||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"testing"
|
||||
|
|
@ -149,7 +150,7 @@ func TestSortedGetAndSet(t *testing.T) {
|
|||
func TestDirty(t *testing.T) {
|
||||
var r Record
|
||||
|
||||
if _, err := rlp.EncodeToBytes(r); err != errEncodeUnsigned {
|
||||
if _, err := rlp.EncodeToBytes(r); !errors.Is(err, errEncodeUnsigned) {
|
||||
t.Errorf("expected errEncodeUnsigned, got %#v", err)
|
||||
}
|
||||
|
||||
|
|
@ -164,7 +165,7 @@ func TestDirty(t *testing.T) {
|
|||
if len(r.signature) != 0 {
|
||||
t.Error("signature still set after modification")
|
||||
}
|
||||
if _, err := rlp.EncodeToBytes(r); err != errEncodeUnsigned {
|
||||
if _, err := rlp.EncodeToBytes(r); !errors.Is(err, errEncodeUnsigned) {
|
||||
t.Errorf("expected errEncodeUnsigned, got %#v", err)
|
||||
}
|
||||
}
|
||||
|
|
@ -248,7 +249,7 @@ func TestRecordTooBig(t *testing.T) {
|
|||
|
||||
// set a big value for random key, expect error
|
||||
r.Set(WithEntry(key, randomString(SizeLimit)))
|
||||
if err := signTest([]byte{5}, &r); err != errTooBig {
|
||||
if err := signTest([]byte{5}, &r); !errors.Is(err, errTooBig) {
|
||||
t.Fatalf("expected to get errTooBig, got %#v", err)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ package p2p
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"runtime"
|
||||
|
|
@ -55,7 +56,7 @@ loop:
|
|||
go func() {
|
||||
if err := SendItems(rw1, 1); err == nil {
|
||||
t.Error("EncodeMsg returned nil error")
|
||||
} else if err != ErrPipeClosed {
|
||||
} else if !errors.Is(err, ErrPipeClosed) {
|
||||
t.Errorf("EncodeMsg returned wrong error: got %v, want %v", err, ErrPipeClosed)
|
||||
}
|
||||
close(done)
|
||||
|
|
|
|||
|
|
@ -138,7 +138,7 @@ func TestPeerProtoReadMsg(t *testing.T) {
|
|||
|
||||
select {
|
||||
case err := <-errc:
|
||||
if err != errProtocolReturned {
|
||||
if !errors.Is(err, errProtocolReturned) {
|
||||
t.Errorf("peer returned error: %v", err)
|
||||
}
|
||||
case <-time.After(2 * time.Second):
|
||||
|
|
|
|||
|
|
@ -331,16 +331,16 @@ func TestStreamReadBytes(t *testing.T) {
|
|||
func TestDecodeErrors(t *testing.T) {
|
||||
r := bytes.NewReader(nil)
|
||||
|
||||
if err := Decode(r, nil); err != errDecodeIntoNil {
|
||||
if err := Decode(r, nil); !errors.Is(err, errDecodeIntoNil) {
|
||||
t.Errorf("Decode(r, nil) error mismatch, got %q, want %q", err, errDecodeIntoNil)
|
||||
}
|
||||
|
||||
var nilptr *struct{}
|
||||
if err := Decode(r, nilptr); err != errDecodeIntoNil {
|
||||
if err := Decode(r, nilptr); !errors.Is(err, errDecodeIntoNil) {
|
||||
t.Errorf("Decode(r, nilptr) error mismatch, got %q, want %q", err, errDecodeIntoNil)
|
||||
}
|
||||
|
||||
if err := Decode(r, struct{}{}); err != errNoPointer {
|
||||
if err := Decode(r, struct{}{}); !errors.Is(err, errNoPointer) {
|
||||
t.Errorf("Decode(r, struct{}{}) error mismatch, got %q, want %q", err, errNoPointer)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -633,7 +633,7 @@ func TestClientNotificationStorm(t *testing.T) {
|
|||
t.Fatalf("(%d/%d) unexpected value %d", i, count, val)
|
||||
}
|
||||
case err := <-sub.Err():
|
||||
if wantError && err != ErrSubscriptionQueueOverflow {
|
||||
if wantError && !errors.Is(err, ErrSubscriptionQueueOverflow) {
|
||||
t.Fatalf("(%d/%d) got error %q, want %q", i, count, err, ErrSubscriptionQueueOverflow)
|
||||
} else if !wantError {
|
||||
t.Fatalf("(%d/%d) got unexpected error %q", i, count, err)
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ package rpc
|
|||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
|
|
@ -234,12 +235,12 @@ func TestNewContextWithHeaders(t *testing.T) {
|
|||
ctx3 := NewContextWithHeaders(ctx2, newHdr("key-2", "val-2"))
|
||||
|
||||
expectedHeaders = 3
|
||||
if err := client.CallContext(ctx3, nil, "test"); err != ErrNoResult {
|
||||
if err := client.CallContext(ctx3, nil, "test"); !errors.Is(err, ErrNoResult) {
|
||||
t.Error("call failed", err)
|
||||
}
|
||||
|
||||
expectedHeaders = 2
|
||||
if err := client.CallContext(ctx2, nil, "test"); err != ErrNoResult {
|
||||
if err := client.CallContext(ctx2, nil, "test"); !errors.Is(err, ErrNoResult) {
|
||||
t.Error("call failed:", err)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue