Skip to content

Commit

Permalink
Merge main to unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
0x19 committed Aug 20, 2023
2 parents 4e39e48 + d9446d7 commit ec1b76a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion releases/releases.json
Git LFS file not shown
8 changes: 7 additions & 1 deletion solc.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"net/http"
"runtime"
"time"
)

// Solc represents the main structure for interacting with the Solidity compiler.
Expand All @@ -15,10 +16,10 @@ type Solc struct {
client *http.Client
gOOSFunc func() string
localReleases []Version
lastSync time.Time
}

// New initializes and returns a new instance of the Solc structure.
// It requires a context and a configuration to be provided.
func New(ctx context.Context, config *Config) (*Solc, error) {
if config == nil {
return nil, fmt.Errorf("config needs to be provided")
Expand All @@ -43,6 +44,11 @@ func (s *Solc) GetContext() context.Context {
return s.ctx
}

// LastSyncTime retrieves the last time the Solc instance was synced.
func (s *Solc) LastSyncTime() time.Time {
return s.lastSync
}

// GetConfig retrieves the configuration associated with the Solc instance.
func (s *Solc) GetConfig() *Config {
return s.config
Expand Down
7 changes: 7 additions & 0 deletions syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ func (s *Solc) SyncReleases() ([]Version, error) {
var allVersions []Version
page := 1

// Sync maximum 4 times per day in order to increase the speed of the sync process when there's really
// no need to sync more often than that.
if time.Since(s.lastSync) < time.Duration(6*time.Hour) {
return s.localReleases, nil
}

for {
url := fmt.Sprintf("%s?page=%d", s.config.GetReleasesUrl(), page)
req, err := http.NewRequest("GET", url, nil)
Expand Down Expand Up @@ -72,6 +78,7 @@ func (s *Solc) SyncReleases() ([]Version, error) {
}

s.localReleases = allVersions
s.lastSync = time.Now()
return allVersions, nil
}

Expand Down
2 changes: 2 additions & 0 deletions syncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func TestSyncer(t *testing.T) {
assert.NoError(t, err)
}

assert.NotNil(t, s.LastSyncTime())
})
}
}
Expand Down Expand Up @@ -108,6 +109,7 @@ func TestSyncOnce(t *testing.T) {
assert.NoError(t, err)
}

assert.NotNil(t, s.LastSyncTime())
})
}
}

0 comments on commit ec1b76a

Please sign in to comment.