Skip to content

Commit

Permalink
Fixes intermittent crash if Confirmations library is called before be…
Browse files Browse the repository at this point in the history
…ing instantiated
  • Loading branch information
tmancey authored and NejcZdovc committed Jan 15, 2020
1 parent 2dcd30b commit 268cb47
Show file tree
Hide file tree
Showing 15 changed files with 292 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ using TransactionInfo = ::ledger::TransactionInfo;
using TransactionsInfo = ::ledger::TransactionsInfo;

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 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

0 comments on commit 268cb47

Please sign in to comment.