Skip to content

Commit

Permalink
Avoids live queries to fiats in most tests (except main one)
Browse files Browse the repository at this point in the history
  • Loading branch information
sjanel committed Oct 11, 2023
1 parent e7bbc91 commit 4d560de
Show file tree
Hide file tree
Showing 8 changed files with 194 additions and 8 deletions.
184 changes: 184 additions & 0 deletions data/cache/fiatcache.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
{
"fiats": [
"AED",
"AFN",
"ALL",
"AMD",
"ANG",
"AOA",
"ARS",
"AUD",
"AWG",
"AZN",
"BAM",
"BBD",
"BDT",
"BGN",
"BHD",
"BIF",
"BMD",
"BND",
"BOB",
"BOV",
"BRL",
"BSD",
"BTN",
"BWP",
"BYN",
"BZD",
"CAD",
"CDF",
"CHE",
"CHF",
"CHW",
"CLF",
"CLP",
"CNY",
"COP",
"COU",
"CRC",
"CUC",
"CUP",
"CVE",
"CZK",
"DJF",
"DKK",
"DOP",
"DZD",
"EGP",
"ERN",
"ETB",
"EUR",
"FJD",
"FKP",
"GBP",
"GEL",
"GHS",
"GIP",
"GMD",
"GNF",
"GTQ",
"GYD",
"HKD",
"HNL",
"HRK",
"HTG",
"HUF",
"IDR",
"ILS",
"INR",
"IQD",
"IRR",
"ISK",
"JMD",
"JOD",
"JPY",
"KES",
"KGS",
"KHR",
"KMF",
"KPW",
"KRW",
"KWD",
"KYD",
"KZT",
"LAK",
"LBP",
"LKR",
"LRD",
"LSL",
"LYD",
"MAD",
"MDL",
"MGA",
"MKD",
"MMK",
"MNT",
"MOP",
"MRU",
"MUR",
"MVR",
"MWK",
"MXN",
"MXV",
"MYR",
"MZN",
"NAD",
"NGN",
"NIO",
"NOK",
"NPR",
"NZD",
"OMR",
"PAB",
"PEN",
"PGK",
"PHP",
"PKR",
"PLN",
"PYG",
"QAR",
"RON",
"RSD",
"RUB",
"RWF",
"SAR",
"SBD",
"SCR",
"SDG",
"SEK",
"SGD",
"SHP",
"SLL",
"SOS",
"SRD",
"SSP",
"STN",
"SVC",
"SYP",
"SZL",
"THB",
"TJS",
"TMT",
"TND",
"TOP",
"TRY",
"TTD",
"TWD",
"TZS",
"UAH",
"UGX",
"USD",
"USN",
"UYI",
"UYU",
"UYW",
"UZS",
"VES",
"VND",
"VUV",
"WST",
"XAF",
"XAG",
"XAU",
"XBA",
"XBB",
"XBC",
"XBD",
"XCD",
"XDR",
"XOF",
"XPD",
"XPF",
"XPT",
"XSU",
"XTS",
"XUA",
"XXX",
"YER",
"ZAR",
"ZMW",
"ZWL"
],
"timeepoch": 1696955013
}
4 changes: 3 additions & 1 deletion src/api/common/include/commonapi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ class CommonAPI : public ExchangeBase {
public:
using Fiats = FlatSet<CurrencyCode>;

enum class AtInit : int8_t { kLoadFromFileCache, kNoLoadFromFileCache };

CommonAPI(const CoincenterInfo &config, Duration fiatsUpdateFrequency = std::chrono::hours(96),
bool loadFromFileCacheAtInit = true);
AtInit atInit = AtInit::kLoadFromFileCache);

/// Returns a new set of fiat currencies.
Fiats queryFiats() {
Expand Down
4 changes: 2 additions & 2 deletions src/api/common/src/commonapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ File GetFiatCacheFile(std::string_view dataDir) {

} // namespace

CommonAPI::CommonAPI(const CoincenterInfo& config, Duration fiatsUpdateFrequency, bool loadFromFileCacheAtInit)
CommonAPI::CommonAPI(const CoincenterInfo& config, Duration fiatsUpdateFrequency, AtInit atInit)
: _coincenterInfo(config), _fiatsCache(CachedResultOptions(fiatsUpdateFrequency, _cachedResultVault)) {
if (loadFromFileCacheAtInit) {
if (atInit == AtInit::kLoadFromFileCache) {
json data = GetFiatCacheFile(_coincenterInfo.dataDir()).readAllJson();
if (!data.empty()) {
int64_t timeEpoch = data["timeepoch"].get<int64_t>();
Expand Down
2 changes: 1 addition & 1 deletion src/api/common/test/exchangeprivateapi_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class ExchangePrivateTest : public ::testing::Test {

LoadConfiguration loadConfiguration{kDefaultDataDir, LoadConfiguration::ExchangeConfigFileType::kTest};
CoincenterInfo coincenterInfo{settings::RunMode::kTestKeys, loadConfiguration};
CommonAPI commonAPI{coincenterInfo, Duration::max(), true};
CommonAPI commonAPI{coincenterInfo, Duration::max()};
FiatConverter fiatConverter{coincenterInfo, Duration::max()}; // max to avoid real Fiat converter queries

MockExchangePublic exchangePublic{kSupportedExchanges[0], fiatConverter, commonAPI, coincenterInfo};
Expand Down
2 changes: 1 addition & 1 deletion src/api/common/test/exchangepublicapi_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class ExchangePublicTest : public ::testing::Test {
settings::RunMode runMode = settings::RunMode::kTestKeys;
LoadConfiguration loadConfiguration{kDefaultDataDir, LoadConfiguration::ExchangeConfigFileType::kTest};
CoincenterInfo coincenterInfo{runMode, loadConfiguration};
CommonAPI commonAPI{coincenterInfo};
CommonAPI commonAPI{coincenterInfo, Duration::max()};
FiatConverter fiatConverter{coincenterInfo, Duration::max()}; // max to avoid real Fiat converter queries
MockExchangePublic exchangePublic{kSupportedExchanges[0], fiatConverter, commonAPI, coincenterInfo};
};
Expand Down
2 changes: 1 addition & 1 deletion src/api/exchanges/test/bithumb_place_order_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class BithumbPrivateAPIPlaceOrderTest : public ::testing::Test {
LoadConfiguration loadConfig{kDefaultDataDir, LoadConfiguration::ExchangeConfigFileType::kTest};
CoincenterInfo coincenterInfo{runMode, loadConfig};
FiatConverter fiatConverter{coincenterInfo, Duration::max()}; // max to avoid real Fiat converter queries
CommonAPI commonAPI{coincenterInfo};
CommonAPI commonAPI{coincenterInfo, Duration::max()};
BithumbPublic exchangePublic{coincenterInfo, fiatConverter, commonAPI};
APIKeysProvider apiKeysProvider{coincenterInfo.dataDir(), coincenterInfo.getRunMode()};
ExchangeName exchangeName{exchangePublic.name(), apiKeysProvider.getKeyNames(exchangePublic.name()).front()};
Expand Down
2 changes: 1 addition & 1 deletion src/api/exchanges/test/commonapi_test.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class TestAPI {
CoincenterInfo coincenterInfo{runMode, loadConfig};
APIKeysProvider apiKeysProvider{coincenterInfo.dataDir(), coincenterInfo.getRunMode()};
FiatConverter fiatConverter{coincenterInfo, Duration::max()}; // max to avoid real Fiat converter queries
CommonAPI commonAPI{coincenterInfo};
CommonAPI commonAPI{coincenterInfo, Duration::max()};
PublicExchangeT exchangePublic{coincenterInfo, fiatConverter, commonAPI};
std::optional<PrivateExchangeT> exchangePrivateOpt;

Expand Down
2 changes: 1 addition & 1 deletion src/engine/test/exchangedata_test.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ExchangesBaseTest : public ::testing::Test {
LoadConfiguration loadConfiguration{kDefaultDataDir, LoadConfiguration::ExchangeConfigFileType::kTest};
settings::RunMode runMode = settings::RunMode::kTestKeys;
CoincenterInfo coincenterInfo{runMode, loadConfiguration};
api::CommonAPI commonAPI{coincenterInfo, Duration::max(), true};
api::CommonAPI commonAPI{coincenterInfo, Duration::max()};
FiatConverter fiatConverter{coincenterInfo, Duration::max()}; // max to avoid real Fiat converter queries
api::MockExchangePublic exchangePublic1{kSupportedExchanges[0], fiatConverter, commonAPI, coincenterInfo};
api::MockExchangePublic exchangePublic2{kSupportedExchanges[1], fiatConverter, commonAPI, coincenterInfo};
Expand Down

0 comments on commit 4d560de

Please sign in to comment.