forked from cerc-io/plugeth
all: more linters (#24783)
This enables the following linters - typecheck - unused - staticcheck - bidichk - durationcheck - exportloopref - gosec WIth a few exceptions. - We use a deprecated protobuf in trezor. I didn't want to mess with that, since I cannot meaningfully test any changes there. - The deprecated TypeMux is used in a few places still, so the warning for it is silenced for now. - Using string type in context.WithValue is apparently wrong, one should use a custom type, to prevent collisions between different places in the hierarchy of callers. That should be fixed at some point, but may require some attention. - The warnings for using weak random generator are squashed, since we use a lot of random without need for cryptographic guarantees.
This commit is contained in:
@@ -104,6 +104,7 @@ func (s *Suite) TestSnapGetAccountRange(t *utesting.T) {
|
||||
// Max bytes: 0. Expect to deliver one account.
|
||||
{0, root, zero, ffHash, 1, firstKey, firstKey},
|
||||
} {
|
||||
tc := tc
|
||||
if err := s.snapGetAccountRange(t, &tc); err != nil {
|
||||
t.Errorf("test %d \n root: %x\n range: %#x - %#x\n bytes: %d\nfailed: %v", i, tc.root, tc.origin, tc.limit, tc.nBytes, err)
|
||||
}
|
||||
@@ -194,6 +195,7 @@ func (s *Suite) TestSnapGetStorageRanges(t *utesting.T) {
|
||||
expSlots: 2,
|
||||
},
|
||||
} {
|
||||
tc := tc
|
||||
if err := s.snapGetStorageRanges(t, &tc); err != nil {
|
||||
t.Errorf("test %d \n root: %x\n range: %#x - %#x\n bytes: %d\n #accounts: %d\nfailed: %v",
|
||||
i, tc.root, tc.origin, tc.limit, tc.nBytes, len(tc.accounts), err)
|
||||
@@ -291,6 +293,7 @@ func (s *Suite) TestSnapGetByteCodes(t *utesting.T) {
|
||||
expHashes: 4,
|
||||
},
|
||||
} {
|
||||
tc := tc
|
||||
if err := s.snapGetByteCodes(t, &tc); err != nil {
|
||||
t.Errorf("test %d \n bytes: %d\n #hashes: %d\nfailed: %v", i, tc.nBytes, len(tc.hashes), err)
|
||||
}
|
||||
@@ -436,6 +439,7 @@ func (s *Suite) TestSnapTrieNodes(t *utesting.T) {
|
||||
},
|
||||
},
|
||||
} {
|
||||
tc := tc
|
||||
if err := s.snapGetTrieNodes(t, &tc); err != nil {
|
||||
t.Errorf("test %d \n #hashes %x\n root: %#x\n bytes: %d\nfailed: %v", i, len(tc.expHashes), tc.root, tc.nBytes, err)
|
||||
}
|
||||
|
||||
@@ -60,11 +60,9 @@ type conn struct {
|
||||
remoteAddr *net.UDPAddr
|
||||
listeners []net.PacketConn
|
||||
|
||||
log logger
|
||||
codec *v5wire.Codec
|
||||
lastRequest v5wire.Packet
|
||||
lastChallenge *v5wire.Whoareyou
|
||||
idCounter uint32
|
||||
log logger
|
||||
codec *v5wire.Codec
|
||||
idCounter uint32
|
||||
}
|
||||
|
||||
type logger interface {
|
||||
|
||||
@@ -239,14 +239,15 @@ func ambiguousAddrRecovery(ks *keystore.KeyStore, err *keystore.AmbiguousAddrErr
|
||||
}
|
||||
fmt.Println("Testing your password against all of them...")
|
||||
var match *accounts.Account
|
||||
for _, a := range err.Matches {
|
||||
if err := ks.Unlock(a, auth); err == nil {
|
||||
match = &a
|
||||
for i, a := range err.Matches {
|
||||
if e := ks.Unlock(a, auth); e == nil {
|
||||
match = &err.Matches[i]
|
||||
break
|
||||
}
|
||||
}
|
||||
if match == nil {
|
||||
utils.Fatalf("None of the listed files could be unlocked.")
|
||||
return accounts.Account{}
|
||||
}
|
||||
fmt.Printf("Your password unlocked %s\n", match.URL)
|
||||
fmt.Println("In order to avoid this warning, you need to remove the following duplicate key files:")
|
||||
|
||||
@@ -81,41 +81,6 @@ func (g *gethrpc) getNodeInfo() *p2p.NodeInfo {
|
||||
return g.nodeInfo
|
||||
}
|
||||
|
||||
func (g *gethrpc) waitSynced() {
|
||||
// Check if it's synced now
|
||||
var result interface{}
|
||||
g.callRPC(&result, "eth_syncing")
|
||||
syncing, ok := result.(bool)
|
||||
if ok && !syncing {
|
||||
g.geth.Logf("%v already synced", g.name)
|
||||
return
|
||||
}
|
||||
|
||||
// Actually wait, subscribe to the event
|
||||
ch := make(chan interface{})
|
||||
sub, err := g.rpc.Subscribe(context.Background(), "eth", ch, "syncing")
|
||||
if err != nil {
|
||||
g.geth.Fatalf("%v syncing: %v", g.name, err)
|
||||
}
|
||||
defer sub.Unsubscribe()
|
||||
timeout := time.After(4 * time.Second)
|
||||
select {
|
||||
case ev := <-ch:
|
||||
g.geth.Log("'syncing' event", ev)
|
||||
syncing, ok := ev.(bool)
|
||||
if ok && !syncing {
|
||||
break
|
||||
}
|
||||
g.geth.Log("Other 'syncing' event", ev)
|
||||
case err := <-sub.Err():
|
||||
g.geth.Fatalf("%v notification: %v", g.name, err)
|
||||
break
|
||||
case <-timeout:
|
||||
g.geth.Fatalf("%v timeout syncing", g.name)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
// ipcEndpoint resolves an IPC endpoint based on a configured value, taking into
|
||||
// account the set data folders as well as the designated platform we're currently
|
||||
// running on.
|
||||
|
||||
+3
-3
@@ -30,7 +30,7 @@ import (
|
||||
"github.com/ethereum/go-ethereum/log"
|
||||
"golang.org/x/crypto/ssh"
|
||||
"golang.org/x/crypto/ssh/agent"
|
||||
"golang.org/x/crypto/ssh/terminal"
|
||||
"golang.org/x/term"
|
||||
)
|
||||
|
||||
// sshClient is a small wrapper around Go's SSH client with a few utility methods
|
||||
@@ -101,7 +101,7 @@ func dial(server string, pubkey []byte) (*sshClient, error) {
|
||||
key, err := ssh.ParsePrivateKey(buf)
|
||||
if err != nil {
|
||||
fmt.Printf("What's the decryption password for %s? (won't be echoed)\n>", path)
|
||||
blob, err := terminal.ReadPassword(int(os.Stdin.Fd()))
|
||||
blob, err := term.ReadPassword(int(os.Stdin.Fd()))
|
||||
fmt.Println()
|
||||
if err != nil {
|
||||
log.Warn("Couldn't read password", "err", err)
|
||||
@@ -118,7 +118,7 @@ func dial(server string, pubkey []byte) (*sshClient, error) {
|
||||
}
|
||||
auths = append(auths, ssh.PasswordCallback(func() (string, error) {
|
||||
fmt.Printf("What's the login password for %s at %s? (won't be echoed)\n> ", username, server)
|
||||
blob, err := terminal.ReadPassword(int(os.Stdin.Fd()))
|
||||
blob, err := term.ReadPassword(int(os.Stdin.Fd()))
|
||||
|
||||
fmt.Println()
|
||||
return string(blob), err
|
||||
|
||||
@@ -34,7 +34,7 @@ import (
|
||||
"github.com/ethereum/go-ethereum/core"
|
||||
"github.com/ethereum/go-ethereum/log"
|
||||
"github.com/peterh/liner"
|
||||
"golang.org/x/crypto/ssh/terminal"
|
||||
"golang.org/x/term"
|
||||
)
|
||||
|
||||
// config contains all the configurations needed by puppeth that should be saved
|
||||
@@ -228,7 +228,7 @@ func (w *wizard) readDefaultFloat(def float64) float64 {
|
||||
// line and returns it. The input will not be echoed.
|
||||
func (w *wizard) readPassword() string {
|
||||
fmt.Printf("> ")
|
||||
text, err := terminal.ReadPassword(int(os.Stdin.Fd()))
|
||||
text, err := term.ReadPassword(int(os.Stdin.Fd()))
|
||||
if err != nil {
|
||||
log.Crit("Failed to read password", "err", err)
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ func getFreeDiskSpace(path string) (uint64, error) {
|
||||
|
||||
// Available blocks * size per block = available space in bytes
|
||||
var bavail = stat.Bavail
|
||||
// nolint:staticcheck
|
||||
if stat.Bavail < 0 {
|
||||
// FreeBSD can have a negative number of blocks available
|
||||
// because of the grace limit.
|
||||
|
||||
Reference in New Issue
Block a user