Skip to content

Commit

Permalink
Remove duplicate fork definitions (#3304)
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenButtolph authored Aug 16, 2024
1 parent ce78e7f commit 4b4ec8a
Show file tree
Hide file tree
Showing 37 changed files with 470 additions and 649 deletions.
70 changes: 70 additions & 0 deletions upgrade/upgradetest/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.

package upgradetest

import (
"time"

"github.com/ava-labs/avalanchego/upgrade"
)

// GetConfig returns an upgrade config with the provided fork scheduled to have
// been initially activated and all other forks to be unscheduled.
func GetConfig(fork Fork) upgrade.Config {
return GetConfigWithUpgradeTime(fork, upgrade.InitiallyActiveTime)
}

// GetConfigWithUpgradeTime returns an upgrade config with the provided fork
// scheduled to be activated at the provided upgradeTime and all other forks to
// be unscheduled.
func GetConfigWithUpgradeTime(fork Fork, upgradeTime time.Time) upgrade.Config {
c := upgrade.Config{}
// Initialize all forks to be unscheduled
SetTimesTo(&c, Latest, upgrade.UnscheduledActivationTime)
// Schedule the requested forks at the provided upgrade time
SetTimesTo(&c, fork, upgradeTime)
return c
}

// SetTimesTo sets the upgrade time of the provided fork, and all prior forks,
// to the provided upgradeTime.
func SetTimesTo(c *upgrade.Config, fork Fork, upgradeTime time.Time) {
switch fork {
case Etna:
c.EtnaTime = upgradeTime
fallthrough
case Durango:
c.DurangoTime = upgradeTime
fallthrough
case Cortina:
c.CortinaTime = upgradeTime
fallthrough
case Banff:
c.BanffTime = upgradeTime
fallthrough
case ApricotPhasePost6:
c.ApricotPhasePost6Time = upgradeTime
fallthrough
case ApricotPhase6:
c.ApricotPhase6Time = upgradeTime
fallthrough
case ApricotPhasePre6:
c.ApricotPhasePre6Time = upgradeTime
fallthrough
case ApricotPhase5:
c.ApricotPhase5Time = upgradeTime
fallthrough
case ApricotPhase4:
c.ApricotPhase4Time = upgradeTime
fallthrough
case ApricotPhase3:
c.ApricotPhase3Time = upgradeTime
fallthrough
case ApricotPhase2:
c.ApricotPhase2Time = upgradeTime
fallthrough
case ApricotPhase1:
c.ApricotPhase1Time = upgradeTime
}
}
25 changes: 25 additions & 0 deletions upgrade/upgradetest/fork.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.

package upgradetest

const (
NoUpgrades Fork = iota
ApricotPhase1
ApricotPhase2
ApricotPhase3
ApricotPhase4
ApricotPhase5
ApricotPhasePre6
ApricotPhase6
ApricotPhasePost6
Banff
Cortina
Durango
Etna

Latest = Etna
)

// Fork is an enum of all the major network upgrades.
type Fork int
6 changes: 2 additions & 4 deletions vms/avm/block/executor/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/ava-labs/avalanchego/chains/atomic"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/snow"
"github.com/ava-labs/avalanchego/upgrade"
"github.com/ava-labs/avalanchego/upgrade/upgradetest"
"github.com/ava-labs/avalanchego/utils"
"github.com/ava-labs/avalanchego/utils/logging"
"github.com/ava-labs/avalanchego/utils/set"
Expand Down Expand Up @@ -940,9 +940,7 @@ func defaultTestBackend(bootstrapped bool, sharedMemory atomic.SharedMemory) *ex
Log: logging.NoLog{},
},
Config: &config.Config{
Upgrades: upgrade.Config{
EtnaTime: mockable.MaxTime,
},
Upgrades: upgradetest.GetConfig(upgradetest.Durango),
TxFee: 0,
CreateAssetTxFee: 0,
},
Expand Down
39 changes: 7 additions & 32 deletions vms/avm/environment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"encoding/json"
"math/rand"
"testing"
"time"

"github.com/stretchr/testify/require"

Expand All @@ -21,14 +20,13 @@ import (
"github.com/ava-labs/avalanchego/snow/engine/common"
"github.com/ava-labs/avalanchego/snow/engine/enginetest"
"github.com/ava-labs/avalanchego/snow/snowtest"
"github.com/ava-labs/avalanchego/upgrade"
"github.com/ava-labs/avalanchego/upgrade/upgradetest"
"github.com/ava-labs/avalanchego/utils/constants"
"github.com/ava-labs/avalanchego/utils/crypto/secp256k1"
"github.com/ava-labs/avalanchego/utils/formatting"
"github.com/ava-labs/avalanchego/utils/formatting/address"
"github.com/ava-labs/avalanchego/utils/logging"
"github.com/ava-labs/avalanchego/utils/sampler"
"github.com/ava-labs/avalanchego/utils/timer/mockable"
"github.com/ava-labs/avalanchego/vms/avm/block/executor"
"github.com/ava-labs/avalanchego/vms/avm/config"
"github.com/ava-labs/avalanchego/vms/avm/fxs"
Expand All @@ -42,14 +40,7 @@ import (
keystoreutils "github.com/ava-labs/avalanchego/vms/components/keystore"
)

type fork uint8

const (
durango fork = iota
etna

latest = durango

testTxFee uint64 = 1000
startBalance uint64 = 50000

Expand Down Expand Up @@ -95,7 +86,7 @@ type user struct {
}

type envConfig struct {
fork fork
fork upgradetest.Fork
isCustomFeeAsset bool
keystoreUsers []*user
vmStaticConfig *config.Config
Expand Down Expand Up @@ -155,7 +146,11 @@ func setup(tb testing.TB, c *envConfig) *environment {
require.NoError(keystoreUser.Close())
}

vmStaticConfig := staticConfig(tb, c.fork)
vmStaticConfig := config.Config{
Upgrades: upgradetest.GetConfig(c.fork),
TxFee: testTxFee,
CreateAssetTxFee: testTxFee,
}
if c.vmStaticConfig != nil {
vmStaticConfig = *c.vmStaticConfig
}
Expand Down Expand Up @@ -230,26 +225,6 @@ func setup(tb testing.TB, c *envConfig) *environment {
return env
}

func staticConfig(tb testing.TB, f fork) config.Config {
c := config.Config{
Upgrades: upgrade.Config{
EtnaTime: mockable.MaxTime,
},
TxFee: testTxFee,
CreateAssetTxFee: testTxFee,
}

switch f {
case etna:
c.Upgrades.EtnaTime = time.Time{}
case durango:
default:
require.FailNow(tb, "unhandled fork", f)
}

return c
}

// Returns:
//
// 1. tx in genesis that creates asset
Expand Down
9 changes: 5 additions & 4 deletions vms/avm/index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/ava-labs/avalanchego/database/prefixdb"
"github.com/ava-labs/avalanchego/database/versiondb"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/upgrade/upgradetest"
"github.com/ava-labs/avalanchego/utils"
"github.com/ava-labs/avalanchego/utils/constants"
"github.com/ava-labs/avalanchego/utils/crypto/secp256k1"
Expand All @@ -27,7 +28,7 @@ import (
func TestIndexTransaction_Ordered(t *testing.T) {
require := require.New(t)

env := setup(t, &envConfig{fork: durango})
env := setup(t, &envConfig{fork: upgradetest.Durango})
defer env.vm.ctx.Lock.Unlock()

key := keys[0]
Expand Down Expand Up @@ -66,7 +67,7 @@ func TestIndexTransaction_Ordered(t *testing.T) {
func TestIndexTransaction_MultipleTransactions(t *testing.T) {
require := require.New(t)

env := setup(t, &envConfig{fork: durango})
env := setup(t, &envConfig{fork: upgradetest.Durango})
defer env.vm.ctx.Lock.Unlock()

addressTxMap := map[ids.ShortID]*txs.Tx{}
Expand Down Expand Up @@ -109,7 +110,7 @@ func TestIndexTransaction_MultipleTransactions(t *testing.T) {
func TestIndexTransaction_MultipleAddresses(t *testing.T) {
require := require.New(t)

env := setup(t, &envConfig{fork: durango})
env := setup(t, &envConfig{fork: upgradetest.Durango})
defer env.vm.ctx.Lock.Unlock()

addrs := make([]ids.ShortID, len(keys))
Expand Down Expand Up @@ -147,7 +148,7 @@ func TestIndexTransaction_MultipleAddresses(t *testing.T) {
func TestIndexer_Read(t *testing.T) {
require := require.New(t)

env := setup(t, &envConfig{fork: durango})
env := setup(t, &envConfig{fork: upgradetest.Durango})
defer env.vm.ctx.Lock.Unlock()

// generate test address and asset IDs
Expand Down
Loading

0 comments on commit 4b4ec8a

Please sign in to comment.