Skip to content

Commit

Permalink
Feat: add TestFilterQuoteAge
Browse files Browse the repository at this point in the history
  • Loading branch information
dwasse committed Jul 30, 2024
1 parent 0cc05e3 commit a7fd85e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
11 changes: 11 additions & 0 deletions services/rfq/api/rest/export_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package rest

import (
"github.com/synapsecns/sanguine/services/rfq/api/config"
"github.com/synapsecns/sanguine/services/rfq/api/db"
)

// FilterQuoteAge exports filterQuoteAge for testing.
func FilterQuoteAge(cfg config.Config, dbQuotes []*db.Quote) []*db.Quote {
return filterQuoteAge(cfg, dbQuotes)
}
21 changes: 20 additions & 1 deletion services/rfq/api/rest/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ import (
"bytes"
"encoding/json"
"fmt"
apiClient "github.com/synapsecns/sanguine/services/rfq/api/client"
"io"
"net/http"
"strconv"
"time"

apiClient "github.com/synapsecns/sanguine/services/rfq/api/client"
"github.com/synapsecns/sanguine/services/rfq/api/db"
"github.com/synapsecns/sanguine/services/rfq/api/rest"

"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/crypto"
"github.com/synapsecns/sanguine/ethergo/signer/wallet"
Expand Down Expand Up @@ -205,6 +208,22 @@ func (c *ServerSuite) TestPutAndGetQuoteByRelayer() {
c.Assert().True(found, "Newly added quote not found")
}

func (c *ServerSuite) TestFilterQuoteAge() {
now := time.Now()

// insert quote outside age range
quotes := []*db.Quote{
&db.Quote{OriginChainID: 1, UpdatedAt: now.Add(-time.Hour)},
&db.Quote{OriginChainID: 2, UpdatedAt: now.Add(-time.Minute)},
}

filteredQuotes := rest.FilterQuoteAge(c.cfg, quotes)

// verify old quote is filtered out
c.Equal(1, len(filteredQuotes))
c.Equal(quotes[1], filteredQuotes[0])
}

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

Expand Down
4 changes: 3 additions & 1 deletion services/rfq/api/rest/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"math/big"
"testing"
"time"

"github.com/Flaque/filet"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
Expand Down Expand Up @@ -76,7 +77,8 @@ func (c *ServerSuite) SetupTest() {
1: ethFastBridgeAddress.Hex(),
42161: arbFastBridgeAddress.Hex(),
},
Port: fmt.Sprintf("%d", port),
Port: fmt.Sprintf("%d", port),
MaxQuoteAge: 15 * time.Minute,
}
c.cfg = testConfig

Expand Down

0 comments on commit a7fd85e

Please sign in to comment.