fix(wallet): report partial creation failures

This commit is contained in:
Ricardo Guilherme Schmidt 2026-07-17 20:12:47 -03:00
parent 9c4ade7237
commit c5e4231890
No known key found for this signature in database
GPG Key ID: 1396EA17DE132FFE
2 changed files with 26 additions and 1 deletions

View File

@ -178,17 +178,22 @@ QString WalletController::createWallet(const QString& configPath,
m_state.configPath = config; m_state.configPath = config;
m_state.storagePath = storage; m_state.storagePath = storage;
m_state.walletExists = true;
QSettings(SETTINGS_ORG, m_settingsApplication).setValue(DISCONNECTED_KEY, false); QSettings(SETTINGS_ORG, m_settingsApplication).setValue(DISCONNECTED_KEY, false);
if (!creation.ok()) { if (!creation.ok()) {
qWarning() << "WalletController: wallet creation failed" qWarning() << "WalletController: wallet creation failed"
<< walletFailureCode(creation.failure); << walletFailureCode(creation.failure);
m_state.walletExists = QFileInfo::exists(storage);
m_state.isWalletOpen = false;
m_state.syncStatus = QStringLiteral("error");
m_state.syncError = walletFailureCode(creation.failure);
emit stateChanged(); emit stateChanged();
return creation.mnemonic; return creation.mnemonic;
} }
m_state.walletExists = true;
m_state.isWalletOpen = true; m_state.isWalletOpen = true;
m_state.syncStatus = QStringLiteral("ready"); m_state.syncStatus = QStringLiteral("ready");
m_state.syncError.clear();
applySnapshot(creation.snapshot); applySnapshot(creation.snapshot);
return creation.mnemonic; return creation.mnemonic;
} }

View File

@ -70,6 +70,7 @@ private slots:
void deferredCallbacksIgnoreDestroyedController(); void deferredCallbacksIgnoreDestroyedController();
void newerReachabilityResultWins(); void newerReachabilityResultWins();
void coalescesReachabilityChecksForSameEndpoint(); void coalescesReachabilityChecksForSameEndpoint();
void controllerReportsPartialWalletCreation();
}; };
void LogosWalletProviderTest::adoptsOpenWalletAndCachesSnapshots() void LogosWalletProviderTest::adoptsOpenWalletAndCachesSnapshots()
@ -615,6 +616,25 @@ void LogosWalletProviderTest::coalescesReachabilityChecksForSameEndpoint()
settings.clear(); settings.clear();
} }
void LogosWalletProviderTest::controllerReportsPartialWalletCreation()
{
const QString settingsApplication = QStringLiteral("WalletPartialCreationTest");
QSettings settings(QStringLiteral("Logos"), settingsApplication);
settings.clear();
FakeWalletProvider provider;
provider.createWalletResult.mnemonic = QStringLiteral("one two three");
provider.createWalletResult.failure = WalletFailure::SaveFailed;
WalletController controller(provider, settingsApplication);
QCOMPARE(controller.createDefaultWallet(QStringLiteral("secret")),
provider.createWalletResult.mnemonic);
QVERIFY(!controller.state().isWalletOpen);
QCOMPARE(controller.state().syncStatus, QStringLiteral("error"));
QCOMPARE(controller.state().syncError, QStringLiteral("save_failed"));
settings.clear();
}
QTEST_GUILESS_MAIN(LogosWalletProviderTest) QTEST_GUILESS_MAIN(LogosWalletProviderTest)
#include "LogosWalletProviderTest.moc" #include "LogosWalletProviderTest.moc"