Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reset reconcile stamp even if ac is off #5692

Merged
merged 1 commit into from
May 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Not really changed here, but maybe we can fix the typo: Staring -> Starting


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