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

rfq: mimimal viable withdrawal api #2815

Merged
merged 12 commits into from
Jul 2, 2024
5 changes: 3 additions & 2 deletions contrib/opbot/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type Config struct {
// inject only with init container!
SignozPassword string `yaml:"signoz_password"`
// SignozBaseURL is the base url of the signoz instance.
SignozBaseURL string `yaml:"signoz_base_url"`
RelayerURLS []string `yaml:"rfq_relayer_urls"`
SignozBaseURL string `yaml:"signoz_base_url"`
// RelayerURLS is the list of RFQ relayer URLs.
RelayerURLS []string `yaml:"rfq_relayer_urls"`
}
6 changes: 6 additions & 0 deletions ethergo/submitter/submitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
SubmitTransaction(ctx context.Context, chainID *big.Int, call ContractCallType) (nonce uint64, err error)
// GetSubmissionStatus returns the status of a transaction and any metadata associated with it if it is complete.
GetSubmissionStatus(ctx context.Context, chainID *big.Int, nonce uint64) (status SubmissionStatus, err error)
// Address returns the address of the signer.
Address() common.Address
}

// txSubmitterImpl is the implementation of the transaction submitter.
Expand Down Expand Up @@ -665,4 +667,8 @@
return gasEstimate, nil
}

func (t *txSubmitterImpl) Address() common.Address {
return t.signer.Address()

Check warning on line 671 in ethergo/submitter/submitter.go

View check run for this annotation

Codecov / codecov/patch

ethergo/submitter/submitter.go#L670-L671

Added lines #L670 - L671 were not covered by tests
}

var _ TransactionSubmitter = &txSubmitterImpl{}
2 changes: 2 additions & 0 deletions go.work.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1638,6 +1638,7 @@ github.com/Azure/go-autorest/logger v0.2.1/go.mod h1:T9E3cAhj2VqvPOtCYAvby9aBXkZ
github.com/Azure/go-autorest/tracing v0.6.0 h1:TYi4+3m5t6K48TGI9AUdb+IzbnSxvnvUMfuitfgcfuo=
github.com/Azure/go-autorest/tracing v0.6.0/go.mod h1:+vhtPC754Xsa23ID7GlGsrdKBpUA79WCAKPPZVC2DeU=
github.com/BurntSushi/toml v1.2.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/BurntSushi/toml v1.2.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802 h1:1BDTz0u9nC3//pOCMdNH+CiXJVYJh5UQNCOBG7jbELc=
github.com/ClickHouse/clickhouse-go v1.5.4 h1:cKjXeYLNWVJIx2J1K6H2CqyRmfwVJVY1OV1coaaFcI0=
github.com/ClickHouse/clickhouse-go v1.5.4/go.mod h1:EaI/sW7Azgz9UATzd5ZdZHRUhHgv5+JMS9NSr2smCJI=
Expand Down Expand Up @@ -1993,6 +1994,7 @@ github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfc
github.com/cpuguy83/dockercfg v0.3.1 h1:/FpZ+JaygUR/lZP2NlFI2DVfrOEMAIKP5wWEJdoYe9E=
github.com/cpuguy83/dockercfg v0.3.1/go.mod h1:sugsbF4//dDlL/i+S+rtpIWp+5h0BHJHfjj5/jFyUJc=
github.com/cpuguy83/go-md2man v1.0.10 h1:BSKMNlYxDvnunlTymqtgONjNnaRV1sTpcovwwjF22jk=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/crackcomm/go-gitignore v0.0.0-20170627025303-887ab5e44cc3 h1:HVTnpeuvF6Owjd5mniCL8DEXo7uYXdQEmOP4FJbV5tg=
github.com/crackcomm/go-gitignore v0.0.0-20170627025303-887ab5e44cc3/go.mod h1:p1d6YEZWvFzEh4KLyvBcVSnrfNDDvK2zfK/4x2v/4pE=
github.com/crate-crypto/go-ipa v0.0.0-20220523130400-f11357ae11c7 h1:6IrxszG5G+O7zhtkWxq6+unVvnrm1fqV2Pe+T95DUzw=
Expand Down
2 changes: 1 addition & 1 deletion services/rfq/relayer/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
}

// commands
app.Commands = cli.Commands{runCommand}
app.Commands = cli.Commands{runCommand, withdrawCommand}

Check warning on line 26 in services/rfq/relayer/cmd/cmd.go

View check run for this annotation

Codecov / codecov/patch

services/rfq/relayer/cmd/cmd.go#L26

Added line #L26 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

No test coverage found for withdrawCommand.

It appears that the withdrawCommand logic is not covered by any tests. Please ensure that appropriate tests are added to verify the functionality of this command.

  • services/rfq/relayer/cmd/commands.go: Definition of withdrawCommand.
Analysis chain

Verify the integration of the withdrawCommand.

Ensure that the new withdrawCommand is correctly integrated into the CLI application.


Verify the definition and coverage of withdrawCommand.

Ensure that the withdrawCommand is correctly defined and that its logic is covered by tests.


Verify the test coverage of withdrawCommand.

Ensure that the withdrawCommand logic is covered by tests.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the integration of the withdrawCommand in the CLI application.

# Test: Search for the usage of withdrawCommand in the codebase. Expect: Proper integration in the CLI application.
rg --type go $'withdrawCommand'

Length of output: 193



Script:

#!/bin/bash
# Description: Verify the definition and test coverage of withdrawCommand.

# Step 1: Display the definition of withdrawCommand in commands.go
rg --type go --context 10 'var withdrawCommand' services/rfq/relayer/cmd/commands.go

# Step 2: Search for test files that might cover the withdrawCommand logic
fd --type f --name '*_test.go' | xargs rg 'withdrawCommand'

Length of output: 1169



Script:

#!/bin/bash
# Description: Verify the test coverage of withdrawCommand.

# Search for test files that might cover the withdrawCommand logic
fd --type f '_test.go' | xargs rg 'withdrawCommand'

Length of output: 49

Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure the new command withdrawCommand is covered by tests.

The addition of the new command should be tested to ensure it works as expected.

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

shellCommand := commandline.GenerateShellCommand(app.Commands)
app.Commands = append(app.Commands, shellCommand)
app.Action = shellCommand.Action
Expand Down
78 changes: 78 additions & 0 deletions services/rfq/relayer/cmd/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
import (
"fmt"

"github.com/ethereum/go-ethereum/common"
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure the new command withdrawCommand is covered by tests.

The addition of the new command should be tested to ensure it works as expected.

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

"github.com/synapsecns/sanguine/core"
"github.com/synapsecns/sanguine/core/commandline"
"github.com/synapsecns/sanguine/core/metrics"
"github.com/synapsecns/sanguine/services/rfq/relayer/relapi"
"github.com/synapsecns/sanguine/services/rfq/relayer/relconfig"
"github.com/synapsecns/sanguine/services/rfq/relayer/service"
"github.com/urfave/cli/v2"
Expand Down Expand Up @@ -44,3 +46,79 @@
return nil
},
}

var relayerURLFlag = &cli.StringFlag{
Name: "relayer-url",
Usage: "relayer url",
}

var chainIDFlag = &cli.StringFlag{
Name: "chain-id",
Usage: "chain id",
}

var amountFlag = &cli.StringFlag{
Name: "amount",
Usage: "amount",
}

var tokenAddressFlag = &cli.StringFlag{
Name: "token-address",
Usage: "token address",
}

var toFlag = &cli.StringFlag{
Name: "to",
Usage: "to",
}

// runCommand runs the rfq relayer.
var withdrawCommand = &cli.Command{
Name: "withdraw",
Description: "run the withdrawal tool",
Flags: []cli.Flag{relayerURLFlag, chainIDFlag, amountFlag, tokenAddressFlag, toFlag, &commandline.LogLevel},
Action: func(c *cli.Context) (err error) {
if c.String(relayerURLFlag.Name) == "" {
return fmt.Errorf("relayer URL is required")
}

Check warning on line 83 in services/rfq/relayer/cmd/commands.go

View check run for this annotation

Codecov / codecov/patch

services/rfq/relayer/cmd/commands.go#L80-L83

Added lines #L80 - L83 were not covered by tests
Comment on lines +81 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 relayerURLFlag validation.

Ensure that this validation is tested for various scenarios, such as missing or invalid URLs.

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


client := relapi.NewRelayerClient(metrics.Get(), c.String(relayerURLFlag.Name))
if err != nil {
return fmt.Errorf("could not create relayer: %w", err)
}

Check warning on line 88 in services/rfq/relayer/cmd/commands.go

View check run for this annotation

Codecov / codecov/patch

services/rfq/relayer/cmd/commands.go#L85-L88

Added lines #L85 - L88 were not covered by tests

chainID := c.Uint(chainIDFlag.Name)
if chainID == 0 {
return fmt.Errorf("valid chain ID is required")
}

Check warning on line 93 in services/rfq/relayer/cmd/commands.go

View check run for this annotation

Codecov / codecov/patch

services/rfq/relayer/cmd/commands.go#L90-L93

Added lines #L90 - L93 were not covered by tests
Comment on lines +90 to +93
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 chainIDFlag validation.

Ensure that this validation is tested for various scenarios, such as missing or invalid chain IDs.

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


amount := c.String(amountFlag.Name)
if amount == "" {
return fmt.Errorf("amount is required")
}

Check warning on line 98 in services/rfq/relayer/cmd/commands.go

View check run for this annotation

Codecov / codecov/patch

services/rfq/relayer/cmd/commands.go#L95-L98

Added lines #L95 - L98 were not covered by tests
Comment on lines +95 to +98
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 amountFlag validation.

Ensure that this validation is tested for various scenarios, such as missing or invalid amounts.

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


tokenAddress := c.String(tokenAddressFlag.Name)
if !common.IsHexAddress(tokenAddress) {
return fmt.Errorf("valid token address is required")
}

Check warning on line 103 in services/rfq/relayer/cmd/commands.go

View check run for this annotation

Codecov / codecov/patch

services/rfq/relayer/cmd/commands.go#L100-L103

Added lines #L100 - L103 were not covered by tests
Comment on lines +100 to +103
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 tokenAddressFlag validation.

Ensure that this validation is tested for various scenarios, such as missing or invalid token addresses.

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


to := c.String(toFlag.Name)
if !common.IsHexAddress(to) {
return fmt.Errorf("valid recipient address is required")
}

Check warning on line 108 in services/rfq/relayer/cmd/commands.go

View check run for this annotation

Codecov / codecov/patch

services/rfq/relayer/cmd/commands.go#L105-L108

Added lines #L105 - L108 were not covered by tests
Comment on lines +105 to +108
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 toFlag validation.

Ensure that this validation is tested for various scenarios, such as missing or invalid recipient addresses.

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


withdrawRequest := relapi.WithdrawRequest{
ChainID: uint32(chainID),
Amount: amount,
TokenAddress: common.HexToAddress(tokenAddress),
To: common.HexToAddress(to),
}

_, err = client.Withdraw(c.Context, &withdrawRequest)
if err != nil {
return fmt.Errorf("could not start relayer: %w", err)
Copy link

Choose a reason for hiding this comment

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

🪶 style: Error message should reflect the context of the operation, e.g., 'could not execute withdrawal'.

}

Check warning on line 120 in services/rfq/relayer/cmd/commands.go

View check run for this annotation

Codecov / codecov/patch

services/rfq/relayer/cmd/commands.go#L110-L120

Added lines #L110 - L120 were not covered by tests
Comment on lines +117 to +120
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 withdrawal process.

Ensure that the withdrawal process is tested for various scenarios, such as successful withdrawals, failed withdrawals, and edge cases.

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


return nil

Check warning on line 122 in services/rfq/relayer/cmd/commands.go

View check run for this annotation

Codecov / codecov/patch

services/rfq/relayer/cmd/commands.go#L122

Added line #L122 was not covered by tests
},
}
22 changes: 22 additions & 0 deletions services/rfq/relayer/relapi/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
GetQuoteRequestStatusByTxHash(ctx context.Context, hash string) (*GetQuoteRequestStatusResponse, error)
GetQuoteRequestStatusByTxID(ctx context.Context, hash string) (*GetQuoteRequestStatusResponse, error)
RetryTransaction(ctx context.Context, txhash string) (*GetTxRetryResponse, error)
Withdraw(ctx context.Context, req *WithdrawRequest) (*WithdrawResponse, error)
}

type relayerClient struct {
Expand Down Expand Up @@ -100,3 +101,24 @@

return &res, nil
}

// WithdrawResponse is the response for the withdraw request.
type WithdrawResponse struct {
Nonce uint64 `json:"nonce"`
}
trajan0x marked this conversation as resolved.
Show resolved Hide resolved

func (r *relayerClient) Withdraw(ctx context.Context, req *WithdrawRequest) (*WithdrawResponse, error) {
var res WithdrawResponse
resp, err := r.client.R().SetContext(ctx).
SetResult(&res).
SetBody(req).
Post(postWithdrawRoute)
if err != nil {
return nil, fmt.Errorf("failed to withdraw transaction: %w", err)
}

Check warning on line 118 in services/rfq/relayer/relapi/client.go

View check run for this annotation

Codecov / codecov/patch

services/rfq/relayer/relapi/client.go#L117-L118

Added lines #L117 - L118 were not covered by tests
if resp.StatusCode() != http.StatusOK {
return nil, fmt.Errorf("unexpected status code: %d", resp.StatusCode())
}

Check warning on line 121 in services/rfq/relayer/relapi/client.go

View check run for this annotation

Codecov / codecov/patch

services/rfq/relayer/relapi/client.go#L120-L121

Added lines #L120 - L121 were not covered by tests

return &res, nil
trajan0x marked this conversation as resolved.
Show resolved Hide resolved
}
16 changes: 16 additions & 0 deletions services/rfq/relayer/relapi/export_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package relapi

import (
"github.com/ethereum/go-ethereum/common"
"github.com/synapsecns/sanguine/services/rfq/relayer/relconfig"
)

// TokenIDExists checks if a token ID exists in the config.
func TokenIDExists(cfg relconfig.Config, tokenAddress common.Address, chainID int) bool {
return tokenIDExists(cfg, tokenAddress, chainID)
}
Comment on lines +8 to +11
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 TokenIDExists function.

Ensure that this function is tested for various scenarios, such as valid token addresses, invalid token addresses, and edge cases.

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


// ToAddressIsWhitelisted checks if a to address is whitelisted.
func ToAddressIsWhitelisted(cfg relconfig.Config, to common.Address) bool {
return toAddressIsWhitelisted(cfg, to)
}
Loading
Loading