Skip to content

Commit

Permalink
fix: Address lint issues and field alignment
Browse files Browse the repository at this point in the history
  • Loading branch information
devin-ai-integration[bot] and trajan0x committed Dec 13, 2024
1 parent bb48e05 commit ee58481
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 27 deletions.
4 changes: 2 additions & 2 deletions tools/abigen/internal/etherscan/etherscan.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ func newEtherscanABIClient(parentCtx context.Context, chainID uint32, url string
}

customization.BeforeRequest = func(_, _ string, _ map[string]interface{}) error {
_, err := client.rateLimiter.obtainLock(ctx)
return err
_, lockErr := client.rateLimiter.obtainLock(ctx)
return lockErr

Check warning on line 62 in tools/abigen/internal/etherscan/etherscan.go

View check run for this annotation

Codecov / codecov/patch

tools/abigen/internal/etherscan/etherscan.go#L61-L62

Added lines #L61 - L62 were not covered by tests
}

customization.AfterRequest = func(_, action string, _ map[string]interface{}, _ interface{}, _ error) {
Expand Down
4 changes: 2 additions & 2 deletions tools/abigen/internal/etherscan/ratelimiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ import (

// fileRateLimiter implements a file based rate limiter for limiting requests across abi generate commands.
type fileRateLimiter struct {

Check failure on line 16 in tools/abigen/internal/etherscan/ratelimiter.go

View workflow job for this annotation

GitHub Actions / Lint (tools)

fieldalignment: struct with 40 pointer bytes could be 24 (govet)
mux sync.Mutex // Mutex (40-byte alignment)
waitBetweenRequests time.Duration // Duration (8-byte alignment)
flock *flock.Flock // Pointer (8-byte alignment)
lastRequestFile *os.File // Pointer (8-byte alignment)
waitBetweenRequests time.Duration // Duration (8-byte alignment)
lockFolderPath string // String (8-byte alignment)
mux sync.Mutex // Mutex (1-byte alignment, moved to end)
}

// fileRateTimeout is how long to wait for file rate limiting.
Expand Down
16 changes: 8 additions & 8 deletions tools/abigen/internal/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ func BuildTemplates(ctx context.Context, version, file, pkg, filename string, op

// Gather all non-excluded contract for binding
for name, contract := range contracts {
abi, err := json.Marshal(contract.Info.AbiDefinition) // Flatten the compiler parse
if err != nil {
panic(fmt.Errorf("failed to parse ABIs from compiler output: %w", err))
abi, marshalErr := json.Marshal(contract.Info.AbiDefinition) // Flatten the compiler parse
if marshalErr != nil {
panic(fmt.Errorf("failed to parse ABIs from compiler output: %w", marshalErr))

Check warning on line 85 in tools/abigen/internal/generate.go

View check run for this annotation

Codecov / codecov/patch

tools/abigen/internal/generate.go#L83-L85

Added lines #L83 - L85 were not covered by tests
}
abis = append(abis, string(abi))
bins = append(bins, contract.Code)
Expand Down Expand Up @@ -284,14 +284,14 @@ func prepareDockerCommand(version, filePath string, optimizeRuns int, evmVersion

// Get source directory and ensure it exists
sourceDir := filepath.Dir(absPath)
if _, err := os.Stat(sourceDir); err != nil {
if _, statErr := os.Stat(sourceDir); statErr != nil {
return nil
}

Check warning on line 289 in tools/abigen/internal/generate.go

View check run for this annotation

Codecov / codecov/patch

tools/abigen/internal/generate.go#L288-L289

Added lines #L288 - L289 were not covered by tests

// Create Docker mount path and source file path
dockerMountPath := "/solidity"
relPath, err := filepath.Rel(sourceDir, absPath)
if err != nil {
relPath, pathErr := filepath.Rel(sourceDir, absPath)
if pathErr != nil {
return nil
}

Check warning on line 296 in tools/abigen/internal/generate.go

View check run for this annotation

Codecov / codecov/patch

tools/abigen/internal/generate.go#L295-L296

Added lines #L295 - L296 were not covered by tests
dockerSourcePath := filepath.Join(dockerMountPath, relPath)
Expand Down Expand Up @@ -412,8 +412,8 @@ func executeBinaryCompilation(ctx context.Context, binaryPath, filePath string,
cmd.Stdout = &stdout
cmd.Dir = baseDir

if err := cmd.Run(); err != nil {
return nil, fmt.Errorf("solc failed: %w\nstderr: %s", err, stderr.String())
if cmdErr := cmd.Run(); cmdErr != nil {
return nil, fmt.Errorf("solc failed: %w\nstderr: %s", cmdErr, stderr.String())
}

contracts, err := compiler.ParseCombinedJSON(stdout.Bytes(), string(solContents), filepath.Base(binaryPath), filepath.Base(binaryPath), strings.Join(args, " "))
Expand Down
25 changes: 13 additions & 12 deletions tools/abigen/internal/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,18 @@ func (a *AbiSuite) TestCompileSolidityExplicitEVM() {

func TestFilePathsAreEqual(t *testing.T) {
tests := []struct {
err error // Interface type (16-byte alignment)
file1 string // String fields (8-byte alignment)
file2 string // String fields (8-byte alignment)
want bool // Bool field (1-byte alignment)
_ [7]byte // padding
err error // Interface type (16-byte alignment)
}{
{"path/to/file1.txt", "path/to/file2.txt", false, [7]byte{}, nil},
{"path/to/file1.txt", "path/to/file1.txt", true, [7]byte{}, nil},
{"path/to/file2.txt", "path/to/file2.txt", true, [7]byte{}, nil},
{"path/to/file1.txt", "", false, [7]byte{}, filepath.ErrBadPattern},
{"", "path/to/file2.txt", false, [7]byte{}, filepath.ErrBadPattern},
{"nonexistent/file.txt", "path/to/file.txt", false, [7]byte{}, nil},
{err: nil, file1: "path/to/file1.txt", file2: "path/to/file2.txt", want: false},
{err: nil, file1: "path/to/file1.txt", file2: "path/to/file1.txt", want: true},
{err: nil, file1: "path/to/file2.txt", file2: "path/to/file2.txt", want: true},
{err: filepath.ErrBadPattern, file1: "path/to/file1.txt", file2: "", want: false},
{err: filepath.ErrBadPattern, file1: "", file2: "path/to/file2.txt", want: false},
{err: nil, file1: "nonexistent/file.txt", file2: "path/to/file.txt", want: false},
}

for _, tt := range tests {
Expand Down Expand Up @@ -271,13 +271,14 @@ func TestCompileSolidityDockerStrategy(t *testing.T) {
type ContractSettings struct {

Check failure on line 271 in tools/abigen/internal/generate_test.go

View workflow job for this annotation

GitHub Actions / Lint (tools)

fieldalignment: struct with 48 pointer bytes could be 40 (govet)
CompilationTarget map[string]string `json:"compilationTarget"` // Map (16-byte alignment)
Metadata map[string]string `json:"metadata"` // Map (16-byte alignment)
Libraries struct{} `json:"libraries"` // Struct (8-byte alignment)
Remappings []interface{} `json:"remappings"` // Slice (16-byte alignment)
EvmVersion string `json:"evmVersion"` // String (8-byte alignment)
Libraries struct{} `json:"libraries"` // Empty struct (0-byte)
Optimizer struct {
Enabled bool `json:"enabled"` // Bool (1-byte alignment)
Runs int `json:"runs"` // Int (8-byte alignment)
Runs int `json:"runs"` // Int (8-byte alignment)
Enabled bool `json:"enabled"` // Bool (1-byte alignment)
_ [7]byte // padding
} `json:"optimizer"`
EvmVersion string `json:"evmVersion"` // String (8-byte alignment)
Remappings []interface{} `json:"remappings"` // Slice (16-byte alignment)
}

type ContractMetadata struct {

Check failure on line 284 in tools/abigen/internal/generate_test.go

View workflow job for this annotation

GitHub Actions / Lint (tools)

fieldalignment: struct with 128 pointer bytes could be 104 (govet)
Expand Down
2 changes: 1 addition & 1 deletion tools/abigen/internal/solc/binary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func TestGetBinary(t *testing.T) {
t.Fatalf("Failed to get binary: %v", err)
}

if _, err := os.Stat(binary); os.IsNotExist(err) {
if _, statErr := os.Stat(binary); os.IsNotExist(statErr) {
t.Error("Binary file does not exist")
}

Expand Down
4 changes: 2 additions & 2 deletions tools/modulecopier/internal/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ func GetModulePath(dependencyName string) (modPath string, err error) {
}

// make sure the module is not a replace which we don't have functionality for yet
if _, err := hasUnsupportedDirective(modFile, dependencyName); err != nil {
return "", fmt.Errorf("module has unupoorted directive: %w", err)
if _, directiveErr := hasUnsupportedDirective(modFile, dependencyName); directiveErr != nil {
return "", fmt.Errorf("module has unupoorted directive: %w", directiveErr)

Check warning on line 27 in tools/modulecopier/internal/module.go

View check run for this annotation

Codecov / codecov/patch

tools/modulecopier/internal/module.go#L27

Added line #L27 was not covered by tests
}

var resolvedModule *modfile.Require
Expand Down

0 comments on commit ee58481

Please sign in to comment.