update api

This commit is contained in:
Iuri Matias 2026-06-10 15:16:20 -04:00
parent 92bf652ce4
commit 4baab13bdd
8 changed files with 466 additions and 622 deletions

View File

@ -16,7 +16,6 @@ logos_module(
SOURCES
src/logos_execution_zone_wallet_module.h
src/logos_execution_zone_wallet_module.cpp
src/i_logos_execution_zone_wallet_module.h
EXTERNAL_LIBS
wallet_ffi
)

View File

@ -1,5 +1,5 @@
{
description = "Logos Execution Zone Wallet Module - Qt6 Plugin";
description = "Logos Execution Zone Wallet Module";
inputs = {
logos-module-builder.url = "github:logos-co/logos-module-builder";

View File

@ -5,6 +5,11 @@
"author": "Logos Blockchain Team",
"type": "core",
"category": "blockchain",
"interface": "universal",
"codegen": {
"impl_header": "src/logos_execution_zone_wallet_module.h",
"impl_class": "LogosExecutionZoneWalletModule"
},
"main": "logos_execution_zone_plugin",
"dependencies": [],
"capabilities": [],
@ -13,7 +18,7 @@
"nix": {
"packages": {
"build": [],
"runtime": []
"runtime": ["nlohmann_json"]
},
"external_libraries": [
{

View File

@ -1,107 +0,0 @@
#ifndef I_LOGOS_EXECUTION_ZONE_WALLET_MODULE_H
#define I_LOGOS_EXECUTION_ZONE_WALLET_MODULE_H
#include <core/interface.h>
class ILogosExecutionZoneWalletModule {
public:
virtual ~ILogosExecutionZoneWalletModule() = default;
// === Logos Core ===
virtual void initLogos(LogosAPI* logosApiInstance) = 0;
// === Logos Execution Zone Wallet ===
// Account Management
virtual QString create_account_public() = 0;
virtual QString create_account_private() = 0;
virtual QJsonArray list_accounts() = 0;
// Account Queries
virtual QString get_balance(const QString& account_id_hex, bool is_public) = 0;
virtual QString get_account_public(const QString& account_id_hex) = 0;
virtual QString get_account_private(const QString& account_id_hex) = 0;
virtual QString get_public_account_key(const QString& account_id_hex) = 0;
virtual QString get_private_account_keys(const QString& account_id_hex) = 0;
// Account Encoding
virtual QString account_id_to_base58(const QString& account_id_hex) = 0;
virtual QString account_id_from_base58(const QString& base58_str) = 0;
// Blockchain Synchronisation
virtual int sync_to_block(uint64_t block_id) = 0;
virtual int sync_to_block(const QString& block_id_str) = 0;
virtual int get_last_synced_block() = 0;
virtual int get_current_block_height() = 0;
// Pinata
virtual QString claim_pinata(
const QString& pinata_account_id_hex,
const QString& winner_account_id_hex,
const QString& solution_le16_hex
) = 0;
virtual QString claim_pinata_private_owned_already_initialized(
const QString& pinata_account_id_hex,
const QString& winner_account_id_hex,
const QString& solution_le16_hex,
uint64_t winner_proof_index,
const QString& winner_proof_siblings_json
) = 0;
virtual QString claim_pinata_private_owned_not_initialized(
const QString& pinata_account_id_hex,
const QString& winner_account_id_hex,
const QString& solution_le16_hex
) = 0;
// Operations
virtual QString transfer_public(
const QString& from_hex,
const QString& to_hex,
const QString& amount_le16_hex
) = 0;
virtual QString transfer_shielded(
const QString& from_hex,
const QString& to_keys_json,
const QString& amount_le16_hex
) = 0;
virtual QString transfer_deshielded(
const QString& from_hex,
const QString& to_hex,
const QString& amount_le16_hex
) = 0;
virtual QString transfer_private(
const QString& from_hex,
const QString& to_keys_json,
const QString& amount_le16_hex
) = 0;
virtual QString transfer_shielded_owned(
const QString& from_hex,
const QString& to_hex,
const QString& amount_le16_hex
) = 0;
virtual QString transfer_private_owned(
const QString& from_hex,
const QString& to_hex,
const QString& amount_le16_hex
) = 0;
virtual QString register_public_account(const QString& account_id_hex) = 0;
virtual QString register_private_account(const QString& account_id_hex) = 0;
// Wallet Lifecycle
virtual int create_new(
const QString& config_path,
const QString& storage_path,
const QString& password
) = 0;
virtual int open(const QString& config_path, const QString& storage_path) = 0;
virtual int save() = 0;
// Configuration & Metadata
virtual QString get_sequencer_addr() = 0;
};
#define ILogosExecutionZoneWalletModule_iid "org.logos.ilogosexecutionzonewalletmodule"
Q_DECLARE_INTERFACE(ILogosExecutionZoneWalletModule, ILogosExecutionZoneWalletModule_iid)
#endif

File diff suppressed because it is too large Load Diff

View File

@ -1,130 +1,80 @@
#ifndef LOGOS_EXECUTION_ZONE_WALLET_MODULE_H
#define LOGOS_EXECUTION_ZONE_WALLET_MODULE_H
#include "i_logos_execution_zone_wallet_module.h"
#include <cstdint>
#include <string>
#include <logos_json.h>
#ifdef __cplusplus
extern "C" {
#endif
#include <wallet_ffi.h>
#ifdef __cplusplus
}
#endif
#include <QJsonArray>
#include <QObject>
#include <QString>
#include <QVariantList>
class LogosExecutionZoneWalletModule : public QObject, public PluginInterface, public ILogosExecutionZoneWalletModule {
Q_OBJECT
Q_PLUGIN_METADATA(IID ILogosExecutionZoneWalletModule_iid FILE "metadata.json")
Q_INTERFACES(PluginInterface ILogosExecutionZoneWalletModule)
private:
LogosAPI* logosApi = nullptr;
WalletHandle* walletHandle = nullptr;
// Universal (Qt-free) execution-zone wallet module. The Qt glue (provider
// object + plugin) is generated from this header by logos-cpp-generator, which
// maps the std return types below to the Qt signatures callers invoke:
// std::string -> QString, int64_t -> int, LogosList -> QVariantList.
//
// NOTE: the generator parses this header line-by-line and only recognises a
// method when its declaration ends with ';' on a single line. Keep every
// method declaration on ONE line — multi-line signatures are silently dropped.
class LogosExecutionZoneWalletModule {
public:
LogosExecutionZoneWalletModule();
~LogosExecutionZoneWalletModule() override;
~LogosExecutionZoneWalletModule();
// === Plugin Interface ===
[[nodiscard]] QString name() const override;
[[nodiscard]] QString version() const override;
LogosExecutionZoneWalletModule(const LogosExecutionZoneWalletModule&) = delete;
LogosExecutionZoneWalletModule& operator=(const LogosExecutionZoneWalletModule&) = delete;
// === Logos Core ===
std::string name() const;
std::string version() const;
Q_INVOKABLE void initLogos(LogosAPI* logosApiInstance) override;
// === Wallet Lifecycle ===
int64_t create_new(const std::string& config_path, const std::string& storage_path, const std::string& password);
int64_t open(const std::string& config_path, const std::string& storage_path);
int64_t save();
// === Logos Execution Zone Wallet ===
// === Account Management ===
std::string create_account_public();
std::string create_account_private();
LogosList list_accounts();
// Pinata claiming
Q_INVOKABLE QString claim_pinata(
const QString& pinata_account_id_hex,
const QString& winner_account_id_hex,
const QString& solution_le16_hex
) override;
Q_INVOKABLE QString claim_pinata_private_owned_already_initialized(
const QString& pinata_account_id_hex,
const QString& winner_account_id_hex,
const QString& solution_le16_hex,
uint64_t winner_proof_index,
const QString& winner_proof_siblings_json
) override;
Q_INVOKABLE QString claim_pinata_private_owned_not_initialized(
const QString& pinata_account_id_hex,
const QString& winner_account_id_hex,
const QString& solution_le16_hex
) override;
// === Account Queries ===
std::string get_balance(const std::string& account_id_hex, bool is_public);
std::string get_account_public(const std::string& account_id_hex);
std::string get_account_private(const std::string& account_id_hex);
std::string get_public_account_key(const std::string& account_id_hex);
std::string get_private_account_keys(const std::string& account_id_hex);
// Account Management
Q_INVOKABLE QString create_account_public() override;
Q_INVOKABLE QString create_account_private() override;
Q_INVOKABLE QJsonArray list_accounts() override;
// === Account Encoding ===
std::string account_id_to_base58(const std::string& account_id_hex);
std::string account_id_from_base58(const std::string& base58_str);
// Account Queries
Q_INVOKABLE QString get_balance(const QString& account_id_hex, bool is_public) override;
Q_INVOKABLE QString get_balance(const QString& account_id_hex, const QString& is_public_str);
Q_INVOKABLE QString get_account_public(const QString& account_id_hex) override;
Q_INVOKABLE QString get_account_private(const QString& account_id_hex) override;
Q_INVOKABLE QString get_public_account_key(const QString& account_id_hex) override;
Q_INVOKABLE QString get_private_account_keys(const QString& account_id_hex) override;
// === Blockchain Synchronisation ===
int64_t sync_to_block(int64_t block_id);
int64_t get_last_synced_block();
int64_t get_current_block_height();
// Account Encoding
Q_INVOKABLE QString account_id_to_base58(const QString& account_id_hex) override;
Q_INVOKABLE QString account_id_from_base58(const QString& base58_str) override;
// === Pinata claiming ===
std::string claim_pinata(const std::string& pinata_account_id_hex, const std::string& winner_account_id_hex, const std::string& solution_le16_hex);
std::string claim_pinata_private_owned_already_initialized(const std::string& pinata_account_id_hex, const std::string& winner_account_id_hex, const std::string& solution_le16_hex, int64_t winner_proof_index, const std::string& winner_proof_siblings_json);
std::string claim_pinata_private_owned_not_initialized(const std::string& pinata_account_id_hex, const std::string& winner_account_id_hex, const std::string& solution_le16_hex);
// Blockchain Synchronisation
Q_INVOKABLE int sync_to_block(uint64_t block_id) override;
Q_INVOKABLE int sync_to_block(const QString& block_id_str) override;
Q_INVOKABLE int get_last_synced_block() override;
Q_INVOKABLE int get_current_block_height() override;
// === Operations ===
std::string transfer_public(const std::string& from_hex, const std::string& to_hex, const std::string& amount_le16_hex);
std::string transfer_shielded(const std::string& from_hex, const std::string& to_keys_json, const std::string& amount_le16_hex);
std::string transfer_deshielded(const std::string& from_hex, const std::string& to_hex, const std::string& amount_le16_hex);
std::string transfer_private(const std::string& from_hex, const std::string& to_keys_json, const std::string& amount_le16_hex);
std::string transfer_shielded_owned(const std::string& from_hex, const std::string& to_hex, const std::string& amount_le16_hex);
std::string transfer_private_owned(const std::string& from_hex, const std::string& to_hex, const std::string& amount_le16_hex);
std::string register_public_account(const std::string& account_id_hex);
std::string register_private_account(const std::string& account_id_hex);
// Operations
Q_INVOKABLE QString transfer_public(
const QString& from_hex,
const QString& to_hex,
const QString& amount_le16_hex
) override;
Q_INVOKABLE QString transfer_shielded(
const QString& from_hex,
const QString& to_keys_json,
const QString& amount_le16_hex
) override;
Q_INVOKABLE QString transfer_deshielded(
const QString& from_hex,
const QString& to_hex,
const QString& amount_le16_hex
) override;
Q_INVOKABLE QString transfer_private(
const QString& from_hex,
const QString& to_keys_json,
const QString& amount_le16_hex
) override;
Q_INVOKABLE QString transfer_shielded_owned(
const QString& from_hex,
const QString& to_hex,
const QString& amount_le16_hex
) override;
Q_INVOKABLE QString transfer_private_owned(
const QString& from_hex,
const QString& to_hex,
const QString& amount_le16_hex
) override;
Q_INVOKABLE QString register_public_account(const QString& account_id_hex) override;
Q_INVOKABLE QString register_private_account(const QString& account_id_hex) override;
// === Configuration ===
std::string get_sequencer_addr();
// Wallet Lifecycle
Q_INVOKABLE int create_new(const QString& config_path, const QString& storage_path, const QString& password) override;
Q_INVOKABLE int open(const QString& config_path, const QString& storage_path) override;
Q_INVOKABLE int save() override;
// Configuration
Q_INVOKABLE QString get_sequencer_addr() override;
signals:
void eventResponse(const QString& eventName, const QVariantList& data);
private:
WalletHandle* walletHandle = nullptr;
};
#endif
#endif // LOGOS_EXECUTION_ZONE_WALLET_MODULE_H

View File

@ -4,19 +4,20 @@
#include <logos_test.h>
#include "logos_execution_zone_wallet_module.h"
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <QString>
#include <string>
#include <nlohmann/json.hpp>
// 64-char hex string = 32 bytes (valid account id).
static const QString VALID_ID = QString(64, 'a');
static const QString VALID_ID_2 = QString(64, 'b');
static const std::string VALID_ID = std::string(64, 'a');
static const std::string VALID_ID_2 = std::string(64, 'b');
// 32-char hex string = 16 bytes (valid amount / solution).
static const QString VALID_U128 = QString(32, '1');
static const std::string VALID_U128 = std::string(32, '1');
static QJsonObject parseObject(const QString& json) {
return QJsonDocument::fromJson(json.toUtf8()).object();
// The impl returns serialized JSON strings (Qt-free). Parse them here so tests
// can assert on individual fields.
static nlohmann::json parseObject(const std::string& json) {
return nlohmann::json::parse(json, nullptr, false);
}
// ============================================================================
@ -25,8 +26,8 @@ static QJsonObject parseObject(const QString& json) {
LOGOS_TEST(name_and_version) {
LogosExecutionZoneWalletModule module;
LOGOS_ASSERT_EQ(module.name(), QStringLiteral("logos_execution_zone"));
LOGOS_ASSERT_EQ(module.version(), QStringLiteral("1.0.0"));
LOGOS_ASSERT_EQ(module.name(), std::string("logos_execution_zone"));
LOGOS_ASSERT_EQ(module.version(), std::string("1.0.0"));
}
// ============================================================================
@ -37,10 +38,12 @@ LOGOS_TEST(create_account_public_returns_hex_on_success) {
auto t = LogosTestContext("logos_execution_zone");
LogosExecutionZoneWalletModule module;
const QString id = module.create_account_public();
const std::string id = module.create_account_public();
LOGOS_ASSERT(t.cFunctionCalled("wallet_ffi_create_account_public"));
// Mock fills the id with 0xAB bytes -> 64 hex chars ("ab" x 32).
LOGOS_ASSERT_EQ(id, QString("ab").repeated(32));
std::string expected;
for (int i = 0; i < 32; ++i) expected += "ab";
LOGOS_ASSERT_EQ(id, expected);
}
LOGOS_TEST(create_account_public_returns_empty_on_error) {
@ -48,16 +51,18 @@ LOGOS_TEST(create_account_public_returns_empty_on_error) {
t.mockCFunction("wallet_ffi_create_account_public").returns(static_cast<int>(INTERNAL_ERROR));
LogosExecutionZoneWalletModule module;
LOGOS_ASSERT_TRUE(module.create_account_public().isEmpty());
LOGOS_ASSERT_TRUE(module.create_account_public().empty());
}
LOGOS_TEST(create_account_private_returns_hex_on_success) {
auto t = LogosTestContext("logos_execution_zone");
LogosExecutionZoneWalletModule module;
const QString id = module.create_account_private();
const std::string id = module.create_account_private();
LOGOS_ASSERT(t.cFunctionCalled("wallet_ffi_create_account_private"));
LOGOS_ASSERT_EQ(id, QString("cd").repeated(32));
std::string expected;
for (int i = 0; i < 32; ++i) expected += "cd";
LOGOS_ASSERT_EQ(id, expected);
}
LOGOS_TEST(list_accounts_maps_entries) {
@ -65,17 +70,16 @@ LOGOS_TEST(list_accounts_maps_entries) {
t.mockCFunction("list_accounts_count").returns(3);
LogosExecutionZoneWalletModule module;
const QJsonArray accounts = module.list_accounts();
const LogosList accounts = module.list_accounts();
LOGOS_ASSERT(t.cFunctionCalled("wallet_ffi_list_accounts"));
LOGOS_ASSERT_EQ(accounts.size(), 3);
LOGOS_ASSERT_EQ(static_cast<int>(accounts.size()), 3);
// list_accounts appends JSON objects (ffiAccountListEntryToJson returns a
// QJsonObject); entry 0 is public, entry 1 is private.
const QJsonObject e0 = accounts[0].toObject();
LOGOS_ASSERT_TRUE(e0["is_public"].toBool());
LOGOS_ASSERT_EQ(e0["account_id"].toString(), QString("10").repeated(32));
const QJsonObject e1 = accounts[1].toObject();
LOGOS_ASSERT_FALSE(e1["is_public"].toBool());
// entry 0 is public, entry 1 is private.
std::string expectedId0;
for (int i = 0; i < 32; ++i) expectedId0 += "10";
LOGOS_ASSERT_TRUE(accounts[0]["is_public"].get<bool>());
LOGOS_ASSERT_EQ(accounts[0]["account_id"].get<std::string>(), expectedId0);
LOGOS_ASSERT_FALSE(accounts[1]["is_public"].get<bool>());
}
LOGOS_TEST(list_accounts_empty_on_error) {
@ -83,7 +87,7 @@ LOGOS_TEST(list_accounts_empty_on_error) {
t.mockCFunction("wallet_ffi_list_accounts").returns(static_cast<int>(INTERNAL_ERROR));
LogosExecutionZoneWalletModule module;
LOGOS_ASSERT_EQ(module.list_accounts().size(), 0);
LOGOS_ASSERT_EQ(static_cast<int>(module.list_accounts().size()), 0);
}
// ============================================================================
@ -94,7 +98,7 @@ LOGOS_TEST(get_balance_invalid_hex_returns_empty) {
auto t = LogosTestContext("logos_execution_zone");
LogosExecutionZoneWalletModule module;
LOGOS_ASSERT_TRUE(module.get_balance(QStringLiteral("not-hex"), true).isEmpty());
LOGOS_ASSERT_TRUE(module.get_balance("not-hex", true).empty());
LOGOS_ASSERT_FALSE(t.cFunctionCalled("wallet_ffi_get_balance"));
}
@ -103,9 +107,9 @@ LOGOS_TEST(get_balance_returns_decimal_string) {
t.mockCFunction("get_balance_value").returns(123456789);
LogosExecutionZoneWalletModule module;
const QString balance = module.get_balance(VALID_ID, true);
const std::string balance = module.get_balance(VALID_ID, true);
LOGOS_ASSERT(t.cFunctionCalled("wallet_ffi_get_balance"));
LOGOS_ASSERT_EQ(balance, QStringLiteral("123456789"));
LOGOS_ASSERT_EQ(balance, std::string("123456789"));
}
LOGOS_TEST(get_balance_zero) {
@ -113,35 +117,26 @@ LOGOS_TEST(get_balance_zero) {
t.mockCFunction("get_balance_value").returns(0);
LogosExecutionZoneWalletModule module;
LOGOS_ASSERT_EQ(module.get_balance(VALID_ID, false), QStringLiteral("0"));
}
LOGOS_TEST(get_balance_string_overload_parses_bool) {
auto t = LogosTestContext("logos_execution_zone");
t.mockCFunction("get_balance_value").returns(42);
LogosExecutionZoneWalletModule module;
LOGOS_ASSERT_EQ(module.get_balance(VALID_ID, QStringLiteral("true")), QStringLiteral("42"));
LOGOS_ASSERT_EQ(module.get_balance(VALID_ID, QStringLiteral("1")), QStringLiteral("42"));
LOGOS_ASSERT_EQ(module.get_balance(VALID_ID, QStringLiteral("yes")), QStringLiteral("42"));
LOGOS_ASSERT_EQ(module.get_balance(VALID_ID, false), std::string("0"));
}
LOGOS_TEST(get_account_public_returns_json) {
auto t = LogosTestContext("logos_execution_zone");
LogosExecutionZoneWalletModule module;
const QString json = module.get_account_public(VALID_ID);
const nlohmann::json obj = parseObject(module.get_account_public(VALID_ID));
LOGOS_ASSERT(t.cFunctionCalled("wallet_ffi_get_account_public"));
const QJsonObject obj = parseObject(json);
// program_owner mocked to 0xAA bytes.
LOGOS_ASSERT_EQ(obj["program_owner"].toString(), QString("aa").repeated(32));
std::string expectedOwner;
for (int i = 0; i < 32; ++i) expectedOwner += "aa";
LOGOS_ASSERT_EQ(obj["program_owner"].get<std::string>(), expectedOwner);
}
LOGOS_TEST(get_account_public_invalid_hex_returns_empty) {
auto t = LogosTestContext("logos_execution_zone");
LogosExecutionZoneWalletModule module;
LOGOS_ASSERT_TRUE(module.get_account_public(QStringLiteral("zz")).isEmpty());
LOGOS_ASSERT_TRUE(module.get_account_public("zz").empty());
LOGOS_ASSERT_FALSE(t.cFunctionCalled("wallet_ffi_get_account_public"));
}
@ -149,15 +144,19 @@ LOGOS_TEST(get_public_account_key_returns_hex) {
auto t = LogosTestContext("logos_execution_zone");
LogosExecutionZoneWalletModule module;
LOGOS_ASSERT_EQ(module.get_public_account_key(VALID_ID), QString("be").repeated(32));
std::string expected;
for (int i = 0; i < 32; ++i) expected += "be";
LOGOS_ASSERT_EQ(module.get_public_account_key(VALID_ID), expected);
}
LOGOS_TEST(get_private_account_keys_returns_json) {
auto t = LogosTestContext("logos_execution_zone");
LogosExecutionZoneWalletModule module;
const QJsonObject obj = parseObject(module.get_private_account_keys(VALID_ID));
LOGOS_ASSERT_EQ(obj["nullifier_public_key"].toString(), QString("ef").repeated(32));
const nlohmann::json obj = parseObject(module.get_private_account_keys(VALID_ID));
std::string expected;
for (int i = 0; i < 32; ++i) expected += "ef";
LOGOS_ASSERT_EQ(obj["nullifier_public_key"].get<std::string>(), expected);
}
// ============================================================================
@ -168,7 +167,7 @@ LOGOS_TEST(account_id_to_base58_invalid_hex_returns_empty) {
auto t = LogosTestContext("logos_execution_zone");
LogosExecutionZoneWalletModule module;
LOGOS_ASSERT_TRUE(module.account_id_to_base58(QStringLiteral("xyz")).isEmpty());
LOGOS_ASSERT_TRUE(module.account_id_to_base58("xyz").empty());
}
LOGOS_TEST(account_id_to_base58_returns_string) {
@ -176,14 +175,16 @@ LOGOS_TEST(account_id_to_base58_returns_string) {
t.mockCFunction("wallet_ffi_account_id_to_base58").returns("SomeBase58Value");
LogosExecutionZoneWalletModule module;
LOGOS_ASSERT_EQ(module.account_id_to_base58(VALID_ID), QStringLiteral("SomeBase58Value"));
LOGOS_ASSERT_EQ(module.account_id_to_base58(VALID_ID), std::string("SomeBase58Value"));
}
LOGOS_TEST(account_id_from_base58_returns_hex) {
auto t = LogosTestContext("logos_execution_zone");
LogosExecutionZoneWalletModule module;
LOGOS_ASSERT_EQ(module.account_id_from_base58(QStringLiteral("anything")), QString("5a").repeated(32));
std::string expected;
for (int i = 0; i < 32; ++i) expected += "5a";
LOGOS_ASSERT_EQ(module.account_id_from_base58("anything"), expected);
}
LOGOS_TEST(account_id_from_base58_error_returns_empty) {
@ -191,27 +192,19 @@ LOGOS_TEST(account_id_from_base58_error_returns_empty) {
t.mockCFunction("wallet_ffi_account_id_from_base58").returns(static_cast<int>(INTERNAL_ERROR));
LogosExecutionZoneWalletModule module;
LOGOS_ASSERT_TRUE(module.account_id_from_base58(QStringLiteral("anything")).isEmpty());
LOGOS_ASSERT_TRUE(module.account_id_from_base58("anything").empty());
}
// ============================================================================
// Blockchain synchronisation
// ============================================================================
LOGOS_TEST(sync_to_block_string_invalid_returns_negative_one) {
auto t = LogosTestContext("logos_execution_zone");
LogosExecutionZoneWalletModule module;
LOGOS_ASSERT_EQ(module.sync_to_block(QStringLiteral("notnum")), -1);
LOGOS_ASSERT_FALSE(t.cFunctionCalled("wallet_ffi_sync_to_block"));
}
LOGOS_TEST(sync_to_block_string_valid_forwards) {
LOGOS_TEST(sync_to_block_forwards_value) {
auto t = LogosTestContext("logos_execution_zone");
t.mockCFunction("wallet_ffi_sync_to_block").returns(7);
LogosExecutionZoneWalletModule module;
LOGOS_ASSERT_EQ(module.sync_to_block(QStringLiteral("100")), 7);
LOGOS_ASSERT_EQ(module.sync_to_block(100), static_cast<int64_t>(7));
LOGOS_ASSERT(t.cFunctionCalled("wallet_ffi_sync_to_block"));
}
@ -220,7 +213,7 @@ LOGOS_TEST(get_last_synced_block_returns_value) {
t.mockCFunction("last_synced_block_value").returns(55);
LogosExecutionZoneWalletModule module;
LOGOS_ASSERT_EQ(module.get_last_synced_block(), 55);
LOGOS_ASSERT_EQ(module.get_last_synced_block(), static_cast<int64_t>(55));
}
LOGOS_TEST(get_last_synced_block_error_returns_zero) {
@ -228,7 +221,7 @@ LOGOS_TEST(get_last_synced_block_error_returns_zero) {
t.mockCFunction("wallet_ffi_get_last_synced_block").returns(static_cast<int>(INTERNAL_ERROR));
LogosExecutionZoneWalletModule module;
LOGOS_ASSERT_EQ(module.get_last_synced_block(), 0);
LOGOS_ASSERT_EQ(module.get_last_synced_block(), static_cast<int64_t>(0));
}
LOGOS_TEST(get_current_block_height_returns_value) {
@ -236,7 +229,7 @@ LOGOS_TEST(get_current_block_height_returns_value) {
t.mockCFunction("current_block_height_value").returns(999);
LogosExecutionZoneWalletModule module;
LOGOS_ASSERT_EQ(module.get_current_block_height(), 999);
LOGOS_ASSERT_EQ(module.get_current_block_height(), static_cast<int64_t>(999));
}
// ============================================================================
@ -247,20 +240,20 @@ LOGOS_TEST(transfer_public_success_json) {
auto t = LogosTestContext("logos_execution_zone");
LogosExecutionZoneWalletModule module;
const QJsonObject obj = parseObject(module.transfer_public(VALID_ID, VALID_ID_2, VALID_U128));
const nlohmann::json obj = parseObject(module.transfer_public(VALID_ID, VALID_ID_2, VALID_U128));
LOGOS_ASSERT(t.cFunctionCalled("wallet_ffi_transfer_public"));
LOGOS_ASSERT_TRUE(obj["success"].toBool());
LOGOS_ASSERT_EQ(obj["tx_hash"].toString(), QStringLiteral("0xmocktxhash"));
LOGOS_ASSERT_TRUE(obj["error"].toString().isEmpty());
LOGOS_ASSERT_TRUE(obj["success"].get<bool>());
LOGOS_ASSERT_EQ(obj["tx_hash"].get<std::string>(), std::string("0xmocktxhash"));
LOGOS_ASSERT_TRUE(obj["error"].get<std::string>().empty());
}
LOGOS_TEST(transfer_public_invalid_hex_error_json) {
auto t = LogosTestContext("logos_execution_zone");
LogosExecutionZoneWalletModule module;
const QJsonObject obj = parseObject(module.transfer_public(QStringLiteral("bad"), VALID_ID_2, VALID_U128));
LOGOS_ASSERT_FALSE(obj["success"].toBool());
LOGOS_ASSERT_FALSE(obj["error"].toString().isEmpty());
const nlohmann::json obj = parseObject(module.transfer_public("bad", VALID_ID_2, VALID_U128));
LOGOS_ASSERT_FALSE(obj["success"].get<bool>());
LOGOS_ASSERT_FALSE(obj["error"].get<std::string>().empty());
LOGOS_ASSERT_FALSE(t.cFunctionCalled("wallet_ffi_transfer_public"));
}
@ -268,9 +261,9 @@ LOGOS_TEST(transfer_public_invalid_amount_error_json) {
auto t = LogosTestContext("logos_execution_zone");
LogosExecutionZoneWalletModule module;
const QJsonObject obj = parseObject(module.transfer_public(VALID_ID, VALID_ID_2, QStringLiteral("ff")));
LOGOS_ASSERT_FALSE(obj["success"].toBool());
LOGOS_ASSERT_CONTAINS(obj["error"].toString().toStdString(), std::string("amount"));
const nlohmann::json obj = parseObject(module.transfer_public(VALID_ID, VALID_ID_2, "ff"));
LOGOS_ASSERT_FALSE(obj["success"].get<bool>());
LOGOS_ASSERT_CONTAINS(obj["error"].get<std::string>(), std::string("amount"));
}
LOGOS_TEST(transfer_public_ffi_error_json) {
@ -278,9 +271,9 @@ LOGOS_TEST(transfer_public_ffi_error_json) {
t.mockCFunction("wallet_ffi_transfer_public").returns(static_cast<int>(INTERNAL_ERROR));
LogosExecutionZoneWalletModule module;
const QJsonObject obj = parseObject(module.transfer_public(VALID_ID, VALID_ID_2, VALID_U128));
LOGOS_ASSERT_FALSE(obj["success"].toBool());
LOGOS_ASSERT_FALSE(obj["error"].toString().isEmpty());
const nlohmann::json obj = parseObject(module.transfer_public(VALID_ID, VALID_ID_2, VALID_U128));
LOGOS_ASSERT_FALSE(obj["success"].get<bool>());
LOGOS_ASSERT_FALSE(obj["error"].get<std::string>().empty());
}
LOGOS_TEST(transfer_shielded_invalid_keys_json_error) {
@ -288,8 +281,8 @@ LOGOS_TEST(transfer_shielded_invalid_keys_json_error) {
LogosExecutionZoneWalletModule module;
// to_keys_json is not valid JSON object -> parse failure.
const QJsonObject obj = parseObject(module.transfer_shielded(VALID_ID, QStringLiteral("not-json"), VALID_U128));
LOGOS_ASSERT_FALSE(obj["success"].toBool());
const nlohmann::json obj = parseObject(module.transfer_shielded(VALID_ID, "not-json", VALID_U128));
LOGOS_ASSERT_FALSE(obj["success"].get<bool>());
LOGOS_ASSERT_FALSE(t.cFunctionCalled("wallet_ffi_transfer_shielded"));
}
@ -297,18 +290,18 @@ LOGOS_TEST(transfer_shielded_success_json) {
auto t = LogosTestContext("logos_execution_zone");
LogosExecutionZoneWalletModule module;
const QString keysJson = QStringLiteral("{\"nullifier_public_key\":\"") + QString(64, 'a') + QStringLiteral("\"}");
const QJsonObject obj = parseObject(module.transfer_shielded(VALID_ID, keysJson, VALID_U128));
const std::string keysJson = std::string("{\"nullifier_public_key\":\"") + std::string(64, 'a') + std::string("\"}");
const nlohmann::json obj = parseObject(module.transfer_shielded(VALID_ID, keysJson, VALID_U128));
LOGOS_ASSERT(t.cFunctionCalled("wallet_ffi_transfer_shielded"));
LOGOS_ASSERT_TRUE(obj["success"].toBool());
LOGOS_ASSERT_TRUE(obj["success"].get<bool>());
}
LOGOS_TEST(register_public_account_invalid_hex_error_json) {
auto t = LogosTestContext("logos_execution_zone");
LogosExecutionZoneWalletModule module;
const QJsonObject obj = parseObject(module.register_public_account(QStringLiteral("bad")));
LOGOS_ASSERT_FALSE(obj["success"].toBool());
const nlohmann::json obj = parseObject(module.register_public_account("bad"));
LOGOS_ASSERT_FALSE(obj["success"].get<bool>());
LOGOS_ASSERT_FALSE(t.cFunctionCalled("wallet_ffi_register_public_account"));
}
@ -316,9 +309,9 @@ LOGOS_TEST(register_private_account_success_json) {
auto t = LogosTestContext("logos_execution_zone");
LogosExecutionZoneWalletModule module;
const QJsonObject obj = parseObject(module.register_private_account(VALID_ID));
const nlohmann::json obj = parseObject(module.register_private_account(VALID_ID));
LOGOS_ASSERT(t.cFunctionCalled("wallet_ffi_register_private_account"));
LOGOS_ASSERT_TRUE(obj["success"].toBool());
LOGOS_ASSERT_TRUE(obj["success"].get<bool>());
}
// ============================================================================
@ -329,7 +322,7 @@ LOGOS_TEST(claim_pinata_invalid_hex_returns_empty) {
auto t = LogosTestContext("logos_execution_zone");
LogosExecutionZoneWalletModule module;
LOGOS_ASSERT_TRUE(module.claim_pinata(QStringLiteral("bad"), VALID_ID_2, VALID_U128).isEmpty());
LOGOS_ASSERT_TRUE(module.claim_pinata("bad", VALID_ID_2, VALID_U128).empty());
LOGOS_ASSERT_FALSE(t.cFunctionCalled("wallet_ffi_claim_pinata"));
}
@ -337,7 +330,7 @@ LOGOS_TEST(claim_pinata_invalid_solution_returns_empty) {
auto t = LogosTestContext("logos_execution_zone");
LogosExecutionZoneWalletModule module;
LOGOS_ASSERT_TRUE(module.claim_pinata(VALID_ID, VALID_ID_2, QStringLiteral("ab")).isEmpty());
LOGOS_ASSERT_TRUE(module.claim_pinata(VALID_ID, VALID_ID_2, "ab").empty());
LOGOS_ASSERT_FALSE(t.cFunctionCalled("wallet_ffi_claim_pinata"));
}
@ -345,9 +338,9 @@ LOGOS_TEST(claim_pinata_success_json) {
auto t = LogosTestContext("logos_execution_zone");
LogosExecutionZoneWalletModule module;
const QJsonObject obj = parseObject(module.claim_pinata(VALID_ID, VALID_ID_2, VALID_U128));
const nlohmann::json obj = parseObject(module.claim_pinata(VALID_ID, VALID_ID_2, VALID_U128));
LOGOS_ASSERT(t.cFunctionCalled("wallet_ffi_claim_pinata"));
LOGOS_ASSERT_TRUE(obj["success"].toBool());
LOGOS_ASSERT_TRUE(obj["success"].get<bool>());
}
LOGOS_TEST(claim_pinata_already_initialized_invalid_siblings_returns_empty) {
@ -355,9 +348,9 @@ LOGOS_TEST(claim_pinata_already_initialized_invalid_siblings_returns_empty) {
LogosExecutionZoneWalletModule module;
// siblings json is not an array -> parse failure.
const QString result = module.claim_pinata_private_owned_already_initialized(
VALID_ID, VALID_ID_2, VALID_U128, 0, QStringLiteral("not-an-array"));
LOGOS_ASSERT_TRUE(result.isEmpty());
const std::string result = module.claim_pinata_private_owned_already_initialized(
VALID_ID, VALID_ID_2, VALID_U128, 0, "not-an-array");
LOGOS_ASSERT_TRUE(result.empty());
LOGOS_ASSERT_FALSE(t.cFunctionCalled("wallet_ffi_claim_pinata_private_owned_already_initialized"));
}
@ -365,11 +358,11 @@ LOGOS_TEST(claim_pinata_already_initialized_success_json) {
auto t = LogosTestContext("logos_execution_zone");
LogosExecutionZoneWalletModule module;
const QString siblings = QStringLiteral("[\"") + QString(64, 'a') + QStringLiteral("\",\"") + QString(64, 'b') + QStringLiteral("\"]");
const QJsonObject obj = parseObject(module.claim_pinata_private_owned_already_initialized(
const std::string siblings = std::string("[\"") + std::string(64, 'a') + std::string("\",\"") + std::string(64, 'b') + std::string("\"]");
const nlohmann::json obj = parseObject(module.claim_pinata_private_owned_already_initialized(
VALID_ID, VALID_ID_2, VALID_U128, 1, siblings));
LOGOS_ASSERT(t.cFunctionCalled("wallet_ffi_claim_pinata_private_owned_already_initialized"));
LOGOS_ASSERT_TRUE(obj["success"].toBool());
LOGOS_ASSERT_TRUE(obj["success"].get<bool>());
}
// ============================================================================
@ -381,12 +374,10 @@ LOGOS_TEST(create_new_success_then_double_open_fails) {
t.mockCFunction("wallet_ffi_create_new").returns(1); // non-null handle
LogosExecutionZoneWalletModule module;
LOGOS_ASSERT_EQ(module.create_new(QStringLiteral("/cfg"), QStringLiteral("/store"), QStringLiteral("pw")),
static_cast<int>(SUCCESS));
LOGOS_ASSERT_EQ(module.create_new("/cfg", "/store", "pw"), static_cast<int64_t>(SUCCESS));
LOGOS_ASSERT(t.cFunctionCalled("wallet_ffi_create_new"));
// Second attempt: already open.
LOGOS_ASSERT_EQ(module.create_new(QStringLiteral("/cfg"), QStringLiteral("/store"), QStringLiteral("pw")),
static_cast<int>(INTERNAL_ERROR));
LOGOS_ASSERT_EQ(module.create_new("/cfg", "/store", "pw"), static_cast<int64_t>(INTERNAL_ERROR));
}
LOGOS_TEST(create_new_null_handle_returns_internal_error) {
@ -394,8 +385,7 @@ LOGOS_TEST(create_new_null_handle_returns_internal_error) {
t.mockCFunction("wallet_ffi_create_new").returns(0); // null handle
LogosExecutionZoneWalletModule module;
LOGOS_ASSERT_EQ(module.create_new(QStringLiteral("/cfg"), QStringLiteral("/store"), QStringLiteral("pw")),
static_cast<int>(INTERNAL_ERROR));
LOGOS_ASSERT_EQ(module.create_new("/cfg", "/store", "pw"), static_cast<int64_t>(INTERNAL_ERROR));
}
LOGOS_TEST(open_success) {
@ -403,7 +393,7 @@ LOGOS_TEST(open_success) {
t.mockCFunction("wallet_ffi_open").returns(1);
LogosExecutionZoneWalletModule module;
LOGOS_ASSERT_EQ(module.open(QStringLiteral("/cfg"), QStringLiteral("/store")), static_cast<int>(SUCCESS));
LOGOS_ASSERT_EQ(module.open("/cfg", "/store"), static_cast<int64_t>(SUCCESS));
LOGOS_ASSERT(t.cFunctionCalled("wallet_ffi_open"));
}
@ -412,7 +402,7 @@ LOGOS_TEST(save_forwards_return_code) {
t.mockCFunction("wallet_ffi_save").returns(static_cast<int>(SUCCESS));
LogosExecutionZoneWalletModule module;
LOGOS_ASSERT_EQ(module.save(), static_cast<int>(SUCCESS));
LOGOS_ASSERT_EQ(module.save(), static_cast<int64_t>(SUCCESS));
LOGOS_ASSERT(t.cFunctionCalled("wallet_ffi_save"));
}
@ -425,5 +415,5 @@ LOGOS_TEST(get_sequencer_addr_returns_string) {
t.mockCFunction("wallet_ffi_get_sequencer_addr").returns("10.0.0.1:9000");
LogosExecutionZoneWalletModule module;
LOGOS_ASSERT_EQ(module.get_sequencer_addr(), QStringLiteral("10.0.0.1:9000"));
LOGOS_ASSERT_EQ(module.get_sequencer_addr(), std::string("10.0.0.1:9000"));
}

View File

@ -8,20 +8,20 @@
#include <logos_test.h>
#include "logos_execution_zone_wallet_module.h"
#include <QString>
#include <string>
// account_id_to_base58 and account_id_from_base58 are pure encoding helpers that
// do not require an open wallet, so they can be exercised against the real lib.
LOGOS_TEST(integration_account_id_base58_round_trip) {
LogosExecutionZoneWalletModule module;
const QString idHex = QString(64, 'a');
const std::string idHex = std::string(64, 'a');
const QString base58 = module.account_id_to_base58(idHex);
LOGOS_ASSERT_FALSE(base58.isEmpty());
const std::string base58 = module.account_id_to_base58(idHex);
LOGOS_ASSERT_FALSE(base58.empty());
const QString decodedHex = module.account_id_from_base58(base58);
LOGOS_ASSERT_FALSE(decodedHex.isEmpty());
const std::string decodedHex = module.account_id_from_base58(base58);
LOGOS_ASSERT_FALSE(decodedHex.empty());
LOGOS_ASSERT_EQ(decodedHex, idHex);
}
@ -29,5 +29,5 @@ LOGOS_TEST(integration_account_id_from_base58_rejects_garbage) {
LogosExecutionZoneWalletModule module;
// Clearly invalid base58 input should not decode to a valid id.
LOGOS_ASSERT_TRUE(module.account_id_from_base58(QStringLiteral("!!!not-base58!!!")).isEmpty());
LOGOS_ASSERT_TRUE(module.account_id_from_base58("!!!not-base58!!!").empty());
}