mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
comparing it with '==' (as in err == xxxErr) is no longer the best practice with Go 1.13 (Q3 2019)
This commit is contained in:
parent
d8e0807da2
commit
e91824491e
70 changed files with 212 additions and 164 deletions
|
|
@ -87,7 +87,7 @@ func TestWaitDeployed(t *testing.T) {
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case <-mined:
|
case <-mined:
|
||||||
if err != test.wantErr {
|
if !errors.Is(err, test.wantErr) {
|
||||||
t.Errorf("test %q: error mismatch: want %q, got %q", name, test.wantErr, err)
|
t.Errorf("test %q: error mismatch: want %q, got %q", name, test.wantErr, err)
|
||||||
}
|
}
|
||||||
if address != test.wantAddress {
|
if address != test.wantAddress {
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/pkg/errors"
|
||||||
"math"
|
"math"
|
||||||
"math/big"
|
"math/big"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
@ -1106,7 +1107,7 @@ func TestPackAndUnpackIncompatibleNumber(t *testing.T) {
|
||||||
{Type: ty},
|
{Type: ty},
|
||||||
}
|
}
|
||||||
decoded, err := decodeABI.Unpack(packed)
|
decoded, err := decodeABI.Unpack(packed)
|
||||||
if err != testCase.err {
|
if !errors.Is(err, testCase.err) {
|
||||||
t.Fatalf("Expected error %v, actual error %v. case %d", testCase.err, err, i)
|
t.Fatalf("Expected error %v, actual error %v. case %d", testCase.err, err, i)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,8 @@
|
||||||
package keystore
|
package keystore
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
|
"github.com/pkg/errors"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
@ -127,7 +129,7 @@ func TestTimedUnlock(t *testing.T) {
|
||||||
|
|
||||||
// Signing without passphrase fails because account is locked
|
// Signing without passphrase fails because account is locked
|
||||||
_, err = ks.SignHash(accounts.Account{Address: a1.Address}, testSigData)
|
_, 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)
|
t.Fatal("Signing should've failed with ErrLocked before unlocking, got ", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -145,7 +147,7 @@ func TestTimedUnlock(t *testing.T) {
|
||||||
// Signing fails again after automatic locking
|
// Signing fails again after automatic locking
|
||||||
time.Sleep(250 * time.Millisecond)
|
time.Sleep(250 * time.Millisecond)
|
||||||
_, err = ks.SignHash(accounts.Account{Address: a1.Address}, testSigData)
|
_, 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)
|
t.Fatal("Signing should've failed with ErrLocked timeout expired, got ", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -185,7 +187,7 @@ func TestOverrideUnlock(t *testing.T) {
|
||||||
// Signing fails again after automatic locking
|
// Signing fails again after automatic locking
|
||||||
time.Sleep(250 * time.Millisecond)
|
time.Sleep(250 * time.Millisecond)
|
||||||
_, err = ks.SignHash(accounts.Account{Address: a1.Address}, testSigData)
|
_, 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)
|
t.Fatal("Signing should've failed with ErrLocked timeout expired, got ", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -206,7 +208,7 @@ func TestSignRace(t *testing.T) {
|
||||||
}
|
}
|
||||||
end := time.Now().Add(500 * time.Millisecond)
|
end := time.Now().Add(500 * time.Millisecond)
|
||||||
for time.Now().Before(end) {
|
for time.Now().Before(end) {
|
||||||
if _, err := ks.SignHash(accounts.Account{Address: a1.Address}, testSigData); err == ErrLocked {
|
if _, err := ks.SignHash(accounts.Account{Address: a1.Address}, testSigData); errors.Is(err, ErrLocked) {
|
||||||
return
|
return
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
t.Errorf("Sign error: %v", err)
|
t.Errorf("Sign error: %v", err)
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ import (
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/pkg/errors"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
@ -90,7 +91,7 @@ func TestKeyStorePassphraseDecryptionFail(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
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)
|
t.Fatalf("wrong error for invalid password\ngot %q\nwant %q", err, ErrDecrypt)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -119,7 +119,7 @@ func (w *ledgerDriver) Open(device io.ReadWriter, passphrase string) error {
|
||||||
_, err := w.ledgerDerive(accounts.DefaultBaseDerivationPath)
|
_, err := w.ledgerDerive(accounts.DefaultBaseDerivationPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Ethereum app is not running or in browser mode, nothing more to do, return
|
// Ethereum app is not running or in browser mode, nothing more to do, return
|
||||||
if err == errLedgerReplyInvalidHeader {
|
if errors.Is(err, errLedgerReplyInvalidHeader) {
|
||||||
w.browser = true
|
w.browser = true
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
@ -141,7 +141,7 @@ func (w *ledgerDriver) Close() error {
|
||||||
// Heartbeat implements usbwallet.driver, performing a sanity check against the
|
// Heartbeat implements usbwallet.driver, performing a sanity check against the
|
||||||
// Ledger to see if it's still online.
|
// Ledger to see if it's still online.
|
||||||
func (w *ledgerDriver) Heartbeat() error {
|
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
|
w.failure = err
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,8 @@ package light
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
|
"errors"
|
||||||
|
"github.com/pkg/errors"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
|
@ -259,13 +261,13 @@ func (c *committeeChainTest) setClockPeriod(period float64) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *committeeChainTest) addFixedCommitteeRoot(tc *testCommitteeChain, period uint64, expErr error) {
|
func (c *committeeChainTest) addFixedCommitteeRoot(tc *testCommitteeChain, period uint64, expErr error) {
|
||||||
if err := c.chain.addFixedCommitteeRoot(period, tc.periods[period].committee.Root()); err != expErr {
|
if err := c.chain.addFixedCommitteeRoot(period, tc.periods[period].committee.Root()); !errors.Is(err, expErr) {
|
||||||
c.t.Errorf("Incorrect error output from addFixedCommitteeRoot at period %d (expected %v, got %v)", period, expErr, err)
|
c.t.Errorf("Incorrect error output from addFixedCommitteeRoot at period %d (expected %v, got %v)", period, expErr, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *committeeChainTest) addCommittee(tc *testCommitteeChain, period uint64, expErr error) {
|
func (c *committeeChainTest) addCommittee(tc *testCommitteeChain, period uint64, expErr error) {
|
||||||
if err := c.chain.addCommittee(period, tc.periods[period].committee); err != expErr {
|
if err := c.chain.addCommittee(period, tc.periods[period].committee); !errors.Is(err, expErr) {
|
||||||
c.t.Errorf("Incorrect error output from addCommittee at period %d (expected %v, got %v)", period, expErr, err)
|
c.t.Errorf("Incorrect error output from addCommittee at period %d (expected %v, got %v)", period, expErr, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -275,7 +277,7 @@ func (c *committeeChainTest) insertUpdate(tc *testCommitteeChain, period uint64,
|
||||||
if addCommittee {
|
if addCommittee {
|
||||||
committee = tc.periods[period+1].committee
|
committee = tc.periods[period+1].committee
|
||||||
}
|
}
|
||||||
if err := c.chain.InsertUpdate(tc.periods[period].update, committee); err != expErr {
|
if err := c.chain.InsertUpdate(tc.periods[period].update, committee); !errors.Is(err, expErr) {
|
||||||
c.t.Errorf("Incorrect error output from InsertUpdate at period %d (expected %v, got %v)", period, expErr, err)
|
c.t.Errorf("Incorrect error output from InsertUpdate at period %d (expected %v, got %v)", period, expErr, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -923,13 +923,13 @@ func testExternalUI(api *core.SignerAPI) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
expectApprove := func(testcase string, err error) {
|
expectApprove := func(testcase string, err error) {
|
||||||
if err == nil || err == accounts.ErrUnknownAccount {
|
if err == nil || errors.Is(err, accounts.ErrUnknownAccount) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
addErr(fmt.Sprintf("%v: expected no error, got %v", testcase, err.Error()))
|
addErr(fmt.Sprintf("%v: expected no error, got %v", testcase, err.Error()))
|
||||||
}
|
}
|
||||||
expectDeny := func(testcase string, err error) {
|
expectDeny := func(testcase string, err error) {
|
||||||
if err == nil || err != core.ErrRequestDenied {
|
if err == nil || !errors.Is(err, core.ErrRequestDenied) {
|
||||||
addErr(fmt.Sprintf("%v: expected ErrRequestDenied, got %v", testcase, err))
|
addErr(fmt.Sprintf("%v: expected ErrRequestDenied, got %v", testcase, err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ package v5test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"github.com/pkg/errors"
|
||||||
"net"
|
"net"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
@ -95,7 +96,7 @@ func (s *Suite) TestPingLargeRequestID(t *utesting.T) {
|
||||||
case *v5wire.Pong:
|
case *v5wire.Pong:
|
||||||
t.Errorf("PONG response with unknown request ID %x", resp.ReqID)
|
t.Errorf("PONG response with unknown request ID %x", resp.ReqID)
|
||||||
case *readError:
|
case *readError:
|
||||||
if resp.err == v5wire.ErrInvalidReqID {
|
if errors.Is(resp.err, v5wire.ErrInvalidReqID) {
|
||||||
t.Error("response with oversized request ID")
|
t.Error("response with oversized request ID")
|
||||||
} else if !netutil.IsTimeout(resp.err) {
|
} else if !netutil.IsTimeout(resp.err) {
|
||||||
t.Error(resp)
|
t.Error(resp)
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/pkg/errors"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/accounts"
|
"github.com/ethereum/go-ethereum/accounts"
|
||||||
|
|
@ -237,7 +238,7 @@ func unlockAccount(ks *keystore.KeyStore, address string, i int, passwords []str
|
||||||
log.Info("Unlocked account", "address", account.Address.Hex())
|
log.Info("Unlocked account", "address", account.Address.Hex())
|
||||||
return ambiguousAddrRecovery(ks, err, password), password
|
return ambiguousAddrRecovery(ks, err, password), password
|
||||||
}
|
}
|
||||||
if err != keystore.ErrDecrypt {
|
if !errors.Is(err, keystore.ErrDecrypt) {
|
||||||
// No need to prompt again if the error is not decryption-related.
|
// No need to prompt again if the error is not decryption-related.
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ import (
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/pkg/errors"
|
||||||
"io"
|
"io"
|
||||||
"math"
|
"math"
|
||||||
"os"
|
"os"
|
||||||
|
|
@ -149,7 +150,7 @@ func dump(in *inStream, s *rlp.Stream, depth int, out io.Writer) error {
|
||||||
if i > 0 {
|
if i > 0 {
|
||||||
fmt.Fprint(out, ",\n")
|
fmt.Fprint(out, ",\n")
|
||||||
}
|
}
|
||||||
if err := dump(in, s, depth+1, out); err == rlp.EOL {
|
if err := dump(in, s, depth+1, out); errors.Is(err, rlp.EOL) {
|
||||||
break
|
break
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,9 @@ package bitutil
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/pkg/errors"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
|
@ -107,7 +109,7 @@ func TestDecodingCycle(t *testing.T) {
|
||||||
data := hexutil.MustDecode(tt.input)
|
data := hexutil.MustDecode(tt.input)
|
||||||
|
|
||||||
orig, err := bitsetDecodeBytes(data, tt.size)
|
orig, err := bitsetDecodeBytes(data, tt.size)
|
||||||
if err != tt.fail {
|
if !errors.Is(err, tt.fail) {
|
||||||
t.Errorf("test %d: failure mismatch: have %v, want %v", i, err, tt.fail)
|
t.Errorf("test %d: failure mismatch: have %v, want %v", i, err, tt.fail)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -143,7 +145,7 @@ func TestCompression(t *testing.T) {
|
||||||
t.Errorf("decoding mismatch for dense data: have %x, want %x, error %v", data, in, err)
|
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
|
// 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)
|
t.Errorf("decoding error mismatch for long data: have %v, want %v", err, errExceededTarget)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,7 @@ package hexutil
|
||||||
import (
|
import (
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/pkg/errors"
|
||||||
"math/big"
|
"math/big"
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
@ -234,7 +235,7 @@ func mapError(err error) error {
|
||||||
if _, ok := err.(hex.InvalidByteError); ok {
|
if _, ok := err.(hex.InvalidByteError); ok {
|
||||||
return ErrSyntax
|
return ErrSyntax
|
||||||
}
|
}
|
||||||
if err == hex.ErrLength {
|
if errors.Is(err, hex.ErrLength) {
|
||||||
return ErrOddLength
|
return ErrOddLength
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ import (
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/pkg/errors"
|
||||||
"math/big"
|
"math/big"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
@ -355,7 +356,7 @@ func (b *Uint) UnmarshalJSON(input []byte) error {
|
||||||
func (b *Uint) UnmarshalText(input []byte) error {
|
func (b *Uint) UnmarshalText(input []byte) error {
|
||||||
var u64 Uint64
|
var u64 Uint64
|
||||||
err := u64.UnmarshalText(input)
|
err := u64.UnmarshalText(input)
|
||||||
if u64 > Uint64(^uint(0)) || err == ErrUint64Range {
|
if u64 > Uint64(^uint(0)) || errors.Is(err, ErrUint64Range) {
|
||||||
return ErrUintRange
|
return ErrUintRange
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"crypto/ecdsa"
|
"crypto/ecdsa"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/pkg/errors"
|
||||||
"math/big"
|
"math/big"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
|
@ -470,7 +471,7 @@ func (tt *cliqueTest) run(t *testing.T) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if _, err = chain.InsertChain(batches[len(batches)-1]); err != tt.failure {
|
if _, err = chain.InsertChain(batches[len(batches)-1]); !errors.Is(err, tt.failure) {
|
||||||
t.Errorf("failure mismatch: have %v, want %v", err, tt.failure)
|
t.Errorf("failure mismatch: have %v, want %v", err, tt.failure)
|
||||||
}
|
}
|
||||||
if tt.failure != nil {
|
if tt.failure != nil {
|
||||||
|
|
|
||||||
|
|
@ -448,7 +448,7 @@ func (c *Console) Interactive() {
|
||||||
return
|
return
|
||||||
|
|
||||||
case err := <-inputErr:
|
case err := <-inputErr:
|
||||||
if err == liner.ErrPromptAborted {
|
if errors.Is(err, liner.ErrPromptAborted) {
|
||||||
// When prompting for multi-line input, the first Ctrl-C resets
|
// When prompting for multi-line input, the first Ctrl-C resets
|
||||||
// the multi-line state.
|
// the multi-line state.
|
||||||
prompt, indents, input = c.prompt, 0, ""
|
prompt, indents, input = c.prompt, 0, ""
|
||||||
|
|
|
||||||
|
|
@ -1251,7 +1251,7 @@ func (bc *BlockChain) InsertReceiptChain(blockChain types.Blocks, receiptChain [
|
||||||
// Write downloaded chain data and corresponding receipt chain data
|
// Write downloaded chain data and corresponding receipt chain data
|
||||||
if len(ancientBlocks) > 0 {
|
if len(ancientBlocks) > 0 {
|
||||||
if n, err := writeAncient(ancientBlocks, ancientReceipts); err != nil {
|
if n, err := writeAncient(ancientBlocks, ancientReceipts); err != nil {
|
||||||
if err == errInsertionInterrupted {
|
if errors.Is(err, errInsertionInterrupted) {
|
||||||
return 0, nil
|
return 0, nil
|
||||||
}
|
}
|
||||||
return n, err
|
return n, err
|
||||||
|
|
@ -1259,7 +1259,7 @@ func (bc *BlockChain) InsertReceiptChain(blockChain types.Blocks, receiptChain [
|
||||||
}
|
}
|
||||||
if len(liveBlocks) > 0 {
|
if len(liveBlocks) > 0 {
|
||||||
if n, err := writeLive(liveBlocks, liveReceipts); err != nil {
|
if n, err := writeLive(liveBlocks, liveReceipts); err != nil {
|
||||||
if err == errInsertionInterrupted {
|
if errors.Is(err, errInsertionInterrupted) {
|
||||||
return 0, nil
|
return 0, nil
|
||||||
}
|
}
|
||||||
return n, err
|
return n, err
|
||||||
|
|
|
||||||
|
|
@ -154,7 +154,7 @@ func testBlockChainImport(chain types.Blocks, blockchain *BlockChain) error {
|
||||||
err = blockchain.validator.ValidateBody(block)
|
err = blockchain.validator.ValidateBody(block)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == ErrKnownBlock {
|
if errors.Is(err, ErrKnownBlock) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ package forkid
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"github.com/pkg/errors"
|
||||||
"hash/crc32"
|
"hash/crc32"
|
||||||
"math"
|
"math"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
@ -359,7 +360,7 @@ func TestValidation(t *testing.T) {
|
||||||
genesis := core.DefaultGenesisBlock().ToBlock()
|
genesis := core.DefaultGenesisBlock().ToBlock()
|
||||||
for i, tt := range tests {
|
for i, tt := range tests {
|
||||||
filter := newFilter(tt.config, genesis, func() (uint64, uint64) { return tt.head, tt.time })
|
filter := newFilter(tt.config, genesis, func() (uint64, uint64) { return tt.head, tt.time })
|
||||||
if err := filter(tt.id); err != tt.err {
|
if err := filter(tt.id); !errors.Is(err, tt.err) {
|
||||||
t.Errorf("test %d: validation error mismatch: have %v, want %v", i, err, tt.err)
|
t.Errorf("test %d: validation error mismatch: have %v, want %v", i, err, tt.err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,9 @@ package rawdb
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/pkg/errors"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
@ -68,7 +70,7 @@ func TestFreezerBasics(t *testing.T) {
|
||||||
}
|
}
|
||||||
// Check that we cannot read too far
|
// Check that we cannot read too far
|
||||||
_, err = f.Retrieve(uint64(255))
|
_, err = f.Retrieve(uint64(255))
|
||||||
if err != errOutOfBounds {
|
if !errors.Is(err, errOutOfBounds) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -878,7 +880,7 @@ func checkRetrieveError(t *testing.T, f *freezerTable, items map[uint64]error) {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatalf("unexpected value %x for item %d, want error %v", item, value, wantError)
|
t.Fatalf("unexpected value %x for item %d, want error %v", item, value, wantError)
|
||||||
}
|
}
|
||||||
if err != wantError {
|
if !errors.Is(err, wantError) {
|
||||||
t.Fatalf("wrong error for item %d: %v", item, err)
|
t.Fatalf("wrong error for item %d: %v", item, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -105,7 +105,7 @@ func TestFreezerModifyRollback(t *testing.T) {
|
||||||
require.NoError(t, op.AppendRaw("test", 2, make([]byte, 2048)))
|
require.NoError(t, op.AppendRaw("test", 2, make([]byte, 2048)))
|
||||||
return theError
|
return theError
|
||||||
})
|
})
|
||||||
if err != theError {
|
if !errors.Is(err, theError) {
|
||||||
t.Errorf("ModifyAncients returned wrong error %q", err)
|
t.Errorf("ModifyAncients returned wrong error %q", err)
|
||||||
}
|
}
|
||||||
checkAncientCount(t, f, "test", 0)
|
checkAncientCount(t, f, "test", 0)
|
||||||
|
|
@ -373,7 +373,7 @@ func checkAncientCount(t *testing.T, f *Freezer, kind string, n uint64) {
|
||||||
}
|
}
|
||||||
if _, err := f.Ancient(kind, index); err == nil {
|
if _, err := f.Ancient(kind, index); err == nil {
|
||||||
t.Errorf("Ancient(%q, %d) didn't return expected error", kind, index)
|
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)
|
t.Errorf("Ancient(%q, %d) returned unexpected error %q", kind, index, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,8 @@ package snapshot
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"errors"
|
||||||
|
"github.com/pkg/errors"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/VictoriaMetrics/fastcache"
|
"github.com/VictoriaMetrics/fastcache"
|
||||||
|
|
@ -311,7 +313,7 @@ func TestDiskPartialMerge(t *testing.T) {
|
||||||
assertAccount := func(account common.Hash, data []byte) {
|
assertAccount := func(account common.Hash, data []byte) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
blob, err := base.AccountRLP(account)
|
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)
|
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) {
|
if bytes.Compare(account[:], genMarker) <= 0 && !bytes.Equal(blob, data) {
|
||||||
|
|
@ -327,7 +329,7 @@ func TestDiskPartialMerge(t *testing.T) {
|
||||||
assertStorage := func(account common.Hash, slot common.Hash, data []byte) {
|
assertStorage := func(account common.Hash, slot common.Hash, data []byte) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
blob, err := base.Storage(account, slot)
|
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)
|
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) {
|
if bytes.Compare(append(account[:], slot[:]...), genMarker) <= 0 && !bytes.Equal(blob, data) {
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,9 @@ package snapshot
|
||||||
import (
|
import (
|
||||||
crand "crypto/rand"
|
crand "crypto/rand"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/pkg/errors"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
@ -118,10 +120,10 @@ func TestDiskLayerExternalInvalidationFullFlatten(t *testing.T) {
|
||||||
t.Fatalf("failed to merge diff layer onto disk: %v", err)
|
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
|
// 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)
|
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)
|
t.Errorf("stale reference returned storage slot: %#x (err: %v)", slot, err)
|
||||||
}
|
}
|
||||||
if n := len(snaps.layers); n != 1 {
|
if n := len(snaps.layers); n != 1 {
|
||||||
|
|
@ -168,10 +170,10 @@ func TestDiskLayerExternalInvalidationPartialFlatten(t *testing.T) {
|
||||||
t.Fatalf("failed to merge accumulator onto disk: %v", err)
|
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
|
// 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)
|
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)
|
t.Errorf("stale reference returned storage slot: %#x (err: %v)", slot, err)
|
||||||
}
|
}
|
||||||
if n := len(snaps.layers); n != 2 {
|
if n := len(snaps.layers); n != 2 {
|
||||||
|
|
@ -230,10 +232,10 @@ func TestDiffLayerExternalInvalidationPartialFlatten(t *testing.T) {
|
||||||
t.Fatalf("failed to flatten diff layer into accumulator: %v", err)
|
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
|
// 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)
|
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)
|
t.Errorf("stale reference returned storage slot: %#x (err: %v)", slot, err)
|
||||||
}
|
}
|
||||||
if n := len(snaps.layers); n != 3 {
|
if n := len(snaps.layers); n != 3 {
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ package core
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/pkg/errors"
|
||||||
"math"
|
"math"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
||||||
|
|
@ -60,7 +61,7 @@ func (result *ExecutionResult) Return() []byte {
|
||||||
// Revert returns the concrete revert reason if the execution is aborted by `REVERT`
|
// Revert returns the concrete revert reason if the execution is aborted by `REVERT`
|
||||||
// opcode. Note the reason can be nil if no data supplied with revert opcode.
|
// opcode. Note the reason can be nil if no data supplied with revert opcode.
|
||||||
func (result *ExecutionResult) Revert() []byte {
|
func (result *ExecutionResult) Revert() []byte {
|
||||||
if result.Err != vm.ErrExecutionReverted {
|
if !errors.Is(result.Err, vm.ErrExecutionReverted) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return common.CopyBytes(result.ReturnData)
|
return common.CopyBytes(result.ReturnData)
|
||||||
|
|
|
||||||
|
|
@ -421,7 +421,7 @@ func TestNegativeValue(t *testing.T) {
|
||||||
tx, _ := types.SignTx(types.NewTransaction(0, common.Address{}, big.NewInt(-1), 100, big.NewInt(1), nil), types.HomesteadSigner{}, key)
|
tx, _ := types.SignTx(types.NewTransaction(0, common.Address{}, big.NewInt(-1), 100, big.NewInt(1), nil), types.HomesteadSigner{}, key)
|
||||||
from, _ := deriveSender(tx)
|
from, _ := deriveSender(tx)
|
||||||
testAddBalance(pool, from, big.NewInt(1))
|
testAddBalance(pool, from, big.NewInt(1))
|
||||||
if err := pool.addRemote(tx); err != txpool.ErrNegativeValue {
|
if err := pool.addRemote(tx); !errors.Is(err, txpool.ErrNegativeValue) {
|
||||||
t.Error("expected", txpool.ErrNegativeValue, "got", err)
|
t.Error("expected", txpool.ErrNegativeValue, "got", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -434,7 +434,7 @@ func TestTipAboveFeeCap(t *testing.T) {
|
||||||
|
|
||||||
tx := dynamicFeeTx(0, 100, big.NewInt(1), big.NewInt(2), key)
|
tx := dynamicFeeTx(0, 100, big.NewInt(1), big.NewInt(2), key)
|
||||||
|
|
||||||
if err := pool.addRemote(tx); err != core.ErrTipAboveFeeCap {
|
if err := pool.addRemote(tx); !errors.Is(err, core.ErrTipAboveFeeCap) {
|
||||||
t.Error("expected", core.ErrTipAboveFeeCap, "got", err)
|
t.Error("expected", core.ErrTipAboveFeeCap, "got", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -449,12 +449,12 @@ func TestVeryHighValues(t *testing.T) {
|
||||||
veryBigNumber.Lsh(veryBigNumber, 300)
|
veryBigNumber.Lsh(veryBigNumber, 300)
|
||||||
|
|
||||||
tx := dynamicFeeTx(0, 100, big.NewInt(1), veryBigNumber, key)
|
tx := dynamicFeeTx(0, 100, big.NewInt(1), veryBigNumber, key)
|
||||||
if err := pool.addRemote(tx); err != core.ErrTipVeryHigh {
|
if err := pool.addRemote(tx); !errors.Is(err, core.ErrTipVeryHigh) {
|
||||||
t.Error("expected", core.ErrTipVeryHigh, "got", err)
|
t.Error("expected", core.ErrTipVeryHigh, "got", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
tx2 := dynamicFeeTx(0, 100, veryBigNumber, big.NewInt(1), key)
|
tx2 := dynamicFeeTx(0, 100, veryBigNumber, big.NewInt(1), key)
|
||||||
if err := pool.addRemote(tx2); err != core.ErrFeeCapVeryHigh {
|
if err := pool.addRemote(tx2); !errors.Is(err, core.ErrFeeCapVeryHigh) {
|
||||||
t.Error("expected", core.ErrFeeCapVeryHigh, "got", err)
|
t.Error("expected", core.ErrFeeCapVeryHigh, "got", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1809,7 +1809,7 @@ func TestUnderpricing(t *testing.T) {
|
||||||
t.Fatalf("failed to add well priced transaction: %v", err)
|
t.Fatalf("failed to add well priced transaction: %v", err)
|
||||||
}
|
}
|
||||||
// Ensure that replacing a pending transaction with a future transaction fails
|
// Ensure that replacing a pending transaction with a future transaction fails
|
||||||
if err := pool.addRemote(pricedTransaction(5, 100000, big.NewInt(6), keys[1])); err != txpool.ErrFutureReplacePending {
|
if err := pool.addRemote(pricedTransaction(5, 100000, big.NewInt(6), keys[1])); !errors.Is(err, txpool.ErrFutureReplacePending) {
|
||||||
t.Fatalf("adding future replace transaction error mismatch: have %v, want %v", err, txpool.ErrFutureReplacePending)
|
t.Fatalf("adding future replace transaction error mismatch: have %v, want %v", err, txpool.ErrFutureReplacePending)
|
||||||
}
|
}
|
||||||
pending, queued = pool.Stats()
|
pending, queued = pool.Stats()
|
||||||
|
|
@ -2179,7 +2179,7 @@ func TestReplacement(t *testing.T) {
|
||||||
if err := pool.addRemoteSync(pricedTransaction(0, 100000, big.NewInt(1), key)); err != nil {
|
if err := pool.addRemoteSync(pricedTransaction(0, 100000, big.NewInt(1), key)); err != nil {
|
||||||
t.Fatalf("failed to add original cheap pending transaction: %v", err)
|
t.Fatalf("failed to add original cheap pending transaction: %v", err)
|
||||||
}
|
}
|
||||||
if err := pool.addRemote(pricedTransaction(0, 100001, big.NewInt(1), key)); err != txpool.ErrReplaceUnderpriced {
|
if err := pool.addRemote(pricedTransaction(0, 100001, big.NewInt(1), key)); !errors.Is(err, txpool.ErrReplaceUnderpriced) {
|
||||||
t.Fatalf("original cheap pending transaction replacement error mismatch: have %v, want %v", err, txpool.ErrReplaceUnderpriced)
|
t.Fatalf("original cheap pending transaction replacement error mismatch: have %v, want %v", err, txpool.ErrReplaceUnderpriced)
|
||||||
}
|
}
|
||||||
if err := pool.addRemote(pricedTransaction(0, 100000, big.NewInt(2), key)); err != nil {
|
if err := pool.addRemote(pricedTransaction(0, 100000, big.NewInt(2), key)); err != nil {
|
||||||
|
|
@ -2192,7 +2192,7 @@ func TestReplacement(t *testing.T) {
|
||||||
if err := pool.addRemoteSync(pricedTransaction(0, 100000, big.NewInt(price), key)); err != nil {
|
if err := pool.addRemoteSync(pricedTransaction(0, 100000, big.NewInt(price), key)); err != nil {
|
||||||
t.Fatalf("failed to add original proper pending transaction: %v", err)
|
t.Fatalf("failed to add original proper pending transaction: %v", err)
|
||||||
}
|
}
|
||||||
if err := pool.addRemote(pricedTransaction(0, 100001, big.NewInt(threshold-1), key)); err != txpool.ErrReplaceUnderpriced {
|
if err := pool.addRemote(pricedTransaction(0, 100001, big.NewInt(threshold-1), key)); !errors.Is(err, txpool.ErrReplaceUnderpriced) {
|
||||||
t.Fatalf("original proper pending transaction replacement error mismatch: have %v, want %v", err, txpool.ErrReplaceUnderpriced)
|
t.Fatalf("original proper pending transaction replacement error mismatch: have %v, want %v", err, txpool.ErrReplaceUnderpriced)
|
||||||
}
|
}
|
||||||
if err := pool.addRemote(pricedTransaction(0, 100000, big.NewInt(threshold), key)); err != nil {
|
if err := pool.addRemote(pricedTransaction(0, 100000, big.NewInt(threshold), key)); err != nil {
|
||||||
|
|
@ -2206,7 +2206,7 @@ func TestReplacement(t *testing.T) {
|
||||||
if err := pool.addRemote(pricedTransaction(2, 100000, big.NewInt(1), key)); err != nil {
|
if err := pool.addRemote(pricedTransaction(2, 100000, big.NewInt(1), key)); err != nil {
|
||||||
t.Fatalf("failed to add original cheap queued transaction: %v", err)
|
t.Fatalf("failed to add original cheap queued transaction: %v", err)
|
||||||
}
|
}
|
||||||
if err := pool.addRemote(pricedTransaction(2, 100001, big.NewInt(1), key)); err != txpool.ErrReplaceUnderpriced {
|
if err := pool.addRemote(pricedTransaction(2, 100001, big.NewInt(1), key)); !errors.Is(err, txpool.ErrReplaceUnderpriced) {
|
||||||
t.Fatalf("original cheap queued transaction replacement error mismatch: have %v, want %v", err, txpool.ErrReplaceUnderpriced)
|
t.Fatalf("original cheap queued transaction replacement error mismatch: have %v, want %v", err, txpool.ErrReplaceUnderpriced)
|
||||||
}
|
}
|
||||||
if err := pool.addRemote(pricedTransaction(2, 100000, big.NewInt(2), key)); err != nil {
|
if err := pool.addRemote(pricedTransaction(2, 100000, big.NewInt(2), key)); err != nil {
|
||||||
|
|
@ -2216,7 +2216,7 @@ func TestReplacement(t *testing.T) {
|
||||||
if err := pool.addRemote(pricedTransaction(2, 100000, big.NewInt(price), key)); err != nil {
|
if err := pool.addRemote(pricedTransaction(2, 100000, big.NewInt(price), key)); err != nil {
|
||||||
t.Fatalf("failed to add original proper queued transaction: %v", err)
|
t.Fatalf("failed to add original proper queued transaction: %v", err)
|
||||||
}
|
}
|
||||||
if err := pool.addRemote(pricedTransaction(2, 100001, big.NewInt(threshold-1), key)); err != txpool.ErrReplaceUnderpriced {
|
if err := pool.addRemote(pricedTransaction(2, 100001, big.NewInt(threshold-1), key)); !errors.Is(err, txpool.ErrReplaceUnderpriced) {
|
||||||
t.Fatalf("original proper queued transaction replacement error mismatch: have %v, want %v", err, txpool.ErrReplaceUnderpriced)
|
t.Fatalf("original proper queued transaction replacement error mismatch: have %v, want %v", err, txpool.ErrReplaceUnderpriced)
|
||||||
}
|
}
|
||||||
if err := pool.addRemote(pricedTransaction(2, 100000, big.NewInt(threshold), key)); err != nil {
|
if err := pool.addRemote(pricedTransaction(2, 100000, big.NewInt(threshold), key)); err != nil {
|
||||||
|
|
@ -2280,7 +2280,7 @@ func TestReplacementDynamicFee(t *testing.T) {
|
||||||
}
|
}
|
||||||
// 2. Don't bump tip or feecap => discard
|
// 2. Don't bump tip or feecap => discard
|
||||||
tx = dynamicFeeTx(nonce, 100001, big.NewInt(2), big.NewInt(1), key)
|
tx = dynamicFeeTx(nonce, 100001, big.NewInt(2), big.NewInt(1), key)
|
||||||
if err := pool.addRemote(tx); err != txpool.ErrReplaceUnderpriced {
|
if err := pool.addRemote(tx); !errors.Is(err, txpool.ErrReplaceUnderpriced) {
|
||||||
t.Fatalf("original cheap %s transaction replacement error mismatch: have %v, want %v", stage, err, txpool.ErrReplaceUnderpriced)
|
t.Fatalf("original cheap %s transaction replacement error mismatch: have %v, want %v", stage, err, txpool.ErrReplaceUnderpriced)
|
||||||
}
|
}
|
||||||
// 3. Bump both more than min => accept
|
// 3. Bump both more than min => accept
|
||||||
|
|
@ -2303,22 +2303,22 @@ func TestReplacementDynamicFee(t *testing.T) {
|
||||||
}
|
}
|
||||||
// 6. Bump tip max allowed so it's still underpriced => discard
|
// 6. Bump tip max allowed so it's still underpriced => discard
|
||||||
tx = dynamicFeeTx(nonce, 100000, big.NewInt(gasFeeCap), big.NewInt(tipThreshold-1), key)
|
tx = dynamicFeeTx(nonce, 100000, big.NewInt(gasFeeCap), big.NewInt(tipThreshold-1), key)
|
||||||
if err := pool.addRemote(tx); err != txpool.ErrReplaceUnderpriced {
|
if err := pool.addRemote(tx); !errors.Is(err, txpool.ErrReplaceUnderpriced) {
|
||||||
t.Fatalf("original proper %s transaction replacement error mismatch: have %v, want %v", stage, err, txpool.ErrReplaceUnderpriced)
|
t.Fatalf("original proper %s transaction replacement error mismatch: have %v, want %v", stage, err, txpool.ErrReplaceUnderpriced)
|
||||||
}
|
}
|
||||||
// 7. Bump fee cap max allowed so it's still underpriced => discard
|
// 7. Bump fee cap max allowed so it's still underpriced => discard
|
||||||
tx = dynamicFeeTx(nonce, 100000, big.NewInt(feeCapThreshold-1), big.NewInt(gasTipCap), key)
|
tx = dynamicFeeTx(nonce, 100000, big.NewInt(feeCapThreshold-1), big.NewInt(gasTipCap), key)
|
||||||
if err := pool.addRemote(tx); err != txpool.ErrReplaceUnderpriced {
|
if err := pool.addRemote(tx); !errors.Is(err, txpool.ErrReplaceUnderpriced) {
|
||||||
t.Fatalf("original proper %s transaction replacement error mismatch: have %v, want %v", stage, err, txpool.ErrReplaceUnderpriced)
|
t.Fatalf("original proper %s transaction replacement error mismatch: have %v, want %v", stage, err, txpool.ErrReplaceUnderpriced)
|
||||||
}
|
}
|
||||||
// 8. Bump tip min for acceptance => accept
|
// 8. Bump tip min for acceptance => accept
|
||||||
tx = dynamicFeeTx(nonce, 100000, big.NewInt(gasFeeCap), big.NewInt(tipThreshold), key)
|
tx = dynamicFeeTx(nonce, 100000, big.NewInt(gasFeeCap), big.NewInt(tipThreshold), key)
|
||||||
if err := pool.addRemote(tx); err != txpool.ErrReplaceUnderpriced {
|
if err := pool.addRemote(tx); !errors.Is(err, txpool.ErrReplaceUnderpriced) {
|
||||||
t.Fatalf("original proper %s transaction replacement error mismatch: have %v, want %v", stage, err, txpool.ErrReplaceUnderpriced)
|
t.Fatalf("original proper %s transaction replacement error mismatch: have %v, want %v", stage, err, txpool.ErrReplaceUnderpriced)
|
||||||
}
|
}
|
||||||
// 9. Bump fee cap min for acceptance => accept
|
// 9. Bump fee cap min for acceptance => accept
|
||||||
tx = dynamicFeeTx(nonce, 100000, big.NewInt(feeCapThreshold), big.NewInt(gasTipCap), key)
|
tx = dynamicFeeTx(nonce, 100000, big.NewInt(feeCapThreshold), big.NewInt(gasTipCap), key)
|
||||||
if err := pool.addRemote(tx); err != txpool.ErrReplaceUnderpriced {
|
if err := pool.addRemote(tx); !errors.Is(err, txpool.ErrReplaceUnderpriced) {
|
||||||
t.Fatalf("original proper %s transaction replacement error mismatch: have %v, want %v", stage, err, txpool.ErrReplaceUnderpriced)
|
t.Fatalf("original proper %s transaction replacement error mismatch: have %v, want %v", stage, err, txpool.ErrReplaceUnderpriced)
|
||||||
}
|
}
|
||||||
// 10. Check events match expected (3 new executable txs during pending, 0 during queue)
|
// 10. Check events match expected (3 new executable txs during pending, 0 during queue)
|
||||||
|
|
|
||||||
|
|
@ -75,7 +75,7 @@ func TestDecodeEmptyTypedTx(t *testing.T) {
|
||||||
input := []byte{0x80}
|
input := []byte{0x80}
|
||||||
var tx Transaction
|
var tx Transaction
|
||||||
err := rlp.DecodeBytes(input, &tx)
|
err := rlp.DecodeBytes(input, &tx)
|
||||||
if err != errShortTypedTx {
|
if !errors.Is(err, errShortTypedTx) {
|
||||||
t.Fatal("wrong error:", err)
|
t.Fatal("wrong error:", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -538,7 +538,7 @@ func TestYParityJSONUnmarshalling(t *testing.T) {
|
||||||
// Unmarshal the tx
|
// Unmarshal the tx
|
||||||
var tx Transaction
|
var tx Transaction
|
||||||
err = tx.UnmarshalJSON(jsonBytes)
|
err = tx.UnmarshalJSON(jsonBytes)
|
||||||
if err != test.wantErr {
|
if !errors.Is(err, test.wantErr) {
|
||||||
t.Fatalf("wrong error: got %v, want %v", err, test.wantErr)
|
t.Fatalf("wrong error: got %v, want %v", err, test.wantErr)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@
|
||||||
package vm
|
package vm
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/pkg/errors"
|
||||||
"math/big"
|
"math/big"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
|
||||||
|
|
@ -246,7 +247,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.
|
// when we're in homestead this also counts for code storage gas errors.
|
||||||
if err != nil {
|
if err != nil {
|
||||||
evm.StateDB.RevertToSnapshot(snapshot)
|
evm.StateDB.RevertToSnapshot(snapshot)
|
||||||
if err != ErrExecutionReverted {
|
if !errors.Is(err, ErrExecutionReverted) {
|
||||||
gas = 0
|
gas = 0
|
||||||
}
|
}
|
||||||
// TODO: consider clearing up unused snapshots:
|
// TODO: consider clearing up unused snapshots:
|
||||||
|
|
@ -299,7 +300,7 @@ func (evm *EVM) CallCode(caller ContractRef, addr common.Address, input []byte,
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
evm.StateDB.RevertToSnapshot(snapshot)
|
evm.StateDB.RevertToSnapshot(snapshot)
|
||||||
if err != ErrExecutionReverted {
|
if !errors.Is(err, ErrExecutionReverted) {
|
||||||
gas = 0
|
gas = 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -343,7 +344,7 @@ func (evm *EVM) DelegateCall(caller ContractRef, addr common.Address, input []by
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
evm.StateDB.RevertToSnapshot(snapshot)
|
evm.StateDB.RevertToSnapshot(snapshot)
|
||||||
if err != ErrExecutionReverted {
|
if !errors.Is(err, ErrExecutionReverted) {
|
||||||
gas = 0
|
gas = 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -399,7 +400,7 @@ func (evm *EVM) StaticCall(caller ContractRef, addr common.Address, input []byte
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
evm.StateDB.RevertToSnapshot(snapshot)
|
evm.StateDB.RevertToSnapshot(snapshot)
|
||||||
if err != ErrExecutionReverted {
|
if !errors.Is(err, ErrExecutionReverted) {
|
||||||
gas = 0
|
gas = 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -492,9 +493,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
|
// 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
|
// 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.
|
// 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)
|
evm.StateDB.RevertToSnapshot(snapshot)
|
||||||
if err != ErrExecutionReverted {
|
if !errors.Is(err, ErrExecutionReverted) {
|
||||||
contract.UseGas(contract.Gas)
|
contract.UseGas(contract.Gas)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,8 @@ package vm
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"errors"
|
||||||
|
"github.com/pkg/errors"
|
||||||
"math"
|
"math"
|
||||||
"math/big"
|
"math/big"
|
||||||
"sort"
|
"sort"
|
||||||
|
|
@ -43,8 +45,8 @@ func TestMemoryGasCost(t *testing.T) {
|
||||||
}
|
}
|
||||||
for i, tt := range tests {
|
for i, tt := range tests {
|
||||||
v, err := memoryGasCost(&Memory{}, tt.size)
|
v, err := memoryGasCost(&Memory{}, tt.size)
|
||||||
if (err == ErrGasUintOverflow) != tt.overflow {
|
if (errors.Is(err, ErrGasUintOverflow)) != tt.overflow {
|
||||||
t.Errorf("test %d: overflow mismatch: have %v, want %v", i, err == ErrGasUintOverflow, tt.overflow)
|
t.Errorf("test %d: overflow mismatch: have %v, want %v", i, errors.Is(err, ErrGasUintOverflow), tt.overflow)
|
||||||
}
|
}
|
||||||
if v != tt.cost {
|
if v != tt.cost {
|
||||||
t.Errorf("test %d: gas cost mismatch: have %v, want %v", i, v, tt.cost)
|
t.Errorf("test %d: gas cost mismatch: have %v, want %v", i, v, tt.cost)
|
||||||
|
|
@ -98,7 +100,7 @@ func TestEIP2200(t *testing.T) {
|
||||||
vmenv := NewEVM(vmctx, TxContext{}, statedb, params.AllEthashProtocolChanges, Config{ExtraEips: []int{2200}})
|
vmenv := NewEVM(vmctx, TxContext{}, statedb, params.AllEthashProtocolChanges, Config{ExtraEips: []int{2200}})
|
||||||
|
|
||||||
_, gas, err := vmenv.Call(AccountRef(common.Address{}), address, nil, tt.gaspool, new(uint256.Int))
|
_, gas, err := vmenv.Call(AccountRef(common.Address{}), address, nil, tt.gaspool, new(uint256.Int))
|
||||||
if err != tt.failure {
|
if !errors.Is(err, tt.failure) {
|
||||||
t.Errorf("test %d: failure mismatch: have %v, want %v", i, err, tt.failure)
|
t.Errorf("test %d: failure mismatch: have %v, want %v", i, err, tt.failure)
|
||||||
}
|
}
|
||||||
if used := tt.gaspool - gas; used != tt.used {
|
if used := tt.gaspool - gas; used != tt.used {
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,8 @@
|
||||||
package vm
|
package vm
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
|
"github.com/pkg/errors"
|
||||||
"math"
|
"math"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
|
|
@ -597,9 +599,9 @@ func opCreate(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]b
|
||||||
// homestead we must check for CodeStoreOutOfGasError (homestead only
|
// homestead we must check for CodeStoreOutOfGasError (homestead only
|
||||||
// rule) and treat as an error, if the ruleset is frontier we must
|
// rule) and treat as an error, if the ruleset is frontier we must
|
||||||
// ignore this error and pretend the operation was successful.
|
// ignore this error and pretend the operation was successful.
|
||||||
if interpreter.evm.chainRules.IsHomestead && suberr == ErrCodeStoreOutOfGas {
|
if interpreter.evm.chainRules.IsHomestead && errors.Is(suberr, ErrCodeStoreOutOfGas) {
|
||||||
stackvalue.Clear()
|
stackvalue.Clear()
|
||||||
} else if suberr != nil && suberr != ErrCodeStoreOutOfGas {
|
} else if suberr != nil && !errors.Is(suberr, ErrCodeStoreOutOfGas) {
|
||||||
stackvalue.Clear()
|
stackvalue.Clear()
|
||||||
} else {
|
} else {
|
||||||
stackvalue.SetBytes(addr.Bytes())
|
stackvalue.SetBytes(addr.Bytes())
|
||||||
|
|
@ -607,7 +609,7 @@ func opCreate(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]b
|
||||||
scope.Stack.push(&stackvalue)
|
scope.Stack.push(&stackvalue)
|
||||||
scope.Contract.Gas += returnGas
|
scope.Contract.Gas += returnGas
|
||||||
|
|
||||||
if suberr == ErrExecutionReverted {
|
if errors.Is(suberr, ErrExecutionReverted) {
|
||||||
interpreter.returnData = res // set REVERT data to return data buffer
|
interpreter.returnData = res // set REVERT data to return data buffer
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
@ -642,7 +644,7 @@ func opCreate2(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]
|
||||||
scope.Stack.push(&stackvalue)
|
scope.Stack.push(&stackvalue)
|
||||||
scope.Contract.Gas += returnGas
|
scope.Contract.Gas += returnGas
|
||||||
|
|
||||||
if suberr == ErrExecutionReverted {
|
if errors.Is(suberr, ErrExecutionReverted) {
|
||||||
interpreter.returnData = res // set REVERT data to return data buffer
|
interpreter.returnData = res // set REVERT data to return data buffer
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
@ -676,7 +678,7 @@ func opCall(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byt
|
||||||
temp.SetOne()
|
temp.SetOne()
|
||||||
}
|
}
|
||||||
stack.push(&temp)
|
stack.push(&temp)
|
||||||
if err == nil || err == ErrExecutionReverted {
|
if err == nil || errors.Is(err, ErrExecutionReverted) {
|
||||||
scope.Memory.Set(retOffset.Uint64(), retSize.Uint64(), ret)
|
scope.Memory.Set(retOffset.Uint64(), retSize.Uint64(), ret)
|
||||||
}
|
}
|
||||||
scope.Contract.Gas += returnGas
|
scope.Contract.Gas += returnGas
|
||||||
|
|
@ -708,7 +710,7 @@ func opCallCode(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([
|
||||||
temp.SetOne()
|
temp.SetOne()
|
||||||
}
|
}
|
||||||
stack.push(&temp)
|
stack.push(&temp)
|
||||||
if err == nil || err == ErrExecutionReverted {
|
if err == nil || errors.Is(err, ErrExecutionReverted) {
|
||||||
scope.Memory.Set(retOffset.Uint64(), retSize.Uint64(), ret)
|
scope.Memory.Set(retOffset.Uint64(), retSize.Uint64(), ret)
|
||||||
}
|
}
|
||||||
scope.Contract.Gas += returnGas
|
scope.Contract.Gas += returnGas
|
||||||
|
|
@ -736,7 +738,7 @@ func opDelegateCall(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext
|
||||||
temp.SetOne()
|
temp.SetOne()
|
||||||
}
|
}
|
||||||
stack.push(&temp)
|
stack.push(&temp)
|
||||||
if err == nil || err == ErrExecutionReverted {
|
if err == nil || errors.Is(err, ErrExecutionReverted) {
|
||||||
scope.Memory.Set(retOffset.Uint64(), retSize.Uint64(), ret)
|
scope.Memory.Set(retOffset.Uint64(), retSize.Uint64(), ret)
|
||||||
}
|
}
|
||||||
scope.Contract.Gas += returnGas
|
scope.Contract.Gas += returnGas
|
||||||
|
|
@ -764,7 +766,7 @@ func opStaticCall(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext)
|
||||||
temp.SetOne()
|
temp.SetOne()
|
||||||
}
|
}
|
||||||
stack.push(&temp)
|
stack.push(&temp)
|
||||||
if err == nil || err == ErrExecutionReverted {
|
if err == nil || errors.Is(err, ErrExecutionReverted) {
|
||||||
scope.Memory.Set(retOffset.Uint64(), retSize.Uint64(), ret)
|
scope.Memory.Set(retOffset.Uint64(), retSize.Uint64(), ret)
|
||||||
}
|
}
|
||||||
scope.Contract.Gas += returnGas
|
scope.Contract.Gas += returnGas
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/common/math"
|
"github.com/ethereum/go-ethereum/common/math"
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"github.com/ethereum/go-ethereum/log"
|
"github.com/ethereum/go-ethereum/log"
|
||||||
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Config are the configuration options for the Interpreter
|
// Config are the configuration options for the Interpreter
|
||||||
|
|
@ -234,7 +235,7 @@ func (in *EVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) (
|
||||||
pc++
|
pc++
|
||||||
}
|
}
|
||||||
|
|
||||||
if err == errStopToken {
|
if errors.Is(err, errStopToken) {
|
||||||
err = nil // clear stop token error
|
err = nil // clear stop token error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"crypto/ecdsa"
|
"crypto/ecdsa"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
|
"github.com/pkg/errors"
|
||||||
"math/big"
|
"math/big"
|
||||||
"os"
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
@ -66,11 +67,11 @@ func BenchmarkSha3(b *testing.B) {
|
||||||
|
|
||||||
func TestUnmarshalPubkey(t *testing.T) {
|
func TestUnmarshalPubkey(t *testing.T) {
|
||||||
key, err := UnmarshalPubkey(nil)
|
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)
|
t.Fatalf("expected error, got %v, %v", err, key)
|
||||||
}
|
}
|
||||||
key, err = UnmarshalPubkey([]byte{1, 2, 3})
|
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)
|
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)
|
_, 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")
|
t.Fatal("ecdh: shared key should be too large for curve")
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = prv2.GenerateShared(&prv1.PublicKey, 32, 32)
|
_, 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")
|
t.Fatal("ecdh: shared key should be too large for curve")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -355,7 +355,7 @@ func TestBasicKeyValidation(t *testing.T) {
|
||||||
for _, b := range badBytes {
|
for _, b := range badBytes {
|
||||||
ct[0] = b
|
ct[0] = b
|
||||||
_, err := prv.Decrypt(ct, nil, nil)
|
_, err := prv.Decrypt(ct, nil, nil)
|
||||||
if err != ErrInvalidPublicKey {
|
if !errors.Is(err, ErrInvalidPublicKey) {
|
||||||
t.Fatal("ecies: validated an invalid key")
|
t.Fatal("ecies: validated an invalid key")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ import (
|
||||||
"crypto/elliptic"
|
"crypto/elliptic"
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
@ -92,7 +93,7 @@ func TestInvalidRecoveryID(t *testing.T) {
|
||||||
sig, _ := Sign(msg, seckey)
|
sig, _ := Sign(msg, seckey)
|
||||||
sig[64] = 99
|
sig[64] = 99
|
||||||
_, err := RecoverPubkey(msg, sig)
|
_, err := RecoverPubkey(msg, sig)
|
||||||
if err != ErrInvalidRecoveryID {
|
if !errors.Is(err, ErrInvalidRecoveryID) {
|
||||||
t.Fatalf("got %q, want %q", err, ErrInvalidRecoveryID)
|
t.Fatalf("got %q, want %q", err, ErrInvalidRecoveryID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -665,7 +665,7 @@ func (d *Downloader) spawnSync(fetchers []func() error) error {
|
||||||
}
|
}
|
||||||
if got := <-errc; got != nil {
|
if got := <-errc; got != nil {
|
||||||
err = got
|
err = got
|
||||||
if got != errCanceled {
|
if !errors.Is(got, errCanceled) {
|
||||||
break // receive a meaningful error, bubble it up
|
break // receive a meaningful error, bubble it up
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1547,7 +1547,7 @@ func (d *Downloader) processSnapSyncContent() error {
|
||||||
}()
|
}()
|
||||||
|
|
||||||
closeOnErr := func(s *stateSync) {
|
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
|
d.queue.Close() // wake up Results
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,9 @@
|
||||||
package downloader
|
package downloader
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/pkg/errors"
|
||||||
"math/big"
|
"math/big"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
@ -614,7 +616,7 @@ func testBoundedForkedSync(t *testing.T, protocol uint, mode SyncMode) {
|
||||||
assertOwnChain(t, tester, len(chainA.blocks))
|
assertOwnChain(t, tester, len(chainA.blocks))
|
||||||
|
|
||||||
// Synchronise with the second peer and ensure that the fork is rejected to being too old
|
// 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)
|
t.Fatalf("sync failure mismatch: have %v, want %v", err, errInvalidAncestor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -649,7 +651,7 @@ func testBoundedHeavyForkedSync(t *testing.T, protocol uint, mode SyncMode) {
|
||||||
|
|
||||||
tester.newPeer("heavy-rewriter", protocol, chainB.blocks[1:])
|
tester.newPeer("heavy-rewriter", protocol, chainB.blocks[1:])
|
||||||
// Synchronise with the second peer and ensure that the fork is rejected to being too old
|
// 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)
|
t.Fatalf("sync failure mismatch: have %v, want %v", err, errInvalidAncestor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -854,7 +856,7 @@ func testHighTDStarvationAttack(t *testing.T, protocol uint, mode SyncMode) {
|
||||||
|
|
||||||
chain := testChainBase.shorten(1)
|
chain := testChainBase.shorten(1)
|
||||||
tester.newPeer("attack", protocol, chain.blocks[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)
|
t.Fatalf("synchronisation error mismatch: have %v, want %v", err, errStallingPeer)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -278,25 +278,25 @@ func (s *skeleton) startup() {
|
||||||
// signalling as the sync loop should never terminate (TM).
|
// signalling as the sync loop should never terminate (TM).
|
||||||
newhead, err := s.sync(head)
|
newhead, err := s.sync(head)
|
||||||
switch {
|
switch {
|
||||||
case err == errSyncLinked:
|
case errors.Is(err, errSyncLinked):
|
||||||
// Sync cycle linked up to the genesis block, or the existent chain
|
// Sync cycle linked up to the genesis block, or the existent chain
|
||||||
// segment. Tear down the loop and restart it so, it can properly
|
// segment. Tear down the loop and restart it so, it can properly
|
||||||
// notify the backfiller. Don't account a new head.
|
// notify the backfiller. Don't account a new head.
|
||||||
head = nil
|
head = nil
|
||||||
|
|
||||||
case err == errSyncMerged:
|
case errors.Is(err, errSyncMerged):
|
||||||
// Subchains were merged, we just need to reinit the internal
|
// Subchains were merged, we just need to reinit the internal
|
||||||
// start to continue on the tail of the merged chain. Don't
|
// start to continue on the tail of the merged chain. Don't
|
||||||
// announce a new head,
|
// announce a new head,
|
||||||
head = nil
|
head = nil
|
||||||
|
|
||||||
case err == errSyncReorged:
|
case errors.Is(err, errSyncReorged):
|
||||||
// The subchain being synced got modified at the head in a
|
// The subchain being synced got modified at the head in a
|
||||||
// way that requires resyncing it. Restart sync with the new
|
// way that requires resyncing it. Restart sync with the new
|
||||||
// head to force a cleanup.
|
// head to force a cleanup.
|
||||||
head = newhead
|
head = newhead
|
||||||
|
|
||||||
case err == errTerminated:
|
case errors.Is(err, errTerminated):
|
||||||
// Sync was requested to be terminated from within, stop and
|
// Sync was requested to be terminated from within, stop and
|
||||||
// return (no need to pass a message, was already done internally)
|
// return (no need to pass a message, was already done internally)
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -478,7 +478,7 @@ func TestInvalidGetRangeLogsRequest(t *testing.T) {
|
||||||
api = NewFilterAPI(sys, false)
|
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)
|
t.Errorf("Expected Logs for invalid range return error, but got: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@ package filters
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"github.com/pkg/errors"
|
||||||
"math/big"
|
"math/big"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
@ -382,7 +383,7 @@ func TestFilters(t *testing.T) {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatal("expected error")
|
t.Fatal("expected error")
|
||||||
}
|
}
|
||||||
if err != context.DeadlineExceeded {
|
if !errors.Is(err, context.DeadlineExceeded) {
|
||||||
t.Fatalf("expected context.DeadlineExceeded, got %v", err)
|
t.Fatalf("expected context.DeadlineExceeded, got %v", err)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -84,7 +84,7 @@ func TestFeeHistory(t *testing.T) {
|
||||||
if len(ratio) != c.expCount {
|
if len(ratio) != c.expCount {
|
||||||
t.Fatalf("Test case %d: gasUsedRatio array length mismatch, want %d, got %d", i, c.expCount, len(ratio))
|
t.Fatalf("Test case %d: gasUsedRatio array length mismatch, want %d, got %d", i, c.expCount, len(ratio))
|
||||||
}
|
}
|
||||||
if err != c.expErr && !errors.Is(err, c.expErr) {
|
if !errors.Is(err, c.expErr) && !errors.Is(err, c.expErr) {
|
||||||
t.Fatalf("Test case %d: error mismatch, want %v, got %v", i, c.expErr, err)
|
t.Fatalf("Test case %d: error mismatch, want %v, got %v", i, c.expErr, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ import (
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/pkg/errors"
|
||||||
"io"
|
"io"
|
||||||
"math/big"
|
"math/big"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
@ -245,7 +246,7 @@ func (l *StructLogger) GetResult() (json.RawMessage, error) {
|
||||||
returnData := common.CopyBytes(l.output)
|
returnData := common.CopyBytes(l.output)
|
||||||
// Return data when successful and revert reason when reverted, otherwise empty.
|
// Return data when successful and revert reason when reverted, otherwise empty.
|
||||||
returnVal := fmt.Sprintf("%x", returnData)
|
returnVal := fmt.Sprintf("%x", returnData)
|
||||||
if failed && l.err != vm.ErrExecutionReverted {
|
if failed && !errors.Is(l.err, vm.ErrExecutionReverted) {
|
||||||
returnVal = ""
|
returnVal = ""
|
||||||
}
|
}
|
||||||
return json.Marshal(&ExecutionResult{
|
return json.Marshal(&ExecutionResult{
|
||||||
|
|
|
||||||
|
|
@ -398,7 +398,7 @@ func testTransactionInBlock(t *testing.T, client *rpc.Client) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test tx in block not found.
|
// Test tx in block not found.
|
||||||
if _, err := ec.TransactionInBlock(context.Background(), block.Hash(), 20); err != ethereum.NotFound {
|
if _, err := ec.TransactionInBlock(context.Background(), block.Hash(), 20); !errors.Is(err, ethereum.NotFound) {
|
||||||
t.Fatal("error should be ethereum.NotFound")
|
t.Fatal("error should be ethereum.NotFound")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,9 @@ package pebble
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/pkg/errors"
|
||||||
"runtime"
|
"runtime"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
|
@ -279,7 +281,7 @@ func (d *Database) Has(key []byte) (bool, error) {
|
||||||
return false, pebble.ErrClosed
|
return false, pebble.ErrClosed
|
||||||
}
|
}
|
||||||
_, closer, err := d.db.Get(key)
|
_, closer, err := d.db.Get(key)
|
||||||
if err == pebble.ErrNotFound {
|
if errors.Is(err, pebble.ErrNotFound) {
|
||||||
return false, nil
|
return false, nil
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
|
|
@ -362,7 +364,7 @@ func (d *Database) NewSnapshot() (ethdb.Snapshot, error) {
|
||||||
func (snap *snapshot) Has(key []byte) (bool, error) {
|
func (snap *snapshot) Has(key []byte) (bool, error) {
|
||||||
_, closer, err := snap.db.Get(key)
|
_, closer, err := snap.db.Get(key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err != pebble.ErrNotFound {
|
if !errors.Is(err, pebble.ErrNotFound) {
|
||||||
return false, err
|
return false, err
|
||||||
} else {
|
} else {
|
||||||
return false, nil
|
return false, nil
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@
|
||||||
package event
|
package event
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/pkg/errors"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
@ -59,7 +60,7 @@ func TestMuxErrorAfterStop(t *testing.T) {
|
||||||
if _, isopen := <-sub.Chan(); isopen {
|
if _, isopen := <-sub.Chan(); isopen {
|
||||||
t.Errorf("subscription channel was not closed")
|
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)
|
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)
|
t.Fatalf("wrong int %d, want %d", got, want)
|
||||||
}
|
}
|
||||||
case err := <-sub.Err():
|
case err := <-sub.Err():
|
||||||
if err != errInts {
|
if !errors.Is(err, errInts) {
|
||||||
t.Fatalf("wrong error: got %q, want %q", err, errInts)
|
t.Fatalf("wrong error: got %q, want %q", err, errInts)
|
||||||
}
|
}
|
||||||
if want != 2 {
|
if want != 2 {
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/pkg/errors"
|
||||||
"go/parser"
|
"go/parser"
|
||||||
"go/token"
|
"go/token"
|
||||||
"io"
|
"io"
|
||||||
|
|
@ -98,7 +99,7 @@ func RunGit(args ...string) string {
|
||||||
var stdout, stderr bytes.Buffer
|
var stdout, stderr bytes.Buffer
|
||||||
cmd.Stdout, cmd.Stderr = &stdout, &stderr
|
cmd.Stdout, cmd.Stderr = &stdout, &stderr
|
||||||
if err := cmd.Run(); err != nil {
|
if err := cmd.Run(); err != nil {
|
||||||
if e, ok := err.(*exec.Error); ok && e.Err == exec.ErrNotFound {
|
if e, ok := err.(*exec.Error); ok && errors.Is(e.Err, exec.ErrNotFound) {
|
||||||
if !warnedAboutGit {
|
if !warnedAboutGit {
|
||||||
log.Println("Warning: can't find 'git' in PATH")
|
log.Println("Warning: can't find 'git' in PATH")
|
||||||
warnedAboutGit = true
|
warnedAboutGit = true
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ func TestNodeCloseMultipleTimes(t *testing.T) {
|
||||||
|
|
||||||
// Ensure that a stopped node can be stopped again
|
// Ensure that a stopped node can be stopped again
|
||||||
for i := 0; i < 3; i++ {
|
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)
|
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 {
|
if err := stack.Start(); err != nil {
|
||||||
t.Fatalf("failed to start node: %v", err)
|
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)
|
t.Fatalf("start failure mismatch: have %v, want %v ", err, ErrNodeRunning)
|
||||||
}
|
}
|
||||||
// Ensure that a node can be stopped, but only once
|
// Ensure that a node can be stopped, but only once
|
||||||
if err := stack.Close(); err != nil {
|
if err := stack.Close(); err != nil {
|
||||||
t.Fatalf("failed to stop node: %v", err)
|
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)
|
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
|
// Create a second node based on the same data directory and ensure failure
|
||||||
_, err = New(&Config{DataDir: dir})
|
_, 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)
|
t.Fatalf("duplicate datadir failure mismatch: have %v, want %v", err, ErrDatadirUsed)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -296,7 +296,7 @@ func TestLifecycleStartupError(t *testing.T) {
|
||||||
stack.RegisterLifecycle(failer)
|
stack.RegisterLifecycle(failer)
|
||||||
|
|
||||||
// Start the protocol stack and ensure all started services stop
|
// Start the protocol stack and ensure all started services stop
|
||||||
if err := stack.Start(); err != failure {
|
if err := stack.Start(); !errors.Is(err, failure) {
|
||||||
t.Fatalf("stack startup failure mismatch: have %v, want %v", err, failure)
|
t.Fatalf("stack startup failure mismatch: have %v, want %v", err, failure)
|
||||||
}
|
}
|
||||||
for id := range lifecycles {
|
for id := range lifecycles {
|
||||||
|
|
@ -364,7 +364,7 @@ func TestLifecycleTerminationGuarantee(t *testing.T) {
|
||||||
t.Fatalf("termination failure mismatch: have %v, want StopError", err)
|
t.Fatalf("termination failure mismatch: have %v, want StopError", err)
|
||||||
} else {
|
} else {
|
||||||
failer := reflect.TypeOf(&InstrumentedService{})
|
failer := reflect.TypeOf(&InstrumentedService{})
|
||||||
if err.Services[failer] != failure {
|
if !errors.Is(failure, err.Services[failer]) {
|
||||||
t.Fatalf("failer termination failure mismatch: have %v, want %v", err.Services[failer], failure)
|
t.Fatalf("failer termination failure mismatch: have %v, want %v", err.Services[failer], failure)
|
||||||
}
|
}
|
||||||
if len(err.Services) != 1 {
|
if len(err.Services) != 1 {
|
||||||
|
|
|
||||||
|
|
@ -281,7 +281,7 @@ func (h *httpServer) doStop() {
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), shutdownTimeout)
|
ctx, cancel := context.WithTimeout(context.Background(), shutdownTimeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
err := h.server.Shutdown(ctx)
|
err := h.server.Shutdown(ctx)
|
||||||
if err != nil && err == ctx.Err() {
|
if err != nil && errors.Is(err, ctx.Err()) {
|
||||||
h.log.Warn("HTTP server graceful shutdown timed out")
|
h.log.Warn("HTTP server graceful shutdown timed out")
|
||||||
h.server.Close()
|
h.server.Close()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -100,7 +100,7 @@ func (test *udpTest) packetInFrom(wantError error, key *ecdsa.PrivateKey, addr *
|
||||||
test.t.Errorf("%s encode error: %v", data.Name(), err)
|
test.t.Errorf("%s encode error: %v", data.Name(), err)
|
||||||
}
|
}
|
||||||
test.sent = append(test.sent, enc)
|
test.sent = append(test.sent, enc)
|
||||||
if err = test.udp.handlePacket(addr, enc); err != wantError {
|
if err = test.udp.handlePacket(addr, enc); !errors.Is(err, wantError) {
|
||||||
test.t.Errorf("error mismatch: got %q, want %q", err, wantError)
|
test.t.Errorf("error mismatch: got %q, want %q", err, wantError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ import (
|
||||||
"crypto/ecdsa"
|
"crypto/ecdsa"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/pkg/errors"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"net"
|
"net"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
@ -239,7 +240,7 @@ func TestUDPv5_pingCall(t *testing.T) {
|
||||||
done <- err
|
done <- err
|
||||||
}()
|
}()
|
||||||
test.waitPacketOut(func(p *v5wire.Ping, addr *net.UDPAddr, _ v5wire.Nonce) {})
|
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)
|
t.Fatalf("want errTimeout, got %q", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -128,7 +128,7 @@ var (
|
||||||
// returns false, it is pretty certain that the packet causing the error does not belong
|
// returns false, it is pretty certain that the packet causing the error does not belong
|
||||||
// to discv5.
|
// to discv5.
|
||||||
func IsInvalidHeader(err error) bool {
|
func IsInvalidHeader(err error) bool {
|
||||||
return err == errTooShort || err == errInvalidHeader || err == errMsgTooShort
|
return errors.Is(err, errTooShort) || errors.Is(err, errInvalidHeader) || errors.Is(err, errMsgTooShort)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Packet sizes.
|
// Packet sizes.
|
||||||
|
|
|
||||||
|
|
@ -94,7 +94,7 @@ func TestClientSyncTreeBadNode(t *testing.T) {
|
||||||
c := NewClient(Config{Resolver: r, Logger: testlog.Logger(t, log.LvlTrace)})
|
c := NewClient(Config{Resolver: r, Logger: testlog.Logger(t, log.LvlTrace)})
|
||||||
_, err := c.SyncTree("enrtree://AKPYQIUQIL7PSIACI32J7FGZW56E5FKHEFCCOFHILBIMW3M6LWXS2@n")
|
_, err := c.SyncTree("enrtree://AKPYQIUQIL7PSIACI32J7FGZW56E5FKHEFCCOFHILBIMW3M6LWXS2@n")
|
||||||
wantErr := nameError{name: "INDMVBZEEQ4ESVYAKGIYU74EAA.n", err: entryError{typ: "enr", err: errInvalidENR}}
|
wantErr := nameError{name: "INDMVBZEEQ4ESVYAKGIYU74EAA.n", err: entryError{typ: "enr", err: errInvalidENR}}
|
||||||
if err != wantErr {
|
if !errors.Is(wantErr, err) {
|
||||||
t.Fatalf("expected sync error %q, got %q", wantErr, err)
|
t.Fatalf("expected sync error %q, got %q", wantErr, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,8 @@
|
||||||
package dnsdisc
|
package dnsdisc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
|
"github.com/pkg/errors"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
|
@ -54,7 +56,7 @@ func TestParseRoot(t *testing.T) {
|
||||||
if !reflect.DeepEqual(e, test.e) {
|
if !reflect.DeepEqual(e, test.e) {
|
||||||
t.Errorf("test %d: wrong entry %s, want %s", i, spew.Sdump(e), spew.Sdump(test.e))
|
t.Errorf("test %d: wrong entry %s, want %s", i, spew.Sdump(e), spew.Sdump(test.e))
|
||||||
}
|
}
|
||||||
if err != test.err {
|
if !errors.Is(err, test.err) {
|
||||||
t.Errorf("test %d: wrong error %q, want %q", i, err, test.err)
|
t.Errorf("test %d: wrong error %q, want %q", i, err, test.err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -131,7 +133,7 @@ func TestParseEntry(t *testing.T) {
|
||||||
if !reflect.DeepEqual(e, test.e) {
|
if !reflect.DeepEqual(e, test.e) {
|
||||||
t.Errorf("test %d: wrong entry %s, want %s", i, spew.Sdump(e), spew.Sdump(test.e))
|
t.Errorf("test %d: wrong entry %s, want %s", i, spew.Sdump(e), spew.Sdump(test.e))
|
||||||
}
|
}
|
||||||
if err != test.err {
|
if !errors.Is(err, test.err) {
|
||||||
t.Errorf("test %d: wrong error %q, want %q", i, err, test.err)
|
t.Errorf("test %d: wrong error %q, want %q", i, err, test.err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -228,13 +228,13 @@ func decodeRecord(s *rlp.Stream) (dec Record, raw []byte, err error) {
|
||||||
return dec, raw, err
|
return dec, raw, err
|
||||||
}
|
}
|
||||||
if err = s.Decode(&dec.signature); err != nil {
|
if err = s.Decode(&dec.signature); err != nil {
|
||||||
if err == rlp.EOL {
|
if errors.Is(err, rlp.EOL) {
|
||||||
err = errIncompleteList
|
err = errIncompleteList
|
||||||
}
|
}
|
||||||
return dec, raw, err
|
return dec, raw, err
|
||||||
}
|
}
|
||||||
if err = s.Decode(&dec.seq); err != nil {
|
if err = s.Decode(&dec.seq); err != nil {
|
||||||
if err == rlp.EOL {
|
if errors.Is(err, rlp.EOL) {
|
||||||
err = errIncompleteList
|
err = errIncompleteList
|
||||||
}
|
}
|
||||||
return dec, raw, err
|
return dec, raw, err
|
||||||
|
|
@ -244,13 +244,13 @@ func decodeRecord(s *rlp.Stream) (dec Record, raw []byte, err error) {
|
||||||
for i := 0; ; i++ {
|
for i := 0; ; i++ {
|
||||||
var kv pair
|
var kv pair
|
||||||
if err := s.Decode(&kv.k); err != nil {
|
if err := s.Decode(&kv.k); err != nil {
|
||||||
if err == rlp.EOL {
|
if errors.Is(err, rlp.EOL) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
return dec, raw, err
|
return dec, raw, err
|
||||||
}
|
}
|
||||||
if err := s.Decode(&kv.v); err != nil {
|
if err := s.Decode(&kv.v); err != nil {
|
||||||
if err == rlp.EOL {
|
if errors.Is(err, rlp.EOL) {
|
||||||
return dec, raw, errIncompletePair
|
return dec, raw, errIncompletePair
|
||||||
}
|
}
|
||||||
return dec, raw, err
|
return dec, raw, err
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/pkg/errors"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
@ -149,7 +150,7 @@ func TestSortedGetAndSet(t *testing.T) {
|
||||||
func TestDirty(t *testing.T) {
|
func TestDirty(t *testing.T) {
|
||||||
var r Record
|
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)
|
t.Errorf("expected errEncodeUnsigned, got %#v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -164,7 +165,7 @@ func TestDirty(t *testing.T) {
|
||||||
if len(r.signature) != 0 {
|
if len(r.signature) != 0 {
|
||||||
t.Error("signature still set after modification")
|
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)
|
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
|
// set a big value for random key, expect error
|
||||||
r.Set(WithEntry(key, randomString(SizeLimit)))
|
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)
|
t.Fatalf("expected to get errTooBig, got %#v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -274,7 +275,7 @@ func TestDecodeIncomplete(t *testing.T) {
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
var r Record
|
var r Record
|
||||||
err := rlp.DecodeBytes(test.input, &r)
|
err := rlp.DecodeBytes(test.input, &r)
|
||||||
if err != test.err {
|
if !errors.Is(err, test.err) {
|
||||||
t.Errorf("wrong error for %X: %v", test.input, err)
|
t.Errorf("wrong error for %X: %v", test.input, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -175,7 +175,7 @@ type KeyError struct {
|
||||||
|
|
||||||
// Error implements error.
|
// Error implements error.
|
||||||
func (err *KeyError) Error() string {
|
func (err *KeyError) Error() string {
|
||||||
if err.Err == errNotFound {
|
if errors.Is(err.Err, errNotFound) {
|
||||||
return fmt.Sprintf("missing ENR key %q", err.Key)
|
return fmt.Sprintf("missing ENR key %q", err.Key)
|
||||||
}
|
}
|
||||||
return fmt.Sprintf("ENR key %q: %v", err.Key, err.Err)
|
return fmt.Sprintf("ENR key %q: %v", err.Key, err.Err)
|
||||||
|
|
@ -190,7 +190,7 @@ func (err *KeyError) Unwrap() error {
|
||||||
func IsNotFound(err error) bool {
|
func IsNotFound(err error) bool {
|
||||||
var ke *KeyError
|
var ke *KeyError
|
||||||
if errors.As(err, &ke) {
|
if errors.As(err, &ke) {
|
||||||
return ke.Err == errNotFound
|
return errors.Is(ke.Err, errNotFound)
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@ package p2p
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/pkg/errors"
|
||||||
"io"
|
"io"
|
||||||
"runtime"
|
"runtime"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
@ -55,7 +56,7 @@ loop:
|
||||||
go func() {
|
go func() {
|
||||||
if err := SendItems(rw1, 1); err == nil {
|
if err := SendItems(rw1, 1); err == nil {
|
||||||
t.Error("EncodeMsg returned nil error")
|
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)
|
t.Errorf("EncodeMsg returned wrong error: got %v, want %v", err, ErrPipeClosed)
|
||||||
}
|
}
|
||||||
close(done)
|
close(done)
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ package netutil
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/pkg/errors"
|
||||||
"net"
|
"net"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
@ -160,7 +161,7 @@ func TestCheckRelayIP(t *testing.T) {
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
err := CheckRelayIP(parseIP(test.sender), parseIP(test.addr))
|
err := CheckRelayIP(parseIP(test.sender), parseIP(test.addr))
|
||||||
if err != test.want {
|
if !errors.Is(err, test.want) {
|
||||||
t.Errorf("%s from %s: got %q, want %q", test.addr, test.sender, err, test.want)
|
t.Errorf("%s from %s: got %q, want %q", test.addr, test.sender, err, test.want)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -138,7 +138,7 @@ func TestPeerProtoReadMsg(t *testing.T) {
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case err := <-errc:
|
case err := <-errc:
|
||||||
if err != errProtocolReturned {
|
if !errors.Is(err, errProtocolReturned) {
|
||||||
t.Errorf("peer returned error: %v", err)
|
t.Errorf("peer returned error: %v", err)
|
||||||
}
|
}
|
||||||
case <-time.After(2 * time.Second):
|
case <-time.After(2 * time.Second):
|
||||||
|
|
@ -190,7 +190,7 @@ func TestPeerDisconnect(t *testing.T) {
|
||||||
}
|
}
|
||||||
select {
|
select {
|
||||||
case reason := <-disc:
|
case reason := <-disc:
|
||||||
if reason != DiscQuitting {
|
if !errors.Is(reason, DiscQuitting) {
|
||||||
t.Errorf("run returned wrong reason: got %v, want %v", reason, DiscQuitting)
|
t.Errorf("run returned wrong reason: got %v, want %v", reason, DiscQuitting)
|
||||||
}
|
}
|
||||||
case <-time.After(500 * time.Millisecond):
|
case <-time.After(500 * time.Millisecond):
|
||||||
|
|
|
||||||
|
|
@ -280,7 +280,7 @@ func TestServerAtCap(t *testing.T) {
|
||||||
// Try inserting a non-trusted connection.
|
// Try inserting a non-trusted connection.
|
||||||
anotherID := randomID()
|
anotherID := randomID()
|
||||||
c := newconn(anotherID)
|
c := newconn(anotherID)
|
||||||
if err := srv.checkpoint(c, srv.checkpointPostHandshake); err != DiscTooManyPeers {
|
if err := srv.checkpoint(c, srv.checkpointPostHandshake); !errors.Is(err, DiscTooManyPeers) {
|
||||||
t.Error("wrong error for insert:", err)
|
t.Error("wrong error for insert:", err)
|
||||||
}
|
}
|
||||||
// Try inserting a trusted connection.
|
// Try inserting a trusted connection.
|
||||||
|
|
@ -295,7 +295,7 @@ func TestServerAtCap(t *testing.T) {
|
||||||
// Remove from trusted set and try again
|
// Remove from trusted set and try again
|
||||||
srv.RemoveTrustedPeer(newNode(trustedID, ""))
|
srv.RemoveTrustedPeer(newNode(trustedID, ""))
|
||||||
c = newconn(trustedID)
|
c = newconn(trustedID)
|
||||||
if err := srv.checkpoint(c, srv.checkpointPostHandshake); err != DiscTooManyPeers {
|
if err := srv.checkpoint(c, srv.checkpointPostHandshake); !errors.Is(err, DiscTooManyPeers) {
|
||||||
t.Error("wrong error for insert:", err)
|
t.Error("wrong error for insert:", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -345,7 +345,7 @@ func TestServerPeerLimits(t *testing.T) {
|
||||||
dialDest := clientnode
|
dialDest := clientnode
|
||||||
conn, _ := net.Pipe()
|
conn, _ := net.Pipe()
|
||||||
srv.SetupConn(conn, flags, dialDest)
|
srv.SetupConn(conn, flags, dialDest)
|
||||||
if tp.closeErr != DiscTooManyPeers {
|
if !errors.Is(tp.closeErr, DiscTooManyPeers) {
|
||||||
t.Errorf("unexpected close error: %q", tp.closeErr)
|
t.Errorf("unexpected close error: %q", tp.closeErr)
|
||||||
}
|
}
|
||||||
conn.Close()
|
conn.Close()
|
||||||
|
|
@ -355,11 +355,11 @@ func TestServerPeerLimits(t *testing.T) {
|
||||||
// Check that server allows a trusted peer despite being full.
|
// Check that server allows a trusted peer despite being full.
|
||||||
conn, _ = net.Pipe()
|
conn, _ = net.Pipe()
|
||||||
srv.SetupConn(conn, flags, dialDest)
|
srv.SetupConn(conn, flags, dialDest)
|
||||||
if tp.closeErr == DiscTooManyPeers {
|
if errors.Is(tp.closeErr, DiscTooManyPeers) {
|
||||||
t.Errorf("failed to bypass MaxPeers with trusted node: %q", tp.closeErr)
|
t.Errorf("failed to bypass MaxPeers with trusted node: %q", tp.closeErr)
|
||||||
}
|
}
|
||||||
|
|
||||||
if tp.closeErr != DiscUselessPeer {
|
if !errors.Is(tp.closeErr, DiscUselessPeer) {
|
||||||
t.Errorf("unexpected close error: %q", tp.closeErr)
|
t.Errorf("unexpected close error: %q", tp.closeErr)
|
||||||
}
|
}
|
||||||
conn.Close()
|
conn.Close()
|
||||||
|
|
@ -369,7 +369,7 @@ func TestServerPeerLimits(t *testing.T) {
|
||||||
// Check that server is full again.
|
// Check that server is full again.
|
||||||
conn, _ = net.Pipe()
|
conn, _ = net.Pipe()
|
||||||
srv.SetupConn(conn, flags, dialDest)
|
srv.SetupConn(conn, flags, dialDest)
|
||||||
if tp.closeErr != DiscTooManyPeers {
|
if !errors.Is(tp.closeErr, DiscTooManyPeers) {
|
||||||
t.Errorf("unexpected close error: %q", tp.closeErr)
|
t.Errorf("unexpected close error: %q", tp.closeErr)
|
||||||
}
|
}
|
||||||
conn.Close()
|
conn.Close()
|
||||||
|
|
|
||||||
|
|
@ -114,7 +114,7 @@ func (t *rlpxTransport) close(err error) {
|
||||||
// We only bother doing this if the underlying connection supports
|
// We only bother doing this if the underlying connection supports
|
||||||
// setting a timeout tough.
|
// setting a timeout tough.
|
||||||
if t.conn != nil {
|
if t.conn != nil {
|
||||||
if r, ok := err.(DiscReason); ok && r != DiscNetworkError {
|
if r, ok := err.(DiscReason); ok && !errors.Is(r, DiscNetworkError) {
|
||||||
deadline := time.Now().Add(discWriteTimeout)
|
deadline := time.Now().Add(discWriteTimeout)
|
||||||
if err := t.conn.SetWriteDeadline(deadline); err == nil {
|
if err := t.conn.SetWriteDeadline(deadline); err == nil {
|
||||||
// Connection supports write deadline.
|
// Connection supports write deadline.
|
||||||
|
|
|
||||||
|
|
@ -326,7 +326,7 @@ func decodeSliceElems(s *Stream, val reflect.Value, elemdec decoder) error {
|
||||||
val.SetLen(i + 1)
|
val.SetLen(i + 1)
|
||||||
}
|
}
|
||||||
// decode into element
|
// decode into element
|
||||||
if err := elemdec(s, val.Index(i)); err == EOL {
|
if err := elemdec(s, val.Index(i)); errors.Is(err, EOL) {
|
||||||
break
|
break
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
return addErrorContext(err, fmt.Sprint("[", i, "]"))
|
return addErrorContext(err, fmt.Sprint("[", i, "]"))
|
||||||
|
|
@ -345,7 +345,7 @@ func decodeListArray(s *Stream, val reflect.Value, elemdec decoder) error {
|
||||||
vlen := val.Len()
|
vlen := val.Len()
|
||||||
i := 0
|
i := 0
|
||||||
for ; i < vlen; i++ {
|
for ; i < vlen; i++ {
|
||||||
if err := elemdec(s, val.Index(i)); err == EOL {
|
if err := elemdec(s, val.Index(i)); errors.Is(err, EOL) {
|
||||||
break
|
break
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
return addErrorContext(err, fmt.Sprint("[", i, "]"))
|
return addErrorContext(err, fmt.Sprint("[", i, "]"))
|
||||||
|
|
@ -417,7 +417,7 @@ func makeStructDecoder(typ reflect.Type) (decoder, error) {
|
||||||
}
|
}
|
||||||
for i, f := range fields {
|
for i, f := range fields {
|
||||||
err := f.info.decoder(s, val.Field(f.index))
|
err := f.info.decoder(s, val.Field(f.index))
|
||||||
if err == EOL {
|
if errors.Is(err, EOL) {
|
||||||
if f.optional {
|
if f.optional {
|
||||||
// The field is optional, so reaching the end of the list before
|
// The field is optional, so reaching the end of the list before
|
||||||
// reaching the last field is acceptable. All remaining undecoded
|
// reaching the last field is acceptable. All remaining undecoded
|
||||||
|
|
@ -757,7 +757,7 @@ func (s *Stream) uint(maxbits int) (uint64, error) {
|
||||||
}
|
}
|
||||||
v, err := s.readUint(byte(size))
|
v, err := s.readUint(byte(size))
|
||||||
switch {
|
switch {
|
||||||
case err == ErrCanonSize:
|
case errors.Is(err, ErrCanonSize):
|
||||||
// Adjust error because we're not reading a size right now.
|
// Adjust error because we're not reading a size right now.
|
||||||
return 0, ErrCanonInt
|
return 0, ErrCanonInt
|
||||||
case err != nil:
|
case err != nil:
|
||||||
|
|
|
||||||
|
|
@ -250,7 +250,7 @@ func TestStreamList(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := s.Uint(); err != EOL {
|
if _, err := s.Uint(); !errors.Is(err, EOL) {
|
||||||
t.Errorf("Uint error mismatch, got %v, want %v", err, EOL)
|
t.Errorf("Uint error mismatch, got %v, want %v", err, EOL)
|
||||||
}
|
}
|
||||||
if err = s.ListEnd(); err != nil {
|
if err = s.ListEnd(); err != nil {
|
||||||
|
|
@ -331,16 +331,16 @@ func TestStreamReadBytes(t *testing.T) {
|
||||||
func TestDecodeErrors(t *testing.T) {
|
func TestDecodeErrors(t *testing.T) {
|
||||||
r := bytes.NewReader(nil)
|
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)
|
t.Errorf("Decode(r, nil) error mismatch, got %q, want %q", err, errDecodeIntoNil)
|
||||||
}
|
}
|
||||||
|
|
||||||
var nilptr *struct{}
|
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)
|
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)
|
t.Errorf("Decode(r, struct{}{}) error mismatch, got %q, want %q", err, errNoPointer)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -129,7 +129,7 @@ func TestSplitUint64(t *testing.T) {
|
||||||
if !bytes.Equal(rest, unhex(test.rest)) {
|
if !bytes.Equal(rest, unhex(test.rest)) {
|
||||||
t.Errorf("test %d: rest mismatch: got %x, want %s (input %q)", i, rest, test.rest, test.input)
|
t.Errorf("test %d: rest mismatch: got %x, want %s (input %q)", i, rest, test.rest, test.input)
|
||||||
}
|
}
|
||||||
if err != test.err {
|
if !errors.Is(err, test.err) {
|
||||||
t.Errorf("test %d: error mismatch: got %q, want %q", i, err, test.err)
|
t.Errorf("test %d: error mismatch: got %q, want %q", i, err, test.err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -213,7 +213,7 @@ func TestSplit(t *testing.T) {
|
||||||
if !bytes.Equal(rest, unhex(test.rest)) {
|
if !bytes.Equal(rest, unhex(test.rest)) {
|
||||||
t.Errorf("test %d: rest mismatch: got %x, want %s", i, rest, test.rest)
|
t.Errorf("test %d: rest mismatch: got %x, want %s", i, rest, test.rest)
|
||||||
}
|
}
|
||||||
if err != test.err {
|
if !errors.Is(err, test.err) {
|
||||||
t.Errorf("test %d: error mismatch: got %q, want %q", i, err, test.err)
|
t.Errorf("test %d: error mismatch: got %q, want %q", i, err, test.err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -251,7 +251,7 @@ func TestReadSize(t *testing.T) {
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
size, err := readSize(unhex(test.input), test.slen)
|
size, err := readSize(unhex(test.input), test.slen)
|
||||||
if err != test.err {
|
if !errors.Is(err, test.err) {
|
||||||
t.Errorf("readSize(%s, %d): error mismatch: got %q, want %q", test.input, test.slen, err, test.err)
|
t.Errorf("readSize(%s, %d): error mismatch: got %q, want %q", test.input, test.slen, err, test.err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -211,7 +211,7 @@ func TestClientBatchRequest_len(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for i, elem := range batch[2:] {
|
for i, elem := range batch[2:] {
|
||||||
if elem.Error != ErrMissingBatchResponse {
|
if !errors.Is(elem.Error, ErrMissingBatchResponse) {
|
||||||
t.Errorf("wrong error %q for batch element %d", elem.Error, i+2)
|
t.Errorf("wrong error %q for batch element %d", elem.Error, i+2)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -239,7 +239,7 @@ func TestClientBatchRequest_len(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for i, elem := range batch[1:] {
|
for i, elem := range batch[1:] {
|
||||||
if elem.Error != ErrMissingBatchResponse {
|
if !errors.Is(elem.Error, ErrMissingBatchResponse) {
|
||||||
t.Errorf("wrong error %q for batch element %d", elem.Error, i+2)
|
t.Errorf("wrong error %q for batch element %d", elem.Error, i+2)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -277,7 +277,7 @@ func TestClientBatchRequestLimit(t *testing.T) {
|
||||||
|
|
||||||
// Check that remaining response batch elements are reported as absent.
|
// Check that remaining response batch elements are reported as absent.
|
||||||
for i, elem := range batch[1:] {
|
for i, elem := range batch[1:] {
|
||||||
if elem.Error != ErrMissingBatchResponse {
|
if !errors.Is(elem.Error, ErrMissingBatchResponse) {
|
||||||
t.Fatalf("batch elem %d has unexpected error: %v", i+1, elem.Error)
|
t.Fatalf("batch elem %d has unexpected error: %v", i+1, elem.Error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -633,7 +633,7 @@ func TestClientNotificationStorm(t *testing.T) {
|
||||||
t.Fatalf("(%d/%d) unexpected value %d", i, count, val)
|
t.Fatalf("(%d/%d) unexpected value %d", i, count, val)
|
||||||
}
|
}
|
||||||
case err := <-sub.Err():
|
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)
|
t.Fatalf("(%d/%d) got error %q, want %q", i, count, err, ErrSubscriptionQueueOverflow)
|
||||||
} else if !wantError {
|
} else if !wantError {
|
||||||
t.Fatalf("(%d/%d) got unexpected error %q", i, count, err)
|
t.Fatalf("(%d/%d) got unexpected error %q", i, count, err)
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@ package rpc
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/pkg/errors"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
@ -234,12 +235,12 @@ func TestNewContextWithHeaders(t *testing.T) {
|
||||||
ctx3 := NewContextWithHeaders(ctx2, newHdr("key-2", "val-2"))
|
ctx3 := NewContextWithHeaders(ctx2, newHdr("key-2", "val-2"))
|
||||||
|
|
||||||
expectedHeaders = 3
|
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)
|
t.Error("call failed", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
expectedHeaders = 2
|
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)
|
t.Error("call failed:", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -304,7 +304,7 @@ func (sub *ClientSubscription) run() {
|
||||||
|
|
||||||
// Send the error.
|
// Send the error.
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == ErrClientQuit {
|
if errors.Is(err, ErrClientQuit) {
|
||||||
// ErrClientQuit gets here when Client.Close is called. This is reported as a
|
// ErrClientQuit gets here when Client.Close is called. This is reported as a
|
||||||
// nil error because it's not an error, but we can't close sub.err here.
|
// nil error because it's not an error, but we can't close sub.err here.
|
||||||
err = nil
|
err = nil
|
||||||
|
|
@ -340,7 +340,7 @@ func (sub *ClientSubscription) forward() (unsubscribeServer bool, err error) {
|
||||||
if !recv.IsNil() {
|
if !recv.IsNil() {
|
||||||
err = recv.Interface().(error)
|
err = recv.Interface().(error)
|
||||||
}
|
}
|
||||||
if err == errUnsubscribed {
|
if errors.Is(err, errUnsubscribed) {
|
||||||
// Exiting because Unsubscribe was called, unsubscribe on server.
|
// Exiting because Unsubscribe was called, unsubscribe on server.
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -159,7 +159,7 @@ func TestWebsocketLargeRead(t *testing.T) {
|
||||||
// Check over limit
|
// Check over limit
|
||||||
if overLimit > 0 {
|
if overLimit > 0 {
|
||||||
err = client.Call(&res, "test_repeat", "A", expLimit+1)
|
err = client.Call(&res, "test_repeat", "A", expLimit+1)
|
||||||
if err == nil || err != websocket.ErrReadLimit {
|
if err == nil || !errors.Is(err, websocket.ErrReadLimit) {
|
||||||
t.Fatalf("wrong error with limit %d: %v expecting %v", expLimit, err, websocket.ErrReadLimit)
|
t.Fatalf("wrong error with limit %d: %v expecting %v", expLimit, err, websocket.ErrReadLimit)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -332,7 +332,7 @@ func (api *SignerAPI) startUSBListener() {
|
||||||
for _, wallet := range am.Wallets() {
|
for _, wallet := range am.Wallets() {
|
||||||
if err := wallet.Open(""); err != nil {
|
if err := wallet.Open(""); err != nil {
|
||||||
log.Warn("Failed to open wallet", "url", wallet.URL(), "err", err)
|
log.Warn("Failed to open wallet", "url", wallet.URL(), "err", err)
|
||||||
if err == usbwallet.ErrTrezorPINNeeded {
|
if errors.Is(err, usbwallet.ErrTrezorPINNeeded) {
|
||||||
go api.openTrezor(wallet.URL())
|
go api.openTrezor(wallet.URL())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -348,7 +348,7 @@ func (api *SignerAPI) derivationLoop(events chan accounts.WalletEvent) {
|
||||||
case accounts.WalletArrived:
|
case accounts.WalletArrived:
|
||||||
if err := event.Wallet.Open(""); err != nil {
|
if err := event.Wallet.Open(""); err != nil {
|
||||||
log.Warn("New wallet appeared, failed to open", "url", event.Wallet.URL(), "err", err)
|
log.Warn("New wallet appeared, failed to open", "url", event.Wallet.URL(), "err", err)
|
||||||
if err == usbwallet.ErrTrezorPINNeeded {
|
if errors.Is(err, usbwallet.ErrTrezorPINNeeded) {
|
||||||
go api.openTrezor(event.Wallet.URL())
|
go api.openTrezor(event.Wallet.URL())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,9 @@ package core_test
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/pkg/errors"
|
||||||
"math/big"
|
"math/big"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
@ -155,7 +157,7 @@ func failCreateAccountWithPassword(ui *headlessUi, api *core.SignerAPI, password
|
||||||
func failCreateAccount(ui *headlessUi, api *core.SignerAPI, t *testing.T) {
|
func failCreateAccount(ui *headlessUi, api *core.SignerAPI, t *testing.T) {
|
||||||
ui.approveCh <- "N"
|
ui.approveCh <- "N"
|
||||||
addr, err := api.New(context.Background())
|
addr, err := api.New(context.Background())
|
||||||
if err != core.ErrRequestDenied {
|
if !errors.Is(err, core.ErrRequestDenied) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if addr != (common.Address{}) {
|
if addr != (common.Address{}) {
|
||||||
|
|
@ -212,7 +214,7 @@ func TestNewAcc(t *testing.T) {
|
||||||
if len(list) != 0 {
|
if len(list) != 0 {
|
||||||
t.Fatalf("List should be empty")
|
t.Fatalf("List should be empty")
|
||||||
}
|
}
|
||||||
if err != core.ErrRequestDenied {
|
if !errors.Is(err, core.ErrRequestDenied) {
|
||||||
t.Fatal("Expected deny")
|
t.Fatal("Expected deny")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -264,7 +266,7 @@ func TestSignTx(t *testing.T) {
|
||||||
if res != nil {
|
if res != nil {
|
||||||
t.Errorf("Expected nil-response, got %v", res)
|
t.Errorf("Expected nil-response, got %v", res)
|
||||||
}
|
}
|
||||||
if err != keystore.ErrDecrypt {
|
if !errors.Is(err, keystore.ErrDecrypt) {
|
||||||
t.Errorf("Expected ErrLocked! %v", err)
|
t.Errorf("Expected ErrLocked! %v", err)
|
||||||
}
|
}
|
||||||
control.approveCh <- "No way"
|
control.approveCh <- "No way"
|
||||||
|
|
@ -272,7 +274,7 @@ func TestSignTx(t *testing.T) {
|
||||||
if res != nil {
|
if res != nil {
|
||||||
t.Errorf("Expected nil-response, got %v", res)
|
t.Errorf("Expected nil-response, got %v", res)
|
||||||
}
|
}
|
||||||
if err != core.ErrRequestDenied {
|
if !errors.Is(err, core.ErrRequestDenied) {
|
||||||
t.Errorf("Expected ErrRequestDenied! %v", err)
|
t.Errorf("Expected ErrRequestDenied! %v", err)
|
||||||
}
|
}
|
||||||
// Sign with correct password
|
// Sign with correct password
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/pkg/errors"
|
||||||
"math/big"
|
"math/big"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
|
@ -201,7 +202,7 @@ func TestSignData(t *testing.T) {
|
||||||
if signature != nil {
|
if signature != nil {
|
||||||
t.Errorf("Expected nil-data, got %x", signature)
|
t.Errorf("Expected nil-data, got %x", signature)
|
||||||
}
|
}
|
||||||
if err != keystore.ErrDecrypt {
|
if !errors.Is(err, keystore.ErrDecrypt) {
|
||||||
t.Errorf("Expected ErrLocked! '%v'", err)
|
t.Errorf("Expected ErrLocked! '%v'", err)
|
||||||
}
|
}
|
||||||
control.approveCh <- "No way"
|
control.approveCh <- "No way"
|
||||||
|
|
@ -209,7 +210,7 @@ func TestSignData(t *testing.T) {
|
||||||
if signature != nil {
|
if signature != nil {
|
||||||
t.Errorf("Expected nil-data, got %x", signature)
|
t.Errorf("Expected nil-data, got %x", signature)
|
||||||
}
|
}
|
||||||
if err != core.ErrRequestDenied {
|
if !errors.Is(err, core.ErrRequestDenied) {
|
||||||
t.Errorf("Expected ErrRequestDenied! '%v'", err)
|
t.Errorf("Expected ErrRequestDenied! '%v'", err)
|
||||||
}
|
}
|
||||||
// text/plain
|
// text/plain
|
||||||
|
|
|
||||||
|
|
@ -268,7 +268,7 @@ func (it *nodeIterator) NodeBlob() []byte {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (it *nodeIterator) Error() error {
|
func (it *nodeIterator) Error() error {
|
||||||
if it.err == errIteratorEnd {
|
if errors.Is(it.err, errIteratorEnd) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if seek, ok := it.err.(seekError); ok {
|
if seek, ok := it.err.(seekError); ok {
|
||||||
|
|
@ -282,7 +282,7 @@ func (it *nodeIterator) Error() error {
|
||||||
// sets the Error field to the encountered failure. If `descend` is false,
|
// sets the Error field to the encountered failure. If `descend` is false,
|
||||||
// skips iterating over any subnodes of the current node.
|
// skips iterating over any subnodes of the current node.
|
||||||
func (it *nodeIterator) Next(descend bool) bool {
|
func (it *nodeIterator) Next(descend bool) bool {
|
||||||
if it.err == errIteratorEnd {
|
if errors.Is(it.err, errIteratorEnd) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if seek, ok := it.err.(seekError); ok {
|
if seek, ok := it.err.(seekError); ok {
|
||||||
|
|
@ -307,7 +307,7 @@ func (it *nodeIterator) seek(prefix []byte) error {
|
||||||
// Move forward until we're just before the closest match to key.
|
// Move forward until we're just before the closest match to key.
|
||||||
for {
|
for {
|
||||||
state, parentIndex, path, err := it.peekSeek(key)
|
state, parentIndex, path, err := it.peekSeek(key)
|
||||||
if err == errIteratorEnd {
|
if errors.Is(err, errIteratorEnd) {
|
||||||
return errIteratorEnd
|
return errIteratorEnd
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
return seekError{prefix, err}
|
return seekError{prefix, err}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue