Skip to content

Commit e86b658

Browse files
authored
Merge pull request #588 from faddat/faddat/errcheck
linter PR 2: enable errcheck and thelper linters
2 parents 4263311 + 300ef9f commit e86b658

File tree

6 files changed

+43
-20
lines changed

6 files changed

+43
-20
lines changed

.golangci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ linters:
88
- gofumpt
99
- gci
1010
- testifylint
11+
- errcheck
12+
- thelper
1113

1214
linters-settings:
1315
gci:

ibc_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ type AcknowledgeDispatch struct {
7676
}
7777

7878
func toBytes(t *testing.T, v interface{}) []byte {
79+
t.Helper()
7980
bz, err := json.Marshal(v)
8081
require.NoError(t, err)
8182
return bz

internal/api/iterator_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ func (q queueData) Store(meter MockGasMeter) types.KVStore {
2424
}
2525

2626
func setupQueueContractWithData(t *testing.T, cache Cache, values ...int) queueData {
27+
t.Helper()
2728
checksum := createQueueContract(t, cache)
2829

2930
gasMeter1 := NewMockGasMeter(TESTING_GAS_LIMIT)
@@ -58,6 +59,7 @@ func setupQueueContractWithData(t *testing.T, cache Cache, values ...int) queueD
5859
}
5960

6061
func setupQueueContract(t *testing.T, cache Cache) queueData {
62+
t.Helper()
6163
return setupQueueContractWithData(t, cache, 17, 22)
6264
}
6365

@@ -216,6 +218,7 @@ func TestQueueIteratorRaces(t *testing.T) {
216218
env := MockEnvBin(t)
217219

218220
reduceQuery := func(t *testing.T, setup queueData, expected string) {
221+
t.Helper()
219222
checksum, querier, api := setup.checksum, setup.querier, setup.api
220223
gasMeter := NewMockGasMeter(TESTING_GAS_LIMIT)
221224
igasMeter := types.GasMeter(gasMeter)

internal/api/lib_test.go

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,10 @@ func TestInitCacheEmptyCapabilities(t *testing.T) {
191191
ReleaseCache(cache)
192192
}
193193

194-
func withCache(t testing.TB) (Cache, func()) {
194+
func withCache(tb testing.TB) (Cache, func()) {
195+
tb.Helper()
195196
tmpdir, err := os.MkdirTemp("", "wasmvm-testing")
196-
require.NoError(t, err)
197+
require.NoError(tb, err)
197198
config := types.VMConfig{
198199
Cache: types.CacheOptions{
199200
BaseDir: tmpdir,
@@ -203,7 +204,7 @@ func withCache(t testing.TB) (Cache, func()) {
203204
},
204205
}
205206
cache, err := InitCache(config)
206-
require.NoError(t, err)
207+
require.NoError(tb, err)
207208

208209
cleanup := func() {
209210
os.RemoveAll(tmpdir)
@@ -868,6 +869,8 @@ func Benchmark100ConcurrentContractCalls(b *testing.B) {
868869
resChan := make(chan []byte, callCount)
869870
wg.Add(callCount)
870871

872+
info = MockInfoBin(b, "fred")
873+
871874
for i := 0; i < callCount; i++ {
872875
go func() {
873876
defer wg.Done()
@@ -1189,6 +1192,7 @@ func TestReplyAndQuery(t *testing.T) {
11891192
}
11901193

11911194
func requireOkResponse(tb testing.TB, res []byte, expectedMsgs int) {
1195+
tb.Helper()
11921196
var result types.ContractResult
11931197
err := json.Unmarshal(res, &result)
11941198
require.NoError(tb, err)
@@ -1197,6 +1201,7 @@ func requireOkResponse(tb testing.TB, res []byte, expectedMsgs int) {
11971201
}
11981202

11991203
func requireQueryError(t *testing.T, res []byte) {
1204+
t.Helper()
12001205
var result types.QueryResult
12011206
err := json.Unmarshal(res, &result)
12021207
require.NoError(t, err)
@@ -1205,6 +1210,7 @@ func requireQueryError(t *testing.T, res []byte) {
12051210
}
12061211

12071212
func requireQueryOk(t *testing.T, res []byte) []byte {
1213+
t.Helper()
12081214
var result types.QueryResult
12091215
err := json.Unmarshal(res, &result)
12101216
require.NoError(t, err)
@@ -1213,36 +1219,43 @@ func requireQueryOk(t *testing.T, res []byte) []byte {
12131219
return result.Ok
12141220
}
12151221

1216-
func createHackatomContract(t testing.TB, cache Cache) []byte {
1217-
return createContract(t, cache, "../../testdata/hackatom.wasm")
1222+
func createHackatomContract(tb testing.TB, cache Cache) []byte {
1223+
tb.Helper()
1224+
return createContract(tb, cache, "../../testdata/hackatom.wasm")
12181225
}
12191226

1220-
func createCyberpunkContract(t testing.TB, cache Cache) []byte {
1221-
return createContract(t, cache, "../../testdata/cyberpunk.wasm")
1227+
func createCyberpunkContract(tb testing.TB, cache Cache) []byte {
1228+
tb.Helper()
1229+
return createContract(tb, cache, "../../testdata/cyberpunk.wasm")
12221230
}
12231231

1224-
func createQueueContract(t testing.TB, cache Cache) []byte {
1225-
return createContract(t, cache, "../../testdata/queue.wasm")
1232+
func createQueueContract(tb testing.TB, cache Cache) []byte {
1233+
tb.Helper()
1234+
return createContract(tb, cache, "../../testdata/queue.wasm")
12261235
}
12271236

1228-
func createReflectContract(t testing.TB, cache Cache) []byte {
1229-
return createContract(t, cache, "../../testdata/reflect.wasm")
1237+
func createReflectContract(tb testing.TB, cache Cache) []byte {
1238+
tb.Helper()
1239+
return createContract(tb, cache, "../../testdata/reflect.wasm")
12301240
}
12311241

1232-
func createFloaty2(t testing.TB, cache Cache) []byte {
1233-
return createContract(t, cache, "../../testdata/floaty_2.0.wasm")
1242+
func createFloaty2(tb testing.TB, cache Cache) []byte {
1243+
tb.Helper()
1244+
return createContract(tb, cache, "../../testdata/floaty_2.0.wasm")
12341245
}
12351246

1236-
func createContract(t testing.TB, cache Cache, wasmFile string) []byte {
1247+
func createContract(tb testing.TB, cache Cache, wasmFile string) []byte {
1248+
tb.Helper()
12371249
wasm, err := os.ReadFile(wasmFile)
1238-
require.NoError(t, err)
1250+
require.NoError(tb, err)
12391251
checksum, err := StoreCode(cache, wasm, true)
1240-
require.NoError(t, err)
1252+
require.NoError(tb, err)
12411253
return checksum
12421254
}
12431255

12441256
// exec runs the handle tx with the given signer
12451257
func exec(t *testing.T, cache Cache, checksum []byte, signer types.HumanAddress, store types.KVStore, api *types.GoAPI, querier Querier, gasExpected uint64) types.ContractResult {
1258+
t.Helper()
12461259
gasMeter := NewMockGasMeter(TESTING_GAS_LIMIT)
12471260
igasMeter := types.GasMeter(gasMeter)
12481261
env := MockEnvBin(t)

internal/api/mocks.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,10 @@ func MockEnv() types.Env {
3535
}
3636
}
3737

38-
func MockEnvBin(t testing.TB) []byte {
38+
func MockEnvBin(tb testing.TB) []byte {
39+
tb.Helper()
3940
bin, err := json.Marshal(MockEnv())
40-
require.NoError(t, err)
41+
require.NoError(tb, err)
4142
return bin
4243
}
4344

@@ -55,9 +56,10 @@ func MockInfoWithFunds(sender types.HumanAddress) types.MessageInfo {
5556
}})
5657
}
5758

58-
func MockInfoBin(t testing.TB, sender types.HumanAddress) []byte {
59+
func MockInfoBin(tb testing.TB, sender types.HumanAddress) []byte {
60+
tb.Helper()
5961
bin, err := json.Marshal(MockInfoWithFunds(sender))
60-
require.NoError(t, err)
62+
require.NoError(tb, err)
6163
return bin
6264
}
6365

lib_libwasmvm_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const (
3131
)
3232

3333
func withVM(t *testing.T) *VM {
34+
t.Helper()
3435
tmpdir, err := os.MkdirTemp("", "wasmvm-testing")
3536
require.NoError(t, err)
3637
vm, err := NewVM(tmpdir, TESTING_CAPABILITIES, TESTING_MEMORY_LIMIT, TESTING_PRINT_DEBUG, TESTING_CACHE_SIZE)
@@ -44,6 +45,7 @@ func withVM(t *testing.T) *VM {
4445
}
4546

4647
func createTestContract(t *testing.T, vm *VM, path string) Checksum {
48+
t.Helper()
4749
wasm, err := os.ReadFile(path)
4850
require.NoError(t, err)
4951
checksum, _, err := vm.StoreCode(wasm, TESTING_GAS_LIMIT)

0 commit comments

Comments
 (0)