Skip to content

Commit

Permalink
Merge pull request #5692 from brave/reconcile-reset
Browse files Browse the repository at this point in the history
Reset reconcile stamp even if ac is off
  • Loading branch information
NejcZdovc authored May 29, 2020
2 parents dc4219c + a4543e5 commit a89eca5
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 9 deletions.
78 changes: 78 additions & 0 deletions components/brave_rewards/browser/rewards_service_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2809,3 +2809,81 @@ IN_PROC_BROWSER_TEST_F(
"[data-test-id=notification-close]",
false);
}

IN_PROC_BROWSER_TEST_F(BraveRewardsBrowserTest, CheckIfReconcileWasReset) {
EnableRewards();
uint64_t current_stamp = 0;

base::RunLoop run_loop_first;
rewards_service_->GetReconcileStamp(
base::BindLambdaForTesting([&](uint64_t stamp) {
current_stamp = stamp;
run_loop_first.Quit();
}));
run_loop_first.Run();

ClaimPromotionViaCode();

VisitPublisher("duckduckgo.com", true);

TipPublisher("duckduckgo.com", ContributionType::MonthlyTip, true);

base::RunLoop run_loop_second;
rewards_service_->GetReconcileStamp(
base::BindLambdaForTesting([&](uint64_t stamp) {
ASSERT_NE(current_stamp, stamp);
run_loop_second.Quit();
}));
run_loop_second.Run();
}

IN_PROC_BROWSER_TEST_F(BraveRewardsBrowserTest, CheckIfReconcileWasResetACOff) {
EnableRewards();
uint64_t current_stamp = 0;

rewards_service_->SetAutoContribute(false);

base::RunLoop run_loop_first;
rewards_service_->GetReconcileStamp(
base::BindLambdaForTesting([&](uint64_t stamp) {
current_stamp = stamp;
run_loop_first.Quit();
}));
run_loop_first.Run();

ClaimPromotionViaCode();
TipPublisher("duckduckgo.com", ContributionType::MonthlyTip, true);

base::RunLoop run_loop_second;
rewards_service_->GetReconcileStamp(
base::BindLambdaForTesting([&](uint64_t stamp) {
ASSERT_NE(current_stamp, stamp);
run_loop_second.Quit();
}));
run_loop_second.Run();
}

IN_PROC_BROWSER_TEST_F(BraveRewardsBrowserTest, CheckIfReconcileWasResetEmpty) {
EnableRewards();
uint64_t current_stamp = 0;

base::RunLoop run_loop_first;
rewards_service_->GetReconcileStamp(
base::BindLambdaForTesting([&](uint64_t stamp) {
current_stamp = stamp;
run_loop_first.Quit();
}));
run_loop_first.Run();

ClaimPromotionViaCode();

rewards_service_->StartMonthlyContributionForTest();

base::RunLoop run_loop_second;
rewards_service_->GetReconcileStamp(
base::BindLambdaForTesting([&](uint64_t stamp) {
ASSERT_NE(current_stamp, stamp);
run_loop_second.Quit();
}));
run_loop_second.Run();
}
Original file line number Diff line number Diff line change
Expand Up @@ -150,25 +150,31 @@ void Contribution::ResetReconcileStamp() {
}

void Contribution::StartMonthlyContribution() {
const auto reconcile_stamp = ledger_->GetReconcileStamp();
ResetReconcileStamp();

if (!ledger_->GetRewardsMainEnabled()) {
ResetReconcileStamp();
return;
}

BLOG(1, "Staring monthly contribution");

auto callback = std::bind(&Contribution::StartAutoContribute,
this,
_1);
_1,
reconcile_stamp);

monthly_->Process(callback);
}

void Contribution::StartAutoContribute(const ledger::Result result) {
void Contribution::StartAutoContribute(
const ledger::Result result,
const uint64_t reconcile_stamp) {
if (result != ledger::Result::LEDGER_OK) {
BLOG(0, "Monthly contribution failed");
}

ac_->Process();
ac_->Process(reconcile_stamp);
}

void Contribution::OnBalance(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ class Contribution {
ledger::ResultCallback callback);

private:
void StartAutoContribute(const ledger::Result result);
void StartAutoContribute(
const ledger::Result result,
const uint64_t reconcile_stamp);

void ContributionCompletedSaved(const ledger::Result result);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ ContributionAC::ContributionAC(bat_ledger::LedgerImpl* ledger,

ContributionAC::~ContributionAC() = default;

void ContributionAC::Process() {
void ContributionAC::Process(const uint64_t reconcile_stamp) {
if (!ledger_->GetRewardsMainEnabled() || !ledger_->GetAutoContribute()) {
BLOG(1, "Auto contribution is off");
return;
Expand All @@ -34,7 +34,7 @@ void ContributionAC::Process() {
"",
ledger::ExcludeFilter::FILTER_ALL_EXCEPT_EXCLUDED,
true,
ledger_->GetReconcileStamp(),
reconcile_stamp,
false,
ledger_->GetPublisherMinVisits());

Expand All @@ -43,7 +43,6 @@ void ContributionAC::Process() {
_1);

ledger_->GetActivityInfoList(0, 0, std::move(filter), get_callback);
contribution_->ResetReconcileStamp();
}

void ContributionAC::PreparePublisherList(ledger::PublisherInfoList list) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ContributionAC {

~ContributionAC();

void Process();
void Process(const uint64_t reconcile_stamp);

private:
void PreparePublisherList(ledger::PublisherInfoList list);
Expand Down

0 comments on commit a89eca5

Please sign in to comment.