Skip to content

Commit

Permalink
Adds development env
Browse files Browse the repository at this point in the history
  • Loading branch information
NejcZdovc committed Aug 29, 2019
1 parent 8f9c17f commit bf0c5fa
Show file tree
Hide file tree
Showing 14 changed files with 195 additions and 98 deletions.
87 changes: 63 additions & 24 deletions components/brave_rewards/browser/rewards_service_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
}

Expand Down Expand Up @@ -1167,7 +1167,7 @@ class BraveRewardsBrowserTest :

const std::vector<double> 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));
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -1511,7 +1550,7 @@ IN_PROC_BROWSER_TEST_F(BraveRewardsBrowserTest, HandleFlagsWrongInput) {
GetReconcileTime();
GetShortRetries();
GetDebug();
GetProduction();
GetEnvironment();
RunUntilIdle();
}

Expand Down
40 changes: 25 additions & 15 deletions components/brave_rewards/browser/rewards_service_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}
}
}

Expand Down Expand Up @@ -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
}

Expand All @@ -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) {
Expand All @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions components/brave_rewards/browser/rewards_service_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class PublisherInfoDatabase;
class RewardsNotificationServiceImpl;
class BraveRewardsBrowserTest;

using GetProductionCallback = base::Callback<void(bool)>;
using GetEnvironmentCallback = base::Callback<void(ledger::Environment)>;
using GetDebugCallback = base::Callback<void(bool)>;
using GetReconcileTimeCallback = base::Callback<void(int32_t)>;
using GetShortRetriesCallback = base::Callback<void(bool)>;
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions components/services/bat_ledger/bat_ledger_service_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
5 changes: 3 additions & 2 deletions components/services/bat_ledger/bat_ledger_service_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#define BRAVE_COMPONENTS_SERVICES_BAT_LEDGER_BAT_LEDGER_SERVICE_IMPL_H_

#include <memory>
#include <bat/ledger/ledger.h>

#include "brave/components/services/bat_ledger/public/interfaces/bat_ledger.mojom.h"
#include "services/service_manager/public/cpp/service_context_ref.h"
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion vendor/bat-native-ledger/include/bat/ledger/ledger.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,3 +223,9 @@ enum Result {
RECURRING_TABLE_EMPTY = 23,
EXPIRED_TOKEN = 24,
};

enum Environment {
STAGING = 0,
PRODUCTION = 1,
DEVELOPMENT = 2
};
Loading

0 comments on commit bf0c5fa

Please sign in to comment.