From 5c290cf01fc234e6776ba5335312f58f38a53625 Mon Sep 17 00:00:00 2001 From: Adam Babik Date: Wed, 12 Jun 2019 11:22:29 +0200 Subject: [PATCH] fix linter errors --- cmd/statusd/main.go | 4 +--- extkeys/hdkey_test.go | 2 +- services/rpcfilters/api_test.go | 4 ++-- services/rpcfilters/latest_logs_test.go | 26 +++++++++++----------- services/shhext/api.go | 3 --- services/shhext/chat/crypto/crypto.go | 7 ++---- services/shhext/chat/crypto/crypto_test.go | 2 +- services/shhext/mailservers/connmanager.go | 2 +- services/shhext/service.go | 2 +- 9 files changed, 22 insertions(+), 30 deletions(-) diff --git a/cmd/statusd/main.go b/cmd/statusd/main.go index 1199238b8a1..8795102e87f 100644 --- a/cmd/statusd/main.go +++ b/cmd/statusd/main.go @@ -95,9 +95,7 @@ func main() { ) if err != nil { printUsage() - if err != nil { - logger.Error(err.Error()) - } + logger.Error(err.Error()) os.Exit(1) } diff --git a/extkeys/hdkey_test.go b/extkeys/hdkey_test.go index e29bf29f6ff..578c36e1150 100644 --- a/extkeys/hdkey_test.go +++ b/extkeys/hdkey_test.go @@ -617,7 +617,7 @@ func TestChildForPurpose(t *testing.T) { // Check that the key generated by ChildForPurpose with KeyPurposeChat is different from the BIP44 if walletChild.String() == chatChild.String() { - t.Errorf("wrong chat key. expected to be diferrent from the wallet key") + t.Errorf("wrong chat key. expected to be different from the wallet key") } } diff --git a/services/rpcfilters/api_test.go b/services/rpcfilters/api_test.go index c4ded952381..9ddb63a070c 100644 --- a/services/rpcfilters/api_test.go +++ b/services/rpcfilters/api_test.go @@ -94,8 +94,8 @@ func TestGetFilterLogs(t *testing.T) { logs, err := api.GetFilterLogs(context.TODO(), id) require.NoError(t, err) require.Empty(t, logs) - require.Len(t, tracker.criterias, 1) - rst, err := hexutil.DecodeBig(tracker.criterias[0]["fromBlock"].(string)) + require.Len(t, tracker.criteria, 1) + rst, err := hexutil.DecodeBig(tracker.criteria[0]["fromBlock"].(string)) require.NoError(t, err) require.Equal(t, block, rst) } diff --git a/services/rpcfilters/latest_logs_test.go b/services/rpcfilters/latest_logs_test.go index 89d70053e01..8abcbd2be86 100644 --- a/services/rpcfilters/latest_logs_test.go +++ b/services/rpcfilters/latest_logs_test.go @@ -17,10 +17,10 @@ import ( ) type callTracker struct { - mu sync.Mutex - calls int - reply [][]types.Log - criterias []map[string]interface{} + mu sync.Mutex + calls int + reply [][]types.Log + criteria []map[string]interface{} } func (c *callTracker) CallContext(ctx context.Context, result interface{}, method string, args ...interface{}) error { @@ -31,7 +31,7 @@ func (c *callTracker) CallContext(ctx context.Context, result interface{}, metho return errors.New("unexpected length of args") } crit := args[0].(map[string]interface{}) - c.criterias = append(c.criterias, crit) + c.criteria = append(c.criteria, crit) select { case <-ctx.Done(): return errors.New("context canceled") @@ -73,7 +73,7 @@ func runLogsFetcherTest(t *testing.T, f *logsFilter, replies [][]types.Log, quer } }() wg.Wait() - require.Len(t, c.criterias, queries) + require.Len(t, c.criteria, queries) return &c } @@ -90,8 +90,8 @@ func TestLogsFetcherAdjusted(t *testing.T) { {BlockNumber: 11}, {BlockNumber: 12}, } c := runLogsFetcherTest(t, f, [][]types.Log{logs}, 2) - require.Equal(t, hexutil.EncodeBig(big.NewInt(10)), c.criterias[0]["fromBlock"]) - require.Equal(t, c.criterias[1]["fromBlock"], "latest") + require.Equal(t, hexutil.EncodeBig(big.NewInt(10)), c.criteria[0]["fromBlock"]) + require.Equal(t, c.criteria[1]["fromBlock"], "latest") } func TestAdjustedDueToReorg(t *testing.T) { @@ -110,9 +110,9 @@ func TestAdjustedDueToReorg(t *testing.T) { {BlockNumber: 12, BlockHash: common.Hash{2, 2}}, } c := runLogsFetcherTest(t, f, [][]types.Log{logs, reorg}, 3) - require.Equal(t, hexutil.EncodeBig(big.NewInt(10)), c.criterias[0]["fromBlock"]) - require.Equal(t, "latest", c.criterias[1]["fromBlock"]) - require.Equal(t, hexutil.EncodeBig(big.NewInt(11)), c.criterias[2]["fromBlock"]) + require.Equal(t, hexutil.EncodeBig(big.NewInt(10)), c.criteria[0]["fromBlock"]) + require.Equal(t, "latest", c.criteria[1]["fromBlock"]) + require.Equal(t, hexutil.EncodeBig(big.NewInt(11)), c.criteria[2]["fromBlock"]) } func TestLogsFetcherCanceledContext(t *testing.T) { @@ -127,6 +127,6 @@ func TestLogsFetcherCanceledContext(t *testing.T) { } cancel() c := runLogsFetcherTest(t, f, [][]types.Log{make([]types.Log, 2)}, 2) - require.Equal(t, hexutil.EncodeBig(big.NewInt(10)), c.criterias[0]["fromBlock"]) - require.Equal(t, hexutil.EncodeBig(big.NewInt(10)), c.criterias[1]["fromBlock"]) + require.Equal(t, hexutil.EncodeBig(big.NewInt(10)), c.criteria[0]["fromBlock"]) + require.Equal(t, hexutil.EncodeBig(big.NewInt(10)), c.criteria[1]["fromBlock"]) } diff --git a/services/shhext/api.go b/services/shhext/api.go index 64c29288025..f845b87713e 100644 --- a/services/shhext/api.go +++ b/services/shhext/api.go @@ -650,9 +650,6 @@ func (api *PublicAPI) SendPairingMessage(ctx context.Context, msg chat.SendDirec } msg.PubKey = crypto.FromECDSAPub(&privateKey.PublicKey) - if err != nil { - return nil, err - } protocolMessage, err := api.service.protocol.BuildDHMessage(privateKey, &privateKey.PublicKey, msg.Payload) if err != nil { diff --git a/services/shhext/chat/crypto/crypto.go b/services/shhext/chat/crypto/crypto.go index fed51cfe036..f650e2c7f01 100644 --- a/services/shhext/chat/crypto/crypto.go +++ b/services/shhext/chat/crypto/crypto.go @@ -8,6 +8,7 @@ import ( "encoding/hex" "errors" "fmt" + "github.com/ethereum/go-ethereum/crypto" ) @@ -103,11 +104,7 @@ func EncryptSymmetric(key, plaintext []byte) ([]byte, error) { return nil, err } - encrypted, err := aesgcm.Seal(nil, salt, plaintext, nil), nil - if err != nil { - return nil, err - } - + encrypted := aesgcm.Seal(nil, salt, plaintext, nil) return append(encrypted, salt...), nil } diff --git a/services/shhext/chat/crypto/crypto_test.go b/services/shhext/chat/crypto/crypto_test.go index e9aef3d0082..ae11f4ba26d 100644 --- a/services/shhext/chat/crypto/crypto_test.go +++ b/services/shhext/chat/crypto/crypto_test.go @@ -115,7 +115,7 @@ func TestSymmetricEncryption(t *testing.T) { t, 32, len(cyphertext1), - "Cyphertext with the correct lenght should be generated") + "Cyphertext with the correct length should be generated") require.NotEqualf( t, diff --git a/services/shhext/mailservers/connmanager.go b/services/shhext/mailservers/connmanager.go index e8b07bc4f34..4970dde10a1 100644 --- a/services/shhext/mailservers/connmanager.go +++ b/services/shhext/mailservers/connmanager.go @@ -122,7 +122,7 @@ func (ps *ConnectionManager) Start() { continue } failuresPerServer[ev.Peer]++ - log.Debug("request to a mail server expired, disconncet a peer", "address", ev.Peer) + log.Debug("request to a mail server expired, disconnect a peer", "address", ev.Peer) if failuresPerServer[ev.Peer] >= ps.maxFailures { state.nodeDisconnected(ev.Peer) } diff --git a/services/shhext/service.go b/services/shhext/service.go index f27d3a5205e..e9fe2d9fa9a 100644 --- a/services/shhext/service.go +++ b/services/shhext/service.go @@ -30,7 +30,7 @@ const ( defaultTimeoutWaitAdded = 5 * time.Second ) -var errProtocolNotInitialized = errors.New("procotol is not initialized") +var errProtocolNotInitialized = errors.New("protocol is not initialized") // EnvelopeEventsHandler used for two different event types. type EnvelopeEventsHandler interface {