Skip to content

Commit

Permalink
fix(cli): doctor check fxcored upgrade version (#512)
Browse files Browse the repository at this point in the history
  • Loading branch information
zakir-code committed May 24, 2024
1 parent 29e258f commit 7aeb895
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 5 deletions.
18 changes: 13 additions & 5 deletions cmd/doctor.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func doctorCmd() *cobra.Command {
if err != nil {
return err
}
if err := checkUpgradeInfo(serverCtx.Config.RootDir); err != nil {
if err = checkUpgradeInfo(serverCtx.Config.RootDir); err != nil {
return err
}
bc, err := getBlockchain(clientCtx, serverCtx)
Expand Down Expand Up @@ -418,13 +418,14 @@ func checkCosmovisor(rootPath string, bc blockchain) error {
fmt.Printf("%s%s%sWarning: %s\n", SPACE, SPACE, SPACE, err.Error())
continue
}
v := string(bytes.Trim(output, "\n"))
fmt.Printf("%s%s%sfxcored version: %s\n", SPACE, SPACE, SPACE, v)
if !(strings.HasPrefix(v, "release/v"+entry.Name()[len(entry.Name())-1:]) || strings.HasPrefix(v, "release/"+entry.Name())) {
outputVersion := string(bytes.Trim(output, "\n"))
fmt.Printf("%s%s%sfxcored version: %s\n", SPACE, SPACE, SPACE, outputVersion)

if checkVersionCompatibility(entry.Name(), outputVersion) {
fmt.Printf("%s%s%sWarning: fxcored version is not match upgrade plan\n", SPACE, SPACE, SPACE)
}
upgradeInfoFile := filepath.Join(upgradesPath, entry.Name(), upgradetypes.UpgradeInfoFilename)

upgradeInfoFile := filepath.Join(upgradesPath, entry.Name(), upgradetypes.UpgradeInfoFilename)
upgradeInfo, err := os.ReadFile(upgradeInfoFile)
if err != nil {
if !os.IsNotExist(err) {
Expand All @@ -449,6 +450,13 @@ func checkCosmovisor(rootPath string, bc blockchain) error {
return nil
}

func checkVersionCompatibility(version, outputVersion string) bool {
semVer := strings.Split(version, ".")
isFxV := len(semVer) == 1 && strings.HasPrefix(semVer[0], "fx") && strings.Contains(outputVersion, semVer[0][2:])
isSemVer := len(semVer) > 1 && strings.Contains(outputVersion, semVer[0]+"."+semVer[1])
return !isFxV && !isSemVer
}

func printDirectory(path string, depth int, last []bool, tab string) error {
printPath := path
if depth > 0 {
Expand Down
34 changes: 34 additions & 0 deletions cmd/doctor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,37 @@ func Test_checkGenesis(t *testing.T) {
})
}
}

func Test_checkVersionCompatibility(t *testing.T) {
type args struct {
version string
outputVersion string
}
tests := []struct {
name string
args args
want bool
}{
{
name: "v1",
args: args{
version: "fxv1",
outputVersion: "release/v1.0.1",
},
want: false,
},
{
name: "v5",
args: args{
version: "v5.0.x",
outputVersion: "release/v5.0.1",
},
want: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equalf(t, tt.want, checkVersionCompatibility(tt.args.version, tt.args.outputVersion), "checkVersionCompatibility(%v, %v)", tt.args.version, tt.args.outputVersion)
})
}
}

0 comments on commit 7aeb895

Please sign in to comment.