diff --git a/ibc_test.go b/ibc_test.go index cedabe248..6fdcdabd2 100644 --- a/ibc_test.go +++ b/ibc_test.go @@ -75,7 +75,7 @@ type AcknowledgeDispatch struct { Err string `json:"error"` } -func toBytes(t *testing.T, v interface{}) []byte { +func toBytes(t *testing.T, v any) []byte { t.Helper() bz, err := json.Marshal(v) require.NoError(t, err) diff --git a/internal/api/iterator_test.go b/internal/api/iterator_test.go index 22b100325..07e82a48e 100644 --- a/internal/api/iterator_test.go +++ b/internal/api/iterator_test.go @@ -44,7 +44,7 @@ func setupQueueContractWithData(t *testing.T, cache Cache, values ...int) queueD for _, value := range values { // push 17 var gasMeter2 types.GasMeter = NewMockGasMeter(TESTING_GAS_LIMIT) - push := []byte(fmt.Sprintf(`{"enqueue":{"value":%d}}`, value)) + push := fmt.Appendf(nil, `{"enqueue":{"value":%d}}`, value) res, _, err = Execute(cache, checksum, env, info, push, &gasMeter2, store, api, &querier, TESTING_GAS_LIMIT, TESTING_PRINT_DEBUG) require.NoError(t, err) requireOkResponse(t, res, 0) @@ -241,7 +241,7 @@ func TestQueueIteratorRaces(t *testing.T) { var wg sync.WaitGroup // for each batch, query each of the 3 contracts - so the contract queries get mixed together wg.Add(numBatches * 3) - for i := 0; i < numBatches; i++ { + for range numBatches { go func() { reduceQuery(t, contract1, "[[17,22],[22,0]]") wg.Done() diff --git a/internal/api/lib_test.go b/internal/api/lib_test.go index acdfd869c..3b2334dbe 100644 --- a/internal/api/lib_test.go +++ b/internal/api/lib_test.go @@ -855,7 +855,7 @@ func Benchmark100ConcurrentContractCalls(b *testing.B) { info = MockInfoBin(b, "fred") - for i := 0; i < callCount; i++ { + for range callCount { go func() { defer wg.Done() gasMeter2 := NewMockGasMeter(TESTING_GAS_LIMIT) @@ -872,7 +872,7 @@ func Benchmark100ConcurrentContractCalls(b *testing.B) { close(resChan) // Now check results in the main test goroutine - for i := 0; i < callCount; i++ { + for range callCount { require.NoError(b, <-errChan) requireOkResponse(b, <-resChan, 0) } @@ -1084,7 +1084,7 @@ func TestDispatchSubmessage(t *testing.T) { } payloadBin, err := json.Marshal(payload) require.NoError(t, err) - payloadMsg := []byte(fmt.Sprintf(`{"reflect_sub_msg":{"msgs":[%s]}}`, string(payloadBin))) + payloadMsg := fmt.Appendf(nil, `{"reflect_sub_msg":{"msgs":[%s]}}`, string(payloadBin)) gasMeter2 := NewMockGasMeter(TESTING_GAS_LIMIT) igasMeter2 := types.GasMeter(gasMeter2) @@ -1433,7 +1433,7 @@ func TestFloats(t *testing.T) { hasher := sha256.New() const RUNS_PER_INSTRUCTION = 150 for _, instr := range instructions { - for seed := 0; seed < RUNS_PER_INSTRUCTION; seed++ { + for seed := range RUNS_PER_INSTRUCTION { // query some input values for the instruction msg := fmt.Sprintf(`{"random_args_for":{"instruction":"%s","seed":%d}}`, instr, seed) data, _, err = Query(cache, checksum, env, []byte(msg), &igasMeter, store, api, &querier, TESTING_GAS_LIMIT, TESTING_PRINT_DEBUG) diff --git a/lib_libwasmvm_test.go b/lib_libwasmvm_test.go index d204e113a..85c3294e7 100644 --- a/lib_libwasmvm_test.go +++ b/lib_libwasmvm_test.go @@ -413,7 +413,7 @@ func TestLongPayloadDeserialization(t *testing.T) { validPayload := make([]byte, 128*1024) validPayloadJSON, err := json.Marshal(validPayload) require.NoError(t, err) - resultJson := []byte(fmt.Sprintf(`{"ok":{"messages":[{"id":0,"msg":{"bank":{"send":{"to_address":"bob","amount":[{"denom":"ATOM","amount":"250"}]}}},"payload":%s,"reply_on":"never"}],"data":"8Auq","attributes":[],"events":[]}}`, validPayloadJSON)) + resultJson := fmt.Appendf(nil, `{"ok":{"messages":[{"id":0,"msg":{"bank":{"send":{"to_address":"bob","amount":[{"denom":"ATOM","amount":"250"}]}}},"payload":%s,"reply_on":"never"}],"data":"8Auq","attributes":[],"events":[]}}`, validPayloadJSON) // Test that a valid payload can be deserialized var result types.ContractResult @@ -425,7 +425,7 @@ func TestLongPayloadDeserialization(t *testing.T) { invalidPayload := make([]byte, 128*1024+1) invalidPayloadJSON, err := json.Marshal(invalidPayload) require.NoError(t, err) - resultJson = []byte(fmt.Sprintf(`{"ok":{"messages":[{"id":0,"msg":{"bank":{"send":{"to_address":"bob","amount":[{"denom":"ATOM","amount":"250"}]}}},"payload":%s,"reply_on":"never"}],"attributes":[],"events":[]}}`, invalidPayloadJSON)) + resultJson = fmt.Appendf(nil, `{"ok":{"messages":[{"id":0,"msg":{"bank":{"send":{"to_address":"bob","amount":[{"denom":"ATOM","amount":"250"}]}}},"payload":%s,"reply_on":"never"}],"attributes":[],"events":[]}}`, invalidPayloadJSON) // Test that an invalid payload cannot be deserialized err = DeserializeResponse(math.MaxUint64, deserCost, &gasReport, resultJson, &result) diff --git a/types/systemerror.go b/types/systemerror.go index c7ca32029..ed0327668 100644 --- a/types/systemerror.go +++ b/types/systemerror.go @@ -140,7 +140,7 @@ func ToSystemError(err error) *SystemError { } // check if an interface is nil (even if it has type info) -func isNil(i interface{}) bool { +func isNil(i any) bool { if i == nil { return true }