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
}
candidate, err := contract.ClaimCreditTx(ctx, addr)
if err != nil {
return fmt.Errorf("failed to create credit claim tx: %w", err)
}
if err = c.txSender.SendAndWaitSimple("claim credit", candidate); errors.Is(err, contracts.ErrSimulationFailed) {
if errors.Is(err, contracts.ErrSimulationFailed) {
c.logger.Debug("Credit still locked", "game", game.Proxy, "addr", addr)
return 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)
}
......
......@@ -3,9 +3,11 @@ package claims
import (
"context"
"errors"
"fmt"
"math/big"
"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-service/testlog"
"github.com/ethereum-optimism/optimism/op-service/txmgr"
......@@ -76,6 +78,17 @@ func TestClaimer_ClaimBonds(t *testing.T) {
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) {
gameAddr := common.HexToAddress("0x1234")
c, m, contract, txSender := newTestClaimer(t)
......@@ -143,8 +156,9 @@ func (s *mockTxSender) SendAndWaitSimple(_ string, _ ...txmgr.TxCandidate) error
}
type stubBondContract struct {
credit map[common.Address]int64
status types.GameStatus
credit map[common.Address]int64
status types.GameStatus
claimSimulationFails bool
}
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
}
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
}
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