-
Notifications
You must be signed in to change notification settings - Fork 32
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
Changes from 9 commits
3b80d3f
9258369
a17db24
484a9a3
e83dd9d
a3c3516
84dcdd7
6d10be7
5ed6d9a
dce9713
2965bb7
5c4554a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,7 @@ | |
} | ||
|
||
// commands | ||
app.Commands = cli.Commands{runCommand} | ||
app.Commands = cli.Commands{runCommand, withdrawCommand} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure the new command 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 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,9 +4,11 @@ | |
import ( | ||
"fmt" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure the new command 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" | ||
|
@@ -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") | ||
} | ||
Comment on lines
+81
to
+83
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add tests for 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) | ||
} | ||
|
||
chainID := c.Uint(chainIDFlag.Name) | ||
if chainID == 0 { | ||
return fmt.Errorf("valid chain ID is required") | ||
} | ||
Comment on lines
+90
to
+93
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add tests for 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") | ||
} | ||
Comment on lines
+95
to
+98
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add tests for 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") | ||
} | ||
Comment on lines
+100
to
+103
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add tests for 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") | ||
} | ||
Comment on lines
+105
to
+108
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add tests for 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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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'. |
||
} | ||
Comment on lines
+117
to
+120
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
}, | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add tests for 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? |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,18 @@ | ||
package relapi | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"math/big" | ||
"net/http" | ||
|
||
"github.com/ethereum/go-ethereum/accounts/abi" | ||
"github.com/ethereum/go-ethereum/accounts/abi/bind" | ||
"github.com/ethereum/go-ethereum/core/types" | ||
"github.com/synapsecns/sanguine/ethergo/submitter" | ||
"github.com/synapsecns/sanguine/services/rfq/contracts/ierc20" | ||
"github.com/synapsecns/sanguine/services/rfq/relayer/relconfig" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/common/hexutil" | ||
"github.com/gin-gonic/gin" | ||
|
@@ -13,15 +22,19 @@ | |
|
||
// Handler is the REST API handler. | ||
type Handler struct { | ||
db reldb.Service | ||
chains map[uint32]*chain.Chain | ||
db reldb.Service | ||
chains map[uint32]*chain.Chain | ||
cfg relconfig.Config | ||
submitter submitter.TransactionSubmitter | ||
Comment on lines
+27
to
+28
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure the new fields in the The addition of new fields should be tested to ensure they are correctly initialized and used. Do you want me to generate the unit testing code or open a GitHub issue to track this task? |
||
} | ||
|
||
// NewHandler creates a new REST API handler. | ||
func NewHandler(db reldb.Service, chains map[uint32]*chain.Chain) *Handler { | ||
func NewHandler(db reldb.Service, chains map[uint32]*chain.Chain, cfg relconfig.Config, txSubmitter submitter.TransactionSubmitter) *Handler { | ||
return &Handler{ | ||
db: db, // Store the database connection in the handler | ||
chains: chains, | ||
db: db, // Store the database connection in the handler | ||
chains: chains, | ||
cfg: cfg, | ||
submitter: txSubmitter, | ||
Comment on lines
+32
to
+37
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tip Codebase Verification The The search through the test files did not yield any results for the
Analysis chainEnsure the The Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Description: Verify if the NewHandler function is covered by tests.
# Test: Search for the usage of NewHandler in test files. Expect: Occurrences in test files.
rg --type go --glob '*_test.go' $'NewHandler'
Length of output: 44 Script: #!/bin/bash
# Description: Verify if the NewHandler function is indirectly covered by tests.
# Test: Search for test functions that might indirectly call or cover the NewHandler function.
# First, list all test files
test_files=$(fd --type f --glob '*_test.go')
# Then search for the term 'NewHandler' within these test files
for file in $test_files; do
echo "Searching in $file"
rg 'NewHandler' $file
done
Length of output: 75358
Comment on lines
+32
to
+37
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure the The addition of new parameters should be tested to ensure the function works as expected. Do you want me to generate the unit testing code or open a GitHub issue to track this task? |
||
} | ||
} | ||
|
||
|
@@ -107,14 +120,14 @@ | |
} | ||
|
||
chainID := quoteRequest.Transaction.DestChainId | ||
chain, ok := h.chains[chainID] | ||
chainHandler, ok := h.chains[chainID] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure the The renaming of the variable should be tested to ensure it does not introduce any issues. Do you want me to generate the unit testing code or open a GitHub issue to track this task? |
||
if !ok { | ||
c.JSON(http.StatusInternalServerError, gin.H{"error": fmt.Sprintf("No contract found for chain: %d", chainID)}) | ||
return | ||
} | ||
|
||
// `quoteRequest == nil` case should be handled by the db query above | ||
nonce, gasAmount, err := chain.SubmitRelay(c, *quoteRequest) | ||
nonce, gasAmount, err := chainHandler.SubmitRelay(c, *quoteRequest) | ||
if err != nil { | ||
c.JSON(http.StatusInternalServerError, gin.H{"error": fmt.Sprintf("could not submit relay: %s", err.Error())}) | ||
return | ||
|
@@ -128,3 +141,148 @@ | |
} | ||
c.JSON(http.StatusOK, resp) | ||
} | ||
|
||
// Withdraw withdraws tokens from the relayer. | ||
// | ||
//nolint:cyclop | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🪶 style: Consider refactoring to reduce cyclomatic complexity. |
||
func (h *Handler) Withdraw(c *gin.Context) { | ||
var req WithdrawRequest | ||
if err := c.ShouldBindJSON(&req); err != nil { | ||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) | ||
return | ||
} | ||
trajan0x marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// validate the token address | ||
if !tokenIDExists(h.cfg, req.TokenAddress, int(req.ChainID)) { | ||
c.JSON(http.StatusBadRequest, gin.H{"error": fmt.Sprintf("invalid token address %s for chain %d", req.TokenAddress.Hex(), req.ChainID)}) | ||
return | ||
} | ||
trajan0x marked this conversation as resolved.
Show resolved
Hide resolved
Comment on lines
+157
to
+159
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add tests for The validation of the token address in the Do you want me to generate the unit testing code or open a GitHub issue to track this task? ToolsGitHub Check: codecov/patch
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @trajan0x, here are the unit tests for the package relapi_test
import (
"testing"
"github.com/ethereum/go-ethereum/common"
"github.com/synapsecns/sanguine/services/rfq/relayer/relconfig"
"github.com/synapsecns/sanguine/services/rfq/relayer/relapi"
"github.com/stretchr/testify/assert"
)
func TestTokenIDExists(t *testing.T) {
cfg := relconfig.Config{
QuotableTokens: map[string]struct{}{
"1:0xTokenAddress1": {},
"2:0xTokenAddress2": {},
},
}
tests := []struct {
name string
tokenAddress common.Address
chainID int
expected bool
}{
{
name: "Token exists",
tokenAddress: common.HexToAddress("0xTokenAddress1"),
chainID: 1,
expected: true,
},
{
name: "Token does not exist",
tokenAddress: common.HexToAddress("0xNonExistentToken"),
chainID: 1,
expected: false,
},
{
name: "Multiple tokens, correct token",
tokenAddress: common.HexToAddress("0xTokenAddress2"),
chainID: 2,
expected: true,
},
{
name: "Multiple tokens, incorrect token",
tokenAddress: common.HexToAddress("0xTokenAddress1"),
chainID: 2,
expected: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := relapi.TokenIDExists(cfg, tt.tokenAddress, tt.chainID)
assert.Equal(t, tt.expected, result)
})
}
} This code tests various scenarios to ensure that the Learnings added
trajan0x marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// validate the withdrawal address | ||
if !toAddressIsWhitelisted(h.cfg, req.To) { | ||
c.JSON(http.StatusBadRequest, gin.H{"error": fmt.Sprintf("withdrawal address %s is not whitelisted", req.To.Hex())}) | ||
return | ||
} | ||
Comment on lines
+162
to
+165
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add tests for The validation of the withdrawal address in the Do you want me to generate the unit testing code or open a GitHub issue to track this task? ToolsGitHub Check: codecov/patch
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you generate? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @trajan0x, sure! Here are the unit tests for the package relapi_test
import (
"bytes"
"encoding/json"
"net/http"
"net/http/httptest"
"testing"
"github.com/ethereum/go-ethereum/common"
"github.com/gin-gonic/gin"
"github.com/stretchr/testify/assert"
"github.com/synapsecns/sanguine/services/rfq/relayer/relapi"
"github.com/synapsecns/sanguine/services/rfq/relayer/relconfig"
"github.com/synapsecns/sanguine/services/rfq/relayer/reldb"
"github.com/synapsecns/sanguine/ethergo/submitter"
)
func TestWithdrawAddressWhitelist(t *testing.T) {
gin.SetMode(gin.TestMode)
// Create a mock configuration with a whitelist
cfg := relconfig.Config{
WithdrawalWhitelist: []string{
"0x1111111111111111111111111111111111111111",
"0x2222222222222222222222222222222222222222",
},
}
// Create a mock handler with the mock configuration
handler := relapi.NewHandler(reldb.NewMockService(), nil, cfg, submitter.NewMockTransactionSubmitter())
tests := []struct {
name string
toAddress common.Address
statusCode int
}{
{
name: "Address is whitelisted",
toAddress: common.HexToAddress("0x1111111111111111111111111111111111111111"),
statusCode: http.StatusOK,
},
{
name: "Address is not whitelisted",
toAddress: common.HexToAddress("0x3333333333333333333333333333333333333333"),
statusCode: http.StatusBadRequest,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
reqBody := relapi.WithdrawRequest{
ChainID: 1,
Amount: "1000000000000000000", // 1 ETH in wei
TokenAddress: common.HexToAddress("0x0000000000000000000000000000000000000000"),
To: tt.toAddress,
}
body, err := json.Marshal(reqBody)
assert.NoError(t, err)
req, err := http.NewRequest(http.MethodPost, "/withdraw", bytes.NewBuffer(body))
assert.NoError(t, err)
req.Header.Set("Content-Type", "application/json")
rec := httptest.NewRecorder()
c, _ := gin.CreateTestContext(rec)
c.Request = req
handler.Withdraw(c)
assert.Equal(t, tt.statusCode, rec.Code)
})
}
} This test suite covers the validation of the withdrawal address in the Learnings added
Learnings used
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. running the whole api for this is crazy. export it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @trajan0x, I understand your concern. We can export the
This approach ensures that the Learnings added
Learnings used
trajan0x marked this conversation as resolved.
Show resolved
Hide resolved
trajan0x marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
var nonce uint64 | ||
var err error | ||
|
||
value, ok := new(big.Int).SetString(req.Amount, 10) | ||
if !ok { | ||
c.JSON(http.StatusBadRequest, gin.H{"error": fmt.Sprintf("invalid amount %s", req.Amount)}) | ||
return | ||
} | ||
trajan0x marked this conversation as resolved.
Show resolved
Hide resolved
Comment on lines
+172
to
+174
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add tests for amount validation. The validation of the amount in the Do you want me to generate the unit testing code or open a GitHub issue to track this task? ToolsGitHub Check: codecov/patch
trajan0x marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
//nolint: nestif | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🪶 style: Consider refactoring to reduce nesting. |
||
if chain.IsGasToken(req.TokenAddress) { | ||
nonce, err = h.submitter.SubmitTransaction(c, big.NewInt(int64(req.ChainID)), func(transactor *bind.TransactOpts) (tx *types.Transaction, err error) { | ||
bc := bind.NewBoundContract(req.To, abi.ABI{}, h.chains[req.ChainID].Client, h.chains[req.ChainID].Client, h.chains[req.ChainID].Client) | ||
if transactor.GasPrice != nil { | ||
transactor.Value = value | ||
// nolint: wrapcheck | ||
return bc.Transfer(transactor) | ||
} | ||
signer, err := transactor.Signer(h.submitter.Address(), tx) | ||
if err != nil { | ||
return nil, fmt.Errorf("could not get signer: %w", err) | ||
} | ||
return signer, nil | ||
}) | ||
if err != nil { | ||
c.JSON(http.StatusInternalServerError, gin.H{"error": fmt.Sprintf("could not submit transaction: %s", err.Error())}) | ||
return | ||
} | ||
} else { | ||
erc20Contract, err := ierc20.NewIERC20(req.TokenAddress, h.chains[req.ChainID].Client) | ||
if err != nil { | ||
c.JSON(http.StatusInternalServerError, gin.H{"error": fmt.Sprintf("could not create erc20 contract: %s", err.Error())}) | ||
return | ||
} | ||
Comment on lines
+192
to
+200
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add tests for gas token withdrawal. The gas token withdrawal logic in the Do you want me to generate the unit testing code or open a GitHub issue to track this task? ToolsGitHub Check: codecov/patch
|
||
|
||
nonce, err = h.submitter.SubmitTransaction(c, big.NewInt(int64(req.ChainID)), func(transactor *bind.TransactOpts) (tx *types.Transaction, err error) { | ||
// nolint: wrapcheck | ||
return erc20Contract.Transfer(transactor, req.To, value) | ||
trajan0x marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🪶 style: Consider adding error handling for the
Comment on lines
+202
to
+204
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🪶 style: Consider adding error handling for the |
||
}) | ||
if err != nil { | ||
c.JSON(http.StatusInternalServerError, gin.H{"error": fmt.Sprintf("could not submit transaction: %s", err.Error())}) | ||
return | ||
} | ||
Comment on lines
+202
to
+209
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add tests for ERC20 token withdrawal. The ERC20 token withdrawal logic in the Do you want me to generate the unit testing code or open a GitHub issue to track this task? ToolsGitHub Check: codecov/patch
Comment on lines
+196
to
+209
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add tests for ERC20 token withdrawal. The ERC20 token withdrawal logic in the Do you want me to generate the unit testing code or open a GitHub issue to track this task? ToolsGitHub Check: codecov/patch
|
||
} | ||
|
||
c.JSON(http.StatusOK, gin.H{"nonce": nonce}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add tests for successful withdrawal response. The successful withdrawal response in the Do you want me to generate the unit testing code or open a GitHub issue to track this task? |
||
} | ||
Comment on lines
+148
to
+213
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add tests for the Ensure that this function is tested for various scenarios, such as valid requests, invalid requests, and edge cases. Do you want me to generate the unit testing code or open a GitHub issue to track this task? |
||
|
||
// tokenIDExists checks if a token ID exists in the config. | ||
// note: this method assumes that SanitizeTokenID is a method of relconfig.Config | ||
func tokenIDExists(cfg relconfig.Config, tokenAddress common.Address, chainID int) bool { | ||
for quotableToken := range cfg.QuotableTokens { | ||
prospectiveChainID, prospectiveAddress, err := relconfig.DecodeTokenID(quotableToken) | ||
if err != nil { | ||
continue | ||
Comment on lines
+217
to
+221
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add tests for The Do you want me to generate the unit testing code or open a GitHub issue to track this task? ToolsGitHub Check: codecov/patch
|
||
} | ||
|
||
if prospectiveChainID == chainID && prospectiveAddress == tokenAddress { | ||
return true | ||
} | ||
} | ||
|
||
return false | ||
} | ||
Comment on lines
+215
to
+230
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add tests for 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? |
||
|
||
func toAddressIsWhitelisted(cfg relconfig.Config, to common.Address) bool { | ||
for _, addr := range cfg.WithdrawalWhitelist { | ||
if common.HexToAddress(addr) == to { | ||
return true | ||
} | ||
Comment on lines
+232
to
+236
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add tests for The Do you want me to generate the unit testing code or open a GitHub issue to track this task? |
||
} | ||
return false | ||
} | ||
Comment on lines
+232
to
+239
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add tests for Ensure that this function is tested for various scenarios, such as valid addresses, invalid addresses, and edge cases. Do you want me to generate the unit testing code or open a GitHub issue to track this task? |
||
|
||
// WithdrawRequest is the request to withdraw tokens from the relayer. | ||
type WithdrawRequest struct { | ||
// ChainID is the chain ID of the chain to withdraw from. | ||
ChainID uint32 `json:"chain_id"` | ||
// Amount is the amount to withdraw, in wei. | ||
Amount string `json:"amount"` | ||
// TokenAddress is the address of the token to withdraw. | ||
TokenAddress common.Address `json:"token_address"` | ||
// To is the address to withdraw to. | ||
To common.Address `json:"to"` | ||
} | ||
|
||
// MarshalJSON handles JSON marshaling for WithdrawRequest. | ||
func (wr *WithdrawRequest) MarshalJSON() ([]byte, error) { | ||
type Alias WithdrawRequest | ||
// nolint: wrapcheck | ||
return json.Marshal(&struct { | ||
TokenAddress string `json:"token_address"` | ||
To string `json:"to"` | ||
*Alias | ||
}{ | ||
TokenAddress: wr.TokenAddress.Hex(), | ||
To: wr.To.Hex(), | ||
Alias: (*Alias)(wr), | ||
}) | ||
trajan0x marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
Comment on lines
+241
to
+266
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add tests for The Do you want me to generate the unit testing code or open a GitHub issue to track this task? |
||
|
||
// UnmarshalJSON has JSON unmarshalling for WithdrawRequest. | ||
func (wr *WithdrawRequest) UnmarshalJSON(data []byte) error { | ||
type Alias WithdrawRequest | ||
aux := &struct { | ||
TokenAddress string `json:"token_address"` | ||
To string `json:"to"` | ||
*Alias | ||
}{ | ||
Alias: (*Alias)(wr), | ||
} | ||
|
||
if err := json.Unmarshal(data, aux); err != nil { | ||
//nolint: wrapcheck | ||
return err | ||
} | ||
trajan0x marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
wr.TokenAddress = common.HexToAddress(aux.TokenAddress) | ||
wr.To = common.HexToAddress(aux.To) | ||
|
||
return nil | ||
} | ||
Comment on lines
+268
to
+288
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add tests for Ensure that this method is tested for various scenarios, such as valid JSON inputs, invalid JSON inputs, and edge cases. Do you want me to generate the unit testing code or open a GitHub issue to track this task? |
There was a problem hiding this comment.
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 ofwithdrawCommand
.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:
Length of output: 193
Script:
Length of output: 1169
Script:
Length of output: 49