console.assert(rawldk.CResult_boolLightningErrorZ_is_ok(result));
console.assert(rawldk.CResult_boolLightningErrorZ_get_ok(result));
rawldk.CResult_boolLightningErrorZ_free(result);
- console.assert(rawldk.CResult_boolLightningErrorZ_ok(false) == result); // malloc doesn't need to guarantee this, but currently does
- console.assert(rawldk.CResult_boolLightningErrorZ_is_ok(result));
- console.assert(!rawldk.CResult_boolLightningErrorZ_get_ok(result));
- rawldk.CResult_boolLightningErrorZ_free(result);
+ const second_res = rawldk.CResult_boolLightningErrorZ_ok(false);
+ console.assert(rawldk.CResult_boolLightningErrorZ_is_ok(second_res));
+ console.assert(!rawldk.CResult_boolLightningErrorZ_get_ok(second_res));
+ rawldk.CResult_boolLightningErrorZ_free(second_res);
- /*var pk_arr = [];
- for (var i = 0; i < 33; i++) { pk_arr[i] = 42; }
- const pk_bytes = encodeUint8Array(pk_arr);
- const pk_res = wasm.TS_CResult_PublicKeyErrorZ_ok(pk_bytes);
- console.assert(wasm.TS_CResult_PublicKeyErrorZ_is_ok(pk_res));
- const pk_res_bytes = wasm.TS_LDKCResult_PublicKeyErrorZ_get_ok(pk_res);
- wasm.TS_CResult_PublicKeyErrorZ_free(pk_res);*/
return true;
});
console.log("test results: " + results);
const result = results.every((v) => { return v === true });
console.log("all tests passed: " + result);
- return result;
+ if (result !== true) { return result; }
+
+ const allocs_finished = new Promise((resolve, reject) => {
+ var loop_count = 0;
+ const interval_id = setInterval(() => {
+ const alloc_count = rawldk.getRemainingAllocationCount();
+ if (loop_count % 20 == 0)
+ console.log("Remaining LDK allocation count: " + alloc_count);
+ // Note that there are currently 9 leaks in the above tests. At least some are known - look for XXX in bindings.c
+ if (alloc_count <= 10) { resolve(true); clearInterval(interval_id); }
+ loop_count += 1;
+ if (loop_count > 30*2) { resolve(false); clearInterval(interval_id); rawldk.debugPrintRemainingAllocs(); }
+ }, 500);
+ });
+ return allocs_finished;
}