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

Intermittent crash if Confirmations library is called before being instantiated #4370

Merged
merged 2 commits into from
Jan 15, 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
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ namespace confirmations {
using TransactionInfo = ::ledger::TransactionInfo;
using TransactionsInfo = ::ledger::TransactionsInfo;

using OnGetTransactionHistory = ::ledger::GetTransactionHistoryCallback;
using OnGetTransactionHistoryCallback = ::ledger::GetTransactionHistoryCallback;
using OnInitializeCallback = std::function<void(bool)>;

// |_environment| indicates that URL requests should use production, staging or
// development servers but can be overridden via command-line arguments
Expand All @@ -46,8 +47,11 @@ class CONFIRMATIONS_EXPORT Confirmations {
static Confirmations* CreateInstance(
ConfirmationsClient* confirmations_client);

// Should be called from Ledger to initialize Confirmations
virtual void Initialize() = 0;
// Should be called from Ledger to initialize Confirmations. The callback
// takes one argument - |true| if Confirmations was successfully initialized;
// otherwise |false|
virtual void Initialize(
OnInitializeCallback callback) = 0;

// Should be called when the wallet |payment_id| and |private_key| are set in
// the Ledger library, e.g. initializing a wallet, creating a new wallet or
Expand All @@ -63,7 +67,7 @@ class CONFIRMATIONS_EXPORT Confirmations {
// argument — |TransactionsInfo| which contains a list of |TransactionInfo|
// transactions and associated earned ads rewards
virtual void GetTransactionHistory(
OnGetTransactionHistory callback) = 0;
OnGetTransactionHistoryCallback callback) = 0;

// Should be called to confirm an ad was viewed, clicked, dismissed or landed
virtual void ConfirmAd(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ struct CONFIRMATIONS_EXPORT WalletInfo {
WalletInfo(const WalletInfo& info);
~WalletInfo();

bool IsValid();
bool IsValid() const;

bool operator==(const WalletInfo& info) const;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

// npm run test -- brave_unit_tests --filter=Confirmations*

using std::placeholders::_1;

namespace confirmations {

class ConfirmationsCreateConfirmationRequestTest : public ::testing::Test {
Expand Down Expand Up @@ -44,7 +46,13 @@ class ConfirmationsCreateConfirmationRequestTest : public ::testing::Test {
void SetUp() override {
// Code here will be called immediately after the constructor (right before
// each test)
confirmations_->Initialize();
auto callback = std::bind(
&ConfirmationsCreateConfirmationRequestTest::OnInitialize, this, _1);
confirmations_->Initialize(callback);
}

void OnInitialize(const bool success) {
EXPECT_EQ(true, success);
}

void TearDown() override {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

// npm run test -- brave_unit_tests --filter=Confirmations*

using std::placeholders::_1;

namespace confirmations {

class ConfirmationsFetchPaymentTokenRequestTest : public ::testing::Test {
Expand Down Expand Up @@ -41,7 +43,13 @@ class ConfirmationsFetchPaymentTokenRequestTest : public ::testing::Test {
void SetUp() override {
// Code here will be called immediately after the constructor (right before
// each test)
confirmations_->Initialize();
auto callback = std::bind(
&ConfirmationsFetchPaymentTokenRequestTest::OnInitialize, this, _1);
confirmations_->Initialize(callback);
}

void OnInitialize(const bool success) {
EXPECT_EQ(true, success);
}

void TearDown() override {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

// npm run test -- brave_unit_tests --filter=Confirmations*

using std::placeholders::_1;

namespace confirmations {

class ConfirmationsGetSignedTokensRequestTest : public ::testing::Test {
Expand Down Expand Up @@ -43,7 +45,13 @@ class ConfirmationsGetSignedTokensRequestTest : public ::testing::Test {
void SetUp() override {
// Code here will be called immediately after the constructor (right before
// each test)
confirmations_->Initialize();
auto callback = std::bind(
&ConfirmationsGetSignedTokensRequestTest::OnInitialize, this, _1);
confirmations_->Initialize(callback);
}

void OnInitialize(const bool success) {
EXPECT_EQ(true, success);
}

void TearDown() override {
Expand Down
Loading