From 606622f8fc47111e709e392e0e1ae9554f226ec8 Mon Sep 17 00:00:00 2001 From: Ricardo Guilherme Schmidt <3esmit@gmail.com> Date: Sat, 1 Aug 2026 21:30:56 -0300 Subject: [PATCH] fix(lez-core): preserve generic transaction envelope --- src/lez_core_module.cpp | 30 +++++++++++++++++++++++------- tests/test_lez_core.cpp | 33 ++++++++++++++++++++++++++++++--- 2 files changed, 53 insertions(+), 10 deletions(-) diff --git a/src/lez_core_module.cpp b/src/lez_core_module.cpp index ec416ab..55e25fc 100644 --- a/src/lez_core_module.cpp +++ b/src/lez_core_module.cpp @@ -1138,15 +1138,21 @@ std::string LEZCoreModule::send_generic_public_transaction( ) { if (account_ids.empty()) { fprintf(stderr, "send_generic_public_transaction: account_ids must not be empty\n"); - return transferResultToJson(nullptr, "send_generic_public_transaction: account_ids must not be empty"); + return genericTransactionResultToJson( + nullptr, + "send_generic_public_transaction: account_ids must not be empty"); } if (account_ids.size() != signing_requirements.size()) { fprintf(stderr, "send_generic_public_transaction: account_ids and signing_requirements must have the same size\n"); - return transferResultToJson(nullptr, "send_generic_public_transaction: account_ids and signing_requirements must have the same size"); + return genericTransactionResultToJson( + nullptr, + "send_generic_public_transaction: account_ids and signing_requirements must have the same size"); } if (instruction.empty()) { fprintf(stderr, "send_generic_public_transaction: instruction must not be empty\n"); - return transferResultToJson(nullptr, "send_generic_public_transaction: instruction must not be empty"); + return genericTransactionResultToJson( + nullptr, + "send_generic_public_transaction: instruction must not be empty"); } std::vector identities_resolved; @@ -1158,13 +1164,18 @@ std::string LEZCoreModule::send_generic_public_transaction( FfiBytes32 id{}; if (!hexToBytes32(account_ids[i], &id)) { fprintf(stderr, "wallet_ffi_resolve_public_account: invalid account_id_hex"); - return transferResultToJson(nullptr, std::string("wallet_ffi_resolve_public_account: invalid account_id_hex")); + return genericTransactionResultToJson( + nullptr, + std::string("wallet_ffi_resolve_public_account: invalid account_id_hex")); } WalletFfiError error = wallet_ffi_resolve_public_account(id, signing_requirements[i], &acc_identity); if (error != SUCCESS) { fprintf(stderr, "wallet_ffi_resolve_public_account failed for index %zu: wallet FFI error %d\n", i, error); - return transferResultToJson(nullptr, std::string("wallet_ffi_resolve_public_account: wallet FFI error ") + std::to_string(error)); + return genericTransactionResultToJson( + nullptr, + std::string("wallet_ffi_resolve_public_account: wallet FFI error ") + + std::to_string(error)); } identities_resolved.push_back(acc_identity); } @@ -1178,7 +1189,9 @@ std::string LEZCoreModule::send_generic_public_transaction( std::vector program_id_bytes; if (!hexToBytes(program_id_hex, program_id_bytes, 32)) { fprintf(stderr, "send_generic_public_transaction: invalid program_id_hex"); - return transferResultToJson(nullptr, std::string("send_generic_public_transaction: invalid program_id_hex")); + return genericTransactionResultToJson( + nullptr, + std::string("send_generic_public_transaction: invalid program_id_hex")); } FfiProgramId program_id{}; memcpy(program_id.data, program_id_bytes.data(), 32); @@ -1201,7 +1214,10 @@ std::string LEZCoreModule::send_generic_public_transaction( if (error != SUCCESS) { fprintf(stderr, "send_generic_public_transaction: wallet FFI error %d\n", error); - return transferResultToJson(nullptr, std::string("send_generic_public_transaction: wallet FFI error ") + std::to_string(error)); + return genericTransactionResultToJson( + nullptr, + std::string("send_generic_public_transaction: wallet FFI error ") + + std::to_string(error)); } std::string resultJson = genericTransactionResultToJson(&result, std::string()); wallet_ffi_free_transaction_result(&result); diff --git a/tests/test_lez_core.cpp b/tests/test_lez_core.cpp index c8bf062..77814a0 100644 --- a/tests/test_lez_core.cpp +++ b/tests/test_lez_core.cpp @@ -542,27 +542,54 @@ LOGOS_TEST(generic_public_transaction_rejects_malformed_vectors) { auto t = LogosTestContext("logos_execution_zone"); LEZCoreModule module; + const auto assertGenericRejection = [](const nlohmann::json& result) { + LOGOS_ASSERT_FALSE(result["success"].get()); + LOGOS_ASSERT_TRUE(result.contains("secrets")); + LOGOS_ASSERT_TRUE(result["secrets"].is_array()); + LOGOS_ASSERT_EQ(result["secrets"].size(), static_cast(0)); + LOGOS_ASSERT_EQ(result.size(), static_cast(4)); + }; + const nlohmann::json mismatched = parseObject(module.send_generic_public_transaction( {VALID_ID}, {}, {0}, std::string(64, 'c') )); - LOGOS_ASSERT_FALSE(mismatched["success"].get()); + assertGenericRejection(mismatched); LOGOS_ASSERT_CONTAINS(mismatched["error"].get(), std::string("same size")); LOGOS_ASSERT_FALSE(t.cFunctionCalled("wallet_ffi_send_generic_public_transaction")); const nlohmann::json empty_accounts = parseObject(module.send_generic_public_transaction( {}, {}, {0}, std::string(64, 'c') )); - LOGOS_ASSERT_FALSE(empty_accounts["success"].get()); + assertGenericRejection(empty_accounts); LOGOS_ASSERT_CONTAINS(empty_accounts["error"].get(), std::string("account_ids")); const nlohmann::json empty_instruction = parseObject(module.send_generic_public_transaction( {VALID_ID}, {true}, {}, std::string(64, 'c') )); - LOGOS_ASSERT_FALSE(empty_instruction["success"].get()); + assertGenericRejection(empty_instruction); LOGOS_ASSERT_CONTAINS(empty_instruction["error"].get(), std::string("instruction")); LOGOS_ASSERT_FALSE(t.cFunctionCalled("wallet_ffi_send_generic_public_transaction")); } +LOGOS_TEST(generic_public_transaction_ffi_error_preserves_envelope) { + auto t = LogosTestContext("logos_execution_zone"); + t.mockCFunction("wallet_ffi_send_generic_public_transaction") + .returns(static_cast(INTERNAL_ERROR)); + LEZCoreModule module; + + const nlohmann::json result = parseObject(module.send_generic_public_transaction( + {VALID_ID}, {true}, {1}, std::string(64, 'c') + )); + + LOGOS_ASSERT(t.cFunctionCalled("wallet_ffi_send_generic_public_transaction")); + LOGOS_ASSERT_FALSE(result["success"].get()); + LOGOS_ASSERT_TRUE(result.contains("secrets")); + LOGOS_ASSERT_TRUE(result["secrets"].is_array()); + LOGOS_ASSERT_EQ(result["secrets"].size(), static_cast(0)); + LOGOS_ASSERT_EQ(result.size(), static_cast(4)); + LOGOS_ASSERT_CONTAINS(result["error"].get(), std::string("wallet FFI error")); +} + LOGOS_TEST(register_private_account_success_json) { auto t = LogosTestContext("logos_execution_zone"); LEZCoreModule module;