Skip to content

Commit

Permalink
tmpnet: Add support for subnets
Browse files Browse the repository at this point in the history
  • Loading branch information
maru-ava committed Dec 22, 2023
1 parent 74fdef2 commit ef0af9c
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions tests/fixture/tmpnet/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const (
HardHatKeyStr = "56289e99c94b6912bfc12adc093c9b51124f0dc54ac7a766b2bc5ccf558d8027"
)

// Legacy key used for hardhat testing in subnet-evm
// HardhatKey is a legacy used for hardhat testing in subnet-evm
// TODO(marun) Remove when no longer needed.
var HardhatKey *secp256k1.PrivateKey

Expand Down Expand Up @@ -157,10 +157,12 @@ func (n *Network) EnsureDefaultConfig(w io.Writer, avalancheGoPath string, plugi
n.DefaultFlags.SetDefaults(DefaultFlags())

// Only configure the plugin dir with a non-empty value to ensure
// the use of the default value (`$HOME/.avalanchego/plugins`) when
// the use of the default value (`[datadir]/plugins`) when
// no plugin dir is configured.
if len(pluginDir) > 0 {
n.DefaultFlags[config.PluginDirKey] = pluginDir
if _, ok := n.DefaultFlags[config.PluginDirKey]; !ok {
n.DefaultFlags[config.PluginDirKey] = pluginDir
}
}

// Ensure pre-funded keys
Expand Down Expand Up @@ -253,17 +255,29 @@ func (n *Network) Create(rootDir string) error {
}
n.Dir = canonicalDir

pluginDir, err := n.DefaultFlags.GetStringVal(config.PluginDirKey)
if err != nil {
return err
}
if len(pluginDir) > 0 {
// Ensure the existence of the plugin directory or nodes won't be able to start.
if err := os.MkdirAll(pluginDir, perms.ReadWriteExecute); err != nil {
return fmt.Errorf("failed to create plugin dir: %w", err)
}
}

if n.Genesis == nil {
// Pre-fund known legacy keys to support ad-hoc testing. Usage of a legacy key will
// require knowing the key beforehand rather than retrieving it from the set of pre-funded
// keys exposed by a network. Since allocation will not be exclusive, a test using a
// legacy key is unlikely to be a good candidate for parallel execution.
keysToFund := append(
n.PreFundedKeys,
keysToFund := []*secp256k1.PrivateKey{
genesis.VMRQKey,
genesis.EWOQKey,
HardhatKey,
)
}
keysToFund = append(keysToFund, n.PreFundedKeys...)

genesis, err := NewTestGenesis(networkID, n.Nodes, keysToFund)
if err != nil {
return err
Expand Down

0 comments on commit ef0af9c

Please sign in to comment.