aboutsummaryrefslogtreecommitdiff
path: root/tests/main.cpp
blob: 8818ff9fb546bcfc76b842c878d09df0b13c2233 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <vector>
#include "../include/Database.hpp"
#include "../include/Group.hpp"
#include "../include/LocalUser.hpp"
#include <chrono>
#include <thread>

using namespace std;
using namespace chrono_literals;
using namespace odhtdb;

int main()
{
    LocalUser *localUser = LocalUser::create(Signature::KeyPair(), "dec05eba");
    
    std::string publicKeyStr = localUser->getPublicKey().toString();
    printf("Local user public key: %s\n", publicKeyStr.c_str());
    
    std::string privateKeyStr = localUser->getPrivateKey().toString();
    printf("Local user private key: %s\n", privateKeyStr.c_str());

    // TODO: For tests, dont run against bootstrap.ring.cx.
    // Run against a bootstrap node made only for testing which doesn't persist added data.
    
    Database database("bootstrap.ring.cx", 4222, "storage");
    database.seed();

    Group group("admin");
    group.addUser(localUser);
    database.create("galax.channel.latenight.chat", &group);

    const char *data = "hello, world!";
    database.add("galax.channel.latenight.chat", DataView{ (void*)data, strlen(data) }, localUser);
    database.commit();
    auto start = chrono::high_resolution_clock::now();
    while(chrono::high_resolution_clock::now() - start < 5s)
    {
        this_thread::sleep_for(10ms);
    }
    
    return 0;
}