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
4 changes: 2 additions & 2 deletions agents/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -622,8 +622,8 @@ 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/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
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
48 changes: 44 additions & 4 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,10 +23,13 @@
cfg config.Config
signozClient *signoz.Client
signozEnabled bool
rpcClient omnirpcClient.RPCClient
signer signer.Signer
submitter submitter.TransactionSubmitter
}

// NewBot creates a new bot server.
func NewBot(handler metrics.Handler, cfg config.Config) Bot {
func NewBot(handler metrics.Handler, cfg config.Config) *Bot {

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

View check run for this annotation

Codecov / codecov/patch

contrib/opbot/botmd/botmd.go#L32

Added line #L32 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 following functionalities lack test coverage:

  • rpcClient initialization
  • rfqRefund command
  • signer initialization
  • Database connection
  • submitter initialization
  • Server start

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

Also applies to: 46-47, 49-49, 51-51, 69-73, 75-78, 80-83, 85-90, 92-94, 97-97

Tools
GitHub Check: codecov/patch

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

server := slacker.NewClient(cfg.SlackBotToken, cfg.SlackAppToken)
bot := Bot{
handler: handler,
Expand All @@ -32,10 +43,12 @@
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
return &bot

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

View check run for this annotation

Codecov / codecov/patch

contrib/opbot/botmd/botmd.go#L51

Added line #L51 was not covered by tests
}

func (b *Bot) addMiddleware(middlewares ...slacker.CommandMiddlewareHandler) {
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
}
121 changes: 121 additions & 0 deletions contrib/opbot/botmd/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,22 @@
package botmd

import (
"context"
"errors"
"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"
"strings"
"sync"
Expand Down Expand Up @@ -239,6 +246,103 @@
}}
}

// nolint: gocognit, cyclop.
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) {
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

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

View check run for this annotation

Codecov / codecov/patch

contrib/opbot/botmd/commands.go#L250-L263

Added lines #L250 - L263 were not covered by tests
}

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

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

View check run for this annotation

Codecov / codecov/patch

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

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

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

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

View check run for this annotation

Codecov / codecov/patch

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

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

fastBridgeContract, err := b.makeFastBridge(ctx.Context(), rawRequest)
if err != nil {
_, err := ctx.Response().Reply(err.Error())
if err != nil {
log.Println(err)
}
return

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

View check run for this annotation

Codecov / codecov/patch

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

Added lines #L287 - L293 were not covered by tests
}
nonce, err := b.submitter.SubmitTransaction(ctx.Context(), big.NewInt(int64(rawRequest.OriginChainID)), func(transactor *bind.TransactOpts) (tx *types.Transaction, err error) {
tx, err = fastBridgeContract.Refund(transactor, common.Hex2Bytes(rawRequest.QuoteRequestRaw))
if err != nil {
return nil, fmt.Errorf("error submitting refund: %w", err)
}
return tx, nil

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

View check run for this annotation

Codecov / codecov/patch

contrib/opbot/botmd/commands.go#L295-L300

Added lines #L295 - L300 were not covered by tests
})
if err != nil {
log.Printf("error submitting refund: %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#L302-L304

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

// TODO: follow the lead of https://github.com/synapsecns/sanguine/pull/2845
_, 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 312 in contrib/opbot/botmd/commands.go

View check run for this annotation

Codecov / codecov/patch

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

Added lines #L308 - L312 were not covered by tests
}
},
}
}

func (b *Bot) makeFastBridge(ctx context.Context, req *relapi.GetQuoteRequestResponse) (*fastbridge.FastBridge, error) {
client, err := rfqClient.NewUnauthenticatedClient(b.handler, b.cfg.RFQApiURL)
if err != nil {
return nil, fmt.Errorf("error creating rfq client: %w", err)
}

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

View check run for this annotation

Codecov / codecov/patch

contrib/opbot/botmd/commands.go#L318-L322

Added lines #L318 - L322 were not covered by tests

contracts, err := client.GetRFQContracts(ctx)
if err != nil {
return nil, fmt.Errorf("error fetching rfq contracts: %w", err)
}

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

View check run for this annotation

Codecov / codecov/patch

contrib/opbot/botmd/commands.go#L324-L327

Added lines #L324 - L327 were not covered by tests

chainClient, err := b.rpcClient.GetChainClient(ctx, int(req.OriginChainID))
if err != nil {
return nil, fmt.Errorf("error getting chain client: %w", err)
}

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

View check run for this annotation

Codecov / codecov/patch

contrib/opbot/botmd/commands.go#L329-L332

Added lines #L329 - L332 were not covered by tests

contractAddress, ok := contracts.Contracts[req.OriginChainID]
if !ok {
return nil, errors.New("contract address not found")
}

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

View check run for this annotation

Codecov / codecov/patch

contrib/opbot/botmd/commands.go#L334-L337

Added lines #L334 - L337 were not covered by tests

fastBridgeHandle, err := fastbridge.NewFastBridge(common.HexToAddress(contractAddress), chainClient)
if err != nil {
return nil, fmt.Errorf("error creating fast bridge: %w", err)
}
return fastBridgeHandle, nil

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

View check run for this annotation

Codecov / codecov/patch

contrib/opbot/botmd/commands.go#L339-L343

Added lines #L339 - L343 were not covered by tests
}
Comment on lines +318 to +344
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 fastbridge.NewFastBridge should be wrapped to provide more context.

-	return nil, fmt.Errorf("error creating fast bridge: %w", err)
+	return nil, fmt.Errorf("error creating fast bridge: %w", err)

Committable suggestion was skipped due to low confidence.

Tools
GitHub Check: codecov/patch

[warning] 316-320: contrib/opbot/botmd/commands.go#L316-L320
Added lines #L316 - L320 were not covered by tests


[warning] 322-325: contrib/opbot/botmd/commands.go#L322-L325
Added lines #L322 - L325 were not covered by tests


[warning] 327-330: contrib/opbot/botmd/commands.go#L327-L330
Added lines #L327 - L330 were not covered by tests


[warning] 332-335: contrib/opbot/botmd/commands.go#L332-L335
Added lines #L332 - L335 were not covered by tests


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


func toExplorerSlackLink(ogHash string) string {
rfqHash := strings.ToUpper(ogHash)
// cut off 0x
Expand All @@ -264,3 +368,20 @@
linkRegex := regexp.MustCompile(`<https?://[^|>]+\|([^>]+)>`)
return linkRegex.ReplaceAllString(input, "$1")
}

func getQuoteRequest(ctx context.Context, client relapi.RelayerClient, tx string) (*relapi.GetQuoteRequestResponse, error) {
// at this point tx can be a txid or a has, we try both
txRequest, err := client.GetQuoteRequestStatusByTxHash(ctx, tx)
if err == nil {
// override tx with txid
tx = txRequest.TxID
}

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

View check run for this annotation

Codecov / codecov/patch

contrib/opbot/botmd/commands.go#L372-L378

Added lines #L372 - L378 were not covered by tests
Comment on lines +372 to +378
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure error handling for GetQuoteRequestStatusByTxHash.

The error handling for GetQuoteRequestStatusByTxHash should be improved to provide more context.

-  txRequest, err := client.GetQuoteRequestStatusByTxHash(ctx, tx)
-  if err == nil {
+  txRequest, err := client.GetQuoteRequestStatusByTxHash(ctx, tx)
+  if err != nil {
+    return nil, fmt.Errorf("error fetching quote request status by tx hash: %w", 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
func getQuoteRequest(ctx context.Context, client relapi.RelayerClient, tx string) (*relapi.GetQuoteRequestResponse, error) {
// at this point tx can be a txid or a has, we try both
txRequest, err := client.GetQuoteRequestStatusByTxHash(ctx, tx)
if err == nil {
// override tx with txid
tx = txRequest.TxID
}
func getQuoteRequest(ctx context.Context, client relapi.RelayerClient, tx string) (*relapi.GetQuoteRequestResponse, error) {
// at this point tx can be a txid or a has, we try both
txRequest, err := client.GetQuoteRequestStatusByTxHash(ctx, tx)
if err != nil {
return nil, fmt.Errorf("error fetching quote request status by tx hash: %w", err)
}
// override tx with txid
tx = txRequest.TxID
Tools
GitHub Check: codecov/patch

[warning] 387-393: contrib/opbot/botmd/commands.go#L387-L393
Added lines #L387 - L393 were not covered by tests


// look up quote request
qr, err := client.GetQuoteRequestByTXID(ctx, tx)
if err != nil {
return nil, fmt.Errorf("error fetching quote request: %w", err)
}

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

View check run for this annotation

Codecov / codecov/patch

contrib/opbot/botmd/commands.go#L381-L384

Added lines #L381 - L384 were not covered by tests
Comment on lines +381 to +384
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure error handling for GetQuoteRequestByTXID.

The error handling for GetQuoteRequestByTXID should be improved to provide more context.

-  qr, err := client.GetQuoteRequestByTXID(ctx, tx)
-  if err != nil {
-    return nil, fmt.Errorf("error fetching quote request: %w", err)
+  qr, err := client.GetQuoteRequestByTXID(ctx, tx)
+  if err != nil {
+    return nil, fmt.Errorf("error fetching quote request by tx id: %w", 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
qr, err := client.GetQuoteRequestByTXID(ctx, tx)
if err != nil {
return nil, fmt.Errorf("error fetching quote request: %w", err)
}
qr, err := client.GetQuoteRequestByTXID(ctx, tx)
if err != nil {
return nil, fmt.Errorf("error fetching quote request by tx id: %w", err)
}
Tools
GitHub Check: codecov/patch

[warning] 396-399: contrib/opbot/botmd/commands.go#L396-L399
Added lines #L396 - L399 were not covered by tests


return qr, nil

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

View check run for this annotation

Codecov / codecov/patch

contrib/opbot/botmd/commands.go#L386

Added line #L386 was not covered by tests
Comment on lines +372 to +386
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure error handling for GetQuoteRequestByTXID.

The error handling for GetQuoteRequestByTXID should be improved to provide more context.

-	qr, err := client.GetQuoteRequestByTXID(ctx, tx)
-	if err != nil {
-		return nil, fmt.Errorf("error fetching quote request: %w", err)
+	qr, err := client.GetQuoteRequestByTXID(ctx, tx)
+	if err != nil {
+		return nil, fmt.Errorf("error fetching quote request by tx id: %w", 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
func getQuoteRequest(ctx context.Context, client relapi.RelayerClient, tx string) (*relapi.GetQuoteRequestResponse, error) {
// at this point tx can be a txid or a has, we try both
txRequest, err := client.GetQuoteRequestStatusByTxHash(ctx, tx)
if err == nil {
// override tx with txid
tx = txRequest.TxID
}
// look up quote request
qr, err := client.GetQuoteRequestByTXID(ctx, tx)
if err != nil {
return nil, fmt.Errorf("error fetching quote request: %w", err)
}
return qr, nil
func getQuoteRequest(ctx context.Context, client relapi.RelayerClient, tx string) (*relapi.GetQuoteRequestResponse, error) {
// at this point tx can be a txid or a has, we try both
txRequest, err := client.GetQuoteRequestStatusByTxHash(ctx, tx)
if err == nil {
// override tx with txid
tx = txRequest.TxID
}
// look up quote request
qr, err := client.GetQuoteRequestByTXID(ctx, tx)
if err != nil {
return nil, fmt.Errorf("error fetching quote request by tx id: %w", err)
}
return qr, nil
}
Tools
GitHub Check: codecov/patch

[warning] 370-376: contrib/opbot/botmd/commands.go#L370-L376
Added lines #L370 - L376 were not covered by tests


[warning] 379-382: contrib/opbot/botmd/commands.go#L379-L382
Added lines #L379 - L382 were not covered by tests


[warning] 384-384: contrib/opbot/botmd/commands.go#L384
Added line #L384 was not covered by tests

}
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
3 changes: 2 additions & 1 deletion contrib/opbot/cmd/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import (
"fmt"
"github.com/synapsecns/sanguine/contrib/opbot/botmd"
"github.com/synapsecns/sanguine/core"
"github.com/synapsecns/sanguine/core/metrics"

// used for testing.
Expand All @@ -23,7 +24,7 @@
Usage: "start the slack bot",
Flags: []cli.Flag{fileFlag},
Action: func(c *cli.Context) error {
configFile, err := os.ReadFile(c.String(fileFlag.Name))
configFile, err := os.ReadFile(core.ExpandOrReturnPath(c.String(fileFlag.Name)))

Check warning on line 27 in contrib/opbot/cmd/commands.go

View check run for this annotation

Codecov / codecov/patch

contrib/opbot/cmd/commands.go#L27

Added line #L27 was not covered by tests
if err != nil {
return fmt.Errorf("failed to open config file: %w", err)
}
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:"omnirpc_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
}
Loading
Loading