Fix tests by passing args to dynamic function test

Function purchaseServer would throw with null arguments
This commit is contained in:
Martin Fournier 2021-12-20 17:37:56 -05:00
parent 009bae5870
commit 99f1e67224

@ -33,8 +33,8 @@ describe("Netscript Dynamic RAM Calculation/Generation Tests", function () {
} }
// Runs a Netscript function and properly catches it if it returns promise // Runs a Netscript function and properly catches it if it returns promise
function runPotentiallyAsyncFunction(fn) { function runPotentiallyAsyncFunction(fn, ...args) {
const res = fn(); const res = fn(...args);
if (res instanceof Promise) { if (res instanceof Promise) {
res.catch(() => undefined); res.catch(() => undefined);
} }
@ -48,7 +48,7 @@ describe("Netscript Dynamic RAM Calculation/Generation Tests", function () {
* @param {string[]} fnDesc - describes the name of the function being tested, * @param {string[]} fnDesc - describes the name of the function being tested,
* including the namespace(s). e.g. ["gang", "getMemberNames"] * including the namespace(s). e.g. ["gang", "getMemberNames"]
*/ */
async function testNonzeroDynamicRamCost(fnDesc) { async function testNonzeroDynamicRamCost(fnDesc, ...args) {
if (!Array.isArray(fnDesc)) { if (!Array.isArray(fnDesc)) {
throw new Error("Non-array passed to testNonzeroDynamicRamCost()"); throw new Error("Non-array passed to testNonzeroDynamicRamCost()");
} }
@ -61,7 +61,7 @@ describe("Netscript Dynamic RAM Calculation/Generation Tests", function () {
// We don't need a real WorkerScript // We don't need a real WorkerScript
const workerScript = { const workerScript = {
args: [], args: args,
code: code, code: code,
dynamicLoadedFns: {}, dynamicLoadedFns: {},
dynamicRamUsage: RamCostConstants.ScriptBaseRamCost, dynamicRamUsage: RamCostConstants.ScriptBaseRamCost,
@ -91,9 +91,9 @@ describe("Netscript Dynamic RAM Calculation/Generation Tests", function () {
// actually initialized. Call the fn multiple times to test that repeated calls // actually initialized. Call the fn multiple times to test that repeated calls
// do not incur extra RAM costs. // do not incur extra RAM costs.
try { try {
runPotentiallyAsyncFunction(curr); runPotentiallyAsyncFunction(curr, ...args);
runPotentiallyAsyncFunction(curr); runPotentiallyAsyncFunction(curr, ...args);
runPotentiallyAsyncFunction(curr); runPotentiallyAsyncFunction(curr, ...args);
} catch (e) {} } catch (e) {}
} else { } else {
throw new Error(`Invalid function specified: [${fnDesc}]`); throw new Error(`Invalid function specified: [${fnDesc}]`);
@ -434,7 +434,7 @@ describe("Netscript Dynamic RAM Calculation/Generation Tests", function () {
it("purchaseServer()", async function () { it("purchaseServer()", async function () {
const f = ["purchaseServer"]; const f = ["purchaseServer"];
await testNonzeroDynamicRamCost(f); await testNonzeroDynamicRamCost(f, "abc", '64');
}); });
it("deleteServer()", async function () { it("deleteServer()", async function () {