-
Notifications
You must be signed in to change notification settings - Fork 116
Check that custom dependency version is at least equal to min version defined in latest.json #2734
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
a03b3d9
control default latest version for avago and subnetevm
sukantoraymond 1ecb4fe
add rpc to json
sukantoraymond 1adf4a3
get latest cli version
sukantoraymond 79a9cc2
update json model
sukantoraymond 6cc37fc
update evm prompts
sukantoraymond 079b182
update evm prompt
sukantoraymond 16ff987
update avalanchego latest
sukantoraymond 36ccd1e
add e2e test
sukantoraymond 1556b85
remove unncessary file
sukantoraymond cbbfe9e
lint
sukantoraymond f56b137
try with lower versions
sukantoraymond 5eba446
update how we get newest avago version
sukantoraymond 9b8b529
Merge branch 'main' into control-default-version
sukantoraymond 8dd666f
fix lint
sukantoraymond f864a75
address comments
sukantoraymond 3bb41a4
add min version
sukantoraymond 06789f6
fix ci
sukantoraymond 70add0b
fix ci
sukantoraymond 55dc686
add test for min version
sukantoraymond 64e4ed6
update tests
sukantoraymond 1b82986
fix lint
sukantoraymond bbd6742
Merge branch 'main' into control-default-version
sukantoraymond cb591a9
fix lint
sukantoraymond 207182d
Merge branch 'control-default-version' into min-version
sukantoraymond f65345b
Merge branch 'main' into control-default-version
sukantoraymond 7d8b016
lint
sukantoraymond 5b90883
move to dependencies pkg
sukantoraymond afb4852
lint
sukantoraymond ffbd276
lint
sukantoraymond 2d8bd77
Merge branch 'control-default-version' into min-version
sukantoraymond 4b45bff
lint
sukantoraymond f84e92d
Merge branch 'main' into min-version
sukantoraymond 8d45f3e
fix merge
sukantoraymond 6846f9a
address comments
sukantoraymond 40deb5e
lint
sukantoraymond File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| // Copyright (C) 2022, Ava Labs, Inc. All rights reserved. | ||
| // See the file LICENSE for licensing terms. | ||
| package dependencies | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "fmt" | ||
|
|
||
| "golang.org/x/mod/semver" | ||
|
|
||
| "github.com/ava-labs/avalanche-cli/pkg/models" | ||
|
|
||
| "github.com/ava-labs/avalanche-cli/pkg/application" | ||
| "github.com/ava-labs/avalanche-cli/pkg/constants" | ||
| ) | ||
|
|
||
| func CheckVersionIsOverMin(app *application.Avalanche, dependencyName string, network models.Network, version string) error { | ||
| dependencyBytes, err := app.Downloader.Download(constants.CLILatestDependencyURL) | ||
felipemadero marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| var parsedDependency models.CLIDependencyMap | ||
| if err = json.Unmarshal(dependencyBytes, &parsedDependency); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| switch dependencyName { | ||
| case constants.AvalancheGoRepoName: | ||
| // version has to be at least higher than minimum version specified for the dependency | ||
| minVersion := parsedDependency.AvalancheGo[network.Name()].MinimumVersion | ||
| versionComparison := semver.Compare(version, minVersion) | ||
| if versionComparison == -1 { | ||
| return fmt.Errorf("minimum version of %s that is supported by CLI is %s, current version provided is %s", dependencyName, minVersion, version) | ||
| } | ||
| return nil | ||
| default: | ||
| return fmt.Errorf("minimum version check is unsupported %s dependency", dependencyName) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| // Copyright (C) 2022, Ava Labs, Inc. All rights reserved. | ||
| // See the file LICENSE for licensing terms. | ||
|
|
||
| package dependencies | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/ava-labs/avalanche-cli/internal/mocks" | ||
| "github.com/ava-labs/avalanche-cli/pkg/application" | ||
| "github.com/ava-labs/avalanche-cli/pkg/constants" | ||
| "github.com/ava-labs/avalanche-cli/pkg/models" | ||
| "github.com/stretchr/testify/mock" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| var testCLIMinVersion = []byte(`{"subnet-evm":"v0.7.3","rpc":39,"avalanchego":{"Local Network":{"latest-version":"v1.13.0", "minimum-version":""},"DevNet":{"latest-version":"v1.13.0", "minimum-version":""},"Fuji":{"latest-version":"v1.13.0", "minimum-version":"v1.13.0-fuji"},"Mainnet":{"latest-version":"v1.13.0", "minimum-version":"v1.13.0"}}}`) | ||
|
|
||
| func TestCheckMinDependencyVersion(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| dependency string | ||
| expectedError bool | ||
| cliDependencyData []byte | ||
| customVersion string | ||
| network models.Network | ||
| }{ | ||
| { | ||
| name: "custom avalanchego dependency equal to cli minimum supported version of avalanchego", | ||
| dependency: constants.AvalancheGoRepoName, | ||
| cliDependencyData: testCLIMinVersion, | ||
| expectedError: false, | ||
| customVersion: "v1.13.0-fuji", | ||
| network: models.NewFujiNetwork(), | ||
| }, | ||
| { | ||
| name: "custom avalanchego dependency higher than cli minimum supported version of avalanchego", | ||
| dependency: constants.AvalancheGoRepoName, | ||
| cliDependencyData: testCLIMinVersion, | ||
| expectedError: false, | ||
| customVersion: "v1.13.0", | ||
| network: models.NewFujiNetwork(), | ||
| }, | ||
| { | ||
| name: "custom avalanchego dependency equal to cli minimum supported version of avalanchego", | ||
| dependency: constants.AvalancheGoRepoName, | ||
| cliDependencyData: testCLIMinVersion, | ||
| expectedError: false, | ||
| customVersion: "v1.13.0-fuji", | ||
| network: models.NewFujiNetwork(), | ||
| }, | ||
| { | ||
| name: "custom avalanchego dependency higher than cli minimum supported version of avalanchego", | ||
| dependency: constants.AvalancheGoRepoName, | ||
| cliDependencyData: testCLIMinVersion, | ||
| expectedError: false, | ||
| customVersion: "v1.13.1", | ||
| network: models.NewFujiNetwork(), | ||
| }, | ||
| { | ||
| name: "custom avalanchego dependency lower than cli minimum supported version of avalanchego", | ||
| dependency: constants.AvalancheGoRepoName, | ||
| cliDependencyData: testCLIMinVersion, | ||
| expectedError: true, | ||
| customVersion: "v1.12.2", | ||
| network: models.NewFujiNetwork(), | ||
| }, | ||
| { | ||
| name: "custom avalanchego dependency for network that doesn't have minimum supported version of avalanchego", | ||
| dependency: constants.AvalancheGoRepoName, | ||
| cliDependencyData: testCLIMinVersion, | ||
| expectedError: false, | ||
| customVersion: "v1.12.2", | ||
| network: models.NewLocalNetwork(), | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| mockDownloader := &mocks.Downloader{} | ||
| mockDownloader.On("Download", mock.MatchedBy(func(url string) bool { | ||
| return url == constants.CLILatestDependencyURL | ||
| })).Return(tt.cliDependencyData, nil) | ||
|
|
||
| app := application.New() | ||
| app.Downloader = mockDownloader | ||
|
|
||
| t.Run(tt.name, func(t *testing.T) { | ||
| err := CheckVersionIsOverMin(app, tt.dependency, tt.network, tt.customVersion) | ||
| if tt.expectedError { | ||
| require.Error(t, err) | ||
| } else { | ||
| require.NoError(t, err) | ||
| } | ||
| }) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.