Commit 16bf8454 authored by Adrian Sutton's avatar Adrian Sutton Committed by GitHub

op-challenger: Check for simulation failed error in correct place (#9947)

parent b57a2634
...@@ -79,14 +79,14 @@ func (c *Claimer) claimBond(ctx context.Context, game types.GameMetadata, addr c ...@@ -79,14 +79,14 @@ func (c *Claimer) claimBond(ctx context.Context, game types.GameMetadata, addr c
} }
candidate, err := contract.ClaimCreditTx(ctx, addr) candidate, err := contract.ClaimCreditTx(ctx, addr)
if err != nil { if errors.Is(err, contracts.ErrSimulationFailed) {
return fmt.Errorf("failed to create credit claim tx: %w", err)
}
if err = c.txSender.SendAndWaitSimple("claim credit", candidate); errors.Is(err, contracts.ErrSimulationFailed) {
c.logger.Debug("Credit still locked", "game", game.Proxy, "addr", addr) c.logger.Debug("Credit still locked", "game", game.Proxy, "addr", addr)
return nil return nil
} else if err != nil { } else if err != nil {
return fmt.Errorf("failed to create credit claim tx: %w", err)
}
if err = c.txSender.SendAndWaitSimple("claim credit", candidate); err != nil {
return fmt.Errorf("failed to claim credit: %w", err) return fmt.Errorf("failed to claim credit: %w", err)
} }
......
...@@ -3,9 +3,11 @@ package claims ...@@ -3,9 +3,11 @@ package claims
import ( import (
"context" "context"
"errors" "errors"
"fmt"
"math/big" "math/big"
"testing" "testing"
"github.com/ethereum-optimism/optimism/op-challenger/game/fault/contracts"
"github.com/ethereum-optimism/optimism/op-challenger/game/types" "github.com/ethereum-optimism/optimism/op-challenger/game/types"
"github.com/ethereum-optimism/optimism/op-service/testlog" "github.com/ethereum-optimism/optimism/op-service/testlog"
"github.com/ethereum-optimism/optimism/op-service/txmgr" "github.com/ethereum-optimism/optimism/op-service/txmgr"
...@@ -76,6 +78,17 @@ func TestClaimer_ClaimBonds(t *testing.T) { ...@@ -76,6 +78,17 @@ func TestClaimer_ClaimBonds(t *testing.T) {
require.Equal(t, 0, m.RecordBondClaimedCalls) require.Equal(t, 0, m.RecordBondClaimedCalls)
}) })
t.Run("BondStillLocked", func(t *testing.T) {
gameAddr := common.HexToAddress("0x1234")
c, m, contract, txSender := newTestClaimer(t)
contract.claimSimulationFails = true
contract.credit[txSender.From()] = 1
err := c.ClaimBonds(context.Background(), []types.GameMetadata{{Proxy: gameAddr}})
require.NoError(t, err)
require.Equal(t, 0, txSender.sends)
require.Equal(t, 0, m.RecordBondClaimedCalls)
})
t.Run("ZeroCreditReturnsNil", func(t *testing.T) { t.Run("ZeroCreditReturnsNil", func(t *testing.T) {
gameAddr := common.HexToAddress("0x1234") gameAddr := common.HexToAddress("0x1234")
c, m, contract, txSender := newTestClaimer(t) c, m, contract, txSender := newTestClaimer(t)
...@@ -143,8 +156,9 @@ func (s *mockTxSender) SendAndWaitSimple(_ string, _ ...txmgr.TxCandidate) error ...@@ -143,8 +156,9 @@ func (s *mockTxSender) SendAndWaitSimple(_ string, _ ...txmgr.TxCandidate) error
} }
type stubBondContract struct { type stubBondContract struct {
credit map[common.Address]int64 credit map[common.Address]int64
status types.GameStatus status types.GameStatus
claimSimulationFails bool
} }
func (s *stubBondContract) GetCredit(_ context.Context, addr common.Address) (*big.Int, types.GameStatus, error) { func (s *stubBondContract) GetCredit(_ context.Context, addr common.Address) (*big.Int, types.GameStatus, error) {
...@@ -152,5 +166,8 @@ func (s *stubBondContract) GetCredit(_ context.Context, addr common.Address) (*b ...@@ -152,5 +166,8 @@ func (s *stubBondContract) GetCredit(_ context.Context, addr common.Address) (*b
} }
func (s *stubBondContract) ClaimCreditTx(_ context.Context, _ common.Address) (txmgr.TxCandidate, error) { func (s *stubBondContract) ClaimCreditTx(_ context.Context, _ common.Address) (txmgr.TxCandidate, error) {
if s.claimSimulationFails {
return txmgr.TxCandidate{}, fmt.Errorf("failed: %w", contracts.ErrSimulationFailed)
}
return txmgr.TxCandidate{}, nil return txmgr.TxCandidate{}, nil
} }
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