diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index 5d2ca3908d..da204895ca 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -24,13 +24,13 @@ jobs: uses: golangci/golangci-lint-action@v3 with: # Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version - version: latest + version: v1.54.2 # Optional: working directory, useful for monorepos working-directory: ${{ env.CHIFRA_PATH }} # Optional: set location of the config file (if it is not in the root directory) - args: --timeout=5m --verbose + args: --timeout=5m --verbose --out-format=colored-line-number Build: needs: golangci runs-on: ubuntu-20.04 diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index a4c6a0b7f6..5901ed0155 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -25,13 +25,13 @@ jobs: uses: golangci/golangci-lint-action@v3 with: # Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version - version: v1.29 + version: v1.54.2 # Optional: working directory, useful for monorepos working-directory: src/apps/chifra # Optional: golangci-lint command line arguments. - # args: --issues-exit-code=0 + args: --timeout=5m --verbose --out-format=colored-line-number # Optional: show only new issues if it's a pull request. The default value is `false`. # only-new-issues: true diff --git a/src/apps/chifra/.golangci.yml b/src/apps/chifra/.golangci.yml index 09493715c0..285ae7ac85 100644 --- a/src/apps/chifra/.golangci.yml +++ b/src/apps/chifra/.golangci.yml @@ -1,6 +1,5 @@ run: - exclude-files: - - ".*_test.go" + tests: false linters: disable: - ineffassign diff --git a/src/apps/chifra/pkg/index/bloom.go b/src/apps/chifra/pkg/index/bloom.go index 148eb970f7..b8b8019f9f 100644 --- a/src/apps/chifra/pkg/index/bloom.go +++ b/src/apps/chifra/pkg/index/bloom.go @@ -147,24 +147,3 @@ func (bl *Bloom) addressToBits(addr base.Address) (bits [5]uint32) { return } - -func (bl *Bloom) getStats() (nBlooms uint64, nInserted uint64, nBitsLit uint64, nBitsNotLit uint64, sz uint64, bitsLit []uint64) { - bitsLit = []uint64{} - sz += 4 - nBlooms = uint64(bl.Count) - for _, bf := range bl.Blooms { - nInserted += uint64(bf.NInserted) - sz += 4 + uint64(len(bf.Bytes)) - for bitPos := 0; bitPos < len(bf.Bytes)*8; bitPos++ { - tester := bitChecker{bit: uint32(bitPos), bytes: bf.Bytes} - if bl.isBitLit(&tester) { - nBitsLit++ - bitsLit = append(bitsLit, uint64(bitPos)) - } else { - nBitsNotLit++ - // fmt.Printf("%d", b) - } - } - } - return -} diff --git a/src/apps/chifra/pkg/index/bloom_ismember.go b/src/apps/chifra/pkg/index/bloom_ismember.go index 9dd0f0c41e..14188420bf 100644 --- a/src/apps/chifra/pkg/index/bloom_ismember.go +++ b/src/apps/chifra/pkg/index/bloom_ismember.go @@ -8,17 +8,6 @@ import ( "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base" ) -func (bl *Bloom) isMemberBytes(addr base.Address) bool { - whichBits := bl.addressToBits(addr) - for _, bb := range bl.Blooms { - var tester = bitChecker{bytes: bb.Bytes, whichBits: whichBits} - if bl.isMember(&tester) { - return true - } - } - return false -} - func (bl *Bloom) IsMember(addr base.Address) bool { whichBits := bl.addressToBits(addr) offset := uint32(bl.HeaderSize) + 4 // the end of Count diff --git a/src/apps/chifra/pkg/index/bloom_test.go b/src/apps/chifra/pkg/index/bloom_test.go index 4b1a47bd52..dfcda70494 100644 --- a/src/apps/chifra/pkg/index/bloom_test.go +++ b/src/apps/chifra/pkg/index/bloom_test.go @@ -131,3 +131,35 @@ func Test_Bloom(t *testing.T) { fmt.Println(hexutil.Encode(tt.Addr.Bytes()), bloom.isMemberBytes(tt.Addr)) } } + +func (bl *Bloom) getStats() (nBlooms uint64, nInserted uint64, nBitsLit uint64, nBitsNotLit uint64, sz uint64, bitsLit []uint64) { + bitsLit = []uint64{} + sz += 4 + nBlooms = uint64(bl.Count) + for _, bf := range bl.Blooms { + nInserted += uint64(bf.NInserted) + sz += 4 + uint64(len(bf.Bytes)) + for bitPos := 0; bitPos < len(bf.Bytes)*8; bitPos++ { + tester := bitChecker{bit: uint32(bitPos), bytes: bf.Bytes} + if bl.isBitLit(&tester) { + nBitsLit++ + bitsLit = append(bitsLit, uint64(bitPos)) + } else { + nBitsNotLit++ + // fmt.Printf("%d", b) + } + } + } + return +} + +func (bl *Bloom) isMemberBytes(addr base.Address) bool { + whichBits := bl.addressToBits(addr) + for _, bb := range bl.Blooms { + var tester = bitChecker{bytes: bb.Bytes, whichBits: whichBits} + if bl.isMember(&tester) { + return true + } + } + return false +} diff --git a/src/apps/chifra/pkg/monitor/monitor_freshen_integration_test.go b/src/apps/chifra/pkg/monitor/monitor_freshen_integration_test.go index 20783fa4c4..41c7d890ca 100644 --- a/src/apps/chifra/pkg/monitor/monitor_freshen_integration_test.go +++ b/src/apps/chifra/pkg/monitor/monitor_freshen_integration_test.go @@ -18,7 +18,7 @@ import ( ) func Test_FreshenMonitors(t *testing.T) { - _ = config.GetRootConfig() + config.GetRootConfig() addrs := []string{"0x846a9cb5593483b59bb386f5a878fbb2a0d1d8dc"} // This is an address that we use for testing...early transactor but not for long so unlikely to be used for real diff --git a/src/apps/chifra/pkg/names/custom_integration_test.go b/src/apps/chifra/pkg/names/custom_integration_test.go index 4799248b14..e201b1aeda 100644 --- a/src/apps/chifra/pkg/names/custom_integration_test.go +++ b/src/apps/chifra/pkg/names/custom_integration_test.go @@ -53,7 +53,7 @@ func TestCrudIntegration(t *testing.T) { t.Fatal(err) } - _, _ = tempFile.Seek(0, 0) + tempFile.Seek(0, 0) r := csv.NewReader(tempFile) r.Comma = '\t' diff --git a/src/apps/chifra/pkg/output/json_writer_test.go b/src/apps/chifra/pkg/output/json_writer_test.go index ffcf0c21fd..9ea605ce46 100644 --- a/src/apps/chifra/pkg/output/json_writer_test.go +++ b/src/apps/chifra/pkg/output/json_writer_test.go @@ -41,8 +41,8 @@ func TestJsonWriter_EmptyField(t *testing.T) { b := make([]byte, 0, 1024) buf := bytes.NewBuffer(b) w := NewJsonWriter(buf) - _, _ = w.OpenField("data", FieldArray) - _, _ = w.CloseField(FieldArray) + w.OpenField("data", FieldArray) + w.CloseField(FieldArray) w.Close() result := buf.String() @@ -62,10 +62,10 @@ func TestJsonWriter_EmptySubField(t *testing.T) { b := make([]byte, 0, 1024) buf := bytes.NewBuffer(b) w := NewJsonWriter(buf) - _, _ = w.OpenField("data", FieldArray) - _, _ = w.OpenField("", FieldObject) - _, _ = w.CloseField(FieldObject) - _, _ = w.CloseField(FieldArray) + w.OpenField("data", FieldArray) + w.OpenField("", FieldObject) + w.CloseField(FieldObject) + w.CloseField(FieldArray) w.Close() result := buf.String() @@ -87,11 +87,11 @@ func TestJsonWriter_SingleKey(t *testing.T) { b := make([]byte, 0, 1024) buf := bytes.NewBuffer(b) w := NewJsonWriter(buf) - _, _ = w.OpenField("data", FieldArray) - _, _ = w.OpenField("", FieldObject) - _, _ = w.Write([]byte(`"key": true`)) - _, _ = w.CloseField(FieldObject) - _, _ = w.CloseField(FieldArray) + w.OpenField("data", FieldArray) + w.OpenField("", FieldObject) + w.Write([]byte(`"key": true`)) + w.CloseField(FieldObject) + w.CloseField(FieldArray) w.Close() result := buf.String() @@ -113,12 +113,12 @@ func TestJsonWriter_SingleEmptySubkey(t *testing.T) { b := make([]byte, 0, 1024) buf := bytes.NewBuffer(b) w := NewJsonWriter(buf) - _, _ = w.OpenField("data", FieldArray) - _, _ = w.OpenField("", FieldObject) - _, _ = w.OpenField("subkey", FieldObject) - _, _ = w.CloseField(FieldObject) - _, _ = w.CloseField(FieldObject) - _, _ = w.CloseField(FieldArray) + w.OpenField("data", FieldArray) + w.OpenField("", FieldObject) + w.OpenField("subkey", FieldObject) + w.CloseField(FieldObject) + w.CloseField(FieldObject) + w.CloseField(FieldArray) w.Close() result := buf.String() @@ -142,13 +142,13 @@ func TestJsonWriter_SingleNonEmptySubkey(t *testing.T) { b := make([]byte, 0, 1024) buf := bytes.NewBuffer(b) w := NewJsonWriter(buf) - _, _ = w.OpenField("data", FieldArray) - _, _ = w.OpenField("", FieldObject) - _, _ = w.OpenField("subkey", FieldObject) - _, _ = w.Write([]byte(`"key": true`)) - _, _ = w.CloseField(FieldObject) - _, _ = w.CloseField(FieldObject) - _, _ = w.CloseField(FieldArray) + w.OpenField("data", FieldArray) + w.OpenField("", FieldObject) + w.OpenField("subkey", FieldObject) + w.Write([]byte(`"key": true`)) + w.CloseField(FieldObject) + w.CloseField(FieldObject) + w.CloseField(FieldArray) w.Close() result := buf.String() @@ -173,14 +173,14 @@ func TestJsonWriter_SingleNonEmptySubkeyMultipleChildren(t *testing.T) { b := make([]byte, 0, 1024) buf := bytes.NewBuffer(b) w := NewJsonWriter(buf) - _, _ = w.OpenField("data", FieldArray) - _, _ = w.OpenField("", FieldObject) - _, _ = w.OpenField("subkey", FieldObject) - _, _ = w.Write([]byte(`"key1": true`)) - _, _ = w.Write([]byte(`"key2": false`)) - _, _ = w.CloseField(FieldObject) - _, _ = w.CloseField(FieldObject) - _, _ = w.CloseField(FieldArray) + w.OpenField("data", FieldArray) + w.OpenField("", FieldObject) + w.OpenField("subkey", FieldObject) + w.Write([]byte(`"key1": true`)) + w.Write([]byte(`"key2": false`)) + w.CloseField(FieldObject) + w.CloseField(FieldObject) + w.CloseField(FieldArray) w.Close() result := buf.String() @@ -239,14 +239,14 @@ func TestJsonWriter_MultipleItemsWithSubitems(t *testing.T) { if err != nil { t.Fatal(err) } - _, _ = w.CloseField(FieldObject) - _, _ = w.CloseField(FieldArray) + w.CloseField(FieldObject) + w.CloseField(FieldArray) - _, _ = w.OpenField("errors", FieldArray) - _, _ = w.CloseField(FieldArray) + w.OpenField("errors", FieldArray) + w.CloseField(FieldArray) - _, _ = w.OpenField("meta", FieldObject) - _, _ = w.CloseField(FieldObject) + w.OpenField("meta", FieldObject) + w.CloseField(FieldObject) w.Close() @@ -263,7 +263,7 @@ func TestJsonWriter_openRoot(t *testing.T) { b := make([]byte, 0, 1024) buf := bytes.NewBuffer(b) w := NewJsonWriter(buf) - _, _ = w.Write([]byte("")) + w.Write([]byte("")) result := buf.String() @@ -311,8 +311,8 @@ func TestJsonWriter_CloseApiResponse(t *testing.T) { if err != nil { t.Fatal(err) } - _, _ = w.CloseField(FieldObject) - _, _ = w.CloseField(FieldArray) + w.CloseField(FieldObject) + w.CloseField(FieldArray) w.WriteError(errors.New("error1")) w.WriteError(errors.New("error2")) @@ -341,7 +341,7 @@ func TestJsonWriter_WriteCompound(t *testing.T) { Key: "data", FieldType: FieldArray, } - _, _ = w.WriteCompoundItem("", map[string]bool{"key": true}) + w.WriteCompoundItem("", map[string]bool{"key": true}) w.Close() result := buf.String() @@ -369,8 +369,8 @@ func TestJsonWriter_WriteCompoundTwice(t *testing.T) { Key: "data", FieldType: FieldArray, } - _, _ = w.WriteCompoundItem("", map[string]bool{"first": true}) - _, _ = w.WriteCompoundItem("", map[string]bool{"second": true}) + w.WriteCompoundItem("", map[string]bool{"first": true}) + w.WriteCompoundItem("", map[string]bool{"second": true}) w.Close() result := buf.String() @@ -395,10 +395,10 @@ func TestJsonWriter_DefaultField(t *testing.T) { Key: "data", FieldType: FieldArray, } - _, _ = w.OpenField("", FieldObject) - _, _ = w.OpenField("subkey", FieldObject) - _, _ = w.CloseField(FieldObject) - _, _ = w.CloseField(FieldObject) + w.OpenField("", FieldObject) + w.OpenField("subkey", FieldObject) + w.CloseField(FieldObject) + w.CloseField(FieldObject) w.Close() result := buf.String() @@ -441,7 +441,7 @@ func TestJsonWriter_DefaultFieldCompound(t *testing.T) { Key: "data", FieldType: FieldArray, } - _, _ = w.WriteCompoundItem("", map[string]string{}) + w.WriteCompoundItem("", map[string]string{}) w.Close() result := buf.String() diff --git a/src/apps/chifra/pkg/output/stream_test.go b/src/apps/chifra/pkg/output/stream_test.go index a335249a9a..54888a0dfb 100644 --- a/src/apps/chifra/pkg/output/stream_test.go +++ b/src/apps/chifra/pkg/output/stream_test.go @@ -40,7 +40,7 @@ var input = types.Receipt{ func helperStreamFormats(w csv.Writer, outputBuffer *bytes.Buffer, chain, format string, expectKeys bool) error { buffer := new(bytes.Buffer) - _ = StreamModel(buffer, input.Model(chain, format, false, nil), OutputOptions{ + StreamModel(buffer, input.Model(chain, format, false, nil), OutputOptions{ Format: format, NoHeader: !expectKeys, }) @@ -52,9 +52,9 @@ func helperStreamFormats(w csv.Writer, outputBuffer *bytes.Buffer, chain, format expectedItems = append(expectedItems, fmt.Sprint(data[key])) } if expectKeys { - _ = w.Write(input.Model(chain, format, false, nil).Order) + w.Write(input.Model(chain, format, false, nil).Order) } - _ = w.Write(expectedItems) + w.Write(expectedItems) w.Flush() expected := outputBuffer.String() @@ -94,7 +94,7 @@ func TestStreamJson(t *testing.T) { outputBuffer := &bytes.Buffer{} w := NewJsonWriter(outputBuffer) w.DefaultField = DefaultField{Key: "Data", FieldType: FieldArray} - _ = StreamModel(w, input.Model(chain, "json", false, nil), OutputOptions{ + StreamModel(w, input.Model(chain, "json", false, nil), OutputOptions{ Format: "json", JsonIndent: " ", }) @@ -169,7 +169,7 @@ func TestStreamMany(t *testing.T) { // Print the values and try to re-parse them to check if // we get the same data - _ = StreamMany(context.Background(), renderData, OutputOptions{ + StreamMany(context.Background(), renderData, OutputOptions{ Writer: jw, Format: "json", }) diff --git a/src/apps/chifra/pkg/rpc/provider/alchemy.go b/src/apps/chifra/pkg/rpc/provider/alchemy.go index e67cfdae4e..04ff1c727f 100644 --- a/src/apps/chifra/pkg/rpc/provider/alchemy.go +++ b/src/apps/chifra/pkg/rpc/provider/alchemy.go @@ -53,7 +53,7 @@ func alchemyCategory(requestType string) (category string) { type AlchemyProvider struct { printProgress bool - perPage int + perPage int //nolint:unused conn *rpc.Connection limiter *rate.Limiter baseUrl string diff --git a/src/apps/chifra/pkg/rpc/provider/alchemy_test.go b/src/apps/chifra/pkg/rpc/provider/alchemy_test.go index e5d686f1f2..1f0203e196 100644 --- a/src/apps/chifra/pkg/rpc/provider/alchemy_test.go +++ b/src/apps/chifra/pkg/rpc/provider/alchemy_test.go @@ -100,7 +100,7 @@ func mockAlchemyServer(t *testing.T) (ts *httptest.Server) { if err != nil { t.Fatal(err) } - _, _ = w.Write(b) + w.Write(b) })) return ts diff --git a/src/apps/chifra/pkg/rpc/provider/covalent_test.go b/src/apps/chifra/pkg/rpc/provider/covalent_test.go index 0bea7fe696..07cfbaf5c4 100644 --- a/src/apps/chifra/pkg/rpc/provider/covalent_test.go +++ b/src/apps/chifra/pkg/rpc/provider/covalent_test.go @@ -155,7 +155,7 @@ func mockCovalentServer(t *testing.T) (ts *httptest.Server) { if err != nil { t.Fatal(err) } - _, _ = w.Write(b) + w.Write(b) })) return ts @@ -253,7 +253,7 @@ LOOP: Orig: "14000000", }, } - _ = provider.TransactionsByAddress(ctx, query, errors) + provider.TransactionsByAddress(ctx, query, errors) err := <-errors if err == nil { t.Fatal("expected error") diff --git a/src/apps/chifra/pkg/rpc/provider/etherscan_test.go b/src/apps/chifra/pkg/rpc/provider/etherscan_test.go index e0e0616b51..ee2e74aadf 100644 --- a/src/apps/chifra/pkg/rpc/provider/etherscan_test.go +++ b/src/apps/chifra/pkg/rpc/provider/etherscan_test.go @@ -104,7 +104,7 @@ func mockEtherscanServer(t *testing.T) (ts *httptest.Server) { if err != nil { t.Fatal(err) } - _, _ = w.Write(b) + w.Write(b) })) return ts @@ -227,7 +227,7 @@ LOOP: Orig: "14000000", }, } - _ = provider.TransactionsByAddress(ctx, query, errors) + provider.TransactionsByAddress(ctx, query, errors) err := <-errors if err == nil { t.Fatal("expected error") diff --git a/src/apps/chifra/pkg/rpc/provider/key_test.go b/src/apps/chifra/pkg/rpc/provider/key_test.go index 0da99599a4..5388f14dab 100644 --- a/src/apps/chifra/pkg/rpc/provider/key_test.go +++ b/src/apps/chifra/pkg/rpc/provider/key_test.go @@ -93,7 +93,7 @@ func mockKeyServer(t *testing.T) (ts *httptest.Server) { if err != nil { t.Fatal(err) } - _, _ = w.Write(b) + w.Write(b) })) return ts diff --git a/src/apps/chifra/pkg/rpc/provider/paginator_page_id_test.go b/src/apps/chifra/pkg/rpc/provider/paginator_page_id_test.go index 09465919d0..2a6cbfa110 100644 --- a/src/apps/chifra/pkg/rpc/provider/paginator_page_id_test.go +++ b/src/apps/chifra/pkg/rpc/provider/paginator_page_id_test.go @@ -13,7 +13,7 @@ func TestPageIdPaginator_NextPage(t *testing.T) { if paginator.page != "latest" { t.Fatal("wrong page after initialization:", paginator.page) } - _ = paginator.SetNextPage("next") + paginator.SetNextPage("next") err = paginator.NextPage() if err != nil { diff --git a/src/apps/chifra/pkg/rpc/query/query_test.go b/src/apps/chifra/pkg/rpc/query/query_test.go index e839b93ed7..1c918bb1fb 100644 --- a/src/apps/chifra/pkg/rpc/query/query_test.go +++ b/src/apps/chifra/pkg/rpc/query/query_test.go @@ -27,7 +27,7 @@ func TestFromRpcCounter(t *testing.T) { t.Fatal(err) } ids = append(ids, payload.ID) - _, _ = w.Write([]byte("{}")) + w.Write([]byte("{}")) })) defer server.Close() diff --git a/src/apps/chifra/pkg/tslib/tslib_integration_test.go b/src/apps/chifra/pkg/tslib/tslib_integration_test.go index 6cfe8a9db0..9080932da8 100644 --- a/src/apps/chifra/pkg/tslib/tslib_integration_test.go +++ b/src/apps/chifra/pkg/tslib/tslib_integration_test.go @@ -28,7 +28,7 @@ func TestLoadTimestampsPass(t *testing.T) { {name: "Block 1 Mil", bn: 1000000, ts: 1455404053, date: "2016-02-13 22:54:13"}, } - _ = config.GetRootConfig() + config.GetRootConfig() for _, e := range expected { bn, err := FromTsToBn(utils.GetTestChain(), e.ts) if err != nil { diff --git a/src/apps/chifra/pkg/validate/block_integration_test.go b/src/apps/chifra/pkg/validate/block_integration_test.go index 505bb78c84..a937037651 100644 --- a/src/apps/chifra/pkg/validate/block_integration_test.go +++ b/src/apps/chifra/pkg/validate/block_integration_test.go @@ -15,7 +15,7 @@ import ( ) func Test_BlockRanges(t *testing.T) { - _ = config.GetRootConfig() + config.GetRootConfig() for _, item := range testBlocks { if !item.enabled { continue