Pushing Cid into protobuf

This commit is contained in:
jmjatlanta 2016-12-12 06:27:06 -05:00
parent 786bd5d80b
commit e0b0552b39
23 changed files with 327 additions and 77 deletions

View file

@ -2,30 +2,35 @@
#include "ipfs/node/node.h"
#include "../test_helper.h"
int test_merkledag_get_data() {
int retVal = 0;
struct FSRepo* createAndOpenRepo(const char* dir) {
int retVal = 1;
// create a fresh repo
retVal = drop_and_build_repository("/tmp/.ipfs");
retVal = drop_and_build_repository(dir);
if (retVal == 0)
return 0;
return NULL;
// open the fs repo
struct RepoConfig* repo_config = NULL;
struct FSRepo* fs_repo;
const char* path = "/tmp/.ipfs";
// create the struct
retVal = ipfs_repo_fsrepo_new((char*)path, repo_config, &fs_repo);
retVal = ipfs_repo_fsrepo_new(dir, repo_config, &fs_repo);
if (retVal == 0)
return 0;
return NULL;
// open the repository and read the config file
retVal = ipfs_repo_fsrepo_open(fs_repo);
if (retVal == 0) {
ipfs_repo_fsrepo_free(fs_repo);
return 0;
return NULL;
}
return fs_repo;
}
int test_merkledag_get_data() {
int retVal = 0;
struct FSRepo* fs_repo = createAndOpenRepo("/tmp/.ipfs");
// create data for node
size_t binary_data_size = 256;
@ -81,28 +86,10 @@ int test_merkledag_get_data() {
int test_merkledag_add_data() {
int retVal = 0;
// create a fresh repo
retVal = drop_and_build_repository("/tmp/.ipfs");
if (retVal == 0)
struct FSRepo* fs_repo = createAndOpenRepo("/tmp.ipfs");
if (fs_repo == NULL)
return 0;
// open the fs repo
struct RepoConfig* repo_config = NULL;
struct FSRepo* fs_repo;
const char* path = "/tmp/.ipfs";
// create the struct
retVal = ipfs_repo_fsrepo_new((char*)path, repo_config, &fs_repo);
if (retVal == 0)
return 0;
// open the repository and read the config file
retVal = ipfs_repo_fsrepo_open(fs_repo);
if (retVal == 0) {
ipfs_repo_fsrepo_free(fs_repo);
return 0;
}
// get the size of the database
int start_file_size = os_utils_file_size("/tmp/.ipfs/datastore/data.mdb");
@ -198,3 +185,63 @@ int test_merkledag_add_data() {
return 1;
}
/**
* Should save links
*/
int test_merkledag_add_node_with_links() {
int retVal = 0;
struct Link* link = NULL;
struct Node* node1 = NULL;
struct FSRepo* fs_repo = createAndOpenRepo("/tmp/.ipfs");
if (fs_repo == NULL) {
printf("Unable to create repo\n");
return 0;
}
// make link
link = Create_Link("", "abc123");
node1 = N_Create_From_Link(link);
retVal = ipfs_merkledag_add(node1, fs_repo);
if (retVal == 0) {
ipfs_repo_fsrepo_free(fs_repo);
Node_Delete(node1);
printf("Unable to add node\n");
return 0;
}
// now look for it
struct Node* node2 = NULL;
retVal = ipfs_merkledag_get(node1->cached, &node2, fs_repo);
if (retVal == 0) {
ipfs_repo_fsrepo_free(fs_repo);
Node_Delete(node1);
return 0;
}
if (node2->link_amount != node1->link_amount) {
ipfs_repo_fsrepo_free(fs_repo);
Node_Delete(node1);
Node_Delete(node2);
printf("Link number do not match. Should be %d and are %d\n", node1->link_amount, node2->link_amount);
return 0;
}
// make sure hashes match
for(int i = 0; i < node1->links[0]->Lcid->hash_length; i++) {
if(node1->links[0]->Lcid->hash[i] != node2->links[0]->Lcid->hash[i]) {
ipfs_repo_fsrepo_free(fs_repo);
Node_Delete(node1);
Node_Delete(node2);
printf("Hashes do not match\n");
return 0;
}
}
Node_Delete(node1);
Node_Delete(node2);
ipfs_repo_fsrepo_free(fs_repo);
return 1;
}