Skip to content

Commit 7c945dd

Browse files
committed
fix linter
1 parent c6fb71f commit 7c945dd

File tree

4 files changed

+23
-26
lines changed

4 files changed

+23
-26
lines changed

common/hexutil/hexutil.libevm.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func DecodeUint16(input string) (uint16, error) {
3333
return 0, ErrUint16Range
3434
}
3535
}
36-
return uint16(dec), err
36+
return uint16(dec), err //nolint:gosec // G115 won't overflow uint16 as ParseUint uses 16 bits
3737
}
3838

3939
// EncodeUint16 encodes i as a hex string with 0x prefix.

common/hexutil/hexutil.libevm_test.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@ var (
4747

4848
func TestEncodeUint16(t *testing.T) {
4949
for _, test := range encodeUint16Tests {
50-
enc := EncodeUint16(test.input.(uint16))
50+
input, ok := test.input.(uint16)
51+
if !ok {
52+
t.Errorf("input %v: not a uint16", test.input)
53+
}
54+
enc := EncodeUint16(input)
5155
if enc != test.want {
5256
t.Errorf("input %x: wrong encoding %s", test.input, enc)
5357
}
@@ -60,8 +64,12 @@ func TestDecodeUint16(t *testing.T) {
6064
if !checkError(t, test.input, err, test.wantErr) {
6165
continue
6266
}
63-
if dec != test.want.(uint16) {
64-
t.Errorf("input %s: value mismatch: got %x, want %x", test.input, dec, test.want)
67+
want, ok := test.want.(uint16)
68+
if !ok {
69+
t.Errorf("want %v: not a uint16", test.want)
70+
}
71+
if dec != want {
72+
t.Errorf("input %s: value mismatch: got %x, want %x", test.input, dec, want)
6573
continue
6674
}
6775
}

common/hexutil/json.libevm.go

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package hexutil
1818

1919
import (
20-
"fmt"
2120
"reflect"
2221
"strconv"
2322
)
@@ -60,7 +59,7 @@ func (b *Uint16) UnmarshalText(input []byte) error {
6059
return ErrSyntax
6160
}
6261
dec *= 16
63-
dec += uint16(nib)
62+
dec += uint16(nib) //nolint:gosec // G115 won't overflow uint16 as decodeNibble uses 4 bits
6463
}
6564

6665
*b = Uint16(dec)
@@ -71,20 +70,3 @@ func (b *Uint16) UnmarshalText(input []byte) error {
7170
func (b Uint16) String() string {
7271
return EncodeUint16(uint16(b))
7372
}
74-
75-
// ImplementsGraphQLType returns true if Uint16 implements the provided GraphQL type.
76-
func (b Uint16) ImplementsGraphQLType(name string) bool { return name == "Int" }
77-
78-
// UnmarshalGraphQL unmarshals the provided GraphQL query data.
79-
func (b *Uint16) UnmarshalGraphQL(input interface{}) error {
80-
var err error
81-
switch input := input.(type) {
82-
case string:
83-
return b.UnmarshalText([]byte(input))
84-
case int32:
85-
*b = Uint16(input)
86-
default:
87-
err = fmt.Errorf("unexpected type %T for Int", input)
88-
}
89-
return err
90-
}

common/hexutil/json.libevm_test.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,12 @@ func TestUnmarshalUint16(t *testing.T) {
5151
if !checkError(t, test.input, err, test.wantErr) {
5252
continue
5353
}
54-
if uint16(v) != test.want.(uint16) {
55-
t.Errorf("input %s: value mismatch: got %d, want %d", test.input, v, test.want)
54+
want, ok := test.want.(uint16)
55+
if !ok {
56+
t.Errorf("want %v: not a uint16", test.want)
57+
}
58+
if uint16(v) != want {
59+
t.Errorf("input %s: value mismatch: got %d, want %d", test.input, v, want)
5660
continue
5761
}
5862
}
@@ -62,7 +66,10 @@ func BenchmarkUnmarshalUint16(b *testing.B) {
6266
input := []byte(`"0x1234"`)
6367
for i := 0; i < b.N; i++ {
6468
var v Uint16
65-
v.UnmarshalJSON(input)
69+
err := v.UnmarshalJSON(input)
70+
if err != nil {
71+
b.Errorf("error unmarshalling: %v", err)
72+
}
6673
}
6774
}
6875

0 commit comments

Comments
 (0)