Skip to content

Commit

Permalink
solana-test-validator should only use enabled features on mainnet
Browse files Browse the repository at this point in the history
  • Loading branch information
aalu1418 committed Feb 14, 2024
1 parent e32c91f commit edda136
Showing 1 changed file with 48 additions and 1 deletion.
49 changes: 48 additions & 1 deletion integration-tests/docker/test_env/sol.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ package test_env

import (
"context"
"encoding/json"
"fmt"
"os"
"os/exec"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -136,6 +139,11 @@ func (ms *Solana) getContainerRequest() (*tc.ContainerRequest, error) {
return nil, err
}

inactiveFeatures, err := GetInactiveFeatureHashes()
if err != nil {
return nil, err
}

return &tc.ContainerRequest{
Name: ms.ContainerName,
Image: "solanalabs/solana:v1.17.22",
Expand Down Expand Up @@ -169,6 +177,45 @@ func (ms *Solana) getContainerRequest() (*tc.ContainerRequest, error) {
},
},
},
Entrypoint: []string{"sh", "-c", "mkdir -p /root/.config/solana/cli && solana-test-validator -r --mint AAxAoGfkbWnbgsiQeAanwUvjv6bQrM5JS8Vxv1ckzVxg"},
Entrypoint: []string{"sh", "-c", "mkdir -p /root/.config/solana/cli && solana-test-validator -r --mint AAxAoGfkbWnbgsiQeAanwUvjv6bQrM5JS8Vxv1ckzVxg " + inactiveFeatures.String()},
}, nil
}

type FeatureStatuses struct {
Features []FeatureStatus
// note: there are other unused params in the json response
}

type FeatureStatus struct {
ID string
Description string
Status string
SinceSlot int
}

type InactiveFeatures []string

func (f InactiveFeatures) String() string {
return "--deactivate-feature " + strings.Join(f, " --deactivate-feature ")
}

func GetInactiveFeatureHashes() (output InactiveFeatures, err error) {
cmd := exec.Command("solana", "feature", "status", "-um", "--output=json") // -um is for mainnet url
stdout, err := cmd.Output()
if err != nil {
return nil, fmt.Errorf("Failed to get feature status: %w", err)
}

statuses := FeatureStatuses{}
if err = json.Unmarshal(stdout, &statuses); err != nil {
return nil, fmt.Errorf("Failed to unmarshal feature status: %w", err)
}

for _, f := range statuses.Features {
if f.Status == "inactive" {
output = append(output, f.ID)
}
}

return output, err
}

0 comments on commit edda136

Please sign in to comment.