diff --git a/op-e2e/e2eutils/disputegame/output_game_helper.go b/op-e2e/e2eutils/disputegame/output_game_helper.go index acb1c981ea6e35f64d2ef31cc0ac5e88fc8bdfa7..d078a5f814f889393328288b78d67a45cf4b3855 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 439ae4c12817c187e0e769901b22279d512fbd33..e87049b9c2e95ae5e63f46a258cd5361ea99750b 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 6bd577d675a692ce628d0d2e024a5d6361085425..6aed7c041e346c3f6f02f512476469ead3c29705 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)