diff --git a/components/brave_rewards/browser/rewards_service_browsertest.cc b/components/brave_rewards/browser/rewards_service_browsertest.cc index b350f03adbc8..ea6e97ed7de3 100644 --- a/components/brave_rewards/browser/rewards_service_browsertest.cc +++ b/components/brave_rewards/browser/rewards_service_browsertest.cc @@ -444,9 +444,9 @@ class BraveRewardsBrowserTest : base::Unretained(this))); } - void GetProduction() { - rewards_service()->GetProduction( - base::Bind(&BraveRewardsBrowserTest::OnGetProduction, + void GetEnvironment() { + rewards_service()->GetEnvironment( + base::Bind(&BraveRewardsBrowserTest::OnGetEnvironment, base::Unretained(this))); } @@ -1167,7 +1167,7 @@ class BraveRewardsBrowserTest : const std::vector tip_amounts_ = {1.0, 5.0, 10.0}; - MOCK_METHOD1(OnGetProduction, void(bool)); + MOCK_METHOD1(OnGetEnvironment, void(ledger::Environment)); MOCK_METHOD1(OnGetDebug, void(bool)); MOCK_METHOD1(OnGetReconcileTime, void(int32_t)); MOCK_METHOD1(OnGetShortRetries, void(bool)); @@ -1364,39 +1364,39 @@ IN_PROC_BROWSER_TEST_F(BraveRewardsBrowserTest, ActivateSettingsModal) { IN_PROC_BROWSER_TEST_F(BraveRewardsBrowserTest, HandleFlagsSingleArg) { testing::InSequence s; - // SetProduction(true) - EXPECT_CALL(*this, OnGetProduction(true)); + // SetEnvironment(ledger::Environment::PRODUCTION) + EXPECT_CALL(*this, OnGetEnvironment(ledger::Environment::PRODUCTION)); // Staging - true and 1 - EXPECT_CALL(*this, OnGetProduction(false)).Times(2); + EXPECT_CALL(*this, OnGetEnvironment(ledger::Environment::STAGING)).Times(2); // Staging - false and random - EXPECT_CALL(*this, OnGetProduction(true)).Times(2); + EXPECT_CALL(*this, OnGetEnvironment(ledger::Environment::PRODUCTION)).Times(2); - rewards_service()->SetProduction(true); - GetProduction(); + rewards_service()->SetEnvironment(ledger::Environment::PRODUCTION); + GetEnvironment(); RunUntilIdle(); // Staging - true - rewards_service()->SetProduction(true); + rewards_service()->SetEnvironment(ledger::Environment::PRODUCTION); rewards_service()->HandleFlags("staging=true"); - GetProduction(); + GetEnvironment(); RunUntilIdle(); // Staging - 1 - rewards_service()->SetProduction(true); + rewards_service()->SetEnvironment(ledger::Environment::PRODUCTION); rewards_service()->HandleFlags("staging=1"); - GetProduction(); + GetEnvironment(); RunUntilIdle(); // Staging - false - rewards_service()->SetProduction(false); + rewards_service()->SetEnvironment(ledger::Environment::STAGING); rewards_service()->HandleFlags("staging=false"); - GetProduction(); + GetEnvironment(); RunUntilIdle(); // Staging - random - rewards_service()->SetProduction(false); + rewards_service()->SetEnvironment(ledger::Environment::STAGING); rewards_service()->HandleFlags("staging=werwe"); - GetProduction(); + GetEnvironment(); RunUntilIdle(); // SetDebug(true) @@ -1434,6 +1434,45 @@ IN_PROC_BROWSER_TEST_F(BraveRewardsBrowserTest, HandleFlagsSingleArg) { GetDebug(); RunUntilIdle(); + // SetEnvironment(ledger::Environment::PRODUCTION) + EXPECT_CALL(*this, OnGetEnvironment(ledger::Environment::PRODUCTION)); + // Development - true and 1 + EXPECT_CALL( + *this, + OnGetEnvironment(ledger::Environment::DEVELOPMENT)).Times(2); + // Development - false and random + EXPECT_CALL( + *this, + OnGetEnvironment(ledger::Environment::PRODUCTION)).Times(2); + + rewards_service()->SetEnvironment(ledger::Environment::PRODUCTION); + GetEnvironment(); + RunUntilIdle(); + + // Development - true + rewards_service()->SetEnvironment(ledger::Environment::PRODUCTION); + rewards_service()->HandleFlags("development=true"); + GetEnvironment(); + RunUntilIdle(); + + // Development - 1 + rewards_service()->SetEnvironment(ledger::Environment::PRODUCTION); + rewards_service()->HandleFlags("development=1"); + GetEnvironment(); + RunUntilIdle(); + + // Development - false + rewards_service()->SetEnvironment(ledger::Environment::PRODUCTION); + rewards_service()->HandleFlags("development=false"); + GetEnvironment(); + RunUntilIdle(); + + // Development - random + rewards_service()->SetEnvironment(ledger::Environment::PRODUCTION); + rewards_service()->HandleFlags("development=werwe"); + GetEnvironment(); + RunUntilIdle(); + // positive number EXPECT_CALL(*this, OnGetReconcileTime(10)); // negative number and string @@ -1474,12 +1513,12 @@ IN_PROC_BROWSER_TEST_F(BraveRewardsBrowserTest, HandleFlagsSingleArg) { } IN_PROC_BROWSER_TEST_F(BraveRewardsBrowserTest, HandleFlagsMultipleFlags) { - EXPECT_CALL(*this, OnGetProduction(false)); + EXPECT_CALL(*this, OnGetEnvironment(ledger::Environment::STAGING)); EXPECT_CALL(*this, OnGetDebug(true)); EXPECT_CALL(*this, OnGetReconcileTime(10)); EXPECT_CALL(*this, OnGetShortRetries(true)); - rewards_service()->SetProduction(true); + rewards_service()->SetEnvironment(ledger::Environment::PRODUCTION); rewards_service()->SetDebug(true); rewards_service()->SetReconcileTime(0); rewards_service()->SetShortRetries(false); @@ -1489,18 +1528,18 @@ IN_PROC_BROWSER_TEST_F(BraveRewardsBrowserTest, HandleFlagsMultipleFlags) { GetReconcileTime(); GetShortRetries(); - GetProduction(); + GetEnvironment(); GetDebug(); RunUntilIdle(); } IN_PROC_BROWSER_TEST_F(BraveRewardsBrowserTest, HandleFlagsWrongInput) { - EXPECT_CALL(*this, OnGetProduction(true)); + EXPECT_CALL(*this, OnGetEnvironment(ledger::Environment::PRODUCTION)); EXPECT_CALL(*this, OnGetDebug(false)); EXPECT_CALL(*this, OnGetReconcileTime(0)); EXPECT_CALL(*this, OnGetShortRetries(false)); - rewards_service()->SetProduction(true); + rewards_service()->SetEnvironment(ledger::Environment::PRODUCTION); rewards_service()->SetDebug(false); rewards_service()->SetReconcileTime(0); rewards_service()->SetShortRetries(false); @@ -1511,7 +1550,7 @@ IN_PROC_BROWSER_TEST_F(BraveRewardsBrowserTest, HandleFlagsWrongInput) { GetReconcileTime(); GetShortRetries(); GetDebug(); - GetProduction(); + GetEnvironment(); RunUntilIdle(); } diff --git a/components/brave_rewards/browser/rewards_service_impl.cc b/components/brave_rewards/browser/rewards_service_impl.cc index 82c2d50a30d5..36c1164ea871 100644 --- a/components/brave_rewards/browser/rewards_service_impl.cc +++ b/components/brave_rewards/browser/rewards_service_impl.cc @@ -461,14 +461,12 @@ void RewardsServiceImpl::StartLedger() { bat_ledger_service_.set_connection_error_handler( base::Bind(&RewardsServiceImpl::ConnectionClosed, AsWeakPtr())); - bool isProduction = true; + ledger::Environment environment = ledger::Environment::STAGING; // Environment #if defined(OFFICIAL_BUILD) - isProduction = true; - #else - isProduction = false; + environment = ledger::Environment::PRODUCTION; #endif - SetProduction(isProduction); + SetEnvironment(environment); SetDebug(false); @@ -2681,16 +2679,16 @@ void RewardsServiceImpl::HandleFlags(const std::string& options) { } if (name == "staging") { - bool is_production; + ledger::Environment environment; std::string lower = base::ToLowerASCII(value); if (lower == "true" || lower == "1") { - is_production = false; + environment = ledger::Environment::STAGING; } else { - is_production = true; + environment = ledger::Environment::PRODUCTION; } - SetProduction(is_production); + SetEnvironment(environment); continue; } @@ -2745,6 +2743,18 @@ void RewardsServiceImpl::HandleFlags(const std::string& options) { SaveExternalWallet(ledger::kWalletUphold, std::move(uphold)); continue; } + + if (name == "development") { + ledger::Environment environment; + std::string lower = base::ToLowerASCII(value); + + if (lower == "true" || lower == "1") { + environment = ledger::Environment::DEVELOPMENT; + SetEnvironment(environment); + } + + continue; + } } } @@ -2812,9 +2822,9 @@ void RewardsServiceImpl::SetLedgerEnvForTesting() { // this is needed because we are using braveledger_bat_helper::buildURL // directly in BraveRewardsBrowserTest #if defined(OFFICIAL_BUILD) - ledger::is_production = true; + SetEnvironment(ledger::Environment::PRODUCTION); #else - ledger::is_production = false; + SetEnvironment(ledger::Environment::STAGING); #endif } @@ -2826,8 +2836,8 @@ void RewardsServiceImpl::CheckInsufficientFundsForTesting() { MaybeShowNotificationAddFunds(); } -void RewardsServiceImpl::GetProduction(const GetProductionCallback& callback) { - bat_ledger_service_->GetProduction(callback); +void RewardsServiceImpl::GetEnvironment(const GetEnvironmentCallback& callback) { + bat_ledger_service_->GetEnvironment(callback); } void RewardsServiceImpl::GetDebug(const GetDebugCallback& callback) { @@ -2844,8 +2854,8 @@ void RewardsServiceImpl::GetShortRetries( bat_ledger_service_->GetShortRetries(callback); } -void RewardsServiceImpl::SetProduction(bool production) { - bat_ledger_service_->SetProduction(production); +void RewardsServiceImpl::SetEnvironment(ledger::Environment environment) { + bat_ledger_service_->SetEnvironment(environment); } void RewardsServiceImpl::SetDebug(bool debug) { diff --git a/components/brave_rewards/browser/rewards_service_impl.h b/components/brave_rewards/browser/rewards_service_impl.h index f60104b99a1a..d212f2789b77 100644 --- a/components/brave_rewards/browser/rewards_service_impl.h +++ b/components/brave_rewards/browser/rewards_service_impl.h @@ -68,7 +68,7 @@ class PublisherInfoDatabase; class RewardsNotificationServiceImpl; class BraveRewardsBrowserTest; -using GetProductionCallback = base::Callback; +using GetEnvironmentCallback = base::Callback; using GetDebugCallback = base::Callback; using GetReconcileTimeCallback = base::Callback; using GetShortRetriesCallback = base::Callback; @@ -189,8 +189,8 @@ class RewardsServiceImpl : public RewardsService, GetRewardsInternalsInfoCallback callback) override; void HandleFlags(const std::string& options); - void SetProduction(bool production); - void GetProduction(const GetProductionCallback& callback); + void SetEnvironment(ledger::Environment environment); + void GetEnvironment(const GetEnvironmentCallback& callback); void SetDebug(bool debug); void GetDebug(const GetDebugCallback& callback); void SetReconcileTime(int32_t time); diff --git a/components/services/bat_ledger/bat_ledger_service_impl.cc b/components/services/bat_ledger/bat_ledger_service_impl.cc index 8222031b0829..66e2532f0dca 100644 --- a/components/services/bat_ledger/bat_ledger_service_impl.cc +++ b/components/services/bat_ledger/bat_ledger_service_impl.cc @@ -39,9 +39,9 @@ void BatLedgerServiceImpl::Create( initialized_ = true; } -void BatLedgerServiceImpl::SetProduction(bool is_production) { +void BatLedgerServiceImpl::SetEnvironment(ledger::Environment environment) { DCHECK(!initialized_ || testing()); - ledger::is_production = is_production; + ledger::_environment = environment; } void BatLedgerServiceImpl::SetDebug(bool is_debug) { @@ -63,8 +63,8 @@ void BatLedgerServiceImpl::SetTesting() { ledger::is_testing = true; } -void BatLedgerServiceImpl::GetProduction(GetProductionCallback callback) { - std::move(callback).Run(ledger::is_production); +void BatLedgerServiceImpl::GetEnvironment(GetEnvironmentCallback callback) { + std::move(callback).Run(ledger::_environment); } void BatLedgerServiceImpl::GetDebug(GetDebugCallback callback) { diff --git a/components/services/bat_ledger/bat_ledger_service_impl.h b/components/services/bat_ledger/bat_ledger_service_impl.h index ef5a263d579f..52177f6bcab7 100644 --- a/components/services/bat_ledger/bat_ledger_service_impl.h +++ b/components/services/bat_ledger/bat_ledger_service_impl.h @@ -7,6 +7,7 @@ #define BRAVE_COMPONENTS_SERVICES_BAT_LEDGER_BAT_LEDGER_SERVICE_IMPL_H_ #include +#include #include "brave/components/services/bat_ledger/public/interfaces/bat_ledger.mojom.h" #include "services/service_manager/public/cpp/service_context_ref.h" @@ -23,13 +24,13 @@ class BatLedgerServiceImpl : public mojom::BatLedgerService { void Create(mojom::BatLedgerClientAssociatedPtrInfo client_info, mojom::BatLedgerAssociatedRequest bat_ledger) override; - void SetProduction(bool isProduction) override; + void SetEnvironment(ledger::Environment environment) override; void SetDebug(bool isDebug) override; void SetReconcileTime(int32_t time) override; void SetShortRetries(bool short_retries) override; void SetTesting() override; - void GetProduction(GetProductionCallback callback) override; + void GetEnvironment(GetEnvironmentCallback callback) override; void GetDebug(GetDebugCallback callback) override; void GetReconcileTime(GetReconcileTimeCallback callback) override; void GetShortRetries(GetShortRetriesCallback callback) override; diff --git a/components/services/bat_ledger/public/interfaces/bat_ledger.mojom b/components/services/bat_ledger/public/interfaces/bat_ledger.mojom index 5cf02e8cb4f3..3bf640504493 100644 --- a/components/services/bat_ledger/public/interfaces/bat_ledger.mojom +++ b/components/services/bat_ledger/public/interfaces/bat_ledger.mojom @@ -10,13 +10,13 @@ const string kServiceName = "bat_ledger"; interface BatLedgerService { Create(associated BatLedgerClient bat_ledger_client, associated BatLedger& bat_ledger); - SetProduction(bool isProduction); + SetEnvironment(ledger.mojom.Environment environment); SetDebug(bool isDebug); SetReconcileTime(int32 time); SetShortRetries(bool short_retries); SetTesting(); - GetProduction() => (bool production); + GetEnvironment() => (ledger.mojom.Environment environment); GetDebug() => (bool debug); GetReconcileTime() => (int32 time); GetShortRetries() => (bool short_retries); diff --git a/vendor/bat-native-ledger/include/bat/ledger/ledger.h b/vendor/bat-native-ledger/include/bat/ledger/ledger.h index df6858fcf2b0..d8c1a04996fb 100644 --- a/vendor/bat-native-ledger/include/bat/ledger/ledger.h +++ b/vendor/bat-native-ledger/include/bat/ledger/ledger.h @@ -27,8 +27,9 @@ namespace ledger { using VisitData = ledger::mojom::VisitData; using VisitDataPtr = ledger::mojom::VisitDataPtr; +using Environment = ledger::mojom::Environment; -extern bool is_production; +extern Environment _environment; extern bool is_debug; extern bool is_testing; extern int reconcile_time; // minutes diff --git a/vendor/bat-native-ledger/include/bat/ledger/public/interfaces/ledger.mojom b/vendor/bat-native-ledger/include/bat/ledger/public/interfaces/ledger.mojom index 786eb3ef861a..b81c096ab73b 100644 --- a/vendor/bat-native-ledger/include/bat/ledger/public/interfaces/ledger.mojom +++ b/vendor/bat-native-ledger/include/bat/ledger/public/interfaces/ledger.mojom @@ -223,3 +223,9 @@ enum Result { RECURRING_TABLE_EMPTY = 23, EXPIRED_TOKEN = 24, }; + +enum Environment { + STAGING = 0, + PRODUCTION = 1, + DEVELOPMENT = 2 +}; diff --git a/vendor/bat-native-ledger/src/bat/ledger/internal/bat_helper.cc b/vendor/bat-native-ledger/src/bat/ledger/internal/bat_helper.cc index 2ab6d355b1db..b67ddec64d72 100644 --- a/vendor/bat-native-ledger/src/bat/ledger/internal/bat_helper.cc +++ b/vendor/bat-native-ledger/src/bat/ledger/internal/bat_helper.cc @@ -2513,31 +2513,55 @@ std::string buildURL(const std::string& path, std::string url; switch (server) { case SERVER_TYPES::BALANCE: - if (ledger::is_production) { - url = BALANCE_PRODUCTION_SERVER; - } else { - url = BALANCE_STAGING_SERVER; + switch (ledger::_environment) { + case ledger::Environment::STAGING: + url = BALANCE_STAGING_SERVER; + break; + case ledger::Environment::PRODUCTION: + url = BALANCE_PRODUCTION_SERVER; + break; + case ledger::Environment::DEVELOPMENT: + url = BALANCE_DEVELOPMENT_SERVER; + break; } break; case SERVER_TYPES::PUBLISHER: - if (ledger::is_production) { - url = PUBLISHER_PRODUCTION_SERVER; - } else { - url = PUBLISHER_STAGING_SERVER; + switch (ledger::_environment) { + case ledger::Environment::STAGING: + url = PUBLISHER_STAGING_SERVER; + break; + case ledger::Environment::PRODUCTION: + url = PUBLISHER_PRODUCTION_SERVER; + break; + case ledger::Environment::DEVELOPMENT: + url = PUBLISHER_DEVELOPMENT_SERVER; + break; } break; case SERVER_TYPES::PUBLISHER_DISTRO: - if (ledger::is_production) { - url = PUBLISHER_DISTRO_PRODUCTION_SERVER; - } else { - url = PUBLISHER_DISTRO_STAGING_SERVER; + switch (ledger::_environment) { + case ledger::Environment::STAGING: + url = PUBLISHER_DISTRO_STAGING_SERVER; + break; + case ledger::Environment::PRODUCTION: + url = PUBLISHER_DISTRO_PRODUCTION_SERVER; + break; + case ledger::Environment::DEVELOPMENT: + url = PUBLISHER_DISTRO_DEVELOPMENT_SERVER; + break; } break; - default: - if (ledger::is_production) { - url = LEDGER_PRODUCTION_SERVER; - } else { - url = LEDGER_STAGING_SERVER; + case SERVER_TYPES::LEDGER: + switch (ledger::_environment) { + case ledger::Environment::STAGING: + url = LEDGER_STAGING_SERVER; + break; + case ledger::Environment::PRODUCTION: + url = LEDGER_PRODUCTION_SERVER; + break; + case ledger::Environment::DEVELOPMENT: + url = LEDGER_DEVELOPMENT_SERVER; + break; } break; } diff --git a/vendor/bat-native-ledger/src/bat/ledger/internal/ledger_impl.cc b/vendor/bat-native-ledger/src/bat/ledger/internal/ledger_impl.cc index ea24bcf70ea8..48a8591f2f38 100644 --- a/vendor/bat-native-ledger/src/bat/ledger/internal/ledger_impl.cc +++ b/vendor/bat-native-ledger/src/bat/ledger/internal/ledger_impl.cc @@ -310,7 +310,10 @@ void LedgerImpl::OnLedgerStateLoaded(ledger::Result result, void LedgerImpl::SetConfirmationsWalletInfo( const braveledger_bat_helper::WALLET_INFO_ST& wallet_info) { if (!bat_confirmations_) { - confirmations::_is_production = ledger::is_production; + // TODO(Terry): change when ads/confirmations adopts enums + bool is_production = + ledger::_environment == ledger::Environment::PRODUCTION; + confirmations::_is_production = is_production; confirmations::_is_debug = ledger::is_debug; bat_confirmations_.reset( diff --git a/vendor/bat-native-ledger/src/bat/ledger/internal/static_values.h b/vendor/bat-native-ledger/src/bat/ledger/internal/static_values.h index e2ec102bfc3f..f50b3a17ea1a 100644 --- a/vendor/bat-native-ledger/src/bat/ledger/internal/static_values.h +++ b/vendor/bat-native-ledger/src/bat/ledger/internal/static_values.h @@ -14,18 +14,29 @@ "https://ledger-staging.mercury.basicattentiontoken.org" #define LEDGER_PRODUCTION_SERVER \ "https://ledger.mercury.basicattentiontoken.org" +#define LEDGER_DEVELOPMENT_SERVER \ +"https://ledger-dev.mercury.basicattentiontoken.org" + #define BALANCE_STAGING_SERVER \ "https://balance-staging.mercury.basicattentiontoken.org" #define BALANCE_PRODUCTION_SERVER \ "https://balance.mercury.basicattentiontoken.org" +#define BALANCE_DEVELOPMENT_SERVER \ +"https://balance-dev.mercury.basicattentiontoken.org" + #define PUBLISHER_STAGING_SERVER \ "https://publishers-staging.basicattentiontoken.org" #define PUBLISHER_PRODUCTION_SERVER \ "https://publishers.basicattentiontoken.org" +#define PUBLISHER_DEVELOPMENT_SERVER \ +"https://publishers-staging.basicattentiontoken.org" + #define PUBLISHER_DISTRO_STAGING_SERVER \ "https://publishers-staging-distro.basicattentiontoken.org" #define PUBLISHER_DISTRO_PRODUCTION_SERVER \ "https://publishers-distro.basicattentiontoken.org" +#define PUBLISHER_DISTRO_DEVELOPMENT_SERVER \ +"https://publishers-staging-distro.basicattentiontoken.org" #define PREFIX_V2 "/v2" #define PREFIX_V4 "/v4" diff --git a/vendor/bat-native-ledger/src/bat/ledger/internal/uphold/uphold_util.cc b/vendor/bat-native-ledger/src/bat/ledger/internal/uphold/uphold_util.cc index 15384f160c7a..cc257de28e89 100644 --- a/vendor/bat-native-ledger/src/bat/ledger/internal/uphold/uphold_util.cc +++ b/vendor/bat-native-ledger/src/bat/ledger/internal/uphold/uphold_util.cc @@ -4,6 +4,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include +#include #include "base/base64.h" #include "base/strings/string_number_conversions.h" @@ -15,26 +16,26 @@ namespace braveledger_uphold { std::string GetClientId() { - return ledger::is_production + return ledger::_environment == ledger::Environment::PRODUCTION ? kClientIdProduction : kClientIdStaging; } std::string GetClientSecret() { - return ledger::is_production + return ledger::_environment == ledger::Environment::PRODUCTION ? kClientSecretProduction : kClientSecretStaging; } std::string GetUrl() { - return ledger::is_production + return ledger::_environment == ledger::Environment::PRODUCTION ? kUrlProduction : kUrlStaging; } std::string GetAPIUrl(const std::string& path) { std::string url; - if (ledger::is_production) { + if (ledger::_environment == ledger::Environment::PRODUCTION) { url = kAPIUrlProduction; } else { url = kAPIUrlStaging; @@ -44,7 +45,7 @@ std::string GetAPIUrl(const std::string& path) { } std::string GetFeeAddress() { - return ledger::is_production + return ledger::_environment == ledger::Environment::PRODUCTION ? kFeeAddressProduction : kFeeAddressStaging; } diff --git a/vendor/bat-native-ledger/src/bat/ledger/internal/uphold/uphold_util_unittest.cc b/vendor/bat-native-ledger/src/bat/ledger/internal/uphold/uphold_util_unittest.cc index 4b58a083e893..42dcfd05e59d 100644 --- a/vendor/bat-native-ledger/src/bat/ledger/internal/uphold/uphold_util_unittest.cc +++ b/vendor/bat-native-ledger/src/bat/ledger/internal/uphold/uphold_util_unittest.cc @@ -19,53 +19,53 @@ class UpholdUtilTest : public testing::Test { TEST(UpholdUtilTest, GetClientId) { // production - ledger::is_production = true; + ledger::_environment = ledger::Environment::PRODUCTION; std::string result = braveledger_uphold::GetClientId(); ASSERT_EQ(result, kClientIdProduction); // staging - ledger::is_production = false; + ledger::_environment = ledger::Environment::STAGING; result = braveledger_uphold::GetClientId(); ASSERT_EQ(result, kClientIdStaging); } TEST(UpholdUtilTest, GetClientSecret) { // production - ledger::is_production = true; + ledger::_environment = ledger::Environment::PRODUCTION; std::string result = braveledger_uphold::GetClientSecret(); ASSERT_EQ(result, kClientSecretProduction); // staging - ledger::is_production = false; + ledger::_environment = ledger::Environment::STAGING; result = braveledger_uphold::GetClientSecret(); ASSERT_EQ(result, kClientSecretStaging); } TEST(UpholdUtilTest, GetAPIUrl) { // empty path, production - ledger::is_production = true; + ledger::_environment = ledger::Environment::PRODUCTION; std::string result = braveledger_uphold::GetAPIUrl(""); ASSERT_EQ(result, kAPIUrlProduction); // empty path, staging - ledger::is_production = false; + ledger::_environment = ledger::Environment::STAGING; result = braveledger_uphold::GetAPIUrl(""); ASSERT_EQ(result, kAPIUrlStaging); // with path - ledger::is_production = false; + ledger::_environment = ledger::Environment::STAGING; result = braveledger_uphold::GetAPIUrl("/v0/testing"); ASSERT_EQ(result, static_cast(kAPIUrlStaging) + "/v0/testing"); } TEST(UpholdUtilTest, GetFeeAddress) { // production - ledger::is_production = true; + ledger::_environment = ledger::Environment::PRODUCTION; std::string result = braveledger_uphold::GetFeeAddress(); ASSERT_EQ(result, kFeeAddressProduction); // staging - ledger::is_production = false; + ledger::_environment = ledger::Environment::STAGING; result = braveledger_uphold::GetFeeAddress(); ASSERT_EQ(result, kFeeAddressStaging); } @@ -94,7 +94,7 @@ TEST(UpholdUtilTest, ConvertToProbi) { TEST(UpholdUtilTest, GetVerifyUrl) { // production - ledger::is_production = true; + ledger::_environment = ledger::Environment::PRODUCTION; std::string result = braveledger_uphold::GetVerifyUrl("rdfdsfsdfsdf"); ASSERT_EQ(result, "https://uphold.com/authorize/" @@ -103,7 +103,7 @@ TEST(UpholdUtilTest, GetVerifyUrl) { "transactions:transfer:others&intention=kyc&state=rdfdsfsdfsdf"); // staging - ledger::is_production = false; + ledger::_environment = ledger::Environment::STAGING; result = braveledger_uphold::GetVerifyUrl("rdfdsfsdfsdf"); ASSERT_EQ(result, "https://sandbox.uphold.com/authorize/" @@ -118,12 +118,12 @@ TEST(UpholdUtilTest, GetAddUrl) { ASSERT_EQ(result, ""); // production - ledger::is_production = true; + ledger::_environment = ledger::Environment::PRODUCTION; result = braveledger_uphold::GetAddUrl("9324i5i32459i"); ASSERT_EQ(result, "https://uphold.com/dashboard/cards/9324i5i32459i/add"); // staging - ledger::is_production = false; + ledger::_environment = ledger::Environment::STAGING; result = braveledger_uphold::GetAddUrl("9324i5i32459i"); ASSERT_EQ(result, "https://sandbox.uphold.com/dashboard/cards/9324i5i32459i/add"); @@ -135,12 +135,12 @@ TEST(UpholdUtilTest, GetWithdrawUrl) { ASSERT_EQ(result, ""); // production - ledger::is_production = true; + ledger::_environment = ledger::Environment::PRODUCTION; result = braveledger_uphold::GetWithdrawUrl("9324i5i32459i"); ASSERT_EQ(result, "https://uphold.com/dashboard/cards/9324i5i32459i/use"); // staging - ledger::is_production = false; + ledger::_environment = ledger::Environment::STAGING; result = braveledger_uphold::GetWithdrawUrl("9324i5i32459i"); ASSERT_EQ(result, "https://sandbox.uphold.com/dashboard/cards/9324i5i32459i/use"); @@ -148,14 +148,14 @@ TEST(UpholdUtilTest, GetWithdrawUrl) { TEST(UpholdUtilTest, GetSecondStepVerify) { // production - ledger::is_production = true; + ledger::_environment = ledger::Environment::PRODUCTION; std::string result = braveledger_uphold::GetSecondStepVerify(); ASSERT_EQ(result, "https://uphold.com/signup/step2?" "application_id=6d8d9473ed20be627f71ed46e207f40c004c5b1a&intention=kyc"); // staging - ledger::is_production = false; + ledger::_environment = ledger::Environment::STAGING; result = braveledger_uphold::GetSecondStepVerify(); ASSERT_EQ(result, "https://sandbox.uphold.com/signup/step2?" @@ -164,13 +164,13 @@ TEST(UpholdUtilTest, GetSecondStepVerify) { TEST(UpholdUtilTest, GetSecondStepRegistration) { // production - ledger::is_production = true; + ledger::_environment = ledger::Environment::PRODUCTION; std::string result = braveledger_uphold::GetSecondStepRegistration(); ASSERT_EQ(result, "https://uphold.com/signup/step2"); // staging - ledger::is_production = false; + ledger::_environment = ledger::Environment::STAGING; result = braveledger_uphold::GetSecondStepRegistration(); ASSERT_EQ(result, "https://sandbox.uphold.com/signup/step2"); @@ -206,7 +206,7 @@ TEST(UpholdUtilTest, RequestAuthorization) { // token is not defined - ledger::is_production = false; + ledger::_environment = ledger::Environment::STAGING; result = braveledger_uphold::RequestAuthorization(); ASSERT_EQ(result.at(0), "Authorization: Basic NGMyYjY2NWNhMDYwZDkxMmZlYzVjNzM1YzczNDg1OWEwNjEx" @@ -219,13 +219,13 @@ TEST(UpholdUtilTest, GenerateRandomString) { ASSERT_EQ(result, "123456789"); // random string - ledger::is_production = false; + ledger::_environment = ledger::Environment::STAGING; result = braveledger_uphold::GenerateRandomString(false); ASSERT_EQ(result.length(), 64u); } TEST(UpholdUtilTest, GenerateLinks) { - ledger::is_production = false; + ledger::_environment = ledger::Environment::STAGING; auto wallet = ledger::ExternalWallet::New(); wallet->address = "123123123124234234234"; @@ -299,7 +299,7 @@ TEST(UpholdUtilTest, GenerateLinks) { } TEST(UpholdUtilTest, GenerateVerifyLink) { - ledger::is_production = false; + ledger::_environment = ledger::Environment::STAGING; auto wallet = ledger::ExternalWallet::New(); wallet->one_time_string = "123123123124234234234"; diff --git a/vendor/bat-native-ledger/src/bat/ledger/ledger.cc b/vendor/bat-native-ledger/src/bat/ledger/ledger.cc index 40a231732f4f..dad4de24b2fe 100644 --- a/vendor/bat-native-ledger/src/bat/ledger/ledger.cc +++ b/vendor/bat-native-ledger/src/bat/ledger/ledger.cc @@ -13,7 +13,8 @@ namespace ledger { -bool is_production = true; +Environment _environment = Environment::STAGING; + bool is_debug = false; bool is_testing = false; int reconcile_time = 0; // minutes