Skip to content

Commit

Permalink
Change payment token redemption timing
Browse files Browse the repository at this point in the history
  • Loading branch information
tmancey committed Mar 25, 2019
1 parent 596d189 commit 4b9bd5d
Show file tree
Hide file tree
Showing 21 changed files with 253 additions and 49 deletions.
45 changes: 43 additions & 2 deletions components/brave_rewards/browser/rewards_service_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,41 @@ IN_PROC_BROWSER_TEST_F(BraveRewardsBrowserTest, HandleFlagsSingleArg) {
GetProduction();
RunUntilIdle();

// SetDebug(true)
EXPECT_CALL(*this, OnGetDebug(true));
// Debug - true and 1
EXPECT_CALL(*this, OnGetDebug(false)).Times(2);
// Debug - false and random
EXPECT_CALL(*this, OnGetDebug(true)).Times(2);

rewards_service()->SetDebug(true);
GetDebug();
RunUntilIdle();

// Debug - true
rewards_service()->SetDebug(true);
rewards_service()->HandleFlags("debug=true");
GetDebug();
RunUntilIdle();

// Debug - 1
rewards_service()->SetDebug(true);
rewards_service()->HandleFlags("debug=1");
GetDebug();
RunUntilIdle();

// Debug - false
rewards_service()->SetDebug(false);
rewards_service()->HandleFlags("debug=false");
GetDebug();
RunUntilIdle();

// Debug - random
rewards_service()->SetDebug(false);
rewards_service()->HandleFlags("debug=werwe");
GetDebug();
RunUntilIdle();

// positive number
EXPECT_CALL(*this, OnGetReconcileTime(10));
// negative number and string
Expand Down Expand Up @@ -428,36 +463,42 @@ IN_PROC_BROWSER_TEST_F(BraveRewardsBrowserTest, HandleFlagsSingleArg) {

IN_PROC_BROWSER_TEST_F(BraveRewardsBrowserTest, HandleFlagsMultipleFlags) {
EXPECT_CALL(*this, OnGetProduction(false));
EXPECT_CALL(*this, OnGetDebug(false));
EXPECT_CALL(*this, OnGetReconcileTime(10));
EXPECT_CALL(*this, OnGetShortRetries(true));

rewards_service()->SetProduction(true);
rewards_service()->SetDebug(true);
rewards_service()->SetReconcileTime(0);
rewards_service()->SetShortRetries(false);

rewards_service()->HandleFlags(
"staging=true,short-retries=true,reconcile-interval=10");
"staging=true,debug=true,short-retries=true,reconcile-interval=10");

GetReconcileTime();
GetShortRetries();
GetProduction();
GetDebug();
RunUntilIdle();
}

IN_PROC_BROWSER_TEST_F(BraveRewardsBrowserTest, HandleFlagsWrongInput) {
EXPECT_CALL(*this, OnGetProduction(true));
EXPECT_CALL(*this, OnGetDebug(true));
EXPECT_CALL(*this, OnGetReconcileTime(0));
EXPECT_CALL(*this, OnGetShortRetries(false));

rewards_service()->SetProduction(true);
rewards_service()->SetDebug(true);
rewards_service()->SetReconcileTime(0);
rewards_service()->SetShortRetries(false);

rewards_service()->HandleFlags(
"staging=,shortretries=true,reconcile-interval");
"staging=,debug=,shortretries=true,reconcile-interval");

GetReconcileTime();
GetShortRetries();
GetProduction();
GetDebug();
RunUntilIdle();
}
20 changes: 20 additions & 0 deletions components/brave_rewards/browser/rewards_service_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,8 @@ void RewardsServiceImpl::StartLedger() {
#endif
SetProduction(isProduction);

SetDebug(false);

const base::CommandLine& command_line =
*base::CommandLine::ForCurrentProcess();

Expand Down Expand Up @@ -2453,6 +2455,20 @@ void RewardsServiceImpl::HandleFlags(const std::string& options) {
continue;
}

if (name == "debug") {
bool is_debug;
std::string lower = base::ToLowerASCII(value);

if (lower == "true" || lower == "1") {
is_debug = true;
} else {
is_debug = false;
}

SetDebug(is_debug);
continue;
}

if (name == "reconcile-interval") {
int reconcile_int;
bool success = base::StringToInt(value, &reconcile_int);
Expand Down Expand Up @@ -2557,6 +2573,10 @@ void RewardsServiceImpl::SetProduction(bool production) {
bat_ledger_service_->SetProduction(production);
}

void RewardsServiceImpl::SetDebug(bool debug) {
bat_ledger_service_->SetDebug(debug);
}

void RewardsServiceImpl::SetReconcileTime(int32_t time) {
bat_ledger_service_->SetReconcileTime(time);
}
Expand Down
3 changes: 3 additions & 0 deletions components/brave_rewards/browser/rewards_service_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class PublisherInfoDatabase;
class RewardsNotificationServiceImpl;

using GetProductionCallback = base::Callback<void(bool)>;
using GetDebugCallback = base::Callback<void(bool)>;
using GetReconcileTimeCallback = base::Callback<void(int32_t)>;
using GetShortRetriesCallback = base::Callback<void(bool)>;

Expand Down Expand Up @@ -176,6 +177,8 @@ class RewardsServiceImpl : public RewardsService,
void HandleFlags(const std::string& options);
void SetProduction(bool production);
void GetProduction(const GetProductionCallback& callback);
void SetDebug(bool debug);
void GetDebug(const GetDebugCallback& callback);
void SetReconcileTime(int32_t time);
void GetReconcileTime(const GetReconcileTimeCallback& callback);
void SetShortRetries(bool short_retries);
Expand Down
13 changes: 13 additions & 0 deletions components/services/bat_ledger/bat_ledger_service_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ bool testing() {
return ledger::is_testing;
}

bool debug() {
return ledger::is_debug;
}

}

namespace bat_ledger {
Expand Down Expand Up @@ -44,6 +48,11 @@ void BatLedgerServiceImpl::SetProduction(bool is_production) {
ledger::is_production = is_production;
}

void BatLedgerServiceImpl::SetDebug(bool is_debug) {
DCHECK(!initialized_ || debug());
ledger::is_debug = is_debug;
}

void BatLedgerServiceImpl::SetReconcileTime(int32_t time) {
DCHECK(!initialized_ || testing());
ledger::reconcile_time = time;
Expand All @@ -62,6 +71,10 @@ void BatLedgerServiceImpl::GetProduction(GetProductionCallback callback) {
std::move(callback).Run(ledger::is_production);
}

void BatLedgerServiceImpl::GetDebug(GetDebugCallback callback) {
std::move(callback).Run(ledger::is_debug);
}

void BatLedgerServiceImpl::GetReconcileTime(GetReconcileTimeCallback callback) {
std::move(callback).Run(ledger::reconcile_time);
}
Expand Down
59 changes: 31 additions & 28 deletions components/services/bat_ledger/bat_ledger_service_impl.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
/* Copyright (c) 2019 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef BRAVE_COMPONENTS_SERVICES_BAT_LEDGER_BAT_LEDGER_SERVICE_IMPL_H_
#define BRAVE_COMPONENTS_SERVICES_BAT_LEDGER_BAT_LEDGER_SERVICE_IMPL_H_
#ifndef COMPONENTS_SERVICES_BAT_LEDGER_BAT_LEDGER_SERVICE_IMPL_H_
#define COMPONENTS_SERVICES_BAT_LEDGER_BAT_LEDGER_SERVICE_IMPL_H_

#include <memory>

Expand All @@ -13,31 +14,33 @@
namespace bat_ledger {

class BatLedgerServiceImpl : public mojom::BatLedgerService {
public:
explicit BatLedgerServiceImpl(
std::unique_ptr<service_manager::ServiceContextRef> service_ref);
~BatLedgerServiceImpl() override;

// bat_ledger::mojom::BatLedgerService
void Create(mojom::BatLedgerClientAssociatedPtrInfo client_info,
mojom::BatLedgerAssociatedRequest bat_ledger) override;

void SetProduction(bool isProduction) override;
void SetReconcileTime(int32_t time) override;
void SetShortRetries(bool short_retries) override;
void SetTesting() override;

void GetProduction(GetProductionCallback callback) override;
void GetReconcileTime(GetReconcileTimeCallback callback) override;
void GetShortRetries(GetShortRetriesCallback callback) override;

private:
const std::unique_ptr<service_manager::ServiceContextRef> service_ref_;
bool initialized_;

DISALLOW_COPY_AND_ASSIGN(BatLedgerServiceImpl);
public:
explicit BatLedgerServiceImpl(
std::unique_ptr<service_manager::ServiceContextRef> service_ref);
~BatLedgerServiceImpl() override;

// bat_ledger::mojom::BatLedgerService
void Create(mojom::BatLedgerClientAssociatedPtrInfo client_info,
mojom::BatLedgerAssociatedRequest bat_ledger) override;

void SetProduction(bool isProduction) 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 GetDebug(GetDebugCallback callback) override;
void GetReconcileTime(GetReconcileTimeCallback callback) override;
void GetShortRetries(GetShortRetriesCallback callback) override;

private:
const std::unique_ptr<service_manager::ServiceContextRef> service_ref_;
bool initialized_;

DISALLOW_COPY_AND_ASSIGN(BatLedgerServiceImpl);
};

} // namespace bat_ledger
} // namespace bat_ledger

#endif // BRAVE_COMPONENTS_SERVICES_BAT_LEDGER_BAT_LEDGER_SERVICE_IMPL_H_
#endif // COMPONENTS_SERVICES_BAT_LEDGER_BAT_LEDGER_SERVICE_IMPL_H_
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ interface BatLedgerService {
Create(associated BatLedgerClient bat_ledger_client,
associated BatLedger& bat_ledger);
SetProduction(bool isProduction);
SetDebug(bool isDebug);
SetReconcileTime(int32 time);
SetShortRetries(bool short_retries);
SetTesting();

GetProduction() => (bool production);
GetDebug() => (bool debug);
GetReconcileTime() => (int32 time);
GetShortRetries() => (bool short_retries);
};
Expand Down
3 changes: 3 additions & 0 deletions vendor/bat-native-ads/src/bat/ads/internal/ads_serve.cc
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,9 @@ void AdsServe::RetryDownloadingCatalog() {
next_retry_start_timer_in_ *= 2;
}

auto rand_delay = base::RandInt(0, next_retry_start_timer_in_ / 10);
next_retry_start_timer_in_ += rand_delay;

ads_->StartCollectingActivity(next_retry_start_timer_in_);
}

Expand Down
2 changes: 2 additions & 0 deletions vendor/bat-native-confirmations/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ source_set("bat-native-confirmations") {
"src/bat/confirmations/internal/security_helper.h",
"src/bat/confirmations/internal/string_helper.cc",
"src/bat/confirmations/internal/string_helper.h",
"src/bat/confirmations/internal/time.cc",
"src/bat/confirmations/internal/time.h",
"src/bat/confirmations/internal/token_info.cc",
"src/bat/confirmations/internal/token_info.h",
"src/bat/confirmations/internal/unblinded_tokens.cc",
Expand Down
6 changes: 6 additions & 0 deletions vendor/bat-native-confirmations/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@ Use staging Ads Serve as defined by `STAGING_SERVER` in `static_values.h`. Defau
--rewards=staging=true
```

Use shorter timers to help with testing token redemption as defined by `kDebugNextTokenRedemptionAfterSeconds` in `static_values.h`.

```
--rewards=debug=true
```

Enable diagnostic logging, where `#` should set to a minimum log level. Valid values are from 0 to 3 where INFO = 0, WARNING = 1, ERROR = 2 and FATAL = 3. So if you want INFO, WARNING and ERROR you would choose 2

```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ namespace confirmations {
// Determines whether to use the staging or production Ad Serve
extern bool _is_production;

// Determines whether to enable or disable debugging
extern bool _is_debug;

extern const char _confirmations_name[];

using TransactionInfo = ::ledger::TransactionInfo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
namespace confirmations {

bool _is_production = false;
bool _is_debug = false;

const char _confirmations_name[] = "confirmations.json";

Expand Down
Loading

0 comments on commit 4b9bd5d

Please sign in to comment.