Skip to content

Commit 445f165

Browse files
committed
enable errcheck and thelper linters
1 parent f8005f8 commit 445f165

File tree

6 files changed

+55
-23
lines changed

6 files changed

+55
-23
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: 41 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,10 @@ func TestInitCacheEmptyCapabilities(t *testing.T) {
194194
ReleaseCache(cache)
195195
}
196196

197-
func withCache(t testing.TB) (Cache, func()) {
197+
func withCache(tb testing.TB) (Cache, func()) {
198+
tb.Helper()
198199
tmpdir, err := os.MkdirTemp("", "wasmvm-testing")
199-
require.NoError(t, err)
200+
require.NoError(tb, err)
200201
config := types.VMConfig{
201202
Cache: types.CacheOptions{
202203
BaseDir: tmpdir,
@@ -206,7 +207,7 @@ func withCache(t testing.TB) (Cache, func()) {
206207
},
207208
}
208209
cache, err := InitCache(config)
209-
require.NoError(t, err)
210+
require.NoError(tb, err)
210211

211212
cleanup := func() {
212213
os.RemoveAll(tmpdir)
@@ -848,9 +849,7 @@ func Benchmark100ConcurrentContractCalls(b *testing.B) {
848849
errChan := make(chan error, callCount)
849850
resChan := make(chan []byte, callCount)
850851
wg.Add(callCount)
851-
testMutex.Lock()
852-
info = MockInfoBin(b, "fred")
853-
testMutex.Unlock()
852+
info = mockInfoBinNoAssert("fred")
854853
for i := 0; i < callCount; i++ {
855854
go func() {
856855
defer wg.Done()
@@ -1172,6 +1171,7 @@ func TestReplyAndQuery(t *testing.T) {
11721171
}
11731172

11741173
func requireOkResponse(tb testing.TB, res []byte, expectedMsgs int) {
1174+
tb.Helper()
11751175
var result types.ContractResult
11761176
err := json.Unmarshal(res, &result)
11771177
require.NoError(tb, err)
@@ -1180,6 +1180,7 @@ func requireOkResponse(tb testing.TB, res []byte, expectedMsgs int) {
11801180
}
11811181

11821182
func requireQueryError(t *testing.T, res []byte) {
1183+
t.Helper()
11831184
var result types.QueryResult
11841185
err := json.Unmarshal(res, &result)
11851186
require.NoError(t, err)
@@ -1188,6 +1189,7 @@ func requireQueryError(t *testing.T, res []byte) {
11881189
}
11891190

11901191
func requireQueryOk(t *testing.T, res []byte) []byte {
1192+
t.Helper()
11911193
var result types.QueryResult
11921194
err := json.Unmarshal(res, &result)
11931195
require.NoError(t, err)
@@ -1196,36 +1198,43 @@ func requireQueryOk(t *testing.T, res []byte) []byte {
11961198
return result.Ok
11971199
}
11981200

1199-
func createHackatomContract(t testing.TB, cache Cache) []byte {
1200-
return createContract(t, cache, "../../testdata/hackatom.wasm")
1201+
func createHackatomContract(tb testing.TB, cache Cache) []byte {
1202+
tb.Helper()
1203+
return createContract(tb, cache, "../../testdata/hackatom.wasm")
12011204
}
12021205

1203-
func createCyberpunkContract(t testing.TB, cache Cache) []byte {
1204-
return createContract(t, cache, "../../testdata/cyberpunk.wasm")
1206+
func createCyberpunkContract(tb testing.TB, cache Cache) []byte {
1207+
tb.Helper()
1208+
return createContract(tb, cache, "../../testdata/cyberpunk.wasm")
12051209
}
12061210

1207-
func createQueueContract(t testing.TB, cache Cache) []byte {
1208-
return createContract(t, cache, "../../testdata/queue.wasm")
1211+
func createQueueContract(tb testing.TB, cache Cache) []byte {
1212+
tb.Helper()
1213+
return createContract(tb, cache, "../../testdata/queue.wasm")
12091214
}
12101215

1211-
func createReflectContract(t testing.TB, cache Cache) []byte {
1212-
return createContract(t, cache, "../../testdata/reflect.wasm")
1216+
func createReflectContract(tb testing.TB, cache Cache) []byte {
1217+
tb.Helper()
1218+
return createContract(tb, cache, "../../testdata/reflect.wasm")
12131219
}
12141220

1215-
func createFloaty2(t testing.TB, cache Cache) []byte {
1216-
return createContract(t, cache, "../../testdata/floaty_2.0.wasm")
1221+
func createFloaty2(tb testing.TB, cache Cache) []byte {
1222+
tb.Helper()
1223+
return createContract(tb, cache, "../../testdata/floaty_2.0.wasm")
12171224
}
12181225

1219-
func createContract(t testing.TB, cache Cache, wasmFile string) []byte {
1226+
func createContract(tb testing.TB, cache Cache, wasmFile string) []byte {
1227+
tb.Helper()
12201228
wasm, err := os.ReadFile(wasmFile)
1221-
require.NoError(t, err)
1229+
require.NoError(tb, err)
12221230
checksum, err := StoreCode(cache, wasm, true)
1223-
require.NoError(t, err)
1231+
require.NoError(tb, err)
12241232
return checksum
12251233
}
12261234

12271235
// exec runs the handle tx with the given signer
12281236
func exec(t *testing.T, cache Cache, checksum []byte, signer types.HumanAddress, store types.KVStore, api *types.GoAPI, querier Querier, gasExpected uint64) types.ContractResult {
1237+
t.Helper()
12291238
gasMeter := NewMockGasMeter(TESTING_GAS_LIMIT)
12301239
igasMeter := types.GasMeter(gasMeter)
12311240
env := MockEnvBin(t)
@@ -1461,3 +1470,16 @@ func TestFloats(t *testing.T) {
14611470
hash := hasher.Sum(nil)
14621471
require.Equal(t, "95f70fa6451176ab04a9594417a047a1e4d8e2ff809609b8f81099496bee2393", hex.EncodeToString(hash))
14631472
}
1473+
1474+
// mockInfoBinNoAssert creates the message binary without using testify assertions
1475+
func mockInfoBinNoAssert(sender types.HumanAddress) []byte {
1476+
info := types.MessageInfo{
1477+
Sender: sender,
1478+
Funds: types.Array[types.Coin]{},
1479+
}
1480+
res, err := json.Marshal(info)
1481+
if err != nil {
1482+
panic(err)
1483+
}
1484+
return res
1485+
}

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)