Skip to content

Commit 5d21667

Browse files
gballetfjl
authored andcommitted
tests, signer: remove staticcheck warnings (#20364)
1 parent fdff182 commit 5d21667

File tree

12 files changed

+60
-68
lines changed

12 files changed

+60
-68
lines changed

signer/core/api.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ type (
269269
}
270270
)
271271

272-
var ErrRequestDenied = errors.New("Request denied")
272+
var ErrRequestDenied = errors.New("request denied")
273273

274274
// NewSignerAPI creates a new API that can be used for Account management.
275275
// ksLocation specifies the directory where to store the password protected private
@@ -552,6 +552,9 @@ func (api *SignerAPI) SignTransaction(ctx context.Context, args SendTxArgs, meth
552552
}
553553

554554
rlpdata, err := rlp.EncodeToBytes(signedTx)
555+
if err != nil {
556+
return nil, err
557+
}
555558
response := ethapi.SignTransactionResult{Raw: rlpdata, Tx: signedTx}
556559

557560
// Finally, send the signed tx to the UI

signer/core/api_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func (ui *headlessUi) ApproveTx(request *core.SignTxRequest) (core.SignTxRespons
7171
}
7272

7373
func (ui *headlessUi) ApproveSignData(request *core.SignDataRequest) (core.SignDataResponse, error) {
74-
approved := "Y" == <-ui.approveCh
74+
approved := (<-ui.approveCh == "Y")
7575
return core.SignDataResponse{approved}, nil
7676
}
7777

@@ -91,7 +91,7 @@ func (ui *headlessUi) ApproveListing(request *core.ListRequest) (core.ListRespon
9191
}
9292

9393
func (ui *headlessUi) ApproveNewAccount(request *core.NewAccountRequest) (core.NewAccountResponse, error) {
94-
if "Y" == <-ui.approveCh {
94+
if <-ui.approveCh == "Y" {
9595
return core.NewAccountResponse{true}, nil
9696
}
9797
return core.NewAccountResponse{false}, nil

signer/core/cliui.go

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -58,34 +58,6 @@ func (ui *CommandlineUI) readString() string {
5858
}
5959
}
6060

61-
// readPassword reads a single line from stdin, trimming it from the trailing new
62-
// line and returns it. The input will not be echoed.
63-
func (ui *CommandlineUI) readPassword() string {
64-
fmt.Printf("Enter password to approve:\n")
65-
fmt.Printf("> ")
66-
67-
text, err := terminal.ReadPassword(int(os.Stdin.Fd()))
68-
if err != nil {
69-
log.Crit("Failed to read password", "err", err)
70-
}
71-
fmt.Println()
72-
fmt.Println("-----------------------")
73-
return string(text)
74-
}
75-
76-
// readPassword reads a single line from stdin, trimming it from the trailing new
77-
// line and returns it. The input will not be echoed.
78-
func (ui *CommandlineUI) readPasswordText(inputstring string) string {
79-
fmt.Printf("Enter %s:\n", inputstring)
80-
fmt.Printf("> ")
81-
text, err := terminal.ReadPassword(int(os.Stdin.Fd()))
82-
if err != nil {
83-
log.Crit("Failed to read password", "err", err)
84-
}
85-
fmt.Println("-----------------------")
86-
return string(text)
87-
}
88-
8961
func (ui *CommandlineUI) OnInputRequired(info UserInputRequest) (UserInputResponse, error) {
9062

9163
fmt.Printf("## %s\n\n%s\n", info.Title, info.Prompt)

signer/core/stdioui.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package core
1818

1919
import (
2020
"context"
21-
"sync"
2221

2322
"github.com/ethereum/go-ethereum/internal/ethapi"
2423
"github.com/ethereum/go-ethereum/log"
@@ -27,7 +26,6 @@ import (
2726

2827
type StdIOUI struct {
2928
client rpc.Client
30-
mu sync.Mutex
3129
}
3230

3331
func NewStdIOUI() *StdIOUI {

signer/core/types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func (v *ValidationMessages) getWarnings() error {
6060
}
6161
}
6262
if len(messages) > 0 {
63-
return fmt.Errorf("Validation failed: %s", strings.Join(messages, ","))
63+
return fmt.Errorf("validation failed: %s", strings.Join(messages, ","))
6464
}
6565
return nil
6666
}

signer/core/uiapi.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ func (s *UIServerAPI) Export(ctx context.Context, addr common.Address) (json.Raw
173173
return nil, err
174174
}
175175
if wallet.URL().Scheme != keystore.KeyStoreScheme {
176-
return nil, fmt.Errorf("Account is not a keystore-account")
176+
return nil, fmt.Errorf("account is not a keystore-account")
177177
}
178178
return ioutil.ReadFile(wallet.URL().Path)
179179
}

signer/rules/deps/bindata.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
// Code generated by go-bindata.
1+
// Package deps Code generated by go-bindata. (@generated) DO NOT EDIT.
22
// sources:
33
// bignumber.js
4-
// DO NOT EDIT!
5-
64
package deps
75

86
import (
@@ -20,15 +18,15 @@ import (
2018
func bindataRead(data []byte, name string) ([]byte, error) {
2119
gz, err := gzip.NewReader(bytes.NewBuffer(data))
2220
if err != nil {
23-
return nil, fmt.Errorf("Read %q: %v", name, err)
21+
return nil, fmt.Errorf("read %q: %v", name, err)
2422
}
2523

2624
var buf bytes.Buffer
2725
_, err = io.Copy(&buf, gz)
2826
clErr := gz.Close()
2927

3028
if err != nil {
31-
return nil, fmt.Errorf("Read %q: %v", name, err)
29+
return nil, fmt.Errorf("read %q: %v", name, err)
3230
}
3331
if clErr != nil {
3432
return nil, err
@@ -49,21 +47,32 @@ type bindataFileInfo struct {
4947
modTime time.Time
5048
}
5149

50+
// Name return file name
5251
func (fi bindataFileInfo) Name() string {
5352
return fi.name
5453
}
54+
55+
// Size return file size
5556
func (fi bindataFileInfo) Size() int64 {
5657
return fi.size
5758
}
59+
60+
// Mode return file mode
5861
func (fi bindataFileInfo) Mode() os.FileMode {
5962
return fi.mode
6063
}
64+
65+
// ModTime return file modify time
6166
func (fi bindataFileInfo) ModTime() time.Time {
6267
return fi.modTime
6368
}
69+
70+
// IsDir return file whether a directory
6471
func (fi bindataFileInfo) IsDir() bool {
65-
return false
72+
return fi.mode&os.ModeDir != 0
6673
}
74+
75+
// Sys return file is sys mode
6776
func (fi bindataFileInfo) Sys() interface{} {
6877
return nil
6978
}

signer/rules/rules.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ func (r *rulesetUI) checkApproval(jsfunc string, jsarg []byte, err error) (bool,
152152
log.Info("Op rejected")
153153
return false, nil
154154
}
155-
return false, fmt.Errorf("Unknown response")
155+
return false, fmt.Errorf("unknown response")
156156
}
157157

158158
func (r *rulesetUI) ApproveTx(request *core.SignTxRequest) (core.SignTxResponse, error) {

signer/storage/storage.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ type Storage interface {
4141
// EphemeralStorage is an in-memory storage that does
4242
// not persist values to disk. Mainly used for testing
4343
type EphemeralStorage struct {
44-
data map[string]string
45-
namespace string
44+
data map[string]string
4645
}
4746

4847
// Put stores a value by key. 0-length keys results in noop.
@@ -83,5 +82,5 @@ type NoStorage struct{}
8382
func (s *NoStorage) Put(key, value string) {}
8483
func (s *NoStorage) Del(key string) {}
8584
func (s *NoStorage) Get(key string) (string, error) {
86-
return "", errors.New("I forgot")
85+
return "", errors.New("missing key, I probably forgot")
8786
}

tests/block_test_util.go

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ func (t *BlockTest) insertBlocks(blockchain *core.BlockChain) ([]btBlock, error)
179179
if b.BlockHeader == nil {
180180
continue // OK - block is supposed to be invalid, continue with next block
181181
} else {
182-
return nil, fmt.Errorf("Block RLP decoding failed when expected to succeed: %v", err)
182+
return nil, fmt.Errorf("block RLP decoding failed when expected to succeed: %v", err)
183183
}
184184
}
185185
// RLP decoding worked, try to insert into chain:
@@ -189,16 +189,16 @@ func (t *BlockTest) insertBlocks(blockchain *core.BlockChain) ([]btBlock, error)
189189
if b.BlockHeader == nil {
190190
continue // OK - block is supposed to be invalid, continue with next block
191191
} else {
192-
return nil, fmt.Errorf("Block #%v insertion into chain failed: %v", blocks[i].Number(), err)
192+
return nil, fmt.Errorf("block #%v insertion into chain failed: %v", blocks[i].Number(), err)
193193
}
194194
}
195195
if b.BlockHeader == nil {
196-
return nil, fmt.Errorf("Block insertion should have failed")
196+
return nil, fmt.Errorf("block insertion should have failed")
197197
}
198198

199199
// validate RLP decoding by checking all values against test file JSON
200200
if err = validateHeader(b.BlockHeader, cb.Header()); err != nil {
201-
return nil, fmt.Errorf("Deserialised block header validation failed: %v", err)
201+
return nil, fmt.Errorf("deserialised block header validation failed: %v", err)
202202
}
203203
validBlocks = append(validBlocks, b)
204204
}
@@ -207,49 +207,49 @@ func (t *BlockTest) insertBlocks(blockchain *core.BlockChain) ([]btBlock, error)
207207

208208
func validateHeader(h *btHeader, h2 *types.Header) error {
209209
if h.Bloom != h2.Bloom {
210-
return fmt.Errorf("Bloom: want: %x have: %x", h.Bloom, h2.Bloom)
210+
return fmt.Errorf("bloom: want: %x have: %x", h.Bloom, h2.Bloom)
211211
}
212212
if h.Coinbase != h2.Coinbase {
213-
return fmt.Errorf("Coinbase: want: %x have: %x", h.Coinbase, h2.Coinbase)
213+
return fmt.Errorf("coinbase: want: %x have: %x", h.Coinbase, h2.Coinbase)
214214
}
215215
if h.MixHash != h2.MixDigest {
216216
return fmt.Errorf("MixHash: want: %x have: %x", h.MixHash, h2.MixDigest)
217217
}
218218
if h.Nonce != h2.Nonce {
219-
return fmt.Errorf("Nonce: want: %x have: %x", h.Nonce, h2.Nonce)
219+
return fmt.Errorf("nonce: want: %x have: %x", h.Nonce, h2.Nonce)
220220
}
221221
if h.Number.Cmp(h2.Number) != 0 {
222-
return fmt.Errorf("Number: want: %v have: %v", h.Number, h2.Number)
222+
return fmt.Errorf("number: want: %v have: %v", h.Number, h2.Number)
223223
}
224224
if h.ParentHash != h2.ParentHash {
225-
return fmt.Errorf("Parent hash: want: %x have: %x", h.ParentHash, h2.ParentHash)
225+
return fmt.Errorf("parent hash: want: %x have: %x", h.ParentHash, h2.ParentHash)
226226
}
227227
if h.ReceiptTrie != h2.ReceiptHash {
228-
return fmt.Errorf("Receipt hash: want: %x have: %x", h.ReceiptTrie, h2.ReceiptHash)
228+
return fmt.Errorf("receipt hash: want: %x have: %x", h.ReceiptTrie, h2.ReceiptHash)
229229
}
230230
if h.TransactionsTrie != h2.TxHash {
231-
return fmt.Errorf("Tx hash: want: %x have: %x", h.TransactionsTrie, h2.TxHash)
231+
return fmt.Errorf("tx hash: want: %x have: %x", h.TransactionsTrie, h2.TxHash)
232232
}
233233
if h.StateRoot != h2.Root {
234-
return fmt.Errorf("State hash: want: %x have: %x", h.StateRoot, h2.Root)
234+
return fmt.Errorf("state hash: want: %x have: %x", h.StateRoot, h2.Root)
235235
}
236236
if h.UncleHash != h2.UncleHash {
237-
return fmt.Errorf("Uncle hash: want: %x have: %x", h.UncleHash, h2.UncleHash)
237+
return fmt.Errorf("uncle hash: want: %x have: %x", h.UncleHash, h2.UncleHash)
238238
}
239239
if !bytes.Equal(h.ExtraData, h2.Extra) {
240-
return fmt.Errorf("Extra data: want: %x have: %x", h.ExtraData, h2.Extra)
240+
return fmt.Errorf("extra data: want: %x have: %x", h.ExtraData, h2.Extra)
241241
}
242242
if h.Difficulty.Cmp(h2.Difficulty) != 0 {
243-
return fmt.Errorf("Difficulty: want: %v have: %v", h.Difficulty, h2.Difficulty)
243+
return fmt.Errorf("difficulty: want: %v have: %v", h.Difficulty, h2.Difficulty)
244244
}
245245
if h.GasLimit != h2.GasLimit {
246-
return fmt.Errorf("GasLimit: want: %d have: %d", h.GasLimit, h2.GasLimit)
246+
return fmt.Errorf("gasLimit: want: %d have: %d", h.GasLimit, h2.GasLimit)
247247
}
248248
if h.GasUsed != h2.GasUsed {
249-
return fmt.Errorf("GasUsed: want: %d have: %d", h.GasUsed, h2.GasUsed)
249+
return fmt.Errorf("gasUsed: want: %d have: %d", h.GasUsed, h2.GasUsed)
250250
}
251251
if h.Timestamp != h2.Time {
252-
return fmt.Errorf("Timestamp: want: %v have: %v", h.Timestamp, h2.Time)
252+
return fmt.Errorf("timestamp: want: %v have: %v", h.Timestamp, h2.Time)
253253
}
254254
return nil
255255
}
@@ -287,7 +287,7 @@ func (t *BlockTest) validateImportedHeaders(cm *core.BlockChain, validBlocks []b
287287
// be part of the longest chain until last block is imported.
288288
for b := cm.CurrentBlock(); b != nil && b.NumberU64() != 0; b = cm.GetBlockByHash(b.Header().ParentHash) {
289289
if err := validateHeader(bmap[b.Hash()].BlockHeader, b.Header()); err != nil {
290-
return fmt.Errorf("Imported block header validation failed: %v", err)
290+
return fmt.Errorf("imported block header validation failed: %v", err)
291291
}
292292
}
293293
return nil

0 commit comments

Comments
 (0)