From fdd43835eff2bea0f77be2f9f57cae13d78a7739 Mon Sep 17 00:00:00 2001 From: refcell Date: Mon, 11 Mar 2024 18:17:35 -0400 Subject: [PATCH] fix(op-e2e): E2E Bond Test Alphabet VM Migration (#9803) * fix(op-e2e): migrate bond e2e test to the alphabet vm * op-e2e: Avoid hard coded expected amounts to make test less brittle. * op-e2e: Skip asserting Alice's initial balance. --------- Co-authored-by: Adrian Sutton --- .../disputegame/output_game_helper.go | 6 -- op-e2e/faultproofs/output_alphabet_test.go | 63 ++++++++++++++++++ op-e2e/faultproofs/output_cannon_test.go | 65 ------------------- 3 files changed, 63 insertions(+), 71 deletions(-) diff --git a/op-e2e/e2eutils/disputegame/output_game_helper.go b/op-e2e/e2eutils/disputegame/output_game_helper.go index acb1c981ea6e..d078a5f814f8 100644 --- a/op-e2e/e2eutils/disputegame/output_game_helper.go +++ b/op-e2e/e2eutils/disputegame/output_game_helper.go @@ -71,12 +71,6 @@ func (g *OutputGameHelper) Addr() common.Address { return g.addr } -func (g *OutputGameHelper) Balance(ctx context.Context, addr common.Address) *big.Int { - balance, err := g.client.BalanceAt(ctx, addr, nil) - g.require.NoError(err, "Failed to get balance") - return balance -} - func (g *OutputGameHelper) SplitDepth(ctx context.Context) types.Depth { splitDepth, err := g.game.SplitDepth(&bind.CallOpts{Context: ctx}) g.require.NoError(err, "failed to load split depth") diff --git a/op-e2e/faultproofs/output_alphabet_test.go b/op-e2e/faultproofs/output_alphabet_test.go index 439ae4c12817..e87049b9c2e9 100644 --- a/op-e2e/faultproofs/output_alphabet_test.go +++ b/op-e2e/faultproofs/output_alphabet_test.go @@ -2,9 +2,11 @@ package faultproofs import ( "context" + "math/big" "testing" "time" + "github.com/ethereum-optimism/optimism/op-chain-ops/deployer" op_e2e "github.com/ethereum-optimism/optimism/op-e2e" "github.com/ethereum-optimism/optimism/op-e2e/e2eutils/challenger" "github.com/ethereum-optimism/optimism/op-e2e/e2eutils/disputegame" @@ -71,6 +73,67 @@ func TestOutputAlphabetGame_ChallengerWins(t *testing.T) { game.LogGameData(ctx) } +func TestOutputAlphabetGame_ReclaimBond(t *testing.T) { + op_e2e.InitParallel(t) + ctx := context.Background() + sys, l1Client := startFaultDisputeSystem(t) + t.Cleanup(sys.Close) + + disputeGameFactory := disputegame.NewFactoryHelper(t, ctx, sys) + game := disputeGameFactory.StartOutputAlphabetGame(ctx, "sequencer", 3, common.Hash{0xff}) + game.LogGameData(ctx) + + // The dispute game should have a zero balance + balance := game.WethBalance(ctx, game.Addr()) + require.Zero(t, balance.Uint64()) + + alice := sys.Cfg.Secrets.Addresses().Alice + + // Grab the root claim + claim := game.RootClaim(ctx) + opts := challenger.WithPrivKey(sys.Cfg.Secrets.Alice) + game.StartChallenger(ctx, "sequencer", "Challenger", opts) + game.LogGameData(ctx) + + // Perform a few moves + claim = claim.WaitForCounterClaim(ctx) + game.LogGameData(ctx) + claim = claim.Attack(ctx, common.Hash{}) + claim = claim.WaitForCounterClaim(ctx) + game.LogGameData(ctx) + claim = claim.Attack(ctx, common.Hash{}) + game.LogGameData(ctx) + _ = claim.WaitForCounterClaim(ctx) + + // Expect posted claims so the game balance is non-zero + balance = game.WethBalance(ctx, game.Addr()) + require.Truef(t, balance.Cmp(big.NewInt(0)) > 0, "Expected game balance to be above zero") + + sys.TimeTravelClock.AdvanceTime(game.GameDuration(ctx)) + require.NoError(t, wait.ForNextBlock(ctx, l1Client)) + game.WaitForGameStatus(ctx, disputegame.StatusChallengerWins) + game.LogGameData(ctx) + + // Expect Alice's credit to be non-zero + // But it can't be claimed right now since there is a delay on the weth unlock + require.Truef(t, game.AvailableCredit(ctx, alice).Cmp(big.NewInt(0)) > 0, "Expected alice credit to be above zero") + + // The actor should have no credit available because all its bonds were paid to Alice. + actorCredit := game.AvailableCredit(ctx, deployer.TestAddress) + require.True(t, actorCredit.Cmp(big.NewInt(0)) == 0, "Expected alice available credit to be zero") + + // Advance the time past the weth unlock delay + sys.TimeTravelClock.AdvanceTime(game.CreditUnlockDuration(ctx)) + require.NoError(t, wait.ForNextBlock(ctx, l1Client)) + + // Wait for alice to have no available credit + // aka, wait for the challenger to claim its credit + game.WaitForNoAvailableCredit(ctx, alice) + + // The dispute game delayed weth balance should be zero since it's all claimed + require.True(t, game.WethBalance(ctx, game.Addr()).Cmp(big.NewInt(0)) == 0) +} + func TestOutputAlphabetGame_ValidOutputRoot(t *testing.T) { op_e2e.InitParallel(t) ctx := context.Background() diff --git a/op-e2e/faultproofs/output_cannon_test.go b/op-e2e/faultproofs/output_cannon_test.go index 6bd577d675a6..6aed7c041e34 100644 --- a/op-e2e/faultproofs/output_cannon_test.go +++ b/op-e2e/faultproofs/output_cannon_test.go @@ -6,7 +6,6 @@ import ( "math/big" "testing" - "github.com/ethereum-optimism/optimism/op-chain-ops/deployer" "github.com/ethereum-optimism/optimism/op-challenger/game/fault/trace/cannon" "github.com/ethereum-optimism/optimism/op-challenger/game/fault/types" op_e2e "github.com/ethereum-optimism/optimism/op-e2e" @@ -74,70 +73,6 @@ func TestOutputCannonGame(t *testing.T) { game.WaitForGameStatus(ctx, disputegame.StatusChallengerWins) } -func TestOutputCannon_ReclaimBond(t *testing.T) { - // The dishonest actor always posts claims with all zeros. - op_e2e.InitParallel(t, op_e2e.UsesCannon) - ctx := context.Background() - sys, l1Client := startFaultDisputeSystem(t) - t.Cleanup(sys.Close) - - disputeGameFactory := disputegame.NewFactoryHelper(t, ctx, sys) - game := disputeGameFactory.StartOutputCannonGame(ctx, "sequencer", 3, common.Hash{}) - game.LogGameData(ctx) - - // The dispute game should have a zero balance - balance := game.WethBalance(ctx, game.Addr()) - require.Zero(t, balance.Uint64()) - - alice := sys.Cfg.Secrets.Addresses().Alice - bal, _ := big.NewInt(0).SetString("1000000000000000000000", 10) - require.Equal(t, bal, game.Balance(ctx, alice)) - - // Grab the root claim - claim := game.RootClaim(ctx) - game.StartChallenger(ctx, "sequencer", "Challenger", challenger.WithPrivKey(sys.Cfg.Secrets.Alice)) - - // Perform a few moves - claim = claim.WaitForCounterClaim(ctx) - game.LogGameData(ctx) - claim = claim.Attack(ctx, common.Hash{}) - claim = claim.WaitForCounterClaim(ctx) - game.LogGameData(ctx) - claim = claim.Attack(ctx, common.Hash{}) - game.LogGameData(ctx) - _ = claim.WaitForCounterClaim(ctx) - - // Expect posted claims so the game balance is non-zero - balance = game.WethBalance(ctx, game.Addr()) - expectedBalance, _ := big.NewInt(0).SetString("589772600000000000", 10) - require.Equal(t, expectedBalance, balance) - - sys.TimeTravelClock.AdvanceTime(game.GameDuration(ctx)) - require.NoError(t, wait.ForNextBlock(ctx, l1Client)) - game.WaitForGameStatus(ctx, disputegame.StatusChallengerWins) - game.LogGameData(ctx) - - // Expect Alice's credit to be non-zero - // But it can't be claimed right now since there is a delay on the weth unlock - expectedCredit, _ := big.NewInt(0).SetString("589772600000000000", 10) - require.Equal(t, expectedCredit, game.AvailableCredit(ctx, alice)) - - // The actor should have a small credit available to claim - actorCredit := game.AvailableCredit(ctx, deployer.TestAddress) - require.True(t, actorCredit.Cmp(big.NewInt(0)) == 0) - - // Advance the time past the weth unlock delay - sys.TimeTravelClock.AdvanceTime(game.CreditUnlockDuration(ctx)) - require.NoError(t, wait.ForNextBlock(ctx, l1Client)) - - // Wait for alice to have no available credit - // aka, wait for the challenger to claim its credit - game.WaitForNoAvailableCredit(ctx, alice) - - // The dispute game delayed weth balance should be zero since it's all claimed - require.True(t, game.WethBalance(ctx, game.Addr()).Cmp(big.NewInt(0)) == 0) -} - func TestOutputCannon_ChallengeAllZeroClaim(t *testing.T) { // The dishonest actor always posts claims with all zeros. op_e2e.InitParallel(t, op_e2e.UsesCannon)