Skip to content

Commit

Permalink
Updates linter and turns off linting in _test files (as we used to do)
Browse files Browse the repository at this point in the history
  • Loading branch information
tjayrush committed Apr 27, 2024
1 parent e8a1c71 commit 479b3b6
Show file tree
Hide file tree
Showing 19 changed files with 104 additions and 105 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions src/apps/chifra/.golangci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
run:
exclude-files:
- ".*_test.go"
tests: false
linters:
disable:
- ineffassign
Expand Down
21 changes: 0 additions & 21 deletions src/apps/chifra/pkg/index/bloom.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
11 changes: 0 additions & 11 deletions src/apps/chifra/pkg/index/bloom_ismember.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 32 additions & 0 deletions src/apps/chifra/pkg/index/bloom_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/apps/chifra/pkg/names/custom_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
98 changes: 49 additions & 49 deletions src/apps/chifra/pkg/output/json_writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -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()

Expand All @@ -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()

Expand Down Expand Up @@ -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"))
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
10 changes: 5 additions & 5 deletions src/apps/chifra/pkg/output/stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
Expand All @@ -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()

Expand Down Expand Up @@ -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: " ",
})
Expand Down Expand Up @@ -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",
})
Expand Down
2 changes: 1 addition & 1 deletion src/apps/chifra/pkg/rpc/provider/alchemy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/apps/chifra/pkg/rpc/provider/alchemy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 479b3b6

Please sign in to comment.