From 99f1e67224aff0ebeb6a248c829e06f1df4cd9a1 Mon Sep 17 00:00:00 2001 From: Martin Fournier Date: Mon, 20 Dec 2021 17:37:56 -0500 Subject: [PATCH] Fix tests by passing args to dynamic function test Function purchaseServer would throw with null arguments --- test/Netscript/DynamicRamCalculation.test.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/test/Netscript/DynamicRamCalculation.test.js b/test/Netscript/DynamicRamCalculation.test.js index 67b16b74b..803d85327 100644 --- a/test/Netscript/DynamicRamCalculation.test.js +++ b/test/Netscript/DynamicRamCalculation.test.js @@ -33,8 +33,8 @@ describe("Netscript Dynamic RAM Calculation/Generation Tests", function () { } // Runs a Netscript function and properly catches it if it returns promise - function runPotentiallyAsyncFunction(fn) { - const res = fn(); + function runPotentiallyAsyncFunction(fn, ...args) { + const res = fn(...args); if (res instanceof Promise) { 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, * including the namespace(s). e.g. ["gang", "getMemberNames"] */ - async function testNonzeroDynamicRamCost(fnDesc) { + async function testNonzeroDynamicRamCost(fnDesc, ...args) { if (!Array.isArray(fnDesc)) { 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 const workerScript = { - args: [], + args: args, code: code, dynamicLoadedFns: {}, 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 // do not incur extra RAM costs. try { - runPotentiallyAsyncFunction(curr); - runPotentiallyAsyncFunction(curr); - runPotentiallyAsyncFunction(curr); + runPotentiallyAsyncFunction(curr, ...args); + runPotentiallyAsyncFunction(curr, ...args); + runPotentiallyAsyncFunction(curr, ...args); } catch (e) {} } else { throw new Error(`Invalid function specified: [${fnDesc}]`); @@ -434,7 +434,7 @@ describe("Netscript Dynamic RAM Calculation/Generation Tests", function () { it("purchaseServer()", async function () { const f = ["purchaseServer"]; - await testNonzeroDynamicRamCost(f); + await testNonzeroDynamicRamCost(f, "abc", '64'); }); it("deleteServer()", async function () {