diff --git a/apps/shared/wallet/src/WalletController.cpp b/apps/shared/wallet/src/WalletController.cpp index 487daa8..5cffdfd 100644 --- a/apps/shared/wallet/src/WalletController.cpp +++ b/apps/shared/wallet/src/WalletController.cpp @@ -215,13 +215,17 @@ void WalletController::applySnapshot(const WalletSnapshot& snapshot) void WalletController::checkReachability() { - if (m_state.sequencerAddress.isEmpty()) + if (!m_state.isWalletOpen || m_state.sequencerAddress.isEmpty()) return; QNetworkRequest request{QUrl(m_state.sequencerAddress)}; request.setTransferTimeout(4000); QNetworkReply* reply = m_network->get(request); connect(reply, &QNetworkReply::finished, this, [this, reply]() { + if (!m_state.isWalletOpen) { + reply->deleteLater(); + return; + } const bool receivedHttp = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).isValid(); const bool reachable = receivedHttp || reply->error() == QNetworkReply::NoError; diff --git a/apps/shared/wallet/tests/cpp/LogosWalletProviderTest.cpp b/apps/shared/wallet/tests/cpp/LogosWalletProviderTest.cpp index f1cb44a..9701d6b 100644 --- a/apps/shared/wallet/tests/cpp/LogosWalletProviderTest.cpp +++ b/apps/shared/wallet/tests/cpp/LogosWalletProviderTest.cpp @@ -1,9 +1,11 @@ #include #include #include +#include #include #include #include +#include #include #include "FakeWalletProvider.h" @@ -56,6 +58,7 @@ private slots: void exposesStableAccountModelRoles(); void fakeProviderImplementsConsumerContract(); void controllerOwnsUiWalletFlow(); + void controllerStopsReachabilityChecksAfterDisconnect(); }; void LogosWalletProviderTest::adoptsOpenWalletAndCachesSnapshots() @@ -358,6 +361,8 @@ void LogosWalletProviderTest::fakeProviderImplementsConsumerContract() QCOMPARE(provider.snapshot(true).accounts.size(), 1); QVERIFY(provider.lastForceRefresh); + QCOMPARE(provider.readPublicAccount(ACCOUNT_B).accountId, ACCOUNT_B); + QCOMPARE(provider.readCalls, 1); WalletTransaction transaction { PROGRAM_ID, { ACCOUNT_A }, { true }, { 9 } }; QVERIFY(provider.submitPublicTransaction(transaction).accepted()); QCOMPARE(provider.lastTransaction.instruction, transaction.instruction); @@ -414,6 +419,34 @@ void LogosWalletProviderTest::controllerOwnsUiWalletFlow() settings.clear(); } +void LogosWalletProviderTest::controllerStopsReachabilityChecksAfterDisconnect() +{ + const QString settingsApplication = QStringLiteral("WalletReachabilityTest"); + QSettings settings(QStringLiteral("Logos"), settingsApplication); + settings.clear(); + + FakeWalletProvider provider; + provider.connectResult.snapshot.sequencerAddress = QStringLiteral("http://127.0.0.1:1"); + WalletController controller(provider, settingsApplication); + auto* network = controller.findChild(); + QVERIFY(network); + QSignalSpy finished(network, &QNetworkAccessManager::finished); + + QVERIFY(controller.open()); + QTRY_VERIFY_WITH_TIMEOUT(!finished.isEmpty(), 1000); + controller.disconnect(); + finished.clear(); + + auto* timer = controller.findChild(); + QVERIFY(timer); + timer->setInterval(1); + controller.start(); + QTest::qWait(50); + QCOMPARE(finished.count(), 0); + + settings.clear(); +} + QTEST_GUILESS_MAIN(LogosWalletProviderTest) #include "LogosWalletProviderTest.moc" diff --git a/apps/shared/wallet/tests/support/FakeWalletProvider.h b/apps/shared/wallet/tests/support/FakeWalletProvider.h index 03b12ad..d5dea0a 100644 --- a/apps/shared/wallet/tests/support/FakeWalletProvider.h +++ b/apps/shared/wallet/tests/support/FakeWalletProvider.h @@ -55,10 +55,12 @@ public: return createAccountResult; } - WalletAccountRead readPublicAccount(const QString&) const override + WalletAccountRead readPublicAccount(const QString& accountId) const override { ++readCalls; - return readResult; + WalletAccountRead result = readResult; + result.accountId = accountId; + return result; } WalletSubmission submitPublicTransaction(