Skip to content

Commit

Permalink
Add test of scheduling upgrade and getting it
Browse files Browse the repository at this point in the history
  • Loading branch information
PlasmaPower committed Jan 29, 2024
1 parent 76924e0 commit 4db1014
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions system_tests/precompile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,54 @@ func TestPrecompileErrorGasLeft(t *testing.T) {
Require(t, err)
assertNotAllGasConsumed(common.HexToAddress("0xff"), arbDebug.Methods["legacyError"].ID)
}

func TestScheduleArbosUpgrade(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

builder := NewNodeBuilder(ctx).DefaultConfig(t, false)
cleanup := builder.Build(t)
defer cleanup()

auth := builder.L2Info.GetDefaultTransactOpts("Owner", ctx)

arbOwnerPublic, err := precompilesgen.NewArbOwnerPublic(common.HexToAddress("0x6b"), builder.L2.Client)
Require(t, err, "could not bind ArbOwner contract")

arbOwner, err := precompilesgen.NewArbOwner(common.HexToAddress("0x70"), builder.L2.Client)
Require(t, err, "could not bind ArbOwner contract")

callOpts := &bind.CallOpts{Context: ctx}
scheduled, err := arbOwnerPublic.GetScheduledUpgrade(callOpts)
Require(t, err, "failed to call GetScheduledUpgrade before scheduling upgrade")
if scheduled.ArbosVersion != 0 || scheduled.ScheduledForTimestamp != 0 {
t.Errorf("expected no upgrade to be scheduled, got version %v timestamp %v", scheduled.ArbosVersion, scheduled.ScheduledForTimestamp)
}

// Schedule a noop upgrade, which should test GetScheduledUpgrade in the same way an already completed upgrade would.
tx, err := arbOwner.ScheduleArbOSUpgrade(&auth, 1, 1)
Require(t, err)
_, err = builder.L2.EnsureTxSucceeded(tx)
Require(t, err)

scheduled, err = arbOwnerPublic.GetScheduledUpgrade(callOpts)
Require(t, err, "failed to call GetScheduledUpgrade after scheduling noop upgrade")
if scheduled.ArbosVersion != 0 || scheduled.ScheduledForTimestamp != 0 {
t.Errorf("expected completed scheduled upgrade to be ignored, got version %v timestamp %v", scheduled.ArbosVersion, scheduled.ScheduledForTimestamp)
}

// TODO: Once we have an ArbOS 30, test a real upgrade with it
// We can't test 11 -> 20 because 11 doesn't have the GetScheduledUpgrade method we want to test
var testVersion uint64 = 100
var testTimestamp uint64 = 1 >> 62
tx, err = arbOwner.ScheduleArbOSUpgrade(&auth, 100, 1>>62)
Require(t, err)
_, err = builder.L2.EnsureTxSucceeded(tx)
Require(t, err)

scheduled, err = arbOwnerPublic.GetScheduledUpgrade(callOpts)
Require(t, err, "failed to call GetScheduledUpgrade after scheduling upgrade")
if scheduled.ArbosVersion != testVersion || scheduled.ScheduledForTimestamp != testTimestamp {
t.Errorf("expected upgrade to be scheduled for version %v timestamp %v, got version %v timestamp %v", testVersion, testTimestamp, scheduled.ArbosVersion, scheduled.ScheduledForTimestamp)
}
}

0 comments on commit 4db1014

Please sign in to comment.