diff --git a/compiler_test.go b/compiler_test.go index a799d42..04d536d 100644 --- a/compiler_test.go +++ b/compiler_test.go @@ -172,6 +172,16 @@ func TestCompiler(t *testing.T) { solc: solc, sync: false, }, + { + name: "Invalid Compiler config", + wantErr: true, + wantCompileErr: true, + compilerConfig: func() *CompilerConfig { + return nil + }(), + solc: solc, + sync: false, + }, } for _, testCase := range testCases { diff --git a/helpers.go b/helpers.go index 5f5d99d..52df3df 100644 --- a/helpers.go +++ b/helpers.go @@ -8,17 +8,6 @@ import ( ) // validatePath checks the validity of a given path. -// It ensures that: -// - The path exists. -// - The path points to a directory. -// - The directory is readable. -// -// Parameters: -// - path: The file system path to validate. -// -// Returns: -// - nil if the path is valid. -// - An error if the path is invalid or any other error occurs. func validatePath(path string) error { info, err := os.Stat(path) if os.IsNotExist(err) { @@ -46,12 +35,6 @@ func validatePath(path string) error { } // getCleanedVersionTag removes the "v" prefix from a version tag. -// -// Parameters: -// - versionTag: A string representing the version tag to be cleaned. -// -// Returns: -// - A string representing the cleaned version tag. func getCleanedVersionTag(versionTag string) string { return strings.ReplaceAll(versionTag, "v", "") } diff --git a/logger.go b/logger.go index b8cc7e9..6d63634 100644 --- a/logger.go +++ b/logger.go @@ -8,25 +8,18 @@ import ( // GetProductionLogger creates and returns a new production logger using the zap library. // The production logger is optimized for performance and is suitable for use in production environments. -// -// Returns: -// - A pointer to the created zap.Logger instance. -// - An error if there's any issue creating the logger. -func GetProductionLogger() (*zap.Logger, error) { - logger, err := zap.NewProduction() +// The log level can be set using the provided level parameter. +func GetProductionLogger(level zapcore.Level) (*zap.Logger, error) { + config := zap.NewProductionConfig() + config.Level = zap.NewAtomicLevelAt(level) + config.EncoderConfig.EncodeLevel = zapcore.CapitalColorLevelEncoder + logger, err := config.Build() return logger, err } // GetDevelopmentLogger creates and returns a new development logger using the zap library. // The development logger is optimized for development and debugging, providing more detailed logs. // The log level can be set using the provided level parameter. -// -// Parameters: -// - level: The desired log level (e.g., DebugLevel, InfoLevel, etc.). -// -// Returns: -// - A pointer to the created zap.Logger instance. -// - An error if there's any issue creating the logger. func GetDevelopmentLogger(level zapcore.Level) (*zap.Logger, error) { config := zap.NewDevelopmentConfig() config.Level = zap.NewAtomicLevelAt(level) diff --git a/releases.go b/releases.go index 4a8bff8..428a6e5 100644 --- a/releases.go +++ b/releases.go @@ -14,10 +14,6 @@ func (s *Solc) GetLocalReleasesPath() string { } // GetLocalReleases fetches the Solidity versions saved locally in releases.json. -// -// Returns: -// - A slice of Version representing all the fetched Solidity versions. -// - An error if there's any issue during the fetch process. func (s *Solc) GetLocalReleases() ([]Version, error) { data, err := os.ReadFile(s.GetLocalReleasesPath()) if err != nil { @@ -34,18 +30,11 @@ func (s *Solc) GetLocalReleases() ([]Version, error) { } // GetCachedReleases returns the cached releases from memory. -// -// Returns: -// - A slice of Version representing all the cached Solidity versions. func (s *Solc) GetCachedReleases() []Version { return s.localReleases } // GetLatestRelease reads the memory cache or local releases.json file and returns the latest Solidity version. -// -// Returns: -// - A pointer to the latest Version. -// - An error if there's any issue during the fetch process. func (s *Solc) GetLatestRelease() (*Version, error) { var versions []Version @@ -69,13 +58,6 @@ func (s *Solc) GetLatestRelease() (*Version, error) { } // GetRelease reads the memory cache or local releases.json file and returns the Solidity version matching the given tag name. -// -// Parameters: -// - tagName: A string representing the tag name of the desired Solidity version. -// -// Returns: -// - A pointer to the matching Version. -// - An error if there's any issue during the fetch process or if the version is not found. func (s *Solc) GetRelease(tagName string) (*Version, error) { var versions []Version @@ -107,10 +89,6 @@ func (s *Solc) GetRelease(tagName string) (*Version, error) { } // GetReleasesSimplified fetches the Solidity versions saved locally in releases.json and returns a simplified version info. -// -// Returns: -// - A slice of VersionInfo representing the simplified version information. -// - An error if there's any issue during the fetch process. func (s *Solc) GetReleasesSimplified() ([]VersionInfo, error) { var versions []Version @@ -159,12 +137,6 @@ func (s *Solc) GetBinary(version string) (string, error) { } // RemoveBinary removes the binary file of the specified version. -// -// Parameters: -// - version: A string representing the Solidity version whose binary should be removed. -// -// Returns: -// - An error if there's any issue during the removal process or if the binary is not found. func (s *Solc) RemoveBinary(version string) error { version = getCleanedVersionTag(version) _, err := s.GetRelease(version) diff --git a/releases/releases.json b/releases/releases.json index 5731492..c58c9bf 100644 --- a/releases/releases.json +++ b/releases/releases.json @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:df6f80e7f72cfcee0df657421b98208e21307d4442c4c694ab79b785545e7795 +oid sha256:863fcb78eb72033f6a58ede1c92156c0e04e00694cc8febac6a060710a18e222 size 965663 diff --git a/solc_test.go b/solc_test.go index 00fd61b..d9378a6 100644 --- a/solc_test.go +++ b/solc_test.go @@ -11,7 +11,7 @@ import ( ) func TestSolc(t *testing.T) { - logger, err := GetProductionLogger() + logger, err := GetProductionLogger(zap.InfoLevel) assert.NoError(t, err) assert.NotNil(t, logger) zap.ReplaceGlobals(logger) diff --git a/syncer.go b/syncer.go index 4a5a1cf..41452ba 100644 --- a/syncer.go +++ b/syncer.go @@ -17,10 +17,6 @@ import ( ) // SyncReleases fetches the available Solidity versions from GitHub, saves them to releases.json, and reloads the local cache. -// -// Returns: -// - A slice of Version representing all the fetched Solidity versions. -// - An error if there's any issue during the synchronization process. func (s *Solc) SyncReleases() ([]Version, error) { var allVersions []Version page := 1 @@ -87,13 +83,6 @@ func (s *Solc) SyncReleases() ([]Version, error) { } // SyncBinaries downloads all the binaries for the specified versions in parallel. -// -// Parameters: -// - versions: A slice of Version representing the Solidity versions for which binaries should be downloaded. -// - limitVersion: A string representing a specific version to limit the download to. If empty, binaries for all versions will be downloaded. -// -// Returns: -// - An error if there's any issue during the download process. func (s *Solc) SyncBinaries(versions []Version, limitVersion string) error { var wg sync.WaitGroup errorsCh := make(chan error, len(versions)) @@ -117,8 +106,8 @@ func (s *Solc) SyncBinaries(versions []Version, limitVersion string) error { if _, err := os.Stat(filename); os.IsNotExist(err) { totalDownloads++ - zap.L().Debug( - "Downloading solc release", + zap.L().Info( + "Downloading missing solc release", zap.String("version", versionTag), zap.String("asset_name", asset.Name), zap.String("asset_local_filename", filepath.Base(filename)), @@ -193,9 +182,6 @@ func (s *Solc) SyncBinaries(versions []Version, limitVersion string) error { // Sync fetches the available Solidity versions from GitHub, saves them to releases.json, reloads the local cache, // and downloads all the binaries for the distribution for future use. -// -// Returns: -// - An error if there's any issue during the synchronization process. func (s *Solc) Sync() error { versions, err := s.SyncReleases() if err != nil { @@ -213,12 +199,6 @@ func (s *Solc) Sync() error { // SyncOne fetches a specific Solidity version from GitHub, saves it to releases.json, reloads the local cache, // and downloads the binary for the distribution for future use. -// -// Parameters: -// - version: A pointer to a Version representing the specific Solidity version to be synchronized. -// -// Returns: -// - An error if there's any issue during the synchronization process. func (s *Solc) SyncOne(version *Version) error { if version == nil { return fmt.Errorf("version must be provided to synchronize one version") @@ -242,13 +222,6 @@ func (s *Solc) SyncOne(version *Version) error { } // downloadFile downloads a file from the provided URL and saves it to the specified path. -// -// Parameters: -// - filepath: A string representing the path where the downloaded file should be saved. -// - url: A string representing the URL from which the file should be downloaded. -// -// Returns: -// - An error if there's any issue during the download process. func (s *Solc) downloadFile(file string, url string) error { // Just a bit of the time because we could receive 503 from GitHub so we don't want to spam them randomDelayBetween500And1500() @@ -284,7 +257,7 @@ func (s *Solc) downloadFile(file string, url string) error { // #nosec G302 // G302 (CWE-276): Expect file permissions to be 0600 or less (Confidence: HIGH, Severity: MEDIUM) // We want executable files to be executable by the user running the program so we can't use 0600. - if err := os.Chmod(file, 0777); err != nil { + if err := os.Chmod(file, 0700); err != nil { return fmt.Errorf("failed to set file as executable: %v", err) }