2021-01-26 13:00:32 +00:00
|
|
|
package wallet
|
|
|
|
|
|
|
|
import (
|
2022-08-09 22:54:44 +00:00
|
|
|
"net/http"
|
|
|
|
"net/http/httptest"
|
2021-01-26 13:00:32 +00:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
2022-08-09 22:54:44 +00:00
|
|
|
const (
|
|
|
|
path = "../../_assets/tests/"
|
|
|
|
)
|
|
|
|
|
2021-01-26 13:00:32 +00:00
|
|
|
func TestCryptoOnRamps_Get(t *testing.T) {
|
2022-08-09 22:54:44 +00:00
|
|
|
s := httptest.NewServer(http.FileServer(http.Dir(path)))
|
|
|
|
defer s.Close()
|
|
|
|
|
2021-01-26 13:00:32 +00:00
|
|
|
cs := []*CryptoOnRampManager{
|
|
|
|
{options: &CryptoOnRampOptions{dataSourceType: DataSourceStatic}},
|
|
|
|
{options: &CryptoOnRampOptions{
|
|
|
|
dataSourceType: DataSourceHTTP,
|
2024-01-18 18:54:54 +00:00
|
|
|
dataSource: s.URL + "/ramps.json",
|
2021-01-26 13:00:32 +00:00
|
|
|
}},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, corm := range cs {
|
|
|
|
require.Equal(t, 0, len(corm.ramps))
|
|
|
|
|
|
|
|
rs, err := corm.Get()
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Greater(t, len(rs), 0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCryptoOnRampManager_hasCacheExpired(t *testing.T) {
|
2022-08-09 22:54:44 +00:00
|
|
|
s := httptest.NewServer(http.FileServer(http.Dir(path)))
|
|
|
|
defer s.Close()
|
|
|
|
|
2021-01-26 13:00:32 +00:00
|
|
|
corm := NewCryptoOnRampManager(&CryptoOnRampOptions{
|
|
|
|
dataSourceType: DataSourceHTTP,
|
2024-01-18 18:54:54 +00:00
|
|
|
dataSource: s.URL + "/ramps.json",
|
2021-01-26 13:00:32 +00:00
|
|
|
})
|
|
|
|
nt := time.Time{}.Add(30 * time.Minute)
|
|
|
|
|
|
|
|
require.False(t, corm.hasCacheExpired(nt))
|
|
|
|
require.True(t, corm.hasCacheExpired(time.Now()))
|
|
|
|
|
|
|
|
_, err := corm.Get()
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.False(t, corm.hasCacheExpired(time.Now()))
|
|
|
|
require.True(t, corm.hasCacheExpired(time.Now().Add(2*time.Hour)))
|
|
|
|
}
|