diff --git a/core/genesis_extra_test.go b/core/genesis_extra_test.go index dd9d77037d..9c0f8c9882 100644 --- a/core/genesis_extra_test.go +++ b/core/genesis_extra_test.go @@ -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/core/genesis_test.go b/core/genesis_test.go index 63a1c50b18..07c85364f8 100644 --- a/core/genesis_test.go +++ b/core/genesis_test.go @@ -79,7 +79,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{ @@ -92,7 +92,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 @@ -176,8 +176,8 @@ func testSetupGenesis(t *testing.T, scheme string) { wantConfig: customg.Config, wantErr: ðparams.ConfigCompatError{ What: "ApricotPhase1 fork block timestamp", - StoredTime: u64(90), - NewTime: u64(100), + StoredTime: utils.PointerTo(uint64(90)), + NewTime: utils.PointerTo(uint64(100)), RewindToTime: 89, }, }, @@ -238,7 +238,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 @@ -276,7 +276,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/core/state_processor_test.go b/core/state_processor_test.go index 4d7702019f..13ad65b446 100644 --- a/core/state_processor_test.go +++ b/core/state_processor_test.go @@ -56,8 +56,6 @@ import ( "golang.org/x/crypto/sha3" ) -func u64(val uint64) *uint64 { return &val } - // TestStateProcessorErrors tests the output from the 'core' errors // as defined in core/error.go. These errors are generated when the // blockchain imports bad blocks, meaning blocks which have valid headers but @@ -65,8 +63,8 @@ func u64(val uint64) *uint64 { return &val } func TestStateProcessorErrors(t *testing.T) { cpcfg := *params.TestChainConfig config := &cpcfg - config.ShanghaiTime = u64(0) - config.CancunTime = u64(0) + config.ShanghaiTime = utils.PointerTo(uint64(0)) + config.CancunTime = utils.PointerTo(uint64(0)) var ( signer = types.LatestSigner(config) @@ -283,8 +281,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 +389,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/internal/ethapi/api_test.go b/internal/ethapi/api_test.go index 798109e95c..ab55de7937 100644 --- a/internal/ethapi/api_test.go +++ b/internal/ethapi/api_test.go @@ -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/params/config.go b/params/config.go index ed85231172..4e3811d854 100644 --- a/params/config.go +++ b/params/config.go @@ -95,8 +95,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, ) @@ -332,7 +332,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, ) @@ -353,8 +353,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, ) @@ -375,8 +375,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, ) @@ -397,8 +397,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, ) diff --git a/params/config_extra.go b/params/config_extra.go index c68097808e..4bcb8d1348 100644 --- a/params/config_extra.go +++ b/params/config_extra.go @@ -81,11 +81,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/params/config_extra_test.go b/params/config_extra_test.go index cd7f329f09..b48b5b7612 100644 --- a/params/config_extra_test.go +++ b/params/config_extra_test.go @@ -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/params/config_test.go b/params/config_test.go index b0a7e15189..19433bf4e0 100644 --- a/params/config_test.go +++ b/params/config_test.go @@ -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/params/extras/config.go b/params/extras/config.go index 5472371c5a..8daa558278 100644 --- a/params/extras/config.go +++ b/params/extras/config.go @@ -20,59 +20,59 @@ 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)) }) TestChainConfig = copyConfig(TestGraniteChainConfig) @@ -121,7 +121,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/params/extras/config_extra_test.go b/params/extras/config_extra_test.go index 272b44ff5f..2fd9330cef 100644 --- a/params/extras/config_extra_test.go +++ b/params/extras/config_extra_test.go @@ -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/params/extras/precompile_upgrade.go b/params/extras/precompile_upgrade.go index 19238b0739..669ad9444c 100644 --- a/params/extras/precompile_upgrade.go +++ b/params/extras/precompile_upgrade.go @@ -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/plugin/evm/config/config_test.go b/plugin/evm/config/config_test.go index 5398e4236a..302a69bde8 100644 --- a/plugin/evm/config/config_test.go +++ b/plugin/evm/config/config_test.go @@ -12,13 +12,9 @@ import ( "github.com/ava-labs/avalanchego/utils/constants" "github.com/ava-labs/libevm/common" "github.com/stretchr/testify/require" -) -// newTrue returns a pointer to a bool that is true -func newTrue() *bool { - b := true - return &b -} + "github.com/ava-labs/coreth/utils" +) func TestUnmarshalConfig(t *testing.T) { tests := []struct { @@ -69,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/plugin/evm/customheader/base_fee_test.go b/plugin/evm/customheader/base_fee_test.go index ccd73c8508..d020a1eac3 100644 --- a/plugin/evm/customheader/base_fee_test.go +++ b/plugin/evm/customheader/base_fee_test.go @@ -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/plugin/evm/customheader/extra_test.go b/plugin/evm/customheader/extra_test.go index ec3b542246..1978f8e698 100644 --- a/plugin/evm/customheader/extra_test.go +++ b/plugin/evm/customheader/extra_test.go @@ -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/plugin/evm/customheader/gas_limit_test.go b/plugin/evm/customheader/gas_limit_test.go index dbe8f46133..2107ae643c 100644 --- a/plugin/evm/customheader/gas_limit_test.go +++ b/plugin/evm/customheader/gas_limit_test.go @@ -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/plugin/evm/customheader/min_delay_excess_test.go b/plugin/evm/customheader/min_delay_excess_test.go index 97aac4f4cf..0b525b8b99 100644 --- a/plugin/evm/customheader/min_delay_excess_test.go +++ b/plugin/evm/customheader/min_delay_excess_test.go @@ -13,13 +13,12 @@ import ( "github.com/ava-labs/coreth/params/extras" "github.com/ava-labs/coreth/plugin/evm/customtypes" "github.com/ava-labs/coreth/utils" - "github.com/ava-labs/coreth/utils/utilstest" ) 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/plugin/evm/customheader/time_test.go b/plugin/evm/customheader/time_test.go index 769af92278..0d84014c55 100644 --- a/plugin/evm/customheader/time_test.go +++ b/plugin/evm/customheader/time_test.go @@ -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/plugin/evm/customtypes/block_ext_test.go b/plugin/evm/customtypes/block_ext_test.go index 51d15b610c..40325ca324 100644 --- a/plugin/evm/customtypes/block_ext_test.go +++ b/plugin/evm/customtypes/block_ext_test.go @@ -19,7 +19,6 @@ import ( "github.com/stretchr/testify/require" "github.com/ava-labs/coreth/utils" - "github.com/ava-labs/coreth/utils/utilstest" ) func TestCopyHeader(t *testing.T) { @@ -326,8 +325,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, @@ -337,8 +336,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/plugin/evm/customtypes/header_ext_test.go b/plugin/evm/customtypes/header_ext_test.go index 1cd09849b1..95b01d31e4 100644 --- a/plugin/evm/customtypes/header_ext_test.go +++ b/plugin/evm/customtypes/header_ext_test.go @@ -18,7 +18,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/ava-labs/coreth/utils/utilstest" + "github.com/ava-labs/coreth/utils" ) func TestHeaderRLP(t *testing.T) { @@ -107,16 +107,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/plugin/evm/vm_test.go b/plugin/evm/vm_test.go index 5973f0de35..72bf5ad692 100644 --- a/plugin/evm/vm_test.go +++ b/plugin/evm/vm_test.go @@ -57,7 +57,6 @@ import ( "github.com/ava-labs/coreth/plugin/evm/vmtest" "github.com/ava-labs/coreth/rpc" "github.com/ava-labs/coreth/utils" - "github.com/ava-labs/coreth/utils/utilstest" commonEng "github.com/ava-labs/avalanchego/snow/engine/common" avalancheWarp "github.com/ava-labs/avalanchego/vms/platformvm/warp" @@ -81,8 +80,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 } ) @@ -1013,13 +1012,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, }, { @@ -1033,14 +1032,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, }, } @@ -1105,7 +1104,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())), }, } @@ -2048,26 +2047,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/precompile/contracts/warp/config_test.go b/precompile/contracts/warp/config_test.go index d69ad0c38d..04ef5c3cdf 100644 --- a/precompile/contracts/warp/config_test.go +++ b/precompile/contracts/warp/config_test.go @@ -16,24 +16,24 @@ import ( 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/precompile/contracts/warp/predicate_test.go b/precompile/contracts/warp/predicate_test.go index 7a0de8e513..6cf94620e2 100644 --- a/precompile/contracts/warp/predicate_test.go +++ b/precompile/contracts/warp/predicate_test.go @@ -244,7 +244,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{ @@ -331,7 +331,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 +362,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 +394,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 +439,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{ @@ -485,7 +485,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 +533,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 +593,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 +645,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 +665,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/tests/init.go b/tests/init.go index b588e66584..07fff3bdbb 100644 --- a/tests/init.go +++ b/tests/init.go @@ -199,7 +199,7 @@ func initializeForks() { }, &extras.ChainConfig{ NetworkUpgrades: extras.NetworkUpgrades{ - ApricotPhase1BlockTimestamp: utils.NewUint64(0), + ApricotPhase1BlockTimestamp: utils.PointerTo(uint64(0)), }, }, ), @@ -219,8 +219,8 @@ func initializeForks() { }, &extras.ChainConfig{ NetworkUpgrades: extras.NetworkUpgrades{ - ApricotPhase1BlockTimestamp: utils.NewUint64(0), - ApricotPhase2BlockTimestamp: utils.NewUint64(0), + ApricotPhase1BlockTimestamp: utils.PointerTo(uint64(0)), + ApricotPhase2BlockTimestamp: utils.PointerTo(uint64(0)), }, }, ), @@ -241,9 +241,9 @@ func initializeForks() { }, &extras.ChainConfig{ NetworkUpgrades: extras.NetworkUpgrades{ - ApricotPhase1BlockTimestamp: utils.NewUint64(0), - ApricotPhase2BlockTimestamp: utils.NewUint64(0), - ApricotPhase3BlockTimestamp: utils.NewUint64(0), + ApricotPhase1BlockTimestamp: utils.PointerTo(uint64(0)), + ApricotPhase2BlockTimestamp: utils.PointerTo(uint64(0)), + ApricotPhase3BlockTimestamp: utils.PointerTo(uint64(0)), }, }, ), @@ -264,10 +264,10 @@ func initializeForks() { }, &extras.ChainConfig{ NetworkUpgrades: extras.NetworkUpgrades{ - ApricotPhase1BlockTimestamp: utils.NewUint64(0), - ApricotPhase2BlockTimestamp: utils.NewUint64(0), - ApricotPhase3BlockTimestamp: utils.NewUint64(0), - ApricotPhase4BlockTimestamp: utils.NewUint64(0), + ApricotPhase1BlockTimestamp: utils.PointerTo(uint64(0)), + ApricotPhase2BlockTimestamp: utils.PointerTo(uint64(0)), + ApricotPhase3BlockTimestamp: utils.PointerTo(uint64(0)), + ApricotPhase4BlockTimestamp: utils.PointerTo(uint64(0)), }, }, ), @@ -287,11 +287,11 @@ func initializeForks() { }, &extras.ChainConfig{ NetworkUpgrades: extras.NetworkUpgrades{ - ApricotPhase1BlockTimestamp: utils.NewUint64(0), - ApricotPhase2BlockTimestamp: utils.NewUint64(0), - ApricotPhase3BlockTimestamp: utils.NewUint64(0), - ApricotPhase4BlockTimestamp: utils.NewUint64(0), - ApricotPhase5BlockTimestamp: utils.NewUint64(0), + ApricotPhase1BlockTimestamp: utils.PointerTo(uint64(0)), + ApricotPhase2BlockTimestamp: utils.PointerTo(uint64(0)), + ApricotPhase3BlockTimestamp: utils.PointerTo(uint64(0)), + ApricotPhase4BlockTimestamp: utils.PointerTo(uint64(0)), + ApricotPhase5BlockTimestamp: utils.PointerTo(uint64(0)), }, }, ), @@ -311,12 +311,12 @@ func initializeForks() { }, &extras.ChainConfig{ NetworkUpgrades: extras.NetworkUpgrades{ - ApricotPhase1BlockTimestamp: utils.NewUint64(0), - ApricotPhase2BlockTimestamp: utils.NewUint64(0), - ApricotPhase3BlockTimestamp: utils.NewUint64(0), - ApricotPhase4BlockTimestamp: utils.NewUint64(0), - ApricotPhase5BlockTimestamp: utils.NewUint64(0), - BanffBlockTimestamp: utils.NewUint64(0), + ApricotPhase1BlockTimestamp: utils.PointerTo(uint64(0)), + ApricotPhase2BlockTimestamp: utils.PointerTo(uint64(0)), + ApricotPhase3BlockTimestamp: utils.PointerTo(uint64(0)), + ApricotPhase4BlockTimestamp: utils.PointerTo(uint64(0)), + ApricotPhase5BlockTimestamp: utils.PointerTo(uint64(0)), + BanffBlockTimestamp: utils.PointerTo(uint64(0)), }, }, ), @@ -336,13 +336,13 @@ func initializeForks() { }, &extras.ChainConfig{ NetworkUpgrades: extras.NetworkUpgrades{ - ApricotPhase1BlockTimestamp: utils.NewUint64(0), - ApricotPhase2BlockTimestamp: utils.NewUint64(0), - ApricotPhase3BlockTimestamp: utils.NewUint64(0), - ApricotPhase4BlockTimestamp: utils.NewUint64(0), - ApricotPhase5BlockTimestamp: utils.NewUint64(0), - BanffBlockTimestamp: utils.NewUint64(0), - CortinaBlockTimestamp: utils.NewUint64(0), + ApricotPhase1BlockTimestamp: utils.PointerTo(uint64(0)), + ApricotPhase2BlockTimestamp: utils.PointerTo(uint64(0)), + ApricotPhase3BlockTimestamp: utils.PointerTo(uint64(0)), + ApricotPhase4BlockTimestamp: utils.PointerTo(uint64(0)), + ApricotPhase5BlockTimestamp: utils.PointerTo(uint64(0)), + BanffBlockTimestamp: utils.PointerTo(uint64(0)), + CortinaBlockTimestamp: utils.PointerTo(uint64(0)), }, }, ), @@ -362,14 +362,14 @@ func initializeForks() { }, &extras.ChainConfig{ NetworkUpgrades: extras.NetworkUpgrades{ - ApricotPhase1BlockTimestamp: utils.NewUint64(0), - ApricotPhase2BlockTimestamp: utils.NewUint64(0), - ApricotPhase3BlockTimestamp: utils.NewUint64(0), - ApricotPhase4BlockTimestamp: utils.NewUint64(0), - ApricotPhase5BlockTimestamp: utils.NewUint64(0), - BanffBlockTimestamp: utils.NewUint64(0), - CortinaBlockTimestamp: utils.NewUint64(0), - DurangoBlockTimestamp: utils.NewUint64(0), + ApricotPhase1BlockTimestamp: utils.PointerTo(uint64(0)), + ApricotPhase2BlockTimestamp: utils.PointerTo(uint64(0)), + ApricotPhase3BlockTimestamp: utils.PointerTo(uint64(0)), + ApricotPhase4BlockTimestamp: utils.PointerTo(uint64(0)), + ApricotPhase5BlockTimestamp: utils.PointerTo(uint64(0)), + BanffBlockTimestamp: utils.PointerTo(uint64(0)), + CortinaBlockTimestamp: utils.PointerTo(uint64(0)), + DurangoBlockTimestamp: utils.PointerTo(uint64(0)), }, }, ), @@ -386,19 +386,19 @@ func initializeForks() { IstanbulBlock: 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.ChainConfig{ NetworkUpgrades: extras.NetworkUpgrades{ - ApricotPhase1BlockTimestamp: utils.NewUint64(0), - ApricotPhase2BlockTimestamp: utils.NewUint64(0), - ApricotPhase3BlockTimestamp: utils.NewUint64(0), - ApricotPhase4BlockTimestamp: utils.NewUint64(0), - ApricotPhase5BlockTimestamp: utils.NewUint64(0), - BanffBlockTimestamp: utils.NewUint64(0), - CortinaBlockTimestamp: utils.NewUint64(0), - DurangoBlockTimestamp: utils.NewUint64(0), + ApricotPhase1BlockTimestamp: utils.PointerTo(uint64(0)), + ApricotPhase2BlockTimestamp: utils.PointerTo(uint64(0)), + ApricotPhase3BlockTimestamp: utils.PointerTo(uint64(0)), + ApricotPhase4BlockTimestamp: utils.PointerTo(uint64(0)), + ApricotPhase5BlockTimestamp: utils.PointerTo(uint64(0)), + BanffBlockTimestamp: utils.PointerTo(uint64(0)), + CortinaBlockTimestamp: utils.PointerTo(uint64(0)), + DurangoBlockTimestamp: utils.PointerTo(uint64(0)), }, }, ), diff --git a/utils/numbers.go b/utils/numbers.go index 5d983a25fe..1361f011db 100644 --- a/utils/numbers.go +++ b/utils/numbers.go @@ -8,11 +8,11 @@ import ( "time" ) -func NewUint64(val uint64) *uint64 { return &val } +func PointerTo[T any](x T) *T { return &x } func TimeToNewUint64(time time.Time) *uint64 { unix := uint64(time.Unix()) - return NewUint64(unix) + return PointerTo(unix) } func Uint64ToTime(val *uint64) time.Time { diff --git a/utils/utilstest/pointer.go b/utils/utilstest/pointer.go deleted file mode 100644 index 27b36369d7..0000000000 --- a/utils/utilstest/pointer.go +++ /dev/null @@ -1,6 +0,0 @@ -// Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. -// See the file LICENSE for licensing terms. - -package utilstest - -func PointerTo[T any](x T) *T { return &x }