Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add refunder to opbot #2838

Merged
merged 16 commits into from
Jul 5, 2024
2 changes: 1 addition & 1 deletion agents/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ require (
github.com/google/uuid v1.6.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
github.com/googleapis/gax-go/v2 v2.12.4 // indirect
github.com/gorilla/websocket v1.5.1 // indirect
github.com/gorilla/websocket v1.5.3 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 // indirect
github.com/hashicorp/consul/sdk v0.14.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
Expand Down
3 changes: 1 addition & 2 deletions agents/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -622,8 +622,7 @@ github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORR
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY=
github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY=
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
github.com/grafana/otel-profiling-go v0.5.1 h1:stVPKAFZSa7eGiqbYuG25VcqYksR6iWvF3YH66t4qL8=
github.com/grafana/otel-profiling-go v0.5.1/go.mod h1:ftN/t5A/4gQI19/8MoWurBEtC6gFw8Dns1sJZ9W4Tls=
github.com/grafana/pyroscope-go v1.1.1 h1:PQoUU9oWtO3ve/fgIiklYuGilvsm8qaGhlY4Vw6MAcQ=
Expand Down
44 changes: 42 additions & 2 deletions contrib/opbot/botmd/botmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@

import (
"context"
"fmt"
"github.com/slack-io/slacker"
"github.com/synapsecns/sanguine/contrib/opbot/config"
"github.com/synapsecns/sanguine/contrib/opbot/signoz"
"github.com/synapsecns/sanguine/core/dbcommon"
"github.com/synapsecns/sanguine/core/metrics"
signerConfig "github.com/synapsecns/sanguine/ethergo/signer/config"
"github.com/synapsecns/sanguine/ethergo/signer/signer"
"github.com/synapsecns/sanguine/ethergo/submitter"
cctpSql "github.com/synapsecns/sanguine/services/cctp-relayer/db/sql"
omnirpcClient "github.com/synapsecns/sanguine/services/omnirpc/client"
"golang.org/x/sync/errgroup"
)

// Bot represents the bot server.
Expand All @@ -15,6 +23,9 @@
cfg config.Config
signozClient *signoz.Client
signozEnabled bool
rpcClient omnirpcClient.RPCClient
signer signer.Signer
submitter submitter.TransactionSubmitter
}

// NewBot creates a new bot server.
Expand All @@ -32,8 +43,10 @@
bot.signozEnabled = true
}

bot.rpcClient = omnirpcClient.NewOmnirpcClient(cfg.OmniRPCURL, handler, omnirpcClient.WithCaptureReqRes())

Check warning on line 47 in contrib/opbot/botmd/botmd.go

View check run for this annotation

Codecov / codecov/patch

contrib/opbot/botmd/botmd.go#L46-L47

Added lines #L46 - L47 were not covered by tests
Comment on lines +46 to +47
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add tests for the new functionality.

The rpcClient initialization lacks test coverage. Ensure that tests are added to cover this initialization.

Do you want me to generate the unit testing code or open a GitHub issue to track this task?

Tools
GitHub Check: codecov/patch

[warning] 46-47: contrib/opbot/botmd/botmd.go#L46-L47
Added lines #L46 - L47 were not covered by tests

bot.addMiddleware(bot.tracingMiddleware(), bot.metricsMiddleware())
bot.addCommands(bot.traceCommand(), bot.rfqLookupCommand())
bot.addCommands(bot.traceCommand(), bot.rfqLookupCommand(), bot.rfqRefund())

Check warning on line 49 in contrib/opbot/botmd/botmd.go

View check run for this annotation

Codecov / codecov/patch

contrib/opbot/botmd/botmd.go#L49

Added line #L49 was not covered by tests
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add tests for the new functionality.

The addition of the rfqRefund command lacks test coverage. Ensure that tests are added to cover this functionality.

Do you want me to generate the unit testing code or open a GitHub issue to track this task?

Tools
GitHub Check: codecov/patch

[warning] 49-49: contrib/opbot/botmd/botmd.go#L49
Added line #L49 was not covered by tests


return bot
}
Expand All @@ -53,6 +66,33 @@
// Start starts the bot server.
// nolint: wrapcheck
func (b *Bot) Start(ctx context.Context) error {
var err error
b.signer, err = signerConfig.SignerFromConfig(ctx, b.cfg.Signer)
if err != nil {
return fmt.Errorf("failed to create signer: %w", err)
Comment on lines +70 to +72
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧠 logic: Error handling for signer creation should be reviewed to ensure it covers all edge cases.

Comment on lines +70 to +72
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧠 logic: Error handling for signer creation should be reviewed to ensure it covers all edge cases.

}

Check warning on line 73 in contrib/opbot/botmd/botmd.go

View check run for this annotation

Codecov / codecov/patch

contrib/opbot/botmd/botmd.go#L69-L73

Added lines #L69 - L73 were not covered by tests
Comment on lines +69 to +73
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add tests for the new functionality.

The initialization of the signer lacks test coverage. Ensure that tests are added to cover this initialization.

Do you want me to generate the unit testing code or open a GitHub issue to track this task?

Tools
GitHub Check: codecov/patch

[warning] 69-73: contrib/opbot/botmd/botmd.go#L69-L73
Added lines #L69 - L73 were not covered by tests


dbType, err := dbcommon.DBTypeFromString(b.cfg.Database.Type)
if err != nil {
return fmt.Errorf("could not get db type: %w", err)
Comment on lines +75 to +77
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧠 logic: Error handling for database type conversion should be reviewed to ensure it covers all edge cases.

Comment on lines +75 to +77
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧠 logic: Error handling for database type conversion should be reviewed to ensure it covers all edge cases.

}

Check warning on line 78 in contrib/opbot/botmd/botmd.go

View check run for this annotation

Codecov / codecov/patch

contrib/opbot/botmd/botmd.go#L75-L78

Added lines #L75 - L78 were not covered by tests
Comment on lines +75 to +78
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add tests for the new functionality.

The database connection lacks test coverage. Ensure that tests are added to cover this functionality.

Do you want me to generate the unit testing code or open a GitHub issue to track this task?

Tools
GitHub Check: codecov/patch

[warning] 75-78: contrib/opbot/botmd/botmd.go#L75-L78
Added lines #L75 - L78 were not covered by tests


store, err := cctpSql.Connect(ctx, dbType, b.cfg.Database.DSN, b.handler)
if err != nil {
return fmt.Errorf("could not connect to database: %w", err)
Comment on lines +80 to +82
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧠 logic: Error handling for database connection should be reviewed to ensure it covers all edge cases.

Comment on lines +80 to +82
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧠 logic: Error handling for database connection should be reviewed to ensure it covers all edge cases.

}

Check warning on line 83 in contrib/opbot/botmd/botmd.go

View check run for this annotation

Codecov / codecov/patch

contrib/opbot/botmd/botmd.go#L80-L83

Added lines #L80 - L83 were not covered by tests
Comment on lines +80 to +83
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add tests for the new functionality.

The connection to the database lacks test coverage. Ensure that tests are added to cover this functionality.

Do you want me to generate the unit testing code or open a GitHub issue to track this task?

Tools
GitHub Check: codecov/patch

[warning] 80-83: contrib/opbot/botmd/botmd.go#L80-L83
Added lines #L80 - L83 were not covered by tests


b.submitter = submitter.NewTransactionSubmitter(b.handler, b.signer, b.rpcClient, store.SubmitterDB(), &b.cfg.SubmitterConfig)

g, ctx := errgroup.WithContext(ctx)
g.Go(func() error {
return b.submitter.Start(ctx)
})

Check warning on line 90 in contrib/opbot/botmd/botmd.go

View check run for this annotation

Codecov / codecov/patch

contrib/opbot/botmd/botmd.go#L85-L90

Added lines #L85 - L90 were not covered by tests
Comment on lines +85 to +90
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add tests for the new functionality.

The initialization and starting of the submitter lack test coverage. Ensure that tests are added to cover this functionality.

Do you want me to generate the unit testing code or open a GitHub issue to track this task?

Tools
GitHub Check: codecov/patch

[warning] 85-90: contrib/opbot/botmd/botmd.go#L85-L90
Added lines #L85 - L90 were not covered by tests


g.Go(func() error {
return b.server.Listen(ctx)
})

Check warning on line 94 in contrib/opbot/botmd/botmd.go

View check run for this annotation

Codecov / codecov/patch

contrib/opbot/botmd/botmd.go#L92-L94

Added lines #L92 - L94 were not covered by tests
Comment on lines +92 to +94
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add tests for the new functionality.

The starting of the server lacks test coverage. Ensure that tests are added to cover this functionality.

Do you want me to generate the unit testing code or open a GitHub issue to track this task?

Tools
GitHub Check: codecov/patch

[warning] 92-94: contrib/opbot/botmd/botmd.go#L92-L94
Added lines #L92 - L94 were not covered by tests


// nolint: wrapcheck
return b.server.Listen(ctx)
return g.Wait()

Check warning on line 97 in contrib/opbot/botmd/botmd.go

View check run for this annotation

Codecov / codecov/patch

contrib/opbot/botmd/botmd.go#L97

Added line #L97 was not covered by tests
}
83 changes: 83 additions & 0 deletions contrib/opbot/botmd/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,21 @@

import (
"fmt"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/hako/durafmt"
"github.com/slack-go/slack"
"github.com/slack-io/slacker"
"github.com/synapsecns/sanguine/contrib/opbot/signoz"
"github.com/synapsecns/sanguine/ethergo/chaindata"
rfqClient "github.com/synapsecns/sanguine/services/rfq/api/client"
"github.com/synapsecns/sanguine/services/rfq/contracts/fastbridge"
"github.com/synapsecns/sanguine/services/rfq/relayer/relapi"
"log"
"math/big"
"regexp"
"strconv"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -239,6 +245,83 @@
}}
}

func (b *Bot) rfqRefund() *slacker.CommandDefinition {
return &slacker.CommandDefinition{
Command: "refund <tx> <origin_chainid>",
Description: "refund a quote request",
Examples: []string{"refund 0x1234"},
Handler: func(ctx *slacker.CommandContext) {
client, err := rfqClient.NewUnauthenticatedClient(b.handler, b.cfg.RFQApiURL)
if err != nil {
log.Printf("error creating rfq client: %v\n", err)
return
}

Check warning on line 258 in contrib/opbot/botmd/commands.go

View check run for this annotation

Codecov / codecov/patch

contrib/opbot/botmd/commands.go#L248-L258

Added lines #L248 - L258 were not covered by tests
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reduce the cognitive complexity of the rfqRefund function.

The function has a high cognitive complexity (46). Consider refactoring to break down the function into smaller, more manageable functions.

func (b *Bot) rfqRefund() *slacker.CommandDefinition {
	return &slacker.CommandDefinition{
		Command:     "refund <tx> <origin_chainid>",
		Description: "refund a quote request",
		Examples:    []string{"refund 0x1234"},
		Handler: func(ctx *slacker.CommandContext) {
			if err := b.handleRFQRefund(ctx); err != nil {
				log.Println(err)
			}
		},
	}
}

func (b *Bot) handleRFQRefund(ctx *slacker.CommandContext) error {
	client, err := rfqClient.NewUnauthenticatedClient(b.handler, b.cfg.RFQApiURL)
	if err != nil {
		log.Printf("error creating rfq client: %v\n", err)
		return err
	}

	contracts, err := client.GetRFQContracts(ctx.Context())
	if err != nil {
		log.Printf("error fetching rfq contracts: %v\n", err)
		_, err := ctx.Response().Reply("error fetching rfq contracts")
		if err != nil {
			return err
		}
		return err
	}

	tx := stripLinks(ctx.Request().Param("tx"))
	if len(tx) == 0 {
		_, err := ctx.Response().Reply("please provide a tx hash")
		if err != nil {
			log.Println(err)
		}
		return nil
	}

	originChainID, err := b.getOriginChainID(ctx)
	if err != nil {
		return err
	}

	chainClient, err := b.rpcClient.GetChainClient(ctx.Context(), originChainID)
	if err != nil {
		log.Printf("error getting chain client: %v\n", err)
		return err
	}

	contractAddress, ok := contracts.Contracts[uint32(originChainID)]
	if !ok {
		_, err := ctx.Response().Reply("contract address not found")
		if err != nil {
			log.Println(err)
		}
		return nil
	}

	fastBridgeHandle, err := fastbridge.NewFastBridge(common.HexToAddress(contractAddress), chainClient)
	if err != nil {
		log.Printf("error creating fast bridge: %v\n", err)
		return err
	}

	return b.submitRefund(ctx, fastBridgeHandle, tx, originChainID)
}

func (b *Bot) getOriginChainID(ctx *slacker.CommandContext) (int, error) {
	originChainIDStr := ctx.Request().Param("origin_chainid")
	if len(originChainIDStr) == 0 {
		_, err := ctx.Response().Reply("please provide an origin chain id")
		if err != nil {
			log.Println(err)
		}
		return 0, nil
	}

	originChainID, err := strconv.Atoi(convertChainName(originChainIDStr))
	if err != nil {
		_, err := ctx.Response().Reply("origin_chainid must be a number")
		if err != nil {
			log.Println(err)
		}
		return 0, err
	}

	return originChainID, nil
}

func (b *Bot) submitRefund(ctx *slacker.CommandContext, fastBridgeHandle *fastbridge.FastBridgeTransactor, tx string, originChainID int) error {
	for _, relayer := range b.cfg.RelayerURLS {
		relClient := relapi.NewRelayerClient(b.handler, relayer)

		rawRequest, err := getQuoteRequest(ctx.Context(), relClient, tx)
		if err != nil {
			_, err := ctx.Response().Reply("error fetching quote request")
			if err != nil {
				log.Println(err)
			}
			return err
		}

		nonce, err := b.submitter.SubmitTransaction(ctx.Context(), big.NewInt(int64(originChainID)), func(transactor *bind.TransactOpts) (*types.Transaction, error) {
			return fastBridgeHandle.Refund(transactor, common.Hex2Bytes(rawRequest.QuoteRequestRaw))
		})
		if err != nil {
			log.Printf("error submitting refund: %v\n", err)
			continue
		}

		if _, err := ctx.Response().Reply(fmt.Sprintf("refund submitted with nonce %d", nonce)); err != nil {
			log.Println(err)
		}
		return nil
	}
	return nil
}
Tools
GitHub Check: codecov/patch

[warning] 249-259: contrib/opbot/botmd/commands.go#L249-L259
Added lines #L249 - L259 were not covered by tests

GitHub Check: Lint (contrib/opbot)

[failure] 249-249:
cognitive complexity 46 of func (*Bot).rfqRefund is high (> 30) (gocognit)


contracts, err := client.GetRFQContracts(ctx.Context())
if err != nil {
log.Printf("error fetching rfq contracts: %v\n", err)
return
}

Check warning on line 264 in contrib/opbot/botmd/commands.go

View check run for this annotation

Codecov / codecov/patch

contrib/opbot/botmd/commands.go#L260-L264

Added lines #L260 - L264 were not covered by tests

tx := stripLinks(ctx.Request().Param("tx"))
originChainIDStr := ctx.Request().Param("origin_chainid")

originChainID, err := strconv.Atoi(originChainIDStr)
if err != nil {
_, err := ctx.Response().Reply("origin_chainid must be a number")
if err != nil {
log.Println(err)
}
return

Check warning on line 275 in contrib/opbot/botmd/commands.go

View check run for this annotation

Codecov / codecov/patch

contrib/opbot/botmd/commands.go#L266-L275

Added lines #L266 - L275 were not covered by tests
}

chainClient, err := b.rpcClient.GetChainClient(ctx.Context(), originChainID)
if err != nil {
log.Printf("error getting chain client: %v\n", err)
return
}

Check warning on line 282 in contrib/opbot/botmd/commands.go

View check run for this annotation

Codecov / codecov/patch

contrib/opbot/botmd/commands.go#L278-L282

Added lines #L278 - L282 were not covered by tests

contractAddress, ok := contracts.Contracts[uint32(originChainID)]
if !ok {
_, err := ctx.Response().Reply("contract address not found")
if err != nil {
log.Println(err)
}
return

Check warning on line 290 in contrib/opbot/botmd/commands.go

View check run for this annotation

Codecov / codecov/patch

contrib/opbot/botmd/commands.go#L284-L290

Added lines #L284 - L290 were not covered by tests
}

fastBridgeHandle, err := fastbridge.NewFastBridge(common.HexToAddress(contractAddress), chainClient)
if err != nil {
log.Printf("error creating fast bridge: %v\n", err)
return
}

Check warning on line 297 in contrib/opbot/botmd/commands.go

View check run for this annotation

Codecov / codecov/patch

contrib/opbot/botmd/commands.go#L293-L297

Added lines #L293 - L297 were not covered by tests

for _, relayer := range b.cfg.RelayerURLS {
relClient := relapi.NewRelayerClient(b.handler, relayer)
qr, err := relClient.GetQuoteRequestByTXID(ctx.Context(), tx)
if err != nil {
log.Printf("error fetching quote request: %v\n", err)
continue

Check warning on line 304 in contrib/opbot/botmd/commands.go

View check run for this annotation

Codecov / codecov/patch

contrib/opbot/botmd/commands.go#L299-L304

Added lines #L299 - L304 were not covered by tests
}

nonce, err := b.submitter.SubmitTransaction(ctx.Context(), big.NewInt(int64(originChainID)), func(transactor *bind.TransactOpts) (tx *types.Transaction, err error) {
return fastBridgeHandle.Refund(transactor, common.Hex2Bytes(qr.QuoteRequestRaw))

Check failure on line 308 in contrib/opbot/botmd/commands.go

View workflow job for this annotation

GitHub Actions / Lint (contrib/opbot)

error returned from external package is unwrapped: sig: func (*github.com/synapsecns/sanguine/services/rfq/contracts/fastbridge.FastBridgeTransactor).Refund(opts *github.com/ethereum/go-ethereum/accounts/abi/bind.TransactOpts, request []byte) (*github.com/ethereum/go-ethereum/core/types.Transaction, error) (wrapcheck)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrap the error returned from the external package.

The error returned from fastBridgeHandle.Refund should be wrapped to provide more context.

-  return fastBridgeHandle.Refund(transactor, common.Hex2Bytes(qr.QuoteRequestRaw))
+  tx, err := fastBridgeHandle.Refund(transactor, common.Hex2Bytes(qr.QuoteRequestRaw))
+  if err != nil {
+    return nil, fmt.Errorf("failed to refund: %w", err)
+  }
+  return tx, nil
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
return fastBridgeHandle.Refund(transactor, common.Hex2Bytes(qr.QuoteRequestRaw))
tx, err := fastBridgeHandle.Refund(transactor, common.Hex2Bytes(qr.QuoteRequestRaw))
if err != nil {
return nil, fmt.Errorf("failed to refund: %w", err)
}
return tx, nil
Tools
GitHub Check: Lint (contrib/opbot)

[failure] 308-308:
error returned from external package is unwrapped: sig: func (*github.com/synapsecns/sanguine/services/rfq/contracts/fastbridge.FastBridgeTransactor).Refund(opts *github.com/ethereum/go-ethereum/accounts/abi/bind.TransactOpts, request []byte) (*github.com/ethereum/go-ethereum/core/types.Transaction, error) (wrapcheck)

})
if err != nil {
log.Printf("error submitting refund: %v\n", err)
continue

Check warning on line 312 in contrib/opbot/botmd/commands.go

View check run for this annotation

Codecov / codecov/patch

contrib/opbot/botmd/commands.go#L307-L312

Added lines #L307 - L312 were not covered by tests
}

_, err = ctx.Response().Reply(fmt.Sprintf("refund submitted with nonce %d", nonce))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix ineffectual assignment to err.

The variable err is assigned but not used.

-  _, err = ctx.Response().Reply(fmt.Sprintf("refund submitted with nonce %d", nonce))
+  if _, err := ctx.Response().Reply(fmt.Sprintf("refund submitted with nonce %d", nonce)); err != nil {
+    log.Println(err)
+  }
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
_, err = ctx.Response().Reply(fmt.Sprintf("refund submitted with nonce %d", nonce))
if _, err := ctx.Response().Reply(fmt.Sprintf("refund submitted with nonce %d", nonce)); err != nil {
log.Println(err)
}
Tools
GitHub Check: codecov/patch

[warning] 341-345: contrib/opbot/botmd/commands.go#L341-L345
Added lines #L341 - L345 were not covered by tests

if err != nil {
log.Println(err)
}
return

Check warning on line 319 in contrib/opbot/botmd/commands.go

View check run for this annotation

Codecov / codecov/patch

contrib/opbot/botmd/commands.go#L315-L319

Added lines #L315 - L319 were not covered by tests
}
},
}
}

func toExplorerSlackLink(ogHash string) string {
rfqHash := strings.ToUpper(ogHash)
// cut off 0x
Expand Down
5 changes: 3 additions & 2 deletions contrib/opbot/botmd/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@
func (b *Bot) tracingMiddleware() slacker.CommandMiddlewareHandler {
return func(next slacker.CommandHandler) slacker.CommandHandler {
return func(cmdCtx *slacker.CommandContext) {
// TODO: context is not inherited here.
_, span := b.handler.Tracer().Start(cmdCtx.Context(), fmt.Sprintf("command.%s", cmdCtx.Definition().Command), trace.WithAttributes(
ctx, span := b.handler.Tracer().Start(cmdCtx.Context(), fmt.Sprintf("command.%s", cmdCtx.Definition().Command), trace.WithAttributes(

Check warning on line 24 in contrib/opbot/botmd/middleware.go

View check run for this annotation

Codecov / codecov/patch

contrib/opbot/botmd/middleware.go#L24

Added line #L24 was not covered by tests
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tip

Codebase Verification

Add tests for new functionality.

The new functionality added to the tracingMiddleware method is not covered by tests. Ensure that tests are added to cover:

  • Context inheritance using ctx.

  • Span creation with appropriate attributes.

  • contrib/opbot/botmd/middleware.go

Analysis chain

Add tests for new functionality.

The new functionality added to the tracingMiddleware method is not covered by tests. Ensure that tests are added to cover:

  • Context inheritance using ctx.
  • Span creation with appropriate attributes.
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify test coverage for new functionality in `tracingMiddleware`.

# Test: Search for test cases covering the `tracingMiddleware` method. Expect: Test cases covering all new functionality.
rg --type go 'tracingMiddleware'

Length of output: 233



Script:

#!/bin/bash
# Description: Verify test coverage for the `tracingMiddleware` method by searching for test files and functions.

# Find all test files in the repository.
fd --type f --name '*_test.go'

# Search for test functions that might cover `tracingMiddleware`.
rg --type go 'func Test' | rg 'tracingMiddleware'

Length of output: 333



Script:

#!/bin/bash
# Description: Verify test coverage for the `tracingMiddleware` method by searching for test files and functions.

# Find all test files in the repository.
fd '_test.go$'

# Search for references to `tracingMiddleware` within test files.
rg 'tracingMiddleware' $(fd '_test.go$')

Length of output: 25161

Tools
GitHub Check: codecov/patch

[warning] 24-24: contrib/opbot/botmd/middleware.go#L24
Added line #L24 was not covered by tests

attribute.String("user_id", cmdCtx.Event().UserID),
attribute.String("channel_id", cmdCtx.Event().Channel.ID),
))

cmdCtx.WithContext(ctx)

Check warning on line 30 in contrib/opbot/botmd/middleware.go

View check run for this annotation

Codecov / codecov/patch

contrib/opbot/botmd/middleware.go#L29-L30

Added lines #L29 - L30 were not covered by tests
Comment on lines +29 to +30
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tip

Codebase Verification

Add tests for new functionality.

The tracingMiddleware method is not covered by any existing test cases. Please add tests to ensure the following functionalities are covered:

  • Context inheritance using ctx.

  • Span creation with appropriate attributes.

  • contrib/opbot/botmd/middleware.go

Analysis chain

Add tests for new functionality.

The new functionality added to the tracingMiddleware method is not covered by tests. Ensure that tests are added to cover:

  • Context inheritance using ctx.
  • Span creation with appropriate attributes.
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify test coverage for new functionality in `tracingMiddleware`.

# Test: Search for test cases covering the `tracingMiddleware` method. Expect: Test cases covering all new functionality.
rg --type go 'tracingMiddleware'

Length of output: 233



Script:

#!/bin/bash
# Description: Verify if there are tests covering the `tracingMiddleware` method.

# Find all Go test files in the repository
test_files=$(fd --type f --extension go --glob '*_test.go')

# Search for test cases covering the `tracingMiddleware` method in the test files
for file in $test_files; do
    echo "Checking $file"
    rg 'tracingMiddleware' "$file"
done

Length of output: 75047

Tools
GitHub Check: codecov/patch

[warning] 29-30: contrib/opbot/botmd/middleware.go#L29-L30
Added lines #L29 - L30 were not covered by tests

defer func() {
metrics.EndSpan(span)
}()
Expand Down
21 changes: 21 additions & 0 deletions contrib/opbot/config/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
// Package config provides a simple way to read and write configuration files.
package config

import (
"github.com/synapsecns/sanguine/ethergo/signer/config"
submitterConfig "github.com/synapsecns/sanguine/ethergo/submitter/config"
)

// Config represents the configuration of the application.
type Config struct {
// SlackBotToken is the token of the slack bot.
Expand All @@ -18,4 +23,20 @@ type Config struct {
SignozBaseURL string `yaml:"signoz_base_url"`
// RelayerURLS is the list of RFQ relayer URLs.
RelayerURLS []string `yaml:"rfq_relayer_urls"`
// RFQApiURL is the URL of the RFQ API.
RFQApiURL string `yaml:"rfq_api_url"`
// OmniRPCURL is the URL of the Omni RPC.
OmniRPCURL string `yaml:"omni_rpc_url"`
// Signer is the signer config.
Signer config.SignerConfig `yaml:"signer"`
// SubmitterConfig is the submitter config.
SubmitterConfig submitterConfig.Config `yaml:"submitter_config"`
// Database is the database config.
Database DatabaseConfig `yaml:"database"`
}

// DatabaseConfig represents the configuration for the database.
type DatabaseConfig struct {
Type string `yaml:"type"`
DSN string `yaml:"dsn"` // Data Source Name
}
35 changes: 24 additions & 11 deletions contrib/opbot/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ require (
github.com/google/uuid v1.6.0
github.com/hako/durafmt v0.0.0-20210608085754-5c1018a4e16b
github.com/hedzr/log v1.6.3
github.com/ipfs/go-log v1.0.5
github.com/joho/godotenv v1.5.1
github.com/keybase/go-keychain v0.0.0-20231219164618-57a3676c3af6
github.com/mailru/easyjson v0.7.7
Expand All @@ -23,13 +24,19 @@ require (
github.com/slack-io/slacker v0.1.0
github.com/synapsecns/sanguine/core v0.0.0-00010101000000-000000000000
github.com/synapsecns/sanguine/ethergo v0.1.0
github.com/synapsecns/sanguine/services/cctp-relayer v0.0.0-00010101000000-000000000000
github.com/synapsecns/sanguine/services/omnirpc v0.0.0-00010101000000-000000000000
github.com/synapsecns/sanguine/services/rfq v0.0.0-00010101000000-000000000000
github.com/urfave/cli/v2 v2.27.2
go.opentelemetry.io/otel v1.27.0
go.opentelemetry.io/otel/metric v1.27.0
go.opentelemetry.io/otel/trace v1.27.0
golang.org/x/sync v0.7.0
gopkg.in/yaml.v2 v2.4.0
gopkg.in/yaml.v3 v3.0.1
gorm.io/driver/mysql v1.5.6
gorm.io/driver/sqlite v1.5.6
gorm.io/gorm v1.25.10
k8s.io/apimachinery v0.29.3
)

Expand All @@ -44,6 +51,7 @@ require (
dario.cat/mergo v1.0.0 // indirect
github.com/DataDog/zstd v1.5.2 // indirect
github.com/ImVexed/fasturl v0.0.0-20230304231329-4e41488060f3 // indirect
github.com/KyleBanks/depth v1.2.1 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/ProtonMail/go-crypto v1.0.0 // indirect
github.com/VictoriaMetrics/fastcache v1.12.1 // indirect
Expand Down Expand Up @@ -127,9 +135,14 @@ require (
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-ole/go-ole v1.3.0 // indirect
github.com/go-openapi/jsonpointer v0.20.2 // indirect
github.com/go-openapi/jsonreference v0.20.4 // indirect
github.com/go-openapi/spec v0.20.14 // indirect
github.com/go-openapi/swag v0.22.9 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.20.0 // indirect
github.com/go-sql-driver/mysql v1.7.0 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/gofrs/flock v0.8.1 // indirect
github.com/gogo/protobuf v1.3.3 // indirect
Expand All @@ -139,7 +152,7 @@ require (
github.com/google/s2a-go v0.1.7 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
github.com/googleapis/gax-go/v2 v2.12.4 // indirect
github.com/gorilla/websocket v1.5.1 // indirect
github.com/gorilla/websocket v1.5.3 // indirect
github.com/grafana/otel-profiling-go v0.5.1 // indirect
github.com/grafana/pyroscope-go v1.1.1 // indirect
github.com/grafana/pyroscope-go/godeltaprof v0.1.7 // indirect
Expand All @@ -149,11 +162,12 @@ require (
github.com/holiman/bloomfilter/v2 v2.0.3 // indirect
github.com/holiman/uint256 v1.2.4 // indirect
github.com/huin/goupnp v1.3.0 // indirect
github.com/imkira/go-interpol v1.1.0 // indirect
github.com/integralist/go-findroot v0.0.0-20160518114804-ac90681525dc // indirect
github.com/ipfs/go-log v1.0.5 // indirect
github.com/ipfs/go-log/v2 v2.5.1 // indirect
github.com/jackpal/go-nat-pmp v1.0.2 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/jellydator/ttlcache/v3 v3.1.1 // indirect
github.com/jftuga/ellipsis v1.0.0 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
Expand All @@ -173,6 +187,7 @@ require (
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-localereader v0.0.1 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/mattn/go-sqlite3 v2.0.3+incompatible // indirect
github.com/mattn/go-tty v0.0.3 // indirect
github.com/miguelmota/go-ethereum-hdwallet v0.1.1 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
Expand Down Expand Up @@ -202,13 +217,15 @@ require (
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect
github.com/shibukawa/configdir v0.0.0-20170330084843-e180dbdc8da0 // indirect
github.com/shirou/gopsutil v3.21.11+incompatible // indirect
github.com/shomali11/commander v0.0.0-20230730023802-0b64f620037d // indirect
github.com/shomali11/proper v0.0.0-20190608032528-6e70a05688e7 // indirect
github.com/shopspring/decimal v1.4.0 // indirect
github.com/skeema/knownhosts v1.2.2 // indirect
github.com/slack-io/commander v0.0.0-20231120025847-9fd78b4b2d54 // indirect
github.com/slack-io/proper v0.0.0-20231119200853-f78ba4fc878f // indirect
github.com/stretchr/testify v1.9.0 // indirect
github.com/supranational/blst v0.3.11 // indirect
github.com/synapsecns/sanguine/services/cctp-relayer v0.0.0-00010101000000-000000000000 // indirect
github.com/synapsecns/sanguine/services/omnirpc v0.0.0-00010101000000-000000000000 // indirect
github.com/swaggo/files v1.0.1 // indirect
github.com/swaggo/gin-swagger v1.6.0 // indirect
github.com/swaggo/swag v1.16.3 // indirect
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 // indirect
github.com/teivah/onecontext v1.3.0 // indirect
github.com/tklauser/go-sysconf v0.3.12 // indirect
Expand Down Expand Up @@ -248,7 +265,6 @@ require (
golang.org/x/mod v0.18.0 // indirect
golang.org/x/net v0.26.0 // indirect
golang.org/x/oauth2 v0.21.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/time v0.5.0 // indirect
Expand All @@ -260,7 +276,6 @@ require (
google.golang.org/grpc v1.64.0 // indirect
google.golang.org/protobuf v1.34.1 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gorm.io/gorm v1.25.10 // indirect
k8s.io/klog/v2 v2.120.1 // indirect
k8s.io/utils v0.0.0-20230726121419-3b25d923346b // indirect
rsc.io/tmplfunc v0.0.3 // indirect
Expand All @@ -271,9 +286,7 @@ replace (
// later versions give errors on uint64 being too high.
github.com/brianvoe/gofakeit/v6 => github.com/brianvoe/gofakeit/v6 v6.9.0
github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1
github.com/slack-go/slack => github.com/slack-go/slack v0.12.2
// TODO: replace after https://github.com/slack-io/slacker/pull/14 is merged
github.com/slack-io/slacker => github.com/kathiouchka/slacker v0.0.0-20240629123301-04d4e71c3a96
github.com/slack-io/slacker => github.com/slack-io/slacker v0.1.1-0.20240701203341-bd3ee211e9d2
github.com/synapsecns/sanguine/core => ./../../core
github.com/synapsecns/sanguine/ethergo => ./../../ethergo
github.com/synapsecns/sanguine/services/cctp-relayer => ./../../services/cctp-relayer
Expand Down
Loading
Loading