Skip to content
This repository has been archived by the owner on Dec 26, 2022. It is now read-only.

Commit

Permalink
feat(reg): Add tests for new APIs
Browse files Browse the repository at this point in the history
Add regression tests for `find_transactions` and `find_trnasction_objects`.
  • Loading branch information
howjmay committed Jun 29, 2019
1 parent 89b7385 commit ecb7406
Show file tree
Hide file tree
Showing 11 changed files with 208 additions and 303 deletions.
1 change: 1 addition & 0 deletions accelerator/apis.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ status_t api_find_transactions(const iota_client_service_t* const service, const

*json_result = (char*)malloc((res_buff->length + 1) * sizeof(char));
if (*json_result == NULL) {
ret = SC_CCLIENT_JSON_PARSE;
goto done;
}
snprintf(*json_result, (res_buff->length + 1), "%s", res_buff->data);
Expand Down
48 changes: 7 additions & 41 deletions accelerator/common_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,8 @@ status_t ta_find_transaction_objects(const iota_client_service_t* const service,
get_trytes_req_t* req_get_trytes = get_trytes_req_new();
transaction_array_t* uncached_txn_array = transaction_array_new();
if (req == NULL || res == NULL || req_get_trytes == NULL || uncached_txn_array == NULL) {
return SC_TA_NULL;
ret = SC_TA_NULL;
goto done;
}
char txn_hash[NUM_TRYTES_HASH + 1] = {0};
char cache_value[NUM_TRYTES_SERIALIZED_TRANSACTION + 1] = {0};
Expand All @@ -319,16 +320,16 @@ status_t ta_find_transaction_objects(const iota_client_service_t* const service,

transaction_array_push_back(res, temp);
transaction_free(temp);

// reset the string `cache_value`
cache_value[0] = '\0';
} else {
if (hash243_queue_push(&req_get_trytes->hashes, q_iter->hash) != RC_OK) {
ret = SC_CCLIENT_OOM;
ret = SC_CCLIENT_HASH;
goto done;
}
ret = SC_OK;
}

// reset the string `cache_value`
cache_value[0] = '\0';
}

if (req_get_trytes->hashes != NULL) {
Expand All @@ -338,7 +339,7 @@ status_t ta_find_transaction_objects(const iota_client_service_t* const service,
}
}

// append response of `iota_client_find_transaction_objectss` into cache
// append response of `iota_client_find_transaction_objects` into cache
flex_trit_t* temp_txn_trits = NULL;
TX_OBJS_FOREACH(uncached_txn_array, temp) {
temp_txn_trits = transaction_serialize(temp);
Expand Down Expand Up @@ -369,41 +370,6 @@ status_t ta_find_transaction_objects(const iota_client_service_t* const service,
return ret;
}

status_t ta_find_transactions_obj_by_tag(const iota_client_service_t* const service, const char* const req,
ta_find_transactions_obj_res_t* res) {
if (req == NULL || res == NULL) {
return SC_TA_NULL;
}
status_t ret = SC_OK;

ta_find_transactions_res_t* hash_res = ta_find_transactions_res_new();
if (hash_res == NULL) {
ret = SC_TA_OOM;
goto done;
}

// get transaction hash
ret = ta_find_transactions_by_tag(service, req, hash_res);
if (ret) {
goto done;
}

// get transaction obj
ta_find_transaction_objects_req_t* obj_req = ta_find_transaction_objects_req_new();
if (obj_req == NULL) {
ret = SC_TA_OOM;
goto done;
}
hash243_queue_copy(&obj_req->hashes, hash_res->hashes, hash243_queue_count(hash_res->hashes));

ret = ta_find_transaction_objects(service, obj_req, res->txn_obj);

done:
ta_find_transaction_objects_req_free(&obj_req);
ta_find_transactions_res_free(&hash_res);
return ret;
}

static int idx_sort(void const* lhs, void const* rhs) {
iota_transaction_t* _lhs = (iota_transaction_t*)lhs;
iota_transaction_t* _rhs = (iota_transaction_t*)rhs;
Expand Down
2 changes: 1 addition & 1 deletion accelerator/common_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ status_t ta_find_transactions_obj_by_tag(const iota_client_service_t* const serv
*
* @param[in] service IRI node end point service
* @param[in] req Given transaction hashes
* @param[out] res Result containing transaction object in transaction_array_t.
* @param[out] res Result containing transaction objects in transaction_array_t.
*
* @return
* - SC_OK on success
Expand Down
6 changes: 3 additions & 3 deletions accelerator/server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ int main(int argc, char* argv[]) {
});

/**
* @method {post} /transaction/object Get transaction hash
* @method {post} /transaction/object Find transaction hash
*
* @return {String[]} hash Transaction hash
*/
Expand Down Expand Up @@ -156,9 +156,9 @@ int main(int argc, char* argv[]) {
});

/**
* @method {post} /transaction/object Get transaction object
* @method {post} /transaction/object Find transaction object
*
* @return {String[]} object Info of enitre transaction object
* @return {String[]} object Info of entire transaction object
*/
mux.handle("/transaction/object")
.method(served::method::OPTIONS,
Expand Down
10 changes: 9 additions & 1 deletion serializer/serializer.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,8 @@ status_t iota_transaction_to_json_object(iota_transaction_t const* const txn, cJ
return SC_OK;
}

status_t transaction_array_to_json_array(cJSON* json_root, char* obj_name, const transaction_array_t* const txn_array) {
static status_t transaction_array_to_json_array(cJSON* json_root, char* obj_name,
const transaction_array_t* const txn_array) {
status_t ret = SC_OK;
iota_transaction_t* txn = NULL;
cJSON* txn_obj = NULL;
Expand Down Expand Up @@ -415,7 +416,14 @@ status_t ta_send_trytes_res_serialize(const hash8019_array_p trytes, char** obj)
status_t ta_find_transaction_objects_req_deserialize(const char* const obj,
ta_find_transaction_objects_req_t* const req) {
status_t ret = SC_OK;
if (obj == NULL) {
return SC_SERIALIZER_NULL;
}

cJSON* json_obj = cJSON_Parse(obj);
if (json_obj == NULL) {
return SC_SERIALIZER_JSON_PARSE;
}

if (json_array_to_hash243_queue(json_obj, "hashes", &req->hashes) != RC_OK) {
ret = SC_SERIALIZER_JSON_PARSE;
Expand Down
4 changes: 2 additions & 2 deletions tests/driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ void test_send_trytes(void) {
}

void test_find_transactions(void) {
const char* json = "{\"addresses\":[\"" TX_HASH_1 "\",\"" TX_HASH_2 "\"]}";
const char* json = "{\"addresses\":[\"" TRYTES_81_2 "\",\"" TRYTES_81_3 "\"]}";
char* json_result;
double sum = 0;

Expand All @@ -144,7 +144,7 @@ void test_find_transactions(void) {
}

void test_find_transaction_objects(void) {
const char* json = "{\"hashes\":[\"" TX_HASH_1 "\",\"" TX_HASH_2 "\"]}";
const char* json = "{\"hashes\":[\"" TRYTES_81_2 "\",\"" TRYTES_81_3 "\"]}";
char* json_result;
double sum = 0;

Expand Down
5 changes: 2 additions & 3 deletions tests/iota_api_mock.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,10 @@ retcode_t iota_client_get_transaction_objects(iota_client_service_t const* const
get_trytes_req_t* const tx_hashes, transaction_array_t* out_tx_objs) {
flex_trit_t tx_trits[NUM_TRITS_SERIALIZED_TRANSACTION];
flex_trit_t hash_trits[NUM_TRITS_HASH];
flex_trits_from_trytes(tx_trits, NUM_TRITS_SERIALIZED_TRANSACTION, (const tryte_t*)TRYTES_2673_1,
flex_trits_from_trytes(tx_trits, NUM_TRITS_SERIALIZED_TRANSACTION, (const tryte_t*)TRYTES_2673_2,
NUM_TRYTES_SERIALIZED_TRANSACTION, NUM_TRYTES_SERIALIZED_TRANSACTION);

iota_transaction_t* temp = transaction_deserialize(tx_trits, 0);
transaction_set_hash(temp, hash_trits);
iota_transaction_t* temp = transaction_deserialize(tx_trits, true);
transaction_array_push_back(out_tx_objs, temp);
transaction_free(temp);

Expand Down
5 changes: 4 additions & 1 deletion tests/regression/1_run_TA_API.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ pip install --user -r tests/regression/requirements.txt
python3 tests/regression/runner.py $3 $4 $5
rc=$?

if [[ $rc != 0 ]]; then exit -1 $rc; fi
if [ $rc -ne 0 ]
then
exit -1;
fi

wait $(kill -9 $TA)
trap 'exit 0' SIGTERM
Loading

0 comments on commit ecb7406

Please sign in to comment.