From dd873b19a7702c9fd732d316af029c63186db7c9 Mon Sep 17 00:00:00 2001 From: NejcZdovc Date: Tue, 24 Mar 2020 09:08:54 +0100 Subject: [PATCH] Fixes contribution that is split Resolves https://github.com/brave/brave-browser/issues/8828 --- .../browser/rewards_service_browsertest.cc | 203 +++++++++++++----- .../ui/components/modalActivity/index.tsx | 1 + .../ui/components/walletSummary/index.tsx | 2 +- test/data/rewards-data/contribution_resp.json | 16 ++ .../rewards-data/current_reconcile_resp.json | 5 + test/data/rewards-data/reconcile_resp.json | 67 ++++++ .../register_credential_resp.json | 9 + .../surveyor_voting_credential_resp.json | 38 ++++ .../rewards-data/surveyor_voting_resp.json | 26 +++ .../internal/contribution/contribution.cc | 14 +- .../contribution/contribution_unblinded.cc | 2 +- 11 files changed, 323 insertions(+), 60 deletions(-) create mode 100644 test/data/rewards-data/contribution_resp.json create mode 100644 test/data/rewards-data/current_reconcile_resp.json create mode 100644 test/data/rewards-data/reconcile_resp.json create mode 100644 test/data/rewards-data/register_credential_resp.json create mode 100644 test/data/rewards-data/surveyor_voting_credential_resp.json create mode 100644 test/data/rewards-data/surveyor_voting_resp.json diff --git a/components/brave_rewards/browser/rewards_service_browsertest.cc b/components/brave_rewards/browser/rewards_service_browsertest.cc index effd11e7eee6..693f56fb0c7d 100644 --- a/components/brave_rewards/browser/rewards_service_browsertest.cc +++ b/components/brave_rewards/browser/rewards_service_browsertest.cc @@ -142,6 +142,14 @@ namespace brave_test_resp { std::string uphold_auth_resp_; std::string uphold_transactions_resp_; std::string uphold_commit_resp_; + + std::string contribution_; + std::string reconcile_; + std::string current_reconcile_; + std::string register_; + std::string register_credential_; + std::string surveyor_voting_; + std::string surveyor_voting_credential_; } // namespace brave_test_resp class BraveRewardsBrowserTest @@ -391,6 +399,30 @@ class BraveRewardsBrowserTest braveledger_uphold::GetAPIUrl("/v0/me"), base::CompareCase::INSENSITIVE_ASCII)) { *response = GetUpholdUser(); + } else if (URLMatches(url, WALLET_PROPERTIES, PREFIX_V2, + ServerTypes::LEDGER)) { + GURL gurl(url); + if (gurl.has_query()) { + *response = brave_test_resp::reconcile_; + } else { + *response = brave_test_resp::current_reconcile_; + } + + } else if (URLMatches(url, RECONCILE_CONTRIBUTION, PREFIX_V2, + ServerTypes::LEDGER)) { + *response = brave_test_resp::contribution_; + } else if (URLMatches(url, REGISTER_VIEWING, PREFIX_V2, + ServerTypes::LEDGER)) { + if (url.find(REGISTER_VIEWING "/") != std::string::npos) + *response = brave_test_resp::register_credential_; + else + *response = brave_test_resp::register_; + } else if (URLMatches(url, SURVEYOR_BATCH_VOTING, PREFIX_V2, + ServerTypes::LEDGER)) { + if (url.find(SURVEYOR_BATCH_VOTING "/") != std::string::npos) + *response = brave_test_resp::surveyor_voting_credential_; + else + *response = brave_test_resp::surveyor_voting_; } } @@ -456,6 +488,16 @@ class BraveRewardsBrowserTest wait_for_multiple_tip_completed_loop_->Run(); } + void WaitForMultipleACReconcileCompleted(int32_t needed) { + multiple_ac_reconcile_needed_ = needed; + if (multiple_ac_reconcile_completed_) { + return; + } + + wait_for_multiple_ac_completed_loop_.reset(new base::RunLoop); + wait_for_multiple_ac_completed_loop_->Run(); + } + void WaitForInsufficientFundsNotification() { if (insufficient_notification_would_have_already_shown_) { return; @@ -711,6 +753,26 @@ class BraveRewardsBrowserTest ASSERT_TRUE(base::ReadFileToString( path.AppendASCII("uphold_commit_resp.json"), &brave_test_resp::uphold_commit_resp_)); + + ASSERT_TRUE( + base::ReadFileToString(path.AppendASCII("contribution_resp.json"), + &brave_test_resp::contribution_)); + ASSERT_TRUE(base::ReadFileToString(path.AppendASCII("reconcile_resp.json"), + &brave_test_resp::reconcile_)); + ASSERT_TRUE( + base::ReadFileToString(path.AppendASCII("current_reconcile_resp.json"), + &brave_test_resp::current_reconcile_)); + ASSERT_TRUE(base::ReadFileToString(path.AppendASCII("register_resp.json"), + &brave_test_resp::register_)); + ASSERT_TRUE(base::ReadFileToString( + path.AppendASCII("register_credential_resp.json"), + &brave_test_resp::register_credential_)); + ASSERT_TRUE( + base::ReadFileToString(path.AppendASCII("surveyor_voting_resp.json"), + &brave_test_resp::surveyor_voting_)); + ASSERT_TRUE(base::ReadFileToString( + path.AppendASCII("surveyor_voting_credential_resp.json"), + &brave_test_resp::surveyor_voting_credential_)); } void UpdateContributionBalance(double amount, bool verified = false) { @@ -1349,6 +1411,17 @@ class BraveRewardsBrowserTest if (wait_for_ac_completed_loop_) { wait_for_ac_completed_loop_->Quit(); } + + // Multiple ac + multiple_ac_reconcile_count_++; + multiple_ac_reconcile_status_.push_back(converted_result); + + if (multiple_ac_reconcile_count_ == multiple_ac_reconcile_needed_) { + multiple_ac_reconcile_completed_ = true; + if (wait_for_multiple_ac_completed_loop_) { + wait_for_multiple_ac_completed_loop_->Quit(); + } + } } if (converted_type == ledger::RewardsType::ONE_TIME_TIP || @@ -1484,6 +1557,22 @@ class BraveRewardsBrowserTest UpdateContributionBalance(amount, should_contribute); } + void SetUpUpholdWallet( + const double balance, + const ledger::WalletStatus status = ledger::WalletStatus::VERIFIED) { + verified_wallet_ = true; + external_balance_ = balance; + + auto wallet = ledger::ExternalWallet::New(); + wallet->token = "token"; + wallet->address = external_wallet_address_; + wallet->status = status; + wallet->one_time_string = ""; + wallet->user_name = "Brave Test"; + wallet->transferred = true; + rewards_service()->SaveExternalWallet("uphold", std::move(wallet)); + } + MOCK_METHOD1(OnGetEnvironment, void(ledger::Environment)); MOCK_METHOD1(OnGetDebug, void(bool)); MOCK_METHOD1(OnGetReconcileTime, void(int32_t)); @@ -1511,8 +1600,16 @@ class BraveRewardsBrowserTest bool ac_reconcile_completed_ = false; ledger::Result ac_reconcile_status_ = ledger::Result::LEDGER_ERROR; std::unique_ptr wait_for_tip_completed_loop_; + + std::unique_ptr wait_for_multiple_ac_completed_loop_; + bool multiple_ac_reconcile_completed_ = false; + int32_t multiple_ac_reconcile_count_ = 0; + int32_t multiple_ac_reconcile_needed_ = 0; + std::vector multiple_ac_reconcile_status_; + bool tip_reconcile_completed_ = false; ledger::Result tip_reconcile_status_ = ledger::Result::LEDGER_ERROR; + std::unique_ptr wait_for_multiple_tip_completed_loop_; bool multiple_tip_reconcile_completed_ = false; int32_t multiple_tip_reconcile_count_ = 0; @@ -1541,7 +1638,6 @@ class BraveRewardsBrowserTest double verified_wallet_ = false; const std::string external_wallet_address_ = "abe5f454-fedd-4ea9-9203-470ae7315bb3"; - bool first_url_ac_called_ = false; }; IN_PROC_BROWSER_TEST_F(BraveRewardsBrowserTest, RenderWelcome) { @@ -2050,7 +2146,6 @@ IN_PROC_BROWSER_TEST_F(BraveRewardsBrowserTest, AutoContributeWhenACOff) { // Trigger contribution process rewards_service()->StartMonthlyContributionForTest(); - ASSERT_FALSE(first_url_ac_called_); } // #6 - Tip verified publisher @@ -2659,17 +2754,7 @@ IN_PROC_BROWSER_TEST_F(BraveRewardsBrowserTest, IN_PROC_BROWSER_TEST_F(BraveRewardsBrowserTest, TipWithVerifiedWallet) { - verified_wallet_ = true; - external_balance_ = 50.0; - - auto wallet = ledger::ExternalWallet::New(); - wallet->token = "token"; - wallet->address = external_wallet_address_; - wallet->status = ledger::WalletStatus::VERIFIED; - wallet->one_time_string = ""; - wallet->user_name = "Brave Test"; - wallet->transferred = true; - rewards_service()->SaveExternalWallet("uphold", std::move(wallet)); + SetUpUpholdWallet(50.0); // Enable Rewards EnableRewards(); @@ -2689,17 +2774,7 @@ IN_PROC_BROWSER_TEST_F(BraveRewardsBrowserTest, IN_PROC_BROWSER_TEST_F(BraveRewardsBrowserTest, MultipleTipsProduceMultipleFeesWithVerifiedWallet) { - verified_wallet_ = true; - external_balance_ = 50.0; - - auto wallet = ledger::ExternalWallet::New(); - wallet->token = "token"; - wallet->address = external_wallet_address_; - wallet->status = ledger::WalletStatus::VERIFIED; - wallet->one_time_string = ""; - wallet->user_name = "Brave Test"; - wallet->transferred = true; - rewards_service()->SaveExternalWallet("uphold", std::move(wallet)); + SetUpUpholdWallet(50.0); // Enable Rewards EnableRewards(); @@ -2760,17 +2835,7 @@ IN_PROC_BROWSER_TEST_F(BraveRewardsBrowserTest, TipConnectedPublisherAnon) { IN_PROC_BROWSER_TEST_F( BraveRewardsBrowserTest, TipConnectedPublisherAnonAndConnected) { - verified_wallet_ = true; - external_balance_ = 50.0; - - auto wallet = ledger::ExternalWallet::New(); - wallet->token = "token"; - wallet->address = external_wallet_address_; - wallet->status = ledger::WalletStatus::CONNECTED; - wallet->one_time_string = ""; - wallet->user_name = "Brave Test"; - wallet->transferred = true; - rewards_service()->SaveExternalWallet("uphold", std::move(wallet)); + SetUpUpholdWallet(50.0); // Enable Rewards EnableRewards(); @@ -2793,17 +2858,7 @@ IN_PROC_BROWSER_TEST_F( IN_PROC_BROWSER_TEST_F( BraveRewardsBrowserTest, TipConnectedPublisherConnected) { - verified_wallet_ = true; - external_balance_ = 50.0; - - auto wallet = ledger::ExternalWallet::New(); - wallet->token = "token"; - wallet->address = external_wallet_address_; - wallet->status = ledger::WalletStatus::CONNECTED; - wallet->one_time_string = ""; - wallet->user_name = "Brave Test"; - wallet->transferred = true; - rewards_service()->SaveExternalWallet("uphold", std::move(wallet)); + SetUpUpholdWallet(50.0, ledger::WalletStatus::CONNECTED); // Enable Rewards EnableRewards(); @@ -2827,17 +2882,7 @@ IN_PROC_BROWSER_TEST_F( IN_PROC_BROWSER_TEST_F( BraveRewardsBrowserTest, TipConnectedPublisherVerified) { - verified_wallet_ = true; - external_balance_ = 50.0; - - auto wallet = ledger::ExternalWallet::New(); - wallet->token = "token"; - wallet->address = external_wallet_address_; - wallet->status = ledger::WalletStatus::VERIFIED; - wallet->one_time_string = ""; - wallet->user_name = "Brave Test"; - wallet->transferred = true; - rewards_service()->SaveExternalWallet("uphold", std::move(wallet)); + SetUpUpholdWallet(50.0); // Enable Rewards EnableRewards(); @@ -3033,3 +3078,47 @@ IN_PROC_BROWSER_TEST_F(BraveRewardsBrowserTest, ShowMonthlyIfACOff) { WaitForSelector(popup_contents, "#panel-donate-monthly"); } + +IN_PROC_BROWSER_TEST_F( + BraveRewardsBrowserTest, + SplitProcessorAutoContribution) { + SetUpUpholdWallet(50.0); + + EnableRewards(); + + // Claim promotion using panel (30BAT) + const bool use_panel = true; + ClaimPromotion(use_panel); + + VisitPublisher("3zsistemi.si", true); + + // 30 form unblinded and 20 from uphold + rewards_service()->SetContributionAmount(50.0); + + // Trigger contribution process + rewards_service()->StartMonthlyContributionForTest(); + + // Wait for reconciliation to complete successfully + WaitForMultipleACReconcileCompleted(2); + ASSERT_EQ(multiple_ac_reconcile_status_[0], ledger::Result::LEDGER_OK); + ASSERT_EQ(multiple_ac_reconcile_status_[1], ledger::Result::LEDGER_OK); + + // Check monthly report + ASSERT_TRUE(ExecJs(contents(), + "document.querySelector(\"[data-test-id='showMonthlyReport']\").click();", + content::EXECUTE_SCRIPT_DEFAULT_OPTIONS, + content::ISOLATED_WORLD_ID_CONTENT_END)); + + + WaitForSelector(contents(), "#transactionTable"); + + ASSERT_NE(ElementInnerText("#transactionTable").find("-30.0BAT"), + std::string::npos); + + ASSERT_NE(ElementInnerText("#transactionTable").find("-20.0BAT"), + std::string::npos); + + // Check that summary table shows the appropriate contribution + ASSERT_NE(ElementInnerText("[color=contribute]").find("-50.0BAT"), + std::string::npos); +} diff --git a/components/brave_rewards/resources/ui/components/modalActivity/index.tsx b/components/brave_rewards/resources/ui/components/modalActivity/index.tsx index 680393c8049b..41727281756c 100644 --- a/components/brave_rewards/resources/ui/components/modalActivity/index.tsx +++ b/components/brave_rewards/resources/ui/components/modalActivity/index.tsx @@ -185,6 +185,7 @@ export default class ModalActivity extends React.PureComponent { return ( {getLocale('noActivity')} diff --git a/components/brave_rewards/resources/ui/components/walletSummary/index.tsx b/components/brave_rewards/resources/ui/components/walletSummary/index.tsx index 543978df79ed..2ebf787200d4 100644 --- a/components/brave_rewards/resources/ui/components/walletSummary/index.tsx +++ b/components/brave_rewards/resources/ui/components/walletSummary/index.tsx @@ -193,7 +193,7 @@ export default class WalletSummary extends React.PureComponent { { onActivity - ? + ? diff --git a/test/data/rewards-data/contribution_resp.json b/test/data/rewards-data/contribution_resp.json new file mode 100644 index 000000000000..bb90592f0817 --- /dev/null +++ b/test/data/rewards-data/contribution_resp.json @@ -0,0 +1,16 @@ +{ + "signature":"28a00fb8a4b663b9a6e38e8e712a3df, iay57CDbWSG9Y2z39QVgx0nSSexW4OAWwjQdBuq+EN 4BaXMtejRWXjKZ17aAfWLkj08t8ClSQCXFUo0QPkQvL 1 CdbDycAPfzVRsfT3p3jH8pdyFjuW1cySuu68jcovI0n 3p+RP29bqtPgACqJn98xWhUepfoV1ZQ2o4LfTOyHY9H\n", + "payload":{ + "adFree":{ + "fee":{ + "USD":5 + }, + "votes":100, + "altcurrency":"BAT", + "probi":"25000000000000000000" + } + }, + "surveyorId":"FuznYc8NaAXt+At2S+DdaM/rsEyHWd3vFpLpbCLm/z7", + "surveyVK":"==========ANONLOGIN_VK_BEG==========\n6SWJBmkQXkPm1/0Sge4ezHWVXRCtdbGFwcb5XZnjEH2 O4cvn69IzJiH5znUsFK45e4KNoccd4vHmtaozGQgEj 1\n2MHE1Qepdw64bc69nN58JDslzeI36AHr5VfRQfmB/VC 6xtkMq6YI56oVETjouerencG2CJ4pP1Y0PPEPWAyi84 1\n6belVbSubm7yHJFFD5JIz8BwCUBGzHawZH/ILqiSZGh 6r6Rpi8hGcQWa+regtXCtzx5uJI+BG3dzln6/DuKVGe 1\n9XqLkmga7sBZRBeESqNIs2HlUr71C7VQ13mG1Ias2W mg+JzzbVuJKLYABVE975tWtKT0o7dxJOBk16zUdNhc 1\n8yNeactDzb+RTNHNIrQSsvT00wEDP0cRdMkrD0vQW5A 4tga6SJf+aU3ewRmEa2+azykll3d77VTsfvTCVFbNWb y3h8BC+KIIU54hv02sISKzRpSMN3kam1sFfY6Dp2Xq 31AENnYtE0dGLqMhr0t+pDKx/dPJ1rO4hncDfqfaj2Z 1 0\n===========ANONLOGIN_VK_END==========", + "registrarVK":"==========ANONLOGIN_VK_BEG==========\nx3EmZXFb2jD7OocZz6l7o638S45k2kKrX5BrWp1Ox+ ANJXSauJVPNHKl/mmakFwxbkwJkJzfXe+c9+jxFtuX6 1\n5xMuqWE8J7HIHbW/UEJwFELYjTWRF10x7LMd7s46MVT 4DC6LqGM8zLz1pCsHA3qab48gkpeiQpNZAdb9owFvU6 1\n1tADCD6LdrEDQQDhRy1ijjAfhV9uKwlKKuhD6xXyPAZ BLOzUy+ZZh48riPnAHnUGal+ceCclccZXmoXXx92WHW 1\n7VRDst4U4iaT/9QNCwajEaqgRNtKPV1Dp5QuMjP019h HucbxBMGGAZBNLXGzfKsTlF+wAdmOFAvBRAo8i2Azd 1\n5SLk8SphICEkF+CNhN5g7IX2ih+Tb6w14LLlwupKw7y 96ANsdHzg0pwo2DDWOyAh1YPnION196pIT9xwISFZTA 3ef5G5d2c8cctdK4LuaxlSeEf1OZ100Sy5un5EjuHJB 77yFnY61GM7PHd6q3TLs2QS6c9PfrXD2idxaFq2DMd 1 0\n===========ANONLOGIN_VK_END==========" +} \ No newline at end of file diff --git a/test/data/rewards-data/current_reconcile_resp.json b/test/data/rewards-data/current_reconcile_resp.json new file mode 100644 index 000000000000..9488ff023e7f --- /dev/null +++ b/test/data/rewards-data/current_reconcile_resp.json @@ -0,0 +1,5 @@ +{ + "paymentStamp":1551325017004, + "probi":"1000000000000000000", + "altcurrency":"BAT" +} \ No newline at end of file diff --git a/test/data/rewards-data/reconcile_resp.json b/test/data/rewards-data/reconcile_resp.json new file mode 100644 index 000000000000..3e4032985602 --- /dev/null +++ b/test/data/rewards-data/reconcile_resp.json @@ -0,0 +1,67 @@ +{ + "altcurrency":"BAT", + "paymentStamp":0, + "httpSigningPubKey":"ecb1132244475e1a5c5f08648ce594fcad0fda4a1a715af2dab8b853256caef4", + "rates":{ + "BTC":0.000042699069007737, + "ETH":0.001201763025187042, + "XRP":0.5246050162355701, + "BCH":0.001243508186632462, + "LTC":0.003590124034065517, + "DASH":0.002026628168709195, + "BTG":0.012951215171998555, + "USD":0.16313341782581928, + "EUR":0.1433725775243243 + }, + "addresses":{ + "BAT":"0xD72237CC12D3a8209EdaF99713eae677eA26E358", + "BTC":"n2ri2eAqccRaS3BpRnVfJjdoM7Sq152nyM", + "CARD_ID":"cdd39592-0964-4048-9c50-4ff76e55d71d", + "ETH":"0xD72237CC12D3a8209EdaF99713eae677eA26E358", + "LTC":"mxhHDYMxbMFkZfgU6Jv1LHbg2XrruiQd5g" + }, + "parameters":{ + "adFree":{ + "currency":"BAT", + "fee":{ + "BAT":20 + }, + "choices":{ + "BAT":[ + 10, + 15, + 20, + 30, + 50, + 100 + ] + }, + "range":{ + "BAT":[ + 10, + 100 + ] + }, + "days":30, + "nanos":1 + } + }, + "grants":[ + { + "altcurrency":"BAT", + "expiryTime":1640995200, + "probi":"30000000000000000000" + } + ], + "probi":"30000000000000000000", + "balance":"30.0000", + "unconfirmed":"0.0000", + "requestType":"httpSignature", + "unsignedTx":{ + "denomination":{ + "amount":"1", + "currency":"BAT" + }, + "destination":"6654ecb0-6079-4f6c-ba58-791cc890a561" + } +} \ No newline at end of file diff --git a/test/data/rewards-data/register_credential_resp.json b/test/data/rewards-data/register_credential_resp.json new file mode 100644 index 000000000000..1f544791d16c --- /dev/null +++ b/test/data/rewards-data/register_credential_resp.json @@ -0,0 +1,9 @@ +{ + "surveyorIds":[ + "DL4LvvYYQL0UM99cK5Fzhj1hvno9tUXlVRDFTguKGlZ", + "6hK+xhExVChfP8y17iX4ZHDLDhQpAtFaexk6k0sPwj8", + "Dp8pzNQTa4eYI0IQiHN7+2bpx5rIkbGaNNV5LdffDz8", + "2xQG08DS+sBXlv7376WC+fkz/yZCr8K1QA4RghQKL9A" + ], + "verification":"5/alnMBLuQskB4nmX7Lj/6yZFqQCSrjGWMjwQXgpqPo B6vimIH1P4x95u2Md9WIEflpMa/HRJ41neCZ7wRkJzn 1 BdGcoaum1AMSMgUePvwVvsbP90XSZeGuqqJqcOKxKnm\n" +} \ No newline at end of file diff --git a/test/data/rewards-data/surveyor_voting_credential_resp.json b/test/data/rewards-data/surveyor_voting_credential_resp.json new file mode 100644 index 000000000000..ce1f661fb5b6 --- /dev/null +++ b/test/data/rewards-data/surveyor_voting_credential_resp.json @@ -0,0 +1,38 @@ +[ + { + "signature":"e33991d4902bd9982d0fb80e15345a8, 6xUZRtd9M1S6fMQdoB/XGMWIc7M5O6c14K/MH4fec8k 3ge5Wxa0+ZQixl8vq65S0zEXzOteKehzQLIOqQ5HTtZ 1 FqgCWY32c0dJdy1Uk1vVdSVMKzdtQkK90zN8u+IAXmG 84/PiJiFAg5pRZfmxVKCnse9PZVuQtKZw+cadbg+yp2\n", + "payload":{ + "cohort":"grant" + }, + "surveyorId":"Dp8pzNQTa4eYI0IQiHN7+2bpx5rIkbGaNNV5LdffDz8", + "surveyVK":"==========ANONLOGIN_VK_BEG==========\nfHkhv0xgGRxhKjKvL/oUxFG8sLW97r7w+8T9q8V3+J 6ItDG6BFN7whKf/ozxrcu1om1GseOL7DzFq//KFNngC 1\n9x53aLXEYLwK92474w22NNAnqX9wg47QVZsbEyUQu3e 8zQySgRqFaHwr3zXQirxFXyvH0LSOoe1B/p1emXnN9b 1\n28TUqLrPcbIvDwoB2/0x/xetyYFUeYpoYLEnuL/IpJu 67GL6ZD1MXQJE+omJC8WKfWHfgefWyiuEwj8A+Ot5iF 1\n4YHzUOgQOIC4ELDVxDw1B17PyBfbAC3Cl2D8FUW687p 2TYXeNIqgNpNTSPE/7FkMM2f8xwsQ7Y65cUoXhrE5Zm 1\n7kkcQewu9qDkVTPL8YbJ1FT1/w0DHzRqufvo2mdeQQm 8iXLonMliV5WaWx4D1rEQUziVQxJMtMEOOdOSyEL1Zp 4v3hwfYFAtwOqDAZtbUFSBorwdaV5HudJGRcoKNbBDM 7TYlKvktCudGxluiM412UiwlEz6liG6rsmIjzaMxFxc 1 0\n===========ANONLOGIN_VK_END==========", + "registrarVK":"==========ANONLOGIN_VK_BEG==========\n8MMyJJmqhl/C8PVenwLrAucbcDAAEVPHYa/WMvCFmTu 1sO+XpYPdGS/nqkJoy7Ni6L4vfkX3+6+/8mH+YsoIFb 1\nAPz5/M6QPS0ovaIptqGkTWvwe0wAUpCS1nkn3o578Ow 4QV/FW74yTEzJ2YbYoSwoYJGLeKJ3JWphpHhddmszL2 1\n4Jw9l7H/0I+xLBKl7//SPhWAFhVBbp3XWcewn69WYEx 3bUNzMKNsnpWRKgivBfShbCsfhcR0MGD4CfOFeAYhPE 1\nA5KTrxKgqycFYnvo9BgmYafUJ46Gti/5T+4LmDYOEHL B33Ne5c9wPj1LZF4Nd2O3xeRrF5z2WHtTcnW0dRWJqP 1\n6Aza57xUODgaN5vBgHnr3S7aZQezQl9M6t/IUcLDFxy 6TG8AP2XmsXiDYNfULlMlKmkcIE8wypl41airjsUDOo 7AlIDZY0AA96/pbbBwhaMMaPlsU8zKFrh3nln9R+lta 4O7rb+E7S1RiHB6MZ9f9tX0F6J6TIxX2a5miuRXptf 1 0\n===========ANONLOGIN_VK_END==========" + }, + { + "signature":"e33991d4902bd9982d0fb80e15345a8, np1dFZKGnztf1sEQVpr5duBBT/v/tJJNKMzzqJG3qi 8DzsvRSG3DTJGfIL5cCTUJKNazPR+4JBDzTAMvfaORU 1 Ajm4Mflc+Cc3dJKfYT89K+cANXb5SWtYkHCyZTrKuFk 9+cwZgXzbPSL/0zNrriAsp5SDZcea70Vh9TcWUPtyhO\n", + "payload":{ + "cohort":"grant" + }, + "surveyorId":"DL4LvvYYQL0UM99cK5Fzhj1hvno9tUXlVRDFTguKGlZ", + "surveyVK":"==========ANONLOGIN_VK_BEG==========\n1zO1RppknZP6XugXsxlLH02rZcBJKg5Z67Kh+UCz/yG 6pVbM4d/GSLm5wh3jgZPML1lI3JTHzXgicITHOeeRd7 1\n39jyd/GNXUUhFyqhXneFQOWYe0bAlIrM4XFmoqh23VD 5CHNBUdI1U+kf9E1iIo2llO0ykIAcXQ3DHe3Wc8wF76 1\n2irIX55Dc3q3W8d0BvD0BCCbqGQEOJOolVKzfoJkTAQ 8lrMS3aipYyZrT/oBelV380bzSsE1Dnb99+678cmyqr 1\nB6IXJBZZDz7pWURlUeAruYF+3nu51/uY4F8XDwz/V8r 6F3u6xAEUAjpg9B+cnSPG0PJhpfnicR0vU3W75OHtew 1\n2FaPYcspv1g2Wzorwn9k/rMO8kw6ug2U4mp6ae9JqO/ 3fizfUe7sZP0ePrLkz60Oi+CJrCgc/M34aLSA014seP 6iZXw0iBlrWJf99VdhmqsLT3SB8PU3khNHVq/2HmgGI 2v/Y9X5nsUp2GCr5msiD1i6pAZuUFZ8LOj0QQUKPP56 1 0\n===========ANONLOGIN_VK_END==========", + "registrarVK":"==========ANONLOGIN_VK_BEG==========\n8MMyJJmqhl/C8PVenwLrAucbcDAAEVPHYa/WMvCFmTu 1sO+XpYPdGS/nqkJoy7Ni6L4vfkX3+6+/8mH+YsoIFb 1\nAPz5/M6QPS0ovaIptqGkTWvwe0wAUpCS1nkn3o578Ow 4QV/FW74yTEzJ2YbYoSwoYJGLeKJ3JWphpHhddmszL2 1\n4Jw9l7H/0I+xLBKl7//SPhWAFhVBbp3XWcewn69WYEx 3bUNzMKNsnpWRKgivBfShbCsfhcR0MGD4CfOFeAYhPE 1\nA5KTrxKgqycFYnvo9BgmYafUJ46Gti/5T+4LmDYOEHL B33Ne5c9wPj1LZF4Nd2O3xeRrF5z2WHtTcnW0dRWJqP 1\n6Aza57xUODgaN5vBgHnr3S7aZQezQl9M6t/IUcLDFxy 6TG8AP2XmsXiDYNfULlMlKmkcIE8wypl41airjsUDOo 7AlIDZY0AA96/pbbBwhaMMaPlsU8zKFrh3nln9R+lta 4O7rb+E7S1RiHB6MZ9f9tX0F6J6TIxX2a5miuRXptf 1 0\n===========ANONLOGIN_VK_END==========" + }, + { + "signature":"e33991d4902bd9982d0fb80e15345a8, wK0n1p7AzXMIe8nl0JnO/1J4zoZeOa2MgKszzzaHNq 2OrGCAwY2uMRrfkKvZeLkPhBXnnSuupS0MdQh5No8AF 1 9lLKQbGk/XBuAK+Ao9JBlS5JOTCY/ijhsNds60zEe9T 8RoGT2L+VUvfwkJN0WcsNtVHI1jTJG39nC4xFU0YvTk\n", + "payload":{ + "cohort":"grant" + }, + "surveyorId":"2xQG08DS+sBXlv7376WC+fkz/yZCr8K1QA4RghQKL9A", + "surveyVK":"==========ANONLOGIN_VK_BEG==========\n1+CkQ4F4RTpmPZDV4mV+PiolH20KROLwgNpqTp3HmV6 7/jGNEji/DuCasyaFGlLD4LHHe3kC3Pl+nQmwBmqzpp 1\n5FjtzmmKhfyid2WUhEe8WhVK3eozWZicTH7EKJwNvfP 9zV4SEpqH37/Ev/aJ9SlOoskRqjut6WzTgO0sI9r4bs 1\n8tV/QjIhcCut3CdjZIwU5ZAiDQiSF4z8jEnnTZZkG9v 9Bbc3klPeqLL1YtbUf5mAG4ibdNGSgXRF42bsvdUdnQ 1\n3sI+k3QmZp1OkBki3ErKQNoPuI4xuPv4bwLQBK2xkgi 1gooebLRhce4Qx1bI55wFzK8hb1lI7wshSYyHKG8hND 1\n6G0Otrpmkk6qfgDl4W4UwfV35Yklm4qXTQDuxrKKUAl BKlkaOYuTZJPC+AfzXm65s7nQNHj1RRJpBW6MJ+RRRc 4lJ0U5tLnc6htwXLRB1+TY4FeEf//Z7NlCJgBxanFHa 3WtnfCi9zc9+I1uPgEHr1Xb12kkYFGmL3fncBEcqzva 1 0\n===========ANONLOGIN_VK_END==========", + "registrarVK":"==========ANONLOGIN_VK_BEG==========\n8MMyJJmqhl/C8PVenwLrAucbcDAAEVPHYa/WMvCFmTu 1sO+XpYPdGS/nqkJoy7Ni6L4vfkX3+6+/8mH+YsoIFb 1\nAPz5/M6QPS0ovaIptqGkTWvwe0wAUpCS1nkn3o578Ow 4QV/FW74yTEzJ2YbYoSwoYJGLeKJ3JWphpHhddmszL2 1\n4Jw9l7H/0I+xLBKl7//SPhWAFhVBbp3XWcewn69WYEx 3bUNzMKNsnpWRKgivBfShbCsfhcR0MGD4CfOFeAYhPE 1\nA5KTrxKgqycFYnvo9BgmYafUJ46Gti/5T+4LmDYOEHL B33Ne5c9wPj1LZF4Nd2O3xeRrF5z2WHtTcnW0dRWJqP 1\n6Aza57xUODgaN5vBgHnr3S7aZQezQl9M6t/IUcLDFxy 6TG8AP2XmsXiDYNfULlMlKmkcIE8wypl41airjsUDOo 7AlIDZY0AA96/pbbBwhaMMaPlsU8zKFrh3nln9R+lta 4O7rb+E7S1RiHB6MZ9f9tX0F6J6TIxX2a5miuRXptf 1 0\n===========ANONLOGIN_VK_END==========" + }, + { + "signature":"e33991d4902bd9982d0fb80e15345a8, 7/RJ0Czhi/xqWHW9SleZpeMqfH1XaB9hAkBFXCEv4+v 8x8fAReJ+lC8bcvYixunBcdPnuKHnvmIQu05BHYV8eu 1 B9ISQ2BL/zrFXcpA3ZubI39Emp4OXMR59RxK0smWtba EN3+Ojq47AFEavHSsQJX5ZDP9FDhXc46HjzvyvkePS2\n", + "payload":{ + "cohort":"grant" + }, + "surveyorId":"6hK+xhExVChfP8y17iX4ZHDLDhQpAtFaexk6k0sPwj8", + "surveyVK":"==========ANONLOGIN_VK_BEG==========\n1zarqtmQbOnM8VaQWuVoXNy7FDgzDonn2yi88BKuYf 4SVoTBWpHO8t+bdgE5PPkEvJA/UV+i4/qeKPOEjkecq 1\n708Z/W3x0/bjS3HGSy72Mjcrda7SBADPZTOuvvNVCPO Aw90YltPtsD1NPItsAtSJyiebjmQ4hVqPbsphcfH6Gk 1\n9FV6ZP54l6onPqVgtjwq9gVsDOvFYQA1TOTPXFTdzXK 5Ekk3w0ssHs4d5mb/HCHgllBMDoQzW5NvZuyOzl3gGj 1\n30DJMVqu/059b57biHn0cvfYWVxmru81QZahAhv1Cbs 17F/L4IW9uY4r7sZPRSSlucFbDLgsA4YZDzbIS7yKJD 1\n1YQ03u23TXviyBwX3V+62AHHd27BrLArdYJF6szH0z2 T62hLNlMyDNIi6ZWIITeeBCZ6G5ya9tfTPjmepj48S Af65DgA+aX9mBk7g/Db0g4DG86i6Xj+kbNN2NFJqSaw 2Se5DacPgmJnky8WGMSgCY/S1LKWLnJL0Am4TSt1C88 1 0\n===========ANONLOGIN_VK_END==========", + "registrarVK":"==========ANONLOGIN_VK_BEG==========\n8MMyJJmqhl/C8PVenwLrAucbcDAAEVPHYa/WMvCFmTu 1sO+XpYPdGS/nqkJoy7Ni6L4vfkX3+6+/8mH+YsoIFb 1\nAPz5/M6QPS0ovaIptqGkTWvwe0wAUpCS1nkn3o578Ow 4QV/FW74yTEzJ2YbYoSwoYJGLeKJ3JWphpHhddmszL2 1\n4Jw9l7H/0I+xLBKl7//SPhWAFhVBbp3XWcewn69WYEx 3bUNzMKNsnpWRKgivBfShbCsfhcR0MGD4CfOFeAYhPE 1\nA5KTrxKgqycFYnvo9BgmYafUJ46Gti/5T+4LmDYOEHL B33Ne5c9wPj1LZF4Nd2O3xeRrF5z2WHtTcnW0dRWJqP 1\n6Aza57xUODgaN5vBgHnr3S7aZQezQl9M6t/IUcLDFxy 6TG8AP2XmsXiDYNfULlMlKmkcIE8wypl41airjsUDOo 7AlIDZY0AA96/pbbBwhaMMaPlsU8zKFrh3nln9R+lta 4O7rb+E7S1RiHB6MZ9f9tX0F6J6TIxX2a5miuRXptf 1 0\n===========ANONLOGIN_VK_END==========" + } +] \ No newline at end of file diff --git a/test/data/rewards-data/surveyor_voting_resp.json b/test/data/rewards-data/surveyor_voting_resp.json new file mode 100644 index 000000000000..4e393f4a2e51 --- /dev/null +++ b/test/data/rewards-data/surveyor_voting_resp.json @@ -0,0 +1,26 @@ +[ + { + "surveyorId":"2xQG08DS+sBXlv7376WC+fkz/yZCr8K1QA4RghQKL9A", + "response":{ + "submissionId":"9AbjitgUneZgh4iAPt/H+hXGoNotLiYAtMi7iSmF2j4 6BnZyrGE2HzQqrT35aJ2NOemY8vqcPhAznKLA6P75X7 1" + } + }, + { + "surveyorId":"Dp8pzNQTa4eYI0IQiHN7+2bpx5rIkbGaNNV5LdffDz8", + "response":{ + "submissionId":"8ujn5fBuye7jOGcSo6u7kObRfsUPDTx8B75dddsTZVD 7jNhWSYOu6q02edoOJ35olbqcskQfref9zFpl8kolFF 1" + } + }, + { + "surveyorId":"6hK+xhExVChfP8y17iX4ZHDLDhQpAtFaexk6k0sPwj8", + "response":{ + "submissionId":"3r6tC/femy/jO8Uh64Je3myVyp8JP+zkCVDL1J68z6Z 5eO//I2fzeSE8MeBvndxQW5X/Nnr4/r4UClxkDf7HBn 1" + } + }, + { + "surveyorId":"DL4LvvYYQL0UM99cK5Fzhj1hvno9tUXlVRDFTguKGlZ", + "response":{ + "submissionId":"1NgQ3Sd8OeeTPMYmEOHe9WROm+aS3eEG77LCwr6PJcx 1KjOZkq8qo9t0THIepkHffKrg/jPNS/bBeaeB3RTuV0 1" + } + } +] \ No newline at end of file diff --git a/vendor/bat-native-ledger/src/bat/ledger/internal/contribution/contribution.cc b/vendor/bat-native-ledger/src/bat/ledger/internal/contribution/contribution.cc index 22ccedef26c0..4cbcc38626f7 100644 --- a/vendor/bat-native-ledger/src/bat/ledger/internal/contribution/contribution.cc +++ b/vendor/bat-native-ledger/src/bat/ledger/internal/contribution/contribution.cc @@ -822,7 +822,8 @@ bool Contribution::ProcessReconcileUnblindedTokens( ledger::ReconcileDirections new_directions; bool full_amount = true; if (balance < *fee) { - contribution->amount = *fee - balance; + *fee = *fee - balance; + contribution->amount = balance; full_amount = false; if (type == ledger::RewardsType::RECURRING_TIP || @@ -832,6 +833,8 @@ bool Contribution::ProcessReconcileUnblindedTokens( &new_directions, leftovers, balance); + } else { + new_directions = directions; } } else { new_directions = directions; @@ -951,6 +954,15 @@ bool Contribution::ProcessExternalWallet( contribution->publishers = std::move(publisher_list); + if (type == ledger::RewardsType::AUTO_CONTRIBUTE) { + auto reconcile = ledger::CurrentReconcileProperties(); + reconcile.viewing_id = contribution_id; + reconcile.fee = fee; + reconcile.directions = directions; + reconcile.type = contribution->type; + ledger_->AddReconcile(reconcile.viewing_id, reconcile); + } + auto save_callback = std::bind(&Contribution::OnProcessExternalWalletSaved, this, _1, diff --git a/vendor/bat-native-ledger/src/bat/ledger/internal/contribution/contribution_unblinded.cc b/vendor/bat-native-ledger/src/bat/ledger/internal/contribution/contribution_unblinded.cc index 26f949bf3a5c..e17da9a6306c 100644 --- a/vendor/bat-native-ledger/src/bat/ledger/internal/contribution/contribution_unblinded.cc +++ b/vendor/bat-native-ledger/src/bat/ledger/internal/contribution/contribution_unblinded.cc @@ -329,7 +329,7 @@ void Unblinded::PreparePublishers( ledger::ContributionPublisherList Unblinded::PrepareAutoContribution( const std::vector& list, ledger::ContributionInfoPtr contribution) { - if (!contribution || list.size() == 0) { + if (!contribution || list.size() == 0 || contribution->publishers.empty()) { return {}; }