Skip to content

Commit

Permalink
👌 Applied suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
nagdahimanshu committed Feb 21, 2024
1 parent 823db75 commit 1965d90
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions cmd/faultdetector/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"io"
"math/big"
"math/rand"
"net/http"
"strconv"
"strings"
Expand All @@ -30,13 +31,14 @@ import (
)

const (
host = "127.0.0.1"
port = 8088
faultProofWindow = 1000
currentOutputIndex = 1
l1RpcApi = "https://rpc.notadegen.com/eth"
l2RpcApi = "https://mainnet.optimism.io/"
faultDetectorStateMismatch = "fault_detector_is_state_mismatch"
host = "127.0.0.1"
port = 8088
faultProofWindow = 1000
currentOutputIndex = 1
l1RpcApi = "https://rpc.notadegen.com/eth"
l2RpcApi = "https://mainnet.optimism.io/"
faultDetectorStateMismatchMetricKey = "fault_detector_is_state_mismatch"
metricValue = "value"
)

type parseMetric map[string]map[string]interface{}
Expand Down Expand Up @@ -76,6 +78,11 @@ func randHash() (out common.Hash) {
return out
}

func randTimestamp() (out uint64) {
timestamp := uint64(rand.Int63n(time.Now().Unix()))
return timestamp
}

func prepareHTTPServer(t *testing.T, ctx context.Context, logger log.Logger, config *config.Config, wg *sync.WaitGroup, erroChan chan error) *api.HTTPServer {
testServer := api.NewHTTPServer(ctx, logger, wg, config, erroChan)
return testServer
Expand Down Expand Up @@ -106,13 +113,13 @@ func prepareFaultDetector(t *testing.T, ctx context.Context, logger log.Logger,
oracle.On("FinalizationPeriodSeconds").Return(faultProofWindow, nil)
oracle.On("GetL2Output", big.NewInt(0)).Return(chain.L2Output{
OutputRoot: randHash().String(),
L1Timestamp: 1000000,
L1Timestamp: randTimestamp(),
L2BlockNumber: latestL2BlockNumber,
L2OutputIndex: 2,
}, nil)
oracle.On("GetL2Output", big.NewInt(1)).Return(chain.L2Output{
OutputRoot: randHash().String(),
L1Timestamp: 1000000,
L1Timestamp: randTimestamp(),
L2BlockNumber: latestL2BlockNumber,
L2OutputIndex: 2,
}, nil)
Expand Down Expand Up @@ -166,9 +173,9 @@ func parseMetricRes(input *strings.Reader) []parseMetric {
}
switch metricFamily.GetType() {
case promClient.MetricType_COUNTER:
metric["value"] = m.GetCounter().GetValue()
metric[metricValue] = m.GetCounter().GetValue()
case promClient.MetricType_GAUGE:
metric["value"] = m.GetGauge().GetValue()
metric[metricValue] = m.GetGauge().GetValue()
}
parsedOutput = append(parsedOutput, parseMetric{
metricFamily.GetName(): metric,
Expand Down Expand Up @@ -250,8 +257,8 @@ func TestMain_E2E(t *testing.T) {
assert.NoError(t, err)
parsedMetric := parseMetricRes(strings.NewReader(string(body)))
for _, m := range parsedMetric {
if m[faultDetectorStateMismatch] != nil {
isStateMismatch := m[faultDetectorStateMismatch]["value"].(float64)
if m[faultDetectorStateMismatchMetricKey] != nil {
isStateMismatch := m[faultDetectorStateMismatchMetricKey][metricValue].(float64)
tt.assertion(isStateMismatch, nil)
}
}
Expand Down

0 comments on commit 1965d90

Please sign in to comment.