Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 23 additions & 7 deletions src/lez_core_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<FfiAccountIdentity> identities_resolved;
Expand All @@ -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);
}
Expand All @@ -1178,7 +1189,9 @@ std::string LEZCoreModule::send_generic_public_transaction(
std::vector<uint8_t> 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);
Expand All @@ -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);
Expand Down
33 changes: 30 additions & 3 deletions tests/test_lez_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool>());
LOGOS_ASSERT_TRUE(result.contains("secrets"));
LOGOS_ASSERT_TRUE(result["secrets"].is_array());
LOGOS_ASSERT_EQ(result["secrets"].size(), static_cast<size_t>(0));
LOGOS_ASSERT_EQ(result.size(), static_cast<size_t>(4));
};

const nlohmann::json mismatched = parseObject(module.send_generic_public_transaction(
{VALID_ID}, {}, {0}, std::string(64, 'c')
));
LOGOS_ASSERT_FALSE(mismatched["success"].get<bool>());
assertGenericRejection(mismatched);
LOGOS_ASSERT_CONTAINS(mismatched["error"].get<std::string>(), 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<bool>());
assertGenericRejection(empty_accounts);
LOGOS_ASSERT_CONTAINS(empty_accounts["error"].get<std::string>(), 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<bool>());
assertGenericRejection(empty_instruction);
LOGOS_ASSERT_CONTAINS(empty_instruction["error"].get<std::string>(), 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<int>(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<bool>());
LOGOS_ASSERT_TRUE(result.contains("secrets"));
LOGOS_ASSERT_TRUE(result["secrets"].is_array());
LOGOS_ASSERT_EQ(result["secrets"].size(), static_cast<size_t>(0));
LOGOS_ASSERT_EQ(result.size(), static_cast<size_t>(4));
LOGOS_ASSERT_CONTAINS(result["error"].get<std::string>(), std::string("wallet FFI error"));
}

LOGOS_TEST(register_private_account_success_json) {
auto t = LogosTestContext("logos_execution_zone");
LEZCoreModule module;
Expand Down