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

[ZCash] Fix ZCashShieldSyncServiceTest::ScanBlocks (uplift to 1.77.x) #27879

Merged
merged 1 commit into from
Feb 28, 2025
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 @@ -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
Loading