diff --git a/graft/coreth/core/genesis_extra_test.go b/graft/coreth/core/genesis_extra_test.go index 8e84a409e02f..a5879edcce18 100644 --- a/graft/coreth/core/genesis_extra_test.go +++ b/graft/coreth/core/genesis_extra_test.go @@ -35,8 +35,8 @@ import ( "github.com/ava-labs/avalanchego/graft/coreth/params" "github.com/ava-labs/avalanchego/graft/coreth/params/extras" "github.com/ava-labs/avalanchego/graft/coreth/params/paramstest" - "github.com/ava-labs/avalanchego/graft/evm/utils" "github.com/ava-labs/avalanchego/upgrade/upgradetest" + "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/libevm/common" "github.com/ava-labs/libevm/core/rawdb" "github.com/ava-labs/libevm/core/types" @@ -68,8 +68,8 @@ func TestGenesisEthUpgrades(t *testing.T) { }, &extras.ChainConfig{ NetworkUpgrades: extras.NetworkUpgrades{ - ApricotPhase1BlockTimestamp: utils.NewUint64(0), - ApricotPhase2BlockTimestamp: utils.NewUint64(0), + ApricotPhase1BlockTimestamp: utils.PointerTo[uint64](0), + ApricotPhase2BlockTimestamp: utils.PointerTo[uint64](0), }, }, ) diff --git a/graft/coreth/core/genesis_test.go b/graft/coreth/core/genesis_test.go index 5a8f37fdd4d0..5ec58dfd9be2 100644 --- a/graft/coreth/core/genesis_test.go +++ b/graft/coreth/core/genesis_test.go @@ -42,7 +42,7 @@ import ( "github.com/ava-labs/avalanchego/graft/coreth/precompile/contracts/warp" "github.com/ava-labs/avalanchego/graft/coreth/triedb/pathdb" "github.com/ava-labs/avalanchego/graft/evm/firewood" - "github.com/ava-labs/avalanchego/graft/evm/utils" + "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/vms/evm/sync/customrawdb" "github.com/ava-labs/libevm/common" "github.com/ava-labs/libevm/core/rawdb" @@ -78,7 +78,7 @@ func TestSetupGenesis(t *testing.T) { func testSetupGenesis(t *testing.T, scheme string) { apricotPhase1Config := params.Copy(params.TestApricotPhase1Config) - params.GetExtra(&apricotPhase1Config).ApricotPhase1BlockTimestamp = utils.NewUint64(100) + params.GetExtra(&apricotPhase1Config).ApricotPhase1BlockTimestamp = utils.PointerTo[uint64](100) var ( customghash = common.HexToHash("0x1099a11e9e454bd3ef31d688cf21936671966407bc330f051d754b5ce401e7ed") customg = Genesis{ @@ -91,7 +91,7 @@ func testSetupGenesis(t *testing.T, scheme string) { ) rollbackApricotPhase1Config := params.Copy(&apricotPhase1Config) - params.GetExtra(&rollbackApricotPhase1Config).ApricotPhase1BlockTimestamp = utils.NewUint64(90) + params.GetExtra(&rollbackApricotPhase1Config).ApricotPhase1BlockTimestamp = utils.PointerTo[uint64](90) oldcustomg.Config = &rollbackApricotPhase1Config tests := []struct { name string @@ -237,7 +237,7 @@ func TestNetworkUpgradeBetweenHeadAndAcceptedBlock(t *testing.T) { require.Greater(block.Time, bc.lastAccepted.Time()) activatedGenesis := customg - apricotPhase2Timestamp := utils.NewUint64(51) + apricotPhase2Timestamp := utils.PointerTo[uint64](51) updatedApricotPhase2Config := params.Copy(params.TestApricotPhase1Config) params.GetExtra(&updatedApricotPhase2Config).ApricotPhase2BlockTimestamp = apricotPhase2Timestamp @@ -275,7 +275,7 @@ func TestGenesisWriteUpgradesRegression(t *testing.T) { params.GetExtra(genesis.Config).UpgradeConfig.PrecompileUpgrades = []extras.PrecompileUpgrade{ { - Config: warp.NewConfig(utils.NewUint64(51), 0, false), + Config: warp.NewConfig(utils.PointerTo[uint64](51), 0, false), }, } _, _, err = SetupGenesisBlock(db, trieDB, genesis, genesisBlock.Hash(), false) diff --git a/graft/coreth/core/state_processor_test.go b/graft/coreth/core/state_processor_test.go index a5f14e1ee995..ae5a0dc9d48f 100644 --- a/graft/coreth/core/state_processor_test.go +++ b/graft/coreth/core/state_processor_test.go @@ -41,8 +41,8 @@ import ( "github.com/ava-labs/avalanchego/graft/coreth/plugin/evm/upgrade/ap1" "github.com/ava-labs/avalanchego/graft/coreth/plugin/evm/upgrade/ap3" "github.com/ava-labs/avalanchego/graft/coreth/plugin/evm/upgrade/cortina" - "github.com/ava-labs/avalanchego/graft/evm/utils" "github.com/ava-labs/avalanchego/upgrade" + "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/vms/evm/acp176" "github.com/ava-labs/libevm/common" "github.com/ava-labs/libevm/consensus/misc/eip4844" @@ -283,8 +283,8 @@ func TestStateProcessorErrors(t *testing.T) { }, &extras.ChainConfig{ NetworkUpgrades: extras.NetworkUpgrades{ - ApricotPhase1BlockTimestamp: utils.NewUint64(0), - ApricotPhase2BlockTimestamp: utils.NewUint64(0), + ApricotPhase1BlockTimestamp: utils.PointerTo[uint64](0), + ApricotPhase2BlockTimestamp: utils.PointerTo[uint64](0), }, }, ), @@ -391,7 +391,7 @@ func GenerateBadBlock(parent *types.Block, engine consensus.Engine, txs types.Tr } if configExtra.IsGranite(header.Time) { headerExtra := customtypes.GetHeaderExtra(header) - headerExtra.TimeMilliseconds = utils.NewUint64(timeMS) + headerExtra.TimeMilliseconds = utils.PointerTo(timeMS) } if configExtra.IsApricotPhase4(header.Time) { headerExtra := customtypes.GetHeaderExtra(header) diff --git a/graft/coreth/internal/ethapi/api_test.go b/graft/coreth/internal/ethapi/api_test.go index 37c3a715f39e..1902ff286380 100644 --- a/graft/coreth/internal/ethapi/api_test.go +++ b/graft/coreth/internal/ethapi/api_test.go @@ -49,7 +49,7 @@ import ( "github.com/ava-labs/avalanchego/graft/coreth/params" "github.com/ava-labs/avalanchego/graft/coreth/plugin/evm/upgrade/ap3" "github.com/ava-labs/avalanchego/graft/coreth/rpc" - "github.com/ava-labs/avalanchego/graft/evm/utils" + "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/libevm/accounts" "github.com/ava-labs/libevm/accounts/keystore" "github.com/ava-labs/libevm/common" @@ -796,8 +796,8 @@ func TestEstimateGas(t *testing.T) { func TestCall(t *testing.T) { // Enable BLOBHASH opcode in Cancun cfg := *params.TestChainConfig - cfg.ShanghaiTime = utils.NewUint64(0) - cfg.CancunTime = utils.NewUint64(0) + cfg.ShanghaiTime = utils.PointerTo[uint64](0) + cfg.CancunTime = utils.PointerTo[uint64](0) t.Parallel() // Initialize test accounts var ( diff --git a/graft/coreth/params/config.go b/graft/coreth/params/config.go index 80f1f4bf917d..46b9c984f434 100644 --- a/graft/coreth/params/config.go +++ b/graft/coreth/params/config.go @@ -31,7 +31,7 @@ import ( "math/big" "github.com/ava-labs/avalanchego/graft/coreth/params/extras" - "github.com/ava-labs/avalanchego/graft/evm/utils" + "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/libevm/libevm" ethparams "github.com/ava-labs/libevm/params" ) @@ -96,8 +96,8 @@ func initialiseChainConfigs() { MuirGlacierBlock: big.NewInt(0), BerlinBlock: big.NewInt(0), LondonBlock: big.NewInt(0), - ShanghaiTime: utils.NewUint64(0), - CancunTime: utils.NewUint64(0), + ShanghaiTime: utils.PointerTo[uint64](0), + CancunTime: utils.PointerTo[uint64](0), }, extras.TestChainConfig, ) @@ -333,7 +333,7 @@ func initialiseChainConfigs() { MuirGlacierBlock: big.NewInt(0), BerlinBlock: big.NewInt(0), LondonBlock: big.NewInt(0), - ShanghaiTime: utils.NewUint64(0), + ShanghaiTime: utils.PointerTo[uint64](0), }, extras.TestDurangoChainConfig, ) @@ -354,8 +354,8 @@ func initialiseChainConfigs() { MuirGlacierBlock: big.NewInt(0), BerlinBlock: big.NewInt(0), LondonBlock: big.NewInt(0), - ShanghaiTime: utils.NewUint64(0), - CancunTime: utils.NewUint64(0), + ShanghaiTime: utils.PointerTo[uint64](0), + CancunTime: utils.PointerTo[uint64](0), }, extras.TestEtnaChainConfig, ) @@ -376,8 +376,8 @@ func initialiseChainConfigs() { MuirGlacierBlock: big.NewInt(0), BerlinBlock: big.NewInt(0), LondonBlock: big.NewInt(0), - ShanghaiTime: utils.NewUint64(0), - CancunTime: utils.NewUint64(0), + ShanghaiTime: utils.PointerTo[uint64](0), + CancunTime: utils.PointerTo[uint64](0), }, extras.TestFortunaChainConfig, ) @@ -398,8 +398,8 @@ func initialiseChainConfigs() { MuirGlacierBlock: big.NewInt(0), BerlinBlock: big.NewInt(0), LondonBlock: big.NewInt(0), - ShanghaiTime: utils.NewUint64(0), - CancunTime: utils.NewUint64(0), + ShanghaiTime: utils.PointerTo[uint64](0), + CancunTime: utils.PointerTo[uint64](0), }, extras.TestGraniteChainConfig, ) @@ -420,8 +420,8 @@ func initialiseChainConfigs() { MuirGlacierBlock: big.NewInt(0), BerlinBlock: big.NewInt(0), LondonBlock: big.NewInt(0), - ShanghaiTime: utils.NewUint64(0), - CancunTime: utils.NewUint64(0), + ShanghaiTime: utils.PointerTo[uint64](0), + CancunTime: utils.PointerTo[uint64](0), }, extras.TestHeliconChainConfig, ) diff --git a/graft/coreth/params/config_extra.go b/graft/coreth/params/config_extra.go index 42e8cd730ae8..b96194534f8c 100644 --- a/graft/coreth/params/config_extra.go +++ b/graft/coreth/params/config_extra.go @@ -10,8 +10,8 @@ import ( "math/big" "github.com/ava-labs/avalanchego/graft/coreth/params/extras" - "github.com/ava-labs/avalanchego/graft/evm/utils" "github.com/ava-labs/avalanchego/upgrade" + "github.com/ava-labs/avalanchego/utils" ) const ( @@ -80,11 +80,11 @@ func SetEthUpgrades(c *ChainConfig) error { // We only mark Shanghai and Cancun as enabled if we have marked them as // scheduled. if durango := extra.DurangoBlockTimestamp; durango != nil && *durango < unscheduledActivation { - c.ShanghaiTime = utils.NewUint64(*durango) + c.ShanghaiTime = utils.PointerTo(*durango) } if etna := extra.EtnaTimestamp; etna != nil && *etna < unscheduledActivation { - c.CancunTime = utils.NewUint64(*etna) + c.CancunTime = utils.PointerTo(*etna) } return nil } diff --git a/graft/coreth/params/config_extra_test.go b/graft/coreth/params/config_extra_test.go index f20f4c5f2205..70f5fa2fe209 100644 --- a/graft/coreth/params/config_extra_test.go +++ b/graft/coreth/params/config_extra_test.go @@ -11,8 +11,8 @@ import ( "github.com/stretchr/testify/require" "github.com/ava-labs/avalanchego/graft/coreth/params/extras" - "github.com/ava-labs/avalanchego/graft/evm/utils" "github.com/ava-labs/avalanchego/upgrade/upgradetest" + "github.com/ava-labs/avalanchego/utils" ) func TestMain(m *testing.M) { @@ -22,7 +22,7 @@ func TestMain(m *testing.M) { func TestSetEthUpgrades(t *testing.T) { genesisBlock := big.NewInt(0) - genesisTimestamp := utils.NewUint64(initiallyActive) + genesisTimestamp := utils.PointerTo(initiallyActive) tests := []struct { fork upgradetest.Fork expected *ChainConfig diff --git a/graft/coreth/params/config_test.go b/graft/coreth/params/config_test.go index 052485701b2c..7d97a8853041 100644 --- a/graft/coreth/params/config_test.go +++ b/graft/coreth/params/config_test.go @@ -35,7 +35,7 @@ import ( "time" "github.com/ava-labs/avalanchego/graft/coreth/params/extras" - "github.com/ava-labs/avalanchego/graft/evm/utils" + "github.com/ava-labs/avalanchego/utils" ethparams "github.com/ava-labs/libevm/params" ) @@ -119,7 +119,7 @@ func TestCheckCompatible(t *testing.T) { headTimestamp: 0, wantErr: ðparams.ConfigCompatError{ What: "ApricotPhase5 fork block timestamp", - StoredTime: utils.NewUint64(0), + StoredTime: utils.PointerTo[uint64](0), NewTime: nil, RewindToTime: 0, }, @@ -131,7 +131,7 @@ func TestCheckCompatible(t *testing.T) { headTimestamp: 100, wantErr: ðparams.ConfigCompatError{ What: "ApricotPhase5 fork block timestamp", - StoredTime: utils.NewUint64(0), + StoredTime: utils.PointerTo[uint64](0), NewTime: nil, RewindToTime: 0, }, @@ -151,7 +151,7 @@ func TestConfigRules(t *testing.T) { &ChainConfig{}, &extras.ChainConfig{ NetworkUpgrades: extras.NetworkUpgrades{ - CortinaBlockTimestamp: utils.NewUint64(500), + CortinaBlockTimestamp: utils.PointerTo[uint64](500), }, }, ) diff --git a/graft/coreth/params/extras/config.go b/graft/coreth/params/extras/config.go index 478fec5d75be..59841607a77d 100644 --- a/graft/coreth/params/extras/config.go +++ b/graft/coreth/params/extras/config.go @@ -10,8 +10,8 @@ import ( "github.com/ava-labs/libevm/common" - "github.com/ava-labs/avalanchego/graft/evm/utils" "github.com/ava-labs/avalanchego/snow" + "github.com/ava-labs/avalanchego/utils" ethparams "github.com/ava-labs/libevm/params" ) @@ -20,63 +20,63 @@ var ( TestLaunchConfig = &ChainConfig{} TestApricotPhase1Config = copyAndSet(TestLaunchConfig, func(c *ChainConfig) { - c.NetworkUpgrades.ApricotPhase1BlockTimestamp = utils.NewUint64(0) + c.NetworkUpgrades.ApricotPhase1BlockTimestamp = utils.PointerTo[uint64](0) }) TestApricotPhase2Config = copyAndSet(TestApricotPhase1Config, func(c *ChainConfig) { - c.NetworkUpgrades.ApricotPhase2BlockTimestamp = utils.NewUint64(0) + c.NetworkUpgrades.ApricotPhase2BlockTimestamp = utils.PointerTo[uint64](0) }) TestApricotPhase3Config = copyAndSet(TestApricotPhase2Config, func(c *ChainConfig) { - c.NetworkUpgrades.ApricotPhase3BlockTimestamp = utils.NewUint64(0) + c.NetworkUpgrades.ApricotPhase3BlockTimestamp = utils.PointerTo[uint64](0) }) TestApricotPhase4Config = copyAndSet(TestApricotPhase3Config, func(c *ChainConfig) { - c.NetworkUpgrades.ApricotPhase4BlockTimestamp = utils.NewUint64(0) + c.NetworkUpgrades.ApricotPhase4BlockTimestamp = utils.PointerTo[uint64](0) }) TestApricotPhase5Config = copyAndSet(TestApricotPhase4Config, func(c *ChainConfig) { - c.NetworkUpgrades.ApricotPhase5BlockTimestamp = utils.NewUint64(0) + c.NetworkUpgrades.ApricotPhase5BlockTimestamp = utils.PointerTo[uint64](0) }) TestApricotPhasePre6Config = copyAndSet(TestApricotPhase5Config, func(c *ChainConfig) { - c.NetworkUpgrades.ApricotPhasePre6BlockTimestamp = utils.NewUint64(0) + c.NetworkUpgrades.ApricotPhasePre6BlockTimestamp = utils.PointerTo[uint64](0) }) TestApricotPhase6Config = copyAndSet(TestApricotPhasePre6Config, func(c *ChainConfig) { - c.NetworkUpgrades.ApricotPhase6BlockTimestamp = utils.NewUint64(0) + c.NetworkUpgrades.ApricotPhase6BlockTimestamp = utils.PointerTo[uint64](0) }) TestApricotPhasePost6Config = copyAndSet(TestApricotPhase6Config, func(c *ChainConfig) { - c.NetworkUpgrades.ApricotPhasePost6BlockTimestamp = utils.NewUint64(0) + c.NetworkUpgrades.ApricotPhasePost6BlockTimestamp = utils.PointerTo[uint64](0) }) TestBanffChainConfig = copyAndSet(TestApricotPhasePost6Config, func(c *ChainConfig) { - c.NetworkUpgrades.BanffBlockTimestamp = utils.NewUint64(0) + c.NetworkUpgrades.BanffBlockTimestamp = utils.PointerTo[uint64](0) }) TestCortinaChainConfig = copyAndSet(TestBanffChainConfig, func(c *ChainConfig) { - c.NetworkUpgrades.CortinaBlockTimestamp = utils.NewUint64(0) + c.NetworkUpgrades.CortinaBlockTimestamp = utils.PointerTo[uint64](0) }) TestDurangoChainConfig = copyAndSet(TestCortinaChainConfig, func(c *ChainConfig) { - c.NetworkUpgrades.DurangoBlockTimestamp = utils.NewUint64(0) + c.NetworkUpgrades.DurangoBlockTimestamp = utils.PointerTo[uint64](0) }) TestEtnaChainConfig = copyAndSet(TestDurangoChainConfig, func(c *ChainConfig) { - c.NetworkUpgrades.EtnaTimestamp = utils.NewUint64(0) + c.NetworkUpgrades.EtnaTimestamp = utils.PointerTo[uint64](0) }) TestFortunaChainConfig = copyAndSet(TestEtnaChainConfig, func(c *ChainConfig) { - c.NetworkUpgrades.FortunaTimestamp = utils.NewUint64(0) + c.NetworkUpgrades.FortunaTimestamp = utils.PointerTo[uint64](0) }) TestGraniteChainConfig = copyAndSet(TestFortunaChainConfig, func(c *ChainConfig) { - c.NetworkUpgrades.GraniteTimestamp = utils.NewUint64(0) + c.NetworkUpgrades.GraniteTimestamp = utils.PointerTo[uint64](0) }) TestHeliconChainConfig = copyAndSet(TestGraniteChainConfig, func(c *ChainConfig) { - c.NetworkUpgrades.HeliconTimestamp = utils.NewUint64(0) + c.NetworkUpgrades.HeliconTimestamp = utils.PointerTo[uint64](0) }) TestChainConfig = copyConfig(TestHeliconChainConfig) @@ -125,7 +125,7 @@ func (c *ChainConfig) CheckConfigCompatible(newcfg_ *ethparams.ChainConfig, head // Return an error to prevent the chain from starting, just in case. return ethparams.NewTimestampCompatError( fmt.Sprintf("ChainConfig.Hooks() is not of the expected type *extras.ChainConfig, got %T", newcfg_.Hooks()), - utils.NewUint64(0), + utils.PointerTo[uint64](0), nil, ) } diff --git a/graft/coreth/params/extras/config_extra_test.go b/graft/coreth/params/extras/config_extra_test.go index 4e26cf667571..d8bfc4a2d764 100644 --- a/graft/coreth/params/extras/config_extra_test.go +++ b/graft/coreth/params/extras/config_extra_test.go @@ -8,7 +8,7 @@ import ( "github.com/stretchr/testify/require" - "github.com/ava-labs/avalanchego/graft/evm/utils" + "github.com/ava-labs/avalanchego/utils" ) func TestIsTimestampForked(t *testing.T) { @@ -30,22 +30,22 @@ func TestIsTimestampForked(t *testing.T) { isForked: false, }, "zero fork at genesis": { - fork: utils.NewUint64(0), + fork: utils.PointerTo[uint64](0), block: 0, isForked: true, }, "pre fork timestamp": { - fork: utils.NewUint64(100), + fork: utils.PointerTo[uint64](100), block: 50, isForked: false, }, "at fork timestamp": { - fork: utils.NewUint64(100), + fork: utils.PointerTo[uint64](100), block: 100, isForked: true, }, "post fork timestamp": { - fork: utils.NewUint64(100), + fork: utils.PointerTo[uint64](100), block: 150, isForked: true, }, @@ -72,50 +72,50 @@ func TestIsForkTransition(t *testing.T) { transitioned: false, }, "activate at genesis": { - fork: utils.NewUint64(0), + fork: utils.PointerTo[uint64](0), parent: nil, current: 0, transitioned: true, }, "nil fork arbitrary transition": { fork: nil, - parent: utils.NewUint64(100), + parent: utils.PointerTo[uint64](100), current: 101, transitioned: false, }, "nil fork transition same timestamp": { fork: nil, - parent: utils.NewUint64(100), + parent: utils.PointerTo[uint64](100), current: 100, transitioned: false, }, "exact match on current timestamp": { - fork: utils.NewUint64(100), - parent: utils.NewUint64(99), + fork: utils.PointerTo[uint64](100), + parent: utils.PointerTo[uint64](99), current: 100, transitioned: true, }, "current same as parent does not transition twice": { - fork: utils.NewUint64(100), - parent: utils.NewUint64(101), + fork: utils.PointerTo[uint64](100), + parent: utils.PointerTo[uint64](101), current: 101, transitioned: false, }, "current, parent, and fork same should not transition twice": { - fork: utils.NewUint64(100), - parent: utils.NewUint64(100), + fork: utils.PointerTo[uint64](100), + parent: utils.PointerTo[uint64](100), current: 100, transitioned: false, }, "current transitions after fork": { - fork: utils.NewUint64(100), - parent: utils.NewUint64(99), + fork: utils.PointerTo[uint64](100), + parent: utils.PointerTo[uint64](99), current: 101, transitioned: true, }, "current and parent come after fork": { - fork: utils.NewUint64(100), - parent: utils.NewUint64(101), + fork: utils.PointerTo[uint64](100), + parent: utils.PointerTo[uint64](101), current: 102, transitioned: false, }, diff --git a/graft/coreth/params/extras/precompile_upgrade.go b/graft/coreth/params/extras/precompile_upgrade.go index 9ca7648f0ce6..d2cc2abd754d 100644 --- a/graft/coreth/params/extras/precompile_upgrade.go +++ b/graft/coreth/params/extras/precompile_upgrade.go @@ -12,7 +12,7 @@ import ( "github.com/ava-labs/avalanchego/graft/coreth/precompile/modules" "github.com/ava-labs/avalanchego/graft/coreth/precompile/precompileconfig" - "github.com/ava-labs/avalanchego/graft/evm/utils" + "github.com/ava-labs/avalanchego/utils" ethparams "github.com/ava-labs/libevm/params" ) @@ -97,7 +97,7 @@ func (c *ChainConfig) verifyPrecompileUpgrades() error { lastTimestamp = nil } else { disabled = lastUpgradeByKey.disabled - lastTimestamp = utils.NewUint64(lastUpgradeByKey.blockTimestamp) + lastTimestamp = utils.PointerTo(lastUpgradeByKey.blockTimestamp) } upgradeTimestamp := upgrade.Timestamp() diff --git a/graft/coreth/plugin/evm/atomic/export_tx.go b/graft/coreth/plugin/evm/atomic/export_tx.go index 9c0c9bf552e9..c902cf6382cb 100644 --- a/graft/coreth/plugin/evm/atomic/export_tx.go +++ b/graft/coreth/plugin/evm/atomic/export_tx.go @@ -19,6 +19,7 @@ import ( "github.com/ava-labs/avalanchego/graft/coreth/plugin/evm/upgrade/ap5" "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/snow" + "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/utils/constants" "github.com/ava-labs/avalanchego/utils/crypto/secp256k1" "github.com/ava-labs/avalanchego/utils/math" @@ -27,8 +28,6 @@ import ( "github.com/ava-labs/avalanchego/vms/components/avax" "github.com/ava-labs/avalanchego/vms/components/verify" "github.com/ava-labs/avalanchego/vms/secp256k1fx" - - avalancheutils "github.com/ava-labs/avalanchego/utils" ) var ( @@ -125,7 +124,7 @@ func (utx *UnsignedExportTx) Verify( if !avax.IsSortedTransferableOutputs(utx.ExportedOutputs, Codec) { return ErrOutputsNotSorted } - if rules.IsApricotPhase1 && !avalancheutils.IsSortedAndUnique(utx.Ins) { + if rules.IsApricotPhase1 && !utils.IsSortedAndUnique(utx.Ins) { return ErrInputsNotSortedUnique } diff --git a/graft/coreth/plugin/evm/config/config_test.go b/graft/coreth/plugin/evm/config/config_test.go index 2ef813043149..9e351cdea7de 100644 --- a/graft/coreth/plugin/evm/config/config_test.go +++ b/graft/coreth/plugin/evm/config/config_test.go @@ -12,15 +12,10 @@ import ( "github.com/ava-labs/libevm/common" "github.com/stretchr/testify/require" + "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/utils/constants" ) -// newTrue returns a pointer to a bool that is true -func newTrue() *bool { - b := true - return &b -} - func TestUnmarshalConfig(t *testing.T) { tests := []struct { name string @@ -70,7 +65,7 @@ func TestUnmarshalConfig(t *testing.T) { { "state sync enabled", []byte(`{"state-sync-enabled":true}`), - Config{StateSyncEnabled: newTrue()}, + Config{StateSyncEnabled: utils.PointerTo(true)}, false, }, { diff --git a/graft/coreth/plugin/evm/customheader/base_fee_test.go b/graft/coreth/plugin/evm/customheader/base_fee_test.go index 70fe14f07c2d..ce3fd090d1e0 100644 --- a/graft/coreth/plugin/evm/customheader/base_fee_test.go +++ b/graft/coreth/plugin/evm/customheader/base_fee_test.go @@ -17,7 +17,7 @@ import ( "github.com/ava-labs/avalanchego/graft/coreth/plugin/evm/upgrade/ap4" "github.com/ava-labs/avalanchego/graft/coreth/plugin/evm/upgrade/ap5" "github.com/ava-labs/avalanchego/graft/coreth/plugin/evm/upgrade/etna" - "github.com/ava-labs/avalanchego/graft/evm/utils" + "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/vms/components/gas" "github.com/ava-labs/avalanchego/vms/evm/acp176" ) @@ -40,7 +40,7 @@ func TestBaseFee(t *testing.T) { { name: "ap3_first_block", upgrades: extras.NetworkUpgrades{ - ApricotPhase3BlockTimestamp: utils.NewUint64(1), + ApricotPhase3BlockTimestamp: utils.PointerTo[uint64](1), }, parent: &types.Header{ Number: big.NewInt(1), @@ -347,7 +347,7 @@ func TestBaseFee(t *testing.T) { { name: "fortuna_first_block", upgrades: extras.NetworkUpgrades{ - FortunaTimestamp: utils.NewUint64(1), + FortunaTimestamp: utils.PointerTo[uint64](1), }, parent: &types.Header{ Number: big.NewInt(1), @@ -409,7 +409,7 @@ func TestBaseFee(t *testing.T) { Time: 1, Extra: (&acp176.State{}).Bytes(), }, &customtypes.HeaderExtra{ - TimeMilliseconds: utils.NewUint64(1000), + TimeMilliseconds: utils.PointerTo[uint64](1000), }), timeMS: 0, wantErr: errInvalidTimestamp, @@ -417,8 +417,8 @@ func TestBaseFee(t *testing.T) { { name: "granite_first_block_with_state", upgrades: extras.NetworkUpgrades{ - FortunaTimestamp: utils.NewUint64(1), - GraniteTimestamp: utils.NewUint64(1), + FortunaTimestamp: utils.PointerTo[uint64](1), + GraniteTimestamp: utils.PointerTo[uint64](1), }, parent: &types.Header{ Number: big.NewInt(1), @@ -430,8 +430,8 @@ func TestBaseFee(t *testing.T) { { name: "granite_first_block_after_fortuna", upgrades: extras.NetworkUpgrades{ - FortunaTimestamp: utils.NewUint64(0), - GraniteTimestamp: utils.NewUint64(1), + FortunaTimestamp: utils.PointerTo[uint64](0), + GraniteTimestamp: utils.PointerTo[uint64](1), }, parent: &types.Header{ Number: big.NewInt(1), diff --git a/graft/coreth/plugin/evm/customheader/extra_test.go b/graft/coreth/plugin/evm/customheader/extra_test.go index e8263190583e..1b8826103ac5 100644 --- a/graft/coreth/plugin/evm/customheader/extra_test.go +++ b/graft/coreth/plugin/evm/customheader/extra_test.go @@ -17,7 +17,7 @@ import ( "github.com/ava-labs/avalanchego/graft/coreth/plugin/evm/upgrade/ap3" "github.com/ava-labs/avalanchego/graft/coreth/plugin/evm/upgrade/ap4" "github.com/ava-labs/avalanchego/graft/coreth/plugin/evm/upgrade/ap5" - "github.com/ava-labs/avalanchego/graft/evm/utils" + "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/vms/components/gas" "github.com/ava-labs/avalanchego/vms/evm/acp176" ) @@ -47,7 +47,7 @@ func TestExtraPrefix(t *testing.T) { { name: "ap3_first_block", upgrades: extras.NetworkUpgrades{ - ApricotPhase3BlockTimestamp: utils.NewUint64(1), + ApricotPhase3BlockTimestamp: utils.PointerTo[uint64](1), }, parent: &types.Header{ Number: big.NewInt(1), @@ -278,7 +278,7 @@ func TestExtraPrefix(t *testing.T) { { name: "fortuna_first_block", upgrades: extras.NetworkUpgrades{ - FortunaTimestamp: utils.NewUint64(1), + FortunaTimestamp: utils.PointerTo[uint64](1), }, parent: &types.Header{ Number: big.NewInt(1), @@ -315,7 +315,7 @@ func TestExtraPrefix(t *testing.T) { ExtDataGasUsed: big.NewInt(1), }, ), - desiredTargetExcess: (*gas.Gas)(utils.NewUint64(3)), + desiredTargetExcess: (*gas.Gas)(utils.PointerTo[uint64](3)), want: (&acp176.State{ Gas: gas.State{ Capacity: acp176.MinMaxPerSecond - 3, @@ -366,7 +366,7 @@ func TestExtraPrefix(t *testing.T) { ExtDataGasUsed: big.NewInt(1), }, ), - desiredTargetExcess: (*gas.Gas)(utils.NewUint64(0)), + desiredTargetExcess: (*gas.Gas)(utils.PointerTo[uint64](0)), want: (&acp176.State{ Gas: gas.State{ Capacity: 10_009_770, // [acp176.MinMaxCapacity] * e^([acp176.MaxTargetExcessDiff] / [acp176.TargetConversion]) diff --git a/graft/coreth/plugin/evm/customheader/gas_limit_test.go b/graft/coreth/plugin/evm/customheader/gas_limit_test.go index cae4a1476991..06d6ad02b91a 100644 --- a/graft/coreth/plugin/evm/customheader/gas_limit_test.go +++ b/graft/coreth/plugin/evm/customheader/gas_limit_test.go @@ -17,7 +17,7 @@ import ( "github.com/ava-labs/avalanchego/graft/coreth/plugin/evm/upgrade/ap1" "github.com/ava-labs/avalanchego/graft/coreth/plugin/evm/upgrade/ap5" "github.com/ava-labs/avalanchego/graft/coreth/plugin/evm/upgrade/cortina" - "github.com/ava-labs/avalanchego/graft/evm/utils" + "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/utils/math" "github.com/ava-labs/avalanchego/vms/components/gas" "github.com/ava-labs/avalanchego/vms/evm/acp176" @@ -94,13 +94,13 @@ func TestVerifyGasUsed(t *testing.T) { parent: customtypes.WithHeaderExtra(&types.Header{ Number: big.NewInt(0), }, &customtypes.HeaderExtra{ - TimeMilliseconds: utils.NewUint64(0), + TimeMilliseconds: utils.PointerTo[uint64](0), }), header: customtypes.WithHeaderExtra(&types.Header{ Time: 1, GasUsed: acp176.MinMaxPerSecond + 500, }, &customtypes.HeaderExtra{ - TimeMilliseconds: utils.NewUint64(1500), + TimeMilliseconds: utils.PointerTo[uint64](1500), }), want: nil, }, @@ -206,12 +206,12 @@ func TestVerifyGasLimit(t *testing.T) { parent: customtypes.WithHeaderExtra(&types.Header{ Number: big.NewInt(0), }, &customtypes.HeaderExtra{ - TimeMilliseconds: utils.NewUint64(0), + TimeMilliseconds: utils.PointerTo[uint64](0), }), header: customtypes.WithHeaderExtra(&types.Header{ GasLimit: acp176.MinMaxPerSecond - 1, }, &customtypes.HeaderExtra{ - TimeMilliseconds: utils.NewUint64(0), + TimeMilliseconds: utils.PointerTo[uint64](0), }), want: errInvalidGasLimit, }, @@ -221,12 +221,12 @@ func TestVerifyGasLimit(t *testing.T) { parent: customtypes.WithHeaderExtra(&types.Header{ Number: big.NewInt(0), }, &customtypes.HeaderExtra{ - TimeMilliseconds: utils.NewUint64(0), + TimeMilliseconds: utils.PointerTo[uint64](0), }), header: customtypes.WithHeaderExtra(&types.Header{ GasLimit: acp176.MinMaxCapacity, }, &customtypes.HeaderExtra{ - TimeMilliseconds: utils.NewUint64(0), + TimeMilliseconds: utils.PointerTo[uint64](0), }), }, { @@ -390,7 +390,7 @@ func TestGasCapacity(t *testing.T) { parent: customtypes.WithHeaderExtra(&types.Header{ Number: big.NewInt(0), }, &customtypes.HeaderExtra{ - TimeMilliseconds: utils.NewUint64(0), + TimeMilliseconds: utils.PointerTo[uint64](0), }), timestamp: 1000, want: acp176.MinMaxPerSecond, @@ -401,7 +401,7 @@ func TestGasCapacity(t *testing.T) { parent: customtypes.WithHeaderExtra(&types.Header{ Number: big.NewInt(0), }, &customtypes.HeaderExtra{ - TimeMilliseconds: utils.NewUint64(0), + TimeMilliseconds: utils.PointerTo[uint64](0), }), timestamp: 1500, want: acp176.MinMaxPerSecond * 3 / 2, @@ -474,13 +474,13 @@ func TestRemainingAtomicGasCapacity(t *testing.T) { parent: customtypes.WithHeaderExtra(&types.Header{ Number: big.NewInt(0), }, &customtypes.HeaderExtra{ - TimeMilliseconds: utils.NewUint64(0), + TimeMilliseconds: utils.PointerTo[uint64](0), }), header: customtypes.WithHeaderExtra(&types.Header{ Time: 1, GasUsed: 1, }, &customtypes.HeaderExtra{ - TimeMilliseconds: utils.NewUint64(1500), + TimeMilliseconds: utils.PointerTo[uint64](1500), }), want: acp176.MinMaxPerSecond*3/2 - 1, }, diff --git a/graft/coreth/plugin/evm/customheader/min_delay_excess_test.go b/graft/coreth/plugin/evm/customheader/min_delay_excess_test.go index f86a58d985fe..f4a073266c93 100644 --- a/graft/coreth/plugin/evm/customheader/min_delay_excess_test.go +++ b/graft/coreth/plugin/evm/customheader/min_delay_excess_test.go @@ -11,15 +11,14 @@ import ( "github.com/ava-labs/avalanchego/graft/coreth/params/extras" "github.com/ava-labs/avalanchego/graft/coreth/plugin/evm/customtypes" - "github.com/ava-labs/avalanchego/graft/evm/utils" - "github.com/ava-labs/avalanchego/graft/evm/utils/utilstest" + "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/vms/evm/acp226" ) func TestMinDelayExcess(t *testing.T) { activatingGraniteConfig := *extras.TestGraniteChainConfig activatingGraniteTimestamp := uint64(1000) - activatingGraniteConfig.NetworkUpgrades.GraniteTimestamp = utils.NewUint64(activatingGraniteTimestamp) + activatingGraniteConfig.NetworkUpgrades.GraniteTimestamp = utils.PointerTo(activatingGraniteTimestamp) tests := []struct { name string @@ -52,7 +51,7 @@ func TestMinDelayExcess(t *testing.T) { header: &types.Header{ Time: 1001, }, - desiredMinDelayExcess: utilstest.PointerTo(acp226.DelayExcess(1000)), + desiredMinDelayExcess: utils.PointerTo(acp226.DelayExcess(1000)), expectedDelayExcess: nil, }, { @@ -65,7 +64,7 @@ func TestMinDelayExcess(t *testing.T) { Time: activatingGraniteTimestamp + 1, }, desiredMinDelayExcess: nil, - expectedDelayExcess: utilstest.PointerTo(acp226.DelayExcess(acp226.InitialDelayExcess)), + expectedDelayExcess: utils.PointerTo(acp226.DelayExcess(acp226.InitialDelayExcess)), }, { name: "granite_no_parent_min_delay_error", @@ -88,7 +87,7 @@ func TestMinDelayExcess(t *testing.T) { Time: 1001, }, desiredMinDelayExcess: nil, - expectedDelayExcess: utilstest.PointerTo(acp226.DelayExcess(500)), + expectedDelayExcess: utils.PointerTo(acp226.DelayExcess(500)), }, { name: "granite_with_desired_min_delay_excess", @@ -97,8 +96,8 @@ func TestMinDelayExcess(t *testing.T) { header: &types.Header{ Time: 1001, }, - desiredMinDelayExcess: utilstest.PointerTo(acp226.DelayExcess(1000)), - expectedDelayExcess: utilstest.PointerTo(acp226.DelayExcess(500 + acp226.MaxDelayExcessDiff)), + desiredMinDelayExcess: utils.PointerTo(acp226.DelayExcess(1000)), + expectedDelayExcess: utils.PointerTo(acp226.DelayExcess(500 + acp226.MaxDelayExcessDiff)), }, { name: "granite_with_zero_desired_value", @@ -107,8 +106,8 @@ func TestMinDelayExcess(t *testing.T) { header: &types.Header{ Time: 1001, }, - desiredMinDelayExcess: utilstest.PointerTo(acp226.DelayExcess(0)), - expectedDelayExcess: utilstest.PointerTo(acp226.DelayExcess(500 - acp226.MaxDelayExcessDiff)), + desiredMinDelayExcess: utils.PointerTo(acp226.DelayExcess(0)), + expectedDelayExcess: utils.PointerTo(acp226.DelayExcess(500 - acp226.MaxDelayExcessDiff)), }, } diff --git a/graft/coreth/plugin/evm/customheader/time_test.go b/graft/coreth/plugin/evm/customheader/time_test.go index 7721c438553c..20ff7e2cd663 100644 --- a/graft/coreth/plugin/evm/customheader/time_test.go +++ b/graft/coreth/plugin/evm/customheader/time_test.go @@ -12,7 +12,7 @@ import ( "github.com/ava-labs/avalanchego/graft/coreth/params/extras" "github.com/ava-labs/avalanchego/graft/coreth/plugin/evm/customtypes" - "github.com/ava-labs/avalanchego/graft/evm/utils" + "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/vms/evm/acp226" ) @@ -31,7 +31,7 @@ func TestVerifyTime(t *testing.T) { }{ { name: "pre_granite_time_milliseconds_should_fail", - header: generateHeader(timeSeconds, utils.NewUint64(timeMillis)), + header: generateHeader(timeSeconds, utils.PointerTo(timeMillis)), extraConfig: extras.TestFortunaChainConfig, expectedErr: ErrTimeMillisecondsBeforeGranite, }, @@ -48,23 +48,23 @@ func TestVerifyTime(t *testing.T) { }, { name: "granite_time_milliseconds_matching_time_should_work", - header: generateHeader(timeSeconds, utils.NewUint64(timeSeconds*1000)), + header: generateHeader(timeSeconds, utils.PointerTo(timeSeconds*1000)), extraConfig: extras.TestGraniteChainConfig, }, { name: "granite_time_milliseconds_matching_time_rounded_should_work", - header: generateHeader(timeSeconds, utils.NewUint64(timeMillis)), + header: generateHeader(timeSeconds, utils.PointerTo(timeMillis)), extraConfig: extras.TestGraniteChainConfig, }, { name: "granite_time_milliseconds_less_than_time_should_fail", - header: generateHeader(timeSeconds, utils.NewUint64((timeSeconds-1)*1000)), + header: generateHeader(timeSeconds, utils.PointerTo((timeSeconds-1)*1000)), extraConfig: extras.TestGraniteChainConfig, expectedErr: ErrTimeMillisecondsMismatched, }, { name: "granite_time_milliseconds_greater_than_time_should_fail", - header: generateHeader(timeSeconds, utils.NewUint64((timeSeconds+1)*1000)), + header: generateHeader(timeSeconds, utils.PointerTo((timeSeconds+1)*1000)), extraConfig: extras.TestGraniteChainConfig, expectedErr: ErrTimeMillisecondsMismatched, }, @@ -77,10 +77,10 @@ func TestVerifyTime(t *testing.T) { }, { name: "granite_time_earlier_than_parent_should_fail", - header: generateHeader(timeSeconds, utils.NewUint64(timeSeconds*1000)), + header: generateHeader(timeSeconds, utils.PointerTo(timeSeconds*1000)), parentHeader: generateHeader( timeSeconds+1, - utils.NewUint64((timeSeconds+1)*1000), + utils.PointerTo((timeSeconds+1)*1000), ), extraConfig: extras.TestGraniteChainConfig, expectedErr: errBlockTooOld, @@ -89,11 +89,11 @@ func TestVerifyTime(t *testing.T) { name: "granite_time_milliseconds_earlier_than_parent_should_fail", header: generateHeader( timeSeconds, - utils.NewUint64(timeSeconds*1000), + utils.PointerTo(timeSeconds*1000), ), parentHeader: generateHeader( timeSeconds, - utils.NewUint64(timeSeconds*1000+1), + utils.PointerTo(timeSeconds*1000+1), ), extraConfig: extras.TestGraniteChainConfig, expectedErr: errBlockTooOld, @@ -108,7 +108,7 @@ func TestVerifyTime(t *testing.T) { name: "granite_time_too_far_in_future_should_fail", header: generateHeader( uint64(now.Add(MaxFutureBlockTime).Add(1*time.Second).Unix()), - utils.NewUint64(uint64(now.Add(MaxFutureBlockTime).Add(1*time.Second).UnixMilli())), + utils.PointerTo(uint64(now.Add(MaxFutureBlockTime).Add(1*time.Second).UnixMilli())), ), extraConfig: extras.TestGraniteChainConfig, expectedErr: ErrBlockTooFarInFuture, @@ -117,14 +117,14 @@ func TestVerifyTime(t *testing.T) { name: "granite_time_milliseconds_too_far_in_future_should_fail", header: generateHeader( uint64(now.Add(MaxFutureBlockTime).Unix()), - utils.NewUint64(uint64(now.Add(MaxFutureBlockTime).Add(1*time.Millisecond).UnixMilli())), + utils.PointerTo(uint64(now.Add(MaxFutureBlockTime).Add(1*time.Millisecond).UnixMilli())), ), extraConfig: extras.TestGraniteChainConfig, expectedErr: ErrBlockTooFarInFuture, }, { name: "first_granite_block_should_work", - header: generateHeader(timeSeconds, utils.NewUint64(timeMillis)), + header: generateHeader(timeSeconds, utils.PointerTo(timeMillis)), parentHeader: generateHeader(timeSeconds, nil), extraConfig: extras.TestGraniteChainConfig, }, @@ -139,8 +139,8 @@ func TestVerifyTime(t *testing.T) { name: "granite_first_block_no_parent_min_delay_excess", header: generateHeaderWithMinDelayExcessAndTime( timeSeconds, - utils.NewUint64(timeMillis), - utils.NewUint64(acp226.InitialDelayExcess), + utils.PointerTo(timeMillis), + utils.PointerTo(uint64(acp226.InitialDelayExcess)), ), parentHeader: generateHeader(timeSeconds-1, nil), // Pre-Granite parent extraConfig: extras.TestGraniteChainConfig, @@ -149,13 +149,13 @@ func TestVerifyTime(t *testing.T) { name: "granite_initial_delay_met", header: generateHeaderWithMinDelayExcessAndTime( timeSeconds, - utils.NewUint64(timeMillis), - utils.NewUint64(acp226.InitialDelayExcess), + utils.PointerTo(timeMillis), + utils.PointerTo(uint64(acp226.InitialDelayExcess)), ), parentHeader: generateHeaderWithMinDelayExcessAndTime( timeSeconds-1, - utils.NewUint64(timeMillis-2000), // 2000 ms is the exact initial delay - utils.NewUint64(acp226.InitialDelayExcess), + utils.PointerTo(timeMillis-2000), // 2000 ms is the exact initial delay + utils.PointerTo(uint64(acp226.InitialDelayExcess)), ), extraConfig: extras.TestGraniteChainConfig, }, @@ -163,13 +163,13 @@ func TestVerifyTime(t *testing.T) { name: "granite_initial_delay_not_met", header: generateHeaderWithMinDelayExcessAndTime( timeSeconds, - utils.NewUint64(timeMillis), - utils.NewUint64(acp226.InitialDelayExcess), + utils.PointerTo(timeMillis), + utils.PointerTo(uint64(acp226.InitialDelayExcess)), ), parentHeader: generateHeaderWithMinDelayExcessAndTime( timeSeconds-1, - utils.NewUint64(timeMillis-1999), // 1 ms less than required - utils.NewUint64(acp226.InitialDelayExcess), + utils.PointerTo(timeMillis-1999), // 1 ms less than required + utils.PointerTo(uint64(acp226.InitialDelayExcess)), ), extraConfig: extras.TestGraniteChainConfig, expectedErr: ErrMinDelayNotMet, @@ -178,13 +178,13 @@ func TestVerifyTime(t *testing.T) { name: "granite_future_timestamp_within_limits", header: generateHeaderWithMinDelayExcessAndTime( timeSeconds+5, // 5 seconds in future - utils.NewUint64(timeMillis+5000), - utils.NewUint64(acp226.InitialDelayExcess), + utils.PointerTo(timeMillis+5000), + utils.PointerTo(uint64(acp226.InitialDelayExcess)), ), parentHeader: generateHeaderWithMinDelayExcessAndTime( timeSeconds-1, - utils.NewUint64(timeMillis-2000), - utils.NewUint64(acp226.InitialDelayExcess), + utils.PointerTo(timeMillis-2000), + utils.PointerTo(uint64(acp226.InitialDelayExcess)), ), extraConfig: extras.TestGraniteChainConfig, }, @@ -192,13 +192,13 @@ func TestVerifyTime(t *testing.T) { name: "granite_future_timestamp_abuse", header: generateHeaderWithMinDelayExcessAndTime( timeSeconds+15, // 15 seconds in future, exceeds MaxFutureBlockTime - utils.NewUint64(timeMillis+15000), - utils.NewUint64(acp226.InitialDelayExcess), + utils.PointerTo(timeMillis+15000), + utils.PointerTo(uint64(acp226.InitialDelayExcess)), ), parentHeader: generateHeaderWithMinDelayExcessAndTime( timeSeconds-1, - utils.NewUint64(timeMillis-2000), - utils.NewUint64(acp226.InitialDelayExcess), + utils.PointerTo(timeMillis-2000), + utils.PointerTo(uint64(acp226.InitialDelayExcess)), ), extraConfig: extras.TestGraniteChainConfig, expectedErr: ErrBlockTooFarInFuture, @@ -207,13 +207,13 @@ func TestVerifyTime(t *testing.T) { name: "granite_zero_delay_excess", header: generateHeaderWithMinDelayExcessAndTime( timeSeconds, - utils.NewUint64(timeMillis), - utils.NewUint64(0), + utils.PointerTo(timeMillis), + utils.PointerTo[uint64](0), ), parentHeader: generateHeaderWithMinDelayExcessAndTime( timeSeconds, - utils.NewUint64(timeMillis-1), // 1ms delay, meets zero requirement - utils.NewUint64(0), // Parent has zero delay excess + utils.PointerTo(timeMillis-1), // 1ms delay, meets zero requirement + utils.PointerTo[uint64](0), // Parent has zero delay excess ), extraConfig: extras.TestGraniteChainConfig, }, @@ -221,13 +221,13 @@ func TestVerifyTime(t *testing.T) { name: "granite_zero_delay_excess_but_zero_delay", header: generateHeaderWithMinDelayExcessAndTime( timeSeconds, - utils.NewUint64(timeMillis), - utils.NewUint64(0), + utils.PointerTo(timeMillis), + utils.PointerTo[uint64](0), ), parentHeader: generateHeaderWithMinDelayExcessAndTime( timeSeconds, - utils.NewUint64(timeMillis), // Same timestamp, zero delay - utils.NewUint64(0), // Parent has zero delay excess + utils.PointerTo(timeMillis), // Same timestamp, zero delay + utils.PointerTo[uint64](0), // Parent has zero delay excess ), extraConfig: extras.TestGraniteChainConfig, expectedErr: ErrMinDelayNotMet, @@ -269,7 +269,7 @@ func TestGetNextTimestamp(t *testing.T) { }, { name: "current_time_after_parent_time_with_milliseconds", - parent: generateHeader(nowSeconds-10, utils.NewUint64(nowMillis-500)), + parent: generateHeader(nowSeconds-10, utils.PointerTo(nowMillis-500)), now: now, expectedSec: nowSeconds, expectedMillis: nowMillis, @@ -290,28 +290,28 @@ func TestGetNextTimestamp(t *testing.T) { }, { name: "current_time_before_parent_time_with_milliseconds", - parent: generateHeader(nowSeconds+10, utils.NewUint64(nowMillis)), + parent: generateHeader(nowSeconds+10, utils.PointerTo(nowMillis)), now: now, expectedSec: nowSeconds, expectedMillis: nowMillis, }, { name: "current_time_milliseconds_before_parent_time_milliseconds", - parent: generateHeader(nowSeconds, utils.NewUint64(nowMillis+10)), + parent: generateHeader(nowSeconds, utils.PointerTo(nowMillis+10)), now: now, expectedSec: nowSeconds, expectedMillis: nowMillis, }, { name: "current_time_equals_parent_time_with_milliseconds_granite", - parent: generateHeader(nowSeconds, utils.NewUint64(nowMillis)), + parent: generateHeader(nowSeconds, utils.PointerTo(nowMillis)), now: now, expectedSec: nowSeconds, expectedMillis: nowMillis, }, { name: "current_timesec_equals_parent_time_with_less_milliseconds", - parent: generateHeader(nowSeconds, utils.NewUint64(nowMillis-10)), + parent: generateHeader(nowSeconds, utils.PointerTo(nowMillis-10)), now: now, expectedSec: nowSeconds, expectedMillis: nowMillis, diff --git a/graft/coreth/plugin/evm/customtypes/block_ext_test.go b/graft/coreth/plugin/evm/customtypes/block_ext_test.go index a1af7c7cc18f..6ee0afbd4dda 100644 --- a/graft/coreth/plugin/evm/customtypes/block_ext_test.go +++ b/graft/coreth/plugin/evm/customtypes/block_ext_test.go @@ -16,8 +16,7 @@ import ( "github.com/google/go-cmp/cmp/cmpopts" "github.com/stretchr/testify/require" - "github.com/ava-labs/avalanchego/graft/evm/utils" - "github.com/ava-labs/avalanchego/graft/evm/utils/utilstest" + "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/vms/evm/acp226" ) @@ -325,8 +324,8 @@ func TestBlockGetters(t *testing.T) { headerExtra: &HeaderExtra{ ExtDataGasUsed: big.NewInt(1), BlockGasCost: big.NewInt(2), - TimeMilliseconds: utils.NewUint64(3), - MinDelayExcess: utilstest.PointerTo(acp226.DelayExcess(4)), + TimeMilliseconds: utils.PointerTo[uint64](3), + MinDelayExcess: utils.PointerTo(acp226.DelayExcess(4)), }, blockExtra: &BlockBodyExtra{ Version: 3, @@ -336,8 +335,8 @@ func TestBlockGetters(t *testing.T) { wantBlockGasCost: big.NewInt(2), wantVersion: 3, wantExtData: []byte{4}, - wantTimeMilliseconds: utils.NewUint64(3), - wantMinDelayExcess: utilstest.PointerTo(acp226.DelayExcess(4)), + wantTimeMilliseconds: utils.PointerTo[uint64](3), + wantMinDelayExcess: utils.PointerTo(acp226.DelayExcess(4)), }, } diff --git a/graft/coreth/plugin/evm/customtypes/header_ext_test.go b/graft/coreth/plugin/evm/customtypes/header_ext_test.go index 3d67bbbbe29c..c61fce4f1bd9 100644 --- a/graft/coreth/plugin/evm/customtypes/header_ext_test.go +++ b/graft/coreth/plugin/evm/customtypes/header_ext_test.go @@ -16,7 +16,7 @@ import ( "github.com/ava-labs/libevm/rlp" "github.com/stretchr/testify/require" - "github.com/ava-labs/avalanchego/graft/evm/utils/utilstest" + "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/vms/evm/acp226" ) @@ -106,16 +106,16 @@ func headerWithNonZeroFields() (*Header, *HeaderExtra) { Nonce: BlockNonce{15}, BaseFee: big.NewInt(16), WithdrawalsHash: &common.Hash{17}, - BlobGasUsed: utilstest.PointerTo(uint64(18)), - ExcessBlobGas: utilstest.PointerTo(uint64(19)), + BlobGasUsed: utils.PointerTo[uint64](18), + ExcessBlobGas: utils.PointerTo[uint64](19), ParentBeaconRoot: &common.Hash{20}, } extra := &HeaderExtra{ ExtDataHash: common.Hash{21}, ExtDataGasUsed: big.NewInt(22), BlockGasCost: big.NewInt(23), - TimeMilliseconds: utilstest.PointerTo(uint64(24)), - MinDelayExcess: utilstest.PointerTo(acp226.DelayExcess(25)), + TimeMilliseconds: utils.PointerTo[uint64](24), + MinDelayExcess: utils.PointerTo(acp226.DelayExcess(25)), } return WithHeaderExtra(header, extra), extra } diff --git a/graft/coreth/plugin/evm/vm_test.go b/graft/coreth/plugin/evm/vm_test.go index d432ea83bba9..b9d208ca36de 100644 --- a/graft/coreth/plugin/evm/vm_test.go +++ b/graft/coreth/plugin/evm/vm_test.go @@ -45,12 +45,11 @@ import ( "github.com/ava-labs/avalanchego/graft/coreth/plugin/evm/vmtest" "github.com/ava-labs/avalanchego/graft/coreth/rpc" "github.com/ava-labs/avalanchego/graft/evm/constants" - "github.com/ava-labs/avalanchego/graft/evm/utils" - "github.com/ava-labs/avalanchego/graft/evm/utils/utilstest" "github.com/ava-labs/avalanchego/ids" "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" "github.com/ava-labs/avalanchego/utils/set" "github.com/ava-labs/avalanchego/utils/timer/mockable" "github.com/ava-labs/avalanchego/vms/components/chain" @@ -82,8 +81,8 @@ var ( activateCancun = func(cfg *params.ChainConfig) *params.ChainConfig { cpy := *cfg - cpy.ShanghaiTime = utils.NewUint64(0) - cpy.CancunTime = utils.NewUint64(0) + cpy.ShanghaiTime = utils.PointerTo[uint64](0) + cpy.CancunTime = utils.PointerTo[uint64](0) return &cpy } ) @@ -1014,13 +1013,13 @@ func TestTimeSemanticVerify(t *testing.T) { name: "Granite with TimeMilliseconds", fork: upgradetest.Granite, timeSeconds: uint64(timestamp.Unix()), - timeMilliseconds: utils.NewUint64(uint64(timestamp.UnixMilli())), + timeMilliseconds: utils.PointerTo(uint64(timestamp.UnixMilli())), }, { name: "Fortuna with TimeMilliseconds", fork: upgradetest.Fortuna, timeSeconds: uint64(timestamp.Unix()), - timeMilliseconds: utils.NewUint64(uint64(timestamp.UnixMilli())), + timeMilliseconds: utils.PointerTo(uint64(timestamp.UnixMilli())), expectedError: customheader.ErrTimeMillisecondsBeforeGranite, }, { @@ -1034,14 +1033,14 @@ func TestTimeSemanticVerify(t *testing.T) { name: "Granite with mismatched TimeMilliseconds", fork: upgradetest.Granite, timeSeconds: uint64(timestamp.Unix()), - timeMilliseconds: utils.NewUint64(uint64(timestamp.UnixMilli()) + 1000), + timeMilliseconds: utils.PointerTo(uint64(timestamp.UnixMilli()) + 1000), expectedError: customheader.ErrTimeMillisecondsMismatched, }, { name: "Block too far in the future", fork: upgradetest.Granite, timeSeconds: uint64(timestamp.Add(2 * time.Hour).Unix()), - timeMilliseconds: utils.NewUint64(uint64(timestamp.Add(2 * time.Hour).UnixMilli())), + timeMilliseconds: utils.PointerTo(uint64(timestamp.Add(2 * time.Hour).UnixMilli())), expectedError: customheader.ErrBlockTooFarInFuture, }, } @@ -1106,7 +1105,7 @@ func TestBuildTimeMilliseconds(t *testing.T) { { name: "granite_should_have_timestamp_milliseconds", fork: upgradetest.Granite, - expectedTimeMilliseconds: utils.NewUint64(uint64(buildTime.UnixMilli())), + expectedTimeMilliseconds: utils.PointerTo(uint64(buildTime.UnixMilli())), }, } @@ -2146,26 +2145,26 @@ func TestMinDelayExcessInHeader(t *testing.T) { { name: "pre_granite_min_delay_excess", fork: upgradetest.Fortuna, - desiredMinDelay: utils.NewUint64(1000), + desiredMinDelay: utils.PointerTo[uint64](1000), expectedMinDelayExcess: nil, }, { name: "granite_first_block_initial_delay_excess", fork: upgradetest.Granite, desiredMinDelay: nil, - expectedMinDelayExcess: utilstest.PointerTo(acp226.DelayExcess(acp226.InitialDelayExcess)), + expectedMinDelayExcess: utils.PointerTo(acp226.DelayExcess(acp226.InitialDelayExcess)), }, { name: "granite_with_excessive_desired_min_delay_excess", fork: upgradetest.Granite, - desiredMinDelay: utils.NewUint64(4000), - expectedMinDelayExcess: utilstest.PointerTo(acp226.DelayExcess(acp226.InitialDelayExcess + acp226.MaxDelayExcessDiff)), + desiredMinDelay: utils.PointerTo[uint64](4000), + expectedMinDelayExcess: utils.PointerTo(acp226.DelayExcess(acp226.InitialDelayExcess + acp226.MaxDelayExcessDiff)), }, { name: "granite_with_zero_desired_min_delay_excess", fork: upgradetest.Granite, - desiredMinDelay: utils.NewUint64(0), - expectedMinDelayExcess: utilstest.PointerTo(acp226.DelayExcess(acp226.InitialDelayExcess - acp226.MaxDelayExcessDiff)), + desiredMinDelay: utils.PointerTo[uint64](0), + expectedMinDelayExcess: utils.PointerTo(acp226.DelayExcess(acp226.InitialDelayExcess - acp226.MaxDelayExcessDiff)), }, } diff --git a/graft/coreth/precompile/contracts/warp/config_test.go b/graft/coreth/precompile/contracts/warp/config_test.go index 094d11645ee7..e8a8cfe4a0f7 100644 --- a/graft/coreth/precompile/contracts/warp/config_test.go +++ b/graft/coreth/precompile/contracts/warp/config_test.go @@ -10,30 +10,30 @@ import ( "github.com/ava-labs/avalanchego/graft/coreth/precompile/precompileconfig" "github.com/ava-labs/avalanchego/graft/coreth/precompile/precompiletest" - "github.com/ava-labs/avalanchego/graft/evm/utils" + "github.com/ava-labs/avalanchego/utils" ) func TestVerify(t *testing.T) { tests := map[string]precompiletest.ConfigVerifyTest{ "quorum numerator less than minimum": { - Config: NewConfig(utils.NewUint64(3), WarpQuorumNumeratorMinimum-1, false), + Config: NewConfig(utils.PointerTo[uint64](3), WarpQuorumNumeratorMinimum-1, false), ExpectedError: ErrInvalidQuorumRatio, }, "quorum numerator greater than quorum denominator": { - Config: NewConfig(utils.NewUint64(3), WarpQuorumDenominator+1, false), + Config: NewConfig(utils.PointerTo[uint64](3), WarpQuorumDenominator+1, false), ExpectedError: ErrInvalidQuorumRatio, }, "default quorum numerator": { - Config: NewDefaultConfig(utils.NewUint64(3)), + Config: NewDefaultConfig(utils.PointerTo[uint64](3)), }, "valid quorum numerator 1 less than denominator": { - Config: NewConfig(utils.NewUint64(3), WarpQuorumDenominator-1, false), + Config: NewConfig(utils.PointerTo[uint64](3), WarpQuorumDenominator-1, false), }, "valid quorum numerator 1 more than minimum": { - Config: NewConfig(utils.NewUint64(3), WarpQuorumNumeratorMinimum+1, false), + Config: NewConfig(utils.PointerTo[uint64](3), WarpQuorumNumeratorMinimum+1, false), }, "invalid cannot activated before Durango activation": { - Config: NewConfig(utils.NewUint64(3), 0, false), + Config: NewConfig(utils.PointerTo[uint64](3), 0, false), ChainConfig: func() precompileconfig.ChainConfig { config := precompileconfig.NewMockChainConfig(gomock.NewController(t)) config.EXPECT().IsDurango(gomock.Any()).Return(false) @@ -48,38 +48,38 @@ func TestVerify(t *testing.T) { func TestEqualWarpConfig(t *testing.T) { tests := map[string]precompiletest.ConfigEqualTest{ "non-nil config and nil other": { - Config: NewDefaultConfig(utils.NewUint64(3)), + Config: NewDefaultConfig(utils.PointerTo[uint64](3)), Other: nil, Expected: false, }, "different type": { - Config: NewDefaultConfig(utils.NewUint64(3)), + Config: NewDefaultConfig(utils.PointerTo[uint64](3)), Other: precompileconfig.NewMockConfig(gomock.NewController(t)), Expected: false, }, "different timestamp": { - Config: NewDefaultConfig(utils.NewUint64(3)), - Other: NewDefaultConfig(utils.NewUint64(4)), + Config: NewDefaultConfig(utils.PointerTo[uint64](3)), + Other: NewDefaultConfig(utils.PointerTo[uint64](4)), Expected: false, }, "different quorum numerator": { - Config: NewConfig(utils.NewUint64(3), WarpQuorumNumeratorMinimum+1, false), - Other: NewConfig(utils.NewUint64(3), WarpQuorumNumeratorMinimum+2, false), + Config: NewConfig(utils.PointerTo[uint64](3), WarpQuorumNumeratorMinimum+1, false), + Other: NewConfig(utils.PointerTo[uint64](3), WarpQuorumNumeratorMinimum+2, false), Expected: false, }, "same default config": { - Config: NewDefaultConfig(utils.NewUint64(3)), - Other: NewDefaultConfig(utils.NewUint64(3)), + Config: NewDefaultConfig(utils.PointerTo[uint64](3)), + Other: NewDefaultConfig(utils.PointerTo[uint64](3)), Expected: true, }, "same non-default config": { - Config: NewConfig(utils.NewUint64(3), WarpQuorumNumeratorMinimum+5, false), - Other: NewConfig(utils.NewUint64(3), WarpQuorumNumeratorMinimum+5, false), + Config: NewConfig(utils.PointerTo[uint64](3), WarpQuorumNumeratorMinimum+5, false), + Other: NewConfig(utils.PointerTo[uint64](3), WarpQuorumNumeratorMinimum+5, false), Expected: true, }, } diff --git a/graft/coreth/precompile/contracts/warp/predicate_test.go b/graft/coreth/precompile/contracts/warp/predicate_test.go index 80c52f3aaaa4..20cc68e78042 100644 --- a/graft/coreth/precompile/contracts/warp/predicate_test.go +++ b/graft/coreth/precompile/contracts/warp/predicate_test.go @@ -16,7 +16,6 @@ import ( "github.com/ava-labs/avalanchego/graft/coreth/params/extras/extrastest" "github.com/ava-labs/avalanchego/graft/coreth/precompile/precompileconfig" "github.com/ava-labs/avalanchego/graft/coreth/precompile/precompiletest" - "github.com/ava-labs/avalanchego/graft/evm/utils" "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/snow" "github.com/ava-labs/avalanchego/snow/engine/snowman/block" @@ -24,6 +23,7 @@ import ( "github.com/ava-labs/avalanchego/snow/validators" "github.com/ava-labs/avalanchego/snow/validators/validatorstest" "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/bls" "github.com/ava-labs/avalanchego/utils/crypto/bls/signer/localsigner" @@ -31,13 +31,12 @@ import ( "github.com/ava-labs/avalanchego/vms/evm/predicate" "github.com/ava-labs/avalanchego/vms/platformvm/warp/payload" - agoUtils "github.com/ava-labs/avalanchego/utils" safemath "github.com/ava-labs/avalanchego/utils/math" avalancheWarp "github.com/ava-labs/avalanchego/vms/platformvm/warp" ) var ( - _ agoUtils.Sortable[*testValidator] = (*testValidator)(nil) + _ utils.Sortable[*testValidator] = (*testValidator)(nil) sourceChainID = ids.GenerateTestID() sourceSubnetID = ids.GenerateTestID() @@ -62,7 +61,7 @@ func init() { for i := 0; i < numTestVdrs; i++ { testVdrs = append(testVdrs, newTestValidator()) } - agoUtils.Sort(testVdrs) + utils.Sort(testVdrs) vdrs = map[ids.NodeID]*validators.GetValidatorOutput{ testVdrs[0].nodeID: { @@ -244,7 +243,7 @@ func createValidPredicateTest( ) precompiletest.PredicateTest { gasCost := CurrentGasConfig(rules) return precompiletest.PredicateTest{ - Config: NewDefaultConfig(utils.NewUint64(0)), + Config: NewDefaultConfig(utils.PointerTo[uint64](0)), PredicateContext: &precompileconfig.PredicateContext{ SnowCtx: snowCtx, ProposerVMBlockCtx: &block.Context{ @@ -269,7 +268,7 @@ func testWarpMessageFromPrimaryNetwork(t *testing.T, requirePrimaryNetworkSigner require := require.New(t) numKeys := 10 cChainID := ids.GenerateTestID() - addressedCall, err := payload.NewAddressedCall(agoUtils.RandomBytes(20), agoUtils.RandomBytes(100)) + addressedCall, err := payload.NewAddressedCall(utils.RandomBytes(20), utils.RandomBytes(100)) require.NoError(err) unsignedMsg, err := avalancheWarp.NewUnsignedMessage(constants.UnitTestID, cChainID, addressedCall.Bytes()) require.NoError(err) @@ -295,7 +294,7 @@ func testWarpMessageFromPrimaryNetwork(t *testing.T, requirePrimaryNetworkSigner NodeIDs: []ids.NodeID{vdr.nodeID}, }) } - agoUtils.Sort(warpValidators.Validators) + utils.Sort(warpValidators.Validators) aggregateSignature, err := bls.AggregateSignatures(blsSignatures) require.NoError(err) @@ -331,7 +330,7 @@ func testWarpMessageFromPrimaryNetwork(t *testing.T, requirePrimaryNetworkSigner } test := precompiletest.PredicateTest{ - Config: NewConfig(utils.NewUint64(0), 0, requirePrimaryNetworkSigners), + Config: NewConfig(utils.PointerTo[uint64](0), 0, requirePrimaryNetworkSigners), PredicateContext: &precompileconfig.PredicateContext{ SnowCtx: snowCtx, ProposerVMBlockCtx: &block.Context{ @@ -362,7 +361,7 @@ func TestInvalidPredicatePacking(t *testing.T) { pred = append(pred, common.Hash{1}) // Invalidate the predicate byte packing test := precompiletest.PredicateTest{ - Config: NewDefaultConfig(utils.NewUint64(0)), + Config: NewDefaultConfig(utils.PointerTo[uint64](0)), PredicateContext: &precompileconfig.PredicateContext{ SnowCtx: snowCtx, ProposerVMBlockCtx: &block.Context{ @@ -394,7 +393,7 @@ func TestInvalidWarpMessage(t *testing.T) { pred := predicate.New(warpMsgBytes) test := precompiletest.PredicateTest{ - Config: NewDefaultConfig(utils.NewUint64(0)), + Config: NewDefaultConfig(utils.PointerTo[uint64](0)), PredicateContext: &precompileconfig.PredicateContext{ SnowCtx: snowCtx, ProposerVMBlockCtx: &block.Context{ @@ -439,7 +438,7 @@ func TestInvalidAddressedPayload(t *testing.T) { pred := predicate.New(warpMsgBytes) test := precompiletest.PredicateTest{ - Config: NewDefaultConfig(utils.NewUint64(0)), + Config: NewDefaultConfig(utils.PointerTo[uint64](0)), PredicateContext: &precompileconfig.PredicateContext{ SnowCtx: snowCtx, ProposerVMBlockCtx: &block.Context{ @@ -456,7 +455,7 @@ func TestInvalidAddressedPayload(t *testing.T) { } func TestInvalidBitSet(t *testing.T) { - addressedCall, err := payload.NewAddressedCall(agoUtils.RandomBytes(20), agoUtils.RandomBytes(100)) + addressedCall, err := payload.NewAddressedCall(utils.RandomBytes(20), utils.RandomBytes(100)) require.NoError(t, err) unsignedMsg, err := avalancheWarp.NewUnsignedMessage( constants.UnitTestID, @@ -485,7 +484,7 @@ func TestInvalidBitSet(t *testing.T) { }) pred := predicate.New(msg.Bytes()) test := precompiletest.PredicateTest{ - Config: NewDefaultConfig(utils.NewUint64(0)), + Config: NewDefaultConfig(utils.PointerTo[uint64](0)), PredicateContext: &precompileconfig.PredicateContext{ SnowCtx: snowCtx, ProposerVMBlockCtx: &block.Context{ @@ -533,7 +532,7 @@ func TestWarpSignatureWeightsDefaultQuorumNumerator(t *testing.T) { tests[i] = precompiletest.PredicateTest{ Name: fmt.Sprintf("default quorum %d signature(s)", numSigners), - Config: NewDefaultConfig(utils.NewUint64(0)), + Config: NewDefaultConfig(utils.PointerTo[uint64](0)), PredicateContext: &precompileconfig.PredicateContext{ SnowCtx: snowCtx, ProposerVMBlockCtx: &block.Context{ @@ -593,7 +592,7 @@ func TestWarpMultiplePredicates(t *testing.T) { tests = append(tests, precompiletest.PredicateTest{ Name: fmt.Sprintf("multiple predicates %v", validMessageIndices), - Config: NewDefaultConfig(utils.NewUint64(0)), + Config: NewDefaultConfig(utils.PointerTo[uint64](0)), PredicateContext: &precompileconfig.PredicateContext{ SnowCtx: snowCtx, ProposerVMBlockCtx: &block.Context{ @@ -645,7 +644,7 @@ func TestWarpSignatureWeightsNonDefaultQuorumNumerator(t *testing.T) { tests[i] = precompiletest.PredicateTest{ Name: fmt.Sprintf("non-default quorum %d signature(s)", numSigners), - Config: NewConfig(utils.NewUint64(0), uint64(nonDefaultQuorumNumerator), false), + Config: NewConfig(utils.PointerTo[uint64](0), uint64(nonDefaultQuorumNumerator), false), PredicateContext: &precompileconfig.PredicateContext{ SnowCtx: snowCtx, ProposerVMBlockCtx: &block.Context{ @@ -665,7 +664,7 @@ func TestWarpSignatureWeightsNonDefaultQuorumNumerator(t *testing.T) { func TestWarpNoValidatorsAndOverflowUseSameGas(t *testing.T) { var ( - config = NewConfig(utils.NewUint64(0), 0, false) + config = NewConfig(utils.PointerTo[uint64](0), 0, false) proposervmContext = &block.Context{ PChainHeight: 1, } diff --git a/graft/evm/utils/numbers.go b/graft/evm/utils/numbers.go index 9ec110bb8742..60cc55e406a7 100644 --- a/graft/evm/utils/numbers.go +++ b/graft/evm/utils/numbers.go @@ -6,13 +6,12 @@ package utils import ( "math/big" "time" -) -func NewUint64(val uint64) *uint64 { return &val } + "github.com/ava-labs/avalanchego/utils" +) func TimeToNewUint64(time time.Time) *uint64 { - unix := uint64(time.Unix()) - return NewUint64(unix) + return utils.PointerTo(uint64(time.Unix())) } func Uint64ToTime(val *uint64) time.Time { diff --git a/graft/evm/utils/utilstest/pointer.go b/graft/evm/utils/utilstest/pointer.go deleted file mode 100644 index e24106465b61..000000000000 --- a/graft/evm/utils/utilstest/pointer.go +++ /dev/null @@ -1,6 +0,0 @@ -// Copyright (C) 2019, Ava Labs, Inc. All rights reserved. -// See the file LICENSE for licensing terms. - -package utilstest - -func PointerTo[T any](x T) *T { return &x } diff --git a/graft/subnet-evm/accounts/abi/bind/precompilebind/precompile_bind_test.go b/graft/subnet-evm/accounts/abi/bind/precompilebind/precompile_bind_test.go index f12d9f950248..c33953a61a4b 100644 --- a/graft/subnet-evm/accounts/abi/bind/precompilebind/precompile_bind_test.go +++ b/graft/subnet-evm/accounts/abi/bind/precompilebind/precompile_bind_test.go @@ -694,6 +694,11 @@ func TestPrecompileBind(t *testing.T) { out, err = replacer.CombinedOutput() require.NoError(t, err, "failed to replace binding test dependency to current source tree: %v\n%s", err, out) + replacer = exec.Command(gocmd, "mod", "edit", "-x", "-require", "github.com/ava-labs/avalanchego@v0.0.0", "-replace", "github.com/ava-labs/avalanchego="+filepath.Join(pwd, "..", "..", "..", "..", "..", "..")) + replacer.Dir = pkg + out, err = replacer.CombinedOutput() + require.NoError(t, err, "failed to replace binding test dependency to current source tree: %v\n%s", err, out) + tidier := exec.Command(gocmd, "mod", "tidy", "-compat=1.24") tidier.Dir = pkg out, err = tidier.CombinedOutput() diff --git a/graft/subnet-evm/accounts/abi/bind/precompilebind/templatetest/precompile_config_test_template.go b/graft/subnet-evm/accounts/abi/bind/precompilebind/templatetest/precompile_config_test_template.go index 08b04f3947af..e6d2b555ebad 100644 --- a/graft/subnet-evm/accounts/abi/bind/precompilebind/templatetest/precompile_config_test_template.go +++ b/graft/subnet-evm/accounts/abi/bind/precompilebind/templatetest/precompile_config_test_template.go @@ -16,7 +16,8 @@ import ( "github.com/ava-labs/avalanchego/graft/subnet-evm/precompile/precompileconfig" "github.com/ava-labs/avalanchego/graft/subnet-evm/precompile/precompiletest" - "github.com/ava-labs/avalanchego/graft/evm/utils" + + "github.com/ava-labs/avalanchego/utils" {{- if .Contract.AllowList}} "github.com/ava-labs/avalanchego/graft/subnet-evm/precompile/allowlist/allowlisttest" @@ -34,7 +35,7 @@ func TestVerify(t *testing.T) { {{- end}} tests := map[string]precompiletest.ConfigVerifyTest{ "valid config": { - Config: NewConfig(utils.NewUint64(3){{- if .Contract.AllowList}}, admins, enableds, managers{{- end}}), + Config: NewConfig(utils.PointerTo[uint64](3){{- if .Contract.AllowList}}, admins, enableds, managers{{- end}}), ChainConfig: func() precompileconfig.ChainConfig { config := precompileconfig.NewMockChainConfig(gomock.NewController(t)) config.EXPECT().IsDurango(gomock.Any()).Return(true).AnyTimes() @@ -45,7 +46,7 @@ func TestVerify(t *testing.T) { // CUSTOM CODE STARTS HERE // Add your own Verify tests here, e.g.: // "your custom test name": { - // Config: NewConfig(utils.NewUint64(3), {{- if .Contract.AllowList}} admins, enableds, managers{{- end}}), + // Config: NewConfig(utils.PointerTo[uint64](3), {{- if .Contract.AllowList}} admins, enableds, managers{{- end}}), // ExpectedError: ErrYourCustomError, // }, } @@ -71,23 +72,23 @@ func TestEqual(t *testing.T) { {{- end}} tests := map[string]precompiletest.ConfigEqualTest{ "non-nil config and nil other": { - Config: NewConfig(utils.NewUint64(3){{- if .Contract.AllowList}}, admins, enableds,managers{{- end}}), + Config: NewConfig(utils.PointerTo[uint64](3){{- if .Contract.AllowList}}, admins, enableds, managers{{- end}}), Other: nil, Expected: false, }, "different type": { - Config: NewConfig(utils.NewUint64(3){{- if .Contract.AllowList}}, admins, enableds, managers{{- end}}), + Config: NewConfig(utils.PointerTo[uint64](3){{- if .Contract.AllowList}}, admins, enableds, managers{{- end}}), Other: precompileconfig.NewMockConfig(gomock.NewController(t)), Expected: false, }, "different timestamp": { - Config: NewConfig(utils.NewUint64(3){{- if .Contract.AllowList}}, admins, enableds, managers{{- end}}), - Other: NewConfig(utils.NewUint64(4){{- if .Contract.AllowList}}, admins, enableds, managers{{- end}}), + Config: NewConfig(utils.PointerTo[uint64](3){{- if .Contract.AllowList}}, admins, enableds, managers{{- end}}), + Other: NewConfig(utils.PointerTo[uint64](4){{- if .Contract.AllowList}}, admins, enableds, managers{{- end}}), Expected: false, }, "same config": { - Config: NewConfig(utils.NewUint64(3){{- if .Contract.AllowList}}, admins, enableds, managers{{- end}}), - Other: NewConfig(utils.NewUint64(3){{- if .Contract.AllowList}}, admins, enableds, managers{{- end}}), + Config: NewConfig(utils.PointerTo[uint64](3){{- if .Contract.AllowList}}, admins, enableds, managers{{- end}}), + Other: NewConfig(utils.PointerTo[uint64](3){{- if .Contract.AllowList}}, admins, enableds, managers{{- end}}), Expected: true, }, // CUSTOM CODE STARTS HERE diff --git a/graft/subnet-evm/core/blockchain_ext_test.go b/graft/subnet-evm/core/blockchain_ext_test.go index 1d25811da232..714dd0be1da4 100644 --- a/graft/subnet-evm/core/blockchain_ext_test.go +++ b/graft/subnet-evm/core/blockchain_ext_test.go @@ -20,7 +20,6 @@ import ( "github.com/holiman/uint256" "github.com/stretchr/testify/require" - "github.com/ava-labs/avalanchego/graft/evm/utils" "github.com/ava-labs/avalanchego/graft/subnet-evm/commontype" "github.com/ava-labs/avalanchego/graft/subnet-evm/consensus/dummy" "github.com/ava-labs/avalanchego/graft/subnet-evm/params" @@ -29,6 +28,7 @@ import ( "github.com/ava-labs/avalanchego/graft/subnet-evm/precompile/allowlist" "github.com/ava-labs/avalanchego/graft/subnet-evm/precompile/contracts/deployerallowlist" "github.com/ava-labs/avalanchego/graft/subnet-evm/precompile/contracts/feemanager" + "github.com/ava-labs/avalanchego/utils" ethparams "github.com/ava-labs/libevm/params" ) @@ -1405,8 +1405,8 @@ func StatefulPrecompiles(t *testing.T, create createFunc) { config := params.Copy(params.TestChainConfig) // Set all of the required config parameters params.GetExtra(&config).GenesisPrecompiles = extras.Precompiles{ - deployerallowlist.ConfigKey: deployerallowlist.NewConfig(utils.NewUint64(0), []common.Address{addr1}, nil, nil), - feemanager.ConfigKey: feemanager.NewConfig(utils.NewUint64(0), []common.Address{addr1}, nil, nil, nil), + deployerallowlist.ConfigKey: deployerallowlist.NewConfig(utils.PointerTo[uint64](0), []common.Address{addr1}, nil, nil), + feemanager.ConfigKey: feemanager.NewConfig(utils.PointerTo[uint64](0), []common.Address{addr1}, nil, nil, nil), } gspec := &Genesis{ Config: &config, diff --git a/graft/subnet-evm/core/genesis_extra_test.go b/graft/subnet-evm/core/genesis_extra_test.go index 11db8e6cc8dc..f7a5b38b0b0c 100644 --- a/graft/subnet-evm/core/genesis_extra_test.go +++ b/graft/subnet-evm/core/genesis_extra_test.go @@ -14,12 +14,12 @@ import ( "github.com/ava-labs/libevm/triedb" "github.com/stretchr/testify/require" - "github.com/ava-labs/avalanchego/graft/evm/utils" "github.com/ava-labs/avalanchego/graft/subnet-evm/commontype" "github.com/ava-labs/avalanchego/graft/subnet-evm/params" "github.com/ava-labs/avalanchego/graft/subnet-evm/params/extras" "github.com/ava-labs/avalanchego/graft/subnet-evm/params/paramstest" "github.com/ava-labs/avalanchego/upgrade/upgradetest" + "github.com/ava-labs/avalanchego/utils" ) func TestGenesisEthUpgrades(t *testing.T) { @@ -49,7 +49,7 @@ func TestGenesisEthUpgrades(t *testing.T) { MinBaseFee: big.NewInt(1), }, NetworkUpgrades: extras.NetworkUpgrades{ - SubnetEVMTimestamp: utils.NewUint64(0), + SubnetEVMTimestamp: utils.PointerTo[uint64](0), }, }, ) diff --git a/graft/subnet-evm/core/genesis_test.go b/graft/subnet-evm/core/genesis_test.go index 0764356984b0..c84969df8ab4 100644 --- a/graft/subnet-evm/core/genesis_test.go +++ b/graft/subnet-evm/core/genesis_test.go @@ -36,7 +36,6 @@ import ( "testing" "github.com/ava-labs/avalanchego/graft/evm/firewood" - "github.com/ava-labs/avalanchego/graft/evm/utils" "github.com/ava-labs/avalanchego/graft/subnet-evm/consensus/dummy" "github.com/ava-labs/avalanchego/graft/subnet-evm/params" "github.com/ava-labs/avalanchego/graft/subnet-evm/params/extras" @@ -44,6 +43,7 @@ import ( "github.com/ava-labs/avalanchego/graft/subnet-evm/precompile/allowlist" "github.com/ava-labs/avalanchego/graft/subnet-evm/precompile/contracts/deployerallowlist" "github.com/ava-labs/avalanchego/graft/subnet-evm/triedb/pathdb" + "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/vms/evm/sync/customrawdb" "github.com/ava-labs/libevm/common" "github.com/ava-labs/libevm/core/rawdb" @@ -81,7 +81,7 @@ func TestSetupGenesis(t *testing.T) { func testSetupGenesis(t *testing.T, scheme string) { preSubnetConfig := params.Copy(params.TestPreSubnetEVMChainConfig) - params.GetExtra(&preSubnetConfig).SubnetEVMTimestamp = utils.NewUint64(100) + params.GetExtra(&preSubnetConfig).SubnetEVMTimestamp = utils.PointerTo[uint64](100) var ( customghash = common.HexToHash("0x4a12fe7bf8d40d152d7e9de22337b115186a4662aa3a97217b36146202bbfc66") customg = Genesis{ @@ -95,7 +95,7 @@ func testSetupGenesis(t *testing.T, scheme string) { ) rollbackpreSubnetConfig := params.Copy(&preSubnetConfig) - params.GetExtra(&rollbackpreSubnetConfig).SubnetEVMTimestamp = utils.NewUint64(90) + params.GetExtra(&rollbackpreSubnetConfig).SubnetEVMTimestamp = utils.PointerTo[uint64](90) oldcustomg.Config = &rollbackpreSubnetConfig tests := []struct { @@ -226,7 +226,7 @@ func TestStatefulPrecompilesConfigure(t *testing.T) { getConfig: func() *params.ChainConfig { config := params.Copy(params.TestChainConfig) params.GetExtra(&config).GenesisPrecompiles = extras.Precompiles{ - deployerallowlist.ConfigKey: deployerallowlist.NewConfig(utils.NewUint64(0), []common.Address{addr}, nil, nil), + deployerallowlist.ConfigKey: deployerallowlist.NewConfig(utils.PointerTo[uint64](0), []common.Address{addr}, nil, nil), } return &config }, @@ -300,7 +300,7 @@ func TestPrecompileActivationAfterHeaderBlock(t *testing.T) { require.Greater(block.Time, bc.lastAccepted.Time()) activatedGenesisConfig := params.Copy(customg.Config) - contractDeployerConfig := deployerallowlist.NewConfig(utils.NewUint64(51), nil, nil, nil) + contractDeployerConfig := deployerallowlist.NewConfig(utils.PointerTo[uint64](51), nil, nil, nil) params.GetExtra(&activatedGenesisConfig).UpgradeConfig.PrecompileUpgrades = []extras.PrecompileUpgrade{ { Config: contractDeployerConfig, @@ -341,7 +341,7 @@ func TestGenesisWriteUpgradesRegression(t *testing.T) { params.GetExtra(genesis.Config).UpgradeConfig.PrecompileUpgrades = []extras.PrecompileUpgrade{ { - Config: deployerallowlist.NewConfig(utils.NewUint64(51), nil, nil, nil), + Config: deployerallowlist.NewConfig(utils.PointerTo[uint64](51), nil, nil, nil), }, } _, _, err = SetupGenesisBlock(db, trieDB, genesis, genesisBlock.Hash(), false) diff --git a/graft/subnet-evm/core/state_processor_ext_test.go b/graft/subnet-evm/core/state_processor_ext_test.go index d154a6b4bbb4..d6f8586dc88f 100644 --- a/graft/subnet-evm/core/state_processor_ext_test.go +++ b/graft/subnet-evm/core/state_processor_ext_test.go @@ -14,12 +14,12 @@ import ( "github.com/ava-labs/libevm/crypto" "github.com/stretchr/testify/require" - "github.com/ava-labs/avalanchego/graft/evm/utils" "github.com/ava-labs/avalanchego/graft/subnet-evm/consensus/dummy" "github.com/ava-labs/avalanchego/graft/subnet-evm/params" "github.com/ava-labs/avalanchego/graft/subnet-evm/params/extras" "github.com/ava-labs/avalanchego/graft/subnet-evm/plugin/evm/vmerrors" "github.com/ava-labs/avalanchego/graft/subnet-evm/precompile/contracts/txallowlist" + "github.com/ava-labs/avalanchego/utils" ethparams "github.com/ava-labs/libevm/params" ) @@ -50,10 +50,10 @@ func TestBadTxAllowListBlock(t *testing.T) { &extras.ChainConfig{ FeeConfig: params.DefaultFeeConfig, NetworkUpgrades: extras.NetworkUpgrades{ - SubnetEVMTimestamp: utils.NewUint64(0), + SubnetEVMTimestamp: utils.PointerTo[uint64](0), }, GenesisPrecompiles: extras.Precompiles{ - txallowlist.ConfigKey: txallowlist.NewConfig(utils.NewUint64(0), nil, nil, nil), + txallowlist.ConfigKey: txallowlist.NewConfig(utils.PointerTo[uint64](0), nil, nil, nil), }, }, ) diff --git a/graft/subnet-evm/core/state_processor_test.go b/graft/subnet-evm/core/state_processor_test.go index dc38b6ef46f4..63f68169b605 100644 --- a/graft/subnet-evm/core/state_processor_test.go +++ b/graft/subnet-evm/core/state_processor_test.go @@ -32,7 +32,6 @@ import ( "math/big" "testing" - "github.com/ava-labs/avalanchego/graft/evm/utils" "github.com/ava-labs/avalanchego/graft/subnet-evm/consensus" "github.com/ava-labs/avalanchego/graft/subnet-evm/consensus/dummy" "github.com/ava-labs/avalanchego/graft/subnet-evm/params" @@ -41,6 +40,7 @@ import ( "github.com/ava-labs/avalanchego/graft/subnet-evm/plugin/evm/customtypes" "github.com/ava-labs/avalanchego/graft/subnet-evm/plugin/evm/upgrade/legacy" "github.com/ava-labs/avalanchego/upgrade" + "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/libevm/common" "github.com/ava-labs/libevm/consensus/misc/eip4844" "github.com/ava-labs/libevm/core/rawdb" @@ -385,7 +385,7 @@ func GenerateBadBlock(parent *types.Block, engine consensus.Engine, txs types.Tr } if configExtra.IsGranite(header.Time) { headerExtra := customtypes.GetHeaderExtra(header) - headerExtra.TimeMilliseconds = utils.NewUint64(timeMS) + headerExtra.TimeMilliseconds = utils.PointerTo(timeMS) } if params.GetExtra(config).IsSubnetEVM(header.Time) { diff --git a/graft/subnet-evm/internal/ethapi/api_test.go b/graft/subnet-evm/internal/ethapi/api_test.go index 4a83016e4f93..27385bf86d54 100644 --- a/graft/subnet-evm/internal/ethapi/api_test.go +++ b/graft/subnet-evm/internal/ethapi/api_test.go @@ -42,7 +42,6 @@ import ( "testing" "time" - "github.com/ava-labs/avalanchego/graft/evm/utils" "github.com/ava-labs/avalanchego/graft/subnet-evm/commontype" "github.com/ava-labs/avalanchego/graft/subnet-evm/consensus" "github.com/ava-labs/avalanchego/graft/subnet-evm/consensus/dummy" @@ -52,6 +51,7 @@ import ( "github.com/ava-labs/avalanchego/graft/subnet-evm/plugin/evm/upgrade/legacy" "github.com/ava-labs/avalanchego/graft/subnet-evm/rpc" "github.com/ava-labs/avalanchego/upgrade" + "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/libevm/accounts" "github.com/ava-labs/libevm/accounts/keystore" "github.com/ava-labs/libevm/common" @@ -800,8 +800,8 @@ func TestEstimateGas(t *testing.T) { func TestCall(t *testing.T) { // Enable BLOBHASH opcode in Cancun cfg := *params.TestChainConfig - cfg.ShanghaiTime = utils.NewUint64(0) - cfg.CancunTime = utils.NewUint64(0) + cfg.ShanghaiTime = utils.PointerTo[uint64](0) + cfg.CancunTime = utils.PointerTo[uint64](0) t.Parallel() // Initialize test accounts var ( diff --git a/graft/subnet-evm/params/config.go b/graft/subnet-evm/params/config.go index e5a6a2824397..641811bb66dd 100644 --- a/graft/subnet-evm/params/config.go +++ b/graft/subnet-evm/params/config.go @@ -30,8 +30,8 @@ package params import ( "math/big" - "github.com/ava-labs/avalanchego/graft/evm/utils" "github.com/ava-labs/avalanchego/graft/subnet-evm/params/extras" + "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/libevm/libevm" ethparams "github.com/ava-labs/libevm/params" ) @@ -97,8 +97,8 @@ func initialiseChainConfigs() { MuirGlacierBlock: big.NewInt(0), BerlinBlock: big.NewInt(0), LondonBlock: big.NewInt(0), - ShanghaiTime: utils.NewUint64(0), - CancunTime: utils.NewUint64(0), + ShanghaiTime: utils.PointerTo[uint64](0), + CancunTime: utils.PointerTo[uint64](0), }, extras.TestChainConfig, ) @@ -153,7 +153,7 @@ func initialiseChainConfigs() { MuirGlacierBlock: big.NewInt(0), BerlinBlock: big.NewInt(0), LondonBlock: big.NewInt(0), - ShanghaiTime: utils.NewUint64(0), + ShanghaiTime: utils.PointerTo[uint64](0), }, extras.TestDurangoChainConfig, ) @@ -172,8 +172,8 @@ func initialiseChainConfigs() { MuirGlacierBlock: big.NewInt(0), BerlinBlock: big.NewInt(0), LondonBlock: big.NewInt(0), - ShanghaiTime: utils.NewUint64(0), - CancunTime: utils.NewUint64(0), + ShanghaiTime: utils.PointerTo[uint64](0), + CancunTime: utils.PointerTo[uint64](0), }, extras.TestEtnaChainConfig, ) @@ -192,8 +192,8 @@ func initialiseChainConfigs() { MuirGlacierBlock: big.NewInt(0), BerlinBlock: big.NewInt(0), LondonBlock: big.NewInt(0), - ShanghaiTime: utils.NewUint64(0), - CancunTime: utils.NewUint64(0), + ShanghaiTime: utils.PointerTo[uint64](0), + CancunTime: utils.PointerTo[uint64](0), }, extras.TestFortunaChainConfig, ) @@ -212,8 +212,8 @@ func initialiseChainConfigs() { MuirGlacierBlock: big.NewInt(0), BerlinBlock: big.NewInt(0), LondonBlock: big.NewInt(0), - ShanghaiTime: utils.NewUint64(0), - CancunTime: utils.NewUint64(0), + ShanghaiTime: utils.PointerTo[uint64](0), + CancunTime: utils.PointerTo[uint64](0), }, extras.TestGraniteChainConfig, ) @@ -232,8 +232,8 @@ func initialiseChainConfigs() { MuirGlacierBlock: big.NewInt(0), BerlinBlock: big.NewInt(0), LondonBlock: big.NewInt(0), - ShanghaiTime: utils.NewUint64(0), - CancunTime: utils.NewUint64(0), + ShanghaiTime: utils.PointerTo[uint64](0), + CancunTime: utils.PointerTo[uint64](0), }, extras.TestHeliconChainConfig, ) diff --git a/graft/subnet-evm/params/config_extra.go b/graft/subnet-evm/params/config_extra.go index 88927c124ec3..0c4ebb08f497 100644 --- a/graft/subnet-evm/params/config_extra.go +++ b/graft/subnet-evm/params/config_extra.go @@ -8,9 +8,9 @@ import ( "errors" "math/big" - "github.com/ava-labs/avalanchego/graft/evm/utils" "github.com/ava-labs/avalanchego/graft/subnet-evm/params/extras" "github.com/ava-labs/avalanchego/upgrade" + "github.com/ava-labs/avalanchego/utils" ) const ( @@ -73,11 +73,11 @@ func SetEthUpgrades(c *ChainConfig) error { extra := GetExtra(c) // We only mark Eth upgrades as enabled if we have marked them as scheduled. if durango := extra.DurangoTimestamp; durango != nil && *durango < unscheduledActivation { - c.ShanghaiTime = utils.NewUint64(*durango) + c.ShanghaiTime = utils.PointerTo(*durango) } if etna := extra.EtnaTimestamp; etna != nil && *etna < unscheduledActivation { - c.CancunTime = utils.NewUint64(*etna) + c.CancunTime = utils.PointerTo(*etna) } return nil } diff --git a/graft/subnet-evm/params/config_extra_test.go b/graft/subnet-evm/params/config_extra_test.go index 2887edefff14..a470a7fe4b7d 100644 --- a/graft/subnet-evm/params/config_extra_test.go +++ b/graft/subnet-evm/params/config_extra_test.go @@ -10,9 +10,9 @@ import ( "github.com/stretchr/testify/require" - "github.com/ava-labs/avalanchego/graft/evm/utils" "github.com/ava-labs/avalanchego/graft/subnet-evm/params/extras" "github.com/ava-labs/avalanchego/upgrade/upgradetest" + "github.com/ava-labs/avalanchego/utils" ) func TestMain(m *testing.M) { @@ -22,7 +22,7 @@ func TestMain(m *testing.M) { func TestSetEthUpgrades(t *testing.T) { genesisBlock := big.NewInt(0) - genesisTimestamp := utils.NewUint64(initiallyActive) + genesisTimestamp := utils.PointerTo(initiallyActive) tests := []struct { fork upgradetest.Fork expected *ChainConfig diff --git a/graft/subnet-evm/params/config_test.go b/graft/subnet-evm/params/config_test.go index 1e2ca555d6fb..0c406fbe748d 100644 --- a/graft/subnet-evm/params/config_test.go +++ b/graft/subnet-evm/params/config_test.go @@ -35,11 +35,11 @@ import ( "testing" "time" - "github.com/ava-labs/avalanchego/graft/evm/utils" "github.com/ava-labs/avalanchego/graft/subnet-evm/params/extras" "github.com/ava-labs/avalanchego/graft/subnet-evm/precompile/contracts/nativeminter" "github.com/ava-labs/avalanchego/graft/subnet-evm/precompile/contracts/rewardmanager" "github.com/ava-labs/avalanchego/graft/subnet-evm/precompile/contracts/txallowlist" + "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/libevm/common" ethparams "github.com/ava-labs/libevm/params" "github.com/stretchr/testify/require" @@ -125,7 +125,7 @@ func TestCheckCompatible(t *testing.T) { headTimestamp: 0, wantErr: ðparams.ConfigCompatError{ What: "SubnetEVM fork block timestamp", - StoredTime: utils.NewUint64(0), + StoredTime: utils.PointerTo[uint64](0), NewTime: GetExtra(TestPreSubnetEVMChainConfig).NetworkUpgrades.SubnetEVMTimestamp, RewindToTime: 0, }, @@ -137,7 +137,7 @@ func TestCheckCompatible(t *testing.T) { headTimestamp: 100, wantErr: ðparams.ConfigCompatError{ What: "SubnetEVM fork block timestamp", - StoredTime: utils.NewUint64(0), + StoredTime: utils.PointerTo[uint64](0), NewTime: GetExtra(TestPreSubnetEVMChainConfig).NetworkUpgrades.SubnetEVMTimestamp, RewindToTime: 0, }, @@ -157,7 +157,7 @@ func TestConfigRules(t *testing.T) { &ChainConfig{}, &extras.ChainConfig{ NetworkUpgrades: extras.NetworkUpgrades{ - SubnetEVMTimestamp: utils.NewUint64(500), + SubnetEVMTimestamp: utils.PointerTo[uint64](500), }, }, ) @@ -180,7 +180,7 @@ func TestConfigUnmarshalJSON(t *testing.T) { require := require.New(t) testRewardManagerConfig := rewardmanager.NewConfig( - utils.NewUint64(1671542573), + utils.PointerTo[uint64](1671542573), []common.Address{common.HexToAddress("0x8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FC")}, nil, nil, @@ -189,7 +189,7 @@ func TestConfigUnmarshalJSON(t *testing.T) { }) testContractNativeMinterConfig := nativeminter.NewConfig( - utils.NewUint64(0), + utils.PointerTo[uint64](0), []common.Address{common.HexToAddress("0x8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FC")}, nil, nil, @@ -249,10 +249,10 @@ func TestActivePrecompiles(t *testing.T) { UpgradeConfig: extras.UpgradeConfig{ PrecompileUpgrades: []extras.PrecompileUpgrade{ { - Config: nativeminter.NewConfig(utils.NewUint64(0), nil, nil, nil, nil), // enable at genesis + Config: nativeminter.NewConfig(utils.PointerTo[uint64](0), nil, nil, nil, nil), // enable at genesis }, { - Config: nativeminter.NewDisableConfig(utils.NewUint64(1)), // disable at timestamp 1 + Config: nativeminter.NewDisableConfig(utils.PointerTo[uint64](1)), // disable at timestamp 1 }, }, }, @@ -285,8 +285,8 @@ func TestChainConfigMarshalWithUpgrades(t *testing.T) { FeeConfig: DefaultFeeConfig, AllowFeeRecipients: false, NetworkUpgrades: extras.NetworkUpgrades{ - SubnetEVMTimestamp: utils.NewUint64(0), - DurangoTimestamp: utils.NewUint64(0), + SubnetEVMTimestamp: utils.PointerTo[uint64](0), + DurangoTimestamp: utils.PointerTo[uint64](0), }, GenesisPrecompiles: extras.Precompiles{}, }, @@ -294,7 +294,7 @@ func TestChainConfigMarshalWithUpgrades(t *testing.T) { UpgradeConfig: extras.UpgradeConfig{ PrecompileUpgrades: []extras.PrecompileUpgrade{ { - Config: txallowlist.NewConfig(utils.NewUint64(100), nil, nil, nil), + Config: txallowlist.NewConfig(utils.PointerTo[uint64](100), nil, nil, nil), }, }, }, diff --git a/graft/subnet-evm/params/extras/config.go b/graft/subnet-evm/params/extras/config.go index adaec43132ad..5209137b2ccb 100644 --- a/graft/subnet-evm/params/extras/config.go +++ b/graft/subnet-evm/params/extras/config.go @@ -10,10 +10,10 @@ import ( "github.com/ava-labs/libevm/common" - "github.com/ava-labs/avalanchego/graft/evm/utils" "github.com/ava-labs/avalanchego/graft/subnet-evm/commontype" "github.com/ava-labs/avalanchego/snow" "github.com/ava-labs/avalanchego/upgrade" + "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/utils/constants" ethparams "github.com/ava-labs/libevm/params" @@ -46,27 +46,27 @@ var ( } TestSubnetEVMChainConfig = copyAndSet(TestPreSubnetEVMChainConfig, func(c *ChainConfig) { - c.NetworkUpgrades.SubnetEVMTimestamp = utils.NewUint64(0) + c.NetworkUpgrades.SubnetEVMTimestamp = utils.PointerTo[uint64](0) }) TestDurangoChainConfig = copyAndSet(TestSubnetEVMChainConfig, func(c *ChainConfig) { - c.NetworkUpgrades.DurangoTimestamp = utils.NewUint64(0) + c.NetworkUpgrades.DurangoTimestamp = utils.PointerTo[uint64](0) }) TestEtnaChainConfig = copyAndSet(TestDurangoChainConfig, func(c *ChainConfig) { - c.NetworkUpgrades.EtnaTimestamp = utils.NewUint64(0) + c.NetworkUpgrades.EtnaTimestamp = utils.PointerTo[uint64](0) }) TestFortunaChainConfig = copyAndSet(TestEtnaChainConfig, func(c *ChainConfig) { - c.NetworkUpgrades.FortunaTimestamp = utils.NewUint64(0) + c.NetworkUpgrades.FortunaTimestamp = utils.PointerTo[uint64](0) }) TestGraniteChainConfig = copyAndSet(TestFortunaChainConfig, func(c *ChainConfig) { - c.NetworkUpgrades.GraniteTimestamp = utils.NewUint64(0) + c.NetworkUpgrades.GraniteTimestamp = utils.PointerTo[uint64](0) }) TestHeliconChainConfig = copyAndSet(TestGraniteChainConfig, func(c *ChainConfig) { - c.NetworkUpgrades.HeliconTimestamp = utils.NewUint64(0) + c.NetworkUpgrades.HeliconTimestamp = utils.PointerTo[uint64](0) }) TestChainConfig = copyConfig(TestHeliconChainConfig) @@ -123,7 +123,7 @@ func (c *ChainConfig) CheckConfigCompatible(newConfig *ethparams.ChainConfig, he // Return an error to prevent the chain from starting, just in case. return ethparams.NewTimestampCompatError( fmt.Sprintf("ChainConfig.Hooks() is not of the expected type *extras.ChainConfig, got %T", newConfig.Hooks()), - utils.NewUint64(0), + utils.PointerTo[uint64](0), nil, ) } diff --git a/graft/subnet-evm/params/extras/config_extra_test.go b/graft/subnet-evm/params/extras/config_extra_test.go index 4e26cf667571..d8bfc4a2d764 100644 --- a/graft/subnet-evm/params/extras/config_extra_test.go +++ b/graft/subnet-evm/params/extras/config_extra_test.go @@ -8,7 +8,7 @@ import ( "github.com/stretchr/testify/require" - "github.com/ava-labs/avalanchego/graft/evm/utils" + "github.com/ava-labs/avalanchego/utils" ) func TestIsTimestampForked(t *testing.T) { @@ -30,22 +30,22 @@ func TestIsTimestampForked(t *testing.T) { isForked: false, }, "zero fork at genesis": { - fork: utils.NewUint64(0), + fork: utils.PointerTo[uint64](0), block: 0, isForked: true, }, "pre fork timestamp": { - fork: utils.NewUint64(100), + fork: utils.PointerTo[uint64](100), block: 50, isForked: false, }, "at fork timestamp": { - fork: utils.NewUint64(100), + fork: utils.PointerTo[uint64](100), block: 100, isForked: true, }, "post fork timestamp": { - fork: utils.NewUint64(100), + fork: utils.PointerTo[uint64](100), block: 150, isForked: true, }, @@ -72,50 +72,50 @@ func TestIsForkTransition(t *testing.T) { transitioned: false, }, "activate at genesis": { - fork: utils.NewUint64(0), + fork: utils.PointerTo[uint64](0), parent: nil, current: 0, transitioned: true, }, "nil fork arbitrary transition": { fork: nil, - parent: utils.NewUint64(100), + parent: utils.PointerTo[uint64](100), current: 101, transitioned: false, }, "nil fork transition same timestamp": { fork: nil, - parent: utils.NewUint64(100), + parent: utils.PointerTo[uint64](100), current: 100, transitioned: false, }, "exact match on current timestamp": { - fork: utils.NewUint64(100), - parent: utils.NewUint64(99), + fork: utils.PointerTo[uint64](100), + parent: utils.PointerTo[uint64](99), current: 100, transitioned: true, }, "current same as parent does not transition twice": { - fork: utils.NewUint64(100), - parent: utils.NewUint64(101), + fork: utils.PointerTo[uint64](100), + parent: utils.PointerTo[uint64](101), current: 101, transitioned: false, }, "current, parent, and fork same should not transition twice": { - fork: utils.NewUint64(100), - parent: utils.NewUint64(100), + fork: utils.PointerTo[uint64](100), + parent: utils.PointerTo[uint64](100), current: 100, transitioned: false, }, "current transitions after fork": { - fork: utils.NewUint64(100), - parent: utils.NewUint64(99), + fork: utils.PointerTo[uint64](100), + parent: utils.PointerTo[uint64](99), current: 101, transitioned: true, }, "current and parent come after fork": { - fork: utils.NewUint64(100), - parent: utils.NewUint64(101), + fork: utils.PointerTo[uint64](100), + parent: utils.PointerTo[uint64](101), current: 102, transitioned: false, }, diff --git a/graft/subnet-evm/params/extras/config_test.go b/graft/subnet-evm/params/extras/config_test.go index 8191b7e56fd9..3636cc17fff7 100644 --- a/graft/subnet-evm/params/extras/config_test.go +++ b/graft/subnet-evm/params/extras/config_test.go @@ -15,10 +15,9 @@ import ( "github.com/ava-labs/avalanchego/graft/subnet-evm/precompile/contracts/txallowlist" "github.com/ava-labs/avalanchego/snow" "github.com/ava-labs/avalanchego/upgrade" + "github.com/ava-labs/avalanchego/utils" ) -func pointer[T any](v T) *T { return &v } - func TestChainConfigDescription(t *testing.T) { t.Parallel() @@ -40,10 +39,10 @@ $`, "set": { config: &ChainConfig{ NetworkUpgrades: NetworkUpgrades{ - SubnetEVMTimestamp: pointer(uint64(1)), - DurangoTimestamp: pointer(uint64(2)), - EtnaTimestamp: pointer(uint64(3)), - FortunaTimestamp: pointer(uint64(4)), + SubnetEVMTimestamp: utils.PointerTo[uint64](1), + DurangoTimestamp: utils.PointerTo[uint64](2), + EtnaTimestamp: utils.PointerTo[uint64](3), + FortunaTimestamp: utils.PointerTo[uint64](4), }, FeeConfig: commontype.FeeConfig{ GasLimit: big.NewInt(5), @@ -58,11 +57,11 @@ $`, AllowFeeRecipients: true, UpgradeConfig: UpgradeConfig{ NetworkUpgradeOverrides: &NetworkUpgrades{ - SubnetEVMTimestamp: pointer(uint64(13)), + SubnetEVMTimestamp: utils.PointerTo[uint64](13), }, StateUpgrades: []StateUpgrade{ { - BlockTimestamp: pointer(uint64(14)), + BlockTimestamp: utils.PointerTo[uint64](14), StateUpgradeAccounts: map[common.Address]StateUpgradeAccount{ {15}: { Code: []byte{16}, @@ -123,8 +122,8 @@ func TestChainConfigVerify(t *testing.T) { UpgradeConfig: UpgradeConfig{ PrecompileUpgrades: []PrecompileUpgrade{ // same precompile cannot be configured twice for the same timestamp - {Config: txallowlist.NewDisableConfig(pointer(uint64(1)))}, - {Config: txallowlist.NewDisableConfig(pointer(uint64(1)))}, + {Config: txallowlist.NewDisableConfig(utils.PointerTo[uint64](1))}, + {Config: txallowlist.NewDisableConfig(utils.PointerTo[uint64](1))}, }, }, }, @@ -155,10 +154,10 @@ func TestChainConfigVerify(t *testing.T) { config: ChainConfig{ FeeConfig: validFeeConfig, NetworkUpgrades: NetworkUpgrades{ - SubnetEVMTimestamp: pointer(uint64(1)), - DurangoTimestamp: pointer(uint64(2)), - EtnaTimestamp: pointer(uint64(3)), - FortunaTimestamp: pointer(uint64(4)), + SubnetEVMTimestamp: utils.PointerTo[uint64](1), + DurangoTimestamp: utils.PointerTo[uint64](2), + EtnaTimestamp: utils.PointerTo[uint64](3), + FortunaTimestamp: utils.PointerTo[uint64](4), }, AvalancheContext: AvalancheContext{SnowCtx: &snow.Context{ NetworkUpgrades: upgrade.Config{ diff --git a/graft/subnet-evm/params/extras/network_upgrades.go b/graft/subnet-evm/params/extras/network_upgrades.go index 289377996c39..b3f15c7ec8e4 100644 --- a/graft/subnet-evm/params/extras/network_upgrades.go +++ b/graft/subnet-evm/params/extras/network_upgrades.go @@ -12,6 +12,7 @@ import ( "github.com/ava-labs/avalanchego/graft/evm/utils" "github.com/ava-labs/avalanchego/upgrade" + avalancheutils "github.com/ava-labs/avalanchego/utils" ethparams "github.com/ava-labs/libevm/params" ) @@ -237,7 +238,7 @@ func (n *NetworkUpgrades) GetAvalancheRules(time uint64) AvalancheRules { // Nil values are used to indicate optional upgrades. func GetNetworkUpgrades(agoUpgrade upgrade.Config) NetworkUpgrades { return NetworkUpgrades{ - SubnetEVMTimestamp: utils.NewUint64(0), + SubnetEVMTimestamp: avalancheutils.PointerTo[uint64](0), DurangoTimestamp: utils.TimeToNewUint64(agoUpgrade.DurangoTime), EtnaTimestamp: utils.TimeToNewUint64(agoUpgrade.EtnaTime), FortunaTimestamp: nil, // Fortuna is optional and has no effect on Subnet-EVM diff --git a/graft/subnet-evm/params/extras/network_upgrades_test.go b/graft/subnet-evm/params/extras/network_upgrades_test.go index beafb103d0cb..e703b3396107 100644 --- a/graft/subnet-evm/params/extras/network_upgrades_test.go +++ b/graft/subnet-evm/params/extras/network_upgrades_test.go @@ -12,6 +12,8 @@ import ( "github.com/ava-labs/avalanchego/upgrade" "github.com/ava-labs/avalanchego/upgrade/upgradetest" "github.com/ava-labs/avalanchego/utils/constants" + + avalancheutils "github.com/ava-labs/avalanchego/utils" ) func TestNetworkUpgradesEqual(t *testing.T) { @@ -24,32 +26,32 @@ func TestNetworkUpgradesEqual(t *testing.T) { { name: "EqualNetworkUpgrades", upgrades1: &NetworkUpgrades{ - SubnetEVMTimestamp: utils.NewUint64(1), - DurangoTimestamp: utils.NewUint64(2), + SubnetEVMTimestamp: avalancheutils.PointerTo[uint64](1), + DurangoTimestamp: avalancheutils.PointerTo[uint64](2), }, upgrades2: &NetworkUpgrades{ - SubnetEVMTimestamp: utils.NewUint64(1), - DurangoTimestamp: utils.NewUint64(2), + SubnetEVMTimestamp: avalancheutils.PointerTo[uint64](1), + DurangoTimestamp: avalancheutils.PointerTo[uint64](2), }, expected: true, }, { name: "NotEqualNetworkUpgrades", upgrades1: &NetworkUpgrades{ - SubnetEVMTimestamp: utils.NewUint64(1), - DurangoTimestamp: utils.NewUint64(2), + SubnetEVMTimestamp: avalancheutils.PointerTo[uint64](1), + DurangoTimestamp: avalancheutils.PointerTo[uint64](2), }, upgrades2: &NetworkUpgrades{ - SubnetEVMTimestamp: utils.NewUint64(1), - DurangoTimestamp: utils.NewUint64(3), + SubnetEVMTimestamp: avalancheutils.PointerTo[uint64](1), + DurangoTimestamp: avalancheutils.PointerTo[uint64](3), }, expected: false, }, { name: "NilNetworkUpgrades", upgrades1: &NetworkUpgrades{ - SubnetEVMTimestamp: utils.NewUint64(1), - DurangoTimestamp: utils.NewUint64(2), + SubnetEVMTimestamp: avalancheutils.PointerTo[uint64](1), + DurangoTimestamp: avalancheutils.PointerTo[uint64](2), }, upgrades2: nil, expected: false, @@ -57,11 +59,11 @@ func TestNetworkUpgradesEqual(t *testing.T) { { name: "NilNetworkUpgrade", upgrades1: &NetworkUpgrades{ - SubnetEVMTimestamp: utils.NewUint64(1), - DurangoTimestamp: utils.NewUint64(2), + SubnetEVMTimestamp: avalancheutils.PointerTo[uint64](1), + DurangoTimestamp: avalancheutils.PointerTo[uint64](2), }, upgrades2: &NetworkUpgrades{ - SubnetEVMTimestamp: utils.NewUint64(1), + SubnetEVMTimestamp: avalancheutils.PointerTo[uint64](1), DurangoTimestamp: nil, }, expected: false, @@ -85,12 +87,12 @@ func TestCheckNetworkUpgradesCompatible(t *testing.T) { { name: "Compatible_same_NetworkUpgrades", upgrades1: &NetworkUpgrades{ - SubnetEVMTimestamp: utils.NewUint64(1), - DurangoTimestamp: utils.NewUint64(2), + SubnetEVMTimestamp: avalancheutils.PointerTo[uint64](1), + DurangoTimestamp: avalancheutils.PointerTo[uint64](2), }, upgrades2: &NetworkUpgrades{ - SubnetEVMTimestamp: utils.NewUint64(1), - DurangoTimestamp: utils.NewUint64(2), + SubnetEVMTimestamp: avalancheutils.PointerTo[uint64](1), + DurangoTimestamp: avalancheutils.PointerTo[uint64](2), }, time: 1, valid: true, @@ -98,12 +100,12 @@ func TestCheckNetworkUpgradesCompatible(t *testing.T) { { name: "Compatible_different_NetworkUpgrades", upgrades1: &NetworkUpgrades{ - SubnetEVMTimestamp: utils.NewUint64(1), - DurangoTimestamp: utils.NewUint64(2), + SubnetEVMTimestamp: avalancheutils.PointerTo[uint64](1), + DurangoTimestamp: avalancheutils.PointerTo[uint64](2), }, upgrades2: &NetworkUpgrades{ - SubnetEVMTimestamp: utils.NewUint64(1), - DurangoTimestamp: utils.NewUint64(3), + SubnetEVMTimestamp: avalancheutils.PointerTo[uint64](1), + DurangoTimestamp: avalancheutils.PointerTo[uint64](3), }, time: 1, valid: true, @@ -111,11 +113,11 @@ func TestCheckNetworkUpgradesCompatible(t *testing.T) { { name: "Compatible_nil_NetworkUpgrades", upgrades1: &NetworkUpgrades{ - SubnetEVMTimestamp: utils.NewUint64(1), - DurangoTimestamp: utils.NewUint64(2), + SubnetEVMTimestamp: avalancheutils.PointerTo[uint64](1), + DurangoTimestamp: avalancheutils.PointerTo[uint64](2), }, upgrades2: &NetworkUpgrades{ - SubnetEVMTimestamp: utils.NewUint64(1), + SubnetEVMTimestamp: avalancheutils.PointerTo[uint64](1), DurangoTimestamp: nil, }, time: 1, @@ -124,12 +126,12 @@ func TestCheckNetworkUpgradesCompatible(t *testing.T) { { name: "Incompatible_rewinded_NetworkUpgrades", upgrades1: &NetworkUpgrades{ - SubnetEVMTimestamp: utils.NewUint64(1), - DurangoTimestamp: utils.NewUint64(2), + SubnetEVMTimestamp: avalancheutils.PointerTo[uint64](1), + DurangoTimestamp: avalancheutils.PointerTo[uint64](2), }, upgrades2: &NetworkUpgrades{ - SubnetEVMTimestamp: utils.NewUint64(1), - DurangoTimestamp: utils.NewUint64(1), + SubnetEVMTimestamp: avalancheutils.PointerTo[uint64](1), + DurangoTimestamp: avalancheutils.PointerTo[uint64](1), }, time: 1, valid: false, @@ -137,12 +139,12 @@ func TestCheckNetworkUpgradesCompatible(t *testing.T) { { name: "Incompatible_fastforward_NetworkUpgrades", upgrades1: &NetworkUpgrades{ - SubnetEVMTimestamp: utils.NewUint64(1), - DurangoTimestamp: utils.NewUint64(2), + SubnetEVMTimestamp: avalancheutils.PointerTo[uint64](1), + DurangoTimestamp: avalancheutils.PointerTo[uint64](2), }, upgrades2: &NetworkUpgrades{ - SubnetEVMTimestamp: utils.NewUint64(1), - DurangoTimestamp: utils.NewUint64(3), + SubnetEVMTimestamp: avalancheutils.PointerTo[uint64](1), + DurangoTimestamp: avalancheutils.PointerTo[uint64](3), }, time: 4, valid: false, @@ -150,11 +152,11 @@ func TestCheckNetworkUpgradesCompatible(t *testing.T) { { name: "Incompatible_nil_NetworkUpgrades", upgrades1: &NetworkUpgrades{ - SubnetEVMTimestamp: utils.NewUint64(1), - DurangoTimestamp: utils.NewUint64(2), + SubnetEVMTimestamp: avalancheutils.PointerTo[uint64](1), + DurangoTimestamp: avalancheutils.PointerTo[uint64](2), }, upgrades2: &NetworkUpgrades{ - SubnetEVMTimestamp: utils.NewUint64(1), + SubnetEVMTimestamp: avalancheutils.PointerTo[uint64](1), DurangoTimestamp: nil, }, time: 2, @@ -211,7 +213,7 @@ func TestVerifyNetworkUpgrades(t *testing.T) { { name: "Invalid_Durango_nil_upgrade", upgrades: &NetworkUpgrades{ - SubnetEVMTimestamp: utils.NewUint64(1), + SubnetEVMTimestamp: avalancheutils.PointerTo[uint64](1), DurangoTimestamp: nil, }, avagoUpgrades: upgrade.Mainnet, @@ -220,8 +222,8 @@ func TestVerifyNetworkUpgrades(t *testing.T) { { name: "Invalid_Subnet-EVM_non-zero", upgrades: &NetworkUpgrades{ - SubnetEVMTimestamp: utils.NewUint64(1), - DurangoTimestamp: utils.NewUint64(2), + SubnetEVMTimestamp: avalancheutils.PointerTo[uint64](1), + DurangoTimestamp: avalancheutils.PointerTo[uint64](2), }, avagoUpgrades: upgrade.Mainnet, wantError: errTimestampTooEarly, @@ -229,8 +231,8 @@ func TestVerifyNetworkUpgrades(t *testing.T) { { name: "Invalid_Durango_before_default_upgrade", upgrades: &NetworkUpgrades{ - SubnetEVMTimestamp: utils.NewUint64(0), - DurangoTimestamp: utils.NewUint64(1), + SubnetEVMTimestamp: avalancheutils.PointerTo[uint64](0), + DurangoTimestamp: avalancheutils.PointerTo[uint64](1), }, avagoUpgrades: upgrade.Mainnet, wantError: errTimestampTooEarly, @@ -238,7 +240,7 @@ func TestVerifyNetworkUpgrades(t *testing.T) { { name: "Invalid_Mainnet_Durango_reconfigured_to_Fuji", upgrades: &NetworkUpgrades{ - SubnetEVMTimestamp: utils.NewUint64(0), + SubnetEVMTimestamp: avalancheutils.PointerTo[uint64](0), DurangoTimestamp: utils.TimeToNewUint64(upgrade.GetConfig(constants.FujiID).DurangoTime), }, avagoUpgrades: upgrade.Mainnet, @@ -247,7 +249,7 @@ func TestVerifyNetworkUpgrades(t *testing.T) { { name: "Valid_Fuji_Durango_reconfigured_to_Mainnet", upgrades: &NetworkUpgrades{ - SubnetEVMTimestamp: utils.NewUint64(0), + SubnetEVMTimestamp: avalancheutils.PointerTo[uint64](0), DurangoTimestamp: utils.TimeToNewUint64(upgrade.GetConfig(constants.MainnetID).DurangoTime), }, avagoUpgrades: upgrade.Fuji, @@ -256,7 +258,7 @@ func TestVerifyNetworkUpgrades(t *testing.T) { { name: "Invalid_Etna_nil", upgrades: &NetworkUpgrades{ - SubnetEVMTimestamp: utils.NewUint64(0), + SubnetEVMTimestamp: avalancheutils.PointerTo[uint64](0), DurangoTimestamp: utils.TimeToNewUint64(upgrade.Mainnet.DurangoTime), EtnaTimestamp: nil, }, @@ -266,7 +268,7 @@ func TestVerifyNetworkUpgrades(t *testing.T) { { name: "Invalid_Etna_before_Durango", upgrades: &NetworkUpgrades{ - SubnetEVMTimestamp: utils.NewUint64(0), + SubnetEVMTimestamp: avalancheutils.PointerTo[uint64](0), DurangoTimestamp: utils.TimeToNewUint64(upgrade.Mainnet.DurangoTime), EtnaTimestamp: utils.TimeToNewUint64(upgrade.Mainnet.DurangoTime.Add(-1)), }, @@ -276,7 +278,7 @@ func TestVerifyNetworkUpgrades(t *testing.T) { { name: "Valid_Granite_After_nil_Fortuna", upgrades: &NetworkUpgrades{ - SubnetEVMTimestamp: utils.NewUint64(0), + SubnetEVMTimestamp: avalancheutils.PointerTo[uint64](0), DurangoTimestamp: utils.TimeToNewUint64(upgrade.Fuji.DurangoTime), EtnaTimestamp: utils.TimeToNewUint64(upgrade.Fuji.EtnaTime), FortunaTimestamp: nil, @@ -303,16 +305,16 @@ func TestForkOrder(t *testing.T) { { name: "ValidNetworkUpgrades", upgrades: &NetworkUpgrades{ - SubnetEVMTimestamp: utils.NewUint64(0), - DurangoTimestamp: utils.NewUint64(2), + SubnetEVMTimestamp: avalancheutils.PointerTo[uint64](0), + DurangoTimestamp: avalancheutils.PointerTo[uint64](2), }, wantError: nil, }, { name: "Invalid order", upgrades: &NetworkUpgrades{ - SubnetEVMTimestamp: utils.NewUint64(1), - DurangoTimestamp: utils.NewUint64(0), + SubnetEVMTimestamp: avalancheutils.PointerTo[uint64](1), + DurangoTimestamp: avalancheutils.PointerTo[uint64](0), }, wantError: errUnsupportedForkOrdering, }, @@ -327,12 +329,12 @@ func TestForkOrder(t *testing.T) { func TestSetDefaultsTreatsZeroAsUnset(t *testing.T) { upgrades := &NetworkUpgrades{ - SubnetEVMTimestamp: utils.NewUint64(0), - DurangoTimestamp: utils.NewUint64(0), + SubnetEVMTimestamp: avalancheutils.PointerTo[uint64](0), + DurangoTimestamp: avalancheutils.PointerTo[uint64](0), EtnaTimestamp: nil, - FortunaTimestamp: utils.NewUint64(0), - GraniteTimestamp: utils.NewUint64(0), - HeliconTimestamp: utils.NewUint64(0), + FortunaTimestamp: avalancheutils.PointerTo[uint64](0), + GraniteTimestamp: avalancheutils.PointerTo[uint64](0), + HeliconTimestamp: avalancheutils.PointerTo[uint64](0), } agoUpgrades := upgradetest.GetConfig(upgradetest.Latest) upgrades.SetDefaults(agoUpgrades) diff --git a/graft/subnet-evm/params/extras/precompile_config_test.go b/graft/subnet-evm/params/extras/precompile_config_test.go index 030f5d5b9b61..126239e05a09 100644 --- a/graft/subnet-evm/params/extras/precompile_config_test.go +++ b/graft/subnet-evm/params/extras/precompile_config_test.go @@ -11,7 +11,6 @@ import ( "github.com/ava-labs/libevm/common" "github.com/stretchr/testify/require" - "github.com/ava-labs/avalanchego/graft/evm/utils" "github.com/ava-labs/avalanchego/graft/evm/utils/utilstest" "github.com/ava-labs/avalanchego/graft/subnet-evm/commontype" "github.com/ava-labs/avalanchego/graft/subnet-evm/precompile/allowlist" @@ -20,6 +19,7 @@ import ( "github.com/ava-labs/avalanchego/graft/subnet-evm/precompile/contracts/nativeminter" "github.com/ava-labs/avalanchego/graft/subnet-evm/precompile/contracts/rewardmanager" "github.com/ava-labs/avalanchego/graft/subnet-evm/precompile/contracts/txallowlist" + "github.com/ava-labs/avalanchego/utils" ) func TestVerifyWithChainConfig(t *testing.T) { @@ -28,16 +28,16 @@ func TestVerifyWithChainConfig(t *testing.T) { config := &c config.SnowCtx = utilstest.NewTestSnowContext(t, utilstest.SubnetEVMTestChainID) config.GenesisPrecompiles = Precompiles{ - txallowlist.ConfigKey: txallowlist.NewConfig(utils.NewUint64(2), nil, nil, nil), + txallowlist.ConfigKey: txallowlist.NewConfig(utils.PointerTo[uint64](2), nil, nil, nil), } config.PrecompileUpgrades = []PrecompileUpgrade{ { // disable TxAllowList at timestamp 4 - txallowlist.NewDisableConfig(utils.NewUint64(4)), + txallowlist.NewDisableConfig(utils.PointerTo[uint64](4)), }, { // re-enable TxAllowList at timestamp 5 - txallowlist.NewConfig(utils.NewUint64(5), admins, nil, nil), + txallowlist.NewConfig(utils.PointerTo[uint64](5), admins, nil, nil), }, } @@ -50,7 +50,7 @@ func TestVerifyWithChainConfig(t *testing.T) { badConfig.PrecompileUpgrades = append( badConfig.PrecompileUpgrades, PrecompileUpgrade{ - Config: txallowlist.NewDisableConfig(utils.NewUint64(5)), + Config: txallowlist.NewDisableConfig(utils.PointerTo[uint64](5)), }, ) err = badConfig.Verify() @@ -61,7 +61,7 @@ func TestVerifyWithChainConfig(t *testing.T) { badConfig.PrecompileUpgrades = append( badConfig.PrecompileUpgrades, PrecompileUpgrade{ - Config: txallowlist.NewConfig(utils.NewUint64(5), admins, nil, nil), + Config: txallowlist.NewConfig(utils.PointerTo[uint64](5), admins, nil, nil), }, ) err = badConfig.Verify() @@ -81,7 +81,7 @@ func TestVerifyWithChainConfigAtNilTimestamp(t *testing.T) { config.PrecompileUpgrades = []PrecompileUpgrade{ { // enable TxAllowList at timestamp 5 - Config: txallowlist.NewConfig(utils.NewUint64(5), admins, nil, nil), + Config: txallowlist.NewConfig(utils.PointerTo[uint64](5), admins, nil, nil), }, } @@ -100,10 +100,10 @@ func TestVerifyPrecompileUpgrades(t *testing.T) { name: "enable and disable tx allow list", upgrades: []PrecompileUpgrade{ { - Config: txallowlist.NewConfig(utils.NewUint64(1), admins, nil, nil), + Config: txallowlist.NewConfig(utils.PointerTo[uint64](1), admins, nil, nil), }, { - Config: txallowlist.NewDisableConfig(utils.NewUint64(2)), + Config: txallowlist.NewDisableConfig(utils.PointerTo[uint64](2)), }, }, expectedError: nil, @@ -112,13 +112,13 @@ func TestVerifyPrecompileUpgrades(t *testing.T) { name: "invalid allow list config in tx allowlist", upgrades: []PrecompileUpgrade{ { - Config: txallowlist.NewConfig(utils.NewUint64(1), admins, nil, nil), + Config: txallowlist.NewConfig(utils.PointerTo[uint64](1), admins, nil, nil), }, { - Config: txallowlist.NewDisableConfig(utils.NewUint64(2)), + Config: txallowlist.NewDisableConfig(utils.PointerTo[uint64](2)), }, { - Config: txallowlist.NewConfig(utils.NewUint64(3), admins, admins, admins), + Config: txallowlist.NewConfig(utils.PointerTo[uint64](3), admins, admins, admins), }, }, expectedError: allowlist.ErrAdminAndEnabledAddress, @@ -127,7 +127,7 @@ func TestVerifyPrecompileUpgrades(t *testing.T) { name: "invalid initial fee manager config", upgrades: []PrecompileUpgrade{ { - Config: feemanager.NewConfig(utils.NewUint64(3), admins, nil, nil, + Config: feemanager.NewConfig(utils.PointerTo[uint64](3), admins, nil, nil, func() *commontype.FeeConfig { feeConfig := DefaultFeeConfig feeConfig.GasLimit = big.NewInt(-1) @@ -141,7 +141,7 @@ func TestVerifyPrecompileUpgrades(t *testing.T) { name: "invalid initial fee manager config gas limit 0", upgrades: []PrecompileUpgrade{ { - Config: feemanager.NewConfig(utils.NewUint64(3), admins, nil, nil, + Config: feemanager.NewConfig(utils.PointerTo[uint64](3), admins, nil, nil, func() *commontype.FeeConfig { feeConfig := DefaultFeeConfig feeConfig.GasLimit = common.Big0 @@ -155,10 +155,10 @@ func TestVerifyPrecompileUpgrades(t *testing.T) { name: "different upgrades are allowed to configure same timestamp for different precompiles", upgrades: []PrecompileUpgrade{ { - Config: txallowlist.NewConfig(utils.NewUint64(1), admins, nil, nil), + Config: txallowlist.NewConfig(utils.PointerTo[uint64](1), admins, nil, nil), }, { - Config: feemanager.NewConfig(utils.NewUint64(1), admins, nil, nil, nil), + Config: feemanager.NewConfig(utils.PointerTo[uint64](1), admins, nil, nil, nil), }, }, expectedError: nil, @@ -167,10 +167,10 @@ func TestVerifyPrecompileUpgrades(t *testing.T) { name: "different upgrades must be monotonically increasing", upgrades: []PrecompileUpgrade{ { - Config: txallowlist.NewConfig(utils.NewUint64(2), admins, nil, nil), + Config: txallowlist.NewConfig(utils.PointerTo[uint64](2), admins, nil, nil), }, { - Config: feemanager.NewConfig(utils.NewUint64(1), admins, nil, nil, nil), + Config: feemanager.NewConfig(utils.PointerTo[uint64](1), admins, nil, nil, nil), }, }, expectedError: errPrecompileUpgradeTimestampNotMonotonic, @@ -179,10 +179,10 @@ func TestVerifyPrecompileUpgrades(t *testing.T) { name: "upgrades with same keys are not allowed to configure same timestamp for same precompiles", upgrades: []PrecompileUpgrade{ { - Config: txallowlist.NewConfig(utils.NewUint64(1), admins, nil, nil), + Config: txallowlist.NewConfig(utils.PointerTo[uint64](1), admins, nil, nil), }, { - Config: txallowlist.NewDisableConfig(utils.NewUint64(1)), + Config: txallowlist.NewDisableConfig(utils.PointerTo[uint64](1)), }, }, expectedError: errPrecompileUpgradeSameKeyTimestampNotStrictly, @@ -212,14 +212,14 @@ func TestVerifyPrecompiles(t *testing.T) { { name: "invalid allow list config in tx allowlist", precompiles: Precompiles{ - txallowlist.ConfigKey: txallowlist.NewConfig(utils.NewUint64(3), admins, admins, admins), + txallowlist.ConfigKey: txallowlist.NewConfig(utils.PointerTo[uint64](3), admins, admins, admins), }, expectedError: allowlist.ErrAdminAndEnabledAddress, }, { name: "invalid initial fee manager config", precompiles: Precompiles{ - feemanager.ConfigKey: feemanager.NewConfig(utils.NewUint64(3), admins, nil, nil, + feemanager.ConfigKey: feemanager.NewConfig(utils.PointerTo[uint64](3), admins, nil, nil, func() *commontype.FeeConfig { feeConfig := DefaultFeeConfig feeConfig.GasLimit = big.NewInt(-1) @@ -253,10 +253,10 @@ func TestVerifyRequiresSortedTimestamps(t *testing.T) { } config.PrecompileUpgrades = []PrecompileUpgrade{ { - Config: txallowlist.NewConfig(utils.NewUint64(2), admins, nil, nil), + Config: txallowlist.NewConfig(utils.PointerTo[uint64](2), admins, nil, nil), }, { - Config: deployerallowlist.NewConfig(utils.NewUint64(1), admins, nil, nil), + Config: deployerallowlist.NewConfig(utils.PointerTo[uint64](1), admins, nil, nil), }, } @@ -269,7 +269,7 @@ func TestGetPrecompileConfig(t *testing.T) { require := require.New(t) config := &ChainConfig{} config.GenesisPrecompiles = Precompiles{ - deployerallowlist.ConfigKey: deployerallowlist.NewConfig(utils.NewUint64(10), nil, nil, nil), + deployerallowlist.ConfigKey: deployerallowlist.NewConfig(utils.PointerTo[uint64](10), nil, nil, nil), } deployerConfig := config.GetActivePrecompileConfig(deployerallowlist.ContractAddress, 0) @@ -320,7 +320,7 @@ func TestPrecompileUpgradeUnmarshalJSON(t *testing.T) { rewardManagerConf := upgradeConfig.PrecompileUpgrades[0] require.Equal(rewardmanager.ConfigKey, rewardManagerConf.Key()) testRewardManagerConfig := rewardmanager.NewConfig( - utils.NewUint64(1671542573), + utils.PointerTo[uint64](1671542573), []common.Address{common.HexToAddress("0x8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FC")}, nil, nil, @@ -331,7 +331,7 @@ func TestPrecompileUpgradeUnmarshalJSON(t *testing.T) { nativeMinterConfig := upgradeConfig.PrecompileUpgrades[1] require.Equal(nativeminter.ConfigKey, nativeMinterConfig.Key()) - expectedNativeMinterConfig := nativeminter.NewConfig(utils.NewUint64(1671543172), nil, nil, nil, nil) + expectedNativeMinterConfig := nativeminter.NewConfig(utils.PointerTo[uint64](1671543172), nil, nil, nil, nil) require.True(nativeMinterConfig.Equal(expectedNativeMinterConfig)) // Marshal and unmarshal again and check that the result is the same diff --git a/graft/subnet-evm/params/extras/precompile_upgrade.go b/graft/subnet-evm/params/extras/precompile_upgrade.go index cf60a29daa81..2895fcadd465 100644 --- a/graft/subnet-evm/params/extras/precompile_upgrade.go +++ b/graft/subnet-evm/params/extras/precompile_upgrade.go @@ -10,9 +10,9 @@ import ( "github.com/ava-labs/libevm/common" - "github.com/ava-labs/avalanchego/graft/evm/utils" "github.com/ava-labs/avalanchego/graft/subnet-evm/precompile/modules" "github.com/ava-labs/avalanchego/graft/subnet-evm/precompile/precompileconfig" + "github.com/ava-labs/avalanchego/utils" ethparams "github.com/ava-labs/libevm/params" ) @@ -119,7 +119,7 @@ func (c *ChainConfig) verifyPrecompileUpgrades() error { lastTimestamp = nil } else { disabled = lastUpgradeByKey.disabled - lastTimestamp = utils.NewUint64(lastUpgradeByKey.blockTimestamp) + lastTimestamp = utils.PointerTo(lastUpgradeByKey.blockTimestamp) } upgradeTimestamp := upgrade.Timestamp() diff --git a/graft/subnet-evm/params/extras/precompile_upgrade_test.go b/graft/subnet-evm/params/extras/precompile_upgrade_test.go index 9264d55b9d5f..e5dac41ea8cb 100644 --- a/graft/subnet-evm/params/extras/precompile_upgrade_test.go +++ b/graft/subnet-evm/params/extras/precompile_upgrade_test.go @@ -10,9 +10,9 @@ import ( "github.com/ava-labs/libevm/common" "github.com/stretchr/testify/require" - "github.com/ava-labs/avalanchego/graft/evm/utils" "github.com/ava-labs/avalanchego/graft/subnet-evm/precompile/contracts/deployerallowlist" "github.com/ava-labs/avalanchego/graft/subnet-evm/precompile/contracts/txallowlist" + "github.com/ava-labs/avalanchego/utils" ) func TestVerifyUpgradeConfig(t *testing.T) { @@ -21,7 +21,7 @@ func TestVerifyUpgradeConfig(t *testing.T) { FeeConfig: DefaultFeeConfig, } chainConfig.GenesisPrecompiles = Precompiles{ - txallowlist.ConfigKey: txallowlist.NewConfig(utils.NewUint64(1), admins, nil, nil), + txallowlist.ConfigKey: txallowlist.NewConfig(utils.PointerTo[uint64](1), admins, nil, nil), } type test struct { @@ -34,7 +34,7 @@ func TestVerifyUpgradeConfig(t *testing.T) { expectedError: errPrecompileUpgradeInvalidDisable, upgrades: []PrecompileUpgrade{ { - Config: txallowlist.NewConfig(utils.NewUint64(2), admins, nil, nil), + Config: txallowlist.NewConfig(utils.PointerTo[uint64](2), admins, nil, nil), }, }, }, @@ -42,7 +42,7 @@ func TestVerifyUpgradeConfig(t *testing.T) { expectedError: errPrecompileUpgradeSameKeyTimestampNotStrictly, upgrades: []PrecompileUpgrade{ { - Config: txallowlist.NewDisableConfig(utils.NewUint64(0)), + Config: txallowlist.NewDisableConfig(utils.PointerTo[uint64](0)), }, }, }, @@ -50,7 +50,7 @@ func TestVerifyUpgradeConfig(t *testing.T) { expectedError: errPrecompileUpgradeSameKeyTimestampNotStrictly, upgrades: []PrecompileUpgrade{ { - Config: txallowlist.NewDisableConfig(utils.NewUint64(1)), + Config: txallowlist.NewDisableConfig(utils.PointerTo[uint64](1)), }, }, }, @@ -79,8 +79,8 @@ func TestCheckCompatibleUpgradeConfigs(t *testing.T) { admins := []common.Address{{1}} chainConfig := &ChainConfig{} chainConfig.GenesisPrecompiles = Precompiles{ - txallowlist.ConfigKey: txallowlist.NewConfig(utils.NewUint64(1), admins, nil, nil), - deployerallowlist.ConfigKey: deployerallowlist.NewConfig(utils.NewUint64(10), admins, nil, nil), + txallowlist.ConfigKey: txallowlist.NewConfig(utils.PointerTo[uint64](1), admins, nil, nil), + deployerallowlist.ConfigKey: deployerallowlist.NewConfig(utils.PointerTo[uint64](10), admins, nil, nil), } tests := map[string]upgradeCompatibilityTest{ @@ -90,10 +90,10 @@ func TestCheckCompatibleUpgradeConfigs(t *testing.T) { { PrecompileUpgrades: []PrecompileUpgrade{ { - Config: txallowlist.NewDisableConfig(utils.NewUint64(6)), + Config: txallowlist.NewDisableConfig(utils.PointerTo[uint64](6)), }, { - Config: txallowlist.NewConfig(utils.NewUint64(7), admins, nil, nil), + Config: txallowlist.NewConfig(utils.PointerTo[uint64](7), admins, nil, nil), }, }, }, @@ -105,20 +105,20 @@ func TestCheckCompatibleUpgradeConfigs(t *testing.T) { { PrecompileUpgrades: []PrecompileUpgrade{ { - Config: txallowlist.NewDisableConfig(utils.NewUint64(6)), + Config: txallowlist.NewDisableConfig(utils.PointerTo[uint64](6)), }, { - Config: txallowlist.NewConfig(utils.NewUint64(7), admins, nil, nil), + Config: txallowlist.NewConfig(utils.PointerTo[uint64](7), admins, nil, nil), }, }, }, { PrecompileUpgrades: []PrecompileUpgrade{ { - Config: txallowlist.NewDisableConfig(utils.NewUint64(6)), + Config: txallowlist.NewDisableConfig(utils.PointerTo[uint64](6)), }, { - Config: txallowlist.NewConfig(utils.NewUint64(8), admins, nil, nil), + Config: txallowlist.NewConfig(utils.PointerTo[uint64](8), admins, nil, nil), }, }, }, @@ -131,20 +131,20 @@ func TestCheckCompatibleUpgradeConfigs(t *testing.T) { { PrecompileUpgrades: []PrecompileUpgrade{ { - Config: txallowlist.NewDisableConfig(utils.NewUint64(6)), + Config: txallowlist.NewDisableConfig(utils.PointerTo[uint64](6)), }, { - Config: txallowlist.NewConfig(utils.NewUint64(7), admins, nil, nil), + Config: txallowlist.NewConfig(utils.PointerTo[uint64](7), admins, nil, nil), }, }, }, { PrecompileUpgrades: []PrecompileUpgrade{ { - Config: txallowlist.NewDisableConfig(utils.NewUint64(6)), + Config: txallowlist.NewDisableConfig(utils.PointerTo[uint64](6)), }, { - Config: txallowlist.NewConfig(utils.NewUint64(8), admins, nil, nil), + Config: txallowlist.NewConfig(utils.PointerTo[uint64](8), admins, nil, nil), }, }, }, @@ -156,17 +156,17 @@ func TestCheckCompatibleUpgradeConfigs(t *testing.T) { { PrecompileUpgrades: []PrecompileUpgrade{ { - Config: txallowlist.NewDisableConfig(utils.NewUint64(6)), + Config: txallowlist.NewDisableConfig(utils.PointerTo[uint64](6)), }, { - Config: txallowlist.NewConfig(utils.NewUint64(7), admins, nil, nil), + Config: txallowlist.NewConfig(utils.PointerTo[uint64](7), admins, nil, nil), }, }, }, { PrecompileUpgrades: []PrecompileUpgrade{ { - Config: txallowlist.NewDisableConfig(utils.NewUint64(6)), + Config: txallowlist.NewDisableConfig(utils.PointerTo[uint64](6)), }, }, }, @@ -179,17 +179,17 @@ func TestCheckCompatibleUpgradeConfigs(t *testing.T) { { PrecompileUpgrades: []PrecompileUpgrade{ { - Config: txallowlist.NewDisableConfig(utils.NewUint64(6)), + Config: txallowlist.NewDisableConfig(utils.PointerTo[uint64](6)), }, { - Config: txallowlist.NewConfig(utils.NewUint64(7), admins, nil, nil), + Config: txallowlist.NewConfig(utils.PointerTo[uint64](7), admins, nil, nil), }, }, }, { PrecompileUpgrades: []PrecompileUpgrade{ { - Config: txallowlist.NewDisableConfig(utils.NewUint64(6)), + Config: txallowlist.NewDisableConfig(utils.PointerTo[uint64](6)), }, }, }, @@ -202,21 +202,21 @@ func TestCheckCompatibleUpgradeConfigs(t *testing.T) { { PrecompileUpgrades: []PrecompileUpgrade{ { - Config: txallowlist.NewDisableConfig(utils.NewUint64(6)), + Config: txallowlist.NewDisableConfig(utils.PointerTo[uint64](6)), }, { - Config: txallowlist.NewConfig(utils.NewUint64(7), admins, nil, nil), + Config: txallowlist.NewConfig(utils.PointerTo[uint64](7), admins, nil, nil), }, }, }, { PrecompileUpgrades: []PrecompileUpgrade{ { - Config: txallowlist.NewDisableConfig(utils.NewUint64(6)), + Config: txallowlist.NewDisableConfig(utils.PointerTo[uint64](6)), }, { // uses a different (empty) admin list, not allowed - Config: txallowlist.NewConfig(utils.NewUint64(7), []common.Address{}, nil, nil), + Config: txallowlist.NewConfig(utils.PointerTo[uint64](7), []common.Address{}, nil, nil), }, }, }, @@ -228,20 +228,20 @@ func TestCheckCompatibleUpgradeConfigs(t *testing.T) { { PrecompileUpgrades: []PrecompileUpgrade{ { - Config: txallowlist.NewDisableConfig(utils.NewUint64(6)), + Config: txallowlist.NewDisableConfig(utils.PointerTo[uint64](6)), }, { - Config: txallowlist.NewConfig(utils.NewUint64(7), admins, nil, nil), + Config: txallowlist.NewConfig(utils.PointerTo[uint64](7), admins, nil, nil), }, }, }, { PrecompileUpgrades: []PrecompileUpgrade{ { - Config: txallowlist.NewDisableConfig(utils.NewUint64(6)), + Config: txallowlist.NewDisableConfig(utils.PointerTo[uint64](6)), }, { - Config: txallowlist.NewConfig(utils.NewUint64(7), admins, nil, nil), + Config: txallowlist.NewConfig(utils.PointerTo[uint64](7), admins, nil, nil), }, }, }, @@ -254,10 +254,10 @@ func TestCheckCompatibleUpgradeConfigs(t *testing.T) { { PrecompileUpgrades: []PrecompileUpgrade{ { - Config: txallowlist.NewDisableConfig(utils.NewUint64(5)), + Config: txallowlist.NewDisableConfig(utils.PointerTo[uint64](5)), }, { - Config: txallowlist.NewConfig(utils.NewUint64(6), admins, nil, nil), + Config: txallowlist.NewConfig(utils.PointerTo[uint64](6), admins, nil, nil), }, }, }, diff --git a/graft/subnet-evm/params/extras/state_upgrade_test.go b/graft/subnet-evm/params/extras/state_upgrade_test.go index dcf897bd3cb3..1f4d485501c9 100644 --- a/graft/subnet-evm/params/extras/state_upgrade_test.go +++ b/graft/subnet-evm/params/extras/state_upgrade_test.go @@ -12,8 +12,8 @@ import ( "github.com/ava-labs/libevm/common/math" "github.com/stretchr/testify/require" - "github.com/ava-labs/avalanchego/graft/evm/utils" "github.com/ava-labs/avalanchego/graft/evm/utils/utilstest" + "github.com/ava-labs/avalanchego/utils" ) func TestVerifyStateUpgrades(t *testing.T) { @@ -30,31 +30,31 @@ func TestVerifyStateUpgrades(t *testing.T) { { name: "valid upgrade", upgrades: []StateUpgrade{ - {BlockTimestamp: utils.NewUint64(1), StateUpgradeAccounts: modifiedAccounts}, - {BlockTimestamp: utils.NewUint64(2), StateUpgradeAccounts: modifiedAccounts}, + {BlockTimestamp: utils.PointerTo[uint64](1), StateUpgradeAccounts: modifiedAccounts}, + {BlockTimestamp: utils.PointerTo[uint64](2), StateUpgradeAccounts: modifiedAccounts}, }, expectedError: nil, }, { name: "upgrade block timestamp is not strictly increasing", upgrades: []StateUpgrade{ - {BlockTimestamp: utils.NewUint64(1), StateUpgradeAccounts: modifiedAccounts}, - {BlockTimestamp: utils.NewUint64(1), StateUpgradeAccounts: modifiedAccounts}, + {BlockTimestamp: utils.PointerTo[uint64](1), StateUpgradeAccounts: modifiedAccounts}, + {BlockTimestamp: utils.PointerTo[uint64](1), StateUpgradeAccounts: modifiedAccounts}, }, expectedError: errStateUpgradeTimestampNotMonotonic, }, { name: "upgrade block timestamp decreases", upgrades: []StateUpgrade{ - {BlockTimestamp: utils.NewUint64(2), StateUpgradeAccounts: modifiedAccounts}, - {BlockTimestamp: utils.NewUint64(1), StateUpgradeAccounts: modifiedAccounts}, + {BlockTimestamp: utils.PointerTo[uint64](2), StateUpgradeAccounts: modifiedAccounts}, + {BlockTimestamp: utils.PointerTo[uint64](1), StateUpgradeAccounts: modifiedAccounts}, }, expectedError: errStateUpgradeTimestampNotMonotonic, }, { name: "upgrade block timestamp is zero", upgrades: []StateUpgrade{ - {BlockTimestamp: utils.NewUint64(0), StateUpgradeAccounts: modifiedAccounts}, + {BlockTimestamp: utils.PointerTo[uint64](0), StateUpgradeAccounts: modifiedAccounts}, }, expectedError: errStateUpgradeTimestampZero, }, @@ -88,12 +88,12 @@ func TestCheckCompatibleStateUpgrades(t *testing.T) { configs: []*UpgradeConfig{ { StateUpgrades: []StateUpgrade{ - {BlockTimestamp: utils.NewUint64(6), StateUpgradeAccounts: stateUpgrade}, + {BlockTimestamp: utils.PointerTo[uint64](6), StateUpgradeAccounts: stateUpgrade}, }, }, { StateUpgrades: []StateUpgrade{ - {BlockTimestamp: utils.NewUint64(6), StateUpgradeAccounts: stateUpgrade}, + {BlockTimestamp: utils.PointerTo[uint64](6), StateUpgradeAccounts: stateUpgrade}, }, }, }, @@ -104,14 +104,14 @@ func TestCheckCompatibleStateUpgrades(t *testing.T) { configs: []*UpgradeConfig{ { StateUpgrades: []StateUpgrade{ - {BlockTimestamp: utils.NewUint64(6), StateUpgradeAccounts: stateUpgrade}, - {BlockTimestamp: utils.NewUint64(7), StateUpgradeAccounts: stateUpgrade}, + {BlockTimestamp: utils.PointerTo[uint64](6), StateUpgradeAccounts: stateUpgrade}, + {BlockTimestamp: utils.PointerTo[uint64](7), StateUpgradeAccounts: stateUpgrade}, }, }, { StateUpgrades: []StateUpgrade{ - {BlockTimestamp: utils.NewUint64(6), StateUpgradeAccounts: stateUpgrade}, - {BlockTimestamp: utils.NewUint64(7), StateUpgradeAccounts: differentStateUpgrade}, + {BlockTimestamp: utils.PointerTo[uint64](6), StateUpgradeAccounts: stateUpgrade}, + {BlockTimestamp: utils.PointerTo[uint64](7), StateUpgradeAccounts: differentStateUpgrade}, }, }, }, @@ -121,13 +121,13 @@ func TestCheckCompatibleStateUpgrades(t *testing.T) { configs: []*UpgradeConfig{ { StateUpgrades: []StateUpgrade{ - {BlockTimestamp: utils.NewUint64(6), StateUpgradeAccounts: stateUpgrade}, - {BlockTimestamp: utils.NewUint64(7), StateUpgradeAccounts: stateUpgrade}, + {BlockTimestamp: utils.PointerTo[uint64](6), StateUpgradeAccounts: stateUpgrade}, + {BlockTimestamp: utils.PointerTo[uint64](7), StateUpgradeAccounts: stateUpgrade}, }, }, { StateUpgrades: []StateUpgrade{ - {BlockTimestamp: utils.NewUint64(6), StateUpgradeAccounts: stateUpgrade}, + {BlockTimestamp: utils.PointerTo[uint64](6), StateUpgradeAccounts: stateUpgrade}, }, }, }, @@ -138,7 +138,7 @@ func TestCheckCompatibleStateUpgrades(t *testing.T) { configs: []*UpgradeConfig{ { StateUpgrades: []StateUpgrade{ - {BlockTimestamp: utils.NewUint64(5), StateUpgradeAccounts: stateUpgrade}, + {BlockTimestamp: utils.PointerTo[uint64](5), StateUpgradeAccounts: stateUpgrade}, }, }, }, @@ -171,7 +171,7 @@ func TestUnmarshalStateUpgradeJSON(t *testing.T) { upgradeConfig := UpgradeConfig{ StateUpgrades: []StateUpgrade{ { - BlockTimestamp: utils.NewUint64(1677608400), + BlockTimestamp: utils.PointerTo[uint64](1677608400), StateUpgradeAccounts: map[common.Address]StateUpgradeAccount{ common.HexToAddress("0x8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FC"): { BalanceChange: (*math.HexOrDecimal256)(big.NewInt(100)), diff --git a/graft/subnet-evm/plugin/evm/customheader/base_fee_test.go b/graft/subnet-evm/plugin/evm/customheader/base_fee_test.go index 4f04728f9967..dd3f6f8be525 100644 --- a/graft/subnet-evm/plugin/evm/customheader/base_fee_test.go +++ b/graft/subnet-evm/plugin/evm/customheader/base_fee_test.go @@ -15,6 +15,8 @@ import ( "github.com/ava-labs/avalanchego/graft/subnet-evm/commontype" "github.com/ava-labs/avalanchego/graft/subnet-evm/params/extras" "github.com/ava-labs/avalanchego/graft/subnet-evm/plugin/evm/upgrade/subnetevm" + + avalancheutils "github.com/ava-labs/avalanchego/utils" ) const ( @@ -48,7 +50,7 @@ func BaseFeeTest(t *testing.T, feeConfig commontype.FeeConfig) { { name: "subnet_evm_first_block", upgrades: extras.NetworkUpgrades{ - SubnetEVMTimestamp: utils.NewUint64(1), + SubnetEVMTimestamp: avalancheutils.PointerTo[uint64](1), }, parent: &types.Header{ Number: big.NewInt(1), diff --git a/graft/subnet-evm/plugin/evm/customheader/extra_test.go b/graft/subnet-evm/plugin/evm/customheader/extra_test.go index e3ac7e45a44c..dc95b2e985c5 100644 --- a/graft/subnet-evm/plugin/evm/customheader/extra_test.go +++ b/graft/subnet-evm/plugin/evm/customheader/extra_test.go @@ -11,10 +11,10 @@ import ( "github.com/ava-labs/libevm/core/types" "github.com/stretchr/testify/require" - "github.com/ava-labs/avalanchego/graft/evm/utils" "github.com/ava-labs/avalanchego/graft/subnet-evm/params/extras" "github.com/ava-labs/avalanchego/graft/subnet-evm/plugin/evm/customtypes" "github.com/ava-labs/avalanchego/graft/subnet-evm/plugin/evm/upgrade/subnetevm" + "github.com/ava-labs/avalanchego/utils" ) func TestMain(m *testing.M) { @@ -46,7 +46,7 @@ func TestExtraPrefix(t *testing.T) { { name: "subnet_evm_first_block", upgrades: extras.NetworkUpgrades{ - SubnetEVMTimestamp: utils.NewUint64(1), + SubnetEVMTimestamp: utils.PointerTo[uint64](1), }, parent: &types.Header{ Number: big.NewInt(1), diff --git a/graft/subnet-evm/plugin/evm/customheader/min_delay_excess_test.go b/graft/subnet-evm/plugin/evm/customheader/min_delay_excess_test.go index 875108b683c3..72b454e7a40e 100644 --- a/graft/subnet-evm/plugin/evm/customheader/min_delay_excess_test.go +++ b/graft/subnet-evm/plugin/evm/customheader/min_delay_excess_test.go @@ -9,17 +9,16 @@ import ( "github.com/ava-labs/libevm/core/types" "github.com/stretchr/testify/require" - "github.com/ava-labs/avalanchego/graft/evm/utils" - "github.com/ava-labs/avalanchego/graft/evm/utils/utilstest" "github.com/ava-labs/avalanchego/graft/subnet-evm/params/extras" "github.com/ava-labs/avalanchego/graft/subnet-evm/plugin/evm/customtypes" + "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/vms/evm/acp226" ) func TestMinDelayExcess(t *testing.T) { activatingGraniteConfig := *extras.TestGraniteChainConfig activatingGraniteTimestamp := uint64(1000) - activatingGraniteConfig.NetworkUpgrades.GraniteTimestamp = utils.NewUint64(activatingGraniteTimestamp) + activatingGraniteConfig.NetworkUpgrades.GraniteTimestamp = utils.PointerTo(activatingGraniteTimestamp) tests := []struct { name string @@ -52,7 +51,7 @@ func TestMinDelayExcess(t *testing.T) { header: &types.Header{ Time: 1001, }, - desiredMinDelayExcess: utilstest.PointerTo(acp226.DelayExcess(1000)), + desiredMinDelayExcess: utils.PointerTo(acp226.DelayExcess(1000)), expectedDelayExcess: nil, }, { @@ -65,7 +64,7 @@ func TestMinDelayExcess(t *testing.T) { Time: activatingGraniteTimestamp + 1, }, desiredMinDelayExcess: nil, - expectedDelayExcess: utilstest.PointerTo(acp226.DelayExcess(acp226.InitialDelayExcess)), + expectedDelayExcess: utils.PointerTo(acp226.DelayExcess(acp226.InitialDelayExcess)), }, { name: "granite_no_parent_min_delay_error", @@ -88,7 +87,7 @@ func TestMinDelayExcess(t *testing.T) { Time: 1001, }, desiredMinDelayExcess: nil, - expectedDelayExcess: utilstest.PointerTo(acp226.DelayExcess(500)), + expectedDelayExcess: utils.PointerTo(acp226.DelayExcess(500)), }, { name: "granite_with_desired_min_delay_excess", @@ -97,8 +96,8 @@ func TestMinDelayExcess(t *testing.T) { header: &types.Header{ Time: 1001, }, - desiredMinDelayExcess: utilstest.PointerTo(acp226.DelayExcess(1000)), - expectedDelayExcess: utilstest.PointerTo(acp226.DelayExcess(500 + acp226.MaxDelayExcessDiff)), + desiredMinDelayExcess: utils.PointerTo(acp226.DelayExcess(1000)), + expectedDelayExcess: utils.PointerTo(acp226.DelayExcess(500 + acp226.MaxDelayExcessDiff)), }, { name: "granite_with_zero_desired_value", @@ -107,8 +106,8 @@ func TestMinDelayExcess(t *testing.T) { header: &types.Header{ Time: 1001, }, - desiredMinDelayExcess: utilstest.PointerTo(acp226.DelayExcess(0)), - expectedDelayExcess: utilstest.PointerTo(acp226.DelayExcess(500 - acp226.MaxDelayExcessDiff)), + desiredMinDelayExcess: utils.PointerTo(acp226.DelayExcess(0)), + expectedDelayExcess: utils.PointerTo(acp226.DelayExcess(500 - acp226.MaxDelayExcessDiff)), }, } diff --git a/graft/subnet-evm/plugin/evm/customheader/time_test.go b/graft/subnet-evm/plugin/evm/customheader/time_test.go index c84005265028..dd5f33897f6e 100644 --- a/graft/subnet-evm/plugin/evm/customheader/time_test.go +++ b/graft/subnet-evm/plugin/evm/customheader/time_test.go @@ -10,9 +10,9 @@ import ( "github.com/ava-labs/libevm/core/types" "github.com/stretchr/testify/require" - "github.com/ava-labs/avalanchego/graft/evm/utils" "github.com/ava-labs/avalanchego/graft/subnet-evm/params/extras" "github.com/ava-labs/avalanchego/graft/subnet-evm/plugin/evm/customtypes" + "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/vms/evm/acp226" ) @@ -31,7 +31,7 @@ func TestVerifyTime(t *testing.T) { }{ { name: "pre_granite_time_milliseconds_should_fail", - header: generateHeader(timeSeconds, utils.NewUint64(timeMillis)), + header: generateHeader(timeSeconds, utils.PointerTo(timeMillis)), extraConfig: extras.TestFortunaChainConfig, expectedErr: ErrTimeMillisecondsBeforeGranite, }, @@ -48,23 +48,23 @@ func TestVerifyTime(t *testing.T) { }, { name: "granite_time_milliseconds_matching_time_should_work", - header: generateHeader(timeSeconds, utils.NewUint64(timeSeconds*1000)), + header: generateHeader(timeSeconds, utils.PointerTo(timeSeconds*1000)), extraConfig: extras.TestGraniteChainConfig, }, { name: "granite_time_milliseconds_matching_time_rounded_should_work", - header: generateHeader(timeSeconds, utils.NewUint64(timeMillis)), + header: generateHeader(timeSeconds, utils.PointerTo(timeMillis)), extraConfig: extras.TestGraniteChainConfig, }, { name: "granite_time_milliseconds_less_than_time_should_fail", - header: generateHeader(timeSeconds, utils.NewUint64((timeSeconds-1)*1000)), + header: generateHeader(timeSeconds, utils.PointerTo((timeSeconds-1)*1000)), extraConfig: extras.TestGraniteChainConfig, expectedErr: ErrTimeMillisecondsMismatched, }, { name: "granite_time_milliseconds_greater_than_time_should_fail", - header: generateHeader(timeSeconds, utils.NewUint64((timeSeconds+1)*1000)), + header: generateHeader(timeSeconds, utils.PointerTo((timeSeconds+1)*1000)), extraConfig: extras.TestGraniteChainConfig, expectedErr: ErrTimeMillisecondsMismatched, }, @@ -77,10 +77,10 @@ func TestVerifyTime(t *testing.T) { }, { name: "granite_time_earlier_than_parent_should_fail", - header: generateHeader(timeSeconds, utils.NewUint64(timeSeconds*1000)), + header: generateHeader(timeSeconds, utils.PointerTo(timeSeconds*1000)), parentHeader: generateHeader( timeSeconds+1, - utils.NewUint64((timeSeconds+1)*1000), + utils.PointerTo((timeSeconds+1)*1000), ), extraConfig: extras.TestGraniteChainConfig, expectedErr: errBlockTooOld, @@ -89,11 +89,11 @@ func TestVerifyTime(t *testing.T) { name: "granite_time_milliseconds_earlier_than_parent_should_fail", header: generateHeader( timeSeconds, - utils.NewUint64(timeSeconds*1000), + utils.PointerTo(timeSeconds*1000), ), parentHeader: generateHeader( timeSeconds, - utils.NewUint64(timeSeconds*1000+1), + utils.PointerTo(timeSeconds*1000+1), ), extraConfig: extras.TestGraniteChainConfig, expectedErr: errBlockTooOld, @@ -108,7 +108,7 @@ func TestVerifyTime(t *testing.T) { name: "granite_time_too_far_in_future_should_fail", header: generateHeader( uint64(now.Add(MaxFutureBlockTime).Add(1*time.Second).Unix()), - utils.NewUint64(uint64(now.Add(MaxFutureBlockTime).Add(1*time.Second).UnixMilli())), + utils.PointerTo(uint64(now.Add(MaxFutureBlockTime).Add(1*time.Second).UnixMilli())), ), extraConfig: extras.TestGraniteChainConfig, expectedErr: ErrBlockTooFarInFuture, @@ -117,14 +117,14 @@ func TestVerifyTime(t *testing.T) { name: "granite_time_milliseconds_too_far_in_future_should_fail", header: generateHeader( uint64(now.Add(MaxFutureBlockTime).Unix()), - utils.NewUint64(uint64(now.Add(MaxFutureBlockTime).Add(1*time.Millisecond).UnixMilli())), + utils.PointerTo(uint64(now.Add(MaxFutureBlockTime).Add(1*time.Millisecond).UnixMilli())), ), extraConfig: extras.TestGraniteChainConfig, expectedErr: ErrBlockTooFarInFuture, }, { name: "first_granite_block_should_work", - header: generateHeader(timeSeconds, utils.NewUint64(timeMillis)), + header: generateHeader(timeSeconds, utils.PointerTo(timeMillis)), parentHeader: generateHeader(timeSeconds, nil), extraConfig: extras.TestGraniteChainConfig, }, @@ -139,8 +139,8 @@ func TestVerifyTime(t *testing.T) { name: "granite_first_block_no_parent_min_delay_excess", header: generateHeaderWithMinDelayExcessAndTime( timeSeconds, - utils.NewUint64(timeMillis), - utils.NewUint64(acp226.InitialDelayExcess), + utils.PointerTo(timeMillis), + utils.PointerTo[uint64](acp226.InitialDelayExcess), ), parentHeader: generateHeader(timeSeconds-1, nil), // Pre-Granite parent extraConfig: extras.TestGraniteChainConfig, @@ -149,13 +149,13 @@ func TestVerifyTime(t *testing.T) { name: "granite_initial_delay_met", header: generateHeaderWithMinDelayExcessAndTime( timeSeconds, - utils.NewUint64(timeMillis), - utils.NewUint64(acp226.InitialDelayExcess), + utils.PointerTo(timeMillis), + utils.PointerTo[uint64](acp226.InitialDelayExcess), ), parentHeader: generateHeaderWithMinDelayExcessAndTime( timeSeconds-1, - utils.NewUint64(timeMillis-2000), // 2000 ms is the exact initial delay - utils.NewUint64(acp226.InitialDelayExcess), + utils.PointerTo(timeMillis-2000), // 2000 ms is the exact initial delay + utils.PointerTo[uint64](acp226.InitialDelayExcess), ), extraConfig: extras.TestGraniteChainConfig, }, @@ -163,13 +163,13 @@ func TestVerifyTime(t *testing.T) { name: "granite_initial_delay_not_met", header: generateHeaderWithMinDelayExcessAndTime( timeSeconds, - utils.NewUint64(timeMillis), - utils.NewUint64(acp226.InitialDelayExcess), + utils.PointerTo(timeMillis), + utils.PointerTo[uint64](acp226.InitialDelayExcess), ), parentHeader: generateHeaderWithMinDelayExcessAndTime( timeSeconds-1, - utils.NewUint64(timeMillis-1999), // 1 ms less than required - utils.NewUint64(acp226.InitialDelayExcess), + utils.PointerTo(timeMillis-1999), // 1 ms less than required + utils.PointerTo[uint64](acp226.InitialDelayExcess), ), extraConfig: extras.TestGraniteChainConfig, expectedErr: ErrMinDelayNotMet, @@ -178,13 +178,13 @@ func TestVerifyTime(t *testing.T) { name: "granite_future_timestamp_within_limits", header: generateHeaderWithMinDelayExcessAndTime( timeSeconds+5, // 5 seconds in future - utils.NewUint64(timeMillis+5000), - utils.NewUint64(acp226.InitialDelayExcess), + utils.PointerTo(timeMillis+5000), + utils.PointerTo[uint64](acp226.InitialDelayExcess), ), parentHeader: generateHeaderWithMinDelayExcessAndTime( timeSeconds-1, - utils.NewUint64(timeMillis-2000), - utils.NewUint64(acp226.InitialDelayExcess), + utils.PointerTo(timeMillis-2000), + utils.PointerTo[uint64](acp226.InitialDelayExcess), ), extraConfig: extras.TestGraniteChainConfig, }, @@ -192,13 +192,13 @@ func TestVerifyTime(t *testing.T) { name: "granite_future_timestamp_abuse", header: generateHeaderWithMinDelayExcessAndTime( timeSeconds+15, // 15 seconds in future, exceeds MaxFutureBlockTime - utils.NewUint64(timeMillis+15000), - utils.NewUint64(acp226.InitialDelayExcess), + utils.PointerTo(timeMillis+15000), + utils.PointerTo[uint64](acp226.InitialDelayExcess), ), parentHeader: generateHeaderWithMinDelayExcessAndTime( timeSeconds-1, - utils.NewUint64(timeMillis-2000), - utils.NewUint64(acp226.InitialDelayExcess), + utils.PointerTo(timeMillis-2000), + utils.PointerTo[uint64](acp226.InitialDelayExcess), ), extraConfig: extras.TestGraniteChainConfig, expectedErr: ErrBlockTooFarInFuture, @@ -207,13 +207,13 @@ func TestVerifyTime(t *testing.T) { name: "granite_zero_delay_excess", header: generateHeaderWithMinDelayExcessAndTime( timeSeconds, - utils.NewUint64(timeMillis), - utils.NewUint64(0), + utils.PointerTo(timeMillis), + utils.PointerTo[uint64](0), ), parentHeader: generateHeaderWithMinDelayExcessAndTime( timeSeconds, - utils.NewUint64(timeMillis-1), // 1ms delay, meets zero requirement - utils.NewUint64(0), // Parent has zero delay excess + utils.PointerTo(timeMillis-1), // 1ms delay, meets zero requirement + utils.PointerTo[uint64](0), // Parent has zero delay excess ), extraConfig: extras.TestGraniteChainConfig, }, @@ -221,13 +221,13 @@ func TestVerifyTime(t *testing.T) { name: "granite_zero_delay_excess_but_zero_delay", header: generateHeaderWithMinDelayExcessAndTime( timeSeconds, - utils.NewUint64(timeMillis), - utils.NewUint64(0), + utils.PointerTo(timeMillis), + utils.PointerTo[uint64](0), ), parentHeader: generateHeaderWithMinDelayExcessAndTime( timeSeconds, - utils.NewUint64(timeMillis), // Same timestamp, zero delay - utils.NewUint64(0), // Parent has zero delay excess + utils.PointerTo(timeMillis), // Same timestamp, zero delay + utils.PointerTo[uint64](0), // Parent has zero delay excess ), extraConfig: extras.TestGraniteChainConfig, expectedErr: ErrMinDelayNotMet, @@ -269,7 +269,7 @@ func TestGetNextTimestamp(t *testing.T) { }, { name: "current_time_after_parent_time_with_milliseconds", - parent: generateHeader(nowSeconds-10, utils.NewUint64(nowMillis-500)), + parent: generateHeader(nowSeconds-10, utils.PointerTo(nowMillis-500)), now: now, expectedSec: nowSeconds, expectedMillis: nowMillis, @@ -290,28 +290,28 @@ func TestGetNextTimestamp(t *testing.T) { }, { name: "current_time_before_parent_time_with_milliseconds", - parent: generateHeader(nowSeconds+10, utils.NewUint64(nowMillis)), + parent: generateHeader(nowSeconds+10, utils.PointerTo(nowMillis)), now: now, expectedSec: nowSeconds, expectedMillis: nowMillis, }, { name: "current_time_milliseconds_before_parent_time_milliseconds", - parent: generateHeader(nowSeconds, utils.NewUint64(nowMillis+10)), + parent: generateHeader(nowSeconds, utils.PointerTo(nowMillis+10)), now: now, expectedSec: nowSeconds, expectedMillis: nowMillis, }, { name: "current_time_equals_parent_time_with_milliseconds_granite", - parent: generateHeader(nowSeconds, utils.NewUint64(nowMillis)), + parent: generateHeader(nowSeconds, utils.PointerTo(nowMillis)), now: now, expectedSec: nowSeconds, expectedMillis: nowMillis, }, { name: "current_timesec_equals_parent_time_with_less_milliseconds", - parent: generateHeader(nowSeconds, utils.NewUint64(nowMillis-10)), + parent: generateHeader(nowSeconds, utils.PointerTo(nowMillis-10)), now: now, expectedSec: nowSeconds, expectedMillis: nowMillis, diff --git a/graft/subnet-evm/plugin/evm/customtypes/block_ext_test.go b/graft/subnet-evm/plugin/evm/customtypes/block_ext_test.go index ba6a7f92b63d..7c82319b559b 100644 --- a/graft/subnet-evm/plugin/evm/customtypes/block_ext_test.go +++ b/graft/subnet-evm/plugin/evm/customtypes/block_ext_test.go @@ -12,9 +12,8 @@ import ( "github.com/ava-labs/libevm/common" "github.com/stretchr/testify/require" - "github.com/ava-labs/avalanchego/graft/evm/utils" - "github.com/ava-labs/avalanchego/graft/evm/utils/utilstest" "github.com/ava-labs/avalanchego/graft/subnet-evm/internal/blocktest" + "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/vms/evm/acp226" ) @@ -37,12 +36,12 @@ func TestBlockGetters(t *testing.T) { name: "fields_set", headerExtra: &HeaderExtra{ BlockGasCost: big.NewInt(2), - TimeMilliseconds: utils.NewUint64(3), - MinDelayExcess: utilstest.PointerTo(acp226.DelayExcess(4)), + TimeMilliseconds: utils.PointerTo[uint64](3), + MinDelayExcess: utils.PointerTo(acp226.DelayExcess(4)), }, wantBlockGasCost: big.NewInt(2), - wantTimeMilliseconds: utils.NewUint64(3), - wantMinDelayExcess: utilstest.PointerTo(acp226.DelayExcess(4)), + wantTimeMilliseconds: utils.PointerTo[uint64](3), + wantMinDelayExcess: utils.PointerTo(acp226.DelayExcess(4)), }, } for _, test := range tests { diff --git a/graft/subnet-evm/plugin/evm/customtypes/header_ext_test.go b/graft/subnet-evm/plugin/evm/customtypes/header_ext_test.go index bdde73c208f9..58361bc3b080 100644 --- a/graft/subnet-evm/plugin/evm/customtypes/header_ext_test.go +++ b/graft/subnet-evm/plugin/evm/customtypes/header_ext_test.go @@ -17,7 +17,7 @@ import ( "github.com/ava-labs/libevm/rlp" "github.com/stretchr/testify/require" - "github.com/ava-labs/avalanchego/graft/evm/utils/utilstest" + "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/vms/evm/acp226" ) @@ -112,14 +112,14 @@ func headerWithNonZeroFields() (*Header, *HeaderExtra) { Nonce: BlockNonce{15}, BaseFee: big.NewInt(16), WithdrawalsHash: &common.Hash{17}, - BlobGasUsed: utilstest.PointerTo(uint64(18)), - ExcessBlobGas: utilstest.PointerTo(uint64(19)), + BlobGasUsed: utils.PointerTo[uint64](18), + ExcessBlobGas: utils.PointerTo[uint64](19), ParentBeaconRoot: &common.Hash{20}, } extra := &HeaderExtra{ BlockGasCost: big.NewInt(23), - TimeMilliseconds: utilstest.PointerTo(uint64(24)), - MinDelayExcess: utilstest.PointerTo(acp226.DelayExcess(25)), + TimeMilliseconds: utils.PointerTo[uint64](24), + MinDelayExcess: utils.PointerTo(acp226.DelayExcess(25)), } return WithHeaderExtra(header, extra), extra } diff --git a/graft/subnet-evm/plugin/evm/vm_test.go b/graft/subnet-evm/plugin/evm/vm_test.go index 18f6868b9814..4098f0191f3a 100644 --- a/graft/subnet-evm/plugin/evm/vm_test.go +++ b/graft/subnet-evm/plugin/evm/vm_test.go @@ -71,6 +71,7 @@ import ( warpcontract "github.com/ava-labs/avalanchego/graft/subnet-evm/precompile/contracts/warp" commonEng "github.com/ava-labs/avalanchego/snow/engine/common" + avalancheutils "github.com/ava-labs/avalanchego/utils" avagoconstants "github.com/ava-labs/avalanchego/utils/constants" avalancheWarp "github.com/ava-labs/avalanchego/vms/platformvm/warp" ) @@ -1481,13 +1482,13 @@ func TestTimeSemanticVerify(t *testing.T) { name: "Granite with TimeMilliseconds", fork: upgradetest.Granite, timeSeconds: uint64(timestamp.Unix()), - timeMilliseconds: utils.NewUint64(uint64(timestamp.UnixMilli())), + timeMilliseconds: avalancheutils.PointerTo(uint64(timestamp.UnixMilli())), }, { name: "Fortuna with TimeMilliseconds", fork: upgradetest.Fortuna, timeSeconds: uint64(timestamp.Unix()), - timeMilliseconds: utils.NewUint64(uint64(timestamp.UnixMilli())), + timeMilliseconds: avalancheutils.PointerTo(uint64(timestamp.UnixMilli())), expectedError: customheader.ErrTimeMillisecondsBeforeGranite, }, { @@ -1501,14 +1502,14 @@ func TestTimeSemanticVerify(t *testing.T) { name: "Granite with mismatched TimeMilliseconds", fork: upgradetest.Granite, timeSeconds: uint64(timestamp.Unix()), - timeMilliseconds: utils.NewUint64(uint64(timestamp.UnixMilli()) + 1000), + timeMilliseconds: avalancheutils.PointerTo(uint64(timestamp.UnixMilli()) + 1000), expectedError: customheader.ErrTimeMillisecondsMismatched, }, { name: "Block too far in the future", fork: upgradetest.Granite, timeSeconds: uint64(timestamp.Add(2 * time.Hour).Unix()), - timeMilliseconds: utils.NewUint64(uint64(timestamp.Add(2 * time.Hour).UnixMilli())), + timeMilliseconds: avalancheutils.PointerTo(uint64(timestamp.Add(2 * time.Hour).UnixMilli())), expectedError: customheader.ErrBlockTooFarInFuture, }, } @@ -1584,7 +1585,7 @@ func TestBuildTimeMilliseconds(t *testing.T) { { name: "granite_should_have_timestamp_milliseconds", fork: upgradetest.Granite, - expectedTimeMilliseconds: utils.NewUint64(uint64(buildTime.UnixMilli())), + expectedTimeMilliseconds: avalancheutils.PointerTo(uint64(buildTime.UnixMilli())), }, } @@ -1744,7 +1745,7 @@ func TestTxAllowListSuccessfulTx(t *testing.T) { require.NoError(t, genesis.UnmarshalJSON([]byte(toGenesisJSON(paramstest.ForkToChainConfig[upgradetest.Durango])))) // this manager role should not be activated because DurangoTimestamp is in the future params.GetExtra(genesis.Config).GenesisPrecompiles = extras.Precompiles{ - txallowlist.ConfigKey: txallowlist.NewConfig(utils.NewUint64(0), testEthAddrs[0:1], nil, nil), + txallowlist.ConfigKey: txallowlist.NewConfig(avalancheutils.PointerTo[uint64](0), testEthAddrs[0:1], nil, nil), } durangoTime := time.Now().Add(10 * time.Hour) params.GetExtra(genesis.Config).DurangoTimestamp = utils.TimeToNewUint64(durangoTime) @@ -1887,7 +1888,7 @@ func TestVerifyManagerConfig(t *testing.T) { params.GetExtra(genesis.Config).DurangoTimestamp = utils.TimeToNewUint64(durangoTimestamp) // this manager role should not be activated because DurangoTimestamp is in the future params.GetExtra(genesis.Config).GenesisPrecompiles = extras.Precompiles{ - txallowlist.ConfigKey: txallowlist.NewConfig(utils.NewUint64(0), testEthAddrs[0:1], nil, []common.Address{testEthAddrs[1]}), + txallowlist.ConfigKey: txallowlist.NewConfig(avalancheutils.PointerTo[uint64](0), testEthAddrs[0:1], nil, []common.Address{testEthAddrs[1]}), } genesisJSON, err := genesis.MarshalJSON() @@ -2039,7 +2040,7 @@ func TestFeeManagerChangeFee(t *testing.T) { require.NoError(t, genesis.UnmarshalJSON([]byte(genesisJSONSubnetEVM))) configExtra := params.GetExtra(genesis.Config) configExtra.GenesisPrecompiles = extras.Precompiles{ - feemanager.ConfigKey: feemanager.NewConfig(utils.NewUint64(0), testEthAddrs[0:1], nil, nil, nil), + feemanager.ConfigKey: feemanager.NewConfig(avalancheutils.PointerTo[uint64](0), testEthAddrs[0:1], nil, nil, nil), } // set a lower fee config now @@ -2255,7 +2256,7 @@ func TestRewardManagerPrecompileSetRewardAddress(t *testing.T) { require.NoError(t, genesis.UnmarshalJSON([]byte(genesisJSONSubnetEVM))) params.GetExtra(genesis.Config).GenesisPrecompiles = extras.Precompiles{ - rewardmanager.ConfigKey: rewardmanager.NewConfig(utils.NewUint64(0), testEthAddrs[0:1], nil, nil, nil), + rewardmanager.ConfigKey: rewardmanager.NewConfig(avalancheutils.PointerTo[uint64](0), testEthAddrs[0:1], nil, nil, nil), } params.GetExtra(genesis.Config).AllowFeeRecipients = true // enable this in genesis to test if this is recognized by the reward manager genesisJSON, err := genesis.MarshalJSON() @@ -2399,7 +2400,7 @@ func TestRewardManagerPrecompileAllowFeeRecipients(t *testing.T) { require.NoError(t, genesis.UnmarshalJSON([]byte(genesisJSONSubnetEVM))) params.GetExtra(genesis.Config).GenesisPrecompiles = extras.Precompiles{ - rewardmanager.ConfigKey: rewardmanager.NewConfig(utils.NewUint64(0), testEthAddrs[0:1], nil, nil, nil), + rewardmanager.ConfigKey: rewardmanager.NewConfig(avalancheutils.PointerTo[uint64](0), testEthAddrs[0:1], nil, nil, nil), } params.GetExtra(genesis.Config).AllowFeeRecipients = false // disable this in genesis genesisJSON, err := genesis.MarshalJSON() @@ -2735,7 +2736,7 @@ func TestFeeManagerRegressionMempoolMinFeeAfterRestart(t *testing.T) { // Setup chain params genesis := &core.Genesis{} require.NoError(t, genesis.UnmarshalJSON([]byte(genesisJSONSubnetEVM))) - precompileActivationTime := utils.NewUint64(genesis.Timestamp + 5) // 5 seconds after genesis + precompileActivationTime := avalancheutils.PointerTo(genesis.Timestamp + 5) // 5 seconds after genesis configExtra := params.GetExtra(genesis.Config) configExtra.GenesisPrecompiles = extras.Precompiles{ feemanager.ConfigKey: feemanager.NewConfig(precompileActivationTime, testEthAddrs[0:1], nil, nil, nil), @@ -3584,26 +3585,26 @@ func TestMinDelayExcessInHeader(t *testing.T) { { name: "pre_granite_min_delay_excess", fork: upgradetest.Fortuna, - desiredMinDelay: utils.NewUint64(1000), + desiredMinDelay: avalancheutils.PointerTo[uint64](1000), expectedMinDelayExcess: nil, }, { name: "granite_first_block_initial_delay_excess", fork: upgradetest.Granite, desiredMinDelay: nil, - expectedMinDelayExcess: utilstest.PointerTo(acp226.DelayExcess(acp226.InitialDelayExcess)), + expectedMinDelayExcess: avalancheutils.PointerTo(acp226.DelayExcess(acp226.InitialDelayExcess)), }, { name: "granite_with_excessive_desired_min_delay_excess", fork: upgradetest.Granite, - desiredMinDelay: utils.NewUint64(4000), - expectedMinDelayExcess: utilstest.PointerTo(acp226.DelayExcess(acp226.InitialDelayExcess + acp226.MaxDelayExcessDiff)), + desiredMinDelay: avalancheutils.PointerTo[uint64](4000), + expectedMinDelayExcess: avalancheutils.PointerTo(acp226.DelayExcess(acp226.InitialDelayExcess + acp226.MaxDelayExcessDiff)), }, { name: "granite_with_zero_desired_min_delay_excess", fork: upgradetest.Granite, - desiredMinDelay: utils.NewUint64(0), - expectedMinDelayExcess: utilstest.PointerTo(acp226.DelayExcess(acp226.InitialDelayExcess - acp226.MaxDelayExcessDiff)), + desiredMinDelay: avalancheutils.PointerTo[uint64](0), + expectedMinDelayExcess: avalancheutils.PointerTo(acp226.DelayExcess(acp226.InitialDelayExcess - acp226.MaxDelayExcessDiff)), }, } diff --git a/graft/subnet-evm/plugin/evm/vm_upgrade_bytes_test.go b/graft/subnet-evm/plugin/evm/vm_upgrade_bytes_test.go index d96b7167d1d0..5b7919770dff 100644 --- a/graft/subnet-evm/plugin/evm/vm_upgrade_bytes_test.go +++ b/graft/subnet-evm/plugin/evm/vm_upgrade_bytes_test.go @@ -32,6 +32,7 @@ import ( "github.com/ava-labs/avalanchego/vms/components/chain" commonEng "github.com/ava-labs/avalanchego/snow/engine/common" + avalancheutils "github.com/ava-labs/avalanchego/utils" ) func TestVMUpgradeBytesPrecompile(t *testing.T) { @@ -142,7 +143,7 @@ func TestNetworkUpgradesOverridden(t *testing.T) { fork := upgradetest.Granite chainConfig := paramstest.ForkToChainConfig[fork] extraConfig := params.GetExtra(chainConfig) - extraConfig.NetworkUpgrades.GraniteTimestamp = utils.NewUint64(uint64(upgrade.InitiallyActiveTime.Unix())) + extraConfig.NetworkUpgrades.GraniteTimestamp = avalancheutils.PointerTo(uint64(upgrade.InitiallyActiveTime.Unix())) genesis := &core.Genesis{} require.NoError(t, json.Unmarshal([]byte(toGenesisJSON(chainConfig)), genesis)) // Set the genesis timestamp to before the Granite activation time @@ -351,7 +352,7 @@ func TestVMEtnaActivatesCancun(t *testing.T) { upgradeJSON: func() string { upgrade := &extras.UpgradeConfig{ NetworkUpgradeOverrides: &extras.NetworkUpgrades{ - EtnaTimestamp: utils.NewUint64(defaultEtnaTime + 2), + EtnaTimestamp: avalancheutils.PointerTo(defaultEtnaTime + 2), }, } b, err := json.Marshal(upgrade) diff --git a/graft/subnet-evm/precompile/allowlist/allowlisttest/test_allowlist_config.go b/graft/subnet-evm/precompile/allowlist/allowlisttest/test_allowlist_config.go index dc63f2e4c42c..66e14d53b92b 100644 --- a/graft/subnet-evm/precompile/allowlist/allowlisttest/test_allowlist_config.go +++ b/graft/subnet-evm/precompile/allowlist/allowlisttest/test_allowlist_config.go @@ -11,11 +11,11 @@ import ( "github.com/stretchr/testify/require" "go.uber.org/mock/gomock" - "github.com/ava-labs/avalanchego/graft/evm/utils" "github.com/ava-labs/avalanchego/graft/subnet-evm/precompile/allowlist" "github.com/ava-labs/avalanchego/graft/subnet-evm/precompile/modules" "github.com/ava-labs/avalanchego/graft/subnet-evm/precompile/precompileconfig" "github.com/ava-labs/avalanchego/graft/subnet-evm/precompile/precompiletest" + "github.com/ava-labs/avalanchego/utils" ) // mkConfigWithAllowList creates a new config with the correct type for [module] @@ -105,7 +105,7 @@ func AllowListConfigVerifyTests(t testing.TB, module modules.Module) map[string] ManagerAddresses: []common.Address{TestManagerAddr}, EnabledAddresses: nil, }, precompileconfig.Upgrade{ - BlockTimestamp: utils.NewUint64(1), + BlockTimestamp: utils.PointerTo[uint64](1), }), ChainConfig: func() precompileconfig.ChainConfig { config := precompileconfig.NewMockChainConfig(gomock.NewController(t)) diff --git a/graft/subnet-evm/precompile/contracts/deployerallowlist/config_test.go b/graft/subnet-evm/precompile/contracts/deployerallowlist/config_test.go index 20fcbb4377a4..5d2b45b8d677 100644 --- a/graft/subnet-evm/precompile/contracts/deployerallowlist/config_test.go +++ b/graft/subnet-evm/precompile/contracts/deployerallowlist/config_test.go @@ -9,11 +9,11 @@ import ( "github.com/ava-labs/libevm/common" "go.uber.org/mock/gomock" - "github.com/ava-labs/avalanchego/graft/evm/utils" "github.com/ava-labs/avalanchego/graft/subnet-evm/precompile/allowlist/allowlisttest" "github.com/ava-labs/avalanchego/graft/subnet-evm/precompile/contracts/deployerallowlist" "github.com/ava-labs/avalanchego/graft/subnet-evm/precompile/precompileconfig" "github.com/ava-labs/avalanchego/graft/subnet-evm/precompile/precompiletest" + "github.com/ava-labs/avalanchego/utils" ) func TestVerify(t *testing.T) { @@ -26,7 +26,7 @@ func TestEqual(t *testing.T) { managers := []common.Address{allowlisttest.TestManagerAddr} tests := map[string]precompiletest.ConfigEqualTest{ "non-nil config and nil other": { - Config: deployerallowlist.NewConfig(utils.NewUint64(3), admins, enableds, managers), + Config: deployerallowlist.NewConfig(utils.PointerTo[uint64](3), admins, enableds, managers), Other: nil, Expected: false, }, @@ -36,13 +36,13 @@ func TestEqual(t *testing.T) { Expected: false, }, "different timestamp": { - Config: deployerallowlist.NewConfig(utils.NewUint64(3), admins, enableds, managers), - Other: deployerallowlist.NewConfig(utils.NewUint64(4), admins, enableds, managers), + Config: deployerallowlist.NewConfig(utils.PointerTo[uint64](3), admins, enableds, managers), + Other: deployerallowlist.NewConfig(utils.PointerTo[uint64](4), admins, enableds, managers), Expected: false, }, "same config": { - Config: deployerallowlist.NewConfig(utils.NewUint64(3), admins, enableds, managers), - Other: deployerallowlist.NewConfig(utils.NewUint64(3), admins, enableds, managers), + Config: deployerallowlist.NewConfig(utils.PointerTo[uint64](3), admins, enableds, managers), + Other: deployerallowlist.NewConfig(utils.PointerTo[uint64](3), admins, enableds, managers), Expected: true, }, } diff --git a/graft/subnet-evm/precompile/contracts/deployerallowlist/simulated_test.go b/graft/subnet-evm/precompile/contracts/deployerallowlist/simulated_test.go index ed4e49f4691b..77444f50877f 100644 --- a/graft/subnet-evm/precompile/contracts/deployerallowlist/simulated_test.go +++ b/graft/subnet-evm/precompile/contracts/deployerallowlist/simulated_test.go @@ -11,7 +11,6 @@ import ( "github.com/ava-labs/libevm/crypto" "github.com/stretchr/testify/require" - "github.com/ava-labs/avalanchego/graft/evm/utils" "github.com/ava-labs/avalanchego/graft/subnet-evm/accounts/abi/bind" "github.com/ava-labs/avalanchego/graft/subnet-evm/core" "github.com/ava-labs/avalanchego/graft/subnet-evm/params" @@ -20,6 +19,7 @@ import ( "github.com/ava-labs/avalanchego/graft/subnet-evm/precompile/allowlist/allowlisttest" "github.com/ava-labs/avalanchego/graft/subnet-evm/precompile/contracts/deployerallowlist" "github.com/ava-labs/avalanchego/graft/subnet-evm/precompile/contracts/utilstest" + "github.com/ava-labs/avalanchego/utils" sim "github.com/ava-labs/avalanchego/graft/subnet-evm/ethclient/simulated" allowlistbindings "github.com/ava-labs/avalanchego/graft/subnet-evm/precompile/allowlist/allowlisttest/bindings" @@ -182,7 +182,7 @@ func TestDeployerAllowList(t *testing.T) { }, } - precompileCfg := deployerallowlist.NewConfig(utils.NewUint64(0), []common.Address{adminAddress}, nil, nil) + precompileCfg := deployerallowlist.NewConfig(utils.PointerTo[uint64](0), []common.Address{adminAddress}, nil, nil) for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { backend := utilstest.NewBackendWithPrecompile(t, precompileCfg, []common.Address{adminAddress, unprivilegedAddress}) @@ -197,7 +197,7 @@ func TestDeployerAllowList(t *testing.T) { } func TestIAllowList_Events(t *testing.T) { - precompileCfg := deployerallowlist.NewConfig(utils.NewUint64(0), []common.Address{adminAddress}, nil, nil) + precompileCfg := deployerallowlist.NewConfig(utils.PointerTo[uint64](0), []common.Address{adminAddress}, nil, nil) admin := utilstest.NewAuth(t, adminKey, params.TestChainConfig.ChainID) allowlisttest.RunAllowListEventTests(t, precompileCfg, deployerallowlist.ContractAddress, admin, adminAddress, unprivilegedAddress) } diff --git a/graft/subnet-evm/precompile/contracts/feemanager/config_test.go b/graft/subnet-evm/precompile/contracts/feemanager/config_test.go index 53d93d7bfad9..7fcf6ed9eb68 100644 --- a/graft/subnet-evm/precompile/contracts/feemanager/config_test.go +++ b/graft/subnet-evm/precompile/contracts/feemanager/config_test.go @@ -10,12 +10,12 @@ import ( "github.com/ava-labs/libevm/common" "go.uber.org/mock/gomock" - "github.com/ava-labs/avalanchego/graft/evm/utils" "github.com/ava-labs/avalanchego/graft/subnet-evm/commontype" "github.com/ava-labs/avalanchego/graft/subnet-evm/precompile/allowlist/allowlisttest" "github.com/ava-labs/avalanchego/graft/subnet-evm/precompile/contracts/feemanager" "github.com/ava-labs/avalanchego/graft/subnet-evm/precompile/precompileconfig" "github.com/ava-labs/avalanchego/graft/subnet-evm/precompile/precompiletest" + "github.com/ava-labs/avalanchego/utils" ) var validFeeConfig = commontype.FeeConfig{ @@ -37,11 +37,11 @@ func TestVerify(t *testing.T) { invalidFeeConfig.GasLimit = big.NewInt(0) tests := map[string]precompiletest.ConfigVerifyTest{ "invalid initial fee manager config": { - Config: feemanager.NewConfig(utils.NewUint64(3), admins, nil, nil, &invalidFeeConfig), + Config: feemanager.NewConfig(utils.PointerTo[uint64](3), admins, nil, nil, &invalidFeeConfig), ExpectedError: commontype.ErrGasLimitTooLow, }, "nil initial fee manager config": { - Config: feemanager.NewConfig(utils.NewUint64(3), admins, nil, nil, &commontype.FeeConfig{}), + Config: feemanager.NewConfig(utils.PointerTo[uint64](3), admins, nil, nil, &commontype.FeeConfig{}), ExpectedError: commontype.ErrGasLimitNil, }, } @@ -53,28 +53,28 @@ func TestEqual(t *testing.T) { enableds := []common.Address{allowlisttest.TestEnabledAddr} tests := map[string]precompiletest.ConfigEqualTest{ "non-nil config and nil other": { - Config: feemanager.NewConfig(utils.NewUint64(3), admins, enableds, nil, nil), + Config: feemanager.NewConfig(utils.PointerTo[uint64](3), admins, enableds, nil, nil), Other: nil, Expected: false, }, "different type": { - Config: feemanager.NewConfig(utils.NewUint64(3), admins, enableds, nil, nil), + Config: feemanager.NewConfig(utils.PointerTo[uint64](3), admins, enableds, nil, nil), Other: precompileconfig.NewMockConfig(gomock.NewController(t)), Expected: false, }, "different timestamp": { - Config: feemanager.NewConfig(utils.NewUint64(3), admins, nil, nil, nil), - Other: feemanager.NewConfig(utils.NewUint64(4), admins, nil, nil, nil), + Config: feemanager.NewConfig(utils.PointerTo[uint64](3), admins, nil, nil, nil), + Other: feemanager.NewConfig(utils.PointerTo[uint64](4), admins, nil, nil, nil), Expected: false, }, "non-nil initial config and nil initial config": { - Config: feemanager.NewConfig(utils.NewUint64(3), admins, nil, nil, &validFeeConfig), - Other: feemanager.NewConfig(utils.NewUint64(3), admins, nil, nil, nil), + Config: feemanager.NewConfig(utils.PointerTo[uint64](3), admins, nil, nil, &validFeeConfig), + Other: feemanager.NewConfig(utils.PointerTo[uint64](3), admins, nil, nil, nil), Expected: false, }, "different initial config": { - Config: feemanager.NewConfig(utils.NewUint64(3), admins, nil, nil, &validFeeConfig), - Other: feemanager.NewConfig(utils.NewUint64(3), admins, nil, nil, + Config: feemanager.NewConfig(utils.PointerTo[uint64](3), admins, nil, nil, &validFeeConfig), + Other: feemanager.NewConfig(utils.PointerTo[uint64](3), admins, nil, nil, func() *commontype.FeeConfig { c := validFeeConfig c.GasLimit = big.NewInt(123) @@ -83,8 +83,8 @@ func TestEqual(t *testing.T) { Expected: false, }, "same config": { - Config: feemanager.NewConfig(utils.NewUint64(3), admins, nil, nil, &validFeeConfig), - Other: feemanager.NewConfig(utils.NewUint64(3), admins, nil, nil, &validFeeConfig), + Config: feemanager.NewConfig(utils.PointerTo[uint64](3), admins, nil, nil, &validFeeConfig), + Other: feemanager.NewConfig(utils.PointerTo[uint64](3), admins, nil, nil, &validFeeConfig), Expected: true, }, } diff --git a/graft/subnet-evm/precompile/contracts/feemanager/simulated_test.go b/graft/subnet-evm/precompile/contracts/feemanager/simulated_test.go index 8597caae0edc..ef4a706bc3ab 100644 --- a/graft/subnet-evm/precompile/contracts/feemanager/simulated_test.go +++ b/graft/subnet-evm/precompile/contracts/feemanager/simulated_test.go @@ -13,7 +13,6 @@ import ( "github.com/ava-labs/libevm/crypto" "github.com/stretchr/testify/require" - "github.com/ava-labs/avalanchego/graft/evm/utils" "github.com/ava-labs/avalanchego/graft/subnet-evm/accounts/abi/bind" "github.com/ava-labs/avalanchego/graft/subnet-evm/commontype" "github.com/ava-labs/avalanchego/graft/subnet-evm/core" @@ -24,6 +23,7 @@ import ( "github.com/ava-labs/avalanchego/graft/subnet-evm/precompile/allowlist/allowlisttest" "github.com/ava-labs/avalanchego/graft/subnet-evm/precompile/contracts/feemanager" "github.com/ava-labs/avalanchego/graft/subnet-evm/precompile/contracts/utilstest" + "github.com/ava-labs/avalanchego/utils" sim "github.com/ava-labs/avalanchego/graft/subnet-evm/ethclient/simulated" feemanagerbindings "github.com/ava-labs/avalanchego/graft/subnet-evm/precompile/contracts/feemanager/feemanagertest/bindings" @@ -233,7 +233,7 @@ func TestFeeManager(t *testing.T) { }, } - precompileCfg := feemanager.NewConfig(utils.NewUint64(0), []common.Address{adminAddress}, nil, nil, &genesisFeeConfig) + precompileCfg := feemanager.NewConfig(utils.PointerTo[uint64](0), []common.Address{adminAddress}, nil, nil, &genesisFeeConfig) for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { backend := utilstest.NewBackendWithPrecompile(t, precompileCfg, []common.Address{adminAddress, unprivilegedAddress}) @@ -251,7 +251,7 @@ func TestIFeeManager_Events(t *testing.T) { chainID := params.TestChainConfig.ChainID admin := utilstest.NewAuth(t, adminKey, chainID) - precompileCfg := feemanager.NewConfig(utils.NewUint64(0), []common.Address{adminAddress}, nil, nil, &genesisFeeConfig) + precompileCfg := feemanager.NewConfig(utils.PointerTo[uint64](0), []common.Address{adminAddress}, nil, nil, &genesisFeeConfig) backend := utilstest.NewBackendWithPrecompile(t, precompileCfg, []common.Address{adminAddress, unprivilegedAddress}) defer backend.Close() diff --git a/graft/subnet-evm/precompile/contracts/nativeminter/config_test.go b/graft/subnet-evm/precompile/contracts/nativeminter/config_test.go index b3f390d419a8..ac94cc8f792f 100644 --- a/graft/subnet-evm/precompile/contracts/nativeminter/config_test.go +++ b/graft/subnet-evm/precompile/contracts/nativeminter/config_test.go @@ -10,12 +10,12 @@ import ( "github.com/ava-labs/libevm/common/math" "go.uber.org/mock/gomock" - "github.com/ava-labs/avalanchego/graft/evm/utils" "github.com/ava-labs/avalanchego/graft/subnet-evm/precompile/allowlist" "github.com/ava-labs/avalanchego/graft/subnet-evm/precompile/allowlist/allowlisttest" "github.com/ava-labs/avalanchego/graft/subnet-evm/precompile/contracts/nativeminter" "github.com/ava-labs/avalanchego/graft/subnet-evm/precompile/precompileconfig" "github.com/ava-labs/avalanchego/graft/subnet-evm/precompile/precompiletest" + "github.com/ava-labs/avalanchego/utils" ) func TestVerify(t *testing.T) { @@ -24,7 +24,7 @@ func TestVerify(t *testing.T) { managers := []common.Address{allowlisttest.TestManagerAddr} tests := map[string]precompiletest.ConfigVerifyTest{ "valid config": { - Config: nativeminter.NewConfig(utils.NewUint64(3), admins, enableds, managers, nil), + Config: nativeminter.NewConfig(utils.PointerTo[uint64](3), admins, enableds, managers, nil), ChainConfig: func() precompileconfig.ChainConfig { config := precompileconfig.NewMockChainConfig(gomock.NewController(t)) config.EXPECT().IsDurango(gomock.Any()).Return(true).AnyTimes() @@ -33,19 +33,19 @@ func TestVerify(t *testing.T) { ExpectedError: nil, }, "invalid allow list config in native minter allowlisttest": { - Config: nativeminter.NewConfig(utils.NewUint64(3), admins, admins, nil, nil), + Config: nativeminter.NewConfig(utils.PointerTo[uint64](3), admins, admins, nil, nil), ExpectedError: allowlist.ErrAdminAndEnabledAddress, }, "duplicate admins in config in native minter allowlisttest": { - Config: nativeminter.NewConfig(utils.NewUint64(3), append(admins, admins[0]), enableds, managers, nil), + Config: nativeminter.NewConfig(utils.PointerTo[uint64](3), append(admins, admins[0]), enableds, managers, nil), ExpectedError: allowlist.ErrDuplicateAdminAddress, }, "duplicate enableds in config in native minter allowlisttest": { - Config: nativeminter.NewConfig(utils.NewUint64(3), admins, append(enableds, enableds[0]), managers, nil), + Config: nativeminter.NewConfig(utils.PointerTo[uint64](3), admins, append(enableds, enableds[0]), managers, nil), ExpectedError: allowlist.ErrDuplicateEnabledAddress, }, "nil amount in native minter config": { - Config: nativeminter.NewConfig(utils.NewUint64(3), admins, nil, nil, + Config: nativeminter.NewConfig(utils.PointerTo[uint64](3), admins, nil, nil, map[common.Address]*math.HexOrDecimal256{ common.HexToAddress("0x01"): math.NewHexOrDecimal256(123), common.HexToAddress("0x02"): nil, @@ -53,7 +53,7 @@ func TestVerify(t *testing.T) { ExpectedError: nativeminter.ErrInitialMintNilAmount, }, "negative amount in native minter config": { - Config: nativeminter.NewConfig(utils.NewUint64(3), admins, nil, nil, + Config: nativeminter.NewConfig(utils.PointerTo[uint64](3), admins, nil, nil, map[common.Address]*math.HexOrDecimal256{ common.HexToAddress("0x01"): math.NewHexOrDecimal256(123), common.HexToAddress("0x02"): math.NewHexOrDecimal256(-1), @@ -70,48 +70,48 @@ func TestEqual(t *testing.T) { managers := []common.Address{allowlisttest.TestManagerAddr} tests := map[string]precompiletest.ConfigEqualTest{ "non-nil config and nil other": { - Config: nativeminter.NewConfig(utils.NewUint64(3), admins, enableds, managers, nil), + Config: nativeminter.NewConfig(utils.PointerTo[uint64](3), admins, enableds, managers, nil), Other: nil, Expected: false, }, "different type": { - Config: nativeminter.NewConfig(utils.NewUint64(3), admins, enableds, managers, nil), + Config: nativeminter.NewConfig(utils.PointerTo[uint64](3), admins, enableds, managers, nil), Other: precompileconfig.NewMockConfig(gomock.NewController(t)), Expected: false, }, "different timestamp": { - Config: nativeminter.NewConfig(utils.NewUint64(3), admins, nil, nil, nil), - Other: nativeminter.NewConfig(utils.NewUint64(4), admins, nil, nil, nil), + Config: nativeminter.NewConfig(utils.PointerTo[uint64](3), admins, nil, nil, nil), + Other: nativeminter.NewConfig(utils.PointerTo[uint64](4), admins, nil, nil, nil), Expected: false, }, "different initial mint amounts": { - Config: nativeminter.NewConfig(utils.NewUint64(3), admins, nil, nil, + Config: nativeminter.NewConfig(utils.PointerTo[uint64](3), admins, nil, nil, map[common.Address]*math.HexOrDecimal256{ common.HexToAddress("0x01"): math.NewHexOrDecimal256(1), }), - Other: nativeminter.NewConfig(utils.NewUint64(3), admins, nil, nil, + Other: nativeminter.NewConfig(utils.PointerTo[uint64](3), admins, nil, nil, map[common.Address]*math.HexOrDecimal256{ common.HexToAddress("0x01"): math.NewHexOrDecimal256(2), }), Expected: false, }, "different initial mint addresses": { - Config: nativeminter.NewConfig(utils.NewUint64(3), admins, nil, nil, + Config: nativeminter.NewConfig(utils.PointerTo[uint64](3), admins, nil, nil, map[common.Address]*math.HexOrDecimal256{ common.HexToAddress("0x01"): math.NewHexOrDecimal256(1), }), - Other: nativeminter.NewConfig(utils.NewUint64(3), admins, nil, nil, + Other: nativeminter.NewConfig(utils.PointerTo[uint64](3), admins, nil, nil, map[common.Address]*math.HexOrDecimal256{ common.HexToAddress("0x02"): math.NewHexOrDecimal256(1), }), Expected: false, }, "same config": { - Config: nativeminter.NewConfig(utils.NewUint64(3), admins, nil, nil, + Config: nativeminter.NewConfig(utils.PointerTo[uint64](3), admins, nil, nil, map[common.Address]*math.HexOrDecimal256{ common.HexToAddress("0x01"): math.NewHexOrDecimal256(1), }), - Other: nativeminter.NewConfig(utils.NewUint64(3), admins, nil, nil, + Other: nativeminter.NewConfig(utils.PointerTo[uint64](3), admins, nil, nil, map[common.Address]*math.HexOrDecimal256{ common.HexToAddress("0x01"): math.NewHexOrDecimal256(1), }), diff --git a/graft/subnet-evm/precompile/contracts/nativeminter/simulated_test.go b/graft/subnet-evm/precompile/contracts/nativeminter/simulated_test.go index 14266c292b58..26cb684bbf76 100644 --- a/graft/subnet-evm/precompile/contracts/nativeminter/simulated_test.go +++ b/graft/subnet-evm/precompile/contracts/nativeminter/simulated_test.go @@ -12,7 +12,6 @@ import ( "github.com/ava-labs/libevm/crypto" "github.com/stretchr/testify/require" - "github.com/ava-labs/avalanchego/graft/evm/utils" "github.com/ava-labs/avalanchego/graft/subnet-evm/accounts/abi/bind" "github.com/ava-labs/avalanchego/graft/subnet-evm/core" "github.com/ava-labs/avalanchego/graft/subnet-evm/params" @@ -21,6 +20,7 @@ import ( "github.com/ava-labs/avalanchego/graft/subnet-evm/precompile/allowlist/allowlisttest" "github.com/ava-labs/avalanchego/graft/subnet-evm/precompile/contracts/nativeminter" "github.com/ava-labs/avalanchego/graft/subnet-evm/precompile/contracts/utilstest" + "github.com/ava-labs/avalanchego/utils" sim "github.com/ava-labs/avalanchego/graft/subnet-evm/ethclient/simulated" nativeminterbindings "github.com/ava-labs/avalanchego/graft/subnet-evm/precompile/contracts/nativeminter/nativemintertest/bindings" @@ -143,7 +143,7 @@ func TestNativeMinter(t *testing.T) { }, } - precompileCfg := nativeminter.NewConfig(utils.NewUint64(0), []common.Address{adminAddress}, nil, nil, nil) + precompileCfg := nativeminter.NewConfig(utils.PointerTo[uint64](0), []common.Address{adminAddress}, nil, nil, nil) for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { backend := utilstest.NewBackendWithPrecompile(t, precompileCfg, []common.Address{adminAddress, unprivilegedAddress}) @@ -163,7 +163,7 @@ func TestINativeMinter_Events(t *testing.T) { testKey, _ := crypto.GenerateKey() testAddress := crypto.PubkeyToAddress(testKey.PublicKey) - precompileCfg := nativeminter.NewConfig(utils.NewUint64(0), []common.Address{adminAddress}, nil, nil, nil) + precompileCfg := nativeminter.NewConfig(utils.PointerTo[uint64](0), []common.Address{adminAddress}, nil, nil, nil) backend := utilstest.NewBackendWithPrecompile(t, precompileCfg, []common.Address{adminAddress, unprivilegedAddress}) defer backend.Close() diff --git a/graft/subnet-evm/precompile/contracts/rewardmanager/config_test.go b/graft/subnet-evm/precompile/contracts/rewardmanager/config_test.go index 63fdabbb0237..18da05e6978c 100644 --- a/graft/subnet-evm/precompile/contracts/rewardmanager/config_test.go +++ b/graft/subnet-evm/precompile/contracts/rewardmanager/config_test.go @@ -9,11 +9,11 @@ import ( "github.com/ava-labs/libevm/common" "go.uber.org/mock/gomock" - "github.com/ava-labs/avalanchego/graft/evm/utils" "github.com/ava-labs/avalanchego/graft/subnet-evm/precompile/allowlist/allowlisttest" "github.com/ava-labs/avalanchego/graft/subnet-evm/precompile/contracts/rewardmanager" "github.com/ava-labs/avalanchego/graft/subnet-evm/precompile/precompileconfig" "github.com/ava-labs/avalanchego/graft/subnet-evm/precompile/precompiletest" + "github.com/ava-labs/avalanchego/utils" ) func TestVerify(t *testing.T) { @@ -22,7 +22,7 @@ func TestVerify(t *testing.T) { managers := []common.Address{allowlisttest.TestManagerAddr} tests := map[string]precompiletest.ConfigVerifyTest{ "both reward mechanisms should not be activated at the same time in reward manager": { - Config: rewardmanager.NewConfig(utils.NewUint64(3), admins, enableds, managers, &rewardmanager.InitialRewardConfig{ + Config: rewardmanager.NewConfig(utils.PointerTo[uint64](3), admins, enableds, managers, &rewardmanager.InitialRewardConfig{ AllowFeeRecipients: true, RewardAddress: common.HexToAddress("0x01"), }), @@ -38,42 +38,42 @@ func TestEqual(t *testing.T) { managers := []common.Address{allowlisttest.TestManagerAddr} tests := map[string]precompiletest.ConfigEqualTest{ "non-nil config and nil other": { - Config: rewardmanager.NewConfig(utils.NewUint64(3), admins, enableds, managers, nil), + Config: rewardmanager.NewConfig(utils.PointerTo[uint64](3), admins, enableds, managers, nil), Other: nil, Expected: false, }, "different type": { - Config: rewardmanager.NewConfig(utils.NewUint64(3), admins, enableds, managers, nil), + Config: rewardmanager.NewConfig(utils.PointerTo[uint64](3), admins, enableds, managers, nil), Other: precompileconfig.NewMockConfig(gomock.NewController(t)), Expected: false, }, "different timestamp": { - Config: rewardmanager.NewConfig(utils.NewUint64(3), admins, nil, nil, nil), - Other: rewardmanager.NewConfig(utils.NewUint64(4), admins, nil, nil, nil), + Config: rewardmanager.NewConfig(utils.PointerTo[uint64](3), admins, nil, nil, nil), + Other: rewardmanager.NewConfig(utils.PointerTo[uint64](4), admins, nil, nil, nil), Expected: false, }, "non-nil initial config and nil initial config": { - Config: rewardmanager.NewConfig(utils.NewUint64(3), admins, nil, nil, &rewardmanager.InitialRewardConfig{ + Config: rewardmanager.NewConfig(utils.PointerTo[uint64](3), admins, nil, nil, &rewardmanager.InitialRewardConfig{ AllowFeeRecipients: true, }), - Other: rewardmanager.NewConfig(utils.NewUint64(3), admins, nil, nil, nil), + Other: rewardmanager.NewConfig(utils.PointerTo[uint64](3), admins, nil, nil, nil), Expected: false, }, "different initial config": { - Config: rewardmanager.NewConfig(utils.NewUint64(3), admins, nil, nil, &rewardmanager.InitialRewardConfig{ + Config: rewardmanager.NewConfig(utils.PointerTo[uint64](3), admins, nil, nil, &rewardmanager.InitialRewardConfig{ RewardAddress: common.HexToAddress("0x01"), }), - Other: rewardmanager.NewConfig(utils.NewUint64(3), admins, nil, nil, + Other: rewardmanager.NewConfig(utils.PointerTo[uint64](3), admins, nil, nil, &rewardmanager.InitialRewardConfig{ RewardAddress: common.HexToAddress("0x02"), }), Expected: false, }, "same config": { - Config: rewardmanager.NewConfig(utils.NewUint64(3), admins, nil, nil, &rewardmanager.InitialRewardConfig{ + Config: rewardmanager.NewConfig(utils.PointerTo[uint64](3), admins, nil, nil, &rewardmanager.InitialRewardConfig{ RewardAddress: common.HexToAddress("0x01"), }), - Other: rewardmanager.NewConfig(utils.NewUint64(3), admins, nil, nil, &rewardmanager.InitialRewardConfig{ + Other: rewardmanager.NewConfig(utils.PointerTo[uint64](3), admins, nil, nil, &rewardmanager.InitialRewardConfig{ RewardAddress: common.HexToAddress("0x01"), }), Expected: true, diff --git a/graft/subnet-evm/precompile/contracts/rewardmanager/simulated_test.go b/graft/subnet-evm/precompile/contracts/rewardmanager/simulated_test.go index bfe542e2a7b7..eba258066228 100644 --- a/graft/subnet-evm/precompile/contracts/rewardmanager/simulated_test.go +++ b/graft/subnet-evm/precompile/contracts/rewardmanager/simulated_test.go @@ -15,7 +15,6 @@ import ( "github.com/stretchr/testify/require" "github.com/ava-labs/avalanchego/graft/evm/constants" - "github.com/ava-labs/avalanchego/graft/evm/utils" "github.com/ava-labs/avalanchego/graft/subnet-evm/accounts/abi/bind" "github.com/ava-labs/avalanchego/graft/subnet-evm/core" "github.com/ava-labs/avalanchego/graft/subnet-evm/eth/ethconfig" @@ -26,6 +25,7 @@ import ( "github.com/ava-labs/avalanchego/graft/subnet-evm/precompile/allowlist/allowlisttest" "github.com/ava-labs/avalanchego/graft/subnet-evm/precompile/contracts/rewardmanager" "github.com/ava-labs/avalanchego/graft/subnet-evm/precompile/contracts/utilstest" + "github.com/ava-labs/avalanchego/utils" sim "github.com/ava-labs/avalanchego/graft/subnet-evm/ethclient/simulated" rewardmanagerbindings "github.com/ava-labs/avalanchego/graft/subnet-evm/precompile/contracts/rewardmanager/rewardmanagertest/bindings" @@ -297,7 +297,7 @@ func TestRewardManager(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { - cfg := rewardmanager.NewConfig(utils.NewUint64(0), []common.Address{adminAddress}, nil, nil, tc.initialRewardConfig) + cfg := rewardmanager.NewConfig(utils.PointerTo[uint64](0), []common.Address{adminAddress}, nil, nil, tc.initialRewardConfig) backend := utilstest.NewBackendWithPrecompile(t, cfg, []common.Address{adminAddress, unprivilegedAddress}, tc.backendOpts...) defer backend.Close() @@ -392,7 +392,7 @@ func TestIRewardManager_Events(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { - backend := utilstest.NewBackendWithPrecompile(t, rewardmanager.NewConfig(utils.NewUint64(0), []common.Address{adminAddress}, nil, nil, nil), []common.Address{adminAddress, unprivilegedAddress}) + backend := utilstest.NewBackendWithPrecompile(t, rewardmanager.NewConfig(utils.PointerTo[uint64](0), []common.Address{adminAddress}, nil, nil, nil), []common.Address{adminAddress, unprivilegedAddress}) defer backend.Close() rewardManager, err := rewardmanagerbindings.NewIRewardManager(rewardmanager.ContractAddress, backend.Client()) @@ -404,7 +404,7 @@ func TestIRewardManager_Events(t *testing.T) { } func TestIAllowList_Events(t *testing.T) { - precompileCfg := rewardmanager.NewConfig(utils.NewUint64(0), []common.Address{adminAddress}, nil, nil, nil) + precompileCfg := rewardmanager.NewConfig(utils.PointerTo[uint64](0), []common.Address{adminAddress}, nil, nil, nil) admin := utilstest.NewAuth(t, adminKey, params.TestChainConfig.ChainID) allowlisttest.RunAllowListEventTests(t, precompileCfg, rewardmanager.ContractAddress, admin, adminAddress) } diff --git a/graft/subnet-evm/precompile/contracts/txallowlist/config_test.go b/graft/subnet-evm/precompile/contracts/txallowlist/config_test.go index dcf296aa0367..32a1697314d7 100644 --- a/graft/subnet-evm/precompile/contracts/txallowlist/config_test.go +++ b/graft/subnet-evm/precompile/contracts/txallowlist/config_test.go @@ -9,11 +9,11 @@ import ( "github.com/ava-labs/libevm/common" "go.uber.org/mock/gomock" - "github.com/ava-labs/avalanchego/graft/evm/utils" "github.com/ava-labs/avalanchego/graft/subnet-evm/precompile/allowlist/allowlisttest" "github.com/ava-labs/avalanchego/graft/subnet-evm/precompile/contracts/txallowlist" "github.com/ava-labs/avalanchego/graft/subnet-evm/precompile/precompileconfig" "github.com/ava-labs/avalanchego/graft/subnet-evm/precompile/precompiletest" + "github.com/ava-labs/avalanchego/utils" ) func TestVerify(t *testing.T) { @@ -26,7 +26,7 @@ func TestEqual(t *testing.T) { managers := []common.Address{allowlisttest.TestManagerAddr} tests := map[string]precompiletest.ConfigEqualTest{ "non-nil config and nil other": { - Config: txallowlist.NewConfig(utils.NewUint64(3), admins, enableds, managers), + Config: txallowlist.NewConfig(utils.PointerTo[uint64](3), admins, enableds, managers), Other: nil, Expected: false, }, @@ -36,13 +36,13 @@ func TestEqual(t *testing.T) { Expected: false, }, "different timestamp": { - Config: txallowlist.NewConfig(utils.NewUint64(3), admins, enableds, managers), - Other: txallowlist.NewConfig(utils.NewUint64(4), admins, enableds, managers), + Config: txallowlist.NewConfig(utils.PointerTo[uint64](3), admins, enableds, managers), + Other: txallowlist.NewConfig(utils.PointerTo[uint64](4), admins, enableds, managers), Expected: false, }, "same config": { - Config: txallowlist.NewConfig(utils.NewUint64(3), admins, enableds, managers), - Other: txallowlist.NewConfig(utils.NewUint64(3), admins, enableds, managers), + Config: txallowlist.NewConfig(utils.PointerTo[uint64](3), admins, enableds, managers), + Other: txallowlist.NewConfig(utils.PointerTo[uint64](3), admins, enableds, managers), Expected: true, }, } diff --git a/graft/subnet-evm/precompile/contracts/txallowlist/simulated_test.go b/graft/subnet-evm/precompile/contracts/txallowlist/simulated_test.go index 1d7c3c4c41c2..c2c03f96944a 100644 --- a/graft/subnet-evm/precompile/contracts/txallowlist/simulated_test.go +++ b/graft/subnet-evm/precompile/contracts/txallowlist/simulated_test.go @@ -11,7 +11,6 @@ import ( "github.com/ava-labs/libevm/crypto" "github.com/stretchr/testify/require" - "github.com/ava-labs/avalanchego/graft/evm/utils" "github.com/ava-labs/avalanchego/graft/subnet-evm/accounts/abi/bind" "github.com/ava-labs/avalanchego/graft/subnet-evm/core" "github.com/ava-labs/avalanchego/graft/subnet-evm/params" @@ -21,6 +20,7 @@ import ( "github.com/ava-labs/avalanchego/graft/subnet-evm/precompile/allowlist/allowlisttest" "github.com/ava-labs/avalanchego/graft/subnet-evm/precompile/contracts/txallowlist" "github.com/ava-labs/avalanchego/graft/subnet-evm/precompile/contracts/utilstest" + "github.com/ava-labs/avalanchego/utils" sim "github.com/ava-labs/avalanchego/graft/subnet-evm/ethclient/simulated" allowlistbindings "github.com/ava-labs/avalanchego/graft/subnet-evm/precompile/allowlist/allowlisttest/bindings" @@ -268,7 +268,7 @@ func TestTxAllowList(t *testing.T) { }, } - precompileCfg := txallowlist.NewConfig(utils.NewUint64(0), []common.Address{adminAddress}, nil, nil) + precompileCfg := txallowlist.NewConfig(utils.PointerTo[uint64](0), []common.Address{adminAddress}, nil, nil) for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { backend := utilstest.NewBackendWithPrecompile(t, precompileCfg, []common.Address{adminAddress, unprivilegedAddress}) @@ -283,7 +283,7 @@ func TestTxAllowList(t *testing.T) { } func TestIAllowList_Events(t *testing.T) { - precompileCfg := txallowlist.NewConfig(utils.NewUint64(0), []common.Address{adminAddress}, nil, nil) + precompileCfg := txallowlist.NewConfig(utils.PointerTo[uint64](0), []common.Address{adminAddress}, nil, nil) admin := utilstest.NewAuth(t, adminKey, params.TestChainConfig.ChainID) allowlisttest.RunAllowListEventTests(t, precompileCfg, txallowlist.ContractAddress, admin, adminAddress, unprivilegedAddress) } diff --git a/graft/subnet-evm/precompile/contracts/warp/config_test.go b/graft/subnet-evm/precompile/contracts/warp/config_test.go index 7d035b0a0438..7b515ff43d5b 100644 --- a/graft/subnet-evm/precompile/contracts/warp/config_test.go +++ b/graft/subnet-evm/precompile/contracts/warp/config_test.go @@ -8,32 +8,32 @@ import ( "go.uber.org/mock/gomock" - "github.com/ava-labs/avalanchego/graft/evm/utils" "github.com/ava-labs/avalanchego/graft/subnet-evm/precompile/precompileconfig" "github.com/ava-labs/avalanchego/graft/subnet-evm/precompile/precompiletest" + "github.com/ava-labs/avalanchego/utils" ) func TestVerify(t *testing.T) { tests := map[string]precompiletest.ConfigVerifyTest{ "quorum numerator less than minimum": { - Config: NewConfig(utils.NewUint64(3), WarpQuorumNumeratorMinimum-1, false), + Config: NewConfig(utils.PointerTo[uint64](3), WarpQuorumNumeratorMinimum-1, false), ExpectedError: ErrInvalidQuorumRatio, }, "quorum numerator greater than quorum denominator": { - Config: NewConfig(utils.NewUint64(3), WarpQuorumDenominator+1, false), + Config: NewConfig(utils.PointerTo[uint64](3), WarpQuorumDenominator+1, false), ExpectedError: ErrInvalidQuorumRatio, }, "default quorum numerator": { - Config: NewDefaultConfig(utils.NewUint64(3)), + Config: NewDefaultConfig(utils.PointerTo[uint64](3)), }, "valid quorum numerator 1 less than denominator": { - Config: NewConfig(utils.NewUint64(3), WarpQuorumDenominator-1, false), + Config: NewConfig(utils.PointerTo[uint64](3), WarpQuorumDenominator-1, false), }, "valid quorum numerator 1 more than minimum": { - Config: NewConfig(utils.NewUint64(3), WarpQuorumNumeratorMinimum+1, false), + Config: NewConfig(utils.PointerTo[uint64](3), WarpQuorumNumeratorMinimum+1, false), }, "invalid cannot activated before Durango activation": { - Config: NewConfig(utils.NewUint64(3), 0, false), + Config: NewConfig(utils.PointerTo[uint64](3), 0, false), ChainConfig: func() precompileconfig.ChainConfig { config := precompileconfig.NewMockChainConfig(gomock.NewController(t)) config.EXPECT().IsDurango(gomock.Any()).Return(false) @@ -48,38 +48,38 @@ func TestVerify(t *testing.T) { func TestEqualWarpConfig(t *testing.T) { tests := map[string]precompiletest.ConfigEqualTest{ "non-nil config and nil other": { - Config: NewDefaultConfig(utils.NewUint64(3)), + Config: NewDefaultConfig(utils.PointerTo[uint64](3)), Other: nil, Expected: false, }, "different type": { - Config: NewDefaultConfig(utils.NewUint64(3)), + Config: NewDefaultConfig(utils.PointerTo[uint64](3)), Other: precompileconfig.NewMockConfig(gomock.NewController(t)), Expected: false, }, "different timestamp": { - Config: NewDefaultConfig(utils.NewUint64(3)), - Other: NewDefaultConfig(utils.NewUint64(4)), + Config: NewDefaultConfig(utils.PointerTo[uint64](3)), + Other: NewDefaultConfig(utils.PointerTo[uint64](4)), Expected: false, }, "different quorum numerator": { - Config: NewConfig(utils.NewUint64(3), WarpQuorumNumeratorMinimum+1, false), - Other: NewConfig(utils.NewUint64(3), WarpQuorumNumeratorMinimum+2, false), + Config: NewConfig(utils.PointerTo[uint64](3), WarpQuorumNumeratorMinimum+1, false), + Other: NewConfig(utils.PointerTo[uint64](3), WarpQuorumNumeratorMinimum+2, false), Expected: false, }, "same default config": { - Config: NewDefaultConfig(utils.NewUint64(3)), - Other: NewDefaultConfig(utils.NewUint64(3)), + Config: NewDefaultConfig(utils.PointerTo[uint64](3)), + Other: NewDefaultConfig(utils.PointerTo[uint64](3)), Expected: true, }, "same non-default config": { - Config: NewConfig(utils.NewUint64(3), WarpQuorumNumeratorMinimum+5, false), - Other: NewConfig(utils.NewUint64(3), WarpQuorumNumeratorMinimum+5, false), + Config: NewConfig(utils.PointerTo[uint64](3), WarpQuorumNumeratorMinimum+5, false), + Other: NewConfig(utils.PointerTo[uint64](3), WarpQuorumNumeratorMinimum+5, false), Expected: true, }, } diff --git a/graft/subnet-evm/precompile/contracts/warp/predicate_test.go b/graft/subnet-evm/precompile/contracts/warp/predicate_test.go index 6dfbf8f62f56..9262d24434c4 100644 --- a/graft/subnet-evm/precompile/contracts/warp/predicate_test.go +++ b/graft/subnet-evm/precompile/contracts/warp/predicate_test.go @@ -12,7 +12,6 @@ import ( "github.com/ava-labs/libevm/common" "github.com/stretchr/testify/require" - "github.com/ava-labs/avalanchego/graft/evm/utils" "github.com/ava-labs/avalanchego/graft/evm/utils/utilstest" "github.com/ava-labs/avalanchego/graft/subnet-evm/params/extras" "github.com/ava-labs/avalanchego/graft/subnet-evm/params/extras/extrastest" @@ -25,6 +24,7 @@ import ( "github.com/ava-labs/avalanchego/snow/validators" "github.com/ava-labs/avalanchego/snow/validators/validatorstest" "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/bls" "github.com/ava-labs/avalanchego/utils/crypto/bls/signer/localsigner" @@ -32,13 +32,12 @@ import ( "github.com/ava-labs/avalanchego/vms/evm/predicate" "github.com/ava-labs/avalanchego/vms/platformvm/warp/payload" - agoUtils "github.com/ava-labs/avalanchego/utils" safemath "github.com/ava-labs/avalanchego/utils/math" avalancheWarp "github.com/ava-labs/avalanchego/vms/platformvm/warp" ) var ( - _ agoUtils.Sortable[*testValidator] = (*testValidator)(nil) + _ utils.Sortable[*testValidator] = (*testValidator)(nil) sourceChainID = ids.GenerateTestID() sourceSubnetID = ids.GenerateTestID() @@ -63,7 +62,7 @@ func init() { for i := 0; i < numTestVdrs; i++ { testVdrs = append(testVdrs, newTestValidator()) } - agoUtils.Sort(testVdrs) + utils.Sort(testVdrs) vdrs = map[ids.NodeID]*validators.GetValidatorOutput{ testVdrs[0].nodeID: { @@ -246,7 +245,7 @@ func createValidPredicateTest( ) precompiletest.PredicateTest { gasCost := CurrentGasConfig(rules) return precompiletest.PredicateTest{ - Config: NewDefaultConfig(utils.NewUint64(0)), + Config: NewDefaultConfig(utils.PointerTo[uint64](0)), PredicateContext: &precompileconfig.PredicateContext{ SnowCtx: snowCtx, ProposerVMBlockCtx: &block.Context{ @@ -271,7 +270,7 @@ func testWarpMessageFromPrimaryNetwork(t *testing.T, requirePrimaryNetworkSigner require := require.New(t) numKeys := 10 cChainID := ids.GenerateTestID() - addressedCall, err := payload.NewAddressedCall(agoUtils.RandomBytes(20), agoUtils.RandomBytes(100)) + addressedCall, err := payload.NewAddressedCall(utils.RandomBytes(20), utils.RandomBytes(100)) require.NoError(err) unsignedMsg, err := avalancheWarp.NewUnsignedMessage(constants.UnitTestID, cChainID, addressedCall.Bytes()) require.NoError(err) @@ -297,7 +296,7 @@ func testWarpMessageFromPrimaryNetwork(t *testing.T, requirePrimaryNetworkSigner NodeIDs: []ids.NodeID{vdr.nodeID}, }) } - agoUtils.Sort(warpValidators.Validators) + utils.Sort(warpValidators.Validators) aggregateSignature, err := bls.AggregateSignatures(blsSignatures) require.NoError(err) @@ -334,7 +333,7 @@ func testWarpMessageFromPrimaryNetwork(t *testing.T, requirePrimaryNetworkSigner } test := precompiletest.PredicateTest{ - Config: NewConfig(utils.NewUint64(0), 0, requirePrimaryNetworkSigners), + Config: NewConfig(utils.PointerTo[uint64](0), 0, requirePrimaryNetworkSigners), PredicateContext: &precompileconfig.PredicateContext{ SnowCtx: snowCtx, ProposerVMBlockCtx: &block.Context{ @@ -365,7 +364,7 @@ func TestInvalidPredicatePacking(t *testing.T) { pred = append(pred, common.Hash{1}) // Invalidate the predicate byte packing test := precompiletest.PredicateTest{ - Config: NewDefaultConfig(utils.NewUint64(0)), + Config: NewDefaultConfig(utils.PointerTo[uint64](0)), PredicateContext: &precompileconfig.PredicateContext{ SnowCtx: snowCtx, ProposerVMBlockCtx: &block.Context{ @@ -397,7 +396,7 @@ func TestInvalidWarpMessage(t *testing.T) { pred := predicate.New(warpMsgBytes) test := precompiletest.PredicateTest{ - Config: NewDefaultConfig(utils.NewUint64(0)), + Config: NewDefaultConfig(utils.PointerTo[uint64](0)), PredicateContext: &precompileconfig.PredicateContext{ SnowCtx: snowCtx, ProposerVMBlockCtx: &block.Context{ @@ -442,7 +441,7 @@ func TestInvalidAddressedPayload(t *testing.T) { pred := predicate.New(warpMsgBytes) test := precompiletest.PredicateTest{ - Config: NewDefaultConfig(utils.NewUint64(0)), + Config: NewDefaultConfig(utils.PointerTo[uint64](0)), PredicateContext: &precompileconfig.PredicateContext{ SnowCtx: snowCtx, ProposerVMBlockCtx: &block.Context{ @@ -459,7 +458,7 @@ func TestInvalidAddressedPayload(t *testing.T) { } func TestInvalidBitSet(t *testing.T) { - addressedCall, err := payload.NewAddressedCall(agoUtils.RandomBytes(20), agoUtils.RandomBytes(100)) + addressedCall, err := payload.NewAddressedCall(utils.RandomBytes(20), utils.RandomBytes(100)) require.NoError(t, err) unsignedMsg, err := avalancheWarp.NewUnsignedMessage( constants.UnitTestID, @@ -488,7 +487,7 @@ func TestInvalidBitSet(t *testing.T) { }) pred := predicate.New(msg.Bytes()) test := precompiletest.PredicateTest{ - Config: NewDefaultConfig(utils.NewUint64(0)), + Config: NewDefaultConfig(utils.PointerTo[uint64](0)), PredicateContext: &precompileconfig.PredicateContext{ SnowCtx: snowCtx, ProposerVMBlockCtx: &block.Context{ @@ -536,7 +535,7 @@ func TestWarpSignatureWeightsDefaultQuorumNumerator(t *testing.T) { tests[i] = precompiletest.PredicateTest{ Name: fmt.Sprintf("default quorum %d signature(s)", numSigners), - Config: NewDefaultConfig(utils.NewUint64(0)), + Config: NewDefaultConfig(utils.PointerTo[uint64](0)), PredicateContext: &precompileconfig.PredicateContext{ SnowCtx: snowCtx, ProposerVMBlockCtx: &block.Context{ @@ -596,7 +595,7 @@ func TestWarpMultiplePredicates(t *testing.T) { tests = append(tests, precompiletest.PredicateTest{ Name: fmt.Sprintf("multiple predicates %v", validMessageIndices), - Config: NewDefaultConfig(utils.NewUint64(0)), + Config: NewDefaultConfig(utils.PointerTo[uint64](0)), PredicateContext: &precompileconfig.PredicateContext{ SnowCtx: snowCtx, ProposerVMBlockCtx: &block.Context{ @@ -648,7 +647,7 @@ func TestWarpSignatureWeightsNonDefaultQuorumNumerator(t *testing.T) { tests[i] = precompiletest.PredicateTest{ Name: fmt.Sprintf("non-default quorum %d signature(s)", numSigners), - Config: NewConfig(utils.NewUint64(0), uint64(nonDefaultQuorumNumerator), false), + Config: NewConfig(utils.PointerTo[uint64](0), uint64(nonDefaultQuorumNumerator), false), PredicateContext: &precompileconfig.PredicateContext{ SnowCtx: snowCtx, ProposerVMBlockCtx: &block.Context{ @@ -668,7 +667,7 @@ func TestWarpSignatureWeightsNonDefaultQuorumNumerator(t *testing.T) { func TestWarpNoValidatorsAndOverflowUseSameGas(t *testing.T) { var ( - config = NewConfig(utils.NewUint64(0), 0, false) + config = NewConfig(utils.PointerTo[uint64](0), 0, false) proposervmContext = &block.Context{ PChainHeight: 1, } diff --git a/utils/timer/eta_test.go b/utils/timer/eta_test.go index 9e240e7c9840..40a95e8acaa4 100644 --- a/utils/timer/eta_test.go +++ b/utils/timer/eta_test.go @@ -8,12 +8,9 @@ import ( "time" "github.com/stretchr/testify/require" -) -// timePtr is a helper function to convert a time.Duration to a pointer -func timePtr(d time.Duration) *time.Duration { - return &d -} + "github.com/ava-labs/avalanchego/utils" +) func TestEtaTracker(t *testing.T) { tracker := NewEtaTracker(3, 1.0) @@ -48,7 +45,7 @@ func TestEtaTracker(t *testing.T) { name: "sample 3: sufficient data for ETA", completed: 200, timestamp: now.Add(20 * time.Second), - expectedEta: timePtr(80 * time.Second), + expectedEta: utils.PointerTo(80 * time.Second), expectedPercent: 20.0, }, { @@ -56,7 +53,7 @@ func TestEtaTracker(t *testing.T) { name: "sample 4: non linear since we sped up", completed: 600, timestamp: now.Add(40 * time.Second), - expectedEta: timePtr(24 * time.Second), + expectedEta: utils.PointerTo(24 * time.Second), expectedPercent: 60.0, }, { @@ -64,7 +61,7 @@ func TestEtaTracker(t *testing.T) { name: "sample 5: at the end", completed: 1000, timestamp: now.Add(1 * time.Second), - expectedEta: timePtr(0), + expectedEta: utils.PointerTo[time.Duration](0), expectedPercent: 100.0, }, { @@ -72,7 +69,7 @@ func TestEtaTracker(t *testing.T) { name: "sample 6: past the end", completed: 2000, timestamp: now.Add(1 * time.Second), - expectedEta: timePtr(0), + expectedEta: utils.PointerTo[time.Duration](0), expectedPercent: 100.0, }, { diff --git a/utils/zero.go b/utils/values.go similarity index 65% rename from utils/zero.go rename to utils/values.go index 6e246823737d..55af4695a980 100644 --- a/utils/zero.go +++ b/utils/values.go @@ -7,3 +7,8 @@ package utils func Zero[T any]() (_ T) { return } + +// PointerTo returns a pointer to the provided value. +func PointerTo[T any](v T) *T { + return &v +} diff --git a/vms/evm/metrics/prometheus/prometheus.go b/vms/evm/metrics/prometheus/prometheus.go index 87b42ca31fb1..ba3eedbc376d 100644 --- a/vms/evm/metrics/prometheus/prometheus.go +++ b/vms/evm/metrics/prometheus/prometheus.go @@ -12,6 +12,8 @@ import ( "github.com/ava-labs/libevm/metrics" "github.com/prometheus/client_golang/prometheus" + "github.com/ava-labs/avalanchego/utils" + dto "github.com/prometheus/client_model/go" ) @@ -82,7 +84,7 @@ func metricFamily(registry Registry, name string) (mf *dto.MetricFamily, err err Type: dto.MetricType_COUNTER.Enum(), Metric: []*dto.Metric{{ Counter: &dto.Counter{ - Value: ptrTo(float64(m.Snapshot().Count())), + Value: utils.PointerTo(float64(m.Snapshot().Count())), }, }}, }, nil @@ -93,7 +95,7 @@ func metricFamily(registry Registry, name string) (mf *dto.MetricFamily, err err Type: dto.MetricType_COUNTER.Enum(), Metric: []*dto.Metric{{ Counter: &dto.Counter{ - Value: ptrTo(m.Snapshot().Count()), + Value: utils.PointerTo(m.Snapshot().Count()), }, }}, }, nil @@ -104,7 +106,7 @@ func metricFamily(registry Registry, name string) (mf *dto.MetricFamily, err err Type: dto.MetricType_GAUGE.Enum(), Metric: []*dto.Metric{{ Gauge: &dto.Gauge{ - Value: ptrTo(float64(m.Snapshot().Value())), + Value: utils.PointerTo(float64(m.Snapshot().Value())), }, }}, }, nil @@ -115,7 +117,7 @@ func metricFamily(registry Registry, name string) (mf *dto.MetricFamily, err err Type: dto.MetricType_GAUGE.Enum(), Metric: []*dto.Metric{{ Gauge: &dto.Gauge{ - Value: ptrTo(m.Snapshot().Value()), + Value: utils.PointerTo(m.Snapshot().Value()), }, }}, }, nil @@ -127,8 +129,8 @@ func metricFamily(registry Registry, name string) (mf *dto.MetricFamily, err err dtoQuantiles := make([]*dto.Quantile, len(quantiles)) for i := range thresholds { dtoQuantiles[i] = &dto.Quantile{ - Quantile: ptrTo(quantiles[i]), - Value: ptrTo(thresholds[i]), + Quantile: utils.PointerTo(quantiles[i]), + Value: utils.PointerTo(thresholds[i]), } } return &dto.MetricFamily{ @@ -137,8 +139,8 @@ func metricFamily(registry Registry, name string) (mf *dto.MetricFamily, err err Type: dto.MetricType_SUMMARY.Enum(), Metric: []*dto.Metric{{ Summary: &dto.Summary{ - SampleCount: ptrTo(uint64(snapshot.Count())), - SampleSum: ptrTo(float64(snapshot.Sum())), + SampleCount: utils.PointerTo(uint64(snapshot.Count())), + SampleSum: utils.PointerTo(float64(snapshot.Sum())), Quantile: dtoQuantiles, }, }}, @@ -150,7 +152,7 @@ func metricFamily(registry Registry, name string) (mf *dto.MetricFamily, err err Type: dto.MetricType_GAUGE.Enum(), Metric: []*dto.Metric{{ Gauge: &dto.Gauge{ - Value: ptrTo(float64(m.Snapshot().Count())), + Value: utils.PointerTo(float64(m.Snapshot().Count())), }, }}, }, nil @@ -160,8 +162,8 @@ func metricFamily(registry Registry, name string) (mf *dto.MetricFamily, err err dtoQuantiles := make([]*dto.Quantile, len(quantiles)) for i := range thresholds { dtoQuantiles[i] = &dto.Quantile{ - Quantile: ptrTo(quantiles[i]), - Value: ptrTo(thresholds[i]), + Quantile: utils.PointerTo(quantiles[i]), + Value: utils.PointerTo(thresholds[i]), } } return &dto.MetricFamily{ @@ -170,8 +172,8 @@ func metricFamily(registry Registry, name string) (mf *dto.MetricFamily, err err Type: dto.MetricType_SUMMARY.Enum(), Metric: []*dto.Metric{{ Summary: &dto.Summary{ - SampleCount: ptrTo(uint64(snapshot.Count())), - SampleSum: ptrTo(float64(snapshot.Sum())), + SampleCount: utils.PointerTo(uint64(snapshot.Count())), + SampleSum: utils.PointerTo(float64(snapshot.Sum())), Quantile: dtoQuantiles, }, }}, @@ -182,8 +184,8 @@ func metricFamily(registry Registry, name string) (mf *dto.MetricFamily, err err dtoQuantiles := make([]*dto.Quantile, len(pvShortPercent)) for i := range pvShortPercent { dtoQuantiles[i] = &dto.Quantile{ - Quantile: ptrTo(pvShortPercent[i]), - Value: ptrTo(thresholds[i]), + Quantile: utils.PointerTo(pvShortPercent[i]), + Value: utils.PointerTo(thresholds[i]), } } count := snapshot.Count() @@ -193,8 +195,8 @@ func metricFamily(registry Registry, name string) (mf *dto.MetricFamily, err err Type: dto.MetricType_SUMMARY.Enum(), Metric: []*dto.Metric{{ Summary: &dto.Summary{ - SampleCount: ptrTo(uint64(count)), - SampleSum: ptrTo(float64(count) * snapshot.Mean()), + SampleCount: utils.PointerTo(uint64(count)), + SampleSum: utils.PointerTo(float64(count) * snapshot.Mean()), Quantile: dtoQuantiles, }, }}, @@ -203,5 +205,3 @@ func metricFamily(registry Registry, name string) (mf *dto.MetricFamily, err err return nil, fmt.Errorf("%w: metric %q type %T", errMetricTypeNotSupported, name, metric) } } - -func ptrTo[T any](x T) *T { return &x } diff --git a/x/blockdb/helpers_test.go b/x/blockdb/helpers_test.go index d444efaed5e0..1d67edfc022b 100644 --- a/x/blockdb/helpers_test.go +++ b/x/blockdb/helpers_test.go @@ -76,8 +76,3 @@ func checkDatabaseState(t *testing.T, db *Database, maxHeight uint64) { actualMaxHeight := db.maxBlockHeight.Load() require.Equal(t, maxHeight, actualMaxHeight, "maxBlockHeight mismatch") } - -// Helper function to create a pointer to uint64 -func uint64Ptr(v uint64) *uint64 { - return &v -} diff --git a/x/blockdb/recovery_test.go b/x/blockdb/recovery_test.go index a4cdb462111a..8a8ffc7f1016 100644 --- a/x/blockdb/recovery_test.go +++ b/x/blockdb/recovery_test.go @@ -12,6 +12,7 @@ import ( "github.com/DataDog/zstd" "github.com/stretchr/testify/require" + "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/utils/compression" ) @@ -417,8 +418,8 @@ func TestRecovery_CorruptionDetection(t *testing.T) { name: "missing data file at index 1", blockHeights: []uint64{0, 1, 2, 3, 4, 5}, disableCompression: true, - maxDataFileSize: uint64Ptr(1024), // 1KB per file to force multiple files - blockSize: 512, // 512 bytes per block + maxDataFileSize: utils.PointerTo[uint64](1024), // 1KB per file to force multiple files + blockSize: 512, // 512 bytes per block setupCorruption: func(store *Database, _ [][]byte) error { // Delete the second data file (index 1) dataFilePath := store.dataFilePath(1) @@ -430,8 +431,8 @@ func TestRecovery_CorruptionDetection(t *testing.T) { { name: "unexpected multiple data files when MaxDataFileSize is max uint64", blockHeights: []uint64{0, 1, 2}, - maxDataFileSize: uint64Ptr(math.MaxUint64), // Single file mode - blockSize: 512, // 512 bytes per block + maxDataFileSize: utils.PointerTo[uint64](math.MaxUint64), // Single file mode + blockSize: 512, // 512 bytes per block setupCorruption: func(store *Database, _ [][]byte) error { // Manually create a second data file to simulate corruption secondDataFilePath := store.dataFilePath(1)