Skip to content
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/e2e/c/dynamic_fees.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/c/interchain_workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/p/staking_rewards.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/x/transfer/virtuous.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 7 additions & 7 deletions tests/fixture/e2e/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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...)
}

Expand Down
2 changes: 1 addition & 1 deletion tests/fixture/e2e/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ func StartLocalNetwork(avalancheGoExecPath string, networkDir string) *local.Loc
},
},
tmpnet.DefaultNodeCount,
tmpnet.DefaultFundedKeyCount,
tmpnet.DefaultPreFundedKeyCount,
)
require.NoError(err)
ginkgo.DeferCleanup(func() {
Expand Down
20 changes: 10 additions & 10 deletions tests/fixture/test_data_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var (
)

type TestData struct {
FundedKeys []*secp256k1.PrivateKey
PreFundedKeys []*secp256k1.PrivateKey
}

// http server allocating resources to tests potentially executing in parallel
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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
}
Expand All @@ -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 {
Expand All @@ -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
}
6 changes: 3 additions & 3 deletions tests/fixture/test_data_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -25,7 +25,7 @@ func TestAllocateFundedKeys(t *testing.T) {
}

uri, err := ServeTestData(TestData{
FundedKeys: keys,
PreFundedKeys: keys,
})
require.NoError(err)

Expand Down Expand Up @@ -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))
Expand Down
12 changes: 6 additions & 6 deletions tests/fixture/tmpnet/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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
}
Expand All @@ -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
Expand Down
28 changes: 14 additions & 14 deletions tests/fixture/tmpnet/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,21 @@ 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
)

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")
Expand Down Expand Up @@ -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.
Expand All @@ -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,
}
}

Expand Down
18 changes: 9 additions & 9 deletions tests/fixture/tmpnet/local/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion tests/fixture/tmpnet/local/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down