diff --git a/tests/e2e/c/dynamic_fees.go b/tests/e2e/c/dynamic_fees.go index 38bbd668079b..6d106dc77fed 100644 --- a/tests/e2e/c/dynamic_fees.go +++ b/tests/e2e/c/dynamic_fees.go @@ -42,7 +42,7 @@ var _ = e2e.DescribeCChain("[Dynamic Fees]", func() { privateNetwork := e2e.Env.NewPrivateNetwork() ginkgo.By("allocating a pre-funded key") - key := privateNetwork.GetConfig().FundedKeys[0] + key := privateNetwork.GetConfig().PreFundedKeys[0] ethAddress := evm.GetEthAddress(key) ginkgo.By("initializing a coreth client") diff --git a/tests/e2e/c/interchain_workflow.go b/tests/e2e/c/interchain_workflow.go index 2c9bd198ec39..e959418e878a 100644 --- a/tests/e2e/c/interchain_workflow.go +++ b/tests/e2e/c/interchain_workflow.go @@ -37,7 +37,7 @@ var _ = e2e.DescribeCChain("[Interchain Workflow]", func() { ethClient := e2e.NewEthClient(nodeURI) ginkgo.By("allocating a pre-funded key to send from and a recipient key to deliver to") - senderKey := e2e.Env.AllocateFundedKey() + senderKey := e2e.Env.AllocatePreFundedKey() senderEthAddress := evm.GetEthAddress(senderKey) recipientKey, err := secp256k1.NewPrivateKey() require.NoError(err) diff --git a/tests/e2e/p/staking_rewards.go b/tests/e2e/p/staking_rewards.go index f05b3bfbf64a..f5521ef5e870 100644 --- a/tests/e2e/p/staking_rewards.go +++ b/tests/e2e/p/staking_rewards.go @@ -87,7 +87,7 @@ var _ = ginkgo.Describe("[Staking Rewards]", func() { ginkgo.By("creating keychain and P-Chain wallet") keychain := secp256k1fx.NewKeychain(rewardKeys...) - fundedKey := e2e.Env.AllocateFundedKey() + fundedKey := e2e.Env.AllocatePreFundedKey() keychain.Add(fundedKey) nodeURI := e2e.Env.GetRandomNodeURI() baseWallet := e2e.NewWallet(keychain, nodeURI) diff --git a/tests/e2e/x/transfer/virtuous.go b/tests/e2e/x/transfer/virtuous.go index 7a1eb1bb6b91..b409f7e5e555 100644 --- a/tests/e2e/x/transfer/virtuous.go +++ b/tests/e2e/x/transfer/virtuous.go @@ -69,7 +69,7 @@ var _ = e2e.DescribeXChainSerial("[Virtuous Transfer Tx AVAX]", func() { // Ensure the same set of 10 keys is used for all tests // by retrieving them outside of runFunc. - testKeys := e2e.Env.AllocateFundedKeys(10) + testKeys := e2e.Env.AllocatePreFundedKeys(10) runFunc := func(round int) { tests.Outf("{{green}}\n\n\n\n\n\n---\n[ROUND #%02d]:{{/}}\n", round) diff --git a/tests/fixture/e2e/env.go b/tests/fixture/e2e/env.go index 07c24866a9f0..3cd77ecb5c4c 100644 --- a/tests/fixture/e2e/env.go +++ b/tests/fixture/e2e/env.go @@ -75,7 +75,7 @@ func NewTestEnvironment(flagVars *FlagVars) *TestEnvironment { tests.Outf("{{green}}network URIs: {{/}} %+v\n", uris) testDataServerURI, err := fixture.ServeTestData(fixture.TestData{ - FundedKeys: network.FundedKeys, + PreFundedKeys: network.PreFundedKeys, }) tests.Outf("{{green}}test data server URI: {{/}} %+v\n", testDataServerURI) require.NoError(err) @@ -104,21 +104,21 @@ func (te *TestEnvironment) GetNetwork() tmpnet.Network { } // Retrieve the specified number of funded keys allocated for the caller's exclusive use. -func (te *TestEnvironment) AllocateFundedKeys(count int) []*secp256k1.PrivateKey { - keys, err := fixture.AllocateFundedKeys(te.TestDataServerURI, count) +func (te *TestEnvironment) AllocatePreFundedKeys(count int) []*secp256k1.PrivateKey { + keys, err := fixture.AllocatePreFundedKeys(te.TestDataServerURI, count) te.require.NoError(err) - tests.Outf("{{blue}} allocated funded key(s): %+v{{/}}\n", keys) + tests.Outf("{{blue}} allocated pre-funded key(s): %+v{{/}}\n", keys) return keys } // Retrieve a funded key allocated for the caller's exclusive use. -func (te *TestEnvironment) AllocateFundedKey() *secp256k1.PrivateKey { - return te.AllocateFundedKeys(1)[0] +func (te *TestEnvironment) AllocatePreFundedKey() *secp256k1.PrivateKey { + return te.AllocatePreFundedKeys(1)[0] } // Create a new keychain with the specified number of test keys. func (te *TestEnvironment) NewKeychain(count int) *secp256k1fx.Keychain { - keys := te.AllocateFundedKeys(count) + keys := te.AllocatePreFundedKeys(count) return secp256k1fx.NewKeychain(keys...) } diff --git a/tests/fixture/e2e/helpers.go b/tests/fixture/e2e/helpers.go index 8b7eb5260b8c..c5776e546389 100644 --- a/tests/fixture/e2e/helpers.go +++ b/tests/fixture/e2e/helpers.go @@ -235,7 +235,7 @@ func StartLocalNetwork(avalancheGoExecPath string, networkDir string) *local.Loc }, }, tmpnet.DefaultNodeCount, - tmpnet.DefaultFundedKeyCount, + tmpnet.DefaultPreFundedKeyCount, ) require.NoError(err) ginkgo.DeferCleanup(func() { diff --git a/tests/fixture/test_data_server.go b/tests/fixture/test_data_server.go index 5a39baab8c9c..77e79b278b13 100644 --- a/tests/fixture/test_data_server.go +++ b/tests/fixture/test_data_server.go @@ -33,7 +33,7 @@ var ( ) type TestData struct { - FundedKeys []*secp256k1.PrivateKey + PreFundedKeys []*secp256k1.PrivateKey } // http server allocating resources to tests potentially executing in parallel @@ -68,14 +68,14 @@ func (s *testDataServer) allocateKeys(w http.ResponseWriter, r *http.Request) { defer s.lock.Unlock() // Only fulfill requests for available keys - if keyCount > len(s.FundedKeys) { + if keyCount > len(s.PreFundedKeys) { http.Error(w, requestedKeyCountExceedsAvailable, http.StatusInternalServerError) return } // Allocate the requested number of keys - remainingKeys := len(s.FundedKeys) - keyCount - allocatedKeys := s.FundedKeys[remainingKeys:] + remainingKeys := len(s.PreFundedKeys) - keyCount + allocatedKeys := s.PreFundedKeys[remainingKeys:] keysDoc := &keysDocument{ Keys: allocatedKeys, @@ -88,7 +88,7 @@ func (s *testDataServer) allocateKeys(w http.ResponseWriter, r *http.Request) { // Forget the allocated keys utils.ZeroSlice(allocatedKeys) - s.FundedKeys = s.FundedKeys[:remainingKeys] + s.PreFundedKeys = s.PreFundedKeys[:remainingKeys] } // Serve test data via http to ensure allocation is synchronized even when @@ -122,9 +122,9 @@ func ServeTestData(testData TestData) (string, error) { return address, nil } -// Retrieve the specified number of funded test keys from the provided URI. A given +// Retrieve the specified number of pre-funded test keys from the provided URI. A given // key is allocated at most once during the life of the test data server. -func AllocateFundedKeys(baseURI string, count int) ([]*secp256k1.PrivateKey, error) { +func AllocatePreFundedKeys(baseURI string, count int) ([]*secp256k1.PrivateKey, error) { if count <= 0 { return nil, errInvalidKeyCount } @@ -144,13 +144,13 @@ func AllocateFundedKeys(baseURI string, count int) ([]*secp256k1.PrivateKey, err resp, err := http.DefaultClient.Do(req) if err != nil { - return nil, fmt.Errorf("failed to request funded keys: %w", err) + return nil, fmt.Errorf("failed to request pre-funded keys: %w", err) } defer resp.Body.Close() body, err := io.ReadAll(resp.Body) if err != nil { - return nil, fmt.Errorf("failed to read response for funded keys: %w", err) + return nil, fmt.Errorf("failed to read response for pre-funded keys: %w", err) } if resp.StatusCode != http.StatusOK { if strings.TrimSpace(string(body)) == requestedKeyCountExceedsAvailable { @@ -161,7 +161,7 @@ func AllocateFundedKeys(baseURI string, count int) ([]*secp256k1.PrivateKey, err keysDoc := &keysDocument{} if err := json.Unmarshal(body, keysDoc); err != nil { - return nil, fmt.Errorf("failed to unmarshal funded keys: %w", err) + return nil, fmt.Errorf("failed to unmarshal pre-funded keys: %w", err) } return keysDoc.Keys, nil } diff --git a/tests/fixture/test_data_server_test.go b/tests/fixture/test_data_server_test.go index 979c927fea7f..7f68a6935da3 100644 --- a/tests/fixture/test_data_server_test.go +++ b/tests/fixture/test_data_server_test.go @@ -14,7 +14,7 @@ import ( // Check that funded test keys can be served from an http server to // ensure at-most-once allocation when tests are executed in parallel. -func TestAllocateFundedKeys(t *testing.T) { +func TestAllocatePreFundedKeys(t *testing.T) { require := require.New(t) keys := make([]*secp256k1.PrivateKey, 5) @@ -25,7 +25,7 @@ func TestAllocateFundedKeys(t *testing.T) { } uri, err := ServeTestData(TestData{ - FundedKeys: keys, + PreFundedKeys: keys, }) require.NoError(err) @@ -63,7 +63,7 @@ func TestAllocateFundedKeys(t *testing.T) { } for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { - keys, err := AllocateFundedKeys(uri, tc.count) + keys, err := AllocatePreFundedKeys(uri, tc.count) require.ErrorIs(err, tc.expectedError) addresses := make([]ids.ShortID, len(keys)) diff --git a/tests/fixture/tmpnet/cmd/main.go b/tests/fixture/tmpnet/cmd/main.go index a9f5c1865291..e58bb7213b36 100644 --- a/tests/fixture/tmpnet/cmd/main.go +++ b/tests/fixture/tmpnet/cmd/main.go @@ -46,10 +46,10 @@ func main() { rootCmd.AddCommand(versionCmd) var ( - rootDir string - execPath string - nodeCount uint8 - fundedKeyCount uint8 + rootDir string + execPath string + nodeCount uint8 + preFundedKeyCount uint8 ) startNetworkCmd := &cobra.Command{ Use: "start-network", @@ -68,7 +68,7 @@ func main() { } ctx, cancel := context.WithTimeout(context.Background(), local.DefaultNetworkStartTimeout) defer cancel() - network, err := local.StartNetwork(ctx, os.Stdout, rootDir, network, int(nodeCount), int(fundedKeyCount)) + network, err := local.StartNetwork(ctx, os.Stdout, rootDir, network, int(nodeCount), int(preFundedKeyCount)) if err != nil { return err } @@ -95,7 +95,7 @@ func main() { startNetworkCmd.PersistentFlags().StringVar(&rootDir, "root-dir", os.Getenv(local.RootDirEnvName), "The path to the root directory for local networks") startNetworkCmd.PersistentFlags().StringVar(&execPath, "avalanchego-path", os.Getenv(local.AvalancheGoPathEnvName), "The path to an avalanchego binary") startNetworkCmd.PersistentFlags().Uint8Var(&nodeCount, "node-count", tmpnet.DefaultNodeCount, "Number of nodes the network should initially consist of") - startNetworkCmd.PersistentFlags().Uint8Var(&fundedKeyCount, "funded-key-count", tmpnet.DefaultFundedKeyCount, "Number of funded keys the network should start with") + startNetworkCmd.PersistentFlags().Uint8Var(&preFundedKeyCount, "pre-funded-key-count", tmpnet.DefaultPreFundedKeyCount, "Number of pre-funded keys the network should start with") rootCmd.AddCommand(startNetworkCmd) var networkDir string diff --git a/tests/fixture/tmpnet/config.go b/tests/fixture/tmpnet/config.go index a86b2f26c51a..03a8487f67cc 100644 --- a/tests/fixture/tmpnet/config.go +++ b/tests/fixture/tmpnet/config.go @@ -33,13 +33,13 @@ import ( ) const ( - DefaultNodeCount = 2 // Minimum required to ensure connectivity-based health checks will pass - DefaultFundedKeyCount = 50 + DefaultNodeCount = 2 // Minimum required to ensure connectivity-based health checks will pass + DefaultPreFundedKeyCount = 50 DefaultGasLimit = uint64(100_000_000) // Gas limit is arbitrary // Arbitrarily large amount of AVAX to fund keys on the X-Chain for testing - DefaultFundedKeyXChainAmount = 30 * units.MegaAvax + DefaultPreFundedKeyXChainAmount = 30 * units.MegaAvax // A short min stake duration enables testing of staking logic. DefaultMinStakeDuration = time.Second @@ -47,7 +47,7 @@ const ( var ( // Arbitrarily large amount of AVAX (10^12) to fund keys on the C-Chain for testing - DefaultFundedKeyCChainAmount = new(big.Int).Exp(big.NewInt(10), big.NewInt(30), nil) + DefaultPreFundedKeyCChainAmount = new(big.Int).Exp(big.NewInt(10), big.NewInt(30), nil) errNoKeysForGenesis = errors.New("failed to generate genesis: no keys to fund") errInvalidNetworkIDForGenesis = errors.New("network ID can't be mainnet, testnet or local network ID") @@ -121,10 +121,10 @@ func DefaultJSONMarshal(v interface{}) ([]byte, error) { // NetworkConfig defines configuration shared or // common to all nodes in a given network. type NetworkConfig struct { - Genesis *genesis.UnparsedConfig - CChainConfig FlagsMap - DefaultFlags FlagsMap - FundedKeys []*secp256k1.PrivateKey + Genesis *genesis.UnparsedConfig + CChainConfig FlagsMap + DefaultFlags FlagsMap + PreFundedKeys []*secp256k1.PrivateKey } // Ensure genesis is generated if not already present. @@ -133,17 +133,17 @@ func (c *NetworkConfig) EnsureGenesis(networkID uint32, initialStakers []genesis return nil } - if len(c.FundedKeys) == 0 { + if len(c.PreFundedKeys) == 0 { return errNoKeysForGenesis } // Ensure pre-funded keys have arbitrary large balances on both chains to support testing - xChainBalances := make(XChainBalanceMap, len(c.FundedKeys)) - cChainBalances := make(core.GenesisAlloc, len(c.FundedKeys)) - for _, key := range c.FundedKeys { - xChainBalances[key.Address()] = DefaultFundedKeyXChainAmount + xChainBalances := make(XChainBalanceMap, len(c.PreFundedKeys)) + cChainBalances := make(core.GenesisAlloc, len(c.PreFundedKeys)) + for _, key := range c.PreFundedKeys { + xChainBalances[key.Address()] = DefaultPreFundedKeyXChainAmount cChainBalances[evm.GetEthAddress(key)] = core.GenesisAccount{ - Balance: DefaultFundedKeyCChainAmount, + Balance: DefaultPreFundedKeyCChainAmount, } } diff --git a/tests/fixture/tmpnet/local/network.go b/tests/fixture/tmpnet/local/network.go index ea55f5f5968c..4d0fd4ed8a4d 100644 --- a/tests/fixture/tmpnet/local/network.go +++ b/tests/fixture/tmpnet/local/network.go @@ -226,7 +226,7 @@ func (ln *LocalNetwork) PopulateLocalNetworkConfig(networkID uint32, nodeCount i if len(ln.Nodes) > 0 && nodeCount > 0 { return errInvalidNodeCount } - if len(ln.FundedKeys) > 0 && keyCount > 0 { + if len(ln.PreFundedKeys) > 0 && keyCount > 0 { return errInvalidKeyCount } @@ -264,7 +264,7 @@ func (ln *LocalNetwork) PopulateLocalNetworkConfig(networkID uint32, nodeCount i } keys = append(keys, key) } - ln.FundedKeys = keys + ln.PreFundedKeys = keys } if err := ln.EnsureGenesis(networkID, initialStakers); err != nil { @@ -498,9 +498,9 @@ func (ln *LocalNetwork) WriteCChainConfig() error { // Used to marshal/unmarshal persistent local network defaults. type localDefaults struct { - Flags tmpnet.FlagsMap - ExecPath string - FundedKeys []*secp256k1.PrivateKey + Flags tmpnet.FlagsMap + ExecPath string + PreFundedKeys []*secp256k1.PrivateKey } func (ln *LocalNetwork) GetDefaultsPath() string { @@ -518,15 +518,15 @@ func (ln *LocalNetwork) ReadDefaults() error { } ln.DefaultFlags = defaults.Flags ln.ExecPath = defaults.ExecPath - ln.FundedKeys = defaults.FundedKeys + ln.PreFundedKeys = defaults.PreFundedKeys return nil } func (ln *LocalNetwork) WriteDefaults() error { defaults := localDefaults{ - Flags: ln.DefaultFlags, - ExecPath: ln.ExecPath, - FundedKeys: ln.FundedKeys, + Flags: ln.DefaultFlags, + ExecPath: ln.ExecPath, + PreFundedKeys: ln.PreFundedKeys, } bytes, err := tmpnet.DefaultJSONMarshal(defaults) if err != nil { diff --git a/tests/fixture/tmpnet/local/network_test.go b/tests/fixture/tmpnet/local/network_test.go index 8f7e66d37d5b..3893c9e51db4 100644 --- a/tests/fixture/tmpnet/local/network_test.go +++ b/tests/fixture/tmpnet/local/network_test.go @@ -20,7 +20,7 @@ func TestNetworkSerialization(t *testing.T) { loadedNetwork, err := ReadNetwork(tmpDir) require.NoError(err) - for _, key := range loadedNetwork.FundedKeys { + for _, key := range loadedNetwork.PreFundedKeys { // Address() enables comparison with the original network by // ensuring full population of a key's in-memory representation. _ = key.Address()