Skip to content

Commit

Permalink
[ZCash] Fix ZCashShieldSyncServiceTest::ScanBlocks (#27842)
Browse files Browse the repository at this point in the history
[ZCash] Fix ZCashShieldSyncServiceTest::ScanBlocks
Resolves brave/brave-browser#44253
  • Loading branch information
cypt4 authored Feb 27, 2025
1 parent 2593444 commit c29c0a3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 25 deletions.
32 changes: 14 additions & 18 deletions components/brave_wallet/browser/zcash/zcash_shield_sync_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,7 @@ void ZCashShieldSyncService::OnScanRangeResult(
return;
}

latest_scanned_block_result_ = result.value();
UpdateSpendableNotes();
UpdateSpendableNotes(result.value());
}

uint32_t ZCashShieldSyncService::GetSpendableBalance() {
Expand All @@ -251,16 +250,18 @@ uint32_t ZCashShieldSyncService::GetSpendableBalance() {
return balance;
}

void ZCashShieldSyncService::UpdateSpendableNotes() {
spendable_notes_ = std::nullopt;
void ZCashShieldSyncService::UpdateSpendableNotes(
const ScanRangeResult& scan_range_result) {
sync_state()
.AsyncCall(&OrchardSyncState::GetSpendableNotes)
.WithArgs(context_.account_id.Clone())
.Then(base::BindOnce(&ZCashShieldSyncService::OnGetSpendableNotes,
weak_ptr_factory_.GetWeakPtr()));
weak_ptr_factory_.GetWeakPtr(),
std::move(scan_range_result)));
}

void ZCashShieldSyncService::OnGetSpendableNotes(
const ScanRangeResult& scan_range_result,
base::expected<std::vector<OrchardNote>, OrchardStorage::Error> result) {
if (!result.has_value()) {
error_ = Error{ErrorCode::kFailedToRetrieveSpendableNotes,
Expand All @@ -270,19 +271,14 @@ void ZCashShieldSyncService::OnGetSpendableNotes(
}

spendable_notes_ = result.value();

if (latest_scanned_block_result_) {
current_sync_status_ = mojom::ZCashShieldSyncStatus::New(
latest_scanned_block_result_->start_block,
latest_scanned_block_result_->end_block,
latest_scanned_block_result_->total_ranges,
latest_scanned_block_result_->ready_ranges, spendable_notes_->size(),
GetSpendableBalance());
} else {
current_sync_status_ = mojom::ZCashShieldSyncStatus::New(
latest_scanned_block_.value_or(0), latest_scanned_block_.value_or(0), 0,
0, spendable_notes_->size(), GetSpendableBalance());
}
latest_scanned_block_result_ = scan_range_result;

current_sync_status_ = mojom::ZCashShieldSyncStatus::New(
latest_scanned_block_result_->start_block,
latest_scanned_block_result_->end_block,
latest_scanned_block_result_->total_ranges,
latest_scanned_block_result_->ready_ranges, spendable_notes_->size(),
GetSpendableBalance());

if (observer_) {
observer_->OnSyncStatusUpdate(context_.account_id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,9 @@ class ZCashShieldSyncService {
uint32_t GetSpendableBalance();

// Update spendable notes state
void UpdateSpendableNotes();
void UpdateSpendableNotes(const ScanRangeResult& scan_range_result);
void OnGetSpendableNotes(
const ScanRangeResult& scan_range_result,
base::expected<std::vector<OrchardNote>, OrchardStorage::Error> result);

void StartBlockScanning();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,6 @@ class ZCashShieldSyncServiceTest : public testing::Test {
base::test::TaskEnvironment task_environment_;
};

#if defined(IS_MAC)
#define MAYBE_ScanBlocks DISABLED_ScanBlocks
#else
#define MAYBE_ScanBlocks ScanBlocks
#endif

TEST_F(ZCashShieldSyncServiceTest, ScanBlocks) {
auto mock_block_scanner = CreateMockOrchardBlockScannerProxy();

Expand Down

0 comments on commit c29c0a3

Please sign in to comment.