Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[antithesis] Enable custom plugin dir for subnet-evm #3305

Merged
merged 3 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tests/antithesis/avalanchego/gencomposeconfig/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const baseImageName = "antithesis-avalanchego"
// Creates docker-compose.yml and its associated volumes in the target path.
func main() {
network := tmpnet.LocalNetworkOrPanic()
if err := antithesis.GenerateComposeConfig(network, baseImageName); err != nil {
if err := antithesis.GenerateComposeConfig(network, baseImageName, "" /* runtimePluginDir */); err != nil {
log.Fatalf("failed to generate compose config: %v", err)
}
}
23 changes: 15 additions & 8 deletions tests/antithesis/compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ var (
errPluginDirEnvVarNotSet = errors.New("AVALANCHEGO_PLUGIN_DIR environment variable not set")
)

// Creates docker compose configuration for an antithesis test
// setup. Configuration is via env vars to simplify usage by main entrypoints. If
// the provided network includes a subnet, the initial DB state for the subnet
// will be created and written to the target path.
func GenerateComposeConfig(network *tmpnet.Network, baseImageName string) error {
// Creates docker compose configuration for an antithesis test setup. Configuration is via env vars to
// simplify usage by main entrypoints. If the provided network includes a subnet, the initial DB state for
// the subnet will be created and written to the target path. The runtimePluginDir should be set if the node
// image used for the test setup uses a path other than the default (~/.avalanchego/plugins).
func GenerateComposeConfig(network *tmpnet.Network, baseImageName string, runtimePluginDir string) error {
targetPath := os.Getenv("TARGET_PATH")
if len(targetPath) == 0 {
return errTargetPathEnvVarNotSet
Expand All @@ -51,6 +51,7 @@ func GenerateComposeConfig(network *tmpnet.Network, baseImageName string) error
return errAvalancheGoEvVarNotSet
}

// Plugin dir configured here is only used for initializing the bootstrap db.
pluginDir := os.Getenv(tmpnet.AvalancheGoPluginDirEnvName)
if len(pluginDir) == 0 {
return errPluginDirEnvVarNotSet
Expand All @@ -69,7 +70,7 @@ func GenerateComposeConfig(network *tmpnet.Network, baseImageName string) error
nodeImageName := fmt.Sprintf("%s-node:%s", baseImageName, imageTag)
workloadImageName := fmt.Sprintf("%s-workload:%s", baseImageName, imageTag)

if err := initComposeConfig(network, nodeImageName, workloadImageName, targetPath); err != nil {
if err := initComposeConfig(network, nodeImageName, workloadImageName, targetPath, runtimePluginDir); err != nil {
return fmt.Errorf("failed to generate compose config: %w", err)
}

Expand All @@ -83,9 +84,10 @@ func initComposeConfig(
nodeImageName string,
workloadImageName string,
targetPath string,
pluginDir string,
) error {
// Generate a compose project for the specified network
project, err := newComposeProject(network, nodeImageName, workloadImageName)
project, err := newComposeProject(network, nodeImageName, workloadImageName, pluginDir)
if err != nil {
return fmt.Errorf("failed to create compose project: %w", err)
}
Expand Down Expand Up @@ -123,7 +125,7 @@ func initComposeConfig(

// Create a new docker compose project for an antithesis test setup
// for the provided network configuration.
func newComposeProject(network *tmpnet.Network, nodeImageName string, workloadImageName string) (*types.Project, error) {
func newComposeProject(network *tmpnet.Network, nodeImageName string, workloadImageName string, pluginDir string) (*types.Project, error) {
networkName := "avalanche-testnet"
baseNetworkAddress := "10.0.20"

Expand Down Expand Up @@ -160,6 +162,11 @@ func newComposeProject(network *tmpnet.Network, nodeImageName string, workloadIm
config.StakingSignerKeyContentKey: signerKey,
}

// Set a non-default plugin dir if provided
if len(pluginDir) > 0 {
env[config.PluginDirKey] = pluginDir
}

// Apply configuration appropriate to a test network
for k, v := range tmpnet.DefaultTestFlags() {
switch value := v.(type) {
Expand Down
2 changes: 1 addition & 1 deletion tests/antithesis/xsvm/gencomposeconfig/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func main() {
network.Subnets = []*tmpnet.Subnet{
subnet.NewXSVMOrPanic("xsvm", genesis.VMRQKey, network.Nodes...),
}
if err := antithesis.GenerateComposeConfig(network, baseImageName); err != nil {
if err := antithesis.GenerateComposeConfig(network, baseImageName, "" /* runtimePluginDir */); err != nil {
log.Fatalf("failed to generate compose config: %v", err)
}
}
Loading