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

Add support for BAP reporting endpoint #8054

Merged
merged 1 commit into from
Feb 25, 2021
Merged

Conversation

zenparsing
Copy link
Collaborator

@zenparsing zenparsing commented Feb 23, 2021

Resolves brave/brave-browser#14315

Submitter Checklist:

  • There is a ticket for my issue
  • Used Github auto-closing keywords in the PR description above
  • Wrote a good PR/commit description
  • Added appropriate labels (QA/Yes or QA/No; release-notes/include or release-notes/exclude; OS/...) to the associated issue
  • Checked the PR locally: npm run test -- brave_browser_tests, npm run test -- brave_unit_tests, npm run lint, npm run gn_check, npm run tslint
  • Ran git rebase master (if needed)
  • Requested a security/privacy review as needed

Reviewer Checklist:

  • New files have MPL-2.0 license header
  • Adequate test coverage exists to prevent regressions
  • Major classes, functions and non-trivial code blocks are well-commented
  • Changes in component dependencies are properly reflected in gn
  • Code follows the style guide
  • Test plan is specified in PR before merging

After-merge Checklist:

Test Plan:

Non-JP regions

There are no behavioral changes for profiles with their region not set to JP.

  • Open browser with a clean profile and logging enabled.
  • Open rewards panel and accept UGP grant.
  • After UGP grant completes, restart the browser.
    • Note: restarting the browser will re-trigger the BAP reporting check.
  • Navigate to brave://rewards-internals and view the logs.
    • Verify that there are no requests in the log for /v1/promotions/report-bap.

JP regions

For JP-region profiles, a network request is made to report the user's current virtual token amount. The request is only made if the balance is greater than zero and it is only made once.

  • Update the system region to JP.
  • Open browser with a clean profile and logging enabled.
  • Open the rewards panel to start the rewards process.
  • Navigate to brave://rewards-internals and view the logs.
    • Verify that an entry exists for bap_reporter.cc indicating that the user has zero tokens and a retry has been scheduled.
  • Claim staging UGP grant in some manner (panel, brave://rewards, NTP, etc). Confirm balance updates as expected.
  • Restart the browser.
    • Note: restarting the browser will re-trigger the BAP reporting check.
  • Navigate to brave://rewards-internals and view the logs.
    • Verify that a request was successfully made to /v1/promotions/report-bap.
    • Note: you may need to refresh the log. However, the response should appear quickly.
  • Restart the browser.
  • Navigate to brave://rewards-internals and view the logs.
    • Verify that no additional requests have been made to /v1/promotions/report-bap.

Copy link
Collaborator

@kylehickinson kylehickinson left a comment

Choose a reason for hiding this comment

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

iOS++

Copy link
Contributor

@emerick emerick left a comment

Choose a reason for hiding this comment

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

LGTM, just had a minor nit.

@zenparsing
Copy link
Collaborator Author

CI post-init failed on unrelated audit-deps error.

@zenparsing zenparsing merged commit d681ada into master Feb 25, 2021
@zenparsing zenparsing deleted the ksmith-bap-reporting branch February 25, 2021 03:37
@bsclifton bsclifton added this to the 1.23.x - Nightly milestone Feb 25, 2021
zenparsing added a commit that referenced this pull request Feb 25, 2021
zenparsing added a commit that referenced this pull request Feb 25, 2021
@LaurenWags
Copy link
Member

LaurenWags commented Mar 5, 2021

Verified using

Brave	1.23.20 Chromium: 89.0.4389.72 (Official Build) nightly (x86_64)
Revision	3f345f156bfd157bd1bea06310e55f3fb2490359-refs/branch-heads/4389@{#1393}
OS	macOS Version 10.15.7 (Build 19H512)
Test Case 1 - non JP Region

Pre-req, be set up for non JP region. I am using US.

  1. Clean profile (--args --enable-logging=stderr --vmodule="*/bat-native-ledger/*"=6,"*/brave_rewards/*"=6,"*/bat-native-ads/*"=6,"*/bat-native-confirmations/*"=6,"*/brave_ads/*"=6,"*/brave_user_model/*"=6 --brave-ads-staging --rewards=staging=true,persist-logs=true)
  2. Enable Rewards, claim UGP grant, wait for balance to update
  3. Close browser
  4. Relaunch with same flags
  5. Go to brave://rewards-internals (can also check in terminal)
  6. Confirm no requests to /v1/promotions/report-bap
Test Case 2 - Happy Path, JP Region

Pre-req for this case and all others unless otherwise noted is to have region = Japan

  1. Clean profile (--args --enable-logging=stderr --vmodule="*/bat-native-ledger/*"=6,"*/brave_rewards/*"=6,"*/bat-native-ads/*"=6,"*/bat-native-confirmations/*"=6,"*/brave_ads/*"=6,"*/brave_user_model/*"=6 --brave-ads-staging --rewards=staging=true,persist-logs=true)
  2. Enable Rewards
  3. Go to brave://rewards-internals, confirm BAP retry is scheduled due to zero balance (can also check in terminal)
[Mar 05, 2021, 12:31:50.8 PM:INFO:bap_reporter.cc(95)] User has zero balance - rescheduling BAP reporting in 86400 s
  1. Claim UGP grant, wait for balance to update
  2. Close the browser
  3. Restart with same flags
  4. Look at logs in terminal or on brave://rewards-internals, confirm BAP is successfully sent to the server (calls to /v1/promotions/report-bap)
[ REQUEST ]
> URL: https://grant.rewards.bravesoftware.com/v1/promotions/report-bap
> Method: UrlMethod::POST
> Content: {"amount":30.0}
> Content Type: application/json; charset=utf-8
> Header digest: SHA-256=Z/frhwyMcI3GeHys2lrUHmtSKj/pkTWttptg5TAw+6o=
> Header signature: keyId="93a59ff6-c549-4468-aac1-dc5ba26355dd",algorithm="ed25519",headers="digest (request-target)",signature="4UB5OWZrrlT4bDsvbdRA0hAurC7sD78CZ0LInjnqjkiQEoXtR6V3PCdwmA7sAFMpUKD9JkMKguKFBK8OHbd1Cw=="
> Header accept: application/json

[ RESPONSE - OnFetchCompleted ]
> Url: https://grant.rewards.bravesoftware.com/v1/promotions/report-bap
> Result: Success
> HTTP Code: 200
> Body: {"reportBapId":"a3a10993-a0d1-4722-89cd-e138badec085"}

[1412:775:0305/123300.339256:VERBOSE1:bap_reporter.cc(82)] BAP successsfully reported
  1. Restart the browser
  2. Review brave://rewards-internals (or terminal)
  3. Confirm no additional requests made to /v1/promotions/report-bap
  4. Contact Ben Huson w/ paymentId and amount of BAP to confirm server received expected amount
select * from bap_report where wallet_id='93a59ff6-c549-4468-aac1-dc5ba26355dd';
                  id                  |              wallet_id               |        amount         |          created_at           
--------------------------------------+--------------------------------------+-----------------------+-------------------------------
 a3a10993-a0d1-4722-89cd-e138badec085 | 93a59ff6-c549-4468-aac1-dc5ba26355dd | 30.000000000000000000 | 2021-03-05 17:33:00.290108+00
Test Case 3 - Tip before BAP is reported
  1. Clean profile (--args --enable-logging=stderr --vmodule="*/bat-native-ledger/*"=6,"*/brave_rewards/*"=6,"*/bat-native-ads/*"=6,"*/bat-native-confirmations/*"=6,"*/brave_ads/*"=6,"*/brave_user_model/*"=6 --brave-ads-staging --rewards=staging=true,persist-logs=true)
  2. Enable Rewards
  3. Go to brave://rewards-internals, confirm BAP retry is scheduled (can also check in terminal)
  4. Claim UGP grant
  5. Make a tip in any amount to a verified publisher
  6. Close the browser
  7. Restart with same flags
  8. Look at logs in terminal or on brave://rewards-internals, confirm BAP is successfully sent to the server
[ REQUEST ]
> URL: https://grant.rewards.bravesoftware.com/v1/promotions/report-bap
> Method: UrlMethod::POST
> Content: {"amount":20.0}
> Content Type: application/json; charset=utf-8
> Header digest: SHA-256=stGhxGmERHswrKsP9rKzkEy/Z/zI7/84Eel6Upxiek8=
> Header signature: keyId="d6d53b3f-995f-47af-b9c4-9f5b87885551",algorithm="ed25519",headers="digest (request-target)",signature="q4sKF5Bxj6J/eUI6hsA6fwbuI3dyis/WTGtYmlEcB7RkDJJsJOfqravFaMbZmw+LcKGgXyCsQZ9ueL3V2OoqDA=="
> Header accept: application/json

[ RESPONSE - OnFetchCompleted ]
> Url: https://grant.rewards.bravesoftware.com/v1/promotions/report-bap
> Result: Success
> HTTP Code: 200
> Body: {"reportBapId":"ece9317b-f046-4d69-88ca-8b8654e49852"}

[2421:775:0305/141958.409877:VERBOSE1:bap_reporter.cc(82)] BAP successsfully reported
  1. Contact Ben Huson w/ paymentId and amount of BAP to confirm server received expected amount
                 id                  |              wallet_id               |        amount         |          created_at           
--------------------------------------+--------------------------------------+-----------------------+-------------------------------
 ece9317b-f046-4d69-88ca-8b8654e49852 | d6d53b3f-995f-47af-b9c4-9f5b87885551 | 20.000000000000000000 | 2021-03-05 19:19:58.363048+00
Test Case 4 - Server returns 400, reporting goes into retries
  1. Clean profile (--args --enable-logging=stderr --vmodule="*/bat-native-ledger/*"=6,"*/brave_rewards/*"=6,"*/bat-native-ads/*"=6,"*/bat-native-confirmations/*"=6,"*/brave_ads/*"=6,"*/brave_user_model/*"=6 --brave-ads-staging --rewards=staging=true,persist-logs=true)
  2. Enable Rewards
  3. Go to brave://rewards-internals, confirm BAP retry is scheduled (can also check in terminal)
  4. Claim UGP grant
  5. Close browser
  6. Set up Charles Proxy rule for the server to return 400 for 200 or 409
  7. Restart with same flags
  8. Watch logs for scheduled retries
[ REQUEST ]
> URL: https://grant.rewards.bravesoftware.com/v1/promotions/report-bap
> Method: UrlMethod::POST
> Content: {"amount":30.0}
> Content Type: application/json; charset=utf-8
> Header digest: SHA-256=Z/frhwyMcI3GeHys2lrUHmtSKj/pkTWttptg5TAw+6o=
> Header signature: keyId="f0d10740-cfe1-4f6c-b6dc-282eb3be5ca2",algorithm="ed25519",headers="digest (request-target)",signature="kqak8ZQofnjW5pi61Q/l4ZK4cx9OqlPJeAbv2qBWQwbBEI2UAf+PnRuD6hSykqM2RcX4iCRYMR3kkxygF9fpCg=="
> Header accept: application/json

[ RESPONSE - OnFetchCompleted ]
> Url: https://grant.rewards.bravesoftware.com/v1/promotions/report-bap
> Result: Failure
> HTTP Code: 400
> Body: {"reportBapId":"360f5c86-8228-4e5e-875c-f72cc86f4020"}

[158:775:0305/100257.222750:INFO:bap_reporter_endpoint.cc(70)] Invalid request
[158:775:0305/100257.222796:VERBOSE1:bap_reporter.cc(108)] BAP reporting failed - rescheduling in 717 s
[ REQUEST ]
> URL: https://grant.rewards.bravesoftware.com/v1/promotions/report-bap
> Method: UrlMethod::POST
> Content: {"amount":30.0}
> Content Type: application/json; charset=utf-8
> Header digest: SHA-256=Z/frhwyMcI3GeHys2lrUHmtSKj/pkTWttptg5TAw+6o=
> Header signature: keyId="f0d10740-cfe1-4f6c-b6dc-282eb3be5ca2",algorithm="ed25519",headers="digest (request-target)",signature="kqak8ZQofnjW5pi61Q/l4ZK4cx9OqlPJeAbv2qBWQwbBEI2UAf+PnRuD6hSykqM2RcX4iCRYMR3kkxygF9fpCg=="
> Header accept: application/json
[158:775:0305/101454.679877:VERBOSE6:logging_util.cc(136)] 
[ RESPONSE - OnFetchCompleted ]
> Url: https://grant.rewards.bravesoftware.com/v1/promotions/report-bap
> Result: Failure
> HTTP Code: 400
> Body: {"message":"Error inserting bap report, paymentId already reported: unable to record BAP report","code":409}

[158:775:0305/101454.679972:INFO:bap_reporter_endpoint.cc(70)] Invalid request
[158:775:0305/101454.680028:VERBOSE1:bap_reporter.cc(108)] BAP reporting failed - rescheduling in 683 s
[ REQUEST ]
> URL: https://grant.rewards.bravesoftware.com/v1/promotions/report-bap
> Method: UrlMethod::POST
> Content: {"amount":30.0}
> Content Type: application/json; charset=utf-8
> Header digest: SHA-256=Z/frhwyMcI3GeHys2lrUHmtSKj/pkTWttptg5TAw+6o=
> Header signature: keyId="f0d10740-cfe1-4f6c-b6dc-282eb3be5ca2",algorithm="ed25519",headers="digest (request-target)",signature="kqak8ZQofnjW5pi61Q/l4ZK4cx9OqlPJeAbv2qBWQwbBEI2UAf+PnRuD6hSykqM2RcX4iCRYMR3kkxygF9fpCg=="
> Header accept: application/json
[158:775:0305/102618.140851:VERBOSE6:logging_util.cc(136)] 
[ RESPONSE - OnFetchCompleted ]
> Url: https://grant.rewards.bravesoftware.com/v1/promotions/report-bap
> Result: Failure
> HTTP Code: 400
> Body: {"message":"Error inserting bap report, paymentId already reported: unable to record BAP report","code":409}

[158:775:0305/102618.140934:INFO:bap_reporter_endpoint.cc(70)] Invalid request
[158:775:0305/102618.140971:VERBOSE1:bap_reporter.cc(108)] BAP reporting failed - rescheduling in 4832 s

Note - geometric timer w/ randomness is used so I am unable to confirm that it backs off exactly as listed in https://bravesoftware.slack.com/archives/CB0KCRCQN/p1614191899060000?thread_ts=1614111570.049100&cid=CB0KCRCQN, but I did confirm with @zenparsing that it looked correct

Test Case 5 - Server returns 500, reporting goes into retries
  1. Clean profile (--args --enable-logging=stderr --vmodule="*/bat-native-ledger/*"=6,"*/brave_rewards/*"=6,"*/bat-native-ads/*"=6,"*/bat-native-confirmations/*"=6,"*/brave_ads/*"=6,"*/brave_user_model/*"=6 --brave-ads-staging --rewards=staging=true,persist-logs=true)
  2. Enable Rewards
  3. Go to brave://rewards-internals, confirm BAP retry is scheduled (can also check in terminal)
  4. Claim UGP grant
  5. Close browser
  6. Set up Charles Proxy rule for the server to return 500 for 200 or 409
  7. Restart with same flags
  8. Watch logs for scheduled retries
[ REQUEST ]
> URL: https://grant.rewards.bravesoftware.com/v1/promotions/report-bap
> Method: UrlMethod::POST
> Content: {"amount":30.0}
> Content Type: application/json; charset=utf-8
> Header digest: SHA-256=Z/frhwyMcI3GeHys2lrUHmtSKj/pkTWttptg5TAw+6o=
> Header signature: keyId="c913fead-5143-4b69-baa1-2a9b1556ad7b",algorithm="ed25519",headers="digest (request-target)",signature="mW53v+aMK2Tu/nO5rwO0fvgRCIp+wfWmiwOedPCBPnmRDAC54QO59NtLgFtpTClmsu/YjKqRHCfkYtJ/gmYPDQ=="
> Header accept: application/json

[ RESPONSE - OnFetchCompleted ]
> Url: https://grant.rewards.bravesoftware.com/v1/promotions/report-bap
> Result: Failure
> HTTP Code: 500
> Body: {"reportBapId":"93e6fdd9-5db5-4f2a-b08d-d45c2d69a84e"}

[3227:775:0305/152933.774130:INFO:bap_reporter_endpoint.cc(74)] Internal server error
[3227:775:0305/152933.774176:VERBOSE1:bap_reporter.cc(108)] BAP reporting failed - rescheduling in 211 s
[ REQUEST ]
> URL: https://grant.rewards.bravesoftware.com/v1/promotions/report-bap
> Method: UrlMethod::POST
> Content: {"amount":30.0}
> Content Type: application/json; charset=utf-8
> Header digest: SHA-256=Z/frhwyMcI3GeHys2lrUHmtSKj/pkTWttptg5TAw+6o=
> Header signature: keyId="c913fead-5143-4b69-baa1-2a9b1556ad7b",algorithm="ed25519",headers="digest (request-target)",signature="mW53v+aMK2Tu/nO5rwO0fvgRCIp+wfWmiwOedPCBPnmRDAC54QO59NtLgFtpTClmsu/YjKqRHCfkYtJ/gmYPDQ=="
> Header accept: application/json

[ RESPONSE - OnFetchCompleted ]
> Url: https://grant.rewards.bravesoftware.com/v1/promotions/report-bap
> Result: Failure
> HTTP Code: 500
> Body: {"message":"Error inserting bap report, paymentId already reported: unable to record BAP report","code":409}

[3227:775:0305/153305.134254:INFO:bap_reporter_endpoint.cc(74)] Internal server error
[3227:775:0305/153305.134296:VERBOSE1:bap_reporter.cc(108)] BAP reporting failed - rescheduling in 214 s
[ REQUEST ]
> URL: https://grant.rewards.bravesoftware.com/v1/promotions/report-bap
> Method: UrlMethod::POST
> Content: {"amount":30.0}
> Content Type: application/json; charset=utf-8
> Header digest: SHA-256=Z/frhwyMcI3GeHys2lrUHmtSKj/pkTWttptg5TAw+6o=
> Header signature: keyId="c913fead-5143-4b69-baa1-2a9b1556ad7b",algorithm="ed25519",headers="digest (request-target)",signature="mW53v+aMK2Tu/nO5rwO0fvgRCIp+wfWmiwOedPCBPnmRDAC54QO59NtLgFtpTClmsu/YjKqRHCfkYtJ/gmYPDQ=="
> Header accept: application/json
 
[ RESPONSE - OnFetchCompleted ]
> Url: https://grant.rewards.bravesoftware.com/v1/promotions/report-bap
> Result: Failure
> HTTP Code: 500
> Body: {"message":"Error inserting bap report, paymentId already reported: unable to record BAP report","code":409}

[3227:775:0305/153639.793109:INFO:bap_reporter_endpoint.cc(74)] Internal server error
[3227:775:0305/153639.793152:VERBOSE1:bap_reporter.cc(108)] BAP reporting failed - rescheduling in 411 s

See note about geometric timer/randomness used under TC 4.

Test Case 6 - wifi is off, reporting goes into retries
  1. Clean profile (--args --enable-logging=stderr --vmodule="*/bat-native-ledger/*"=6,"*/brave_rewards/*"=6,"*/bat-native-ads/*"=6,"*/bat-native-confirmations/*"=6,"*/brave_ads/*"=6,"*/brave_user_model/*"=6 --brave-ads-staging --rewards=staging=true,persist-logs=true)
  2. Enable Rewards
  3. Go to brave://rewards-internals, confirm BAP retry is scheduled (can also check in terminal)
  4. Claim UGP grant, wait for balance to update
  5. Close browser
  6. Disable wifi
  7. Restart with same flags
  8. Watch logs for scheduled retries
[ REQUEST ]
> URL: https://grant.rewards.bravesoftware.com/v1/promotions/report-bap
> Method: UrlMethod::POST
> Content: {"amount":30.0}
> Content Type: application/json; charset=utf-8
> Header digest: SHA-256=Z/frhwyMcI3GeHys2lrUHmtSKj/pkTWttptg5TAw+6o=
> Header signature: keyId="27200f46-b87a-406a-aa22-4e46e38fba51",algorithm="ed25519",headers="digest (request-target)",signature="05EGGLjNLTd1vDQfwWLAi4Q9hS2IWyd8WVnpyLuyXGX0cY24yFxQrmZZJGj/IFKTSbZGe75hEGCCnz4P02U0CQ=="
> Header accept: application/json

[ RESPONSE - OnFetchCompleted ]
> Url: https://grant.rewards.bravesoftware.com/v1/promotions/report-bap
> Result: Error (net::ERR_INTERNET_DISCONNECTED)
> HTTP Code: -1
> Body: 
[3622:775:0305/155859.951312:INFO:bap_reporter_endpoint.cc(83)] Unexpected reponse code -1
[3622:775:0305/155859.951363:VERBOSE1:bap_reporter.cc(108)] BAP reporting failed - rescheduling in 130 s
[ REQUEST ]
> URL: https://grant.rewards.bravesoftware.com/v1/promotions/report-bap
> Method: UrlMethod::POST
> Content: {"amount":30.0}
> Content Type: application/json; charset=utf-8
> Header digest: SHA-256=Z/frhwyMcI3GeHys2lrUHmtSKj/pkTWttptg5TAw+6o=
> Header signature: keyId="27200f46-b87a-406a-aa22-4e46e38fba51",algorithm="ed25519",headers="digest (request-target)",signature="05EGGLjNLTd1vDQfwWLAi4Q9hS2IWyd8WVnpyLuyXGX0cY24yFxQrmZZJGj/IFKTSbZGe75hEGCCnz4P02U0CQ=="
> Header accept: application/json

[ RESPONSE - OnFetchCompleted ]
> Url: https://grant.rewards.bravesoftware.com/v1/promotions/report-bap
> Result: Error (net::ERR_INTERNET_DISCONNECTED)
> HTTP Code: -1
> Body: 
[3622:775:0305/160109.961773:INFO:bap_reporter_endpoint.cc(83)] Unexpected reponse code -1
[3622:775:0305/160109.961812:VERBOSE1:bap_reporter.cc(108)] BAP reporting failed - rescheduling in 80 s
[ REQUEST ]
> URL: https://grant.rewards.bravesoftware.com/v1/promotions/report-bap
> Method: UrlMethod::POST
> Content: {"amount":30.0}
> Content Type: application/json; charset=utf-8
> Header digest: SHA-256=Z/frhwyMcI3GeHys2lrUHmtSKj/pkTWttptg5TAw+6o=
> Header signature: keyId="27200f46-b87a-406a-aa22-4e46e38fba51",algorithm="ed25519",headers="digest (request-target)",signature="05EGGLjNLTd1vDQfwWLAi4Q9hS2IWyd8WVnpyLuyXGX0cY24yFxQrmZZJGj/IFKTSbZGe75hEGCCnz4P02U0CQ=="
> Header accept: application/json

[ RESPONSE - OnFetchCompleted ]
> Url: https://grant.rewards.bravesoftware.com/v1/promotions/report-bap
> Result: Error (net::ERR_INTERNET_DISCONNECTED)
> HTTP Code: -1
> Body: 
[3622:775:0305/160229.971329:INFO:bap_reporter_endpoint.cc(83)] Unexpected reponse code -1
[3622:775:0305/160229.971373:VERBOSE1:bap_reporter.cc(108)] BAP reporting failed - rescheduling in 1843 s

See note about geometric timer/randomness used under TC 4.

Test Case 7 - Promotions disabled after BAP successfully reported
  1. Clean profile (--args --enable-logging=stderr --vmodule="*/bat-native-ledger/*"=6,"*/brave_rewards/*"=6,"*/bat-native-ads/*"=6,"*/bat-native-confirmations/*"=6,"*/brave_ads/*"=6,"*/brave_user_model/*"=6 --brave-ads-staging --rewards=staging=true,persist-logs=true)
  2. Enable Rewards
  3. Go to brave://rewards-internals, confirm BAP retry is scheduled (can also check in terminal)
  4. Claim UGP grant
  5. Close the browser
  6. Restart with same flags
  7. Look at logs in terminal or on brave://rewards-internals, confirm BAP is successfully sent to the server
  8. Request Ad grant to be sent to your paymentId (Chris, Kamil can do this)
  9. Once they confirm you have a grant sent to you, close/restart the browser
  10. Look in the logs for Fetch promotions disabled after BAP reporting:
[17822:775:0306/110925.647391:VERBOSE1:promotion.cc(122)] Fetch promotions disabled after BAP reporting
  1. Confirmed no ad grant listed on brave://rewards, panel, or brave://rewards-internals Promotions tab.
Test Case 8 - Server returns 409, reporting does not retry
  1. Clean profile (--args --enable-logging=stderr --vmodule="*/bat-native-ledger/*"=6,"*/brave_rewards/*"=6,"*/bat-native-ads/*"=6,"*/bat-native-confirmations/*"=6,"*/brave_ads/*"=6,"*/brave_user_model/*"=6 --brave-ads-staging --rewards=staging=true,persist-logs=true)
  2. Enable Rewards
  3. Go to brave://rewards-internals, confirm BAP retry is scheduled (can also check in terminal)
  4. Claim UGP grant
  5. Close the browser
  6. Restart the browser w/ same flags
  7. Look at logs in terminal or on brave://rewards-internals, confirm BAP is successfully sent to the server
  8. Close browser
  9. Update brave.rewards.bap_reported in Preferences file to be "false" to indicate that BAP was not sent
  10. Restart the browser w/ same flags
  11. Watch logs for 409 response
[ REQUEST ]
> URL: https://grant.rewards.bravesoftware.com/v1/promotions/report-bap
> Method: UrlMethod::POST
> Content: {"amount":30.0}
> Content Type: application/json; charset=utf-8
> Header digest: SHA-256=Z/frhwyMcI3GeHys2lrUHmtSKj/pkTWttptg5TAw+6o=
> Header signature: keyId="85e65a56-80f0-4b05-ba02-34eccf13b934",algorithm="ed25519",headers="digest (request-target)",signature="xdCCaoytAb0czdhVKGSQSbuTN+JvQn1ayLo9WLvmEehBy4W60QkScXCv4fL0Jxvk/jrH2k988h41by9gYj0WDQ=="
> Header accept: application/json
[ RESPONSE - OnFetchCompleted ]
> Url: https://grant.rewards.bravesoftware.com/v1/promotions/report-bap
> Result: Failure
> HTTP Code: 409
> Body: {"message":"Error inserting bap report, paymentId already reported: unable to record BAP report","code":409}
[99655:775:0305/094031.423218:VERBOSE1:bap_reporter.cc(82)] BAP successsfully reported
  1. Close and relaunch w/ same flags
  2. Confirm BAP is not retried
Test Case 9 - Upgrade w/ single grant claimed
  1. Using 1.21.x, clean profile (--args --enable-logging=stderr --vmodule="*/bat-native-ledger/*"=6,"*/brave_rewards/*"=6,"*/bat-native-ads/*"=6,"*/bat-native-confirmations/*"=6,"*/brave_ads/*"=6,"*/brave_user_model/*"=6 --brave-ads-staging --rewards=staging=true,persist-logs=true)
  2. Enable Rewards
  3. Go to brave://rewards-internals, confirm no mention of BAP
  4. Claim UGP grant, wait for balance to update
  5. Close the browser
  6. Rename profile to Nightly (simulating upgrade to 1.23.x)
  7. Restart with same flags
  8. Look at logs in terminal or on brave://rewards-internals, confirm BAP is successfully sent to the server (calls to /v1/promotions/report-bap)
[ REQUEST ]
> URL: https://grant.rewards.bravesoftware.com/v1/promotions/report-bap
> Method: UrlMethod::POST
> Content: {"amount":30.0}
> Content Type: application/json; charset=utf-8
> Header digest: SHA-256=Z/frhwyMcI3GeHys2lrUHmtSKj/pkTWttptg5TAw+6o=
> Header signature: keyId="45c084bc-0c29-4df2-a7a1-2e073551fa68",algorithm="ed25519",headers="digest (request-target)",signature="R+HOyQrA2Sj2+VlQFJIukG7okxsIOXPMrONNKGiy/k9LrKkAWswGd1FVwELDQOMPmcd/F8hWiGw6z7nfkjWLAg=="
> Header accept: application/json

[ RESPONSE - OnFetchCompleted ]
> Url: https://grant.rewards.bravesoftware.com/v1/promotions/report-bap
> Result: Success
> HTTP Code: 200
> Body: {"reportBapId":"ccfc4421-22f5-4ae9-86ce-4c1ab1827f7a"}

[2806:775:0305/145816.227303:VERBOSE1:bap_reporter.cc(82)] BAP successsfully reported
Test Case 10 - Upgrade with more than one grant claimed
  1. Using 1.21.x, clean profile (--args --enable-logging=stderr --vmodule="*/bat-native-ledger/*"=6,"*/brave_rewards/*"=6,"*/bat-native-ads/*"=6,"*/bat-native-confirmations/*"=6,"*/brave_ads/*"=6,"*/brave_user_model/*"=6 --brave-ads-staging --rewards=staging=true,persist-logs=true)
  2. Enable Rewards
  3. Restore wallet with Ad and UGP grant waiting
  4. Go to brave://rewards-internals, confirm no mention of BAP
  5. Claim both Ad and UGP grants, wait for balance to update
  6. Close the browser
  7. Rename profile to Nightly (simulating upgrade to 1.23.x)
  8. Restart with same flags
  9. Look at logs in terminal or on brave://rewards-internals, confirm BAP is successfully sent to the server (calls to /v1/promotions/report-bap)
[ REQUEST ]
> URL: https://grant.rewards.bravesoftware.com/v1/promotions/report-bap
> Method: UrlMethod::POST
> Content: {"amount":53.0}
> Content Type: application/json; charset=utf-8
> Header digest: SHA-256=6rUw4FQ6xvCC3lJt7stUMS1gBdp+Y/Yb5GFu1vGG2vM=
> Header signature: keyId="7983ef51-b422-4c32-833c-f8a35403381d",algorithm="ed25519",headers="digest (request-target)",signature="1Q079Iswx7r47MUatbnD4jHBUJ2G5YYX1MJ7OTD4dpXl5qy51wQSmve83b7xx2J3n/a/Qc0GzTBvqXbOcghnAg=="
> Header accept: application/json
[ RESPONSE - OnFetchCompleted ]
> Url: https://grant.rewards.bravesoftware.com/v1/promotions/report-bap
> Result: Success
> HTTP Code: 200
> Body: {"reportBapId":"19e80a1b-fecc-4561-a473-f3e9c314203f"}

[3446:775:0305/154720.853483:VERBOSE1:bap_reporter.cc(82)] BAP successsfully reported
  1. Contact Ben Huson w/ paymentId and amount of BAP to confirm server received expected amount
                  id                  |              wallet_id               |        amount         |          created_at           
--------------------------------------+--------------------------------------+-----------------------+-------------------------------
 19e80a1b-fecc-4561-a473-f3e9c314203f | 7983ef51-b422-4c32-833c-f8a35403381d | 53.000000000000000000 | 2021-03-05 20:47:20.812715+00
Test Case 11 - Upgrade w/ 0 BAP balance
  1. Using 1.21.x, clean profile (--args --enable-logging=stderr --vmodule="*/bat-native-ledger/*"=6,"*/brave_rewards/*"=6,"*/bat-native-ads/*"=6,"*/bat-native-confirmations/*"=6,"*/brave_ads/*"=6,"*/brave_user_model/*"=6 --brave-ads-staging --rewards=staging=true,persist-logs=true)
  2. Enable Rewards, do not claim grant
  3. Go to brave://rewards-internals, confirm no mention of BAP
  4. Close the browser
  5. Rename profile to Nightly (simulating upgrade to 1.23.x)
  6. Restart with same flags
  7. Go to brave://rewards-internals, confirm BAP retry is scheduled due to zero balance (can also check in terminal)
[2975:775:0305/150959.335005:VERBOSE1:bap_reporter.cc(95)] User has zero balance - rescheduling BAP reporting in 86400 s
Brave	1.23.23 Chromium: 89.0.4389.72 (Official Build) nightly (x86_64)
Revision	3f345f156bfd157bd1bea06310e55f3fb2490359-refs/branch-heads/4389@{#1393}
OS	macOS Version 10.15.7 (Build 19H512)
Test Case 12 - recheck https://github.com//pull/7698

Verified items from #7698 (comment)

Scenario 1 - Non JP Region

Confirmed able to claim promotion
Confirmed no BAP popup on NTP
Confirmed no BAP alert on NTP when date is after 2021-03-06
Confirmed wallet balance is not showing 0 BAP on 2021-03-13

Claim Promotion NTP - no BAP popup NTP - no BAP alert Wallet balance is retained
1 2 3 4

Scenario 2 - JP Region

Confirmed when BAP balance is 0, there is no popup/alert on NTP
Confirmed after claiming grant, balance is non-zero BAP
Confirmed when opening NTP, the BAP alert is displayed (note, no popup since alert starts showing March 6, and it is now after March 6)
Confirmed when date is 2021-03-13, balance shows 0.0 BAP

0 BAP balance non-zero BAP balance BAP alert is displayed on NTP Balance shows O BAP on 2021-03-13
1 2 3 4

Confirmed BAP alert remains on NTP until it is acknowledged (clicking on OK or "x").
Confirmed clicking OK or x closes BAP alert.

Scenario 3 - Promotion fetching

JP Region - Confirmed on a clean profile, promotions not fetched when date is 2021-03-13

[62094:775:0313/092636.058442:VERBOSE1:promotion.cc(116)] Fetch promotions disabled for BAP migration
2021-03-13

US Region - Confirmed on a clean profile, promotions are fetched when date is 2021-03-13

[ REQUEST ]
> URL: https://grant.rewards.bravesoftware.com/v1/promotions?migrate=true&platform=osx
> Method: UrlMethod::GET

[ RESPONSE - OnRequest ]
> Url: https://grant.rewards.bravesoftware.com/v1/promotions?migrate=true&platform=osx
> Result: Success
> HTTP Code: 200
> Body: {"promotions":[{"id":"2afc219e-4e94-4d15-8758-b457b30fb50c","createdAt":"2020-12-09T18:59:26.30816Z","expiresAt":"2021-04-09T18:59:26.30816Z","version":5,"suggestionsPerGrant":120,"approximateValue":"30","type":"ugp","available":true,"platform":"desktop","publicKeys":["FkAp9KoURjqvziKPs8xXwSnBI89e+rAY9Lik8aETcBU="],"legacyClaimed":false}]}
Screen Shot 2021-03-13 at 3 33 28 PM

bsclifton pushed a commit that referenced this pull request Mar 10, 2021
bsclifton pushed a commit that referenced this pull request Mar 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Integrate with BAP reporting endpoint
5 participants