Commit 2fe0c069 authored by Andreas Bigger's avatar Andreas Bigger

Methodize GameStatusString function

parent 317fcb6d
...@@ -4,13 +4,13 @@ import ( ...@@ -4,13 +4,13 @@ import (
"context" "context"
"math/big" "math/big"
"github.com/ethereum-optimism/optimism/op-bindings/bindings"
"github.com/ethereum-optimism/optimism/op-challenger/fault/types"
"github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient" "github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
"github.com/ethereum-optimism/optimism/op-bindings/bindings"
"github.com/ethereum-optimism/optimism/op-challenger/fault/types"
) )
type FaultDisputeGameCaller interface { type FaultDisputeGameCaller interface {
...@@ -53,7 +53,7 @@ func (fc *FaultCaller) LogGameInfo(ctx context.Context) { ...@@ -53,7 +53,7 @@ func (fc *FaultCaller) LogGameInfo(ctx context.Context) {
fc.log.Error("failed to get claim count", "err", err) fc.log.Error("failed to get claim count", "err", err)
return return
} }
fc.log.Info("Game info", "claims", claimLen, "status", GameStatusString(status)) fc.log.Info("Game info", "claims", claimLen, "status", status)
} }
// GetGameStatus returns the current game status. // GetGameStatus returns the current game status.
...@@ -78,17 +78,3 @@ func (fc *FaultCaller) LogClaimDataLength(ctx context.Context) { ...@@ -78,17 +78,3 @@ func (fc *FaultCaller) LogClaimDataLength(ctx context.Context) {
} }
fc.log.Info("Number of claims", "length", claimLen) fc.log.Info("Number of claims", "length", claimLen)
} }
// GameStatusString returns the current game status as a string.
func GameStatusString(status types.GameStatus) string {
switch status {
case types.GameStatusInProgress:
return "In Progress"
case types.GameStatusChallengerWon:
return "Challenger Won"
case types.GameStatusDefenderWon:
return "Defender Won"
default:
return "Unknown"
}
}
...@@ -4,8 +4,9 @@ import ( ...@@ -4,8 +4,9 @@ import (
"context" "context"
"time" "time"
"github.com/ethereum-optimism/optimism/op-challenger/fault/types"
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
"github.com/ethereum-optimism/optimism/op-challenger/fault/types"
) )
type GameInfo interface { type GameInfo interface {
...@@ -51,9 +52,9 @@ func progressGame(ctx context.Context, logger log.Logger, agreeWithProposedOutpu ...@@ -51,9 +52,9 @@ func progressGame(ctx context.Context, logger log.Logger, agreeWithProposedOutpu
expectedStatus = types.GameStatusDefenderWon expectedStatus = types.GameStatusDefenderWon
} }
if expectedStatus == status { if expectedStatus == status {
logger.Info("Game won", "status", GameStatusString(status)) logger.Info("Game won", "status", status)
} else { } else {
logger.Error("Game lost", "status", GameStatusString(status)) logger.Error("Game lost", "status", status)
} }
return true return true
} else { } else {
......
...@@ -5,10 +5,11 @@ import ( ...@@ -5,10 +5,11 @@ import (
"errors" "errors"
"testing" "testing"
"github.com/ethereum-optimism/optimism/op-challenger/fault/types"
"github.com/ethereum-optimism/optimism/op-node/testlog"
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"github.com/ethereum-optimism/optimism/op-challenger/fault/types"
"github.com/ethereum-optimism/optimism/op-node/testlog"
) )
func TestMonitorExitsWhenContextDone(t *testing.T) { func TestMonitorExitsWhenContextDone(t *testing.T) {
...@@ -48,7 +49,6 @@ func TestProgressGame_LogErrorWhenGameLost(t *testing.T) { ...@@ -48,7 +49,6 @@ func TestProgressGame_LogErrorWhenGameLost(t *testing.T) {
agreeWithOutput bool agreeWithOutput bool
logLevel log.Lvl logLevel log.Lvl
logMsg string logMsg string
statusText string
}{ }{
{ {
name: "GameLostAsDefender", name: "GameLostAsDefender",
...@@ -56,7 +56,6 @@ func TestProgressGame_LogErrorWhenGameLost(t *testing.T) { ...@@ -56,7 +56,6 @@ func TestProgressGame_LogErrorWhenGameLost(t *testing.T) {
agreeWithOutput: false, agreeWithOutput: false,
logLevel: log.LvlError, logLevel: log.LvlError,
logMsg: "Game lost", logMsg: "Game lost",
statusText: "Challenger Won",
}, },
{ {
name: "GameLostAsChallenger", name: "GameLostAsChallenger",
...@@ -64,7 +63,6 @@ func TestProgressGame_LogErrorWhenGameLost(t *testing.T) { ...@@ -64,7 +63,6 @@ func TestProgressGame_LogErrorWhenGameLost(t *testing.T) {
agreeWithOutput: true, agreeWithOutput: true,
logLevel: log.LvlError, logLevel: log.LvlError,
logMsg: "Game lost", logMsg: "Game lost",
statusText: "Defender Won",
}, },
{ {
name: "GameWonAsDefender", name: "GameWonAsDefender",
...@@ -72,7 +70,6 @@ func TestProgressGame_LogErrorWhenGameLost(t *testing.T) { ...@@ -72,7 +70,6 @@ func TestProgressGame_LogErrorWhenGameLost(t *testing.T) {
agreeWithOutput: false, agreeWithOutput: false,
logLevel: log.LvlInfo, logLevel: log.LvlInfo,
logMsg: "Game won", logMsg: "Game won",
statusText: "Defender Won",
}, },
{ {
name: "GameWonAsChallenger", name: "GameWonAsChallenger",
...@@ -80,7 +77,6 @@ func TestProgressGame_LogErrorWhenGameLost(t *testing.T) { ...@@ -80,7 +77,6 @@ func TestProgressGame_LogErrorWhenGameLost(t *testing.T) {
agreeWithOutput: true, agreeWithOutput: true,
logLevel: log.LvlInfo, logLevel: log.LvlInfo,
logMsg: "Game won", logMsg: "Game won",
statusText: "Challenger Won",
}, },
} }
for _, test := range tests { for _, test := range tests {
...@@ -94,7 +90,7 @@ func TestProgressGame_LogErrorWhenGameLost(t *testing.T) { ...@@ -94,7 +90,7 @@ func TestProgressGame_LogErrorWhenGameLost(t *testing.T) {
require.Equal(t, 0, gameInfo.logCount, "should not log latest game state") require.Equal(t, 0, gameInfo.logCount, "should not log latest game state")
errLog := handler.FindLog(test.logLevel, test.logMsg) errLog := handler.FindLog(test.logLevel, test.logMsg)
require.NotNil(t, errLog, "should log game result") require.NotNil(t, errLog, "should log game result")
require.Equal(t, test.statusText, errLog.GetContextValue("status")) require.Equal(t, test.status, errLog.GetContextValue("status"))
}) })
} }
} }
......
...@@ -20,6 +20,20 @@ const ( ...@@ -20,6 +20,20 @@ const (
GameStatusDefenderWon GameStatusDefenderWon
) )
// String returns the string representation of the game status.
func (s GameStatus) String() string {
switch s {
case GameStatusInProgress:
return "In Progress"
case GameStatusChallengerWon:
return "Challenger Won"
case GameStatusDefenderWon:
return "Defender Won"
default:
return "Unknown"
}
}
// PreimageOracleData encapsulates the preimage oracle data // PreimageOracleData encapsulates the preimage oracle data
// to load into the onchain oracle. // to load into the onchain oracle.
type PreimageOracleData struct { type PreimageOracleData struct {
......
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