Skip to content

Commit cca6b63

Browse files
authored
chore: make format golines (#456)
Signed-off-by: Chris Gianelloni <[email protected]>
1 parent 703f976 commit cca6b63

File tree

2 files changed

+76
-24
lines changed

2 files changed

+76
-24
lines changed

input/chainsync/chainsync.go

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,12 @@ func (c *ChainSync) handleRollForward(
361361
default:
362362
return errors.New("unknown type")
363363
}
364-
blockEvt := event.New("chainsync.block", time.Now(), NewBlockHeaderContext(block.Header()), NewBlockEvent(block, c.includeCbor))
364+
blockEvt := event.New(
365+
"chainsync.block",
366+
time.Now(),
367+
NewBlockHeaderContext(block.Header()),
368+
NewBlockEvent(block, c.includeCbor),
369+
)
365370
tmpEvents = append(tmpEvents, blockEvt)
366371
for t, transaction := range block.Transactions() {
367372
resolvedInputs, err := resolveTransactionInputs(transaction, c)
@@ -371,8 +376,22 @@ func (c *ChainSync) handleRollForward(
371376
if t < 0 || t > math.MaxUint32 {
372377
return errors.New("invalid number of transactions")
373378
}
374-
txEvt := event.New("chainsync.transaction", time.Now(), NewTransactionContext(block, transaction, uint32(t), c.networkMagic),
375-
NewTransactionEvent(block, transaction, c.includeCbor, resolvedInputs))
379+
txEvt := event.New(
380+
"chainsync.transaction",
381+
time.Now(),
382+
NewTransactionContext(
383+
block,
384+
transaction,
385+
uint32(t),
386+
c.networkMagic,
387+
),
388+
NewTransactionEvent(
389+
block,
390+
transaction,
391+
c.includeCbor,
392+
resolvedInputs,
393+
),
394+
)
376395
tmpEvents = append(tmpEvents, txEvt)
377396
}
378397
updateTip := ochainsync.Tip{
@@ -409,7 +428,13 @@ func (c *ChainSync) handleRollForward(
409428
c.delayBuffer = slices.Delete(c.delayBuffer, 0, 1)
410429
}
411430
}
412-
c.updateStatus(updateTip.Point.Slot, updateTip.BlockNumber, hex.EncodeToString(updateTip.Point.Hash), tip.Point.Slot, hex.EncodeToString(tip.Point.Hash))
431+
c.updateStatus(
432+
updateTip.Point.Slot,
433+
updateTip.BlockNumber,
434+
hex.EncodeToString(updateTip.Point.Hash),
435+
tip.Point.Slot,
436+
hex.EncodeToString(tip.Point.Hash),
437+
)
413438
return nil
414439
}
415440

@@ -541,7 +566,9 @@ func getKupoClient(c *ChainSync) (*kugo.Client, error) {
541566
// Handle different error types
542567
switch {
543568
case errors.Is(err, context.DeadlineExceeded):
544-
return nil, errors.New("kupo health check timed out after 3 seconds")
569+
return nil, errors.New(
570+
"kupo health check timed out after 3 seconds",
571+
)
545572
case strings.Contains(err.Error(), "no such host"):
546573
return nil, fmt.Errorf("failed to resolve kupo host: %w", err)
547574
default:
@@ -551,7 +578,10 @@ func getKupoClient(c *ChainSync) (*kugo.Client, error) {
551578
defer resp.Body.Close()
552579

553580
if resp.StatusCode != http.StatusOK {
554-
return nil, fmt.Errorf("health check failed with status code: %d", resp.StatusCode)
581+
return nil, fmt.Errorf(
582+
"health check failed with status code: %d",
583+
resp.StatusCode,
584+
)
555585
}
556586

557587
c.kupoClient = k
@@ -579,15 +609,21 @@ func resolveTransactionInputs(
579609
txIndex := int(input.Index())
580610

581611
// Add timeout for matches query
582-
ctx, cancel := context.WithTimeout(context.Background(), defaultKupoTimeout)
612+
ctx, cancel := context.WithTimeout(
613+
context.Background(),
614+
defaultKupoTimeout,
615+
)
583616
defer cancel()
584617

585618
matches, err := k.Matches(ctx,
586619
kugo.TxOut(chainsync.NewTxID(txId, txIndex)),
587620
)
588621
if err != nil {
589622
if errors.Is(err, context.DeadlineExceeded) {
590-
return nil, fmt.Errorf("kupo matches query timed out after %v", defaultKupoTimeout)
623+
return nil, fmt.Errorf(
624+
"kupo matches query timed out after %v",
625+
defaultKupoTimeout,
626+
)
591627
}
592628
return nil, fmt.Errorf(
593629
"error fetching matches for input TxId: %s, Index: %d. Error: %w",

input/chainsync/chainsync_test.go

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,15 @@ func TestHandleRollBackward(t *testing.T) {
7777

7878
func TestGetKupoClient(t *testing.T) {
7979
// Setup test server
80-
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
81-
if r.URL.Path == "/health" {
82-
w.WriteHeader(http.StatusOK)
83-
return
84-
}
85-
w.WriteHeader(http.StatusNotFound)
86-
}))
80+
ts := httptest.NewServer(
81+
http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
82+
if r.URL.Path == "/health" {
83+
w.WriteHeader(http.StatusOK)
84+
return
85+
}
86+
w.WriteHeader(http.StatusNotFound)
87+
}),
88+
)
8789
defer ts.Close()
8890

8991
t.Run("successful client creation", func(t *testing.T) {
@@ -110,10 +112,14 @@ func TestGetKupoClient(t *testing.T) {
110112
})
111113

112114
t.Run("health check timeout", func(t *testing.T) {
113-
slowTS := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
114-
time.Sleep(4 * time.Second) // Longer than the 3s context timeout
115-
w.WriteHeader(http.StatusOK)
116-
}))
115+
slowTS := httptest.NewServer(
116+
http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
117+
time.Sleep(
118+
4 * time.Second,
119+
) // Longer than the 3s context timeout
120+
w.WriteHeader(http.StatusOK)
121+
}),
122+
)
117123
defer slowTS.Close()
118124

119125
c := &ChainSync{
@@ -122,13 +128,19 @@ func TestGetKupoClient(t *testing.T) {
122128

123129
_, err := getKupoClient(c)
124130
require.Error(t, err)
125-
assert.Contains(t, err.Error(), "kupo health check timed out after 3 seconds")
131+
assert.Contains(
132+
t,
133+
err.Error(),
134+
"kupo health check timed out after 3 seconds",
135+
)
126136
})
127137

128138
t.Run("failed health check status", func(t *testing.T) {
129-
failTS := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
130-
w.WriteHeader(http.StatusInternalServerError)
131-
}))
139+
failTS := httptest.NewServer(
140+
http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
141+
w.WriteHeader(http.StatusInternalServerError)
142+
}),
143+
)
132144
defer failTS.Close()
133145

134146
c := &ChainSync{
@@ -137,7 +149,11 @@ func TestGetKupoClient(t *testing.T) {
137149

138150
_, err := getKupoClient(c)
139151
require.Error(t, err)
140-
assert.Contains(t, err.Error(), "health check failed with status code: 500")
152+
assert.Contains(
153+
t,
154+
err.Error(),
155+
"health check failed with status code: 500",
156+
)
141157
})
142158

143159
t.Run("malformed URL", func(t *testing.T) {

0 commit comments

Comments
 (0)