From 2eb6419ce266981b4254412d19888d664da3f90e Mon Sep 17 00:00:00 2001 From: chris erway Date: Tue, 23 Aug 2022 16:56:33 -0400 Subject: [PATCH] extend TestConsensusUpgrades to ensure official version names --- config/config_test.go | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/config/config_test.go b/config/config_test.go index c11edd3797..a586c98ab8 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -24,6 +24,7 @@ import ( "os" "path/filepath" "reflect" + "strings" "testing" "github.com/stretchr/testify/require" @@ -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 } @@ -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 }