Skip to content

Commit

Permalink
fix merge conflicts and simplifying versioning things
Browse files Browse the repository at this point in the history
  • Loading branch information
bermuell committed Nov 7, 2024
1 parent 6d50c26 commit 12bd741
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 182 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/nightly-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
# Run compatibility tests for different consumer (-cv) and provider (-pv) versions.
# Combination of all provider versions with consumer versions are tested.
# For new versions to be tested add/modify -pc/-cv parameters.
run: go run ./tests/e2e/... --tc compatibility -pv latest -cv latest -cv v5.2.0 -cv v6.2.0
run: go run ./tests/e2e/... --tc compatibility -pv latest -cv latest -cv v5.2.0 -cv v6.3.0
happy-path-test:
runs-on: ubuntu-latest
timeout-minutes: 20
Expand Down
131 changes: 34 additions & 97 deletions tests/e2e/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"os"
"os/exec"
"regexp"
"sort"
"strconv"
"strings"
"sync"
Expand All @@ -29,9 +28,8 @@ const (
done = "done!!!!!!!!"

VLatest = "latest"
V400 = "v4.0.0"
V330 = "v3.3.0"
V300 = "v3.0.0"
V630 = "v6.3.0"
V620 = "v6.2.0"
)

// type aliases
Expand Down Expand Up @@ -999,121 +997,63 @@ func (tr *Chain) getConsumerGenesis(providerChain, consumerChain ChainID) string
time.Sleep(2 * time.Second)
}

if tr.testConfig.TransformGenesis || needsGenesisTransform(*tr.testConfig) {
return string(tr.transformConsumerGenesis(consumerChain, bz))
targetVersion := "v5.x" // default to v5.x in case transformation is required
needsTransform, targetVersion := needsGenesisTransform(*tr.testConfig)
if tr.testConfig.TransformGenesis || needsTransform {
return string(tr.transformConsumerGenesis(targetVersion, bz))
} else {
fmt.Println("No genesis transformation performed")
}
return string(bz)
}

// needsGenesisTransform tries to identify if a genesis transformation should be performed
func needsGenesisTransform(cfg TestConfig) bool {
func needsGenesisTransform(cfg TestConfig) (bool, string) {
// no genesis transformation needed for same versions
if cfg.ConsumerVersion == cfg.ProviderVersion {
return false
return false, ""
}

// use v4.0.0 (after genesis transform breakages) for the checks if 'latest' is used
// use v6.3.0 as reference for latest versions
consumerVersion := cfg.ConsumerVersion
if cfg.ConsumerVersion == VLatest {
consumerVersion = V400
consumerVersion = V630
}
providerVersion := cfg.ProviderVersion
if cfg.ProviderVersion == VLatest {
providerVersion = V400
providerVersion = V630
}

if !semver.IsValid(consumerVersion) || !semver.IsValid(providerVersion) {
fmt.Printf("unable to identify the need for genesis transformation: invalid sem-version: consumer='%s', provider='%s'",
consumerVersion, providerVersion)
return false
if !semver.IsValid(consumerVersion) {
fmt.Printf("unable to identify the need for genesis transformation: invalid sem-version: consumer='%s'\n",
consumerVersion)
return false, ""
}
if !semver.IsValid(providerVersion) {
fmt.Printf("unable to identify the need for genesis transformation: invalid sem-version: provider='%s'\n",
providerVersion)
return false, ""
}

breakages := []string{V300, V330, V400}
for _, breakage := range breakages {
if (semver.Compare(consumerVersion, breakage) < 0 && semver.Compare(providerVersion, breakage) >= 0) ||
(semver.Compare(providerVersion, breakage) < 0 && semver.Compare(consumerVersion, breakage) >= 0) {
fmt.Println("genesis transformation needed for versions:", providerVersion, consumerVersion)
return true
}
if semver.Compare(providerVersion, "v6.2") < 0 {
return false, ""
}
// genesis transformation needed for provider >= v6.2.0 and consumer < v4.5.0 or >= v5.0.0 and < v6.2.0
if semver.Compare(consumerVersion, "v4.5.0") < 0 {
return true, "v4.x"
}
fmt.Println("NO genesis transformation needed for versions:", providerVersion, consumerVersion)
return false
}

// getTransformParameter identifies the needed transformation parameter for current `transformGenesis` implementation
// based on consumer and provider versions.
func getTransformParameter(consumerVersion string) (string, error) {
switch consumerVersion {
case "":
// For "" (default: local workspace) use HEAD as reference point
consumerVersion = "HEAD"
case VLatest:
// For 'latest' originated from latest-image use "origin/main" as ref point
consumerVersion = "origin/main"
}

// Hash of breakage due to preHashKey release in version 2.x
// ics23/go v.0.10.0 adding 'prehash_key_before_comparison' in ProofSpec
breakage_prehash := "d4dde74b062c2fded0d3b3dbef4b3b0229e317f3" // first released in v3.2.0-consumer

// breakage 2: split of genesis
breakage_splitgenesisMain := "946f6ec626d3de3fe2e00cbb386ccf9c2f05d94d"
breakage_splitgenesisV33x := "1d2641a3b2ba706ae0a307d9019b48c62d86133b"

// breakage 3: split of genesis + delay_period
breakage_retry_delay := "88499b7c650ea0fb2c448af2b182ad5fee94d795"

// mapping of the accepted parameter values of the `genesis transform` command
// to the related git refs introducing a breakage
transformParams := map[string][]string{
"v2.x": {breakage_prehash},
"v3.3.x": {breakage_splitgenesisMain, breakage_splitgenesisV33x},
"v4.x": {breakage_retry_delay},
}

// set default consumer target version to "v4.x"
// and iterate in order of breakage history [oldest first] to identify
// the "--to" target for consumer version used
targetVersion := "v4.x"
keys := make([]string, 0, len(transformParams))
for k := range transformParams {
keys = append(keys, k)
}
sort.Slice(keys, func(k, l int) bool { return keys[k] < keys[l] })

for _, version := range keys {
for _, breakageHash := range transformParams[version] {
// Check if the 'breakage' is an ancestor of the 'consumerVersion'
//#nosec G204 -- Bypass linter warning for spawning subprocess with cmd arguments
cmd := exec.Command("git", "merge-base", "--is-ancestor", breakageHash, consumerVersion)
fmt.Println("running ", cmd)
out, err := cmd.CombinedOutput()
if err == nil {
// breakage is already part of the consumer version -> goto next breakage
fmt.Println(" consumer >= breakage ", transformParams[version], " ... going to next one")
targetVersion = version
break
}

if rc, ok := err.(*exec.ExitError); ok {
if rc.ExitCode() != 1 {
return "", fmt.Errorf("error identifying transform parameter '%v': %s", err, string(out))
}
// not an ancestor -- ignore this breakage
fmt.Println("breakage :", transformParams[version], " is not an ancestor of version ", version)
continue
}
return "", fmt.Errorf("unexpected error when running '%v': %v", cmd, err) // unable to get return code
}
if semver.Compare(consumerVersion, "v5.0.0") >= 0 && semver.Compare(consumerVersion, "v6.2.0") < 0 {
fmt.Println("genesis transformation needed for versions:", providerVersion, consumerVersion)
return true, "v5.x"
}
// consumer > latest known breakage (use default target version 'v4.x')
return fmt.Sprintf("--to=%s", targetVersion), nil

fmt.Println("NO genesis transformation needed for versions:", providerVersion, consumerVersion)
return false, ""
}

// Transform consumer genesis content from older version
func (tr *Chain) transformConsumerGenesis(consumerChain ChainID, genesis []byte) []byte {
func (tr *Chain) transformConsumerGenesis(targetVersion string, genesis []byte) []byte {
fmt.Println("Transforming consumer genesis")

fileName := "consumer_genesis.json"
Expand All @@ -1139,14 +1079,11 @@ func (tr *Chain) transformConsumerGenesis(consumerChain ChainID, genesis []byte)
}

// check if genesis transform supports --to target
targetVersion = fmt.Sprintf("--to=%s", targetVersion)
bz, err := tr.target.ExecCommand(
"interchain-security-transformer",
"genesis", "transform", "--to").CombinedOutput()
if err != nil && !strings.Contains(string(bz), "unknown flag: --to") {
targetVersion, err := getTransformParameter(tr.testConfig.ConsumerVersion)
if err != nil {
log.Panic("Failed getting genesis transformation parameter: ", err)
}
cmd = tr.target.ExecCommand(
"interchain-security-transformer",
"genesis", "transform", targetVersion, targetFile)
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ func createTestRunners(testCases []testStepsWithConfig) []TestRunner {
target, err := createTarget(cfg, targetCfg, *useImage)
tr := CreateTestRunner(cfg, tc.steps, &target, *verbose)
if err == nil {
fmt.Printf("Created test runner for '%s' with provider version=%s consumer version=%s",
fmt.Printf("Created test runner for '%s' with provider version=%s consumer version=%s\n",
cfg.Name, cfg.ProviderVersion, cfg.ConsumerVersion)
runners = append(runners, tr)
} else {
Expand Down
84 changes: 1 addition & 83 deletions tests/e2e/test_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,19 +124,7 @@ func (td *DefaultDriver) getChainDriver(chainID ChainID) e2e.ChainIF {
icsVersion := td.getIcsVersion(chainID)
switch icsVersion {
case "v3", "v4":
if td.verbose {
fmt.Println("Using 'v5' driver for chain ", chainID)
}
/* targetV4 := v4.Chain{
TestConfig: &td.testCfg,
}
targetV4.Target = v4.Commands{
ContainerConfig: td.testCfg.ContainerConfig,
ValidatorConfigs: td.testCfg.ValidatorConfigs,
ChainConfigs: td.testCfg.ChainConfigs,
Target: td.target,
}
return targetV4 */
panic(fmt.Sprintf("Version %s not supported anymore", icsVersion))
case "v5":
if td.verbose {
fmt.Println("Using 'v5' driver for chain ", chainID)
Expand Down Expand Up @@ -170,76 +158,6 @@ func (td *DefaultDriver) getChainDriver(chainID ChainID) e2e.ChainIF {
return target
}

/* func (td *DefaultDriver) getActionHandler(chainID ChainID, action interface{}) func() {
icsVersion := td.getIcsVersion(chainID)
var handler func()
target := td.getTargetDriver(chainID)
v4AH := v4.ActionHandler{}
defaultAH := ActionHandler{}
switch icsVersion {
case "v3", "v4", "v5":
if td.verbose {
fmt.Println("Using 'v4' action handler for chain ", chainID)
}
switch action := action.(type) {
case e2e.SubmitConsumerAdditionProposalAction:
f := v4AH.SubmitConsumerAdditionProposal
handler = func() { f(target, action, td.verbose) }
default:
panic(fmt.Sprintf("action %s not supported in version %s", action, icsVersion))
}
default:
switch action := action.(type) {
case e2e.SubmitConsumerAdditionProposalAction:
f := defaultAH.SubmitConsumerAdditionProposal
handler = func() { f(target, action, td.verbose) }
default:
panic(fmt.Sprintf("action %s not supported in version %s", action, icsVersion))
}
if td.verbose {
fmt.Println("Using default action handler for ", icsVersion, " for chain ", chainID)
}
}
return handler
} */

/* func (td *DefaultDriver) getTargetDriverNew(chainID ChainID) Chain {
target := Chain{
testConfig: &td.testCfg,
}
icsVersion := td.getIcsVersion(chainID)
switch icsVersion {
case "v3", "v4", "v5":
if td.verbose {
fmt.Println("Using 'v4' driver for chain ", chainID)
}
target.target = v4.Commands{
ContainerConfig: td.testCfg.containerConfig,
ValidatorConfigs: td.testCfg.validatorConfigs,
ChainConfigs: td.testCfg.chainConfigs,
Target: td.target,
}
default:
target.target = Commands{
ContainerConfig: &td.testCfg.containerConfig,
ValidatorConfigs: td.testCfg.validatorConfigs,
ChainConfigs: td.testCfg.chainConfigs,
Target: td.target,
}
if td.verbose {
fmt.Println("Using default driver for version", icsVersion, " for chain ", chainID)
}
}
return target
} */

func (td *DefaultDriver) getState(modelState State) State {
systemState := State{}
for chainID, modelState := range modelState {
Expand Down
1 change: 1 addition & 0 deletions tests/e2e/testlib/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type SubmitConsumerAdditionProposalAction struct {
Denylist []string
MinStake uint64
AllowInactiveVals bool
Prioritylist []string
}

type SubmitConsumerRemovalProposalAction struct {
Expand Down

0 comments on commit 12bd741

Please sign in to comment.