tests for bet protocol done; verify notarisation still to test

This commit is contained in:
Scott Sadler
2018-04-05 05:06:22 -03:00
parent 92df780015
commit 561f3e18c1
23 changed files with 1195 additions and 443 deletions

View File

@@ -96,6 +96,7 @@ char* cc_typeName(const CC *cond);
enum CCTypeId cc_typeId(const CC *cond);
unsigned long cc_getCost(const CC *cond);
uint32_t cc_typeMask(const CC *cond);
int cc_isAnon(const CC *cond);
void cc_free(struct CC *cond);
#ifdef __cplusplus

View File

@@ -284,7 +284,7 @@ char *cc_typeName(const CC *cond) {
CC *cc_new(int typeId) {
CC *cond = calloc(1, sizeof(CC));
cond->type = CCTypeRegistry[typeId];
cond->type = typeId == CC_Anon ? &CC_AnonType : CCTypeRegistry[typeId];
return cond;
}

View File

@@ -130,15 +130,19 @@ static CC *thresholdFromFulfillment(const Fulfillment_t *ffill) {
static Fulfillment_t *thresholdToFulfillment(const CC *cond) {
CC *sub;
Fulfillment_t *fulfillment;
// Make a copy of subconditions so we can leave original order alone
CC** subconditions = malloc(cond->size*sizeof(CC*));
memcpy(subconditions, cond->subconditions, cond->size*sizeof(CC*));
qsort(cond->subconditions, cond->size, sizeof(CC*), cmpConditionCost);
qsort(subconditions, cond->size, sizeof(CC*), cmpConditionCost);
ThresholdFulfillment_t *tf = calloc(1, sizeof(ThresholdFulfillment_t));
int needed = cond->threshold;
for (int i=0; i<cond->size; i++) {
sub = cond->subconditions[i];
sub = subconditions[i];
if (needed && (fulfillment = asnFulfillmentNew(sub))) {
asn_set_add(&tf->subfulfillments, fulfillment);
needed--;
@@ -147,6 +151,8 @@ static Fulfillment_t *thresholdToFulfillment(const CC *cond) {
}
}
free(subconditions);
if (needed) {
ASN_STRUCT_FREE(asn_DEF_ThresholdFulfillment, tf);
return NULL;
@@ -200,7 +206,7 @@ static void thresholdToJSON(const CC *cond, cJSON *params) {
static int thresholdIsFulfilled(const CC *cond) {
int nFulfilled = 0;
for (int i=0; i<cond->threshold; i++) {
for (int i=0; i<cond->size; i++) {
if (cc_isFulfilled(cond->subconditions[i])) {
nFulfilled++;
}