Skip to content

Commit b9b3efb

Browse files
committed
all: fix ineffectual assignments and remove uses of crypto.Sha3
go get github.com/gordonklaus/ineffassign ineffassign .
1 parent 0f34d50 commit b9b3efb

31 files changed

+108
-103
lines changed

accounts/abi/bind/base.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ func (c *BoundContract) transact(opts *TransactOpts, contract *common.Address, i
170170
if value == nil {
171171
value = new(big.Int)
172172
}
173-
nonce := uint64(0)
173+
var nonce uint64
174174
if opts.Nonce == nil {
175175
nonce, err = c.transactor.PendingNonceAt(ensureContext(opts.Context), opts.From)
176176
if err != nil {

accounts/accounts_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ func TestTimedUnlock(t *testing.T) {
115115

116116
pass := "foo"
117117
a1, err := am.NewAccount(pass)
118+
if err != nil {
119+
t.Fatal(err)
120+
}
118121

119122
// Signing without passphrase fails because account is locked
120123
_, err = am.Sign(a1.Address, testSigData)
@@ -147,6 +150,9 @@ func TestOverrideUnlock(t *testing.T) {
147150

148151
pass := "foo"
149152
a1, err := am.NewAccount(pass)
153+
if err != nil {
154+
t.Fatal(err)
155+
}
150156

151157
// Unlock indefinitely.
152158
if err = am.TimedUnlock(a1, pass, 5*time.Minute); err != nil {

accounts/presale.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"crypto/sha256"
2323
"encoding/hex"
2424
"encoding/json"
25+
"errors"
2526
"fmt"
2627

2728
"github.com/ethereum/go-ethereum/crypto"
@@ -53,6 +54,9 @@ func decryptPreSaleKey(fileContent []byte, password string) (key *Key, err error
5354
return nil, err
5455
}
5556
encSeedBytes, err := hex.DecodeString(preSaleKeyStruct.EncSeed)
57+
if err != nil {
58+
return nil, errors.New("invalid hex in encSeed")
59+
}
5660
iv := encSeedBytes[:16]
5761
cipherText := encSeedBytes[16:]
5862
/*

cmd/geth/monitorcmd.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,9 @@ func expandMetrics(metrics map[string]interface{}, path string) []string {
236236

237237
// fetchMetric iterates over the metrics map and retrieves a specific one.
238238
func fetchMetric(metrics map[string]interface{}, metric string) float64 {
239-
parts, found := strings.Split(metric, "/"), true
239+
parts := strings.Split(metric, "/")
240240
for _, part := range parts[:len(parts)-1] {
241+
var found bool
241242
metrics, found = metrics[part].(map[string]interface{})
242243
if !found {
243244
return 0

cmd/utils/customflags.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,10 @@ type DirectoryFlag struct {
5454
}
5555

5656
func (self DirectoryFlag) String() string {
57-
var fmtString string
58-
fmtString = "%s %v\t%v"
59-
57+
fmtString := "%s %v\t%v"
6058
if len(self.Value.Value) > 0 {
6159
fmtString = "%s \"%v\"\t%v"
62-
} else {
63-
fmtString = "%s %v\t%v"
6460
}
65-
6661
return withEnvHint(self.EnvVar, fmt.Sprintf(fmtString, prefixedNames(self.Name), self.Value.Value, self.Usage))
6762
}
6863

console/console.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,8 @@ func (c *Console) AutoCompleteInput(line string, pos int) (string, []string, str
226226
}
227227
// Chunck data to relevant part for autocompletion
228228
// E.g. in case of nested lines eth.getBalance(eth.coinb<tab><tab>
229-
start := 0
230-
for start = pos - 1; start > 0; start-- {
229+
start := pos - 1
230+
for ; start > 0; start-- {
231231
// Skip all methods and namespaces (i.e. including te dot)
232232
if line[start] == '.' || (line[start] >= 'a' && line[start] <= 'z') || (line[start] >= 'A' && line[start] <= 'Z') {
233233
continue

contracts/chequebook/cheque_test.go

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ func TestIssueAndReceive(t *testing.T) {
7373
}
7474
chbook.sent[addr1] = new(big.Int).SetUint64(42)
7575
amount := common.Big1
76-
ch, err := chbook.Issue(addr1, amount)
77-
if err == nil {
76+
77+
if _, err = chbook.Issue(addr1, amount); err == nil {
7878
t.Fatalf("expected insufficient funds error, got none")
7979
}
8080

@@ -83,7 +83,7 @@ func TestIssueAndReceive(t *testing.T) {
8383
t.Fatalf("expected: %v, got %v", "0", chbook.Balance())
8484
}
8585

86-
ch, err = chbook.Issue(addr1, amount)
86+
ch, err := chbook.Issue(addr1, amount)
8787
if err != nil {
8888
t.Fatalf("expected no error, got %v", err)
8989
}
@@ -128,8 +128,8 @@ func TestCheckbookFile(t *testing.T) {
128128
t.Errorf("expected: %v, got %v", "0", chbook.Balance())
129129
}
130130

131-
ch, err := chbook.Issue(addr1, common.Big1)
132-
if err != nil {
131+
var ch *Cheque
132+
if ch, err = chbook.Issue(addr1, common.Big1); err != nil {
133133
t.Fatalf("expected no error, got %v", err)
134134
}
135135
if ch.Amount.Cmp(new(big.Int).SetUint64(43)) != 0 {
@@ -155,7 +155,7 @@ func TestVerifyErrors(t *testing.T) {
155155
}
156156

157157
path1 := filepath.Join(os.TempDir(), "chequebook-test-1.json")
158-
contr1, err := deploy(key1, common.Big2, backend)
158+
contr1, _ := deploy(key1, common.Big2, backend)
159159
chbook1, err := NewChequebook(path1, contr1, key1, backend)
160160
if err != nil {
161161
t.Errorf("expected no error, got %v", err)
@@ -223,7 +223,8 @@ func TestVerifyErrors(t *testing.T) {
223223
func TestDeposit(t *testing.T) {
224224
path0 := filepath.Join(os.TempDir(), "chequebook-test-0.json")
225225
backend := newTestBackend()
226-
contr0, err := deploy(key0, new(big.Int), backend)
226+
contr0, _ := deploy(key0, new(big.Int), backend)
227+
227228
chbook, err := NewChequebook(path0, contr0, key0, backend)
228229
if err != nil {
229230
t.Errorf("expected no error, got %v", err)
@@ -361,7 +362,8 @@ func TestDeposit(t *testing.T) {
361362
func TestCash(t *testing.T) {
362363
path := filepath.Join(os.TempDir(), "chequebook-test.json")
363364
backend := newTestBackend()
364-
contr0, err := deploy(key0, common.Big2, backend)
365+
contr0, _ := deploy(key0, common.Big2, backend)
366+
365367
chbook, err := NewChequebook(path, contr0, key0, backend)
366368
if err != nil {
367369
t.Errorf("expected no error, got %v", err)
@@ -380,11 +382,12 @@ func TestCash(t *testing.T) {
380382
}
381383

382384
// cashing latest cheque
383-
_, err = chbox.Receive(ch)
384-
if err != nil {
385+
if _, err = chbox.Receive(ch); err != nil {
385386
t.Fatalf("expected no error, got %v", err)
386387
}
387-
_, err = ch.Cash(chbook.session)
388+
if _, err = ch.Cash(chbook.session); err != nil {
389+
t.Fatal("Cash failed:", err)
390+
}
388391
backend.Commit()
389392

390393
chbook.balance = new(big.Int).Set(common.Big3)

contracts/ens/ens_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import (
2929
var (
3030
key, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
3131
name = "my name on ENS"
32-
hash = crypto.Sha3Hash([]byte("my content"))
32+
hash = crypto.Keccak256Hash([]byte("my content"))
3333
addr = crypto.PubkeyToAddress(key.PublicKey)
3434
)
3535

core/blockchain.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,11 +1054,10 @@ func (st *insertStats) report(chain []*types.Block, index int) {
10541054
start, end := chain[st.lastIndex], chain[index]
10551055
txcount := countTransactions(chain[st.lastIndex : index+1])
10561056

1057-
extra := ""
1057+
var hashes, extra string
10581058
if st.queued > 0 || st.ignored > 0 {
10591059
extra = fmt.Sprintf(" (%d queued %d ignored)", st.queued, st.ignored)
10601060
}
1061-
hashes := ""
10621061
if st.processed > 1 {
10631062
hashes = fmt.Sprintf("%x… / %x…", start.Hash().Bytes()[:4], end.Hash().Bytes()[:4])
10641063
} else {

core/state/managed_state_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,20 +88,20 @@ func TestRemoteNonceChange(t *testing.T) {
8888
nn[i] = true
8989
}
9090
account.nonces = append(account.nonces, nn...)
91-
nonce := ms.NewNonce(addr)
91+
ms.NewNonce(addr)
9292

9393
ms.StateDB.stateObjects[addr].data.Nonce = 200
94-
nonce = ms.NewNonce(addr)
94+
nonce := ms.NewNonce(addr)
9595
if nonce != 200 {
96-
t.Error("expected nonce after remote update to be", 201, "got", nonce)
96+
t.Error("expected nonce after remote update to be", 200, "got", nonce)
9797
}
9898
ms.NewNonce(addr)
9999
ms.NewNonce(addr)
100100
ms.NewNonce(addr)
101101
ms.StateDB.stateObjects[addr].data.Nonce = 200
102102
nonce = ms.NewNonce(addr)
103103
if nonce != 204 {
104-
t.Error("expected nonce after remote update to be", 201, "got", nonce)
104+
t.Error("expected nonce after remote update to be", 204, "got", nonce)
105105
}
106106
}
107107

0 commit comments

Comments
 (0)