-
Notifications
You must be signed in to change notification settings - Fork 117
Subnet evm min version check #2740
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
Closed
Closed
Changes from all commits
Commits
Show all changes
37 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 35413e4
update tests
sukantoraymond 9fae8d1
add more min subnet evm version check
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 933e24b
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 d7fb635
Merge branch 'min-version' into subnet-evm-min-version-check
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
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,50 @@ | ||
| // 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" | ||
| ) | ||
|
|
||
| var UpdateSubnetEVMInstruction = "To update the blockchain's Subnet-EVM version, call avalanche blockchain upgrade vm <blockchainName> --config --version <version>" | ||
|
|
||
| func CheckVersionIsOverMin(app *application.Avalanche, dependencyName string, network models.Network, version string) error { | ||
| dependencyBytes, err := app.Downloader.Download(constants.CLILatestDependencyURL) | ||
| 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", dependencyName, minVersion) | ||
| } | ||
| return nil | ||
| case constants.SubnetEVMRepoName: | ||
| // version has to be at least higher than minimum version specified for the dependency | ||
| minVersion := parsedDependency.SubnetEVM[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", dependencyName, minVersion) | ||
| } | ||
| return nil | ||
| default: | ||
| return fmt.Errorf("can't check minimum version for dependency: %s", 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,120 @@ | ||
| // 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":{"Local Network":{"latest-version":"v0.7.3", "minimum-version":""},"DevNet":{"latest-version":"v0.7.3", "minimum-version":""},"Fuji":{"latest-version":"v0.7.3", "minimum-version":"v0.7.2"},"Mainnet":{"latest-version":"v0.7.3", "minimum-version":"v0.7.2"}},"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 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(), | ||
| }, | ||
| { | ||
| name: "custom subnetEVM dependency equal to cli minimum supported version of subnetEVM", | ||
| dependency: constants.SubnetEVMRepoName, | ||
| cliDependencyData: testCLIMinVersion, | ||
| expectedError: false, | ||
| customVersion: "v0.7.2", | ||
| network: models.NewFujiNetwork(), | ||
| }, | ||
| { | ||
| name: "custom subnetEVM dependency higher than cli minimum supported version of subnetEVM", | ||
| dependency: constants.SubnetEVMRepoName, | ||
| cliDependencyData: testCLIMinVersion, | ||
| expectedError: false, | ||
| customVersion: "v0.7.3", | ||
| network: models.NewFujiNetwork(), | ||
| }, | ||
| { | ||
| name: "custom subnetEVM dependency lower than cli minimum supported version of subnetEVM", | ||
| dependency: constants.SubnetEVMRepoName, | ||
| cliDependencyData: testCLIMinVersion, | ||
| expectedError: true, | ||
| customVersion: "v0.7.1", | ||
| network: models.NewFujiNetwork(), | ||
| }, | ||
| { | ||
| name: "custom subnetEVM dependency for network that doesn't have minimum supported version of subnetEVM", | ||
| dependency: constants.SubnetEVMRepoName, | ||
| cliDependencyData: testCLIMinVersion, | ||
| expectedError: false, | ||
| customVersion: "v0.7.1", | ||
| 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,9 @@ import ( | |
| "fmt" | ||
| "os" | ||
|
|
||
| "github.com/ava-labs/avalanche-cli/pkg/constants" | ||
| "github.com/ava-labs/avalanche-cli/pkg/dependencies" | ||
|
|
||
| "github.com/ava-labs/avalanche-cli/pkg/application" | ||
| "github.com/ava-labs/avalanche-cli/pkg/models" | ||
| "github.com/ava-labs/avalanche-cli/pkg/ux" | ||
|
|
@@ -43,6 +46,12 @@ func TrackSubnet( | |
| blockchainConfig []byte | ||
| subnetConfig []byte | ||
| ) | ||
| if sc.VM == models.SubnetEvm { | ||
| if err = dependencies.CheckVersionIsOverMin(app, constants.SubnetEVMRepoName, networkModel, sc.VMVersion); err != nil { | ||
| ux.Logger.PrintToUser(dependencies.UpdateSubnetEVMInstruction) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use printFunc |
||
| return err | ||
| } | ||
| } | ||
| vmBinaryPath, err := SetupVMBinary(app, blockchainName) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to setup VM binary: %w", 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
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 |
|---|---|---|
| @@ -1,26 +1,39 @@ | ||
| { | ||
| "subnet-evm": "v0.7.3", | ||
| "subnet-evm": { | ||
| "Local Network": { | ||
| "latest-version": "v0.7.3", | ||
| "minimum-version": "" | ||
| }, | ||
| "DevNet": { | ||
| "latest-version": "v0.7.3", | ||
| "minimum-version": "" | ||
| }, | ||
| "Fuji": { | ||
| "latest-version": "v0.7.3", | ||
| "minimum-version": "v0.7.2" | ||
| }, | ||
| "Mainnet": { | ||
| "latest-version": "v0.7.3", | ||
| "minimum-version": "v0.7.2" | ||
| } | ||
| }, | ||
| "rpc": 39, | ||
| "avalanchego": { | ||
| "Local Network": { | ||
| "latest-version": "v1.13.0", | ||
| "require-prerelease": false, | ||
| "prerelease-version": "" | ||
| "minimum-version": "" | ||
| }, | ||
| "DevNet": { | ||
| "latest-version": "v1.13.0", | ||
| "require-prerelease": false, | ||
| "prerelease-version": "" | ||
| "minimum-version": "" | ||
| }, | ||
| "Fuji": { | ||
| "latest-version": "v1.13.0", | ||
| "require-prerelease": false, | ||
| "prerelease-version": "" | ||
| "minimum-version": "v1.13.0-fuji" | ||
| }, | ||
| "Mainnet": { | ||
| "latest-version": "v1.13.0", | ||
| "require-prerelease": false, | ||
| "prerelease-version": "" | ||
| "minimum-version": "v1.13.0" | ||
| } | ||
| } | ||
| } |
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.