fix(wallet): release completed snapshot state

This commit is contained in:
Ricardo Guilherme Schmidt 2026-07-17 19:58:34 -03:00
parent 3508bfbf42
commit 0ef3c21fd3
No known key found for this signature in database
GPG Key ID: 1396EA17DE132FFE
2 changed files with 27 additions and 1 deletions

View File

@ -581,7 +581,7 @@ void LogosWalletProvider::loadSnapshotAsync(quint64 generation, SnapshotCallback
}
auto finishOne = std::make_shared<std::function<void()>>();
*finishOne = [this, generation, state, finishOne]() mutable {
*finishOne = [this, generation, state]() mutable {
if (generation != m_generation || --state->remaining > 0)
return;
for (qsizetype index = 0;

View File

@ -8,6 +8,8 @@
#include <QTimer>
#include <QtTest>
#include <memory>
#include "FakeWalletProvider.h"
#include "LogosWalletProvider.h"
#include "WalletAccountModel.h"
@ -61,6 +63,7 @@ private slots:
void controllerOwnsUiWalletFlow();
void controllerOpenDoesNotWaitForWalletSync();
void controllerStopsReachabilityChecksAfterDisconnect();
void completedAsyncSnapshotReleasesCallback();
};
void LogosWalletProviderTest::adoptsOpenWalletAndCachesSnapshots()
@ -478,6 +481,29 @@ void LogosWalletProviderTest::controllerStopsReachabilityChecksAfterDisconnect()
settings.clear();
}
void LogosWalletProviderTest::completedAsyncSnapshotReleasesCallback()
{
LogosModules modules;
modules.logos_execution_zone.sequencerAddress = QStringLiteral("http://sequencer");
LogosWalletProvider provider(&modules);
QVERIFY(provider.connect({}).ok());
bool completed = false;
std::weak_ptr<int> callbackLifetime;
{
auto lifetime = std::make_shared<int>(1);
callbackLifetime = lifetime;
provider.snapshotAsync(true,
[lifetime = std::move(lifetime), &completed](WalletSnapshot snapshot) {
QVERIFY(snapshot.ok());
completed = true;
});
}
QVERIFY(completed);
QVERIFY(callbackLifetime.expired());
}
QTEST_GUILESS_MAIN(LogosWalletProviderTest)
#include "LogosWalletProviderTest.moc"