From 1adc32865ef59f9157e2578e2739e5671d878aee Mon Sep 17 00:00:00 2001 From: Alberto Benegiamo Date: Wed, 10 Jan 2024 13:52:05 +0100 Subject: [PATCH 01/18] E fork scaffolding --- node/node.go | 3 + version/constants.go | 13 ++ vms/avm/block/executor/block_test.go | 140 +++++++++++++++++- vms/avm/block/executor/manager_test.go | 25 +++- vms/avm/config/config.go | 7 + vms/avm/environment_test.go | 3 + vms/avm/index_test.go | 17 ++- vms/avm/service_test.go | 36 ++++- .../txs/executor/syntactic_verifier_test.go | 3 + vms/avm/vm_regression_test.go | 7 +- vms/avm/vm_test.go | 24 ++- vms/platformvm/block/builder/helpers_test.go | 2 + vms/platformvm/block/executor/helpers_test.go | 2 + vms/platformvm/config/config.go | 7 + vms/platformvm/txs/executor/helpers_test.go | 1 + .../executor/staker_tx_verification_test.go | 14 ++ .../txs/executor/standard_tx_executor_test.go | 14 ++ vms/platformvm/validator_set_property_test.go | 1 + vms/platformvm/vm_regression_test.go | 1 + vms/platformvm/vm_test.go | 8 + 20 files changed, 305 insertions(+), 23 deletions(-) diff --git a/node/node.go b/node/node.go index 45e2f6a506eb..0c61b0ba848a 100644 --- a/node/node.go +++ b/node/node.go @@ -1078,6 +1078,7 @@ func (n *Node) initVMs() error { }) durangoTime := version.GetDurangoTime(n.Config.NetworkID) + eForkTime := version.GetEForkTime(n.Config.NetworkID) if err := txs.InitCodec(durangoTime); err != nil { return err } @@ -1120,6 +1121,7 @@ func (n *Node) initVMs() error { BanffTime: version.GetBanffTime(n.Config.NetworkID), CortinaTime: version.GetCortinaTime(n.Config.NetworkID), DurangoTime: durangoTime, + EForkTime: eForkTime, UseCurrentHeight: n.Config.UseCurrentHeight, }, }), @@ -1128,6 +1130,7 @@ func (n *Node) initVMs() error { TxFee: n.Config.TxFee, CreateAssetTxFee: n.Config.CreateAssetTxFee, DurangoTime: durangoTime, + EForkTime: eForkTime, }, }), vmRegisterer.Register(context.TODO(), constants.EVMID, &coreth.Factory{}), diff --git a/version/constants.go b/version/constants.go index 053a57a4585b..4a4187bd2774 100644 --- a/version/constants.go +++ b/version/constants.go @@ -109,6 +109,12 @@ var ( constants.MainnetID: time.Date(10000, time.December, 1, 0, 0, 0, 0, time.UTC), constants.FujiID: time.Date(10000, time.December, 1, 0, 0, 0, 0, time.UTC), } + + EForkTimes = map[uint32]time.Time{ + constants.MainnetID: time.Date(10000, time.December, 1, 0, 0, 0, 0, time.UTC), + constants.FujiID: time.Date(10000, time.December, 1, 0, 0, 0, 0, time.UTC), + } + TempForkTime = time.Date(10000, time.December, 1, 0, 0, 0, 0, time.UTC) ) func init() { @@ -204,6 +210,13 @@ func GetDurangoTime(networkID uint32) time.Time { return DefaultUpgradeTime } +func GetEForkTime(networkID uint32) time.Time { + if upgradeTime, exists := EForkTimes[networkID]; exists { + return upgradeTime + } + return TempForkTime +} + func GetCompatibility(networkID uint32) Compatibility { return NewCompatibility( CurrentApp, diff --git a/vms/avm/block/executor/block_test.go b/vms/avm/block/executor/block_test.go index 0b6738822c6e..c44a69389568 100644 --- a/vms/avm/block/executor/block_test.go +++ b/vms/avm/block/executor/block_test.go @@ -23,6 +23,7 @@ import ( "github.com/ava-labs/avalanchego/utils/set" "github.com/ava-labs/avalanchego/utils/timer/mockable" "github.com/ava-labs/avalanchego/vms/avm/block" + "github.com/ava-labs/avalanchego/vms/avm/config" "github.com/ava-labs/avalanchego/vms/avm/metrics" "github.com/ava-labs/avalanchego/vms/avm/state" "github.com/ava-labs/avalanchego/vms/avm/txs" @@ -46,6 +47,12 @@ func TestBlockVerify(t *testing.T) { b := &Block{ Block: mockBlock, manager: &manager{ + backend: &executor.Backend{ + Config: &config.Config{ + DurangoTime: time.Time{}, + EForkTime: mockable.MaxTime, + }, + }, blkIDToState: map[ids.ID]*blockState{}, }, } @@ -63,8 +70,15 @@ func TestBlockVerify(t *testing.T) { mockBlock.EXPECT().ID().Return(ids.Empty).AnyTimes() mockBlock.EXPECT().MerkleRoot().Return(ids.GenerateTestID()).AnyTimes() return &Block{ - Block: mockBlock, - manager: &manager{}, + Block: mockBlock, + manager: &manager{ + backend: &executor.Backend{ + Config: &config.Config{ + DurangoTime: time.Time{}, + EForkTime: mockable.MaxTime, + }, + }, + }, } }, expectedErr: ErrUnexpectedMerkleRoot, @@ -83,6 +97,12 @@ func TestBlockVerify(t *testing.T) { return &Block{ Block: mockBlock, manager: &manager{ + backend: &executor.Backend{ + Config: &config.Config{ + DurangoTime: time.Time{}, + EForkTime: mockable.MaxTime, + }, + }, clk: clk, }, } @@ -100,6 +120,12 @@ func TestBlockVerify(t *testing.T) { return &Block{ Block: mockBlock, manager: &manager{ + backend: &executor.Backend{ + Config: &config.Config{ + DurangoTime: time.Time{}, + EForkTime: mockable.MaxTime, + }, + }, blkIDToState: map[ids.ID]*blockState{}, clk: &mockable.Clock{}, }, @@ -126,6 +152,12 @@ func TestBlockVerify(t *testing.T) { return &Block{ Block: mockBlock, manager: &manager{ + backend: &executor.Backend{ + Config: &config.Config{ + DurangoTime: time.Time{}, + EForkTime: mockable.MaxTime, + }, + }, mempool: mempool, metrics: metrics.NewMockMetrics(ctrl), blkIDToState: map[ids.ID]*blockState{}, @@ -158,6 +190,12 @@ func TestBlockVerify(t *testing.T) { return &Block{ Block: mockBlock, manager: &manager{ + backend: &executor.Backend{ + Config: &config.Config{ + DurangoTime: time.Time{}, + EForkTime: mockable.MaxTime, + }, + }, state: mockState, blkIDToState: map[ids.ID]*blockState{}, clk: &mockable.Clock{}, @@ -194,6 +232,12 @@ func TestBlockVerify(t *testing.T) { return &Block{ Block: mockBlock, manager: &manager{ + backend: &executor.Backend{ + Config: &config.Config{ + DurangoTime: time.Time{}, + EForkTime: mockable.MaxTime, + }, + }, state: mockState, blkIDToState: map[ids.ID]*blockState{}, clk: &mockable.Clock{}, @@ -233,6 +277,12 @@ func TestBlockVerify(t *testing.T) { return &Block{ Block: mockBlock, manager: &manager{ + backend: &executor.Backend{ + Config: &config.Config{ + DurangoTime: time.Time{}, + EForkTime: mockable.MaxTime, + }, + }, blkIDToState: map[ids.ID]*blockState{ parentID: { onAcceptState: mockParentState, @@ -280,6 +330,12 @@ func TestBlockVerify(t *testing.T) { return &Block{ Block: mockBlock, manager: &manager{ + backend: &executor.Backend{ + Config: &config.Config{ + DurangoTime: time.Time{}, + EForkTime: mockable.MaxTime, + }, + }, mempool: mempool, metrics: metrics.NewMockMetrics(ctrl), blkIDToState: map[ids.ID]*blockState{ @@ -332,7 +388,12 @@ func TestBlockVerify(t *testing.T) { manager: &manager{ mempool: mempool, metrics: metrics.NewMockMetrics(ctrl), - backend: &executor.Backend{}, + backend: &executor.Backend{ + Config: &config.Config{ + DurangoTime: time.Time{}, + EForkTime: mockable.MaxTime, + }, + }, blkIDToState: map[ids.ID]*blockState{ parentID: { onAcceptState: mockParentState, @@ -410,7 +471,12 @@ func TestBlockVerify(t *testing.T) { manager: &manager{ mempool: mempool, metrics: metrics.NewMockMetrics(ctrl), - backend: &executor.Backend{}, + backend: &executor.Backend{ + Config: &config.Config{ + DurangoTime: time.Time{}, + EForkTime: mockable.MaxTime, + }, + }, blkIDToState: map[ids.ID]*blockState{ parentID: { onAcceptState: mockParentState, @@ -468,7 +534,12 @@ func TestBlockVerify(t *testing.T) { return &Block{ Block: mockBlock, manager: &manager{ - backend: &executor.Backend{}, + backend: &executor.Backend{ + Config: &config.Config{ + DurangoTime: time.Time{}, + EForkTime: mockable.MaxTime, + }, + }, blkIDToState: map[ids.ID]*blockState{ parentID: { onAcceptState: mockParentState, @@ -520,7 +591,12 @@ func TestBlockVerify(t *testing.T) { manager: &manager{ mempool: mockMempool, metrics: metrics.NewMockMetrics(ctrl), - backend: &executor.Backend{}, + backend: &executor.Backend{ + Config: &config.Config{ + DurangoTime: time.Time{}, + EForkTime: mockable.MaxTime, + }, + }, blkIDToState: map[ids.ID]*blockState{ parentID: { onAcceptState: mockParentState, @@ -598,6 +674,10 @@ func TestBlockAccept(t *testing.T) { Ctx: &snow.Context{ Log: logging.NoLog{}, }, + Config: &config.Config{ + DurangoTime: time.Time{}, + EForkTime: mockable.MaxTime, + }, }, blkIDToState: map[ids.ID]*blockState{}, }, @@ -632,6 +712,10 @@ func TestBlockAccept(t *testing.T) { Ctx: &snow.Context{ Log: logging.NoLog{}, }, + Config: &config.Config{ + DurangoTime: time.Time{}, + EForkTime: mockable.MaxTime, + }, }, blkIDToState: map[ids.ID]*blockState{ blockID: { @@ -676,6 +760,10 @@ func TestBlockAccept(t *testing.T) { SharedMemory: mockSharedMemory, Log: logging.NoLog{}, }, + Config: &config.Config{ + DurangoTime: time.Time{}, + EForkTime: mockable.MaxTime, + }, }, blkIDToState: map[ids.ID]*blockState{ blockID: { @@ -724,6 +812,10 @@ func TestBlockAccept(t *testing.T) { SharedMemory: mockSharedMemory, Log: logging.NoLog{}, }, + Config: &config.Config{ + DurangoTime: time.Time{}, + EForkTime: mockable.MaxTime, + }, }, blkIDToState: map[ids.ID]*blockState{ blockID: { @@ -775,6 +867,10 @@ func TestBlockAccept(t *testing.T) { SharedMemory: mockSharedMemory, Log: logging.NoLog{}, }, + Config: &config.Config{ + DurangoTime: time.Time{}, + EForkTime: mockable.MaxTime, + }, }, blkIDToState: map[ids.ID]*blockState{ blockID: { @@ -872,6 +968,10 @@ func TestBlockReject(t *testing.T) { metrics: metrics.NewMockMetrics(ctrl), backend: &executor.Backend{ Bootstrapped: true, + Config: &config.Config{ + DurangoTime: time.Time{}, + EForkTime: mockable.MaxTime, + }, Ctx: &snow.Context{ Log: logging.NoLog{}, }, @@ -933,6 +1033,10 @@ func TestBlockReject(t *testing.T) { Ctx: &snow.Context{ Log: logging.NoLog{}, }, + Config: &config.Config{ + DurangoTime: time.Time{}, + EForkTime: mockable.MaxTime, + }, }, state: mockState, blkIDToState: map[ids.ID]*blockState{ @@ -982,6 +1086,12 @@ func TestBlockStatus(t *testing.T) { return &Block{ Block: mockBlock, manager: &manager{ + backend: &executor.Backend{ + Config: &config.Config{ + DurangoTime: time.Time{}, + EForkTime: mockable.MaxTime, + }, + }, lastAccepted: blockID, }, } @@ -997,6 +1107,12 @@ func TestBlockStatus(t *testing.T) { return &Block{ Block: mockBlock, manager: &manager{ + backend: &executor.Backend{ + Config: &config.Config{ + DurangoTime: time.Time{}, + EForkTime: mockable.MaxTime, + }, + }, blkIDToState: map[ids.ID]*blockState{ blockID: {}, }, @@ -1018,6 +1134,12 @@ func TestBlockStatus(t *testing.T) { return &Block{ Block: mockBlock, manager: &manager{ + backend: &executor.Backend{ + Config: &config.Config{ + DurangoTime: time.Time{}, + EForkTime: mockable.MaxTime, + }, + }, blkIDToState: map[ids.ID]*blockState{}, state: mockState, }, @@ -1038,6 +1160,12 @@ func TestBlockStatus(t *testing.T) { return &Block{ Block: mockBlock, manager: &manager{ + backend: &executor.Backend{ + Config: &config.Config{ + DurangoTime: time.Time{}, + EForkTime: mockable.MaxTime, + }, + }, blkIDToState: map[ids.ID]*blockState{}, state: mockState, }, diff --git a/vms/avm/block/executor/manager_test.go b/vms/avm/block/executor/manager_test.go index 012428d582e4..89b547eed967 100644 --- a/vms/avm/block/executor/manager_test.go +++ b/vms/avm/block/executor/manager_test.go @@ -14,7 +14,9 @@ import ( "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/utils/set" + "github.com/ava-labs/avalanchego/utils/timer/mockable" "github.com/ava-labs/avalanchego/vms/avm/block" + "github.com/ava-labs/avalanchego/vms/avm/config" "github.com/ava-labs/avalanchego/vms/avm/state" "github.com/ava-labs/avalanchego/vms/avm/txs" "github.com/ava-labs/avalanchego/vms/avm/txs/executor" @@ -124,7 +126,12 @@ func TestManagerVerifyTx(t *testing.T) { }, managerF: func(ctrl *gomock.Controller) *manager { return &manager{ - backend: &executor.Backend{}, + backend: &executor.Backend{ + Config: &config.Config{ + DurangoTime: time.Time{}, + EForkTime: mockable.MaxTime, + }, + }, } }, expectedErr: ErrChainNotSynced, @@ -142,6 +149,10 @@ func TestManagerVerifyTx(t *testing.T) { return &manager{ backend: &executor.Backend{ Bootstrapped: true, + Config: &config.Config{ + DurangoTime: time.Time{}, + EForkTime: mockable.MaxTime, + }, }, } }, @@ -170,6 +181,10 @@ func TestManagerVerifyTx(t *testing.T) { return &manager{ backend: &executor.Backend{ Bootstrapped: true, + Config: &config.Config{ + DurangoTime: time.Time{}, + EForkTime: mockable.MaxTime, + }, }, state: state, lastAccepted: lastAcceptedID, @@ -202,6 +217,10 @@ func TestManagerVerifyTx(t *testing.T) { return &manager{ backend: &executor.Backend{ Bootstrapped: true, + Config: &config.Config{ + DurangoTime: time.Time{}, + EForkTime: mockable.MaxTime, + }, }, state: state, lastAccepted: lastAcceptedID, @@ -234,6 +253,10 @@ func TestManagerVerifyTx(t *testing.T) { return &manager{ backend: &executor.Backend{ Bootstrapped: true, + Config: &config.Config{ + DurangoTime: time.Time{}, + EForkTime: mockable.MaxTime, + }, }, state: state, lastAccepted: lastAcceptedID, diff --git a/vms/avm/config/config.go b/vms/avm/config/config.go index df6e4f7de2ae..b4da6e3781ea 100644 --- a/vms/avm/config/config.go +++ b/vms/avm/config/config.go @@ -15,4 +15,11 @@ type Config struct { // Time of the Durango network upgrade DurangoTime time.Time + + // Time of the E network upgrade + EForkTime time.Time +} + +func (c *Config) IsEForkActivated(timestamp time.Time) bool { + return !timestamp.Before(c.EForkTime) } diff --git a/vms/avm/environment_test.go b/vms/avm/environment_test.go index 236c20875796..00a1b2725e47 100644 --- a/vms/avm/environment_test.go +++ b/vms/avm/environment_test.go @@ -29,6 +29,7 @@ import ( "github.com/ava-labs/avalanchego/utils/linkedhashmap" "github.com/ava-labs/avalanchego/utils/logging" "github.com/ava-labs/avalanchego/utils/sampler" + "github.com/ava-labs/avalanchego/utils/timer/mockable" "github.com/ava-labs/avalanchego/vms/avm/block/executor" "github.com/ava-labs/avalanchego/vms/avm/config" "github.com/ava-labs/avalanchego/vms/avm/fxs" @@ -149,6 +150,8 @@ func setup(tb testing.TB, c *envConfig) *environment { vmStaticConfig := config.Config{ TxFee: testTxFee, CreateAssetTxFee: testTxFee, + DurangoTime: time.Time{}, + EForkTime: mockable.MaxTime, } if c.vmStaticConfig != nil { vmStaticConfig = *c.vmStaticConfig diff --git a/vms/avm/index_test.go b/vms/avm/index_test.go index 03a2fd863c6a..642410951c9e 100644 --- a/vms/avm/index_test.go +++ b/vms/avm/index_test.go @@ -6,6 +6,7 @@ package avm import ( "context" "testing" + "time" "github.com/prometheus/client_golang/prometheus" @@ -20,6 +21,7 @@ import ( "github.com/ava-labs/avalanchego/utils/constants" "github.com/ava-labs/avalanchego/utils/crypto/secp256k1" "github.com/ava-labs/avalanchego/utils/logging" + "github.com/ava-labs/avalanchego/utils/timer/mockable" "github.com/ava-labs/avalanchego/vms/avm/config" "github.com/ava-labs/avalanchego/vms/avm/txs" "github.com/ava-labs/avalanchego/vms/components/avax" @@ -31,7 +33,10 @@ func TestIndexTransaction_Ordered(t *testing.T) { require := require.New(t) env := setup(t, &envConfig{ - vmStaticConfig: &config.Config{}, + vmStaticConfig: &config.Config{ + DurangoTime: time.Time{}, + EForkTime: mockable.MaxTime, + }, }) defer func() { require.NoError(env.vm.Shutdown(context.Background())) @@ -75,7 +80,10 @@ func TestIndexTransaction_MultipleTransactions(t *testing.T) { require := require.New(t) env := setup(t, &envConfig{ - vmStaticConfig: &config.Config{}, + vmStaticConfig: &config.Config{ + DurangoTime: time.Time{}, + EForkTime: mockable.MaxTime, + }, }) defer func() { require.NoError(env.vm.Shutdown(context.Background())) @@ -123,7 +131,10 @@ func TestIndexTransaction_MultipleAddresses(t *testing.T) { require := require.New(t) env := setup(t, &envConfig{ - vmStaticConfig: &config.Config{}, + vmStaticConfig: &config.Config{ + DurangoTime: time.Time{}, + EForkTime: mockable.MaxTime, + }, }) defer func() { require.NoError(env.vm.Shutdown(context.Background())) diff --git a/vms/avm/service_test.go b/vms/avm/service_test.go index c659b8e9de9e..62f81d08f48c 100644 --- a/vms/avm/service_test.go +++ b/vms/avm/service_test.go @@ -34,6 +34,7 @@ import ( "github.com/ava-labs/avalanchego/utils/formatting/address" "github.com/ava-labs/avalanchego/utils/json" "github.com/ava-labs/avalanchego/utils/logging" + "github.com/ava-labs/avalanchego/utils/timer/mockable" "github.com/ava-labs/avalanchego/vms/avm/block" "github.com/ava-labs/avalanchego/vms/avm/block/executor" "github.com/ava-labs/avalanchego/vms/avm/config" @@ -703,7 +704,10 @@ func TestServiceGetTxJSON_CreateAssetTx(t *testing.T) { require := require.New(t) env := setup(t, &envConfig{ - vmStaticConfig: &config.Config{}, + vmStaticConfig: &config.Config{ + DurangoTime: time.Time{}, + EForkTime: mockable.MaxTime, + }, additionalFxs: []*common.Fx{{ ID: propertyfx.ID, Fx: &propertyfx.Fx{}, @@ -819,7 +823,10 @@ func TestServiceGetTxJSON_OperationTxWithNftxMintOp(t *testing.T) { require := require.New(t) env := setup(t, &envConfig{ - vmStaticConfig: &config.Config{}, + vmStaticConfig: &config.Config{ + DurangoTime: time.Time{}, + EForkTime: mockable.MaxTime, + }, additionalFxs: []*common.Fx{{ ID: propertyfx.ID, Fx: &propertyfx.Fx{}, @@ -918,7 +925,10 @@ func TestServiceGetTxJSON_OperationTxWithMultipleNftxMintOp(t *testing.T) { require := require.New(t) env := setup(t, &envConfig{ - vmStaticConfig: &config.Config{}, + vmStaticConfig: &config.Config{ + DurangoTime: time.Time{}, + EForkTime: mockable.MaxTime, + }, additionalFxs: []*common.Fx{{ ID: propertyfx.ID, Fx: &propertyfx.Fx{}, @@ -1056,7 +1066,10 @@ func TestServiceGetTxJSON_OperationTxWithSecpMintOp(t *testing.T) { require := require.New(t) env := setup(t, &envConfig{ - vmStaticConfig: &config.Config{}, + vmStaticConfig: &config.Config{ + DurangoTime: time.Time{}, + EForkTime: mockable.MaxTime, + }, additionalFxs: []*common.Fx{{ ID: propertyfx.ID, Fx: &propertyfx.Fx{}, @@ -1159,7 +1172,10 @@ func TestServiceGetTxJSON_OperationTxWithMultipleSecpMintOp(t *testing.T) { require := require.New(t) env := setup(t, &envConfig{ - vmStaticConfig: &config.Config{}, + vmStaticConfig: &config.Config{ + DurangoTime: time.Time{}, + EForkTime: mockable.MaxTime, + }, additionalFxs: []*common.Fx{{ ID: propertyfx.ID, Fx: &propertyfx.Fx{}, @@ -1305,7 +1321,10 @@ func TestServiceGetTxJSON_OperationTxWithPropertyFxMintOp(t *testing.T) { require := require.New(t) env := setup(t, &envConfig{ - vmStaticConfig: &config.Config{}, + vmStaticConfig: &config.Config{ + DurangoTime: time.Time{}, + EForkTime: mockable.MaxTime, + }, additionalFxs: []*common.Fx{{ ID: propertyfx.ID, Fx: &propertyfx.Fx{}, @@ -1405,7 +1424,10 @@ func TestServiceGetTxJSON_OperationTxWithPropertyFxMintOpMultiple(t *testing.T) require := require.New(t) env := setup(t, &envConfig{ - vmStaticConfig: &config.Config{}, + vmStaticConfig: &config.Config{ + DurangoTime: time.Time{}, + EForkTime: mockable.MaxTime, + }, additionalFxs: []*common.Fx{{ ID: propertyfx.ID, Fx: &propertyfx.Fx{}, diff --git a/vms/avm/txs/executor/syntactic_verifier_test.go b/vms/avm/txs/executor/syntactic_verifier_test.go index 108ac9e94a60..3b5c05d42d07 100644 --- a/vms/avm/txs/executor/syntactic_verifier_test.go +++ b/vms/avm/txs/executor/syntactic_verifier_test.go @@ -15,6 +15,7 @@ import ( "github.com/ava-labs/avalanchego/snow/snowtest" "github.com/ava-labs/avalanchego/utils/constants" "github.com/ava-labs/avalanchego/utils/crypto/secp256k1" + "github.com/ava-labs/avalanchego/utils/timer/mockable" "github.com/ava-labs/avalanchego/vms/avm/config" "github.com/ava-labs/avalanchego/vms/avm/fxs" "github.com/ava-labs/avalanchego/vms/avm/txs" @@ -30,6 +31,8 @@ var ( feeConfig = config.Config{ TxFee: 2, CreateAssetTxFee: 3, + DurangoTime: time.Time{}, + EForkTime: mockable.MaxTime, } ) diff --git a/vms/avm/vm_regression_test.go b/vms/avm/vm_regression_test.go index c6ac40df845d..1e4720f80fe1 100644 --- a/vms/avm/vm_regression_test.go +++ b/vms/avm/vm_regression_test.go @@ -6,12 +6,14 @@ package avm import ( "context" "testing" + "time" "github.com/stretchr/testify/require" "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/utils/constants" "github.com/ava-labs/avalanchego/utils/crypto/secp256k1" + "github.com/ava-labs/avalanchego/utils/timer/mockable" "github.com/ava-labs/avalanchego/vms/avm/config" "github.com/ava-labs/avalanchego/vms/avm/txs" "github.com/ava-labs/avalanchego/vms/components/avax" @@ -24,7 +26,10 @@ func TestVerifyFxUsage(t *testing.T) { require := require.New(t) env := setup(t, &envConfig{ - vmStaticConfig: &config.Config{}, + vmStaticConfig: &config.Config{ + DurangoTime: time.Time{}, + EForkTime: mockable.MaxTime, + }, }) env.vm.ctx.Lock.Unlock() defer func() { diff --git a/vms/avm/vm_test.go b/vms/avm/vm_test.go index d8aeaf3b8743..f7c7d11af0ea 100644 --- a/vms/avm/vm_test.go +++ b/vms/avm/vm_test.go @@ -7,6 +7,7 @@ import ( "context" "math" "testing" + "time" "github.com/stretchr/testify/require" @@ -19,6 +20,7 @@ import ( "github.com/ava-labs/avalanchego/snow/snowtest" "github.com/ava-labs/avalanchego/utils/constants" "github.com/ava-labs/avalanchego/utils/crypto/secp256k1" + "github.com/ava-labs/avalanchego/utils/timer/mockable" "github.com/ava-labs/avalanchego/vms/avm/config" "github.com/ava-labs/avalanchego/vms/avm/fxs" "github.com/ava-labs/avalanchego/vms/avm/txs" @@ -132,7 +134,10 @@ func TestIssueNFT(t *testing.T) { require := require.New(t) env := setup(t, &envConfig{ - vmStaticConfig: &config.Config{}, + vmStaticConfig: &config.Config{ + DurangoTime: time.Time{}, + EForkTime: mockable.MaxTime, + }, }) env.vm.ctx.Lock.Unlock() defer func() { @@ -233,7 +238,10 @@ func TestIssueProperty(t *testing.T) { require := require.New(t) env := setup(t, &envConfig{ - vmStaticConfig: &config.Config{}, + vmStaticConfig: &config.Config{ + DurangoTime: time.Time{}, + EForkTime: mockable.MaxTime, + }, additionalFxs: []*common.Fx{{ ID: propertyfx.ID, Fx: &propertyfx.Fx{}, @@ -520,7 +528,10 @@ func TestIssueImportTx(t *testing.T) { require := require.New(t) env := setup(t, &envConfig{ - vmStaticConfig: &config.Config{}, + vmStaticConfig: &config.Config{ + DurangoTime: time.Time{}, + EForkTime: mockable.MaxTime, + }, }) defer func() { require.NoError(env.vm.Shutdown(context.Background())) @@ -620,8 +631,11 @@ func TestForceAcceptImportTx(t *testing.T) { require := require.New(t) env := setup(t, &envConfig{ - vmStaticConfig: &config.Config{}, - notLinearized: true, + vmStaticConfig: &config.Config{ + DurangoTime: time.Time{}, + EForkTime: mockable.MaxTime, + }, + notLinearized: true, }) defer func() { require.NoError(env.vm.Shutdown(context.Background())) diff --git a/vms/platformvm/block/builder/helpers_test.go b/vms/platformvm/block/builder/helpers_test.go index fa7339be6fdb..7d84060b1346 100644 --- a/vms/platformvm/block/builder/helpers_test.go +++ b/vms/platformvm/block/builder/helpers_test.go @@ -298,6 +298,8 @@ func defaultConfig() *config.Config { ApricotPhase3Time: defaultValidateEndTime, ApricotPhase5Time: defaultValidateEndTime, BanffTime: time.Time{}, // neglecting fork ordering this for package tests + DurangoTime: time.Time{}, + EForkTime: mockable.MaxTime, } } diff --git a/vms/platformvm/block/executor/helpers_test.go b/vms/platformvm/block/executor/helpers_test.go index 5e7b5a3fce1e..848cbdb5c624 100644 --- a/vms/platformvm/block/executor/helpers_test.go +++ b/vms/platformvm/block/executor/helpers_test.go @@ -316,6 +316,8 @@ func defaultConfig() *config.Config { ApricotPhase3Time: defaultValidateEndTime, ApricotPhase5Time: defaultValidateEndTime, BanffTime: mockable.MaxTime, + DurangoTime: mockable.MaxTime, + EForkTime: mockable.MaxTime, } } diff --git a/vms/platformvm/config/config.go b/vms/platformvm/config/config.go index 50628c422afd..292981ddc021 100644 --- a/vms/platformvm/config/config.go +++ b/vms/platformvm/config/config.go @@ -107,6 +107,9 @@ type Config struct { // Time of the Durango network upgrade DurangoTime time.Time + // Time of the E network upgrade + EForkTime time.Time + // UseCurrentHeight forces [GetMinimumHeight] to return the current height // of the P-Chain instead of the oldest block in the [recentlyAccepted] // window. @@ -137,6 +140,10 @@ func (c *Config) IsDurangoActivated(timestamp time.Time) bool { return !timestamp.Before(c.DurangoTime) } +func (c *Config) IsEForkActivated(timestamp time.Time) bool { + return !timestamp.Before(c.EForkTime) +} + func (c *Config) GetCreateBlockchainTxFee(timestamp time.Time) uint64 { if c.IsApricotPhase3Activated(timestamp) { return c.CreateBlockchainTxFee diff --git a/vms/platformvm/txs/executor/helpers_test.go b/vms/platformvm/txs/executor/helpers_test.go index 1ea645efcfb8..7f90b6ab7852 100644 --- a/vms/platformvm/txs/executor/helpers_test.go +++ b/vms/platformvm/txs/executor/helpers_test.go @@ -284,6 +284,7 @@ func defaultConfig(postBanff, postCortina, postDurango bool) *config.Config { BanffTime: banffTime, CortinaTime: cortinaTime, DurangoTime: durangoTime, + EForkTime: mockable.MaxTime, } } diff --git a/vms/platformvm/txs/executor/staker_tx_verification_test.go b/vms/platformvm/txs/executor/staker_tx_verification_test.go index b59daf0da2b0..204ed382a2ac 100644 --- a/vms/platformvm/txs/executor/staker_tx_verification_test.go +++ b/vms/platformvm/txs/executor/staker_tx_verification_test.go @@ -113,6 +113,7 @@ func TestVerifyAddPermissionlessValidatorTx(t *testing.T) { Ctx: ctx, Config: &config.Config{ DurangoTime: activeForkTime, // activate latest fork + EForkTime: mockable.MaxTime, }, } }, @@ -134,6 +135,7 @@ func TestVerifyAddPermissionlessValidatorTx(t *testing.T) { Ctx: ctx, Config: &config.Config{ DurangoTime: activeForkTime, // activate latest fork + EForkTime: mockable.MaxTime, }, Bootstrapped: &utils.Atomic[bool]{}, } @@ -159,6 +161,7 @@ func TestVerifyAddPermissionlessValidatorTx(t *testing.T) { Config: &config.Config{ CortinaTime: activeForkTime, DurangoTime: mockable.MaxTime, + EForkTime: mockable.MaxTime, }, Bootstrapped: bootstrapped, } @@ -185,6 +188,7 @@ func TestVerifyAddPermissionlessValidatorTx(t *testing.T) { Ctx: ctx, Config: &config.Config{ DurangoTime: activeForkTime, // activate latest fork + EForkTime: mockable.MaxTime, }, Bootstrapped: bootstrapped, } @@ -214,6 +218,7 @@ func TestVerifyAddPermissionlessValidatorTx(t *testing.T) { Ctx: ctx, Config: &config.Config{ DurangoTime: activeForkTime, // activate latest fork + EForkTime: mockable.MaxTime, }, Bootstrapped: bootstrapped, } @@ -243,6 +248,7 @@ func TestVerifyAddPermissionlessValidatorTx(t *testing.T) { Ctx: ctx, Config: &config.Config{ DurangoTime: activeForkTime, // activate latest fork + EForkTime: mockable.MaxTime, }, Bootstrapped: bootstrapped, } @@ -273,6 +279,7 @@ func TestVerifyAddPermissionlessValidatorTx(t *testing.T) { Ctx: ctx, Config: &config.Config{ DurangoTime: activeForkTime, // activate latest fork + EForkTime: mockable.MaxTime, }, Bootstrapped: bootstrapped, } @@ -306,6 +313,7 @@ func TestVerifyAddPermissionlessValidatorTx(t *testing.T) { Ctx: ctx, Config: &config.Config{ DurangoTime: activeForkTime, // activate latest fork + EForkTime: mockable.MaxTime, }, Bootstrapped: bootstrapped, } @@ -339,6 +347,7 @@ func TestVerifyAddPermissionlessValidatorTx(t *testing.T) { Ctx: ctx, Config: &config.Config{ DurangoTime: activeForkTime, // activate latest fork + EForkTime: mockable.MaxTime, }, Bootstrapped: bootstrapped, } @@ -374,6 +383,7 @@ func TestVerifyAddPermissionlessValidatorTx(t *testing.T) { Ctx: ctx, Config: &config.Config{ DurangoTime: activeForkTime, // activate latest fork + EForkTime: mockable.MaxTime, }, Bootstrapped: bootstrapped, } @@ -403,6 +413,7 @@ func TestVerifyAddPermissionlessValidatorTx(t *testing.T) { Ctx: ctx, Config: &config.Config{ DurangoTime: activeForkTime, // activate latest fork + EForkTime: mockable.MaxTime, }, Bootstrapped: bootstrapped, } @@ -449,6 +460,7 @@ func TestVerifyAddPermissionlessValidatorTx(t *testing.T) { Config: &config.Config{ AddSubnetValidatorFee: 1, DurangoTime: activeForkTime, // activate latest fork, + EForkTime: mockable.MaxTime, }, Ctx: ctx, Bootstrapped: bootstrapped, @@ -495,6 +507,7 @@ func TestVerifyAddPermissionlessValidatorTx(t *testing.T) { Config: &config.Config{ CortinaTime: activeForkTime, DurangoTime: mockable.MaxTime, + EForkTime: mockable.MaxTime, AddSubnetValidatorFee: 1, }, Ctx: ctx, @@ -547,6 +560,7 @@ func TestVerifyAddPermissionlessValidatorTx(t *testing.T) { Config: &config.Config{ AddSubnetValidatorFee: 1, DurangoTime: activeForkTime, // activate latest fork, + EForkTime: mockable.MaxTime, }, Ctx: ctx, Bootstrapped: bootstrapped, diff --git a/vms/platformvm/txs/executor/standard_tx_executor_test.go b/vms/platformvm/txs/executor/standard_tx_executor_test.go index a86c579fee79..de0e3eebecc2 100644 --- a/vms/platformvm/txs/executor/standard_tx_executor_test.go +++ b/vms/platformvm/txs/executor/standard_tx_executor_test.go @@ -21,6 +21,7 @@ import ( "github.com/ava-labs/avalanchego/utils/constants" "github.com/ava-labs/avalanchego/utils/crypto/secp256k1" "github.com/ava-labs/avalanchego/utils/hashing" + "github.com/ava-labs/avalanchego/utils/timer/mockable" "github.com/ava-labs/avalanchego/vms/components/avax" "github.com/ava-labs/avalanchego/vms/components/verify" "github.com/ava-labs/avalanchego/vms/platformvm/config" @@ -1150,6 +1151,7 @@ func TestStandardExecutorRemoveSubnetValidatorTx(t *testing.T) { BanffTime: env.latestForkTime, CortinaTime: env.latestForkTime, DurangoTime: env.latestForkTime, + EForkTime: mockable.MaxTime, }, Bootstrapped: &utils.Atomic[bool]{}, Fx: env.fx, @@ -1177,6 +1179,7 @@ func TestStandardExecutorRemoveSubnetValidatorTx(t *testing.T) { BanffTime: env.latestForkTime, CortinaTime: env.latestForkTime, DurangoTime: env.latestForkTime, + EForkTime: mockable.MaxTime, }, Bootstrapped: &utils.Atomic[bool]{}, Fx: env.fx, @@ -1204,6 +1207,7 @@ func TestStandardExecutorRemoveSubnetValidatorTx(t *testing.T) { BanffTime: env.latestForkTime, CortinaTime: env.latestForkTime, DurangoTime: env.latestForkTime, + EForkTime: mockable.MaxTime, }, Bootstrapped: &utils.Atomic[bool]{}, Fx: env.fx, @@ -1234,6 +1238,7 @@ func TestStandardExecutorRemoveSubnetValidatorTx(t *testing.T) { BanffTime: env.latestForkTime, CortinaTime: env.latestForkTime, DurangoTime: env.latestForkTime, + EForkTime: mockable.MaxTime, }, Bootstrapped: &utils.Atomic[bool]{}, Fx: env.fx, @@ -1262,6 +1267,7 @@ func TestStandardExecutorRemoveSubnetValidatorTx(t *testing.T) { BanffTime: env.latestForkTime, CortinaTime: env.latestForkTime, DurangoTime: env.latestForkTime, + EForkTime: mockable.MaxTime, }, Bootstrapped: &utils.Atomic[bool]{}, Fx: env.fx, @@ -1289,6 +1295,7 @@ func TestStandardExecutorRemoveSubnetValidatorTx(t *testing.T) { BanffTime: env.latestForkTime, CortinaTime: env.latestForkTime, DurangoTime: env.latestForkTime, + EForkTime: mockable.MaxTime, }, Bootstrapped: &utils.Atomic[bool]{}, Fx: env.fx, @@ -1318,6 +1325,7 @@ func TestStandardExecutorRemoveSubnetValidatorTx(t *testing.T) { BanffTime: env.latestForkTime, CortinaTime: env.latestForkTime, DurangoTime: env.latestForkTime, + EForkTime: mockable.MaxTime, }, Bootstrapped: &utils.Atomic[bool]{}, Fx: env.fx, @@ -1350,6 +1358,7 @@ func TestStandardExecutorRemoveSubnetValidatorTx(t *testing.T) { BanffTime: env.latestForkTime, CortinaTime: env.latestForkTime, DurangoTime: env.latestForkTime, + EForkTime: mockable.MaxTime, }, Bootstrapped: &utils.Atomic[bool]{}, Fx: env.fx, @@ -1507,6 +1516,7 @@ func TestStandardExecutorTransformSubnetTx(t *testing.T) { BanffTime: env.latestForkTime, CortinaTime: env.latestForkTime, DurangoTime: env.latestForkTime, + EForkTime: mockable.MaxTime, }, Bootstrapped: &utils.Atomic[bool]{}, Fx: env.fx, @@ -1533,6 +1543,7 @@ func TestStandardExecutorTransformSubnetTx(t *testing.T) { BanffTime: env.latestForkTime, CortinaTime: env.latestForkTime, DurangoTime: env.latestForkTime, + EForkTime: mockable.MaxTime, }, Bootstrapped: &utils.Atomic[bool]{}, Fx: env.fx, @@ -1561,6 +1572,7 @@ func TestStandardExecutorTransformSubnetTx(t *testing.T) { CortinaTime: env.latestForkTime, DurangoTime: env.latestForkTime, MaxStakeDuration: math.MaxInt64, + EForkTime: mockable.MaxTime, }, Bootstrapped: &utils.Atomic[bool]{}, Fx: env.fx, @@ -1593,6 +1605,7 @@ func TestStandardExecutorTransformSubnetTx(t *testing.T) { BanffTime: env.latestForkTime, CortinaTime: env.latestForkTime, DurangoTime: env.latestForkTime, + EForkTime: mockable.MaxTime, MaxStakeDuration: math.MaxInt64, }, Bootstrapped: &utils.Atomic[bool]{}, @@ -1631,6 +1644,7 @@ func TestStandardExecutorTransformSubnetTx(t *testing.T) { BanffTime: env.latestForkTime, CortinaTime: env.latestForkTime, DurangoTime: env.latestForkTime, + EForkTime: mockable.MaxTime, MaxStakeDuration: math.MaxInt64, }, Bootstrapped: &utils.Atomic[bool]{}, diff --git a/vms/platformvm/validator_set_property_test.go b/vms/platformvm/validator_set_property_test.go index 5ca5bfd6c241..c2894e594f7e 100644 --- a/vms/platformvm/validator_set_property_test.go +++ b/vms/platformvm/validator_set_property_test.go @@ -730,6 +730,7 @@ func buildVM(t *testing.T) (*VM, ids.ID, error) { ApricotPhase5Time: forkTime, BanffTime: forkTime, CortinaTime: forkTime, + EForkTime: mockable.MaxTime, }} vm.clock.Set(forkTime.Add(time.Second)) diff --git a/vms/platformvm/vm_regression_test.go b/vms/platformvm/vm_regression_test.go index 36186ec32ae0..a82cf6f76c67 100644 --- a/vms/platformvm/vm_regression_test.go +++ b/vms/platformvm/vm_regression_test.go @@ -373,6 +373,7 @@ func TestUnverifiedParentPanicRegression(t *testing.T) { BanffTime: latestForkTime, CortinaTime: mockable.MaxTime, DurangoTime: mockable.MaxTime, + EForkTime: mockable.MaxTime, }} ctx := snowtest.Context(t, snowtest.PChainID) diff --git a/vms/platformvm/vm_test.go b/vms/platformvm/vm_test.go index 23e88a646368..6c8733550d09 100644 --- a/vms/platformvm/vm_test.go +++ b/vms/platformvm/vm_test.go @@ -252,6 +252,7 @@ func defaultVM(t *testing.T, fork activeFork) (*VM, database.Database, *mutableS BanffTime: banffTime, CortinaTime: cortinaTime, DurangoTime: durangoTime, + EForkTime: mockable.MaxTime, }} db := memdb.New() @@ -1135,6 +1136,7 @@ func TestRestartFullyAccepted(t *testing.T) { BanffTime: latestForkTime, CortinaTime: latestForkTime, DurangoTime: latestForkTime, + EForkTime: mockable.MaxTime, }} firstCtx := snowtest.Context(t, snowtest.PChainID) @@ -1222,6 +1224,7 @@ func TestRestartFullyAccepted(t *testing.T) { BanffTime: latestForkTime, CortinaTime: latestForkTime, DurangoTime: latestForkTime, + EForkTime: mockable.MaxTime, }} secondCtx := snowtest.Context(t, snowtest.PChainID) @@ -1272,6 +1275,7 @@ func TestBootstrapPartiallyAccepted(t *testing.T) { BanffTime: latestForkTime, CortinaTime: latestForkTime, DurangoTime: latestForkTime, + EForkTime: mockable.MaxTime, }} initialClkTime := latestForkTime.Add(time.Second) @@ -1613,6 +1617,7 @@ func TestUnverifiedParent(t *testing.T) { BanffTime: latestForkTime, CortinaTime: latestForkTime, DurangoTime: latestForkTime, + EForkTime: mockable.MaxTime, }} initialClkTime := latestForkTime.Add(time.Second) @@ -1776,6 +1781,7 @@ func TestUptimeDisallowedWithRestart(t *testing.T) { BanffTime: latestForkTime, CortinaTime: latestForkTime, DurangoTime: latestForkTime, + EForkTime: mockable.MaxTime, }} firstCtx := snowtest.Context(t, snowtest.PChainID) @@ -1824,6 +1830,7 @@ func TestUptimeDisallowedWithRestart(t *testing.T) { BanffTime: latestForkTime, CortinaTime: latestForkTime, DurangoTime: latestForkTime, + EForkTime: mockable.MaxTime, }} secondCtx := snowtest.Context(t, snowtest.PChainID) @@ -1923,6 +1930,7 @@ func TestUptimeDisallowedAfterNeverConnecting(t *testing.T) { BanffTime: latestForkTime, CortinaTime: latestForkTime, DurangoTime: latestForkTime, + EForkTime: mockable.MaxTime, }} ctx := snowtest.Context(t, snowtest.PChainID) From e00d7c9953990f7758e3fb8aa201252e641252d4 Mon Sep 17 00:00:00 2001 From: Alberto Benegiamo Date: Mon, 29 Jan 2024 13:36:20 +0100 Subject: [PATCH 02/18] drop temporary fork time --- version/constants.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/version/constants.go b/version/constants.go index a535f2a07597..f90e1188ab35 100644 --- a/version/constants.go +++ b/version/constants.go @@ -135,7 +135,6 @@ var ( constants.MainnetID: time.Date(10000, time.December, 1, 0, 0, 0, 0, time.UTC), constants.FujiID: time.Date(10000, time.December, 1, 0, 0, 0, 0, time.UTC), } - TempForkTime = time.Date(10000, time.December, 1, 0, 0, 0, 0, time.UTC) ) func init() { @@ -263,7 +262,7 @@ func GetEForkTime(networkID uint32) time.Time { if upgradeTime, exists := EForkTimes[networkID]; exists { return upgradeTime } - return TempForkTime + return DefaultUpgradeTime } func GetCompatibility(networkID uint32) Compatibility { From f832034e7aadba290a87c2a88d6f40fa027919cb Mon Sep 17 00:00:00 2001 From: Alberto Benegiamo Date: Thu, 1 Feb 2024 22:38:42 +0100 Subject: [PATCH 03/18] nits --- node/node.go | 6 +- version/constants.go | 6 +- vms/avm/block/executor/block_test.go | 96 +++++++++---------- vms/avm/block/executor/manager_test.go | 20 ++-- vms/avm/config/config.go | 6 +- vms/avm/environment_test.go | 2 +- vms/avm/index_test.go | 12 +-- vms/avm/service_test.go | 28 +++--- .../txs/executor/syntactic_verifier_test.go | 2 +- vms/avm/vm_regression_test.go | 4 +- vms/avm/vm_test.go | 16 ++-- vms/platformvm/block/builder/helpers_test.go | 2 +- vms/platformvm/block/executor/helpers_test.go | 2 +- vms/platformvm/config/config.go | 4 +- vms/platformvm/txs/executor/helpers_test.go | 2 +- .../executor/staker_tx_verification_test.go | 52 +++++----- .../txs/executor/standard_tx_executor_test.go | 86 ++++++++--------- vms/platformvm/validator_set_property_test.go | 2 +- vms/platformvm/vm_regression_test.go | 2 +- vms/platformvm/vm_test.go | 16 ++-- 20 files changed, 183 insertions(+), 183 deletions(-) diff --git a/node/node.go b/node/node.go index a9cfc4e951e2..88c14ba3a083 100644 --- a/node/node.go +++ b/node/node.go @@ -1182,7 +1182,7 @@ func (n *Node) initVMs() error { } durangoTime := version.GetDurangoTime(n.Config.NetworkID) - eForkTime := version.GetEForkTime(n.Config.NetworkID) + eUpgradeTime := version.GetEUpgradeTime(n.Config.NetworkID) if err := txs.InitCodec(durangoTime); err != nil { return err } @@ -1225,7 +1225,7 @@ func (n *Node) initVMs() error { BanffTime: version.GetBanffTime(n.Config.NetworkID), CortinaTime: version.GetCortinaTime(n.Config.NetworkID), DurangoTime: durangoTime, - EForkTime: eForkTime, + EUpgradeTime: eUpgradeTime, UseCurrentHeight: n.Config.UseCurrentHeight, }, }), @@ -1234,7 +1234,7 @@ func (n *Node) initVMs() error { TxFee: n.Config.TxFee, CreateAssetTxFee: n.Config.CreateAssetTxFee, DurangoTime: durangoTime, - EForkTime: eForkTime, + EUpgradeTime: eUpgradeTime, }, }), n.VMManager.RegisterFactory(context.TODO(), constants.EVMID, &coreth.Factory{}), diff --git a/version/constants.go b/version/constants.go index 494448d08301..153c87a33811 100644 --- a/version/constants.go +++ b/version/constants.go @@ -142,7 +142,7 @@ var ( constants.FujiID: time.Date(10000, time.December, 1, 0, 0, 0, 0, time.UTC), } - EForkTimes = map[uint32]time.Time{ + EUpgradeTimes = map[uint32]time.Time{ constants.MainnetID: time.Date(10000, time.December, 1, 0, 0, 0, 0, time.UTC), constants.FujiID: time.Date(10000, time.December, 1, 0, 0, 0, 0, time.UTC), } @@ -246,8 +246,8 @@ func GetDurangoTime(networkID uint32) time.Time { return DefaultUpgradeTime } -func GetEForkTime(networkID uint32) time.Time { - if upgradeTime, exists := EForkTimes[networkID]; exists { +func GetEUpgradeTime(networkID uint32) time.Time { + if upgradeTime, exists := EUpgradeTimes[networkID]; exists { return upgradeTime } return DefaultUpgradeTime diff --git a/vms/avm/block/executor/block_test.go b/vms/avm/block/executor/block_test.go index c44a69389568..00d7c89264f0 100644 --- a/vms/avm/block/executor/block_test.go +++ b/vms/avm/block/executor/block_test.go @@ -49,8 +49,8 @@ func TestBlockVerify(t *testing.T) { manager: &manager{ backend: &executor.Backend{ Config: &config.Config{ - DurangoTime: time.Time{}, - EForkTime: mockable.MaxTime, + DurangoTime: time.Time{}, + EUpgradeTime: mockable.MaxTime, }, }, blkIDToState: map[ids.ID]*blockState{}, @@ -74,8 +74,8 @@ func TestBlockVerify(t *testing.T) { manager: &manager{ backend: &executor.Backend{ Config: &config.Config{ - DurangoTime: time.Time{}, - EForkTime: mockable.MaxTime, + DurangoTime: time.Time{}, + EUpgradeTime: mockable.MaxTime, }, }, }, @@ -99,8 +99,8 @@ func TestBlockVerify(t *testing.T) { manager: &manager{ backend: &executor.Backend{ Config: &config.Config{ - DurangoTime: time.Time{}, - EForkTime: mockable.MaxTime, + DurangoTime: time.Time{}, + EUpgradeTime: mockable.MaxTime, }, }, clk: clk, @@ -122,8 +122,8 @@ func TestBlockVerify(t *testing.T) { manager: &manager{ backend: &executor.Backend{ Config: &config.Config{ - DurangoTime: time.Time{}, - EForkTime: mockable.MaxTime, + DurangoTime: time.Time{}, + EUpgradeTime: mockable.MaxTime, }, }, blkIDToState: map[ids.ID]*blockState{}, @@ -154,8 +154,8 @@ func TestBlockVerify(t *testing.T) { manager: &manager{ backend: &executor.Backend{ Config: &config.Config{ - DurangoTime: time.Time{}, - EForkTime: mockable.MaxTime, + DurangoTime: time.Time{}, + EUpgradeTime: mockable.MaxTime, }, }, mempool: mempool, @@ -192,8 +192,8 @@ func TestBlockVerify(t *testing.T) { manager: &manager{ backend: &executor.Backend{ Config: &config.Config{ - DurangoTime: time.Time{}, - EForkTime: mockable.MaxTime, + DurangoTime: time.Time{}, + EUpgradeTime: mockable.MaxTime, }, }, state: mockState, @@ -234,8 +234,8 @@ func TestBlockVerify(t *testing.T) { manager: &manager{ backend: &executor.Backend{ Config: &config.Config{ - DurangoTime: time.Time{}, - EForkTime: mockable.MaxTime, + DurangoTime: time.Time{}, + EUpgradeTime: mockable.MaxTime, }, }, state: mockState, @@ -279,8 +279,8 @@ func TestBlockVerify(t *testing.T) { manager: &manager{ backend: &executor.Backend{ Config: &config.Config{ - DurangoTime: time.Time{}, - EForkTime: mockable.MaxTime, + DurangoTime: time.Time{}, + EUpgradeTime: mockable.MaxTime, }, }, blkIDToState: map[ids.ID]*blockState{ @@ -332,8 +332,8 @@ func TestBlockVerify(t *testing.T) { manager: &manager{ backend: &executor.Backend{ Config: &config.Config{ - DurangoTime: time.Time{}, - EForkTime: mockable.MaxTime, + DurangoTime: time.Time{}, + EUpgradeTime: mockable.MaxTime, }, }, mempool: mempool, @@ -390,8 +390,8 @@ func TestBlockVerify(t *testing.T) { metrics: metrics.NewMockMetrics(ctrl), backend: &executor.Backend{ Config: &config.Config{ - DurangoTime: time.Time{}, - EForkTime: mockable.MaxTime, + DurangoTime: time.Time{}, + EUpgradeTime: mockable.MaxTime, }, }, blkIDToState: map[ids.ID]*blockState{ @@ -473,8 +473,8 @@ func TestBlockVerify(t *testing.T) { metrics: metrics.NewMockMetrics(ctrl), backend: &executor.Backend{ Config: &config.Config{ - DurangoTime: time.Time{}, - EForkTime: mockable.MaxTime, + DurangoTime: time.Time{}, + EUpgradeTime: mockable.MaxTime, }, }, blkIDToState: map[ids.ID]*blockState{ @@ -536,8 +536,8 @@ func TestBlockVerify(t *testing.T) { manager: &manager{ backend: &executor.Backend{ Config: &config.Config{ - DurangoTime: time.Time{}, - EForkTime: mockable.MaxTime, + DurangoTime: time.Time{}, + EUpgradeTime: mockable.MaxTime, }, }, blkIDToState: map[ids.ID]*blockState{ @@ -593,8 +593,8 @@ func TestBlockVerify(t *testing.T) { metrics: metrics.NewMockMetrics(ctrl), backend: &executor.Backend{ Config: &config.Config{ - DurangoTime: time.Time{}, - EForkTime: mockable.MaxTime, + DurangoTime: time.Time{}, + EUpgradeTime: mockable.MaxTime, }, }, blkIDToState: map[ids.ID]*blockState{ @@ -675,8 +675,8 @@ func TestBlockAccept(t *testing.T) { Log: logging.NoLog{}, }, Config: &config.Config{ - DurangoTime: time.Time{}, - EForkTime: mockable.MaxTime, + DurangoTime: time.Time{}, + EUpgradeTime: mockable.MaxTime, }, }, blkIDToState: map[ids.ID]*blockState{}, @@ -713,8 +713,8 @@ func TestBlockAccept(t *testing.T) { Log: logging.NoLog{}, }, Config: &config.Config{ - DurangoTime: time.Time{}, - EForkTime: mockable.MaxTime, + DurangoTime: time.Time{}, + EUpgradeTime: mockable.MaxTime, }, }, blkIDToState: map[ids.ID]*blockState{ @@ -761,8 +761,8 @@ func TestBlockAccept(t *testing.T) { Log: logging.NoLog{}, }, Config: &config.Config{ - DurangoTime: time.Time{}, - EForkTime: mockable.MaxTime, + DurangoTime: time.Time{}, + EUpgradeTime: mockable.MaxTime, }, }, blkIDToState: map[ids.ID]*blockState{ @@ -813,8 +813,8 @@ func TestBlockAccept(t *testing.T) { Log: logging.NoLog{}, }, Config: &config.Config{ - DurangoTime: time.Time{}, - EForkTime: mockable.MaxTime, + DurangoTime: time.Time{}, + EUpgradeTime: mockable.MaxTime, }, }, blkIDToState: map[ids.ID]*blockState{ @@ -868,8 +868,8 @@ func TestBlockAccept(t *testing.T) { Log: logging.NoLog{}, }, Config: &config.Config{ - DurangoTime: time.Time{}, - EForkTime: mockable.MaxTime, + DurangoTime: time.Time{}, + EUpgradeTime: mockable.MaxTime, }, }, blkIDToState: map[ids.ID]*blockState{ @@ -969,8 +969,8 @@ func TestBlockReject(t *testing.T) { backend: &executor.Backend{ Bootstrapped: true, Config: &config.Config{ - DurangoTime: time.Time{}, - EForkTime: mockable.MaxTime, + DurangoTime: time.Time{}, + EUpgradeTime: mockable.MaxTime, }, Ctx: &snow.Context{ Log: logging.NoLog{}, @@ -1034,8 +1034,8 @@ func TestBlockReject(t *testing.T) { Log: logging.NoLog{}, }, Config: &config.Config{ - DurangoTime: time.Time{}, - EForkTime: mockable.MaxTime, + DurangoTime: time.Time{}, + EUpgradeTime: mockable.MaxTime, }, }, state: mockState, @@ -1088,8 +1088,8 @@ func TestBlockStatus(t *testing.T) { manager: &manager{ backend: &executor.Backend{ Config: &config.Config{ - DurangoTime: time.Time{}, - EForkTime: mockable.MaxTime, + DurangoTime: time.Time{}, + EUpgradeTime: mockable.MaxTime, }, }, lastAccepted: blockID, @@ -1109,8 +1109,8 @@ func TestBlockStatus(t *testing.T) { manager: &manager{ backend: &executor.Backend{ Config: &config.Config{ - DurangoTime: time.Time{}, - EForkTime: mockable.MaxTime, + DurangoTime: time.Time{}, + EUpgradeTime: mockable.MaxTime, }, }, blkIDToState: map[ids.ID]*blockState{ @@ -1136,8 +1136,8 @@ func TestBlockStatus(t *testing.T) { manager: &manager{ backend: &executor.Backend{ Config: &config.Config{ - DurangoTime: time.Time{}, - EForkTime: mockable.MaxTime, + DurangoTime: time.Time{}, + EUpgradeTime: mockable.MaxTime, }, }, blkIDToState: map[ids.ID]*blockState{}, @@ -1162,8 +1162,8 @@ func TestBlockStatus(t *testing.T) { manager: &manager{ backend: &executor.Backend{ Config: &config.Config{ - DurangoTime: time.Time{}, - EForkTime: mockable.MaxTime, + DurangoTime: time.Time{}, + EUpgradeTime: mockable.MaxTime, }, }, blkIDToState: map[ids.ID]*blockState{}, diff --git a/vms/avm/block/executor/manager_test.go b/vms/avm/block/executor/manager_test.go index 89b547eed967..f0200f398a69 100644 --- a/vms/avm/block/executor/manager_test.go +++ b/vms/avm/block/executor/manager_test.go @@ -128,8 +128,8 @@ func TestManagerVerifyTx(t *testing.T) { return &manager{ backend: &executor.Backend{ Config: &config.Config{ - DurangoTime: time.Time{}, - EForkTime: mockable.MaxTime, + DurangoTime: time.Time{}, + EUpgradeTime: mockable.MaxTime, }, }, } @@ -150,8 +150,8 @@ func TestManagerVerifyTx(t *testing.T) { backend: &executor.Backend{ Bootstrapped: true, Config: &config.Config{ - DurangoTime: time.Time{}, - EForkTime: mockable.MaxTime, + DurangoTime: time.Time{}, + EUpgradeTime: mockable.MaxTime, }, }, } @@ -182,8 +182,8 @@ func TestManagerVerifyTx(t *testing.T) { backend: &executor.Backend{ Bootstrapped: true, Config: &config.Config{ - DurangoTime: time.Time{}, - EForkTime: mockable.MaxTime, + DurangoTime: time.Time{}, + EUpgradeTime: mockable.MaxTime, }, }, state: state, @@ -218,8 +218,8 @@ func TestManagerVerifyTx(t *testing.T) { backend: &executor.Backend{ Bootstrapped: true, Config: &config.Config{ - DurangoTime: time.Time{}, - EForkTime: mockable.MaxTime, + DurangoTime: time.Time{}, + EUpgradeTime: mockable.MaxTime, }, }, state: state, @@ -254,8 +254,8 @@ func TestManagerVerifyTx(t *testing.T) { backend: &executor.Backend{ Bootstrapped: true, Config: &config.Config{ - DurangoTime: time.Time{}, - EForkTime: mockable.MaxTime, + DurangoTime: time.Time{}, + EUpgradeTime: mockable.MaxTime, }, }, state: state, diff --git a/vms/avm/config/config.go b/vms/avm/config/config.go index b4da6e3781ea..42e37b678a01 100644 --- a/vms/avm/config/config.go +++ b/vms/avm/config/config.go @@ -17,9 +17,9 @@ type Config struct { DurangoTime time.Time // Time of the E network upgrade - EForkTime time.Time + EUpgradeTime time.Time } -func (c *Config) IsEForkActivated(timestamp time.Time) bool { - return !timestamp.Before(c.EForkTime) +func (c *Config) IsEUpgradeActivated(timestamp time.Time) bool { + return !timestamp.Before(c.EUpgradeTime) } diff --git a/vms/avm/environment_test.go b/vms/avm/environment_test.go index 00a1b2725e47..5675964d1b70 100644 --- a/vms/avm/environment_test.go +++ b/vms/avm/environment_test.go @@ -151,7 +151,7 @@ func setup(tb testing.TB, c *envConfig) *environment { TxFee: testTxFee, CreateAssetTxFee: testTxFee, DurangoTime: time.Time{}, - EForkTime: mockable.MaxTime, + EUpgradeTime: mockable.MaxTime, } if c.vmStaticConfig != nil { vmStaticConfig = *c.vmStaticConfig diff --git a/vms/avm/index_test.go b/vms/avm/index_test.go index 642410951c9e..f164481590e9 100644 --- a/vms/avm/index_test.go +++ b/vms/avm/index_test.go @@ -34,8 +34,8 @@ func TestIndexTransaction_Ordered(t *testing.T) { env := setup(t, &envConfig{ vmStaticConfig: &config.Config{ - DurangoTime: time.Time{}, - EForkTime: mockable.MaxTime, + DurangoTime: time.Time{}, + EUpgradeTime: mockable.MaxTime, }, }) defer func() { @@ -81,8 +81,8 @@ func TestIndexTransaction_MultipleTransactions(t *testing.T) { env := setup(t, &envConfig{ vmStaticConfig: &config.Config{ - DurangoTime: time.Time{}, - EForkTime: mockable.MaxTime, + DurangoTime: time.Time{}, + EUpgradeTime: mockable.MaxTime, }, }) defer func() { @@ -132,8 +132,8 @@ func TestIndexTransaction_MultipleAddresses(t *testing.T) { env := setup(t, &envConfig{ vmStaticConfig: &config.Config{ - DurangoTime: time.Time{}, - EForkTime: mockable.MaxTime, + DurangoTime: time.Time{}, + EUpgradeTime: mockable.MaxTime, }, }) defer func() { diff --git a/vms/avm/service_test.go b/vms/avm/service_test.go index 62f81d08f48c..8a080c6137b6 100644 --- a/vms/avm/service_test.go +++ b/vms/avm/service_test.go @@ -705,8 +705,8 @@ func TestServiceGetTxJSON_CreateAssetTx(t *testing.T) { env := setup(t, &envConfig{ vmStaticConfig: &config.Config{ - DurangoTime: time.Time{}, - EForkTime: mockable.MaxTime, + DurangoTime: time.Time{}, + EUpgradeTime: mockable.MaxTime, }, additionalFxs: []*common.Fx{{ ID: propertyfx.ID, @@ -824,8 +824,8 @@ func TestServiceGetTxJSON_OperationTxWithNftxMintOp(t *testing.T) { env := setup(t, &envConfig{ vmStaticConfig: &config.Config{ - DurangoTime: time.Time{}, - EForkTime: mockable.MaxTime, + DurangoTime: time.Time{}, + EUpgradeTime: mockable.MaxTime, }, additionalFxs: []*common.Fx{{ ID: propertyfx.ID, @@ -926,8 +926,8 @@ func TestServiceGetTxJSON_OperationTxWithMultipleNftxMintOp(t *testing.T) { env := setup(t, &envConfig{ vmStaticConfig: &config.Config{ - DurangoTime: time.Time{}, - EForkTime: mockable.MaxTime, + DurangoTime: time.Time{}, + EUpgradeTime: mockable.MaxTime, }, additionalFxs: []*common.Fx{{ ID: propertyfx.ID, @@ -1067,8 +1067,8 @@ func TestServiceGetTxJSON_OperationTxWithSecpMintOp(t *testing.T) { env := setup(t, &envConfig{ vmStaticConfig: &config.Config{ - DurangoTime: time.Time{}, - EForkTime: mockable.MaxTime, + DurangoTime: time.Time{}, + EUpgradeTime: mockable.MaxTime, }, additionalFxs: []*common.Fx{{ ID: propertyfx.ID, @@ -1173,8 +1173,8 @@ func TestServiceGetTxJSON_OperationTxWithMultipleSecpMintOp(t *testing.T) { env := setup(t, &envConfig{ vmStaticConfig: &config.Config{ - DurangoTime: time.Time{}, - EForkTime: mockable.MaxTime, + DurangoTime: time.Time{}, + EUpgradeTime: mockable.MaxTime, }, additionalFxs: []*common.Fx{{ ID: propertyfx.ID, @@ -1322,8 +1322,8 @@ func TestServiceGetTxJSON_OperationTxWithPropertyFxMintOp(t *testing.T) { env := setup(t, &envConfig{ vmStaticConfig: &config.Config{ - DurangoTime: time.Time{}, - EForkTime: mockable.MaxTime, + DurangoTime: time.Time{}, + EUpgradeTime: mockable.MaxTime, }, additionalFxs: []*common.Fx{{ ID: propertyfx.ID, @@ -1425,8 +1425,8 @@ func TestServiceGetTxJSON_OperationTxWithPropertyFxMintOpMultiple(t *testing.T) env := setup(t, &envConfig{ vmStaticConfig: &config.Config{ - DurangoTime: time.Time{}, - EForkTime: mockable.MaxTime, + DurangoTime: time.Time{}, + EUpgradeTime: mockable.MaxTime, }, additionalFxs: []*common.Fx{{ ID: propertyfx.ID, diff --git a/vms/avm/txs/executor/syntactic_verifier_test.go b/vms/avm/txs/executor/syntactic_verifier_test.go index 3b5c05d42d07..cc160ed79823 100644 --- a/vms/avm/txs/executor/syntactic_verifier_test.go +++ b/vms/avm/txs/executor/syntactic_verifier_test.go @@ -32,7 +32,7 @@ var ( TxFee: 2, CreateAssetTxFee: 3, DurangoTime: time.Time{}, - EForkTime: mockable.MaxTime, + EUpgradeTime: mockable.MaxTime, } ) diff --git a/vms/avm/vm_regression_test.go b/vms/avm/vm_regression_test.go index 1e4720f80fe1..2412c4e9a70c 100644 --- a/vms/avm/vm_regression_test.go +++ b/vms/avm/vm_regression_test.go @@ -27,8 +27,8 @@ func TestVerifyFxUsage(t *testing.T) { env := setup(t, &envConfig{ vmStaticConfig: &config.Config{ - DurangoTime: time.Time{}, - EForkTime: mockable.MaxTime, + DurangoTime: time.Time{}, + EUpgradeTime: mockable.MaxTime, }, }) env.vm.ctx.Lock.Unlock() diff --git a/vms/avm/vm_test.go b/vms/avm/vm_test.go index f7c7d11af0ea..a01aefd349d0 100644 --- a/vms/avm/vm_test.go +++ b/vms/avm/vm_test.go @@ -135,8 +135,8 @@ func TestIssueNFT(t *testing.T) { env := setup(t, &envConfig{ vmStaticConfig: &config.Config{ - DurangoTime: time.Time{}, - EForkTime: mockable.MaxTime, + DurangoTime: time.Time{}, + EUpgradeTime: mockable.MaxTime, }, }) env.vm.ctx.Lock.Unlock() @@ -239,8 +239,8 @@ func TestIssueProperty(t *testing.T) { env := setup(t, &envConfig{ vmStaticConfig: &config.Config{ - DurangoTime: time.Time{}, - EForkTime: mockable.MaxTime, + DurangoTime: time.Time{}, + EUpgradeTime: mockable.MaxTime, }, additionalFxs: []*common.Fx{{ ID: propertyfx.ID, @@ -529,8 +529,8 @@ func TestIssueImportTx(t *testing.T) { env := setup(t, &envConfig{ vmStaticConfig: &config.Config{ - DurangoTime: time.Time{}, - EForkTime: mockable.MaxTime, + DurangoTime: time.Time{}, + EUpgradeTime: mockable.MaxTime, }, }) defer func() { @@ -632,8 +632,8 @@ func TestForceAcceptImportTx(t *testing.T) { env := setup(t, &envConfig{ vmStaticConfig: &config.Config{ - DurangoTime: time.Time{}, - EForkTime: mockable.MaxTime, + DurangoTime: time.Time{}, + EUpgradeTime: mockable.MaxTime, }, notLinearized: true, }) diff --git a/vms/platformvm/block/builder/helpers_test.go b/vms/platformvm/block/builder/helpers_test.go index 15ca13e2e109..92892df75ae2 100644 --- a/vms/platformvm/block/builder/helpers_test.go +++ b/vms/platformvm/block/builder/helpers_test.go @@ -316,7 +316,7 @@ func defaultConfig() *config.Config { ApricotPhase5Time: defaultValidateEndTime, BanffTime: time.Time{}, // neglecting fork ordering this for package tests DurangoTime: time.Time{}, - EForkTime: mockable.MaxTime, + EUpgradeTime: mockable.MaxTime, } } diff --git a/vms/platformvm/block/executor/helpers_test.go b/vms/platformvm/block/executor/helpers_test.go index f134ecd73dd8..9b98681c44cd 100644 --- a/vms/platformvm/block/executor/helpers_test.go +++ b/vms/platformvm/block/executor/helpers_test.go @@ -344,7 +344,7 @@ func defaultConfig() *config.Config { ApricotPhase5Time: defaultValidateEndTime, BanffTime: mockable.MaxTime, DurangoTime: mockable.MaxTime, - EForkTime: mockable.MaxTime, + EUpgradeTime: mockable.MaxTime, } } diff --git a/vms/platformvm/config/config.go b/vms/platformvm/config/config.go index 292981ddc021..0ac37f81f08e 100644 --- a/vms/platformvm/config/config.go +++ b/vms/platformvm/config/config.go @@ -108,7 +108,7 @@ type Config struct { DurangoTime time.Time // Time of the E network upgrade - EForkTime time.Time + EUpgradeTime time.Time // UseCurrentHeight forces [GetMinimumHeight] to return the current height // of the P-Chain instead of the oldest block in the [recentlyAccepted] @@ -141,7 +141,7 @@ func (c *Config) IsDurangoActivated(timestamp time.Time) bool { } func (c *Config) IsEForkActivated(timestamp time.Time) bool { - return !timestamp.Before(c.EForkTime) + return !timestamp.Before(c.EUpgradeTime) } func (c *Config) GetCreateBlockchainTxFee(timestamp time.Time) uint64 { diff --git a/vms/platformvm/txs/executor/helpers_test.go b/vms/platformvm/txs/executor/helpers_test.go index ce59a27e1467..3d6683529cca 100644 --- a/vms/platformvm/txs/executor/helpers_test.go +++ b/vms/platformvm/txs/executor/helpers_test.go @@ -308,7 +308,7 @@ func defaultConfig(postBanff, postCortina, postDurango bool) *config.Config { BanffTime: banffTime, CortinaTime: cortinaTime, DurangoTime: durangoTime, - EForkTime: mockable.MaxTime, + EUpgradeTime: mockable.MaxTime, } } diff --git a/vms/platformvm/txs/executor/staker_tx_verification_test.go b/vms/platformvm/txs/executor/staker_tx_verification_test.go index c874e884561d..aa602725083f 100644 --- a/vms/platformvm/txs/executor/staker_tx_verification_test.go +++ b/vms/platformvm/txs/executor/staker_tx_verification_test.go @@ -112,8 +112,8 @@ func TestVerifyAddPermissionlessValidatorTx(t *testing.T) { return &Backend{ Ctx: ctx, Config: &config.Config{ - DurangoTime: activeForkTime, // activate latest fork - EForkTime: mockable.MaxTime, + DurangoTime: activeForkTime, // activate latest fork + EUpgradeTime: mockable.MaxTime, }, } }, @@ -134,8 +134,8 @@ func TestVerifyAddPermissionlessValidatorTx(t *testing.T) { return &Backend{ Ctx: ctx, Config: &config.Config{ - DurangoTime: activeForkTime, // activate latest fork - EForkTime: mockable.MaxTime, + DurangoTime: activeForkTime, // activate latest fork + EUpgradeTime: mockable.MaxTime, }, Bootstrapped: &utils.Atomic[bool]{}, } @@ -161,9 +161,9 @@ func TestVerifyAddPermissionlessValidatorTx(t *testing.T) { return &Backend{ Ctx: ctx, Config: &config.Config{ - CortinaTime: activeForkTime, - DurangoTime: mockable.MaxTime, - EForkTime: mockable.MaxTime, + CortinaTime: activeForkTime, + DurangoTime: mockable.MaxTime, + EUpgradeTime: mockable.MaxTime, }, Bootstrapped: bootstrapped, } @@ -189,8 +189,8 @@ func TestVerifyAddPermissionlessValidatorTx(t *testing.T) { return &Backend{ Ctx: ctx, Config: &config.Config{ - DurangoTime: activeForkTime, // activate latest fork - EForkTime: mockable.MaxTime, + DurangoTime: activeForkTime, // activate latest fork + EUpgradeTime: mockable.MaxTime, }, Bootstrapped: bootstrapped, } @@ -219,8 +219,8 @@ func TestVerifyAddPermissionlessValidatorTx(t *testing.T) { return &Backend{ Ctx: ctx, Config: &config.Config{ - DurangoTime: activeForkTime, // activate latest fork - EForkTime: mockable.MaxTime, + DurangoTime: activeForkTime, // activate latest fork + EUpgradeTime: mockable.MaxTime, }, Bootstrapped: bootstrapped, } @@ -249,8 +249,8 @@ func TestVerifyAddPermissionlessValidatorTx(t *testing.T) { return &Backend{ Ctx: ctx, Config: &config.Config{ - DurangoTime: activeForkTime, // activate latest fork - EForkTime: mockable.MaxTime, + DurangoTime: activeForkTime, // activate latest fork + EUpgradeTime: mockable.MaxTime, }, Bootstrapped: bootstrapped, } @@ -280,8 +280,8 @@ func TestVerifyAddPermissionlessValidatorTx(t *testing.T) { return &Backend{ Ctx: ctx, Config: &config.Config{ - DurangoTime: activeForkTime, // activate latest fork - EForkTime: mockable.MaxTime, + DurangoTime: activeForkTime, // activate latest fork + EUpgradeTime: mockable.MaxTime, }, Bootstrapped: bootstrapped, } @@ -314,8 +314,8 @@ func TestVerifyAddPermissionlessValidatorTx(t *testing.T) { return &Backend{ Ctx: ctx, Config: &config.Config{ - DurangoTime: activeForkTime, // activate latest fork - EForkTime: mockable.MaxTime, + DurangoTime: activeForkTime, // activate latest fork + EUpgradeTime: mockable.MaxTime, }, Bootstrapped: bootstrapped, } @@ -348,8 +348,8 @@ func TestVerifyAddPermissionlessValidatorTx(t *testing.T) { return &Backend{ Ctx: ctx, Config: &config.Config{ - DurangoTime: activeForkTime, // activate latest fork - EForkTime: mockable.MaxTime, + DurangoTime: activeForkTime, // activate latest fork + EUpgradeTime: mockable.MaxTime, }, Bootstrapped: bootstrapped, } @@ -384,8 +384,8 @@ func TestVerifyAddPermissionlessValidatorTx(t *testing.T) { return &Backend{ Ctx: ctx, Config: &config.Config{ - DurangoTime: activeForkTime, // activate latest fork - EForkTime: mockable.MaxTime, + DurangoTime: activeForkTime, // activate latest fork + EUpgradeTime: mockable.MaxTime, }, Bootstrapped: bootstrapped, } @@ -414,8 +414,8 @@ func TestVerifyAddPermissionlessValidatorTx(t *testing.T) { return &Backend{ Ctx: ctx, Config: &config.Config{ - DurangoTime: activeForkTime, // activate latest fork - EForkTime: mockable.MaxTime, + DurangoTime: activeForkTime, // activate latest fork + EUpgradeTime: mockable.MaxTime, }, Bootstrapped: bootstrapped, } @@ -462,7 +462,7 @@ func TestVerifyAddPermissionlessValidatorTx(t *testing.T) { Config: &config.Config{ AddSubnetValidatorFee: 1, DurangoTime: activeForkTime, // activate latest fork, - EForkTime: mockable.MaxTime, + EUpgradeTime: mockable.MaxTime, }, Ctx: ctx, Bootstrapped: bootstrapped, @@ -509,7 +509,7 @@ func TestVerifyAddPermissionlessValidatorTx(t *testing.T) { Config: &config.Config{ CortinaTime: activeForkTime, DurangoTime: mockable.MaxTime, - EForkTime: mockable.MaxTime, + EUpgradeTime: mockable.MaxTime, AddSubnetValidatorFee: 1, }, Ctx: ctx, @@ -562,7 +562,7 @@ func TestVerifyAddPermissionlessValidatorTx(t *testing.T) { Config: &config.Config{ AddSubnetValidatorFee: 1, DurangoTime: activeForkTime, // activate latest fork, - EForkTime: mockable.MaxTime, + EUpgradeTime: mockable.MaxTime, }, Ctx: ctx, Bootstrapped: bootstrapped, diff --git a/vms/platformvm/txs/executor/standard_tx_executor_test.go b/vms/platformvm/txs/executor/standard_tx_executor_test.go index aac52b571935..6fd7fd0bc1f9 100644 --- a/vms/platformvm/txs/executor/standard_tx_executor_test.go +++ b/vms/platformvm/txs/executor/standard_tx_executor_test.go @@ -1749,10 +1749,10 @@ func TestStandardExecutorRemoveSubnetValidatorTx(t *testing.T) { e := &StandardTxExecutor{ Backend: &Backend{ Config: &config.Config{ - BanffTime: env.latestForkTime, - CortinaTime: env.latestForkTime, - DurangoTime: env.latestForkTime, - EForkTime: mockable.MaxTime, + BanffTime: env.latestForkTime, + CortinaTime: env.latestForkTime, + DurangoTime: env.latestForkTime, + EUpgradeTime: mockable.MaxTime, }, Bootstrapped: &utils.Atomic[bool]{}, Fx: env.fx, @@ -1777,10 +1777,10 @@ func TestStandardExecutorRemoveSubnetValidatorTx(t *testing.T) { e := &StandardTxExecutor{ Backend: &Backend{ Config: &config.Config{ - BanffTime: env.latestForkTime, - CortinaTime: env.latestForkTime, - DurangoTime: env.latestForkTime, - EForkTime: mockable.MaxTime, + BanffTime: env.latestForkTime, + CortinaTime: env.latestForkTime, + DurangoTime: env.latestForkTime, + EUpgradeTime: mockable.MaxTime, }, Bootstrapped: &utils.Atomic[bool]{}, Fx: env.fx, @@ -1806,10 +1806,10 @@ func TestStandardExecutorRemoveSubnetValidatorTx(t *testing.T) { e := &StandardTxExecutor{ Backend: &Backend{ Config: &config.Config{ - BanffTime: env.latestForkTime, - CortinaTime: env.latestForkTime, - DurangoTime: env.latestForkTime, - EForkTime: mockable.MaxTime, + BanffTime: env.latestForkTime, + CortinaTime: env.latestForkTime, + DurangoTime: env.latestForkTime, + EUpgradeTime: mockable.MaxTime, }, Bootstrapped: &utils.Atomic[bool]{}, Fx: env.fx, @@ -1838,10 +1838,10 @@ func TestStandardExecutorRemoveSubnetValidatorTx(t *testing.T) { e := &StandardTxExecutor{ Backend: &Backend{ Config: &config.Config{ - BanffTime: env.latestForkTime, - CortinaTime: env.latestForkTime, - DurangoTime: env.latestForkTime, - EForkTime: mockable.MaxTime, + BanffTime: env.latestForkTime, + CortinaTime: env.latestForkTime, + DurangoTime: env.latestForkTime, + EUpgradeTime: mockable.MaxTime, }, Bootstrapped: &utils.Atomic[bool]{}, Fx: env.fx, @@ -1868,10 +1868,10 @@ func TestStandardExecutorRemoveSubnetValidatorTx(t *testing.T) { e := &StandardTxExecutor{ Backend: &Backend{ Config: &config.Config{ - BanffTime: env.latestForkTime, - CortinaTime: env.latestForkTime, - DurangoTime: env.latestForkTime, - EForkTime: mockable.MaxTime, + BanffTime: env.latestForkTime, + CortinaTime: env.latestForkTime, + DurangoTime: env.latestForkTime, + EUpgradeTime: mockable.MaxTime, }, Bootstrapped: &utils.Atomic[bool]{}, Fx: env.fx, @@ -1897,10 +1897,10 @@ func TestStandardExecutorRemoveSubnetValidatorTx(t *testing.T) { e := &StandardTxExecutor{ Backend: &Backend{ Config: &config.Config{ - BanffTime: env.latestForkTime, - CortinaTime: env.latestForkTime, - DurangoTime: env.latestForkTime, - EForkTime: mockable.MaxTime, + BanffTime: env.latestForkTime, + CortinaTime: env.latestForkTime, + DurangoTime: env.latestForkTime, + EUpgradeTime: mockable.MaxTime, }, Bootstrapped: &utils.Atomic[bool]{}, Fx: env.fx, @@ -1928,10 +1928,10 @@ func TestStandardExecutorRemoveSubnetValidatorTx(t *testing.T) { e := &StandardTxExecutor{ Backend: &Backend{ Config: &config.Config{ - BanffTime: env.latestForkTime, - CortinaTime: env.latestForkTime, - DurangoTime: env.latestForkTime, - EForkTime: mockable.MaxTime, + BanffTime: env.latestForkTime, + CortinaTime: env.latestForkTime, + DurangoTime: env.latestForkTime, + EUpgradeTime: mockable.MaxTime, }, Bootstrapped: &utils.Atomic[bool]{}, Fx: env.fx, @@ -1962,10 +1962,10 @@ func TestStandardExecutorRemoveSubnetValidatorTx(t *testing.T) { e := &StandardTxExecutor{ Backend: &Backend{ Config: &config.Config{ - BanffTime: env.latestForkTime, - CortinaTime: env.latestForkTime, - DurangoTime: env.latestForkTime, - EForkTime: mockable.MaxTime, + BanffTime: env.latestForkTime, + CortinaTime: env.latestForkTime, + DurangoTime: env.latestForkTime, + EUpgradeTime: mockable.MaxTime, }, Bootstrapped: &utils.Atomic[bool]{}, Fx: env.fx, @@ -2120,10 +2120,10 @@ func TestStandardExecutorTransformSubnetTx(t *testing.T) { e := &StandardTxExecutor{ Backend: &Backend{ Config: &config.Config{ - BanffTime: env.latestForkTime, - CortinaTime: env.latestForkTime, - DurangoTime: env.latestForkTime, - EForkTime: mockable.MaxTime, + BanffTime: env.latestForkTime, + CortinaTime: env.latestForkTime, + DurangoTime: env.latestForkTime, + EUpgradeTime: mockable.MaxTime, }, Bootstrapped: &utils.Atomic[bool]{}, Fx: env.fx, @@ -2148,10 +2148,10 @@ func TestStandardExecutorTransformSubnetTx(t *testing.T) { e := &StandardTxExecutor{ Backend: &Backend{ Config: &config.Config{ - BanffTime: env.latestForkTime, - CortinaTime: env.latestForkTime, - DurangoTime: env.latestForkTime, - EForkTime: mockable.MaxTime, + BanffTime: env.latestForkTime, + CortinaTime: env.latestForkTime, + DurangoTime: env.latestForkTime, + EUpgradeTime: mockable.MaxTime, }, Bootstrapped: &utils.Atomic[bool]{}, Fx: env.fx, @@ -2181,7 +2181,7 @@ func TestStandardExecutorTransformSubnetTx(t *testing.T) { CortinaTime: env.latestForkTime, DurangoTime: env.latestForkTime, MaxStakeDuration: math.MaxInt64, - EForkTime: mockable.MaxTime, + EUpgradeTime: mockable.MaxTime, }, Bootstrapped: &utils.Atomic[bool]{}, Fx: env.fx, @@ -2215,7 +2215,7 @@ func TestStandardExecutorTransformSubnetTx(t *testing.T) { BanffTime: env.latestForkTime, CortinaTime: env.latestForkTime, DurangoTime: env.latestForkTime, - EForkTime: mockable.MaxTime, + EUpgradeTime: mockable.MaxTime, MaxStakeDuration: math.MaxInt64, }, Bootstrapped: &utils.Atomic[bool]{}, @@ -2255,7 +2255,7 @@ func TestStandardExecutorTransformSubnetTx(t *testing.T) { BanffTime: env.latestForkTime, CortinaTime: env.latestForkTime, DurangoTime: env.latestForkTime, - EForkTime: mockable.MaxTime, + EUpgradeTime: mockable.MaxTime, MaxStakeDuration: math.MaxInt64, }, Bootstrapped: &utils.Atomic[bool]{}, diff --git a/vms/platformvm/validator_set_property_test.go b/vms/platformvm/validator_set_property_test.go index 7a879123af20..9a0fd7f88528 100644 --- a/vms/platformvm/validator_set_property_test.go +++ b/vms/platformvm/validator_set_property_test.go @@ -625,7 +625,7 @@ func buildVM(t *testing.T) (*VM, ids.ID, error) { ApricotPhase5Time: forkTime, BanffTime: forkTime, CortinaTime: forkTime, - EForkTime: mockable.MaxTime, + EUpgradeTime: mockable.MaxTime, }} vm.clock.Set(forkTime.Add(time.Second)) diff --git a/vms/platformvm/vm_regression_test.go b/vms/platformvm/vm_regression_test.go index 761a4ad0812d..4335ae460034 100644 --- a/vms/platformvm/vm_regression_test.go +++ b/vms/platformvm/vm_regression_test.go @@ -374,7 +374,7 @@ func TestUnverifiedParentPanicRegression(t *testing.T) { BanffTime: latestForkTime, CortinaTime: mockable.MaxTime, DurangoTime: mockable.MaxTime, - EForkTime: mockable.MaxTime, + EUpgradeTime: mockable.MaxTime, }} ctx := snowtest.Context(t, snowtest.PChainID) diff --git a/vms/platformvm/vm_test.go b/vms/platformvm/vm_test.go index 5af9deb95db4..94e158582cce 100644 --- a/vms/platformvm/vm_test.go +++ b/vms/platformvm/vm_test.go @@ -254,7 +254,7 @@ func defaultVM(t *testing.T, fork activeFork) (*VM, database.Database, *mutableS BanffTime: banffTime, CortinaTime: cortinaTime, DurangoTime: durangoTime, - EForkTime: mockable.MaxTime, + EUpgradeTime: mockable.MaxTime, }} db := memdb.New() @@ -1113,7 +1113,7 @@ func TestRestartFullyAccepted(t *testing.T) { BanffTime: latestForkTime, CortinaTime: latestForkTime, DurangoTime: latestForkTime, - EForkTime: mockable.MaxTime, + EUpgradeTime: mockable.MaxTime, }} firstCtx := snowtest.Context(t, snowtest.PChainID) @@ -1201,7 +1201,7 @@ func TestRestartFullyAccepted(t *testing.T) { BanffTime: latestForkTime, CortinaTime: latestForkTime, DurangoTime: latestForkTime, - EForkTime: mockable.MaxTime, + EUpgradeTime: mockable.MaxTime, }} secondCtx := snowtest.Context(t, snowtest.PChainID) @@ -1252,7 +1252,7 @@ func TestBootstrapPartiallyAccepted(t *testing.T) { BanffTime: latestForkTime, CortinaTime: latestForkTime, DurangoTime: latestForkTime, - EForkTime: mockable.MaxTime, + EUpgradeTime: mockable.MaxTime, }} initialClkTime := latestForkTime.Add(time.Second) @@ -1594,7 +1594,7 @@ func TestUnverifiedParent(t *testing.T) { BanffTime: latestForkTime, CortinaTime: latestForkTime, DurangoTime: latestForkTime, - EForkTime: mockable.MaxTime, + EUpgradeTime: mockable.MaxTime, }} initialClkTime := latestForkTime.Add(time.Second) @@ -1755,7 +1755,7 @@ func TestUptimeDisallowedWithRestart(t *testing.T) { BanffTime: latestForkTime, CortinaTime: latestForkTime, DurangoTime: latestForkTime, - EForkTime: mockable.MaxTime, + EUpgradeTime: mockable.MaxTime, }} firstCtx := snowtest.Context(t, snowtest.PChainID) @@ -1804,7 +1804,7 @@ func TestUptimeDisallowedWithRestart(t *testing.T) { BanffTime: latestForkTime, CortinaTime: latestForkTime, DurangoTime: latestForkTime, - EForkTime: mockable.MaxTime, + EUpgradeTime: mockable.MaxTime, }} secondCtx := snowtest.Context(t, snowtest.PChainID) @@ -1904,7 +1904,7 @@ func TestUptimeDisallowedAfterNeverConnecting(t *testing.T) { BanffTime: latestForkTime, CortinaTime: latestForkTime, DurangoTime: latestForkTime, - EForkTime: mockable.MaxTime, + EUpgradeTime: mockable.MaxTime, }} ctx := snowtest.Context(t, snowtest.PChainID) From 62ab6d03ec03bd6be3973820b56d11f9acd0efe1 Mon Sep 17 00:00:00 2001 From: Alberto Benegiamo Date: Fri, 2 Feb 2024 09:39:30 +0100 Subject: [PATCH 04/18] upgraded codec for dynamic fees --- codec/manager.go | 6 +- codec/reflectcodec/type_codec.go | 16 ++--- codec/test_codec.go | 81 ++++++++++++++++++++++ vms/platformvm/state/metadata_validator.go | 3 +- 4 files changed, 94 insertions(+), 12 deletions(-) diff --git a/codec/manager.go b/codec/manager.go index 6fb48aaad9f8..bf1ad3af72bc 100644 --- a/codec/manager.go +++ b/codec/manager.go @@ -13,6 +13,8 @@ import ( ) const ( + CodecVersionSize = wrappers.ShortLen + // default max size, in bytes, of something being marshalled by Marshal() defaultMaxSize = 256 * units.KiB @@ -102,8 +104,8 @@ func (m *manager) Size(version uint16, value interface{}) (int, error) { res, err := c.Size(value) - // Add [wrappers.ShortLen] for the codec version - return wrappers.ShortLen + res, err + // Add [CodecVersionSize] for the codec version + return CodecVersionSize + res, err } // To marshal an interface, [value] must be a pointer to the interface. diff --git a/codec/reflectcodec/type_codec.go b/codec/reflectcodec/type_codec.go index 312927559280..e8b19e80fe83 100644 --- a/codec/reflectcodec/type_codec.go +++ b/codec/reflectcodec/type_codec.go @@ -27,8 +27,6 @@ const ( var ( _ codec.Codec = (*genericCodec)(nil) - errMarshalNil = errors.New("can't marshal nil pointer or interface") - errUnmarshalNil = errors.New("can't unmarshal nil") errNeedPointer = errors.New("argument to unmarshal must be a pointer") errRecursiveInterfaceTypes = errors.New("recursive interface types") ) @@ -90,7 +88,7 @@ func New(typer TypeCodec, tagNames []string, durangoTime time.Time, maxSliceLen func (c *genericCodec) Size(value interface{}) (int, error) { if value == nil { - return 0, errMarshalNil // can't marshal nil + return 0, nil // can't marshal nil, we return zero size } size, _, err := c.size(reflect.ValueOf(value), nil /*=typeStack*/) @@ -126,14 +124,14 @@ func (c *genericCodec) size( return wrappers.StringLen(value.String()), false, nil case reflect.Ptr: if value.IsNil() { - return 0, false, errMarshalNil + return 0, false, nil // can't marshal nil, we return zero size } return c.size(value.Elem(), typeStack) case reflect.Interface: if value.IsNil() { - return 0, false, errMarshalNil + return 0, false, nil // can't marshal nil, we return zero size } underlyingValue := value.Interface() @@ -292,7 +290,7 @@ func (c *genericCodec) size( // To marshal an interface, [value] must be a pointer to the interface func (c *genericCodec) MarshalInto(value interface{}, p *wrappers.Packer) error { if value == nil { - return errMarshalNil // can't marshal nil + return codec.ErrMarshalNil // can't marshal nil } return c.marshal(reflect.ValueOf(value), p, nil /*=typeStack*/) @@ -339,13 +337,13 @@ func (c *genericCodec) marshal( return p.Err case reflect.Ptr: if value.IsNil() { - return errMarshalNil + return codec.ErrMarshalNil } return c.marshal(value.Elem(), p, typeStack) case reflect.Interface: if value.IsNil() { - return errMarshalNil + return codec.ErrMarshalNil } underlyingValue := value.Interface() @@ -505,7 +503,7 @@ func (c *genericCodec) marshal( // interface func (c *genericCodec) Unmarshal(bytes []byte, dest interface{}) error { if dest == nil { - return errUnmarshalNil + return codec.ErrUnmarshalNil } p := wrappers.Packer{ diff --git a/codec/test_codec.go b/codec/test_codec.go index d58e2d818f9e..ed484042941b 100644 --- a/codec/test_codec.go +++ b/codec/test_codec.go @@ -15,6 +15,8 @@ import ( var ( Tests = []func(c GeneralCodec, t testing.TB){ TestStruct, + TestPartiallyFilledStruct, + TestSliceWithEmptyElements, TestRegisterStructTwice, TestUInt32, TestUIntPtr, @@ -249,6 +251,85 @@ func TestStruct(codec GeneralCodec, t testing.TB) { require.Equal(myStructInstance, *myStructUnmarshaled) } +func TestPartiallyFilledStruct(codec GeneralCodec, t testing.TB) { + require := require.New(t) + + manager := NewDefaultManager() + require.NoError(manager.RegisterCodec(0, codec)) + + // a nil pointer cannot be marshalled but we can get its size + var nilStruct *myStruct + _, err := manager.Marshal(0, nilStruct) + require.ErrorIs(err, ErrMarshalNil) + + bytesLen, err := manager.Size(0, nilStruct) + require.NoError(err) + require.Equal(CodecVersionSize, bytesLen) + + // an empty struct cannot be marshalled but we can get its size + emptyStruct := &myStruct{} + _, err = manager.Marshal(0, nilStruct) + require.ErrorIs(err, ErrMarshalNil) + + emptyStructLen := CodecVersionSize + 117 + bytesLen, err = manager.Size(0, emptyStruct) + require.NoError(err) + require.Equal(emptyStructLen, bytesLen) + + // an partially filled struct cannot be marshalled but we can get its size + elem := &MyInnerStruct{ + Str: "a", + } + elemLen := CodecVersionSize + wrappers.StringLen(elem.Str) + + partialStruct := &myStruct{ + InnerStruct2: elem, + } + partialStructLen := emptyStructLen + elemLen - CodecVersionSize + bytesLen, err = manager.Size(0, partialStruct) + require.NoError(err) + require.Equal(partialStructLen, bytesLen) +} + +func TestSliceWithEmptyElements(codec GeneralCodec, t testing.TB) { + require := require.New(t) + + manager := NewDefaultManager() + require.NoError(manager.RegisterCodec(0, codec)) + + // a non-empty slice with nil pointers cannot be marshalled but we can get its size + slice := make([]*MyInnerStruct, 10) + + _, err := manager.Marshal(0, slice) + require.ErrorIs(err, ErrMarshalNil) + + emptySliceLen := CodecVersionSize + wrappers.IntLen // Codec version + slice size. Slice elements have zero size + bytesLen, err := manager.Size(0, slice) + require.NoError(err) + require.Equal(emptySliceLen, bytesLen) + + elem := &MyInnerStruct{ + Str: "aaa", + } + elemLen := CodecVersionSize + wrappers.StringLen(elem.Str) + bytesLen, err = manager.Size(0, elem) + require.NoError(err) + require.Equal(elemLen, bytesLen) + + // we can fill some elements and leave other empty. Size will be sub-additive + slice[1] = elem + sliceLen := emptySliceLen + elemLen - CodecVersionSize // codec version is marshelled only once + bytesLen, err = manager.Size(0, slice) + require.NoError(err) + require.Equal(sliceLen, bytesLen) + + slice[5] = elem + sliceLen += elemLen - CodecVersionSize // codec version is marshelled only once + bytesLen, err = manager.Size(0, slice) + require.NoError(err) + require.Equal(sliceLen, bytesLen) +} + func TestRegisterStructTwice(codec GeneralCodec, t testing.TB) { require := require.New(t) diff --git a/vms/platformvm/state/metadata_validator.go b/vms/platformvm/state/metadata_validator.go index 0c725368505b..74242150d37f 100644 --- a/vms/platformvm/state/metadata_validator.go +++ b/vms/platformvm/state/metadata_validator.go @@ -6,6 +6,7 @@ package state import ( "time" + "github.com/ava-labs/avalanchego/codec" "github.com/ava-labs/avalanchego/database" "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/utils/constants" @@ -17,7 +18,7 @@ import ( // [preDelegateeRewardMetadata]. // // CodecVersionLen + UpDurationLen + LastUpdatedLen + PotentialRewardLen -const preDelegateeRewardSize = wrappers.ShortLen + 3*wrappers.LongLen +const preDelegateeRewardSize = codec.CodecVersionSize + 3*wrappers.LongLen var _ validatorState = (*metadata)(nil) From 3daec3411519365d01497e0e7a920e110b2e245d Mon Sep 17 00:00:00 2001 From: Alberto Benegiamo Date: Thu, 8 Feb 2024 23:36:17 +0100 Subject: [PATCH 05/18] cleanup --- vms/platformvm/block/builder/builder_test.go | 18 ++--- vms/platformvm/block/builder/helpers_test.go | 58 ++++++++++++++--- .../block/builder/standard_block_test.go | 2 +- vms/platformvm/block/executor/helpers_test.go | 57 +++++++++++++--- .../block/executor/proposal_block_test.go | 16 ++--- .../block/executor/standard_block_test.go | 14 ++-- .../txs/executor/advance_time_test.go | 22 +++---- .../txs/executor/create_chain_test.go | 10 +-- .../txs/executor/create_subnet_test.go | 2 +- vms/platformvm/txs/executor/export_test.go | 2 +- vms/platformvm/txs/executor/helpers_test.go | 65 +++++++++++++------ vms/platformvm/txs/executor/import_test.go | 2 +- .../txs/executor/proposal_tx_executor_test.go | 8 +-- .../txs/executor/reward_validator_test.go | 12 ++-- .../txs/executor/standard_tx_executor_test.go | 14 ++-- vms/platformvm/vm_test.go | 7 +- 16 files changed, 212 insertions(+), 97 deletions(-) diff --git a/vms/platformvm/block/builder/builder_test.go b/vms/platformvm/block/builder/builder_test.go index 56f189cb986a..039bcc92b0c8 100644 --- a/vms/platformvm/block/builder/builder_test.go +++ b/vms/platformvm/block/builder/builder_test.go @@ -33,7 +33,7 @@ import ( func TestBuildBlockBasic(t *testing.T) { require := require.New(t) - env := newEnvironment(t) + env := newEnvironment(t, durangoFork) env.ctx.Lock.Lock() defer env.ctx.Lock.Unlock() @@ -75,7 +75,7 @@ func TestBuildBlockBasic(t *testing.T) { func TestBuildBlockDoesNotBuildWithEmptyMempool(t *testing.T) { require := require.New(t) - env := newEnvironment(t) + env := newEnvironment(t, durangoFork) env.ctx.Lock.Lock() defer env.ctx.Lock.Unlock() @@ -92,7 +92,7 @@ func TestBuildBlockDoesNotBuildWithEmptyMempool(t *testing.T) { func TestBuildBlockShouldReward(t *testing.T) { require := require.New(t) - env := newEnvironment(t) + env := newEnvironment(t, durangoFork) env.ctx.Lock.Lock() defer env.ctx.Lock.Unlock() @@ -193,7 +193,7 @@ func TestBuildBlockShouldReward(t *testing.T) { func TestBuildBlockAdvanceTime(t *testing.T) { require := require.New(t) - env := newEnvironment(t) + env := newEnvironment(t, durangoFork) env.ctx.Lock.Lock() defer env.ctx.Lock.Unlock() @@ -226,7 +226,7 @@ func TestBuildBlockAdvanceTime(t *testing.T) { func TestBuildBlockForceAdvanceTime(t *testing.T) { require := require.New(t) - env := newEnvironment(t) + env := newEnvironment(t, durangoFork) env.ctx.Lock.Lock() defer env.ctx.Lock.Unlock() @@ -280,7 +280,7 @@ func TestBuildBlockForceAdvanceTime(t *testing.T) { func TestBuildBlockDropExpiredStakerTxs(t *testing.T) { require := require.New(t) - env := newEnvironment(t) + env := newEnvironment(t, durangoFork) env.ctx.Lock.Lock() defer env.ctx.Lock.Unlock() @@ -383,7 +383,7 @@ func TestBuildBlockDropExpiredStakerTxs(t *testing.T) { func TestBuildBlockInvalidStakingDurations(t *testing.T) { require := require.New(t) - env := newEnvironment(t) + env := newEnvironment(t, durangoFork) env.ctx.Lock.Lock() defer env.ctx.Lock.Unlock() @@ -467,7 +467,7 @@ func TestBuildBlockInvalidStakingDurations(t *testing.T) { func TestPreviouslyDroppedTxsCannotBeReAddedToMempool(t *testing.T) { require := require.New(t) - env := newEnvironment(t) + env := newEnvironment(t, durangoFork) env.ctx.Lock.Lock() defer env.ctx.Lock.Unlock() @@ -510,7 +510,7 @@ func TestPreviouslyDroppedTxsCannotBeReAddedToMempool(t *testing.T) { func TestNoErrorOnUnexpectedSetPreferenceDuringBootstrapping(t *testing.T) { require := require.New(t) - env := newEnvironment(t) + env := newEnvironment(t, durangoFork) env.ctx.Lock.Lock() defer env.ctx.Lock.Unlock() diff --git a/vms/platformvm/block/builder/helpers_test.go b/vms/platformvm/block/builder/helpers_test.go index 92892df75ae2..27b6573c05fe 100644 --- a/vms/platformvm/block/builder/helpers_test.go +++ b/vms/platformvm/block/builder/helpers_test.go @@ -5,6 +5,7 @@ package builder import ( "context" + "fmt" "testing" "time" @@ -58,8 +59,17 @@ import ( const ( defaultWeight = 10000 trackChecksum = false + + apricotPhase3 activeFork = iota + apricotPhase5 + banffFork + cortinaFork + durangoFork + eUpgradeFork ) +type activeFork uint8 + var ( defaultMinStakingDuration = 24 * time.Hour defaultMaxStakingDuration = 365 * 24 * time.Hour @@ -111,12 +121,12 @@ type environment struct { backend txexecutor.Backend } -func newEnvironment(t *testing.T) *environment { +func newEnvironment(t *testing.T, fork activeFork) *environment { //nolint:unparam require := require.New(t) res := &environment{ isBootstrapped: &utils.Atomic[bool]{}, - config: defaultConfig(), + config: defaultConfig(t, fork), clk: defaultClock(), } res.isBootstrapped.Set(true) @@ -293,7 +303,38 @@ func defaultState( return state } -func defaultConfig() *config.Config { +func defaultConfig(t *testing.T, fork activeFork) *config.Config { + var ( + apricotPhase3Time = mockable.MaxTime + apricotPhase5Time = mockable.MaxTime + banffTime = mockable.MaxTime + cortinaTime = mockable.MaxTime + durangoTime = mockable.MaxTime + eUpgradeTime = mockable.MaxTime + ) + + switch fork { + case eUpgradeFork: + eUpgradeTime = time.Time{} // neglecting fork ordering this for package tests + fallthrough + case durangoFork: + durangoTime = time.Time{} // neglecting fork ordering this for package tests + fallthrough + case cortinaFork: + cortinaTime = time.Time{} // neglecting fork ordering this for package tests + fallthrough + case banffFork: + banffTime = time.Time{} // neglecting fork ordering this for package tests + fallthrough + case apricotPhase5: + apricotPhase5Time = defaultValidateEndTime + fallthrough + case apricotPhase3: + apricotPhase3Time = defaultValidateEndTime + default: + require.NoError(t, fmt.Errorf("unhandled fork %d", fork)) + } + return &config.Config{ Chains: chains.TestManager, UptimeLockedCalculator: uptime.NewLockedCalculator(), @@ -312,11 +353,12 @@ func defaultConfig() *config.Config { MintingPeriod: 365 * 24 * time.Hour, SupplyCap: 720 * units.MegaAvax, }, - ApricotPhase3Time: defaultValidateEndTime, - ApricotPhase5Time: defaultValidateEndTime, - BanffTime: time.Time{}, // neglecting fork ordering this for package tests - DurangoTime: time.Time{}, - EUpgradeTime: mockable.MaxTime, + ApricotPhase3Time: apricotPhase3Time, + ApricotPhase5Time: apricotPhase5Time, + BanffTime: banffTime, + CortinaTime: cortinaTime, + DurangoTime: durangoTime, + EUpgradeTime: eUpgradeTime, } } diff --git a/vms/platformvm/block/builder/standard_block_test.go b/vms/platformvm/block/builder/standard_block_test.go index 6064b2153113..f286a9191ecf 100644 --- a/vms/platformvm/block/builder/standard_block_test.go +++ b/vms/platformvm/block/builder/standard_block_test.go @@ -22,7 +22,7 @@ import ( func TestAtomicTxImports(t *testing.T) { require := require.New(t) - env := newEnvironment(t) + env := newEnvironment(t, durangoFork) env.ctx.Lock.Lock() defer env.ctx.Lock.Unlock() diff --git a/vms/platformvm/block/executor/helpers_test.go b/vms/platformvm/block/executor/helpers_test.go index 9b98681c44cd..26eb69ada86d 100644 --- a/vms/platformvm/block/executor/helpers_test.go +++ b/vms/platformvm/block/executor/helpers_test.go @@ -61,8 +61,17 @@ const ( defaultWeight = 10000 trackChecksum = false + + apricotPhase3 activeFork = iota + apricotPhase5 + banffFork + cortinaFork + durangoFork + eUpgradeFork ) +type activeFork uint8 + var ( defaultMinStakingDuration = 24 * time.Hour defaultMaxStakingDuration = 365 * 24 * time.Hour @@ -126,10 +135,10 @@ type environment struct { backend *executor.Backend } -func newEnvironment(t *testing.T, ctrl *gomock.Controller) *environment { +func newEnvironment(t *testing.T, ctrl *gomock.Controller, fork activeFork) *environment { res := &environment{ isBootstrapped: &utils.Atomic[bool]{}, - config: defaultConfig(), + config: defaultConfig(t, fork), clk: defaultClock(), } res.isBootstrapped.Set(true) @@ -321,7 +330,38 @@ func defaultState( return state } -func defaultConfig() *config.Config { +func defaultConfig(t *testing.T, fork activeFork) *config.Config { + var ( + apricotPhase3Time = mockable.MaxTime + apricotPhase5Time = mockable.MaxTime + banffTime = mockable.MaxTime + cortinaTime = mockable.MaxTime + durangoTime = mockable.MaxTime + eUpgradeTime = mockable.MaxTime + ) + + switch fork { + case eUpgradeFork: + eUpgradeTime = time.Time{} // neglecting fork ordering this for package tests + fallthrough + case durangoFork: + durangoTime = time.Time{} // neglecting fork ordering this for package tests + fallthrough + case cortinaFork: + cortinaTime = time.Time{} // neglecting fork ordering this for package tests + fallthrough + case banffFork: + banffTime = time.Time{} // neglecting fork ordering this for package tests + fallthrough + case apricotPhase5: + apricotPhase5Time = defaultValidateEndTime + fallthrough + case apricotPhase3: + apricotPhase3Time = defaultValidateEndTime + default: + require.NoError(t, fmt.Errorf("unhandled fork %d", fork)) + } + return &config.Config{ Chains: chains.TestManager, UptimeLockedCalculator: uptime.NewLockedCalculator(), @@ -340,11 +380,12 @@ func defaultConfig() *config.Config { MintingPeriod: 365 * 24 * time.Hour, SupplyCap: 720 * units.MegaAvax, }, - ApricotPhase3Time: defaultValidateEndTime, - ApricotPhase5Time: defaultValidateEndTime, - BanffTime: mockable.MaxTime, - DurangoTime: mockable.MaxTime, - EUpgradeTime: mockable.MaxTime, + ApricotPhase3Time: apricotPhase3Time, + ApricotPhase5Time: apricotPhase5Time, + BanffTime: banffTime, + DurangoTime: durangoTime, + CortinaTime: cortinaTime, + EUpgradeTime: eUpgradeTime, } } diff --git a/vms/platformvm/block/executor/proposal_block_test.go b/vms/platformvm/block/executor/proposal_block_test.go index 33a3877fc24b..7476c4f57726 100644 --- a/vms/platformvm/block/executor/proposal_block_test.go +++ b/vms/platformvm/block/executor/proposal_block_test.go @@ -36,7 +36,7 @@ func TestApricotProposalBlockTimeVerification(t *testing.T) { require := require.New(t) ctrl := gomock.NewController(t) - env := newEnvironment(t, ctrl) + env := newEnvironment(t, ctrl, apricotPhase5) // create apricotParentBlk. It's a standard one for simplicity parentHeight := uint64(2022) @@ -139,7 +139,7 @@ func TestBanffProposalBlockTimeVerification(t *testing.T) { require := require.New(t) ctrl := gomock.NewController(t) - env := newEnvironment(t, ctrl) + env := newEnvironment(t, ctrl, banffFork) env.clk.Set(defaultGenesisTime) env.config.BanffTime = time.Time{} // activate Banff env.config.DurangoTime = mockable.MaxTime // deactivate Durango @@ -550,7 +550,7 @@ func TestBanffProposalBlockUpdateStakers(t *testing.T) { for _, test := range tests { t.Run(test.description, func(t *testing.T) { require := require.New(t) - env := newEnvironment(t, nil) + env := newEnvironment(t, nil, banffFork) env.config.BanffTime = time.Time{} // activate Banff subnetID := testSubnet1.ID() @@ -700,7 +700,7 @@ func TestBanffProposalBlockUpdateStakers(t *testing.T) { func TestBanffProposalBlockRemoveSubnetValidator(t *testing.T) { require := require.New(t) - env := newEnvironment(t, nil) + env := newEnvironment(t, nil, banffFork) env.config.BanffTime = time.Time{} // activate Banff subnetID := testSubnet1.ID() @@ -840,7 +840,7 @@ func TestBanffProposalBlockTrackedSubnet(t *testing.T) { for _, tracked := range []bool{true, false} { t.Run(fmt.Sprintf("tracked %t", tracked), func(ts *testing.T) { require := require.New(t) - env := newEnvironment(t, nil) + env := newEnvironment(t, nil, banffFork) env.config.BanffTime = time.Time{} // activate Banff subnetID := testSubnet1.ID() @@ -943,7 +943,7 @@ func TestBanffProposalBlockTrackedSubnet(t *testing.T) { func TestBanffProposalBlockDelegatorStakerWeight(t *testing.T) { require := require.New(t) - env := newEnvironment(t, nil) + env := newEnvironment(t, nil, banffFork) env.config.BanffTime = time.Time{} // activate Banff // Case: Timestamp is after next validator start time @@ -1125,7 +1125,7 @@ func TestBanffProposalBlockDelegatorStakerWeight(t *testing.T) { func TestBanffProposalBlockDelegatorStakers(t *testing.T) { require := require.New(t) - env := newEnvironment(t, nil) + env := newEnvironment(t, nil, banffFork) env.config.BanffTime = time.Time{} // activate Banff // Case: Timestamp is after next validator start time @@ -1307,7 +1307,7 @@ func TestBanffProposalBlockDelegatorStakers(t *testing.T) { func TestAddValidatorProposalBlock(t *testing.T) { require := require.New(t) - env := newEnvironment(t, nil) + env := newEnvironment(t, nil, apricotPhase5) env.config.BanffTime = time.Time{} // activate Banff env.config.DurangoTime = time.Time{} // activate Durango diff --git a/vms/platformvm/block/executor/standard_block_test.go b/vms/platformvm/block/executor/standard_block_test.go index 3e0122c9123d..54b45b0ab7c4 100644 --- a/vms/platformvm/block/executor/standard_block_test.go +++ b/vms/platformvm/block/executor/standard_block_test.go @@ -30,7 +30,7 @@ func TestApricotStandardBlockTimeVerification(t *testing.T) { require := require.New(t) ctrl := gomock.NewController(t) - env := newEnvironment(t, ctrl) + env := newEnvironment(t, ctrl, apricotPhase5) // setup and store parent block // it's a standard block for simplicity @@ -83,7 +83,7 @@ func TestBanffStandardBlockTimeVerification(t *testing.T) { require := require.New(t) ctrl := gomock.NewController(t) - env := newEnvironment(t, ctrl) + env := newEnvironment(t, ctrl, banffFork) now := env.clk.Time() env.clk.Set(now) env.config.BanffTime = time.Time{} // activate Banff @@ -291,7 +291,7 @@ func TestBanffStandardBlockTimeVerification(t *testing.T) { func TestBanffStandardBlockUpdatePrimaryNetworkStakers(t *testing.T) { require := require.New(t) - env := newEnvironment(t, nil) + env := newEnvironment(t, nil, banffFork) env.config.BanffTime = time.Time{} // activate Banff // Case: Timestamp is after next validator start time @@ -493,7 +493,7 @@ func TestBanffStandardBlockUpdateStakers(t *testing.T) { for _, test := range tests { t.Run(test.description, func(t *testing.T) { require := require.New(t) - env := newEnvironment(t, nil) + env := newEnvironment(t, nil, banffFork) env.config.BanffTime = time.Time{} // activate Banff subnetID := testSubnet1.ID() @@ -592,7 +592,7 @@ func TestBanffStandardBlockUpdateStakers(t *testing.T) { // is after the new timestamp func TestBanffStandardBlockRemoveSubnetValidator(t *testing.T) { require := require.New(t) - env := newEnvironment(t, nil) + env := newEnvironment(t, nil, banffFork) env.config.BanffTime = time.Time{} // activate Banff subnetID := testSubnet1.ID() @@ -688,7 +688,7 @@ func TestBanffStandardBlockTrackedSubnet(t *testing.T) { for _, tracked := range []bool{true, false} { t.Run(fmt.Sprintf("tracked %t", tracked), func(t *testing.T) { require := require.New(t) - env := newEnvironment(t, nil) + env := newEnvironment(t, nil, banffFork) env.config.BanffTime = time.Time{} // activate Banff subnetID := testSubnet1.ID() @@ -748,7 +748,7 @@ func TestBanffStandardBlockTrackedSubnet(t *testing.T) { func TestBanffStandardBlockDelegatorStakerWeight(t *testing.T) { require := require.New(t) - env := newEnvironment(t, nil) + env := newEnvironment(t, nil, banffFork) env.config.BanffTime = time.Time{} // activate Banff // Case: Timestamp is after next validator start time diff --git a/vms/platformvm/txs/executor/advance_time_test.go b/vms/platformvm/txs/executor/advance_time_test.go index b7b636ad6dbe..eaab7ca0f04e 100644 --- a/vms/platformvm/txs/executor/advance_time_test.go +++ b/vms/platformvm/txs/executor/advance_time_test.go @@ -34,7 +34,7 @@ func newAdvanceTimeTx(t testing.TB, timestamp time.Time) (*txs.Tx, error) { // for the primary network func TestAdvanceTimeTxUpdatePrimaryNetworkStakers(t *testing.T) { require := require.New(t) - env := newEnvironment(t, false /*=postBanff*/, false /*=postCortina*/, false /*=postDurango*/) + env := newEnvironment(t, apricotPhase5) env.ctx.Lock.Lock() defer env.ctx.Lock.Unlock() dummyHeight := uint64(1) @@ -97,7 +97,7 @@ func TestAdvanceTimeTxUpdatePrimaryNetworkStakers(t *testing.T) { // Ensure semantic verification fails when proposed timestamp is at or before current timestamp func TestAdvanceTimeTxTimestampTooEarly(t *testing.T) { require := require.New(t) - env := newEnvironment(t, false /*=postBanff*/, false /*=postCortina*/, false /*=postDurango*/) + env := newEnvironment(t, apricotPhase5) tx, err := newAdvanceTimeTx(t, env.state.GetTimestamp()) require.NoError(err) @@ -121,7 +121,7 @@ func TestAdvanceTimeTxTimestampTooEarly(t *testing.T) { // Ensure semantic verification fails when proposed timestamp is after next validator set change time func TestAdvanceTimeTxTimestampTooLate(t *testing.T) { require := require.New(t) - env := newEnvironment(t, false /*=postBanff*/, false /*=postCortina*/, false /*=postDurango*/) + env := newEnvironment(t, apricotPhase5) env.ctx.Lock.Lock() defer env.ctx.Lock.Unlock() @@ -154,7 +154,7 @@ func TestAdvanceTimeTxTimestampTooLate(t *testing.T) { } // Case: Timestamp is after next validator end time - env = newEnvironment(t, false /*=postBanff*/, false /*=postCortina*/, false /*=postDurango*/) + env = newEnvironment(t, apricotPhase5) env.ctx.Lock.Lock() defer env.ctx.Lock.Unlock() @@ -354,7 +354,7 @@ func TestAdvanceTimeTxUpdateStakers(t *testing.T) { for _, test := range tests { t.Run(test.description, func(t *testing.T) { require := require.New(t) - env := newEnvironment(t, false /*=postBanff*/, false /*=postCortina*/, false /*=postDurango*/) + env := newEnvironment(t, apricotPhase5) env.ctx.Lock.Lock() defer env.ctx.Lock.Unlock() @@ -457,7 +457,7 @@ func TestAdvanceTimeTxUpdateStakers(t *testing.T) { // is after the new timestamp func TestAdvanceTimeTxRemoveSubnetValidator(t *testing.T) { require := require.New(t) - env := newEnvironment(t, false /*=postBanff*/, false /*=postCortina*/, false /*=postDurango*/) + env := newEnvironment(t, apricotPhase5) env.ctx.Lock.Lock() defer env.ctx.Lock.Unlock() @@ -559,7 +559,7 @@ func TestTrackedSubnet(t *testing.T) { for _, tracked := range []bool{true, false} { t.Run(fmt.Sprintf("tracked %t", tracked), func(t *testing.T) { require := require.New(t) - env := newEnvironment(t, false /*=postBanff*/, false /*=postCortina*/, false /*=postDurango*/) + env := newEnvironment(t, apricotPhase5) env.ctx.Lock.Lock() defer env.ctx.Lock.Unlock() dummyHeight := uint64(1) @@ -627,7 +627,7 @@ func TestTrackedSubnet(t *testing.T) { func TestAdvanceTimeTxDelegatorStakerWeight(t *testing.T) { require := require.New(t) - env := newEnvironment(t, false /*=postBanff*/, false /*=postCortina*/, false /*=postDurango*/) + env := newEnvironment(t, apricotPhase5) env.ctx.Lock.Lock() defer env.ctx.Lock.Unlock() dummyHeight := uint64(1) @@ -732,7 +732,7 @@ func TestAdvanceTimeTxDelegatorStakerWeight(t *testing.T) { func TestAdvanceTimeTxDelegatorStakers(t *testing.T) { require := require.New(t) - env := newEnvironment(t, false /*=postBanff*/, false /*=postCortina*/, false /*=postDurango*/) + env := newEnvironment(t, apricotPhase5) env.ctx.Lock.Lock() defer env.ctx.Lock.Unlock() dummyHeight := uint64(1) @@ -826,7 +826,7 @@ func TestAdvanceTimeTxDelegatorStakers(t *testing.T) { func TestAdvanceTimeTxAfterBanff(t *testing.T) { require := require.New(t) - env := newEnvironment(t, false /*=postBanff*/, false /*=postCortina*/, false /*=postDurango*/) + env := newEnvironment(t, apricotPhase5) env.ctx.Lock.Lock() defer env.ctx.Lock.Unlock() env.clk.Set(defaultGenesisTime) // VM's clock reads the genesis time @@ -858,7 +858,7 @@ func TestAdvanceTimeTxAfterBanff(t *testing.T) { // Ensure marshaling/unmarshaling works func TestAdvanceTimeTxUnmarshal(t *testing.T) { require := require.New(t) - env := newEnvironment(t, false /*=postBanff*/, false /*=postCortina*/, false /*=postDurango*/) + env := newEnvironment(t, apricotPhase5) env.ctx.Lock.Lock() defer env.ctx.Lock.Unlock() diff --git a/vms/platformvm/txs/executor/create_chain_test.go b/vms/platformvm/txs/executor/create_chain_test.go index 0342c8dc1cfe..bfb8097382d4 100644 --- a/vms/platformvm/txs/executor/create_chain_test.go +++ b/vms/platformvm/txs/executor/create_chain_test.go @@ -25,7 +25,7 @@ import ( // Ensure Execute fails when there are not enough control sigs func TestCreateChainTxInsufficientControlSigs(t *testing.T) { require := require.New(t) - env := newEnvironment(t, true /*=postBanff*/, false /*=postCortina*/, false /*=postDurango*/) + env := newEnvironment(t, banffFork) env.ctx.Lock.Lock() defer env.ctx.Lock.Unlock() @@ -58,7 +58,7 @@ func TestCreateChainTxInsufficientControlSigs(t *testing.T) { // Ensure Execute fails when an incorrect control signature is given func TestCreateChainTxWrongControlSig(t *testing.T) { require := require.New(t) - env := newEnvironment(t, true /*=postBanff*/, false /*=postCortina*/, false /*=postDurango*/) + env := newEnvironment(t, banffFork) env.ctx.Lock.Lock() defer env.ctx.Lock.Unlock() @@ -98,7 +98,7 @@ func TestCreateChainTxWrongControlSig(t *testing.T) { // its validator set doesn't exist func TestCreateChainTxNoSuchSubnet(t *testing.T) { require := require.New(t) - env := newEnvironment(t, true /*=postBanff*/, false /*=postCortina*/, false /*=postDurango*/) + env := newEnvironment(t, banffFork) env.ctx.Lock.Lock() defer env.ctx.Lock.Unlock() @@ -130,7 +130,7 @@ func TestCreateChainTxNoSuchSubnet(t *testing.T) { // Ensure valid tx passes semanticVerify func TestCreateChainTxValid(t *testing.T) { require := require.New(t) - env := newEnvironment(t, true /*=postBanff*/, false /*=postCortina*/, false /*=postDurango*/) + env := newEnvironment(t, banffFork) env.ctx.Lock.Lock() defer env.ctx.Lock.Unlock() @@ -187,7 +187,7 @@ func TestCreateChainTxAP3FeeChange(t *testing.T) { t.Run(test.name, func(t *testing.T) { require := require.New(t) - env := newEnvironment(t, true /*=postBanff*/, false /*=postCortina*/, false /*=postDurango*/) + env := newEnvironment(t, banffFork) env.config.ApricotPhase3Time = ap3Time ins, outs, _, signers, err := env.utxosHandler.Spend(env.state, preFundedKeys, 0, test.fee, ids.ShortEmpty) diff --git a/vms/platformvm/txs/executor/create_subnet_test.go b/vms/platformvm/txs/executor/create_subnet_test.go index 6d968daa4df0..a2d59281cc65 100644 --- a/vms/platformvm/txs/executor/create_subnet_test.go +++ b/vms/platformvm/txs/executor/create_subnet_test.go @@ -49,7 +49,7 @@ func TestCreateSubnetTxAP3FeeChange(t *testing.T) { t.Run(test.name, func(t *testing.T) { require := require.New(t) - env := newEnvironment(t, false /*=postBanff*/, false /*=postCortina*/, false /*=postDurango*/) + env := newEnvironment(t, apricotPhase5) env.config.ApricotPhase3Time = ap3Time env.ctx.Lock.Lock() defer env.ctx.Lock.Unlock() diff --git a/vms/platformvm/txs/executor/export_test.go b/vms/platformvm/txs/executor/export_test.go index d9e0ce071008..12aa12de33ef 100644 --- a/vms/platformvm/txs/executor/export_test.go +++ b/vms/platformvm/txs/executor/export_test.go @@ -15,7 +15,7 @@ import ( ) func TestNewExportTx(t *testing.T) { - env := newEnvironment(t, true /*=postBanff*/, false /*=postCortina*/, false /*=postDurango*/) + env := newEnvironment(t, banffFork) env.ctx.Lock.Lock() defer env.ctx.Lock.Unlock() diff --git a/vms/platformvm/txs/executor/helpers_test.go b/vms/platformvm/txs/executor/helpers_test.go index 3d6683529cca..2975d4739f5b 100644 --- a/vms/platformvm/txs/executor/helpers_test.go +++ b/vms/platformvm/txs/executor/helpers_test.go @@ -51,8 +51,17 @@ import ( const ( defaultWeight = 5 * units.MilliAvax trackChecksum = false + + apricotPhase3 activeFork = iota + apricotPhase5 + banffFork + cortinaFork + durangoFork + eUpgradeFork ) +type activeFork uint8 + var ( defaultMinStakingDuration = 24 * time.Hour defaultMaxStakingDuration = 365 * 24 * time.Hour @@ -112,12 +121,12 @@ func (e *environment) SetState(blkID ids.ID, chainState state.Chain) { e.states[blkID] = chainState } -func newEnvironment(t *testing.T, postBanff, postCortina, postDurango bool) *environment { +func newEnvironment(t *testing.T, fork activeFork) *environment { var isBootstrapped utils.Atomic[bool] isBootstrapped.Set(true) - config := defaultConfig(postBanff, postCortina, postDurango) - clk := defaultClock(postBanff || postCortina || postDurango) + config := defaultConfig(t, fork) + clk := defaultClock(fork) baseDB := versiondb.New(memdb.New()) ctx := snowtest.Context(t, snowtest.PChainID) @@ -271,18 +280,36 @@ func defaultState( return state } -func defaultConfig(postBanff, postCortina, postDurango bool) *config.Config { - banffTime := mockable.MaxTime - if postBanff { - banffTime = defaultValidateEndTime.Add(-2 * time.Second) - } - cortinaTime := mockable.MaxTime - if postCortina { - cortinaTime = defaultValidateStartTime.Add(-2 * time.Second) - } - durangoTime := mockable.MaxTime - if postDurango { +func defaultConfig(t *testing.T, fork activeFork) *config.Config { + var ( + apricotPhase3Time = mockable.MaxTime + apricotPhase5Time = mockable.MaxTime + banffTime = mockable.MaxTime + cortinaTime = mockable.MaxTime + durangoTime = mockable.MaxTime + eUpgradeTime = mockable.MaxTime + ) + + switch fork { + case eUpgradeFork: + eUpgradeTime = defaultValidateStartTime.Add(-2 * time.Second) + fallthrough + case durangoFork: durangoTime = defaultValidateStartTime.Add(-2 * time.Second) + fallthrough + case cortinaFork: + cortinaTime = defaultValidateStartTime.Add(-2 * time.Second) + fallthrough + case banffFork: + banffTime = defaultValidateStartTime.Add(-2 * time.Second) + fallthrough + case apricotPhase5: + apricotPhase5Time = defaultValidateEndTime + fallthrough + case apricotPhase3: + apricotPhase3Time = defaultValidateEndTime + default: + require.NoError(t, fmt.Errorf("unhandled fork %d", fork)) } return &config.Config{ @@ -303,18 +330,18 @@ func defaultConfig(postBanff, postCortina, postDurango bool) *config.Config { MintingPeriod: 365 * 24 * time.Hour, SupplyCap: 720 * units.MegaAvax, }, - ApricotPhase3Time: defaultValidateEndTime, - ApricotPhase5Time: defaultValidateEndTime, + ApricotPhase3Time: apricotPhase3Time, + ApricotPhase5Time: apricotPhase5Time, BanffTime: banffTime, CortinaTime: cortinaTime, DurangoTime: durangoTime, - EUpgradeTime: mockable.MaxTime, + EUpgradeTime: eUpgradeTime, } } -func defaultClock(postFork bool) *mockable.Clock { +func defaultClock(fork activeFork) *mockable.Clock { now := defaultGenesisTime - if postFork { + if fork == eUpgradeFork || fork == durangoFork || fork == cortinaFork || fork == banffFork { // 1 second after Banff fork now = defaultValidateEndTime.Add(-2 * time.Second) } diff --git a/vms/platformvm/txs/executor/import_test.go b/vms/platformvm/txs/executor/import_test.go index fed09bd882ce..9f1c90dab501 100644 --- a/vms/platformvm/txs/executor/import_test.go +++ b/vms/platformvm/txs/executor/import_test.go @@ -22,7 +22,7 @@ import ( ) func TestNewImportTx(t *testing.T) { - env := newEnvironment(t, false /*=postBanff*/, false /*=postCortina*/, false /*=postDurango*/) + env := newEnvironment(t, apricotPhase5) type test struct { description string diff --git a/vms/platformvm/txs/executor/proposal_tx_executor_test.go b/vms/platformvm/txs/executor/proposal_tx_executor_test.go index e01bd267a024..d16e072a3a10 100644 --- a/vms/platformvm/txs/executor/proposal_tx_executor_test.go +++ b/vms/platformvm/txs/executor/proposal_tx_executor_test.go @@ -91,7 +91,7 @@ func TestProposalTxExecuteAddDelegator(t *testing.T) { require.NoError(t, target.state.Commit()) } - dummyH := newEnvironment(t, false /*=postBanff*/, false /*=postCortina*/, false /*=postDurango*/) + dummyH := newEnvironment(t, apricotPhase5) currentTimestamp := dummyH.state.GetTimestamp() type test struct { @@ -245,7 +245,7 @@ func TestProposalTxExecuteAddDelegator(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { require := require.New(t) - freshTH := newEnvironment(t, false /*=postBanff*/, false /*=postCortina*/, false /*=postDurango*/) + freshTH := newEnvironment(t, apricotPhase5) freshTH.config.ApricotPhase3Time = tt.AP3Time tx, err := freshTH.txBuilder.NewAddDelegatorTx( @@ -283,7 +283,7 @@ func TestProposalTxExecuteAddDelegator(t *testing.T) { func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { require := require.New(t) - env := newEnvironment(t, false /*=postBanff*/, false /*=postCortina*/, false /*=postDurango*/) + env := newEnvironment(t, apricotPhase5) env.ctx.Lock.Lock() defer env.ctx.Lock.Unlock() @@ -716,7 +716,7 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { func TestProposalTxExecuteAddValidator(t *testing.T) { require := require.New(t) - env := newEnvironment(t, false /*=postBanff*/, false /*=postCortina*/, false /*=postDurango*/) + env := newEnvironment(t, apricotPhase5) env.ctx.Lock.Lock() defer env.ctx.Lock.Unlock() diff --git a/vms/platformvm/txs/executor/reward_validator_test.go b/vms/platformvm/txs/executor/reward_validator_test.go index 18ba653a4e79..c9aa34f207d3 100644 --- a/vms/platformvm/txs/executor/reward_validator_test.go +++ b/vms/platformvm/txs/executor/reward_validator_test.go @@ -35,7 +35,7 @@ func newRewardValidatorTx(t testing.TB, txID ids.ID) (*txs.Tx, error) { func TestRewardValidatorTxExecuteOnCommit(t *testing.T) { require := require.New(t) - env := newEnvironment(t, false /*=postBanff*/, false /*=postCortina*/, false /*=postDurango*/) + env := newEnvironment(t, apricotPhase5) dummyHeight := uint64(1) currentStakerIterator, err := env.state.GetCurrentStakerIterator() @@ -135,7 +135,7 @@ func TestRewardValidatorTxExecuteOnCommit(t *testing.T) { func TestRewardValidatorTxExecuteOnAbort(t *testing.T) { require := require.New(t) - env := newEnvironment(t, false /*=postBanff*/, false /*=postCortina*/, false /*=postDurango*/) + env := newEnvironment(t, apricotPhase5) dummyHeight := uint64(1) currentStakerIterator, err := env.state.GetCurrentStakerIterator() @@ -229,7 +229,7 @@ func TestRewardValidatorTxExecuteOnAbort(t *testing.T) { func TestRewardDelegatorTxExecuteOnCommitPreDelegateeDeferral(t *testing.T) { require := require.New(t) - env := newEnvironment(t, false /*=postBanff*/, false /*=postCortina*/, false /*=postDurango*/) + env := newEnvironment(t, apricotPhase5) dummyHeight := uint64(1) vdrRewardAddress := ids.GenerateTestShortID() @@ -350,7 +350,7 @@ func TestRewardDelegatorTxExecuteOnCommitPreDelegateeDeferral(t *testing.T) { func TestRewardDelegatorTxExecuteOnCommitPostDelegateeDeferral(t *testing.T) { require := require.New(t) - env := newEnvironment(t, true /*=postBanff*/, true /*=postCortina*/, false /*=postDurango*/) + env := newEnvironment(t, cortinaFork) dummyHeight := uint64(1) vdrRewardAddress := ids.GenerateTestShortID() @@ -566,7 +566,7 @@ func TestRewardDelegatorTxExecuteOnCommitPostDelegateeDeferral(t *testing.T) { func TestRewardDelegatorTxAndValidatorTxExecuteOnCommitPostDelegateeDeferral(t *testing.T) { require := require.New(t) - env := newEnvironment(t, true /*=postBanff*/, true /*=postCortina*/, false /*=postDurango*/) + env := newEnvironment(t, cortinaFork) dummyHeight := uint64(1) vdrRewardAddress := ids.GenerateTestShortID() @@ -725,7 +725,7 @@ func TestRewardDelegatorTxAndValidatorTxExecuteOnCommitPostDelegateeDeferral(t * func TestRewardDelegatorTxExecuteOnAbort(t *testing.T) { require := require.New(t) - env := newEnvironment(t, false /*=postBanff*/, false /*=postCortina*/, false /*=postDurango*/) + env := newEnvironment(t, apricotPhase5) dummyHeight := uint64(1) initialSupply, err := env.state.GetCurrentSupply(constants.PrimaryNetworkID) diff --git a/vms/platformvm/txs/executor/standard_tx_executor_test.go b/vms/platformvm/txs/executor/standard_tx_executor_test.go index 6fd7fd0bc1f9..211bc7424091 100644 --- a/vms/platformvm/txs/executor/standard_tx_executor_test.go +++ b/vms/platformvm/txs/executor/standard_tx_executor_test.go @@ -46,7 +46,7 @@ var errTest = errors.New("non-nil error") func TestStandardTxExecutorAddValidatorTxEmptyID(t *testing.T) { require := require.New(t) - env := newEnvironment(t, false /*=postBanff*/, false /*=postCortina*/, false /*=postDurango*/) + env := newEnvironment(t, apricotPhase5) env.ctx.Lock.Lock() defer env.ctx.Lock.Unlock() @@ -168,7 +168,7 @@ func TestStandardTxExecutorAddDelegator(t *testing.T) { require.NoError(t, target.state.Commit()) } - dummyH := newEnvironment(t, false /*=postBanff*/, false /*=postCortina*/, false /*=postDurango*/) + dummyH := newEnvironment(t, apricotPhase5) currentTimestamp := dummyH.state.GetTimestamp() type test struct { @@ -322,7 +322,7 @@ func TestStandardTxExecutorAddDelegator(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { require := require.New(t) - freshTH := newEnvironment(t, false /*=postBanff*/, false /*=postCortina*/, false /*=postDurango*/) + freshTH := newEnvironment(t, apricotPhase5) freshTH.config.ApricotPhase3Time = tt.AP3Time tx, err := freshTH.txBuilder.NewAddDelegatorTx( @@ -358,7 +358,7 @@ func TestStandardTxExecutorAddDelegator(t *testing.T) { func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { require := require.New(t) - env := newEnvironment(t, false /*=postBanff*/, false /*=postCortina*/, false /*=postDurango*/) + env := newEnvironment(t, apricotPhase5) env.ctx.Lock.Lock() defer env.ctx.Lock.Unlock() @@ -785,7 +785,7 @@ func TestApricotStandardTxExecutorAddSubnetValidator(t *testing.T) { func TestBanffStandardTxExecutorAddValidator(t *testing.T) { require := require.New(t) - env := newEnvironment(t, true /*=postBanff*/, false /*=postCortina*/, false /*=postDurango*/) + env := newEnvironment(t, banffFork) env.ctx.Lock.Lock() defer env.ctx.Lock.Unlock() @@ -1068,7 +1068,7 @@ func TestDurangoDisabledTransactions(t *testing.T) { t.Run(tt.name, func(t *testing.T) { require := require.New(t) - env := newEnvironment(t, true /*=postBanff*/, true /*=postCortina*/, true /*=postDurango*/) + env := newEnvironment(t, durangoFork) env.ctx.Lock.Lock() defer env.ctx.Lock.Unlock() @@ -1592,7 +1592,7 @@ func TestDurangoMemoField(t *testing.T) { t.Run(tt.name, func(t *testing.T) { require := require.New(t) - env := newEnvironment(t, true /*=postBanff*/, true /*=postCortina*/, true /*=postDurango*/) + env := newEnvironment(t, durangoFork) env.ctx.Lock.Lock() defer env.ctx.Lock.Unlock() diff --git a/vms/platformvm/vm_test.go b/vms/platformvm/vm_test.go index 94e158582cce..ea0e213d6ef3 100644 --- a/vms/platformvm/vm_test.go +++ b/vms/platformvm/vm_test.go @@ -80,6 +80,7 @@ const ( banffFork cortinaFork durangoFork + eUpgradeFork latestFork activeFork = durangoFork @@ -210,12 +211,16 @@ func defaultVM(t *testing.T, fork activeFork) (*VM, database.Database, *mutableS banffTime = mockable.MaxTime cortinaTime = mockable.MaxTime durangoTime = mockable.MaxTime + eUpgradeTime = mockable.MaxTime ) // always reset latestForkTime (a package level variable) // to ensure test independence latestForkTime = defaultGenesisTime.Add(time.Second) switch fork { + case eUpgradeFork: + eUpgradeTime = latestForkTime + fallthrough case durangoFork: durangoTime = latestForkTime fallthrough @@ -254,7 +259,7 @@ func defaultVM(t *testing.T, fork activeFork) (*VM, database.Database, *mutableS BanffTime: banffTime, CortinaTime: cortinaTime, DurangoTime: durangoTime, - EUpgradeTime: mockable.MaxTime, + EUpgradeTime: eUpgradeTime, }} db := memdb.New() From a4b81e65e4757932d7add5bad19c5c275bff1fdf Mon Sep 17 00:00:00 2001 From: Alberto Benegiamo Date: Tue, 20 Feb 2024 09:22:54 +0100 Subject: [PATCH 06/18] fork switch to the avm --- vms/avm/block/executor/block_test.go | 127 +++++------------- vms/avm/block/executor/manager_test.go | 27 +--- vms/avm/environment_test.go | 45 ++++++- vms/avm/index_test.go | 26 +--- vms/avm/service_test.go | 63 +++------ vms/avm/state_test.go | 3 + vms/avm/vm_benchmark_test.go | 3 +- vms/avm/vm_regression_test.go | 10 +- vms/avm/vm_test.go | 40 ++---- vms/avm/wallet_service_test.go | 1 + vms/platformvm/block/builder/helpers_test.go | 2 +- vms/platformvm/block/executor/helpers_test.go | 2 +- vms/platformvm/txs/executor/helpers_test.go | 2 +- vms/platformvm/vm_test.go | 2 +- 14 files changed, 122 insertions(+), 231 deletions(-) diff --git a/vms/avm/block/executor/block_test.go b/vms/avm/block/executor/block_test.go index 59200e5d88c1..8b2e85a83789 100644 --- a/vms/avm/block/executor/block_test.go +++ b/vms/avm/block/executor/block_test.go @@ -30,6 +30,13 @@ import ( "github.com/ava-labs/avalanchego/vms/avm/txs/mempool" ) +var noFeesTestConfig = &config.Config{ + DurangoTime: time.Time{}, + EUpgradeTime: mockable.MaxTime, + TxFee: 0, + CreateAssetTxFee: 0, +} + func TestBlockVerify(t *testing.T) { type test struct { name string @@ -47,10 +54,7 @@ func TestBlockVerify(t *testing.T) { Block: mockBlock, manager: &manager{ backend: &executor.Backend{ - Config: &config.Config{ - DurangoTime: time.Time{}, - EUpgradeTime: mockable.MaxTime, - }, + Config: noFeesTestConfig, }, blkIDToState: map[ids.ID]*blockState{}, }, @@ -72,10 +76,7 @@ func TestBlockVerify(t *testing.T) { Block: mockBlock, manager: &manager{ backend: &executor.Backend{ - Config: &config.Config{ - DurangoTime: time.Time{}, - EUpgradeTime: mockable.MaxTime, - }, + Config: noFeesTestConfig, }, }, } @@ -97,10 +98,7 @@ func TestBlockVerify(t *testing.T) { Block: mockBlock, manager: &manager{ backend: &executor.Backend{ - Config: &config.Config{ - DurangoTime: time.Time{}, - EUpgradeTime: mockable.MaxTime, - }, + Config: noFeesTestConfig, }, clk: clk, }, @@ -120,10 +118,7 @@ func TestBlockVerify(t *testing.T) { Block: mockBlock, manager: &manager{ backend: &executor.Backend{ - Config: &config.Config{ - DurangoTime: time.Time{}, - EUpgradeTime: mockable.MaxTime, - }, + Config: noFeesTestConfig, }, blkIDToState: map[ids.ID]*blockState{}, clk: &mockable.Clock{}, @@ -152,10 +147,7 @@ func TestBlockVerify(t *testing.T) { Block: mockBlock, manager: &manager{ backend: &executor.Backend{ - Config: &config.Config{ - DurangoTime: time.Time{}, - EUpgradeTime: mockable.MaxTime, - }, + Config: noFeesTestConfig, }, mempool: mempool, metrics: metrics.NewMockMetrics(ctrl), @@ -190,10 +182,7 @@ func TestBlockVerify(t *testing.T) { Block: mockBlock, manager: &manager{ backend: &executor.Backend{ - Config: &config.Config{ - DurangoTime: time.Time{}, - EUpgradeTime: mockable.MaxTime, - }, + Config: noFeesTestConfig, }, state: mockState, blkIDToState: map[ids.ID]*blockState{}, @@ -232,10 +221,7 @@ func TestBlockVerify(t *testing.T) { Block: mockBlock, manager: &manager{ backend: &executor.Backend{ - Config: &config.Config{ - DurangoTime: time.Time{}, - EUpgradeTime: mockable.MaxTime, - }, + Config: noFeesTestConfig, }, state: mockState, blkIDToState: map[ids.ID]*blockState{}, @@ -277,10 +263,7 @@ func TestBlockVerify(t *testing.T) { Block: mockBlock, manager: &manager{ backend: &executor.Backend{ - Config: &config.Config{ - DurangoTime: time.Time{}, - EUpgradeTime: mockable.MaxTime, - }, + Config: noFeesTestConfig, }, blkIDToState: map[ids.ID]*blockState{ parentID: { @@ -330,10 +313,7 @@ func TestBlockVerify(t *testing.T) { Block: mockBlock, manager: &manager{ backend: &executor.Backend{ - Config: &config.Config{ - DurangoTime: time.Time{}, - EUpgradeTime: mockable.MaxTime, - }, + Config: noFeesTestConfig, }, mempool: mempool, metrics: metrics.NewMockMetrics(ctrl), @@ -388,10 +368,7 @@ func TestBlockVerify(t *testing.T) { mempool: mempool, metrics: metrics.NewMockMetrics(ctrl), backend: &executor.Backend{ - Config: &config.Config{ - DurangoTime: time.Time{}, - EUpgradeTime: mockable.MaxTime, - }, + Config: noFeesTestConfig, }, blkIDToState: map[ids.ID]*blockState{ parentID: { @@ -471,10 +448,7 @@ func TestBlockVerify(t *testing.T) { mempool: mempool, metrics: metrics.NewMockMetrics(ctrl), backend: &executor.Backend{ - Config: &config.Config{ - DurangoTime: time.Time{}, - EUpgradeTime: mockable.MaxTime, - }, + Config: noFeesTestConfig, }, blkIDToState: map[ids.ID]*blockState{ parentID: { @@ -534,10 +508,7 @@ func TestBlockVerify(t *testing.T) { Block: mockBlock, manager: &manager{ backend: &executor.Backend{ - Config: &config.Config{ - DurangoTime: time.Time{}, - EUpgradeTime: mockable.MaxTime, - }, + Config: noFeesTestConfig, }, blkIDToState: map[ids.ID]*blockState{ parentID: { @@ -591,10 +562,7 @@ func TestBlockVerify(t *testing.T) { mempool: mockMempool, metrics: metrics.NewMockMetrics(ctrl), backend: &executor.Backend{ - Config: &config.Config{ - DurangoTime: time.Time{}, - EUpgradeTime: mockable.MaxTime, - }, + Config: noFeesTestConfig, }, blkIDToState: map[ids.ID]*blockState{ parentID: { @@ -673,10 +641,7 @@ func TestBlockAccept(t *testing.T) { Ctx: &snow.Context{ Log: logging.NoLog{}, }, - Config: &config.Config{ - DurangoTime: time.Time{}, - EUpgradeTime: mockable.MaxTime, - }, + Config: noFeesTestConfig, }, blkIDToState: map[ids.ID]*blockState{}, }, @@ -711,10 +676,7 @@ func TestBlockAccept(t *testing.T) { Ctx: &snow.Context{ Log: logging.NoLog{}, }, - Config: &config.Config{ - DurangoTime: time.Time{}, - EUpgradeTime: mockable.MaxTime, - }, + Config: noFeesTestConfig, }, blkIDToState: map[ids.ID]*blockState{ blockID: { @@ -759,10 +721,7 @@ func TestBlockAccept(t *testing.T) { SharedMemory: mockSharedMemory, Log: logging.NoLog{}, }, - Config: &config.Config{ - DurangoTime: time.Time{}, - EUpgradeTime: mockable.MaxTime, - }, + Config: noFeesTestConfig, }, blkIDToState: map[ids.ID]*blockState{ blockID: { @@ -811,10 +770,7 @@ func TestBlockAccept(t *testing.T) { SharedMemory: mockSharedMemory, Log: logging.NoLog{}, }, - Config: &config.Config{ - DurangoTime: time.Time{}, - EUpgradeTime: mockable.MaxTime, - }, + Config: noFeesTestConfig, }, blkIDToState: map[ids.ID]*blockState{ blockID: { @@ -866,10 +822,7 @@ func TestBlockAccept(t *testing.T) { SharedMemory: mockSharedMemory, Log: logging.NoLog{}, }, - Config: &config.Config{ - DurangoTime: time.Time{}, - EUpgradeTime: mockable.MaxTime, - }, + Config: noFeesTestConfig, }, blkIDToState: map[ids.ID]*blockState{ blockID: { @@ -967,10 +920,7 @@ func TestBlockReject(t *testing.T) { metrics: metrics.NewMockMetrics(ctrl), backend: &executor.Backend{ Bootstrapped: true, - Config: &config.Config{ - DurangoTime: time.Time{}, - EUpgradeTime: mockable.MaxTime, - }, + Config: noFeesTestConfig, Ctx: &snow.Context{ Log: logging.NoLog{}, }, @@ -1032,10 +982,7 @@ func TestBlockReject(t *testing.T) { Ctx: &snow.Context{ Log: logging.NoLog{}, }, - Config: &config.Config{ - DurangoTime: time.Time{}, - EUpgradeTime: mockable.MaxTime, - }, + Config: noFeesTestConfig, }, state: mockState, blkIDToState: map[ids.ID]*blockState{ @@ -1086,10 +1033,7 @@ func TestBlockStatus(t *testing.T) { Block: mockBlock, manager: &manager{ backend: &executor.Backend{ - Config: &config.Config{ - DurangoTime: time.Time{}, - EUpgradeTime: mockable.MaxTime, - }, + Config: noFeesTestConfig, }, lastAccepted: blockID, }, @@ -1107,10 +1051,7 @@ func TestBlockStatus(t *testing.T) { Block: mockBlock, manager: &manager{ backend: &executor.Backend{ - Config: &config.Config{ - DurangoTime: time.Time{}, - EUpgradeTime: mockable.MaxTime, - }, + Config: noFeesTestConfig, }, blkIDToState: map[ids.ID]*blockState{ blockID: {}, @@ -1134,10 +1075,7 @@ func TestBlockStatus(t *testing.T) { Block: mockBlock, manager: &manager{ backend: &executor.Backend{ - Config: &config.Config{ - DurangoTime: time.Time{}, - EUpgradeTime: mockable.MaxTime, - }, + Config: noFeesTestConfig, }, blkIDToState: map[ids.ID]*blockState{}, state: mockState, @@ -1160,10 +1098,7 @@ func TestBlockStatus(t *testing.T) { Block: mockBlock, manager: &manager{ backend: &executor.Backend{ - Config: &config.Config{ - DurangoTime: time.Time{}, - EUpgradeTime: mockable.MaxTime, - }, + Config: noFeesTestConfig, }, blkIDToState: map[ids.ID]*blockState{}, state: mockState, diff --git a/vms/avm/block/executor/manager_test.go b/vms/avm/block/executor/manager_test.go index 517ced98eafd..adf1650cc780 100644 --- a/vms/avm/block/executor/manager_test.go +++ b/vms/avm/block/executor/manager_test.go @@ -13,9 +13,7 @@ import ( "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/utils/set" - "github.com/ava-labs/avalanchego/utils/timer/mockable" "github.com/ava-labs/avalanchego/vms/avm/block" - "github.com/ava-labs/avalanchego/vms/avm/config" "github.com/ava-labs/avalanchego/vms/avm/state" "github.com/ava-labs/avalanchego/vms/avm/txs" "github.com/ava-labs/avalanchego/vms/avm/txs/executor" @@ -126,10 +124,7 @@ func TestManagerVerifyTx(t *testing.T) { managerF: func(*gomock.Controller) *manager { return &manager{ backend: &executor.Backend{ - Config: &config.Config{ - DurangoTime: time.Time{}, - EUpgradeTime: mockable.MaxTime, - }, + Config: noFeesTestConfig, }, } }, @@ -148,10 +143,7 @@ func TestManagerVerifyTx(t *testing.T) { return &manager{ backend: &executor.Backend{ Bootstrapped: true, - Config: &config.Config{ - DurangoTime: time.Time{}, - EUpgradeTime: mockable.MaxTime, - }, + Config: noFeesTestConfig, }, } }, @@ -180,10 +172,7 @@ func TestManagerVerifyTx(t *testing.T) { return &manager{ backend: &executor.Backend{ Bootstrapped: true, - Config: &config.Config{ - DurangoTime: time.Time{}, - EUpgradeTime: mockable.MaxTime, - }, + Config: noFeesTestConfig, }, state: state, lastAccepted: lastAcceptedID, @@ -216,10 +205,7 @@ func TestManagerVerifyTx(t *testing.T) { return &manager{ backend: &executor.Backend{ Bootstrapped: true, - Config: &config.Config{ - DurangoTime: time.Time{}, - EUpgradeTime: mockable.MaxTime, - }, + Config: noFeesTestConfig, }, state: state, lastAccepted: lastAcceptedID, @@ -252,10 +238,7 @@ func TestManagerVerifyTx(t *testing.T) { return &manager{ backend: &executor.Backend{ Bootstrapped: true, - Config: &config.Config{ - DurangoTime: time.Time{}, - EUpgradeTime: mockable.MaxTime, - }, + Config: noFeesTestConfig, }, state: state, lastAccepted: lastAcceptedID, diff --git a/vms/avm/environment_test.go b/vms/avm/environment_test.go index b4f3e899a41d..a013ec4e0393 100644 --- a/vms/avm/environment_test.go +++ b/vms/avm/environment_test.go @@ -6,6 +6,7 @@ package avm import ( "context" "encoding/json" + "fmt" "math/rand" "testing" "time" @@ -40,7 +41,12 @@ import ( keystoreutils "github.com/ava-labs/avalanchego/vms/components/keystore" ) +type fork uint8 + const ( + durango fork = iota + eUpgrade + testTxFee uint64 = 1000 startBalance uint64 = 50000 @@ -70,6 +76,13 @@ var ( keys = secp256k1.TestKeys()[:3] // TODO: Remove [:3] addrs []ids.ShortID // addrs[i] corresponds to keys[i] + + noFeesTestConfig = &config.Config{ + DurangoTime: time.Time{}, + EUpgradeTime: mockable.MaxTime, + TxFee: 0, + CreateAssetTxFee: 0, + } ) func init() { @@ -86,6 +99,7 @@ type user struct { } type envConfig struct { + fork fork isCustomFeeAsset bool keystoreUsers []*user vmStaticConfig *config.Config @@ -146,12 +160,7 @@ func setup(tb testing.TB, c *envConfig) *environment { require.NoError(keystoreUser.Close()) } - vmStaticConfig := config.Config{ - TxFee: testTxFee, - CreateAssetTxFee: testTxFee, - DurangoTime: time.Time{}, - EUpgradeTime: mockable.MaxTime, - } + vmStaticConfig := staticConfig(tb, c.fork) if c.vmStaticConfig != nil { vmStaticConfig = *c.vmStaticConfig } @@ -224,6 +233,30 @@ func setup(tb testing.TB, c *envConfig) *environment { return env } +func staticConfig(tb testing.TB, f fork) config.Config { + var ( + durangoTime = mockable.MaxTime + eUpgradeTime = mockable.MaxTime + ) + + switch f { + case eUpgrade: + eUpgradeTime = time.Time{} + fallthrough + case durango: + durangoTime = time.Time{} + default: + require.FailNow(tb, fmt.Sprintf("unhandled fork %d", f)) + } + + return config.Config{ + TxFee: testTxFee, + CreateAssetTxFee: testTxFee, + DurangoTime: durangoTime, + EUpgradeTime: eUpgradeTime, + } +} + // Returns: // // 1. tx in genesis that creates asset diff --git a/vms/avm/index_test.go b/vms/avm/index_test.go index 8ed1887b6935..ef8a357935a4 100644 --- a/vms/avm/index_test.go +++ b/vms/avm/index_test.go @@ -6,7 +6,6 @@ package avm import ( "context" "testing" - "time" "github.com/prometheus/client_golang/prometheus" "github.com/stretchr/testify/require" @@ -20,8 +19,6 @@ import ( "github.com/ava-labs/avalanchego/utils/constants" "github.com/ava-labs/avalanchego/utils/crypto/secp256k1" "github.com/ava-labs/avalanchego/utils/logging" - "github.com/ava-labs/avalanchego/utils/timer/mockable" - "github.com/ava-labs/avalanchego/vms/avm/config" "github.com/ava-labs/avalanchego/vms/avm/txs" "github.com/ava-labs/avalanchego/vms/components/avax" "github.com/ava-labs/avalanchego/vms/components/index" @@ -31,12 +28,7 @@ import ( func TestIndexTransaction_Ordered(t *testing.T) { require := require.New(t) - env := setup(t, &envConfig{ - vmStaticConfig: &config.Config{ - DurangoTime: time.Time{}, - EUpgradeTime: mockable.MaxTime, - }, - }) + env := setup(t, &envConfig{vmStaticConfig: noFeesTestConfig}) defer func() { require.NoError(env.vm.Shutdown(context.Background())) env.vm.ctx.Lock.Unlock() @@ -78,12 +70,7 @@ func TestIndexTransaction_Ordered(t *testing.T) { func TestIndexTransaction_MultipleTransactions(t *testing.T) { require := require.New(t) - env := setup(t, &envConfig{ - vmStaticConfig: &config.Config{ - DurangoTime: time.Time{}, - EUpgradeTime: mockable.MaxTime, - }, - }) + env := setup(t, &envConfig{vmStaticConfig: noFeesTestConfig}) defer func() { require.NoError(env.vm.Shutdown(context.Background())) env.vm.ctx.Lock.Unlock() @@ -129,12 +116,7 @@ func TestIndexTransaction_MultipleTransactions(t *testing.T) { func TestIndexTransaction_MultipleAddresses(t *testing.T) { require := require.New(t) - env := setup(t, &envConfig{ - vmStaticConfig: &config.Config{ - DurangoTime: time.Time{}, - EUpgradeTime: mockable.MaxTime, - }, - }) + env := setup(t, &envConfig{vmStaticConfig: noFeesTestConfig}) defer func() { require.NoError(env.vm.Shutdown(context.Background())) env.vm.ctx.Lock.Unlock() @@ -175,7 +157,7 @@ func TestIndexTransaction_MultipleAddresses(t *testing.T) { func TestIndexer_Read(t *testing.T) { require := require.New(t) - env := setup(t, &envConfig{}) + env := setup(t, &envConfig{vmStaticConfig: noFeesTestConfig}) defer func() { require.NoError(env.vm.Shutdown(context.Background())) env.vm.ctx.Lock.Unlock() diff --git a/vms/avm/service_test.go b/vms/avm/service_test.go index 00ec1c93e0cd..c725658f839f 100644 --- a/vms/avm/service_test.go +++ b/vms/avm/service_test.go @@ -28,10 +28,8 @@ import ( "github.com/ava-labs/avalanchego/utils/formatting" "github.com/ava-labs/avalanchego/utils/formatting/address" "github.com/ava-labs/avalanchego/utils/logging" - "github.com/ava-labs/avalanchego/utils/timer/mockable" "github.com/ava-labs/avalanchego/vms/avm/block" "github.com/ava-labs/avalanchego/vms/avm/block/executor" - "github.com/ava-labs/avalanchego/vms/avm/config" "github.com/ava-labs/avalanchego/vms/avm/state" "github.com/ava-labs/avalanchego/vms/avm/txs" "github.com/ava-labs/avalanchego/vms/components/avax" @@ -47,7 +45,7 @@ import ( func TestServiceIssueTx(t *testing.T) { require := require.New(t) - env := setup(t, &envConfig{}) + env := setup(t, &envConfig{fork: durango}) env.vm.ctx.Lock.Unlock() defer func() { @@ -73,7 +71,7 @@ func TestServiceIssueTx(t *testing.T) { func TestServiceGetTxStatus(t *testing.T) { require := require.New(t) - env := setup(t, &envConfig{}) + env := setup(t, &envConfig{fork: durango}) env.vm.ctx.Lock.Unlock() defer func() { @@ -108,7 +106,7 @@ func TestServiceGetTxStatus(t *testing.T) { func TestServiceGetBalanceStrict(t *testing.T) { require := require.New(t) - env := setup(t, &envConfig{}) + env := setup(t, &envConfig{fork: durango}) defer func() { env.vm.ctx.Lock.Lock() require.NoError(env.vm.Shutdown(context.Background())) @@ -264,7 +262,7 @@ func TestServiceGetBalanceStrict(t *testing.T) { func TestServiceGetTxs(t *testing.T) { require := require.New(t) - env := setup(t, &envConfig{}) + env := setup(t, &envConfig{fork: durango}) var err error env.vm.addressTxsIndexer, err = index.NewIndexer(env.vm.db, env.vm.ctx.Log, "", prometheus.NewRegistry(), false) require.NoError(err) @@ -306,7 +304,7 @@ func TestServiceGetTxs(t *testing.T) { func TestServiceGetAllBalances(t *testing.T) { require := require.New(t) - env := setup(t, &envConfig{}) + env := setup(t, &envConfig{fork: durango}) defer func() { env.vm.ctx.Lock.Lock() require.NoError(env.vm.Shutdown(context.Background())) @@ -504,7 +502,7 @@ func TestServiceGetAllBalances(t *testing.T) { func TestServiceGetTx(t *testing.T) { require := require.New(t) - env := setup(t, &envConfig{}) + env := setup(t, &envConfig{fork: durango}) env.vm.ctx.Lock.Unlock() defer func() { @@ -532,7 +530,7 @@ func TestServiceGetTx(t *testing.T) { func TestServiceGetTxJSON_BaseTx(t *testing.T) { require := require.New(t) - env := setup(t, &envConfig{}) + env := setup(t, &envConfig{fork: durango}) env.vm.ctx.Lock.Unlock() defer func() { env.vm.ctx.Lock.Lock() @@ -615,7 +613,7 @@ func TestServiceGetTxJSON_BaseTx(t *testing.T) { func TestServiceGetTxJSON_ExportTx(t *testing.T) { require := require.New(t) - env := setup(t, &envConfig{}) + env := setup(t, &envConfig{fork: durango}) env.vm.ctx.Lock.Unlock() defer func() { env.vm.ctx.Lock.Lock() @@ -700,10 +698,7 @@ func TestServiceGetTxJSON_CreateAssetTx(t *testing.T) { require := require.New(t) env := setup(t, &envConfig{ - vmStaticConfig: &config.Config{ - DurangoTime: time.Time{}, - EUpgradeTime: mockable.MaxTime, - }, + vmStaticConfig: noFeesTestConfig, additionalFxs: []*common.Fx{{ ID: propertyfx.ID, Fx: &propertyfx.Fx{}, @@ -819,10 +814,7 @@ func TestServiceGetTxJSON_OperationTxWithNftxMintOp(t *testing.T) { require := require.New(t) env := setup(t, &envConfig{ - vmStaticConfig: &config.Config{ - DurangoTime: time.Time{}, - EUpgradeTime: mockable.MaxTime, - }, + vmStaticConfig: noFeesTestConfig, additionalFxs: []*common.Fx{{ ID: propertyfx.ID, Fx: &propertyfx.Fx{}, @@ -921,10 +913,7 @@ func TestServiceGetTxJSON_OperationTxWithMultipleNftxMintOp(t *testing.T) { require := require.New(t) env := setup(t, &envConfig{ - vmStaticConfig: &config.Config{ - DurangoTime: time.Time{}, - EUpgradeTime: mockable.MaxTime, - }, + vmStaticConfig: noFeesTestConfig, additionalFxs: []*common.Fx{{ ID: propertyfx.ID, Fx: &propertyfx.Fx{}, @@ -1062,10 +1051,7 @@ func TestServiceGetTxJSON_OperationTxWithSecpMintOp(t *testing.T) { require := require.New(t) env := setup(t, &envConfig{ - vmStaticConfig: &config.Config{ - DurangoTime: time.Time{}, - EUpgradeTime: mockable.MaxTime, - }, + vmStaticConfig: noFeesTestConfig, additionalFxs: []*common.Fx{{ ID: propertyfx.ID, Fx: &propertyfx.Fx{}, @@ -1168,10 +1154,7 @@ func TestServiceGetTxJSON_OperationTxWithMultipleSecpMintOp(t *testing.T) { require := require.New(t) env := setup(t, &envConfig{ - vmStaticConfig: &config.Config{ - DurangoTime: time.Time{}, - EUpgradeTime: mockable.MaxTime, - }, + vmStaticConfig: noFeesTestConfig, additionalFxs: []*common.Fx{{ ID: propertyfx.ID, Fx: &propertyfx.Fx{}, @@ -1317,10 +1300,7 @@ func TestServiceGetTxJSON_OperationTxWithPropertyFxMintOp(t *testing.T) { require := require.New(t) env := setup(t, &envConfig{ - vmStaticConfig: &config.Config{ - DurangoTime: time.Time{}, - EUpgradeTime: mockable.MaxTime, - }, + vmStaticConfig: noFeesTestConfig, additionalFxs: []*common.Fx{{ ID: propertyfx.ID, Fx: &propertyfx.Fx{}, @@ -1420,10 +1400,7 @@ func TestServiceGetTxJSON_OperationTxWithPropertyFxMintOpMultiple(t *testing.T) require := require.New(t) env := setup(t, &envConfig{ - vmStaticConfig: &config.Config{ - DurangoTime: time.Time{}, - EUpgradeTime: mockable.MaxTime, - }, + vmStaticConfig: noFeesTestConfig, additionalFxs: []*common.Fx{{ ID: propertyfx.ID, Fx: &propertyfx.Fx{}, @@ -1802,7 +1779,7 @@ func buildOperationTxWithOp(chainID ids.ID, op ...*txs.Operation) *txs.Tx { func TestServiceGetNilTx(t *testing.T) { require := require.New(t) - env := setup(t, &envConfig{}) + env := setup(t, &envConfig{fork: durango}) env.vm.ctx.Lock.Unlock() defer func() { @@ -1819,7 +1796,7 @@ func TestServiceGetNilTx(t *testing.T) { func TestServiceGetUnknownTx(t *testing.T) { require := require.New(t) - env := setup(t, &envConfig{}) + env := setup(t, &envConfig{fork: durango}) env.vm.ctx.Lock.Unlock() defer func() { @@ -1834,7 +1811,7 @@ func TestServiceGetUnknownTx(t *testing.T) { } func TestServiceGetUTXOs(t *testing.T) { - env := setup(t, &envConfig{}) + env := setup(t, &envConfig{fork: durango}) defer func() { env.vm.ctx.Lock.Lock() require.NoError(t, env.vm.Shutdown(context.Background())) @@ -2089,7 +2066,7 @@ func TestServiceGetUTXOs(t *testing.T) { func TestGetAssetDescription(t *testing.T) { require := require.New(t) - env := setup(t, &envConfig{}) + env := setup(t, &envConfig{fork: durango}) env.vm.ctx.Lock.Unlock() defer func() { @@ -2112,7 +2089,7 @@ func TestGetAssetDescription(t *testing.T) { func TestGetBalance(t *testing.T) { require := require.New(t) - env := setup(t, &envConfig{}) + env := setup(t, &envConfig{fork: durango}) env.vm.ctx.Lock.Unlock() defer func() { diff --git a/vms/avm/state_test.go b/vms/avm/state_test.go index b17604b2ba62..4496ed54d80a 100644 --- a/vms/avm/state_test.go +++ b/vms/avm/state_test.go @@ -24,6 +24,7 @@ func TestSetsAndGets(t *testing.T) { require := require.New(t) env := setup(t, &envConfig{ + fork: durango, additionalFxs: []*common.Fx{{ ID: ids.GenerateTestID(), Fx: &FxTest{ @@ -86,6 +87,7 @@ func TestSetsAndGets(t *testing.T) { func TestFundingNoAddresses(t *testing.T) { env := setup(t, &envConfig{ + fork: durango, additionalFxs: []*common.Fx{{ ID: ids.GenerateTestID(), Fx: &FxTest{ @@ -118,6 +120,7 @@ func TestFundingAddresses(t *testing.T) { require := require.New(t) env := setup(t, &envConfig{ + fork: durango, additionalFxs: []*common.Fx{{ ID: ids.GenerateTestID(), Fx: &FxTest{ diff --git a/vms/avm/vm_benchmark_test.go b/vms/avm/vm_benchmark_test.go index 713f809f7f5c..4ac65c86d7d6 100644 --- a/vms/avm/vm_benchmark_test.go +++ b/vms/avm/vm_benchmark_test.go @@ -23,6 +23,7 @@ func BenchmarkLoadUser(b *testing.B) { require := require.New(b) env := setup(b, &envConfig{ + fork: durango, keystoreUsers: []*user{{ username: username, password: password, @@ -67,7 +68,7 @@ func BenchmarkLoadUser(b *testing.B) { func GetAllUTXOsBenchmark(b *testing.B, utxoCount int) { require := require.New(b) - env := setup(b, &envConfig{}) + env := setup(b, &envConfig{fork: durango}) defer func() { require.NoError(env.vm.Shutdown(context.Background())) env.vm.ctx.Lock.Unlock() diff --git a/vms/avm/vm_regression_test.go b/vms/avm/vm_regression_test.go index 2412c4e9a70c..34d99dcc351e 100644 --- a/vms/avm/vm_regression_test.go +++ b/vms/avm/vm_regression_test.go @@ -6,15 +6,12 @@ package avm import ( "context" "testing" - "time" "github.com/stretchr/testify/require" "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/utils/constants" "github.com/ava-labs/avalanchego/utils/crypto/secp256k1" - "github.com/ava-labs/avalanchego/utils/timer/mockable" - "github.com/ava-labs/avalanchego/vms/avm/config" "github.com/ava-labs/avalanchego/vms/avm/txs" "github.com/ava-labs/avalanchego/vms/components/avax" "github.com/ava-labs/avalanchego/vms/components/verify" @@ -25,12 +22,7 @@ import ( func TestVerifyFxUsage(t *testing.T) { require := require.New(t) - env := setup(t, &envConfig{ - vmStaticConfig: &config.Config{ - DurangoTime: time.Time{}, - EUpgradeTime: mockable.MaxTime, - }, - }) + env := setup(t, &envConfig{vmStaticConfig: noFeesTestConfig}) env.vm.ctx.Lock.Unlock() defer func() { env.vm.ctx.Lock.Lock() diff --git a/vms/avm/vm_test.go b/vms/avm/vm_test.go index a01aefd349d0..527c2e98efe4 100644 --- a/vms/avm/vm_test.go +++ b/vms/avm/vm_test.go @@ -7,7 +7,6 @@ import ( "context" "math" "testing" - "time" "github.com/stretchr/testify/require" @@ -20,8 +19,6 @@ import ( "github.com/ava-labs/avalanchego/snow/snowtest" "github.com/ava-labs/avalanchego/utils/constants" "github.com/ava-labs/avalanchego/utils/crypto/secp256k1" - "github.com/ava-labs/avalanchego/utils/timer/mockable" - "github.com/ava-labs/avalanchego/vms/avm/config" "github.com/ava-labs/avalanchego/vms/avm/fxs" "github.com/ava-labs/avalanchego/vms/avm/txs" "github.com/ava-labs/avalanchego/vms/components/avax" @@ -117,7 +114,7 @@ func TestFxInitializationFailure(t *testing.T) { func TestIssueTx(t *testing.T) { require := require.New(t) - env := setup(t, &envConfig{}) + env := setup(t, &envConfig{fork: durango}) env.vm.ctx.Lock.Unlock() defer func() { env.vm.ctx.Lock.Lock() @@ -133,12 +130,7 @@ func TestIssueTx(t *testing.T) { func TestIssueNFT(t *testing.T) { require := require.New(t) - env := setup(t, &envConfig{ - vmStaticConfig: &config.Config{ - DurangoTime: time.Time{}, - EUpgradeTime: mockable.MaxTime, - }, - }) + env := setup(t, &envConfig{vmStaticConfig: noFeesTestConfig}) env.vm.ctx.Lock.Unlock() defer func() { env.vm.ctx.Lock.Lock() @@ -238,10 +230,7 @@ func TestIssueProperty(t *testing.T) { require := require.New(t) env := setup(t, &envConfig{ - vmStaticConfig: &config.Config{ - DurangoTime: time.Time{}, - EUpgradeTime: mockable.MaxTime, - }, + vmStaticConfig: noFeesTestConfig, additionalFxs: []*common.Fx{{ ID: propertyfx.ID, Fx: &propertyfx.Fx{}, @@ -334,6 +323,7 @@ func TestIssueTxWithFeeAsset(t *testing.T) { require := require.New(t) env := setup(t, &envConfig{ + fork: durango, isCustomFeeAsset: true, }) env.vm.ctx.Lock.Unlock() @@ -352,6 +342,7 @@ func TestIssueTxWithAnotherAsset(t *testing.T) { require := require.New(t) env := setup(t, &envConfig{ + fork: durango, isCustomFeeAsset: true, }) env.vm.ctx.Lock.Unlock() @@ -411,7 +402,7 @@ func TestIssueTxWithAnotherAsset(t *testing.T) { } func TestVMFormat(t *testing.T) { - env := setup(t, &envConfig{}) + env := setup(t, &envConfig{fork: durango}) defer func() { require.NoError(t, env.vm.Shutdown(context.Background())) env.vm.ctx.Lock.Unlock() @@ -440,6 +431,7 @@ func TestTxAcceptAfterParseTx(t *testing.T) { require := require.New(t) env := setup(t, &envConfig{ + fork: durango, notLinearized: true, }) defer func() { @@ -527,12 +519,7 @@ func TestTxAcceptAfterParseTx(t *testing.T) { func TestIssueImportTx(t *testing.T) { require := require.New(t) - env := setup(t, &envConfig{ - vmStaticConfig: &config.Config{ - DurangoTime: time.Time{}, - EUpgradeTime: mockable.MaxTime, - }, - }) + env := setup(t, &envConfig{vmStaticConfig: noFeesTestConfig}) defer func() { require.NoError(env.vm.Shutdown(context.Background())) env.vm.ctx.Lock.Unlock() @@ -631,11 +618,8 @@ func TestForceAcceptImportTx(t *testing.T) { require := require.New(t) env := setup(t, &envConfig{ - vmStaticConfig: &config.Config{ - DurangoTime: time.Time{}, - EUpgradeTime: mockable.MaxTime, - }, - notLinearized: true, + vmStaticConfig: noFeesTestConfig, + notLinearized: true, }) defer func() { require.NoError(env.vm.Shutdown(context.Background())) @@ -711,7 +695,7 @@ func TestImportTxNotState(t *testing.T) { func TestIssueExportTx(t *testing.T) { require := require.New(t) - env := setup(t, &envConfig{}) + env := setup(t, &envConfig{fork: durango}) defer func() { require.NoError(env.vm.Shutdown(context.Background())) env.vm.ctx.Lock.Unlock() @@ -786,7 +770,7 @@ func TestIssueExportTx(t *testing.T) { func TestClearForceAcceptedExportTx(t *testing.T) { require := require.New(t) - env := setup(t, &envConfig{}) + env := setup(t, &envConfig{fork: durango}) defer func() { require.NoError(env.vm.Shutdown(context.Background())) env.vm.ctx.Lock.Unlock() diff --git a/vms/avm/wallet_service_test.go b/vms/avm/wallet_service_test.go index 7ffdccdaaa20..a71403fa385d 100644 --- a/vms/avm/wallet_service_test.go +++ b/vms/avm/wallet_service_test.go @@ -18,6 +18,7 @@ func TestWalletService_SendMultiple(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { env := setup(t, &envConfig{ + fork: durango, isCustomFeeAsset: !tc.avaxAsset, keystoreUsers: []*user{{ username: username, diff --git a/vms/platformvm/block/builder/helpers_test.go b/vms/platformvm/block/builder/helpers_test.go index d75b5780e530..d07ab6140c05 100644 --- a/vms/platformvm/block/builder/helpers_test.go +++ b/vms/platformvm/block/builder/helpers_test.go @@ -334,7 +334,7 @@ func defaultConfig(t *testing.T, f fork) *config.Config { case apricotPhase3: apricotPhase3Time = defaultValidateEndTime default: - require.NoError(t, fmt.Errorf("unhandled fork %d", f)) + require.FailNow(t, fmt.Sprintf("unhandled fork %d", f)) } return &config.Config{ diff --git a/vms/platformvm/block/executor/helpers_test.go b/vms/platformvm/block/executor/helpers_test.go index a2cacb0f2771..26cd8bd566a0 100644 --- a/vms/platformvm/block/executor/helpers_test.go +++ b/vms/platformvm/block/executor/helpers_test.go @@ -358,7 +358,7 @@ func defaultConfig(t *testing.T, f fork) *config.Config { case apricotPhase3: apricotPhase3Time = defaultValidateEndTime default: - require.NoError(t, fmt.Errorf("unhandled fork %d", f)) + require.FailNow(t, fmt.Sprintf("unhandled fork %d", f)) } return &config.Config{ diff --git a/vms/platformvm/txs/executor/helpers_test.go b/vms/platformvm/txs/executor/helpers_test.go index ad8acaa859e3..907829f901c5 100644 --- a/vms/platformvm/txs/executor/helpers_test.go +++ b/vms/platformvm/txs/executor/helpers_test.go @@ -309,7 +309,7 @@ func defaultConfig(t *testing.T, f fork) *config.Config { case apricotPhase3: apricotPhase3Time = defaultValidateEndTime default: - require.NoError(t, fmt.Errorf("unhandled fork %d", f)) + require.FailNow(t, fmt.Sprintf("unhandled fork %d", f)) } return &config.Config{ diff --git a/vms/platformvm/vm_test.go b/vms/platformvm/vm_test.go index 7f0974365765..b1d6a73b6454 100644 --- a/vms/platformvm/vm_test.go +++ b/vms/platformvm/vm_test.go @@ -235,7 +235,7 @@ func defaultVM(t *testing.T, f fork) (*VM, database.Database, *mutableSharedMemo case apricotPhase3: apricotPhase3Time = latestForkTime default: - require.NoError(fmt.Errorf("unhandled fork %d", f)) + require.FailNow(fmt.Sprintf("unhandled fork %d", f)) } vm := &VM{Config: config.Config{ From 507636e6f192e1d9d9aa9aa0ae2e4b4d5ffcc8c6 Mon Sep 17 00:00:00 2001 From: Alberto Benegiamo Date: Thu, 29 Feb 2024 11:25:35 +0100 Subject: [PATCH 07/18] latestFork in avm --- vms/avm/environment_test.go | 2 ++ vms/avm/service_test.go | 26 +++++++++++++------------- vms/avm/state_test.go | 6 +++--- vms/avm/vm_benchmark_test.go | 4 ++-- vms/avm/vm_test.go | 14 +++++++------- vms/avm/wallet_service_test.go | 2 +- 6 files changed, 28 insertions(+), 26 deletions(-) diff --git a/vms/avm/environment_test.go b/vms/avm/environment_test.go index a6c8c3aed766..3500a9bc43f3 100644 --- a/vms/avm/environment_test.go +++ b/vms/avm/environment_test.go @@ -47,6 +47,8 @@ const ( durango fork = iota eUpgrade + latest = durango + testTxFee uint64 = 1000 startBalance uint64 = 50000 diff --git a/vms/avm/service_test.go b/vms/avm/service_test.go index c725658f839f..7fe845b21cbc 100644 --- a/vms/avm/service_test.go +++ b/vms/avm/service_test.go @@ -45,7 +45,7 @@ import ( func TestServiceIssueTx(t *testing.T) { require := require.New(t) - env := setup(t, &envConfig{fork: durango}) + env := setup(t, &envConfig{fork: latest}) env.vm.ctx.Lock.Unlock() defer func() { @@ -71,7 +71,7 @@ func TestServiceIssueTx(t *testing.T) { func TestServiceGetTxStatus(t *testing.T) { require := require.New(t) - env := setup(t, &envConfig{fork: durango}) + env := setup(t, &envConfig{fork: latest}) env.vm.ctx.Lock.Unlock() defer func() { @@ -106,7 +106,7 @@ func TestServiceGetTxStatus(t *testing.T) { func TestServiceGetBalanceStrict(t *testing.T) { require := require.New(t) - env := setup(t, &envConfig{fork: durango}) + env := setup(t, &envConfig{fork: latest}) defer func() { env.vm.ctx.Lock.Lock() require.NoError(env.vm.Shutdown(context.Background())) @@ -262,7 +262,7 @@ func TestServiceGetBalanceStrict(t *testing.T) { func TestServiceGetTxs(t *testing.T) { require := require.New(t) - env := setup(t, &envConfig{fork: durango}) + env := setup(t, &envConfig{fork: latest}) var err error env.vm.addressTxsIndexer, err = index.NewIndexer(env.vm.db, env.vm.ctx.Log, "", prometheus.NewRegistry(), false) require.NoError(err) @@ -304,7 +304,7 @@ func TestServiceGetTxs(t *testing.T) { func TestServiceGetAllBalances(t *testing.T) { require := require.New(t) - env := setup(t, &envConfig{fork: durango}) + env := setup(t, &envConfig{fork: latest}) defer func() { env.vm.ctx.Lock.Lock() require.NoError(env.vm.Shutdown(context.Background())) @@ -502,7 +502,7 @@ func TestServiceGetAllBalances(t *testing.T) { func TestServiceGetTx(t *testing.T) { require := require.New(t) - env := setup(t, &envConfig{fork: durango}) + env := setup(t, &envConfig{fork: latest}) env.vm.ctx.Lock.Unlock() defer func() { @@ -530,7 +530,7 @@ func TestServiceGetTx(t *testing.T) { func TestServiceGetTxJSON_BaseTx(t *testing.T) { require := require.New(t) - env := setup(t, &envConfig{fork: durango}) + env := setup(t, &envConfig{fork: latest}) env.vm.ctx.Lock.Unlock() defer func() { env.vm.ctx.Lock.Lock() @@ -613,7 +613,7 @@ func TestServiceGetTxJSON_BaseTx(t *testing.T) { func TestServiceGetTxJSON_ExportTx(t *testing.T) { require := require.New(t) - env := setup(t, &envConfig{fork: durango}) + env := setup(t, &envConfig{fork: latest}) env.vm.ctx.Lock.Unlock() defer func() { env.vm.ctx.Lock.Lock() @@ -1779,7 +1779,7 @@ func buildOperationTxWithOp(chainID ids.ID, op ...*txs.Operation) *txs.Tx { func TestServiceGetNilTx(t *testing.T) { require := require.New(t) - env := setup(t, &envConfig{fork: durango}) + env := setup(t, &envConfig{fork: latest}) env.vm.ctx.Lock.Unlock() defer func() { @@ -1796,7 +1796,7 @@ func TestServiceGetNilTx(t *testing.T) { func TestServiceGetUnknownTx(t *testing.T) { require := require.New(t) - env := setup(t, &envConfig{fork: durango}) + env := setup(t, &envConfig{fork: latest}) env.vm.ctx.Lock.Unlock() defer func() { @@ -1811,7 +1811,7 @@ func TestServiceGetUnknownTx(t *testing.T) { } func TestServiceGetUTXOs(t *testing.T) { - env := setup(t, &envConfig{fork: durango}) + env := setup(t, &envConfig{fork: latest}) defer func() { env.vm.ctx.Lock.Lock() require.NoError(t, env.vm.Shutdown(context.Background())) @@ -2066,7 +2066,7 @@ func TestServiceGetUTXOs(t *testing.T) { func TestGetAssetDescription(t *testing.T) { require := require.New(t) - env := setup(t, &envConfig{fork: durango}) + env := setup(t, &envConfig{fork: latest}) env.vm.ctx.Lock.Unlock() defer func() { @@ -2089,7 +2089,7 @@ func TestGetAssetDescription(t *testing.T) { func TestGetBalance(t *testing.T) { require := require.New(t) - env := setup(t, &envConfig{fork: durango}) + env := setup(t, &envConfig{fork: latest}) env.vm.ctx.Lock.Unlock() defer func() { diff --git a/vms/avm/state_test.go b/vms/avm/state_test.go index 4496ed54d80a..e71acf1251cb 100644 --- a/vms/avm/state_test.go +++ b/vms/avm/state_test.go @@ -24,7 +24,7 @@ func TestSetsAndGets(t *testing.T) { require := require.New(t) env := setup(t, &envConfig{ - fork: durango, + fork: latest, additionalFxs: []*common.Fx{{ ID: ids.GenerateTestID(), Fx: &FxTest{ @@ -87,7 +87,7 @@ func TestSetsAndGets(t *testing.T) { func TestFundingNoAddresses(t *testing.T) { env := setup(t, &envConfig{ - fork: durango, + fork: latest, additionalFxs: []*common.Fx{{ ID: ids.GenerateTestID(), Fx: &FxTest{ @@ -120,7 +120,7 @@ func TestFundingAddresses(t *testing.T) { require := require.New(t) env := setup(t, &envConfig{ - fork: durango, + fork: latest, additionalFxs: []*common.Fx{{ ID: ids.GenerateTestID(), Fx: &FxTest{ diff --git a/vms/avm/vm_benchmark_test.go b/vms/avm/vm_benchmark_test.go index 4ac65c86d7d6..5befa7062dda 100644 --- a/vms/avm/vm_benchmark_test.go +++ b/vms/avm/vm_benchmark_test.go @@ -23,7 +23,7 @@ func BenchmarkLoadUser(b *testing.B) { require := require.New(b) env := setup(b, &envConfig{ - fork: durango, + fork: latest, keystoreUsers: []*user{{ username: username, password: password, @@ -68,7 +68,7 @@ func BenchmarkLoadUser(b *testing.B) { func GetAllUTXOsBenchmark(b *testing.B, utxoCount int) { require := require.New(b) - env := setup(b, &envConfig{fork: durango}) + env := setup(b, &envConfig{fork: latest}) defer func() { require.NoError(env.vm.Shutdown(context.Background())) env.vm.ctx.Lock.Unlock() diff --git a/vms/avm/vm_test.go b/vms/avm/vm_test.go index 527c2e98efe4..270ab6b36ed2 100644 --- a/vms/avm/vm_test.go +++ b/vms/avm/vm_test.go @@ -114,7 +114,7 @@ func TestFxInitializationFailure(t *testing.T) { func TestIssueTx(t *testing.T) { require := require.New(t) - env := setup(t, &envConfig{fork: durango}) + env := setup(t, &envConfig{fork: latest}) env.vm.ctx.Lock.Unlock() defer func() { env.vm.ctx.Lock.Lock() @@ -323,7 +323,7 @@ func TestIssueTxWithFeeAsset(t *testing.T) { require := require.New(t) env := setup(t, &envConfig{ - fork: durango, + fork: latest, isCustomFeeAsset: true, }) env.vm.ctx.Lock.Unlock() @@ -342,7 +342,7 @@ func TestIssueTxWithAnotherAsset(t *testing.T) { require := require.New(t) env := setup(t, &envConfig{ - fork: durango, + fork: latest, isCustomFeeAsset: true, }) env.vm.ctx.Lock.Unlock() @@ -402,7 +402,7 @@ func TestIssueTxWithAnotherAsset(t *testing.T) { } func TestVMFormat(t *testing.T) { - env := setup(t, &envConfig{fork: durango}) + env := setup(t, &envConfig{fork: latest}) defer func() { require.NoError(t, env.vm.Shutdown(context.Background())) env.vm.ctx.Lock.Unlock() @@ -431,7 +431,7 @@ func TestTxAcceptAfterParseTx(t *testing.T) { require := require.New(t) env := setup(t, &envConfig{ - fork: durango, + fork: latest, notLinearized: true, }) defer func() { @@ -695,7 +695,7 @@ func TestImportTxNotState(t *testing.T) { func TestIssueExportTx(t *testing.T) { require := require.New(t) - env := setup(t, &envConfig{fork: durango}) + env := setup(t, &envConfig{fork: latest}) defer func() { require.NoError(env.vm.Shutdown(context.Background())) env.vm.ctx.Lock.Unlock() @@ -770,7 +770,7 @@ func TestIssueExportTx(t *testing.T) { func TestClearForceAcceptedExportTx(t *testing.T) { require := require.New(t) - env := setup(t, &envConfig{fork: durango}) + env := setup(t, &envConfig{fork: latest}) defer func() { require.NoError(env.vm.Shutdown(context.Background())) env.vm.ctx.Lock.Unlock() diff --git a/vms/avm/wallet_service_test.go b/vms/avm/wallet_service_test.go index a71403fa385d..eeb214fba9bd 100644 --- a/vms/avm/wallet_service_test.go +++ b/vms/avm/wallet_service_test.go @@ -18,7 +18,7 @@ func TestWalletService_SendMultiple(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { env := setup(t, &envConfig{ - fork: durango, + fork: latest, isCustomFeeAsset: !tc.avaxAsset, keystoreUsers: []*user{{ username: username, From 399dfc8afc16ad65c2719b6b47f031a00bae73be Mon Sep 17 00:00:00 2001 From: Alberto Benegiamo Date: Thu, 29 Feb 2024 11:46:24 +0100 Subject: [PATCH 08/18] default test config for a few unit tests --- .../executor/staker_tx_verification_test.go | 92 +++++--------- .../txs/executor/standard_tx_executor_test.go | 115 ++++++------------ 2 files changed, 64 insertions(+), 143 deletions(-) diff --git a/vms/platformvm/txs/executor/staker_tx_verification_test.go b/vms/platformvm/txs/executor/staker_tx_verification_test.go index a5f426a665ab..343b89327855 100644 --- a/vms/platformvm/txs/executor/staker_tx_verification_test.go +++ b/vms/platformvm/txs/executor/staker_tx_verification_test.go @@ -109,11 +109,8 @@ func TestVerifyAddPermissionlessValidatorTx(t *testing.T) { name: "fail syntactic verification", backendF: func(*gomock.Controller) *Backend { return &Backend{ - Ctx: ctx, - Config: &config.Config{ - DurangoTime: activeForkTime, // activate latest fork - EUpgradeTime: mockable.MaxTime, - }, + Ctx: ctx, + Config: defaultTestConfig(activeForkTime), } }, stateF: func(*gomock.Controller) state.Chain { @@ -131,11 +128,8 @@ func TestVerifyAddPermissionlessValidatorTx(t *testing.T) { name: "not bootstrapped", backendF: func(*gomock.Controller) *Backend { return &Backend{ - Ctx: ctx, - Config: &config.Config{ - DurangoTime: activeForkTime, // activate latest fork - EUpgradeTime: mockable.MaxTime, - }, + Ctx: ctx, + Config: defaultTestConfig(activeForkTime), Bootstrapped: &utils.Atomic[bool]{}, } }, @@ -186,11 +180,8 @@ func TestVerifyAddPermissionlessValidatorTx(t *testing.T) { bootstrapped := &utils.Atomic[bool]{} bootstrapped.Set(true) return &Backend{ - Ctx: ctx, - Config: &config.Config{ - DurangoTime: activeForkTime, // activate latest fork - EUpgradeTime: mockable.MaxTime, - }, + Ctx: ctx, + Config: defaultTestConfig(activeForkTime), Bootstrapped: bootstrapped, } }, @@ -216,11 +207,8 @@ func TestVerifyAddPermissionlessValidatorTx(t *testing.T) { bootstrapped := &utils.Atomic[bool]{} bootstrapped.Set(true) return &Backend{ - Ctx: ctx, - Config: &config.Config{ - DurangoTime: activeForkTime, // activate latest fork - EUpgradeTime: mockable.MaxTime, - }, + Ctx: ctx, + Config: defaultTestConfig(activeForkTime), Bootstrapped: bootstrapped, } }, @@ -246,11 +234,8 @@ func TestVerifyAddPermissionlessValidatorTx(t *testing.T) { bootstrapped := &utils.Atomic[bool]{} bootstrapped.Set(true) return &Backend{ - Ctx: ctx, - Config: &config.Config{ - DurangoTime: activeForkTime, // activate latest fork - EUpgradeTime: mockable.MaxTime, - }, + Ctx: ctx, + Config: defaultTestConfig(activeForkTime), Bootstrapped: bootstrapped, } }, @@ -277,11 +262,8 @@ func TestVerifyAddPermissionlessValidatorTx(t *testing.T) { bootstrapped := &utils.Atomic[bool]{} bootstrapped.Set(true) return &Backend{ - Ctx: ctx, - Config: &config.Config{ - DurangoTime: activeForkTime, // activate latest fork - EUpgradeTime: mockable.MaxTime, - }, + Ctx: ctx, + Config: defaultTestConfig(activeForkTime), Bootstrapped: bootstrapped, } }, @@ -311,11 +293,8 @@ func TestVerifyAddPermissionlessValidatorTx(t *testing.T) { bootstrapped := &utils.Atomic[bool]{} bootstrapped.Set(true) return &Backend{ - Ctx: ctx, - Config: &config.Config{ - DurangoTime: activeForkTime, // activate latest fork - EUpgradeTime: mockable.MaxTime, - }, + Ctx: ctx, + Config: defaultTestConfig(activeForkTime), Bootstrapped: bootstrapped, } }, @@ -345,11 +324,8 @@ func TestVerifyAddPermissionlessValidatorTx(t *testing.T) { bootstrapped := &utils.Atomic[bool]{} bootstrapped.Set(true) return &Backend{ - Ctx: ctx, - Config: &config.Config{ - DurangoTime: activeForkTime, // activate latest fork - EUpgradeTime: mockable.MaxTime, - }, + Ctx: ctx, + Config: defaultTestConfig(activeForkTime), Bootstrapped: bootstrapped, } }, @@ -381,11 +357,8 @@ func TestVerifyAddPermissionlessValidatorTx(t *testing.T) { bootstrapped := &utils.Atomic[bool]{} bootstrapped.Set(true) return &Backend{ - Ctx: ctx, - Config: &config.Config{ - DurangoTime: activeForkTime, // activate latest fork - EUpgradeTime: mockable.MaxTime, - }, + Ctx: ctx, + Config: defaultTestConfig(activeForkTime), Bootstrapped: bootstrapped, } }, @@ -411,11 +384,8 @@ func TestVerifyAddPermissionlessValidatorTx(t *testing.T) { bootstrapped := &utils.Atomic[bool]{} bootstrapped.Set(true) return &Backend{ - Ctx: ctx, - Config: &config.Config{ - DurangoTime: activeForkTime, // activate latest fork - EUpgradeTime: mockable.MaxTime, - }, + Ctx: ctx, + Config: defaultTestConfig(activeForkTime), Bootstrapped: bootstrapped, } }, @@ -456,13 +426,12 @@ func TestVerifyAddPermissionlessValidatorTx(t *testing.T) { gomock.Any(), ).Return(ErrFlowCheckFailed) + cfg := defaultTestConfig(activeForkTime) + cfg.AddSubnetValidatorFee = 1 + return &Backend{ - FlowChecker: flowChecker, - Config: &config.Config{ - AddSubnetValidatorFee: 1, - DurangoTime: activeForkTime, // activate latest fork, - EUpgradeTime: mockable.MaxTime, - }, + FlowChecker: flowChecker, + Config: cfg, Ctx: ctx, Bootstrapped: bootstrapped, } @@ -556,13 +525,12 @@ func TestVerifyAddPermissionlessValidatorTx(t *testing.T) { gomock.Any(), ).Return(nil) + cfg := defaultTestConfig(activeForkTime) + cfg.AddSubnetValidatorFee = 1 + return &Backend{ - FlowChecker: flowChecker, - Config: &config.Config{ - AddSubnetValidatorFee: 1, - DurangoTime: activeForkTime, // activate latest fork, - EUpgradeTime: mockable.MaxTime, - }, + FlowChecker: flowChecker, + Config: cfg, Ctx: ctx, Bootstrapped: bootstrapped, } diff --git a/vms/platformvm/txs/executor/standard_tx_executor_test.go b/vms/platformvm/txs/executor/standard_tx_executor_test.go index 55e6289f070f..17553e2f8018 100644 --- a/vms/platformvm/txs/executor/standard_tx_executor_test.go +++ b/vms/platformvm/txs/executor/standard_tx_executor_test.go @@ -1543,12 +1543,7 @@ func TestStandardExecutorRemoveSubnetValidatorTx(t *testing.T) { env.state.EXPECT().AddUTXO(gomock.Any()).Times(len(env.unsignedTx.Outs)) e := &StandardTxExecutor{ Backend: &Backend{ - Config: &config.Config{ - BanffTime: env.latestForkTime, - CortinaTime: env.latestForkTime, - DurangoTime: env.latestForkTime, - EUpgradeTime: mockable.MaxTime, - }, + Config: defaultTestConfig(env.latestForkTime), Bootstrapped: &utils.Atomic[bool]{}, Fx: env.fx, FlowChecker: env.flowChecker, @@ -1571,12 +1566,7 @@ func TestStandardExecutorRemoveSubnetValidatorTx(t *testing.T) { env.state = state.NewMockDiff(ctrl) e := &StandardTxExecutor{ Backend: &Backend{ - Config: &config.Config{ - BanffTime: env.latestForkTime, - CortinaTime: env.latestForkTime, - DurangoTime: env.latestForkTime, - EUpgradeTime: mockable.MaxTime, - }, + Config: defaultTestConfig(env.latestForkTime), Bootstrapped: &utils.Atomic[bool]{}, Fx: env.fx, FlowChecker: env.flowChecker, @@ -1600,12 +1590,7 @@ func TestStandardExecutorRemoveSubnetValidatorTx(t *testing.T) { env.state.EXPECT().GetPendingValidator(env.unsignedTx.Subnet, env.unsignedTx.NodeID).Return(nil, database.ErrNotFound) e := &StandardTxExecutor{ Backend: &Backend{ - Config: &config.Config{ - BanffTime: env.latestForkTime, - CortinaTime: env.latestForkTime, - DurangoTime: env.latestForkTime, - EUpgradeTime: mockable.MaxTime, - }, + Config: defaultTestConfig(env.latestForkTime), Bootstrapped: &utils.Atomic[bool]{}, Fx: env.fx, FlowChecker: env.flowChecker, @@ -1632,12 +1617,7 @@ func TestStandardExecutorRemoveSubnetValidatorTx(t *testing.T) { env.state.EXPECT().GetCurrentValidator(env.unsignedTx.Subnet, env.unsignedTx.NodeID).Return(&staker, nil).Times(1) e := &StandardTxExecutor{ Backend: &Backend{ - Config: &config.Config{ - BanffTime: env.latestForkTime, - CortinaTime: env.latestForkTime, - DurangoTime: env.latestForkTime, - EUpgradeTime: mockable.MaxTime, - }, + Config: defaultTestConfig(env.latestForkTime), Bootstrapped: &utils.Atomic[bool]{}, Fx: env.fx, FlowChecker: env.flowChecker, @@ -1662,12 +1642,7 @@ func TestStandardExecutorRemoveSubnetValidatorTx(t *testing.T) { env.state.EXPECT().GetCurrentValidator(env.unsignedTx.Subnet, env.unsignedTx.NodeID).Return(env.staker, nil) e := &StandardTxExecutor{ Backend: &Backend{ - Config: &config.Config{ - BanffTime: env.latestForkTime, - CortinaTime: env.latestForkTime, - DurangoTime: env.latestForkTime, - EUpgradeTime: mockable.MaxTime, - }, + Config: defaultTestConfig(env.latestForkTime), Bootstrapped: &utils.Atomic[bool]{}, Fx: env.fx, FlowChecker: env.flowChecker, @@ -1691,12 +1666,7 @@ func TestStandardExecutorRemoveSubnetValidatorTx(t *testing.T) { env.state.EXPECT().GetSubnetOwner(env.unsignedTx.Subnet).Return(nil, database.ErrNotFound) e := &StandardTxExecutor{ Backend: &Backend{ - Config: &config.Config{ - BanffTime: env.latestForkTime, - CortinaTime: env.latestForkTime, - DurangoTime: env.latestForkTime, - EUpgradeTime: mockable.MaxTime, - }, + Config: defaultTestConfig(env.latestForkTime), Bootstrapped: &utils.Atomic[bool]{}, Fx: env.fx, FlowChecker: env.flowChecker, @@ -1722,12 +1692,7 @@ func TestStandardExecutorRemoveSubnetValidatorTx(t *testing.T) { env.fx.EXPECT().VerifyPermission(gomock.Any(), env.unsignedTx.SubnetAuth, env.tx.Creds[len(env.tx.Creds)-1], subnetOwner).Return(errTest) e := &StandardTxExecutor{ Backend: &Backend{ - Config: &config.Config{ - BanffTime: env.latestForkTime, - CortinaTime: env.latestForkTime, - DurangoTime: env.latestForkTime, - EUpgradeTime: mockable.MaxTime, - }, + Config: defaultTestConfig(env.latestForkTime), Bootstrapped: &utils.Atomic[bool]{}, Fx: env.fx, FlowChecker: env.flowChecker, @@ -1756,12 +1721,7 @@ func TestStandardExecutorRemoveSubnetValidatorTx(t *testing.T) { ).Return(errTest) e := &StandardTxExecutor{ Backend: &Backend{ - Config: &config.Config{ - BanffTime: env.latestForkTime, - CortinaTime: env.latestForkTime, - DurangoTime: env.latestForkTime, - EUpgradeTime: mockable.MaxTime, - }, + Config: defaultTestConfig(env.latestForkTime), Bootstrapped: &utils.Atomic[bool]{}, Fx: env.fx, FlowChecker: env.flowChecker, @@ -1914,12 +1874,7 @@ func TestStandardExecutorTransformSubnetTx(t *testing.T) { env.state = state.NewMockDiff(ctrl) e := &StandardTxExecutor{ Backend: &Backend{ - Config: &config.Config{ - BanffTime: env.latestForkTime, - CortinaTime: env.latestForkTime, - DurangoTime: env.latestForkTime, - EUpgradeTime: mockable.MaxTime, - }, + Config: defaultTestConfig(env.latestForkTime), Bootstrapped: &utils.Atomic[bool]{}, Fx: env.fx, FlowChecker: env.flowChecker, @@ -1942,12 +1897,7 @@ func TestStandardExecutorTransformSubnetTx(t *testing.T) { env.state.EXPECT().GetTimestamp().Return(env.latestForkTime) e := &StandardTxExecutor{ Backend: &Backend{ - Config: &config.Config{ - BanffTime: env.latestForkTime, - CortinaTime: env.latestForkTime, - DurangoTime: env.latestForkTime, - EUpgradeTime: mockable.MaxTime, - }, + Config: defaultTestConfig(env.latestForkTime), Bootstrapped: &utils.Atomic[bool]{}, Fx: env.fx, FlowChecker: env.flowChecker, @@ -1969,15 +1919,13 @@ func TestStandardExecutorTransformSubnetTx(t *testing.T) { env.tx.Creds = nil env.state = state.NewMockDiff(ctrl) env.state.EXPECT().GetTimestamp().Return(env.latestForkTime) + + cfg := defaultTestConfig(env.latestForkTime) + cfg.MaxStakeDuration = math.MaxInt64 + e := &StandardTxExecutor{ Backend: &Backend{ - Config: &config.Config{ - BanffTime: env.latestForkTime, - CortinaTime: env.latestForkTime, - DurangoTime: env.latestForkTime, - MaxStakeDuration: math.MaxInt64, - EUpgradeTime: mockable.MaxTime, - }, + Config: cfg, Bootstrapped: &utils.Atomic[bool]{}, Fx: env.fx, FlowChecker: env.flowChecker, @@ -2004,15 +1952,13 @@ func TestStandardExecutorTransformSubnetTx(t *testing.T) { env.flowChecker.EXPECT().VerifySpend( gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), ).Return(ErrFlowCheckFailed) + + cfg := defaultTestConfig(env.latestForkTime) + cfg.MaxStakeDuration = math.MaxInt64 + e := &StandardTxExecutor{ Backend: &Backend{ - Config: &config.Config{ - BanffTime: env.latestForkTime, - CortinaTime: env.latestForkTime, - DurangoTime: env.latestForkTime, - EUpgradeTime: mockable.MaxTime, - MaxStakeDuration: math.MaxInt64, - }, + Config: cfg, Bootstrapped: &utils.Atomic[bool]{}, Fx: env.fx, FlowChecker: env.flowChecker, @@ -2044,15 +1990,13 @@ func TestStandardExecutorTransformSubnetTx(t *testing.T) { env.state.EXPECT().SetCurrentSupply(env.unsignedTx.Subnet, env.unsignedTx.InitialSupply) env.state.EXPECT().DeleteUTXO(gomock.Any()).Times(len(env.unsignedTx.Ins)) env.state.EXPECT().AddUTXO(gomock.Any()).Times(len(env.unsignedTx.Outs)) + + cfg := defaultTestConfig(env.latestForkTime) + cfg.MaxStakeDuration = math.MaxInt64 + e := &StandardTxExecutor{ Backend: &Backend{ - Config: &config.Config{ - BanffTime: env.latestForkTime, - CortinaTime: env.latestForkTime, - DurangoTime: env.latestForkTime, - EUpgradeTime: mockable.MaxTime, - MaxStakeDuration: math.MaxInt64, - }, + Config: cfg, Bootstrapped: &utils.Atomic[bool]{}, Fx: env.fx, FlowChecker: env.flowChecker, @@ -2078,3 +2022,12 @@ func TestStandardExecutorTransformSubnetTx(t *testing.T) { }) } } + +func defaultTestConfig(latestForkTime time.Time) *config.Config { + return &config.Config{ + BanffTime: latestForkTime, + CortinaTime: latestForkTime, + DurangoTime: latestForkTime, + EUpgradeTime: mockable.MaxTime, + } +} From 089af5e04c3c5379e74ee6121c84d586b6bef7e1 Mon Sep 17 00:00:00 2001 From: Alberto Benegiamo Date: Thu, 29 Feb 2024 12:55:15 +0100 Subject: [PATCH 09/18] come more unit tests helpers --- vms/avm/block/executor/block_test.go | 155 +++++++------------------ vms/avm/block/executor/manager_test.go | 25 +--- 2 files changed, 50 insertions(+), 130 deletions(-) diff --git a/vms/avm/block/executor/block_test.go b/vms/avm/block/executor/block_test.go index 8b2e85a83789..e8b08ab0346a 100644 --- a/vms/avm/block/executor/block_test.go +++ b/vms/avm/block/executor/block_test.go @@ -30,13 +30,6 @@ import ( "github.com/ava-labs/avalanchego/vms/avm/txs/mempool" ) -var noFeesTestConfig = &config.Config{ - DurangoTime: time.Time{}, - EUpgradeTime: mockable.MaxTime, - TxFee: 0, - CreateAssetTxFee: 0, -} - func TestBlockVerify(t *testing.T) { type test struct { name string @@ -53,9 +46,7 @@ func TestBlockVerify(t *testing.T) { b := &Block{ Block: mockBlock, manager: &manager{ - backend: &executor.Backend{ - Config: noFeesTestConfig, - }, + backend: defaultTestBackend(false, nil), blkIDToState: map[ids.ID]*blockState{}, }, } @@ -75,9 +66,7 @@ func TestBlockVerify(t *testing.T) { return &Block{ Block: mockBlock, manager: &manager{ - backend: &executor.Backend{ - Config: noFeesTestConfig, - }, + backend: defaultTestBackend(false, nil), }, } }, @@ -97,10 +86,8 @@ func TestBlockVerify(t *testing.T) { return &Block{ Block: mockBlock, manager: &manager{ - backend: &executor.Backend{ - Config: noFeesTestConfig, - }, - clk: clk, + backend: defaultTestBackend(false, nil), + clk: clk, }, } }, @@ -117,9 +104,7 @@ func TestBlockVerify(t *testing.T) { return &Block{ Block: mockBlock, manager: &manager{ - backend: &executor.Backend{ - Config: noFeesTestConfig, - }, + backend: defaultTestBackend(false, nil), blkIDToState: map[ids.ID]*blockState{}, clk: &mockable.Clock{}, }, @@ -146,9 +131,7 @@ func TestBlockVerify(t *testing.T) { return &Block{ Block: mockBlock, manager: &manager{ - backend: &executor.Backend{ - Config: noFeesTestConfig, - }, + backend: defaultTestBackend(false, nil), mempool: mempool, metrics: metrics.NewMockMetrics(ctrl), blkIDToState: map[ids.ID]*blockState{}, @@ -181,9 +164,7 @@ func TestBlockVerify(t *testing.T) { return &Block{ Block: mockBlock, manager: &manager{ - backend: &executor.Backend{ - Config: noFeesTestConfig, - }, + backend: defaultTestBackend(false, nil), state: mockState, blkIDToState: map[ids.ID]*blockState{}, clk: &mockable.Clock{}, @@ -220,9 +201,7 @@ func TestBlockVerify(t *testing.T) { return &Block{ Block: mockBlock, manager: &manager{ - backend: &executor.Backend{ - Config: noFeesTestConfig, - }, + backend: defaultTestBackend(false, nil), state: mockState, blkIDToState: map[ids.ID]*blockState{}, clk: &mockable.Clock{}, @@ -262,9 +241,7 @@ func TestBlockVerify(t *testing.T) { return &Block{ Block: mockBlock, manager: &manager{ - backend: &executor.Backend{ - Config: noFeesTestConfig, - }, + backend: defaultTestBackend(false, nil), blkIDToState: map[ids.ID]*blockState{ parentID: { onAcceptState: mockParentState, @@ -312,9 +289,7 @@ func TestBlockVerify(t *testing.T) { return &Block{ Block: mockBlock, manager: &manager{ - backend: &executor.Backend{ - Config: noFeesTestConfig, - }, + backend: defaultTestBackend(false, nil), mempool: mempool, metrics: metrics.NewMockMetrics(ctrl), blkIDToState: map[ids.ID]*blockState{ @@ -367,9 +342,7 @@ func TestBlockVerify(t *testing.T) { manager: &manager{ mempool: mempool, metrics: metrics.NewMockMetrics(ctrl), - backend: &executor.Backend{ - Config: noFeesTestConfig, - }, + backend: defaultTestBackend(false, nil), blkIDToState: map[ids.ID]*blockState{ parentID: { onAcceptState: mockParentState, @@ -447,9 +420,7 @@ func TestBlockVerify(t *testing.T) { manager: &manager{ mempool: mempool, metrics: metrics.NewMockMetrics(ctrl), - backend: &executor.Backend{ - Config: noFeesTestConfig, - }, + backend: defaultTestBackend(false, nil), blkIDToState: map[ids.ID]*blockState{ parentID: { onAcceptState: mockParentState, @@ -507,9 +478,7 @@ func TestBlockVerify(t *testing.T) { return &Block{ Block: mockBlock, manager: &manager{ - backend: &executor.Backend{ - Config: noFeesTestConfig, - }, + backend: defaultTestBackend(false, nil), blkIDToState: map[ids.ID]*blockState{ parentID: { onAcceptState: mockParentState, @@ -561,9 +530,7 @@ func TestBlockVerify(t *testing.T) { manager: &manager{ mempool: mockMempool, metrics: metrics.NewMockMetrics(ctrl), - backend: &executor.Backend{ - Config: noFeesTestConfig, - }, + backend: defaultTestBackend(false, nil), blkIDToState: map[ids.ID]*blockState{ parentID: { onAcceptState: mockParentState, @@ -635,14 +602,9 @@ func TestBlockAccept(t *testing.T) { return &Block{ Block: mockBlock, manager: &manager{ - mempool: mempool, - metrics: metrics.NewMockMetrics(ctrl), - backend: &executor.Backend{ - Ctx: &snow.Context{ - Log: logging.NoLog{}, - }, - Config: noFeesTestConfig, - }, + mempool: mempool, + metrics: metrics.NewMockMetrics(ctrl), + backend: defaultTestBackend(false, nil), blkIDToState: map[ids.ID]*blockState{}, }, } @@ -672,12 +634,7 @@ func TestBlockAccept(t *testing.T) { manager: &manager{ state: mockManagerState, mempool: mempool, - backend: &executor.Backend{ - Ctx: &snow.Context{ - Log: logging.NoLog{}, - }, - Config: noFeesTestConfig, - }, + backend: defaultTestBackend(false, nil), blkIDToState: map[ids.ID]*blockState{ blockID: { onAcceptState: mockOnAcceptState, @@ -716,13 +673,7 @@ func TestBlockAccept(t *testing.T) { manager: &manager{ state: mockManagerState, mempool: mempool, - backend: &executor.Backend{ - Ctx: &snow.Context{ - SharedMemory: mockSharedMemory, - Log: logging.NoLog{}, - }, - Config: noFeesTestConfig, - }, + backend: defaultTestBackend(false, mockSharedMemory), blkIDToState: map[ids.ID]*blockState{ blockID: { onAcceptState: mockOnAcceptState, @@ -765,13 +716,7 @@ func TestBlockAccept(t *testing.T) { state: mockManagerState, mempool: mempool, metrics: metrics, - backend: &executor.Backend{ - Ctx: &snow.Context{ - SharedMemory: mockSharedMemory, - Log: logging.NoLog{}, - }, - Config: noFeesTestConfig, - }, + backend: defaultTestBackend(false, mockSharedMemory), blkIDToState: map[ids.ID]*blockState{ blockID: { onAcceptState: mockOnAcceptState, @@ -817,13 +762,7 @@ func TestBlockAccept(t *testing.T) { state: mockManagerState, mempool: mempool, metrics: metrics, - backend: &executor.Backend{ - Ctx: &snow.Context{ - SharedMemory: mockSharedMemory, - Log: logging.NoLog{}, - }, - Config: noFeesTestConfig, - }, + backend: defaultTestBackend(false, mockSharedMemory), blkIDToState: map[ids.ID]*blockState{ blockID: { onAcceptState: mockOnAcceptState, @@ -918,14 +857,8 @@ func TestBlockReject(t *testing.T) { lastAccepted: lastAcceptedID, mempool: mempool, metrics: metrics.NewMockMetrics(ctrl), - backend: &executor.Backend{ - Bootstrapped: true, - Config: noFeesTestConfig, - Ctx: &snow.Context{ - Log: logging.NoLog{}, - }, - }, - state: mockState, + backend: defaultTestBackend(true, nil), + state: mockState, blkIDToState: map[ids.ID]*blockState{ blockID: {}, }, @@ -977,14 +910,8 @@ func TestBlockReject(t *testing.T) { lastAccepted: lastAcceptedID, mempool: mempool, metrics: metrics.NewMockMetrics(ctrl), - backend: &executor.Backend{ - Bootstrapped: true, - Ctx: &snow.Context{ - Log: logging.NoLog{}, - }, - Config: noFeesTestConfig, - }, - state: mockState, + backend: defaultTestBackend(true, nil), + state: mockState, blkIDToState: map[ids.ID]*blockState{ blockID: {}, }, @@ -1032,9 +959,7 @@ func TestBlockStatus(t *testing.T) { return &Block{ Block: mockBlock, manager: &manager{ - backend: &executor.Backend{ - Config: noFeesTestConfig, - }, + backend: defaultTestBackend(false, nil), lastAccepted: blockID, }, } @@ -1050,9 +975,7 @@ func TestBlockStatus(t *testing.T) { return &Block{ Block: mockBlock, manager: &manager{ - backend: &executor.Backend{ - Config: noFeesTestConfig, - }, + backend: defaultTestBackend(false, nil), blkIDToState: map[ids.ID]*blockState{ blockID: {}, }, @@ -1074,9 +997,7 @@ func TestBlockStatus(t *testing.T) { return &Block{ Block: mockBlock, manager: &manager{ - backend: &executor.Backend{ - Config: noFeesTestConfig, - }, + backend: defaultTestBackend(false, nil), blkIDToState: map[ids.ID]*blockState{}, state: mockState, }, @@ -1097,9 +1018,7 @@ func TestBlockStatus(t *testing.T) { return &Block{ Block: mockBlock, manager: &manager{ - backend: &executor.Backend{ - Config: noFeesTestConfig, - }, + backend: defaultTestBackend(false, nil), blkIDToState: map[ids.ID]*blockState{}, state: mockState, }, @@ -1118,3 +1037,19 @@ func TestBlockStatus(t *testing.T) { }) } } + +func defaultTestBackend(bootstrapped bool, sharedMemory atomic.SharedMemory) *executor.Backend { + return &executor.Backend{ + Bootstrapped: bootstrapped, + Ctx: &snow.Context{ + SharedMemory: sharedMemory, + Log: logging.NoLog{}, + }, + Config: &config.Config{ + DurangoTime: time.Time{}, + EUpgradeTime: mockable.MaxTime, + TxFee: 0, + CreateAssetTxFee: 0, + }, + } +} diff --git a/vms/avm/block/executor/manager_test.go b/vms/avm/block/executor/manager_test.go index adf1650cc780..14484fcbb559 100644 --- a/vms/avm/block/executor/manager_test.go +++ b/vms/avm/block/executor/manager_test.go @@ -16,7 +16,6 @@ import ( "github.com/ava-labs/avalanchego/vms/avm/block" "github.com/ava-labs/avalanchego/vms/avm/state" "github.com/ava-labs/avalanchego/vms/avm/txs" - "github.com/ava-labs/avalanchego/vms/avm/txs/executor" ) var ( @@ -123,9 +122,7 @@ func TestManagerVerifyTx(t *testing.T) { }, managerF: func(*gomock.Controller) *manager { return &manager{ - backend: &executor.Backend{ - Config: noFeesTestConfig, - }, + backend: defaultTestBackend(false, nil), } }, expectedErr: ErrChainNotSynced, @@ -141,10 +138,7 @@ func TestManagerVerifyTx(t *testing.T) { }, managerF: func(*gomock.Controller) *manager { return &manager{ - backend: &executor.Backend{ - Bootstrapped: true, - Config: noFeesTestConfig, - }, + backend: defaultTestBackend(true, nil), } }, expectedErr: errTestSyntacticVerifyFail, @@ -170,10 +164,7 @@ func TestManagerVerifyTx(t *testing.T) { state.EXPECT().GetTimestamp().Return(time.Time{}) return &manager{ - backend: &executor.Backend{ - Bootstrapped: true, - Config: noFeesTestConfig, - }, + backend: defaultTestBackend(true, nil), state: state, lastAccepted: lastAcceptedID, } @@ -203,10 +194,7 @@ func TestManagerVerifyTx(t *testing.T) { state.EXPECT().GetTimestamp().Return(time.Time{}) return &manager{ - backend: &executor.Backend{ - Bootstrapped: true, - Config: noFeesTestConfig, - }, + backend: defaultTestBackend(true, nil), state: state, lastAccepted: lastAcceptedID, } @@ -236,10 +224,7 @@ func TestManagerVerifyTx(t *testing.T) { state.EXPECT().GetTimestamp().Return(time.Time{}) return &manager{ - backend: &executor.Backend{ - Bootstrapped: true, - Config: noFeesTestConfig, - }, + backend: defaultTestBackend(true, nil), state: state, lastAccepted: lastAcceptedID, } From dca34a5297c904c4859ed563c5863b1496676bc1 Mon Sep 17 00:00:00 2001 From: Alberto Benegiamo Date: Mon, 11 Mar 2024 10:56:25 +0100 Subject: [PATCH 10/18] fixed merge --- codec/reflectcodec/type_codec.go | 4 ---- codec/test_codec.go | 3 ++- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/codec/reflectcodec/type_codec.go b/codec/reflectcodec/type_codec.go index c3da55c22a87..486ab006f3f2 100644 --- a/codec/reflectcodec/type_codec.go +++ b/codec/reflectcodec/type_codec.go @@ -157,10 +157,6 @@ func (c *genericCodec) size( return 0, false, err } - if size == 0 { - return 0, false, fmt.Errorf("can't marshal slice of zero length values: %w", codec.ErrMarshalZeroLength) - } - // For fixed-size types we manually calculate lengths rather than // processing each element separately to improve performance. if constSize { diff --git a/codec/test_codec.go b/codec/test_codec.go index 809cd84f21c7..37127f0de9bc 100644 --- a/codec/test_codec.go +++ b/codec/test_codec.go @@ -864,8 +864,9 @@ func TestSliceWithEmptySerializationError(codec GeneralCodec, t testing.TB) { _, err := manager.Marshal(0, val) require.ErrorIs(err, ErrMarshalZeroLength) + // we cannot marshal/unmarshal an empty slice, but we can ask its size _, err = manager.Size(0, val) - require.ErrorIs(err, ErrMarshalZeroLength) + require.NoError(err) b := []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x01} // codec version (0x00, 0x00) then (0x00, 0x00, 0x00, 0x01) for numElts From cd989f37d630472cb2b5fd98b8c1125c35598685 Mon Sep 17 00:00:00 2001 From: Alberto Benegiamo Date: Mon, 11 Mar 2024 15:18:37 +0100 Subject: [PATCH 11/18] nits from code reviews --- vms/avm/config/config.go | 2 +- vms/platformvm/config/config.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/vms/avm/config/config.go b/vms/avm/config/config.go index 42e37b678a01..fb376fb77a30 100644 --- a/vms/avm/config/config.go +++ b/vms/avm/config/config.go @@ -20,6 +20,6 @@ type Config struct { EUpgradeTime time.Time } -func (c *Config) IsEUpgradeActivated(timestamp time.Time) bool { +func (c *Config) IsEUActivated(timestamp time.Time) bool { return !timestamp.Before(c.EUpgradeTime) } diff --git a/vms/platformvm/config/config.go b/vms/platformvm/config/config.go index 0ac37f81f08e..0c5fcf15a475 100644 --- a/vms/platformvm/config/config.go +++ b/vms/platformvm/config/config.go @@ -140,7 +140,7 @@ func (c *Config) IsDurangoActivated(timestamp time.Time) bool { return !timestamp.Before(c.DurangoTime) } -func (c *Config) IsEForkActivated(timestamp time.Time) bool { +func (c *Config) IsEActivated(timestamp time.Time) bool { return !timestamp.Before(c.EUpgradeTime) } From 32da156991d9c6fd5320cb697a2fa81b1b25c7ec Mon Sep 17 00:00:00 2001 From: Alberto Benegiamo Date: Mon, 11 Mar 2024 15:34:13 +0100 Subject: [PATCH 12/18] some more nits from code reviews --- .../executor/staker_tx_verification_test.go | 24 +++---- .../txs/executor/standard_tx_executor_test.go | 70 ++++++++++++++----- 2 files changed, 64 insertions(+), 30 deletions(-) diff --git a/vms/platformvm/txs/executor/staker_tx_verification_test.go b/vms/platformvm/txs/executor/staker_tx_verification_test.go index a4c65395ba07..f9081fdf5ded 100644 --- a/vms/platformvm/txs/executor/staker_tx_verification_test.go +++ b/vms/platformvm/txs/executor/staker_tx_verification_test.go @@ -110,7 +110,7 @@ func TestVerifyAddPermissionlessValidatorTx(t *testing.T) { backendF: func(*gomock.Controller) *Backend { return &Backend{ Ctx: ctx, - Config: defaultTestConfig(activeForkTime), + Config: defaultTestConfig(t, durango, activeForkTime), } }, stateF: func(*gomock.Controller) state.Chain { @@ -129,7 +129,7 @@ func TestVerifyAddPermissionlessValidatorTx(t *testing.T) { backendF: func(*gomock.Controller) *Backend { return &Backend{ Ctx: ctx, - Config: defaultTestConfig(activeForkTime), + Config: defaultTestConfig(t, durango, activeForkTime), Bootstrapped: &utils.Atomic[bool]{}, } }, @@ -181,7 +181,7 @@ func TestVerifyAddPermissionlessValidatorTx(t *testing.T) { bootstrapped.Set(true) return &Backend{ Ctx: ctx, - Config: defaultTestConfig(activeForkTime), + Config: defaultTestConfig(t, durango, activeForkTime), Bootstrapped: bootstrapped, } }, @@ -208,7 +208,7 @@ func TestVerifyAddPermissionlessValidatorTx(t *testing.T) { bootstrapped.Set(true) return &Backend{ Ctx: ctx, - Config: defaultTestConfig(activeForkTime), + Config: defaultTestConfig(t, durango, activeForkTime), Bootstrapped: bootstrapped, } }, @@ -235,7 +235,7 @@ func TestVerifyAddPermissionlessValidatorTx(t *testing.T) { bootstrapped.Set(true) return &Backend{ Ctx: ctx, - Config: defaultTestConfig(activeForkTime), + Config: defaultTestConfig(t, durango, activeForkTime), Bootstrapped: bootstrapped, } }, @@ -263,7 +263,7 @@ func TestVerifyAddPermissionlessValidatorTx(t *testing.T) { bootstrapped.Set(true) return &Backend{ Ctx: ctx, - Config: defaultTestConfig(activeForkTime), + Config: defaultTestConfig(t, durango, activeForkTime), Bootstrapped: bootstrapped, } }, @@ -294,7 +294,7 @@ func TestVerifyAddPermissionlessValidatorTx(t *testing.T) { bootstrapped.Set(true) return &Backend{ Ctx: ctx, - Config: defaultTestConfig(activeForkTime), + Config: defaultTestConfig(t, durango, activeForkTime), Bootstrapped: bootstrapped, } }, @@ -325,7 +325,7 @@ func TestVerifyAddPermissionlessValidatorTx(t *testing.T) { bootstrapped.Set(true) return &Backend{ Ctx: ctx, - Config: defaultTestConfig(activeForkTime), + Config: defaultTestConfig(t, durango, activeForkTime), Bootstrapped: bootstrapped, } }, @@ -358,7 +358,7 @@ func TestVerifyAddPermissionlessValidatorTx(t *testing.T) { bootstrapped.Set(true) return &Backend{ Ctx: ctx, - Config: defaultTestConfig(activeForkTime), + Config: defaultTestConfig(t, durango, activeForkTime), Bootstrapped: bootstrapped, } }, @@ -385,7 +385,7 @@ func TestVerifyAddPermissionlessValidatorTx(t *testing.T) { bootstrapped.Set(true) return &Backend{ Ctx: ctx, - Config: defaultTestConfig(activeForkTime), + Config: defaultTestConfig(t, durango, activeForkTime), Bootstrapped: bootstrapped, } }, @@ -426,7 +426,7 @@ func TestVerifyAddPermissionlessValidatorTx(t *testing.T) { gomock.Any(), ).Return(ErrFlowCheckFailed) - cfg := defaultTestConfig(activeForkTime) + cfg := defaultTestConfig(t, durango, activeForkTime) cfg.AddSubnetValidatorFee = 1 return &Backend{ @@ -472,7 +472,7 @@ func TestVerifyAddPermissionlessValidatorTx(t *testing.T) { gomock.Any(), ).Return(nil) - cfg := defaultTestConfig(activeForkTime) + cfg := defaultTestConfig(t, durango, activeForkTime) cfg.AddSubnetValidatorFee = 1 return &Backend{ diff --git a/vms/platformvm/txs/executor/standard_tx_executor_test.go b/vms/platformvm/txs/executor/standard_tx_executor_test.go index 9fca25a9a289..6e58a4bcfda8 100644 --- a/vms/platformvm/txs/executor/standard_tx_executor_test.go +++ b/vms/platformvm/txs/executor/standard_tx_executor_test.go @@ -5,6 +5,7 @@ package executor import ( "errors" + "fmt" "math" "testing" "time" @@ -1503,7 +1504,7 @@ func TestStandardExecutorRemoveSubnetValidatorTx(t *testing.T) { env.state.EXPECT().AddUTXO(gomock.Any()).Times(len(env.unsignedTx.Outs)) e := &StandardTxExecutor{ Backend: &Backend{ - Config: defaultTestConfig(env.latestForkTime), + Config: defaultTestConfig(t, durango, env.latestForkTime), Bootstrapped: &utils.Atomic[bool]{}, Fx: env.fx, FlowChecker: env.flowChecker, @@ -1526,7 +1527,7 @@ func TestStandardExecutorRemoveSubnetValidatorTx(t *testing.T) { env.state = state.NewMockDiff(ctrl) e := &StandardTxExecutor{ Backend: &Backend{ - Config: defaultTestConfig(env.latestForkTime), + Config: defaultTestConfig(t, durango, env.latestForkTime), Bootstrapped: &utils.Atomic[bool]{}, Fx: env.fx, FlowChecker: env.flowChecker, @@ -1550,7 +1551,7 @@ func TestStandardExecutorRemoveSubnetValidatorTx(t *testing.T) { env.state.EXPECT().GetPendingValidator(env.unsignedTx.Subnet, env.unsignedTx.NodeID).Return(nil, database.ErrNotFound) e := &StandardTxExecutor{ Backend: &Backend{ - Config: defaultTestConfig(env.latestForkTime), + Config: defaultTestConfig(t, durango, env.latestForkTime), Bootstrapped: &utils.Atomic[bool]{}, Fx: env.fx, FlowChecker: env.flowChecker, @@ -1577,7 +1578,7 @@ func TestStandardExecutorRemoveSubnetValidatorTx(t *testing.T) { env.state.EXPECT().GetCurrentValidator(env.unsignedTx.Subnet, env.unsignedTx.NodeID).Return(&staker, nil).Times(1) e := &StandardTxExecutor{ Backend: &Backend{ - Config: defaultTestConfig(env.latestForkTime), + Config: defaultTestConfig(t, durango, env.latestForkTime), Bootstrapped: &utils.Atomic[bool]{}, Fx: env.fx, FlowChecker: env.flowChecker, @@ -1602,7 +1603,7 @@ func TestStandardExecutorRemoveSubnetValidatorTx(t *testing.T) { env.state.EXPECT().GetCurrentValidator(env.unsignedTx.Subnet, env.unsignedTx.NodeID).Return(env.staker, nil) e := &StandardTxExecutor{ Backend: &Backend{ - Config: defaultTestConfig(env.latestForkTime), + Config: defaultTestConfig(t, durango, env.latestForkTime), Bootstrapped: &utils.Atomic[bool]{}, Fx: env.fx, FlowChecker: env.flowChecker, @@ -1626,7 +1627,7 @@ func TestStandardExecutorRemoveSubnetValidatorTx(t *testing.T) { env.state.EXPECT().GetSubnetOwner(env.unsignedTx.Subnet).Return(nil, database.ErrNotFound) e := &StandardTxExecutor{ Backend: &Backend{ - Config: defaultTestConfig(env.latestForkTime), + Config: defaultTestConfig(t, durango, env.latestForkTime), Bootstrapped: &utils.Atomic[bool]{}, Fx: env.fx, FlowChecker: env.flowChecker, @@ -1652,7 +1653,7 @@ func TestStandardExecutorRemoveSubnetValidatorTx(t *testing.T) { env.fx.EXPECT().VerifyPermission(gomock.Any(), env.unsignedTx.SubnetAuth, env.tx.Creds[len(env.tx.Creds)-1], subnetOwner).Return(errTest) e := &StandardTxExecutor{ Backend: &Backend{ - Config: defaultTestConfig(env.latestForkTime), + Config: defaultTestConfig(t, durango, env.latestForkTime), Bootstrapped: &utils.Atomic[bool]{}, Fx: env.fx, FlowChecker: env.flowChecker, @@ -1681,7 +1682,7 @@ func TestStandardExecutorRemoveSubnetValidatorTx(t *testing.T) { ).Return(errTest) e := &StandardTxExecutor{ Backend: &Backend{ - Config: defaultTestConfig(env.latestForkTime), + Config: defaultTestConfig(t, durango, env.latestForkTime), Bootstrapped: &utils.Atomic[bool]{}, Fx: env.fx, FlowChecker: env.flowChecker, @@ -1834,7 +1835,7 @@ func TestStandardExecutorTransformSubnetTx(t *testing.T) { env.state = state.NewMockDiff(ctrl) e := &StandardTxExecutor{ Backend: &Backend{ - Config: defaultTestConfig(env.latestForkTime), + Config: defaultTestConfig(t, durango, env.latestForkTime), Bootstrapped: &utils.Atomic[bool]{}, Fx: env.fx, FlowChecker: env.flowChecker, @@ -1857,7 +1858,7 @@ func TestStandardExecutorTransformSubnetTx(t *testing.T) { env.state.EXPECT().GetTimestamp().Return(env.latestForkTime) e := &StandardTxExecutor{ Backend: &Backend{ - Config: defaultTestConfig(env.latestForkTime), + Config: defaultTestConfig(t, durango, env.latestForkTime), Bootstrapped: &utils.Atomic[bool]{}, Fx: env.fx, FlowChecker: env.flowChecker, @@ -1880,7 +1881,7 @@ func TestStandardExecutorTransformSubnetTx(t *testing.T) { env.state = state.NewMockDiff(ctrl) env.state.EXPECT().GetTimestamp().Return(env.latestForkTime) - cfg := defaultTestConfig(env.latestForkTime) + cfg := defaultTestConfig(t, durango, env.latestForkTime) cfg.MaxStakeDuration = math.MaxInt64 e := &StandardTxExecutor{ @@ -1913,7 +1914,7 @@ func TestStandardExecutorTransformSubnetTx(t *testing.T) { gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), ).Return(ErrFlowCheckFailed) - cfg := defaultTestConfig(env.latestForkTime) + cfg := defaultTestConfig(t, durango, env.latestForkTime) cfg.MaxStakeDuration = math.MaxInt64 e := &StandardTxExecutor{ @@ -1951,7 +1952,7 @@ func TestStandardExecutorTransformSubnetTx(t *testing.T) { env.state.EXPECT().DeleteUTXO(gomock.Any()).Times(len(env.unsignedTx.Ins)) env.state.EXPECT().AddUTXO(gomock.Any()).Times(len(env.unsignedTx.Outs)) - cfg := defaultTestConfig(env.latestForkTime) + cfg := defaultTestConfig(t, durango, env.latestForkTime) cfg.MaxStakeDuration = math.MaxInt64 e := &StandardTxExecutor{ @@ -1983,11 +1984,44 @@ func TestStandardExecutorTransformSubnetTx(t *testing.T) { } } -func defaultTestConfig(latestForkTime time.Time) *config.Config { +func defaultTestConfig(t *testing.T, f fork, tm time.Time) *config.Config { //nolint: unparam + var ( + apricotPhase3Time = mockable.MaxTime + apricotPhase5Time = mockable.MaxTime + banffTime = mockable.MaxTime + cortinaTime = mockable.MaxTime + durangoTime = mockable.MaxTime + eUpgradeTime = mockable.MaxTime + ) + + switch f { + case eUpgrade: + eUpgradeTime = tm + fallthrough + case durango: + durangoTime = tm + fallthrough + case cortina: + cortinaTime = tm + fallthrough + case banff: + banffTime = tm + fallthrough + case apricotPhase5: + apricotPhase5Time = tm + fallthrough + case apricotPhase3: + apricotPhase3Time = tm + default: + require.FailNow(t, fmt.Sprintf("unhandled fork %d", f)) + } + return &config.Config{ - BanffTime: latestForkTime, - CortinaTime: latestForkTime, - DurangoTime: latestForkTime, - EUpgradeTime: mockable.MaxTime, + EUpgradeTime: eUpgradeTime, + DurangoTime: durangoTime, + CortinaTime: cortinaTime, + BanffTime: banffTime, + ApricotPhase5Time: apricotPhase5Time, + ApricotPhase3Time: apricotPhase3Time, } } From d2525d5d2160a11984cb60e86cfe67afd1ba0f4c Mon Sep 17 00:00:00 2001 From: Alberto Benegiamo Date: Mon, 11 Mar 2024 16:06:17 +0100 Subject: [PATCH 13/18] fixed merge --- codec/test_codec.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/codec/test_codec.go b/codec/test_codec.go index 910e72da917f..2712d2ada9f4 100644 --- a/codec/test_codec.go +++ b/codec/test_codec.go @@ -8,6 +8,8 @@ import ( "testing" "github.com/stretchr/testify/require" + + "github.com/ava-labs/avalanchego/utils/wrappers" ) var ( From 7a17a9bfe5fffbacc023ae91e978c6682364bf7f Mon Sep 17 00:00:00 2001 From: Alberto Benegiamo Date: Wed, 13 Mar 2024 17:43:54 +0100 Subject: [PATCH 14/18] drop DurangoTime from avm config --- vms/avm/block/executor/block_test.go | 1 - vms/avm/config/config.go | 5 +---- vms/avm/environment_test.go | 10 ++-------- vms/avm/txs/executor/syntactic_verifier_test.go | 2 -- 4 files changed, 3 insertions(+), 15 deletions(-) diff --git a/vms/avm/block/executor/block_test.go b/vms/avm/block/executor/block_test.go index e8b08ab0346a..8e72f4c21ebe 100644 --- a/vms/avm/block/executor/block_test.go +++ b/vms/avm/block/executor/block_test.go @@ -1046,7 +1046,6 @@ func defaultTestBackend(bootstrapped bool, sharedMemory atomic.SharedMemory) *ex Log: logging.NoLog{}, }, Config: &config.Config{ - DurangoTime: time.Time{}, EUpgradeTime: mockable.MaxTime, TxFee: 0, CreateAssetTxFee: 0, diff --git a/vms/avm/config/config.go b/vms/avm/config/config.go index fb376fb77a30..0d026eb05dbb 100644 --- a/vms/avm/config/config.go +++ b/vms/avm/config/config.go @@ -13,13 +13,10 @@ type Config struct { // Fee that must be burned by every asset creating transaction CreateAssetTxFee uint64 - // Time of the Durango network upgrade - DurangoTime time.Time - // Time of the E network upgrade EUpgradeTime time.Time } -func (c *Config) IsEUActivated(timestamp time.Time) bool { +func (c *Config) IsEActivated(timestamp time.Time) bool { return !timestamp.Before(c.EUpgradeTime) } diff --git a/vms/avm/environment_test.go b/vms/avm/environment_test.go index 35db1462b94a..1ab7cf068d7f 100644 --- a/vms/avm/environment_test.go +++ b/vms/avm/environment_test.go @@ -80,7 +80,6 @@ var ( addrs []ids.ShortID // addrs[i] corresponds to keys[i] noFeesTestConfig = &config.Config{ - DurangoTime: time.Time{}, EUpgradeTime: mockable.MaxTime, TxFee: 0, CreateAssetTxFee: 0, @@ -236,17 +235,13 @@ func setup(tb testing.TB, c *envConfig) *environment { } func staticConfig(tb testing.TB, f fork) config.Config { - var ( - durangoTime = mockable.MaxTime - eUpgradeTime = mockable.MaxTime - ) + var eUpgradeTime time.Time switch f { case eUpgrade: eUpgradeTime = time.Time{} - fallthrough case durango: - durangoTime = time.Time{} + eUpgradeTime = mockable.MaxTime default: require.FailNow(tb, fmt.Sprintf("unhandled fork %d", f)) } @@ -254,7 +249,6 @@ func staticConfig(tb testing.TB, f fork) config.Config { return config.Config{ TxFee: testTxFee, CreateAssetTxFee: testTxFee, - DurangoTime: durangoTime, EUpgradeTime: eUpgradeTime, } } diff --git a/vms/avm/txs/executor/syntactic_verifier_test.go b/vms/avm/txs/executor/syntactic_verifier_test.go index a95df8354c0b..c5762a81c74b 100644 --- a/vms/avm/txs/executor/syntactic_verifier_test.go +++ b/vms/avm/txs/executor/syntactic_verifier_test.go @@ -7,7 +7,6 @@ import ( "math" "strings" "testing" - "time" "github.com/stretchr/testify/require" @@ -31,7 +30,6 @@ var ( feeConfig = config.Config{ TxFee: 2, CreateAssetTxFee: 3, - DurangoTime: time.Time{}, EUpgradeTime: mockable.MaxTime, } ) From 29067561e1dbb7d9965b652c96644c19153af21e Mon Sep 17 00:00:00 2001 From: Alberto Benegiamo Date: Wed, 13 Mar 2024 17:48:53 +0100 Subject: [PATCH 15/18] nit --- .../txs/executor/standard_tx_executor_test.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/vms/platformvm/txs/executor/standard_tx_executor_test.go b/vms/platformvm/txs/executor/standard_tx_executor_test.go index 6e58a4bcfda8..eef52f4b46d8 100644 --- a/vms/platformvm/txs/executor/standard_tx_executor_test.go +++ b/vms/platformvm/txs/executor/standard_tx_executor_test.go @@ -2017,11 +2017,11 @@ func defaultTestConfig(t *testing.T, f fork, tm time.Time) *config.Config { //no } return &config.Config{ - EUpgradeTime: eUpgradeTime, - DurangoTime: durangoTime, - CortinaTime: cortinaTime, - BanffTime: banffTime, - ApricotPhase5Time: apricotPhase5Time, ApricotPhase3Time: apricotPhase3Time, + ApricotPhase5Time: apricotPhase5Time, + BanffTime: banffTime, + CortinaTime: cortinaTime, + DurangoTime: durangoTime, + EUpgradeTime: eUpgradeTime, } } From d3edbaae5618518da96d55b712f9bb46dd06140a Mon Sep 17 00:00:00 2001 From: Alberto Benegiamo Date: Wed, 13 Mar 2024 17:52:11 +0100 Subject: [PATCH 16/18] nit --- .../txs/executor/staker_tx_verification_test.go | 8 ++------ vms/platformvm/txs/executor/standard_tx_executor_test.go | 2 +- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/vms/platformvm/txs/executor/staker_tx_verification_test.go b/vms/platformvm/txs/executor/staker_tx_verification_test.go index f9081fdf5ded..24e1df2a0db6 100644 --- a/vms/platformvm/txs/executor/staker_tx_verification_test.go +++ b/vms/platformvm/txs/executor/staker_tx_verification_test.go @@ -152,12 +152,8 @@ func TestVerifyAddPermissionlessValidatorTx(t *testing.T) { bootstrapped := &utils.Atomic[bool]{} bootstrapped.Set(true) return &Backend{ - Ctx: ctx, - Config: &config.Config{ - CortinaTime: activeForkTime, - DurangoTime: mockable.MaxTime, - EUpgradeTime: mockable.MaxTime, - }, + Ctx: ctx, + Config: defaultTestConfig(t, cortina, activeForkTime), Bootstrapped: bootstrapped, } }, diff --git a/vms/platformvm/txs/executor/standard_tx_executor_test.go b/vms/platformvm/txs/executor/standard_tx_executor_test.go index eef52f4b46d8..f8d5a76811ca 100644 --- a/vms/platformvm/txs/executor/standard_tx_executor_test.go +++ b/vms/platformvm/txs/executor/standard_tx_executor_test.go @@ -1984,7 +1984,7 @@ func TestStandardExecutorTransformSubnetTx(t *testing.T) { } } -func defaultTestConfig(t *testing.T, f fork, tm time.Time) *config.Config { //nolint: unparam +func defaultTestConfig(t *testing.T, f fork, tm time.Time) *config.Config { var ( apricotPhase3Time = mockable.MaxTime apricotPhase5Time = mockable.MaxTime From bd2311e437425e7f5279410e2fc5bb3629c51349 Mon Sep 17 00:00:00 2001 From: Alberto Benegiamo Date: Wed, 27 Mar 2024 09:41:34 +0100 Subject: [PATCH 17/18] reverted unnecessary changes --- codec/manager.go | 4 +- codec/reflectcodec/type_codec.go | 10 ++- codec/test_codec.go | 86 +--------------------- vms/platformvm/state/metadata_validator.go | 2 +- 4 files changed, 11 insertions(+), 91 deletions(-) diff --git a/codec/manager.go b/codec/manager.go index bf1ad3af72bc..27e5e392260c 100644 --- a/codec/manager.go +++ b/codec/manager.go @@ -13,7 +13,7 @@ import ( ) const ( - CodecVersionSize = wrappers.ShortLen + VersionSize = wrappers.ShortLen // default max size, in bytes, of something being marshalled by Marshal() defaultMaxSize = 256 * units.KiB @@ -105,7 +105,7 @@ func (m *manager) Size(version uint16, value interface{}) (int, error) { res, err := c.Size(value) // Add [CodecVersionSize] for the codec version - return CodecVersionSize + res, err + return VersionSize + res, err } // To marshal an interface, [value] must be a pointer to the interface. diff --git a/codec/reflectcodec/type_codec.go b/codec/reflectcodec/type_codec.go index bfec299a3e51..45818a741814 100644 --- a/codec/reflectcodec/type_codec.go +++ b/codec/reflectcodec/type_codec.go @@ -82,7 +82,7 @@ func New(typer TypeCodec, tagNames []string) codec.Codec { func (c *genericCodec) Size(value interface{}) (int, error) { if value == nil { - return 0, nil // can't marshal nil, we return zero size + return 0, codec.ErrMarshalNil // can't marshal nil, we return zero size } size, _, err := c.size(reflect.ValueOf(value), nil /*=typeStack*/) @@ -118,14 +118,14 @@ func (c *genericCodec) size( return wrappers.StringLen(value.String()), false, nil case reflect.Ptr: if value.IsNil() { - return 0, false, nil // can't marshal nil, we return zero size + return 0, false, codec.ErrMarshalNil // can't marshal nil, we return zero size } return c.size(value.Elem(), typeStack) case reflect.Interface: if value.IsNil() { - return 0, false, nil // can't marshal nil, we return zero size + return 0, false, codec.ErrMarshalNil // can't marshal nil, we return zero size } underlyingValue := value.Interface() @@ -152,6 +152,10 @@ func (c *genericCodec) size( return 0, false, err } + if size == 0 { + return 0, false, fmt.Errorf("can't marshal slice of zero length values: %w", codec.ErrMarshalZeroLength) + } + // For fixed-size types we manually calculate lengths rather than // processing each element separately to improve performance. if constSize { diff --git a/codec/test_codec.go b/codec/test_codec.go index 2712d2ada9f4..2dc8b3e2add9 100644 --- a/codec/test_codec.go +++ b/codec/test_codec.go @@ -8,15 +8,11 @@ import ( "testing" "github.com/stretchr/testify/require" - - "github.com/ava-labs/avalanchego/utils/wrappers" ) var ( Tests = []func(c GeneralCodec, t testing.TB){ TestStruct, - TestPartiallyFilledStruct, - TestSliceWithEmptyElements, TestRegisterStructTwice, TestUInt32, TestUIntPtr, @@ -245,85 +241,6 @@ func TestStruct(codec GeneralCodec, t testing.TB) { require.Equal(myStructInstance, *myStructUnmarshaled) } -func TestPartiallyFilledStruct(codec GeneralCodec, t testing.TB) { - require := require.New(t) - - manager := NewDefaultManager() - require.NoError(manager.RegisterCodec(0, codec)) - - // a nil pointer cannot be marshalled but we can get its size - var nilStruct *myStruct - _, err := manager.Marshal(0, nilStruct) - require.ErrorIs(err, ErrMarshalNil) - - bytesLen, err := manager.Size(0, nilStruct) - require.NoError(err) - require.Equal(CodecVersionSize, bytesLen) - - // an empty struct cannot be marshalled but we can get its size - emptyStruct := &myStruct{} - _, err = manager.Marshal(0, nilStruct) - require.ErrorIs(err, ErrMarshalNil) - - emptyStructLen := CodecVersionSize + 117 - bytesLen, err = manager.Size(0, emptyStruct) - require.NoError(err) - require.Equal(emptyStructLen, bytesLen) - - // an partially filled struct cannot be marshalled but we can get its size - elem := &MyInnerStruct{ - Str: "a", - } - elemLen := CodecVersionSize + wrappers.StringLen(elem.Str) - - partialStruct := &myStruct{ - InnerStruct2: elem, - } - partialStructLen := emptyStructLen + elemLen - CodecVersionSize - bytesLen, err = manager.Size(0, partialStruct) - require.NoError(err) - require.Equal(partialStructLen, bytesLen) -} - -func TestSliceWithEmptyElements(codec GeneralCodec, t testing.TB) { - require := require.New(t) - - manager := NewDefaultManager() - require.NoError(manager.RegisterCodec(0, codec)) - - // a non-empty slice with nil pointers cannot be marshalled but we can get its size - slice := make([]*MyInnerStruct, 10) - - _, err := manager.Marshal(0, slice) - require.ErrorIs(err, ErrMarshalNil) - - emptySliceLen := CodecVersionSize + wrappers.IntLen // Codec version + slice size. Slice elements have zero size - bytesLen, err := manager.Size(0, slice) - require.NoError(err) - require.Equal(emptySliceLen, bytesLen) - - elem := &MyInnerStruct{ - Str: "aaa", - } - elemLen := CodecVersionSize + wrappers.StringLen(elem.Str) - bytesLen, err = manager.Size(0, elem) - require.NoError(err) - require.Equal(elemLen, bytesLen) - - // we can fill some elements and leave other empty. Size will be sub-additive - slice[1] = elem - sliceLen := emptySliceLen + elemLen - CodecVersionSize // codec version is marshelled only once - bytesLen, err = manager.Size(0, slice) - require.NoError(err) - require.Equal(sliceLen, bytesLen) - - slice[5] = elem - sliceLen += elemLen - CodecVersionSize // codec version is marshelled only once - bytesLen, err = manager.Size(0, slice) - require.NoError(err) - require.Equal(sliceLen, bytesLen) -} - func TestRegisterStructTwice(codec GeneralCodec, t testing.TB) { require := require.New(t) @@ -856,9 +773,8 @@ func TestSliceWithEmptySerializationError(codec GeneralCodec, t testing.TB) { _, err := manager.Marshal(0, val) require.ErrorIs(err, ErrMarshalZeroLength) - // we cannot marshal/unmarshal an empty slice, but we can ask its size _, err = manager.Size(0, val) - require.NoError(err) + require.ErrorIs(err, ErrMarshalZeroLength) b := []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x01} // codec version (0x00, 0x00) then (0x00, 0x00, 0x00, 0x01) for numElts diff --git a/vms/platformvm/state/metadata_validator.go b/vms/platformvm/state/metadata_validator.go index 74242150d37f..340c7205350a 100644 --- a/vms/platformvm/state/metadata_validator.go +++ b/vms/platformvm/state/metadata_validator.go @@ -18,7 +18,7 @@ import ( // [preDelegateeRewardMetadata]. // // CodecVersionLen + UpDurationLen + LastUpdatedLen + PotentialRewardLen -const preDelegateeRewardSize = codec.CodecVersionSize + 3*wrappers.LongLen +const preDelegateeRewardSize = codec.VersionSize + 3*wrappers.LongLen var _ validatorState = (*metadata)(nil) From 799b355a00a8b276b11adbab294bc3c13abd926e Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Wed, 27 Mar 2024 11:24:44 -0400 Subject: [PATCH 18/18] nit --- codec/manager.go | 2 +- codec/reflectcodec/type_codec.go | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/codec/manager.go b/codec/manager.go index 27e5e392260c..608bbcabc0fe 100644 --- a/codec/manager.go +++ b/codec/manager.go @@ -104,7 +104,7 @@ func (m *manager) Size(version uint16, value interface{}) (int, error) { res, err := c.Size(value) - // Add [CodecVersionSize] for the codec version + // Add [VersionSize] for the codec version return VersionSize + res, err } diff --git a/codec/reflectcodec/type_codec.go b/codec/reflectcodec/type_codec.go index 45818a741814..c5ce970a8054 100644 --- a/codec/reflectcodec/type_codec.go +++ b/codec/reflectcodec/type_codec.go @@ -82,7 +82,7 @@ func New(typer TypeCodec, tagNames []string) codec.Codec { func (c *genericCodec) Size(value interface{}) (int, error) { if value == nil { - return 0, codec.ErrMarshalNil // can't marshal nil, we return zero size + return 0, codec.ErrMarshalNil } size, _, err := c.size(reflect.ValueOf(value), nil /*=typeStack*/) @@ -118,14 +118,14 @@ func (c *genericCodec) size( return wrappers.StringLen(value.String()), false, nil case reflect.Ptr: if value.IsNil() { - return 0, false, codec.ErrMarshalNil // can't marshal nil, we return zero size + return 0, false, codec.ErrMarshalNil } return c.size(value.Elem(), typeStack) case reflect.Interface: if value.IsNil() { - return 0, false, codec.ErrMarshalNil // can't marshal nil, we return zero size + return 0, false, codec.ErrMarshalNil } underlyingValue := value.Interface() @@ -292,7 +292,7 @@ func (c *genericCodec) size( // To marshal an interface, [value] must be a pointer to the interface func (c *genericCodec) MarshalInto(value interface{}, p *wrappers.Packer) error { if value == nil { - return codec.ErrMarshalNil // can't marshal nil + return codec.ErrMarshalNil } return c.marshal(reflect.ValueOf(value), p, nil /*=typeStack*/)