From 02686513606836f6092d6f833e14ca564ebdda32 Mon Sep 17 00:00:00 2001 From: Ricardo Guilherme Schmidt <3esmit@gmail.com> Date: Sat, 1 Aug 2026 08:33:39 -0300 Subject: [PATCH] fix: preserve wallet height read errors --- src/lez_core_module.cpp | 4 ++-- tests/test_lez_core.cpp | 12 ++++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/lez_core_module.cpp b/src/lez_core_module.cpp index 9262163..13fb165 100644 --- a/src/lez_core_module.cpp +++ b/src/lez_core_module.cpp @@ -483,7 +483,7 @@ int64_t LEZCoreModule::get_last_synced_block() { const WalletFfiError error = wallet_ffi_get_last_synced_block(walletHandle, &block_id); if (error != SUCCESS) { fprintf(stderr, "get_last_synced_block: wallet FFI error %d\n", error); - return 0; + return -1; } return static_cast(block_id); } @@ -493,7 +493,7 @@ int64_t LEZCoreModule::get_current_block_height() { const WalletFfiError error = wallet_ffi_get_current_block_height(walletHandle, &block_height); if (error != SUCCESS) { fprintf(stderr, "get_current_block_height: wallet FFI error %d\n", error); - return 0; + return -1; } return static_cast(block_height); } diff --git a/tests/test_lez_core.cpp b/tests/test_lez_core.cpp index 6a7bf1a..838d5bb 100644 --- a/tests/test_lez_core.cpp +++ b/tests/test_lez_core.cpp @@ -220,12 +220,12 @@ LOGOS_TEST(get_last_synced_block_returns_value) { LOGOS_ASSERT_EQ(module.get_last_synced_block(), static_cast(55)); } -LOGOS_TEST(get_last_synced_block_error_returns_zero) { +LOGOS_TEST(get_last_synced_block_error_returns_negative_sentinel) { auto t = LogosTestContext("logos_execution_zone"); t.mockCFunction("wallet_ffi_get_last_synced_block").returns(static_cast(INTERNAL_ERROR)); LEZCoreModule module; - LOGOS_ASSERT_EQ(module.get_last_synced_block(), static_cast(0)); + LOGOS_ASSERT_EQ(module.get_last_synced_block(), static_cast(-1)); } LOGOS_TEST(get_current_block_height_returns_value) { @@ -236,6 +236,14 @@ LOGOS_TEST(get_current_block_height_returns_value) { LOGOS_ASSERT_EQ(module.get_current_block_height(), static_cast(999)); } +LOGOS_TEST(get_current_block_height_error_returns_negative_sentinel) { + auto t = LogosTestContext("logos_execution_zone"); + t.mockCFunction("wallet_ffi_get_current_block_height").returns(static_cast(INTERNAL_ERROR)); + LEZCoreModule module; + + LOGOS_ASSERT_EQ(module.get_current_block_height(), static_cast(-1)); +} + // ============================================================================ // Transfers / registration // ============================================================================