Skip to content

Commit

Permalink
extend TestConsensusUpgrades to ensure official version names
Browse files Browse the repository at this point in the history
  • Loading branch information
cce committed Aug 23, 2022
1 parent 2aaebfb commit 2eb6419
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"os"
"path/filepath"
"reflect"
"strings"
"testing"

"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -345,11 +346,24 @@ func TestConsensusUpgrades(t *testing.T) {
currentVersionName := protocol.ConsensusV7
latestVersionName := protocol.ConsensusCurrentVersion

leadsTo := consensusUpgradesTo(a, currentVersionName, latestVersionName)
leadsTo := consensusUpgradesTo(a, currentVersionName, latestVersionName, checkConsensusVersionName)
a.True(leadsTo, "Consensus protocol must have upgrade path from %v to %v", currentVersionName, latestVersionName)
}

func consensusUpgradesTo(a *require.Assertions, currentName, targetName protocol.ConsensusVersion) bool {
func checkConsensusVersionName(a *require.Assertions, name string) {
// ensure versions come from official specs repo
prefix1 := "https://github.com/algorandfoundation/specs/tree/"
prefix2 := "https://github.com/algorand/spec/tree/"

whitelist := map[string]bool{"v7": true, "v8": true, "v9": true, "v10": true, "v11": true, "v12": true}
if !whitelist[name] {
a.True(strings.HasPrefix(name, prefix1) || strings.HasPrefix(name, prefix2),
"Consensus version %s does not start with allowed prefix", name)
}
}

func consensusUpgradesTo(a *require.Assertions, currentName, targetName protocol.ConsensusVersion, nameCheckFn func(*require.Assertions, string)) bool {
nameCheckFn(a, string(currentName))
if currentName == targetName {
return true
}
Expand All @@ -359,7 +373,7 @@ func consensusUpgradesTo(a *require.Assertions, currentName, targetName protocol
if upgrade == targetName {
return true
}
return consensusUpgradesTo(a, upgrade, targetName)
return consensusUpgradesTo(a, upgrade, targetName, nameCheckFn)
}
return false
}
Expand Down

0 comments on commit 2eb6419

Please sign in to comment.