Skip to content

Commit

Permalink
Feat: add GetRelayAck test
Browse files Browse the repository at this point in the history
  • Loading branch information
dwasse committed May 15, 2024
1 parent 3984a35 commit f5155e6
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
4 changes: 2 additions & 2 deletions services/rfq/api/rest/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,9 @@ func (r *QuoterAPIServer) AuthMiddleware() gin.HandlerFunc {

// GetRelayAck checks if a relay is pending or not.
func (r *QuoterAPIServer) GetRelayAck(c *gin.Context) {
transactionID := c.Query("transaction_id")
transactionID := c.Query("id")
if transactionID == "" {
c.JSON(http.StatusBadRequest, gin.H{"error": "Must specify 'txID'"})
c.JSON(http.StatusBadRequest, gin.H{"error": "Must specify 'id'"})
return
}

Check warning on line 219 in services/rfq/api/rest/server.go

View check run for this annotation

Codecov / codecov/patch

services/rfq/api/rest/server.go#L217-L219

Added lines #L217 - L219 were not covered by tests

Expand Down
45 changes: 45 additions & 0 deletions services/rfq/api/rest/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/ethereum/go-ethereum/crypto"
"github.com/synapsecns/sanguine/ethergo/signer/wallet"
"github.com/synapsecns/sanguine/services/rfq/api/model"
"github.com/synapsecns/sanguine/services/rfq/relayer/relapi"
)

func (c *ServerSuite) TestNewQuoterAPIServer() {
Expand Down Expand Up @@ -203,6 +204,50 @@ func (c *ServerSuite) TestPutAndGetQuoteByRelayer() {
c.Assert().True(found, "Newly added quote not found")
}

func (c *ServerSuite) TestGetAck() {
c.startQuoterAPIServer()

// Send GET request
client := &http.Client{}
testTxID := "0x123"
req, err := http.NewRequestWithContext(c.GetTestContext(), http.MethodGet, fmt.Sprintf("http://localhost:%d/ack?id=%s", c.port, testTxID), nil)
c.Require().NoError(err)
resp, err := client.Do(req)
c.Require().NoError(err)
c.Equal(http.StatusOK, resp.StatusCode)

// Expect ack with shouldRelay=true
var result relapi.GetRelayAckResponse
err = json.NewDecoder(resp.Body).Decode(&result)
c.Require().NoError(err)
expectedResult := relapi.GetRelayAckResponse{
TxID: testTxID,
ShouldRelay: true,
}
c.Equal(expectedResult, result)
err = resp.Body.Close()
c.Require().NoError(err)

// Send another request with same txID
req, err = http.NewRequestWithContext(c.GetTestContext(), http.MethodGet, fmt.Sprintf("http://localhost:%d/ack?id=%s", c.port, testTxID), nil)
c.Require().NoError(err)
resp, err = client.Do(req)
c.Require().NoError(err)
c.Equal(http.StatusOK, resp.StatusCode)

// Expect ack with shouldRelay=false
err = json.NewDecoder(resp.Body).Decode(&result)
c.Require().NoError(err)
expectedResult = relapi.GetRelayAckResponse{
TxID: testTxID,
ShouldRelay: false,
}
c.Equal(expectedResult, result)
err = resp.Body.Close()
c.Require().NoError(err)
c.GetTestContext().Done()
}

// startQuoterAPIServer starts the API server and waits for it to initialize.
func (c *ServerSuite) startQuoterAPIServer() {
go func() {
Expand Down
2 changes: 1 addition & 1 deletion services/rfq/relayer/relapi/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (h *Handler) GetQuoteRequestStatusByTxHash(c *gin.Context) {
func (h *Handler) GetQuoteRequestStatusByTxID(c *gin.Context) {
txIDStr := c.Query("id")
if txIDStr == "" {
c.JSON(http.StatusBadRequest, gin.H{"error": "Must specify 'txID'"})
c.JSON(http.StatusBadRequest, gin.H{"error": "Must specify 'id'"})

Check warning on line 63 in services/rfq/relayer/relapi/handler.go

View check run for this annotation

Codecov / codecov/patch

services/rfq/relayer/relapi/handler.go#L63

Added line #L63 was not covered by tests
return
}

Expand Down

0 comments on commit f5155e6

Please sign in to comment.