Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • cellframe/cellframe-node
  • evseev/cellframe-node
  • dmitry.puzyrkov/cellframe-node
  • MIKA83/cellframe-node
4 results
Show changes
Showing
with 0 additions and 593 deletions
#include <time.h>
#include <unistd.h>
#include "dap_common.h"
#include "dap_strfuncs.h"
#include "dap_file_utils.h"
//#include "dap_list.h"
#include "dap_chain_global_db.h"
#include "dap_chain_global_db_driver.h"
#include "dap_global_db_test.h"
#define DB_FILE "./base.tmp"
static void test_create_db(const char *db_type)
{
if(dap_dir_test(DB_FILE)) {
rmdir(DB_FILE);
char *l_cmd = dap_strdup_printf("rm -rf %s", DB_FILE);
system(l_cmd);
DAP_DELETE(l_cmd);
}
else
unlink(DB_FILE);
int res = dap_db_driver_init(db_type, DB_FILE);
char *l_str = dap_strdup_printf("Test init %s global_db", db_type);
dap_assert(!res, l_str);
DAP_DELETE(l_str);
}
static void test_write_read_one(void)
{
dap_store_obj_t *l_store_obj = DAP_NEW_Z(dap_store_obj_t);
size_t l_store_count = 1;
l_store_obj->type = 'a';
l_store_obj->key = dap_strdup("key");
l_store_obj->group = dap_strdup("section.1");
l_store_obj->timestamp = time(NULL);
l_store_obj->value_len = rand() % 100;
l_store_obj->value = DAP_NEW_SIZE(uint8_t, l_store_obj->value_len);
for(size_t i = 0; i < l_store_obj->value_len; i++) {
l_store_obj->value[i] = rand();
}
int ret = dap_chain_global_db_driver_add(l_store_obj, l_store_count);
dap_store_obj_t *l_store_obj2 = dap_chain_global_db_driver_read(l_store_obj->group, l_store_obj->key, NULL);
dap_assert_PIF(l_store_obj2, "Read global_db entry");
// compare l_store_obj and l_store_obj
if(l_store_obj->timestamp == l_store_obj2->timestamp &&
l_store_obj->value_len == l_store_obj2->value_len &&
l_store_obj->value && l_store_obj2->value &&
!memcmp(l_store_obj->value, l_store_obj2->value, l_store_obj->value_len)) {
dap_assert_PIF(1, "Check read entry");
}
else {
dap_assert_PIF(0, "Check read entry");
}
dap_store_obj_free(l_store_obj, 1);
dap_store_obj_free(l_store_obj2, 1);
dap_assert(1, "Test dap_global_db one record");
}
static void test_close_db(void)
{
dap_db_driver_deinit(); //dap_chain_global_db_deinit();
dap_assert(1, "Test close global_db");
}
static void test_write_db_count(void)
{
int a_count = 20000;
dap_store_obj_t *l_store_obj = DAP_NEW_Z_SIZE(dap_store_obj_t, sizeof(dap_store_obj_t) * a_count);
size_t l_store_count = 1;
for(size_t n = 0; n < a_count; n++) {
dap_store_obj_t *l_store_obj_cur = l_store_obj + n;
l_store_obj_cur->type = 'a';
l_store_obj_cur->key = dap_strdup_printf("key_%d", rand());
l_store_obj_cur->group = dap_strdup("section.1");
l_store_obj_cur->timestamp = time(NULL);
l_store_obj_cur->value_len = 10 + rand() % 100;
l_store_obj_cur->value = DAP_NEW_SIZE(uint8_t, l_store_obj_cur->value_len);
for(size_t i = 0; i < l_store_obj_cur->value_len; i++) {
l_store_obj_cur->value[i] = rand();
}
}
//dap_test_msg("Start test write dap_global_db %d record", a_count);
int ret = dap_chain_global_db_driver_add(l_store_obj, a_count);
//dap_test_msg("Read first record");
dap_store_obj_t *l_store_obj2 = dap_chain_global_db_driver_read(l_store_obj->group, l_store_obj->key, NULL);
dap_store_obj_free(l_store_obj2, 1);
//dap_test_msg("Start test read dap_global_db %d record", a_count);
for(size_t n = 1; n < a_count; n++) {
dap_store_obj_t *l_store_obj2 = dap_chain_global_db_driver_read(l_store_obj->group, l_store_obj->key, NULL);
dap_assert_PIF(l_store_obj2, "Read data");
// compare l_store_obj and l_store_obj
if(l_store_obj->timestamp == l_store_obj2->timestamp &&
l_store_obj->value_len == l_store_obj2->value_len &&
l_store_obj->value && l_store_obj2->value &&
!memcmp(l_store_obj->value, l_store_obj2->value, l_store_obj->value_len)) {
;
}
else {
dap_assert_PIF(0, "Check read entry");
}
dap_store_obj_free(l_store_obj2, 1);
}
//dap_assert_PIF(1, "Read global_db entry");
dap_store_obj_free(l_store_obj, a_count);
//dap_usleep(5 * DAP_USEC_PER_SEC);
//dap_assert(1, "Test dap_global_db");
}
void dap_global_db_tests_run(void)
{
dap_print_module_name("dap_global_db");
// cdb
test_create_db("cdb");
test_write_read_one();
benchmark_mgs_time("Read and Write in cdb 20000 records",
benchmark_test_time(test_write_db_count, 1));
// sqlite
test_create_db("sqlite");
test_write_read_one();
// test_write_db_count(1000000);
benchmark_mgs_time("Read and Write in sqlite 20000 records",
benchmark_test_time(test_write_db_count, 1));
//test_close_db();
//dap_assert(1, "Test dap_global_db: write and read 20000 records");
/*
benchmark_mgs_time("Read and Write in global_db 100 times",
benchmark_test_time(test_write_db_count, 1));
dap_assert(1, "Test dap_global_db 100 records");
*/
// benchmark_mgs_rate("Read and Write in global_db",
// benchmark_test_rate(test_write_db_count, 2000));
//dap_usleep(2 * DAP_USEC_PER_SEC);
test_close_db();
}
#pragma once
#include "libdap-test/dap_test.h"
extern void dap_global_db_tests_run(void);
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <stddef.h>
#include <stdint.h>
#include <unistd.h>
#include <sys/types.h>
#include <getopt.h>
#include <signal.h>
#define __USE_XOPEN_EXTENDED
#include <ftw.h>
#include "dap_config.h"
#include "dap_server.h"
#include "dap_http.h"
#include "dap_http_folder.h"
#include "dap_events.h"
#include "dap_enc.h"
#include "dap_enc_ks.h"
#include "dap_enc_http.h"
#include "dap_chain.h"
#include "dap_chain_wallet.h"
#include "dap_chain_gdb.h"
#include "dap_chain_net.h"
#include "dap_chain_net_srv.h"
#include "dap_chain_global_db.h"
#include "dap_chain_mempool.h"
#include "dap_chain_node_cli.h"
#include "dap_stream_session.h"
#include "dap_stream.h"
#include "dap_stream_ctl.h"
#include "dap_stream_ch_chain.h"
#include "dap_stream_ch_chain_net.h"
#include "dap_common.h"
#include "dap_client_remote.h"
#include "dap_client.h"
#include "dap_http_client.h"
#include "dap_http_client_simple.h"
#include "dap_http_simple.h"
#include "dap_process_manager.h"
#include "dap_traffic_track.h"
#include "dap_file_utils.h"
#include "dap_chain_node_cli_cmd.h"
#include "dap_tx_test.h"
static const char *wallet_from_create_args[] = {
"wallet",
"new",
"-w", "wallet_from"
};
static const char *wallet_to_create_args[] = {
"wallet",
"new",
"-w", "wallet_to"
};
static const char *mempool_proc_args[] = {
"mempool_proc",
"-net" ,"local-testnet",
"-chain" ,"gdb"
};
typedef struct arg_data {
char **call_args;
char *str_reply;
} arg_data;
void *call_com_tx_create(void *arg) {
arg_data *args = (arg_data*)arg;
com_tx_create(15, args->call_args, &(args->str_reply));
DAP_DELETE(args->str_reply);
return NULL;
}
static int rm_r(const char *path, const struct stat *sbuf, int type, struct FTW *ftwb){
return remove(path);
}
int cleanup() {
if(dap_dir_test("./locale/var/lib/global_db")){
nftw("./locale/var/lib/global_db", rm_r, 10, FTW_DEPTH | FTW_MOUNT | FTW_PHYS);
mkdir("./locale/var/lib/global_db", S_IRWXU | S_IRWXG | S_IRWXO);
}
if(dap_dir_test("./locale/var/lib/wallet")){
nftw("./locale/var/lib/wallet", rm_r, 10, FTW_DEPTH | FTW_MOUNT | FTW_PHYS);
mkdir("./locale/var/lib/wallet", S_IRWXU | S_IRWXG | S_IRWXO);
}
return 0;
}
int dap_node_run_action(scenario_t action) {
char *str_reply = NULL;
if (action == VAIN) {
} else if (action == EMIT) {
dap_assert_PIF(com_tx_wallet(4, wallet_from_create_args, &str_reply) == 0, str_reply);
dap_test_msg(str_reply);
DAP_DELETE(str_reply);
str_reply = NULL;
dap_assert_PIF(com_tx_wallet(4, wallet_to_create_args, &str_reply) == 0, str_reply);
dap_test_msg(str_reply);
DAP_DELETE(str_reply);
str_reply = NULL;
dap_chain_wallet_t *l_wallet_from = dap_chain_wallet_open_file("./locale/var/lib/wallet/wallet_from.dwallet");
dap_chain_addr_t *l_addr_from = dap_chain_wallet_get_addr(l_wallet_from);
const char *l_addr_str_from = dap_chain_addr_to_str(l_addr_from);
dap_test_msg(l_addr_str_from);
dap_chain_wallet_close(l_wallet_from);
const char *token_decl_args[] = {
"token_decl",
"-net" ,"local-testnet",
"-chain" ,"gdb",
"token" ,"MAVRODI",
"total_supply" ,"1001000000000000",
"signs_total" ,"1",
"signs_emission","1",
"certs" ,"mavrodi-cert"
};
dap_assert_PIF(com_token_decl(15, token_decl_args, &str_reply) == 0, str_reply);
dap_test_msg(str_reply);
DAP_DELETE(str_reply);
str_reply = NULL;
const char *token_emit_args[] = {
"token_emit",
"-net" ,"local-testnet",
"-chain_emission" ,"gdb",
"-chain_base_tx" ,"gdb",
"-addr" ,l_addr_str_from,
"-token" ,"MAVRODI",
"-certs" ,"mavrodi-cert",
"-emission_value" ,"1001000000000000"
};
dap_assert_PIF(com_token_emit(15, token_emit_args, &str_reply) == 0, str_reply);
dap_test_msg(str_reply);
DAP_DELETE(str_reply);
str_reply = NULL;
dap_assert_PIF(com_mempool_proc(4, mempool_proc_args, &str_reply) == 0, str_reply);
dap_test_msg(str_reply);
DAP_DELETE(str_reply);
str_reply = NULL;
DAP_DELETE(l_addr_str_from);
} else if (action == TX) {
dap_chain_wallet_t *l_wallet_to = dap_chain_wallet_open_file("./locale/var/lib/wallet/wallet_to.dwallet");
dap_chain_addr_t *l_addr_to = dap_chain_wallet_get_addr(l_wallet_to);
const char *l_addr_str_to = dap_chain_addr_to_str(l_addr_to);
dap_test_msg(l_addr_str_to);
dap_chain_wallet_close(l_wallet_to);
const char *tx_create_args[] = {
"tx_create",
"-net" ,"local-testnet",
"-chain" ,"gdb",
"-from_wallet" ,"wallet_from",
"-to_addr" ,l_addr_str_to,
"-token" ,"MAVRODI",
"-value" ,"1000000000000",
"-tx_num" ,"200"
};
pthread_t thrds[5];
arg_data args[5];
for (int i = 0; i < 5; ++i) {
args[i].call_args = tx_create_args;
args[i].str_reply = NULL;
pthread_create(&thrds[i], NULL, call_com_tx_create, (void*)&args[i]);
}
int status;
for (int i = 0; i < 5; ++i) {
pthread_join(thrds[i], (void**)&status);
}
DAP_DELETE(l_addr_str_to);
dap_assert_PIF(com_mempool_proc(4, mempool_proc_args, &str_reply) == 0, str_reply);
}
else if (action == CHECK) {
dap_chain_wallet_t *l_wallet_from = dap_chain_wallet_open_file("./locale/var/lib/wallet/wallet_from.dwallet");
dap_chain_addr_t *l_addr_from = dap_chain_wallet_get_addr(l_wallet_from);
dap_chain_wallet_t *l_wallet_to = dap_chain_wallet_open_file("./locale/var/lib/wallet/wallet_to.dwallet");
dap_chain_addr_t *l_addr_to = dap_chain_wallet_get_addr(l_wallet_to);
dap_ledger_t *l_ledger = dap_chain_ledger_by_net_name("local-testnet");
size_t l_addr_tokens_size = 0;
char **l_addr_tokens = NULL;
dap_chain_ledger_addr_get_token_ticker_all_fast(l_ledger, l_addr_to, &l_addr_tokens, &l_addr_tokens_size);
dap_assert_PIF(l_addr_tokens_size > 0, "No tokens found on wallet.");
uint64_t l_balance_to = dap_chain_ledger_calc_balance(l_ledger, l_addr_to, l_addr_tokens[0]);
dap_assert_PIF(l_balance_to == 1000000000000000, "Balance TO is not equal what it must be.");
l_balance_to = dap_chain_ledger_calc_balance(l_ledger, l_addr_from, l_addr_tokens[0]);
dap_assert_PIF(l_balance_to == 1000000000000, "Balance FROM is not equal what it must be.");
DAP_DELETE(l_addr_tokens[0]);
DAP_DELETE(l_addr_tokens);
dap_chain_wallet_close(l_wallet_from);
dap_chain_wallet_close(l_wallet_to);
}
return 0;
}
int dap_node_init() {
dap_assert_PIF(dap_common_init("locale", "locale_logs.txt") == 0, "Can't init common functions module");
dap_assert_PIF(dap_config_init("./locale/etc") == 0, "Can't init config");
g_config = dap_config_open("local");
dap_assert_PIF(g_config != NULL, "Config not found");
dap_assert_PIF(dap_server_init(1) == 0, "Can't init server");
dap_assert_PIF(dap_http_init() == 0, "Can't init HTTP cli submodule");
dap_http_folder_init();
dap_assert_PIF(dap_enc_init() == 0, "Can't init encryption module");
dap_assert_PIF(dap_enc_ks_init(false, 60 *60 * 2) == 0, "Can't init encryption key storage module");
dap_assert_PIF(dap_chain_global_db_init(g_config) == 0, "Can't init DB");
dap_client_init();
dap_http_client_simple_init();
dap_datum_mempool_init();
dap_assert_PIF(dap_chain_init() == 0, "Can't init CA storage");
dap_chain_wallet_init();
dap_chain_gdb_init();
dap_chain_net_init();
dap_chain_net_srv_init();
enc_http_init();
dap_stream_init(dap_config_get_item_bool_default(g_config, "general", "debug_dump_stream_headers", false));
dap_stream_ctl_init(DAP_ENC_KEY_TYPE_OAES, 32);
dap_http_simple_module_init();
//
// dap_assert_PIF(dap_chain_node_cli_init(g_config) == 0, "Can't init server for console");
dap_stream_ch_chain_init();
dap_stream_ch_chain_net_init();
dap_events_init(0, 0);
dap_events_t *l_events = dap_events_new();
dap_events_start(l_events);
dap_chain_net_load_all();
return 0;
}
int dap_node_deinit() {
dap_stream_deinit();
dap_stream_ctl_deinit();
dap_http_folder_deinit();
dap_http_deinit();
dap_server_deinit();
dap_enc_ks_deinit();
dap_db_driver_deinit();
//dap_config_close(g_config); // sisegv
dap_common_deinit();
return 0;
}
void dap_tx_tests_run() {
cleanup();
dap_node_init();
dap_node_run_action(EMIT);
dap_node_run_action(TX);
dap_node_deinit();
dap_node_init();
dap_node_run_action(CHECK);
dap_node_deinit();
}
#ifndef DAP_TX_TEST_H
#define DAP_TX_TEST_H
#include "dap_test.h"
typedef enum scenario {
VAIN = 0,
EMIT = 1,
TX = 2,
CHECK = 3
} scenario_t;
void dap_tx_tests_run();
int dap_node_run_action(scenario_t);
int dap_node_init();
int dap_node_deinit();
#endif // DAP_TX_TEST_H
Subproject commit b76175acc517f085c319c8e66c62bd143f96bf94
# General section
[general]
debug_mode=true
debug_dump_stream_headers=false
wallets_path=./locale/var/lib/wallet
wallets_default=default
node_role=full
# seed mode. WARNING. Used true only when you start the new network
#seed_mode=false
auto_online=false
# Server part
[server]
# By default you don't need to open you to the world
enabled=true
listen_address=0.0.0.0
listen_port_tcp=8079
# Mempool
[mempool]
accept=false
# VPN stream channel processing module
[vpn]
# Turn to true if you want to share VPN service from you node
enabled=false
# List of loca security access groups. Built in: expats,admins,services,nobody,everybody
access_groups=expats,services,admins
network_address=10.11.12.0
network_mask=255.255.255.0
# Application Resources
[resources]
# 0 means auto detect
threads_cnt=0
pid_path=./locale/var/run/kelvin-node.pid
log_file=./locale/var/log/kelvin-node.log
ca_folders=[./locale/var/lib/ca,./locale/share/ca]
dap_global_db_path=./locale/var/lib/global_db
dap_global_db_driver=cdb
# Kelvin Blockchain: development network
# General section
[general]
id=0xFF00000000000001
name=local-testnet
type=testing
# Possible values: light, full, archive, master, root
node-role=full
#node-alias=addr-%node_addr%
gdb_groups_prefix=local-testnet
#[dag-poa]
#events-sign-cert=mycert
#[dag-pos]
#events-sign-wallet=mywallet
[chain]
id=0xf00000000000000f
name=gdb
consensus=gdb
class=gdb
[gdb]
# Celled means sharded
celled=false
File deleted
File deleted
File deleted
File deleted
File deleted
File deleted
File deleted
# General section
[general]
debug_mode=false
wallets_path=/opt/kelvin-node/var/lib/wallet
wallets_default=default
node_role=full
# seed mode. WARNING. Used true only when you start the new network
#seed_mode=false
# Server part
[server]
# By default you don't need to open you to the world
enabled=true
listen_address=0.0.0.0
listen_port_tcp=8079
# Mempool
[mempool]
accept=false
# VPN stream channel processing module
[vpn]
# Turn to true if you want to share VPN service from you node
enabled=false
# List of loca security access groups. Built in: expats,admins,services,nobody,everybody
access_groups=expats,services,admins
network_address=10.0.0.0
network_mask=255.255.255.0
# Application Resources
[resources]
# 0 means auto detect
threads_cnt=0
pid_path=/opt/kelvin-node/var/run/kelvin-node.pid
log_file=/opt/kelvin-node/var/log/kelvin-node.log
ca_folders=[/opt/kelvin-node/var/lib/ca,/opt/kelvin-node/share/ca]
dap_global_db_path=/opt/kelvin-node/var/whitelist.ldb
# Kelvin Blockchain: development network
# General section
[general]
id=0x0000000000000001
name=kelvin-testnet
type=development
# Possible values: light, full, archive, master, root
node-role=full
node-alias=addr-%node_addr%
gdb_groups_prefix=kelvin.testnet
seed_nodes_ipv4=[159.89.228.115,165.227.17.239,104.248.89.205,157.230.240.104,167.99.87.197,46.101.149.240,159.89.122.48]
seed_nodes_aliases=[kelvin.testnet.root.0,kelvin.testnet.root.1,kelvin.testnet.root.2,kelvin.testnet.root.3,kelvin.testnet.root.4,kelvin.testnet.root.5,kelvin.testnet.root.6]
seed_nodes_addr=[ffff::0000::0000::0001,ffff::0000::0000::0002,ffff::0000::0000::0003,ffff::0000::0000::0004,ffff::0000::0000::0005,ffff::0000::0000::0006,ffff::0000::0000::0007]
#[dag-poa]
#events-sign-cert=mycert
#[dag-pos]
#events-sign-wallet=mywallet
[Unit]
Description=Kelvin Node
After=network.target
[Service]
Type=forking
OOMScoreAdjust=-1000
PIDFile=/opt/kelvin-node/var/run/kelvin-node.pid
WorkingDirectory=/opt/kelvin-node
ExecStart=/opt/kelvin-node/bin/kelvin-node -D
ExecStop=/opt/kelvin-node/bin/kelvin-node --stop
Restart=always
[Install]
WantedBy=multi-user.target
File deleted