Commit fdd43835 authored by refcell's avatar refcell Committed by GitHub

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: default avatarAdrian Sutton <adrian@oplabs.co>
parent ff5d7f88
...@@ -71,12 +71,6 @@ func (g *OutputGameHelper) Addr() common.Address { ...@@ -71,12 +71,6 @@ func (g *OutputGameHelper) Addr() common.Address {
return g.addr 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 { func (g *OutputGameHelper) SplitDepth(ctx context.Context) types.Depth {
splitDepth, err := g.game.SplitDepth(&bind.CallOpts{Context: ctx}) splitDepth, err := g.game.SplitDepth(&bind.CallOpts{Context: ctx})
g.require.NoError(err, "failed to load split depth") g.require.NoError(err, "failed to load split depth")
......
...@@ -2,9 +2,11 @@ package faultproofs ...@@ -2,9 +2,11 @@ package faultproofs
import ( import (
"context" "context"
"math/big"
"testing" "testing"
"time" "time"
"github.com/ethereum-optimism/optimism/op-chain-ops/deployer"
op_e2e "github.com/ethereum-optimism/optimism/op-e2e" 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/challenger"
"github.com/ethereum-optimism/optimism/op-e2e/e2eutils/disputegame" "github.com/ethereum-optimism/optimism/op-e2e/e2eutils/disputegame"
...@@ -71,6 +73,67 @@ func TestOutputAlphabetGame_ChallengerWins(t *testing.T) { ...@@ -71,6 +73,67 @@ func TestOutputAlphabetGame_ChallengerWins(t *testing.T) {
game.LogGameData(ctx) 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) { func TestOutputAlphabetGame_ValidOutputRoot(t *testing.T) {
op_e2e.InitParallel(t) op_e2e.InitParallel(t)
ctx := context.Background() ctx := context.Background()
......
...@@ -6,7 +6,6 @@ import ( ...@@ -6,7 +6,6 @@ import (
"math/big" "math/big"
"testing" "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/trace/cannon"
"github.com/ethereum-optimism/optimism/op-challenger/game/fault/types" "github.com/ethereum-optimism/optimism/op-challenger/game/fault/types"
op_e2e "github.com/ethereum-optimism/optimism/op-e2e" op_e2e "github.com/ethereum-optimism/optimism/op-e2e"
...@@ -74,70 +73,6 @@ func TestOutputCannonGame(t *testing.T) { ...@@ -74,70 +73,6 @@ func TestOutputCannonGame(t *testing.T) {
game.WaitForGameStatus(ctx, disputegame.StatusChallengerWins) 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) { func TestOutputCannon_ChallengeAllZeroClaim(t *testing.T) {
// The dishonest actor always posts claims with all zeros. // The dishonest actor always posts claims with all zeros.
op_e2e.InitParallel(t, op_e2e.UsesCannon) op_e2e.InitParallel(t, op_e2e.UsesCannon)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment