diff --git a/services/rfq/api/rest/export_test.go b/services/rfq/api/rest/export_test.go new file mode 100644 index 0000000000..32775fed39 --- /dev/null +++ b/services/rfq/api/rest/export_test.go @@ -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) +} diff --git a/services/rfq/api/rest/server_test.go b/services/rfq/api/rest/server_test.go index dac06ae00e..493deb6f9b 100644 --- a/services/rfq/api/rest/server_test.go +++ b/services/rfq/api/rest/server_test.go @@ -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" @@ -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() diff --git a/services/rfq/api/rest/suite_test.go b/services/rfq/api/rest/suite_test.go index ebfbf344f7..16e5e29f43 100644 --- a/services/rfq/api/rest/suite_test.go +++ b/services/rfq/api/rest/suite_test.go @@ -4,6 +4,7 @@ import ( "fmt" "math/big" "testing" + "time" "github.com/Flaque/filet" "github.com/ethereum/go-ethereum/accounts/abi/bind" @@ -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