diff --git a/plugin/evm/vm_upgrade_bytes_test.go b/plugin/evm/vm_upgrade_bytes_test.go index 6c5e9f8494..656615b929 100644 --- a/plugin/evm/vm_upgrade_bytes_test.go +++ b/plugin/evm/vm_upgrade_bytes_test.go @@ -14,6 +14,7 @@ import ( "github.com/ava-labs/avalanchego/snow" commonEng "github.com/ava-labs/avalanchego/snow/engine/common" + "github.com/ava-labs/avalanchego/utils/constants" "github.com/ava-labs/avalanchego/vms/components/chain" "github.com/ava-labs/subnet-evm/core" "github.com/ava-labs/subnet-evm/core/types" @@ -229,80 +230,80 @@ func TestVMUpgradeBytesPrecompile(t *testing.T) { // } // } -// This won't work with mainnet is disabled. -// func TestMandatoryUpgradesEnforced(t *testing.T) { -// // make genesis w/ fork at block 5 -// // but this should not be used because we are enforcing -// // network upgrades within the code -// var genesis core.Genesis -// if err := json.Unmarshal([]byte(genesisJSONPreSubnetEVM), &genesis); err != nil { -// t.Fatalf("could not unmarshal genesis bytes: %s", err) -// } -// genesisSubnetEVMTimestamp := utils.NewUint64(5) -// genesis.Config.SubnetEVMTimestamp = genesisSubnetEVMTimestamp -// genesisBytes, err := json.Marshal(&genesis) -// if err != nil { -// t.Fatalf("could not unmarshal genesis bytes: %s", err) -// } +func TestMandatoryUpgradesEnforced(t *testing.T) { + // make genesis w/ fork at block 5 + // but this should not be used because we are enforcing + // network upgrades within the code + var genesis core.Genesis + if err := json.Unmarshal([]byte(genesisJSONPreSubnetEVM), &genesis); err != nil { + t.Fatalf("could not unmarshal genesis bytes: %s", err) + } + genesisSubnetEVMTimestamp := utils.NewUint64(5) + genesis.Config.SubnetEVMTimestamp = genesisSubnetEVMTimestamp + genesisBytes, err := json.Marshal(&genesis) + if err != nil { + t.Fatalf("could not unmarshal genesis bytes: %s", err) + } -// // initialize the VM with these upgrade bytes -// tests := []struct { -// networkID uint32 -// expected bool -// }{ -// { -// networkID: constants.MainnetID, -// expected: true, -// }, -// { -// networkID: constants.FujiID, -// expected: true, -// }, -// { -// networkID: constants.LocalID, -// expected: false, -// }, -// { -// networkID: constants.UnitTestID, -// expected: false, -// }, -// } + // initialize the VM with these upgrade bytes + tests := []struct { + networkID uint32 + expected bool + }{ + // This won't work because mainnet is not suppored in fuji release. + // { + // networkID: constants.MainnetID, + // expected: true, + // }, + { + networkID: constants.FujiID, + expected: true, + }, + { + networkID: constants.LocalID, + expected: false, + }, + { + networkID: constants.UnitTestID, + expected: false, + }, + } -// for _, test := range tests { -// t.Run(fmt.Sprintf("networkID %d", test.networkID), func(t *testing.T) { -// vm := &VM{} -// ctx, dbManager, genesisBytes, issuer, _ := setupGenesis(t, string(genesisBytes)) -// ctx.NetworkID = test.networkID -// appSender := &commonEng.SenderTest{T: t} -// appSender.CantSendAppGossip = true -// appSender.SendAppGossipF = func(context.Context, []byte) error { return nil } -// err := vm.Initialize( -// context.Background(), -// ctx, -// dbManager, -// genesisBytes, -// nil, -// nil, -// issuer, -// []*commonEng.Fx{}, -// appSender, -// ) -// require.NoError(t, err, "error initializing GenesisVM") - -// require.NoError(t, vm.SetState(context.Background(), snow.Bootstrapping)) -// require.NoError(t, vm.SetState(context.Background(), snow.NormalOp)) - -// defer func() { -// if err := vm.Shutdown(context.Background()); err != nil { -// t.Fatal(err) -// } -// }() - -// // verify upgrade is rescheduled -// require.Equal(t, test.expected, vm.chainConfig.IsSubnetEVM(0)) -// }) -// } -// } + for _, test := range tests { + t.Run(fmt.Sprintf("networkID %d", test.networkID), func(t *testing.T) { + vm := &VM{} + ctx, dbManager, genesisBytes, issuer, _ := setupGenesis(t, string(genesisBytes)) + ctx.NetworkID = test.networkID + appSender := &commonEng.SenderTest{T: t} + appSender.CantSendAppGossip = true + appSender.SendAppGossipF = func(context.Context, []byte) error { return nil } + err := vm.Initialize( + context.Background(), + ctx, + dbManager, + genesisBytes, + nil, + nil, + issuer, + []*commonEng.Fx{}, + appSender, + ) + require.NoError(t, err, "error initializing GenesisVM") + + require.NoError(t, vm.SetState(context.Background(), snow.Bootstrapping)) + require.NoError(t, vm.SetState(context.Background(), snow.NormalOp)) + + defer func() { + if err := vm.Shutdown(context.Background()); err != nil { + t.Fatal(err) + } + }() + + // verify upgrade is rescheduled + require.Equal(t, test.expected, vm.chainConfig.IsSubnetEVM(0)) + }) + } +} func mustMarshal(t *testing.T, v interface{}) string { b, err := json.Marshal(v)