mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-16 06:18:42 +02:00
API: Remove RAM cost of hacknet namespace and set RAM cost of each hacknet API (#2502)
* API: Remove RAM cost of hacknet namespace and set RAM cost of each hacknet API * Fix Jest tests * Update based on feedback
This commit is contained in:
@@ -140,13 +140,8 @@ describe("Netscript RAM Calculation/Generation Tests", function () {
|
||||
const expectedRam = grabCost(ramLayer[key]);
|
||||
it(`${fnName}()`, () => combinedRamCheck(fn, newPath, expectedRam, extraLayerCost));
|
||||
}
|
||||
//A layer should be the only other option. Hacknet is currently the only layer with a layer cost.
|
||||
else if (typeof val === "object" && key !== "enums") {
|
||||
//hacknet is currently the only layer with a layer cost.
|
||||
const layerCost = key === "hacknet" ? 4 : 0;
|
||||
testLayer(val as InternalAPI<unknown>, externalLayer[key], ramLayer[key], newPath, layerCost);
|
||||
}
|
||||
// Other things like args, enums, etc. have no cost
|
||||
// A layer should be the only other option, but we don't have any of those with a cost.
|
||||
// Other things like args, enums, etc. have no cost.
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ const BaseCost = 1.6;
|
||||
const HackCost = 0.1;
|
||||
const GrowCost = 0.15;
|
||||
const SleeveGetTaskCost = 4;
|
||||
const HacknetCost = 4;
|
||||
const Hacknet = 0.5;
|
||||
const MaxCost = 1024;
|
||||
|
||||
const filename = "testfile.js" as ScriptFilePath;
|
||||
@@ -148,18 +148,6 @@ describe("Parsing NetScript code to work out static RAM costs", function () {
|
||||
expectCost(calculated, 0);
|
||||
});
|
||||
|
||||
it("Function 'purchaseNode' that can be confused with Hacknet.purchaseNode", function () {
|
||||
const code = `
|
||||
export async function main(ns) {
|
||||
purchaseNode();
|
||||
}
|
||||
function purchaseNode() { return 0; }
|
||||
`;
|
||||
const calculated = calculateRamUsage(code, filename, server, new Map()).cost;
|
||||
// Works at present, because the parser checks the namespace only, not the function name
|
||||
expectCost(calculated, 0);
|
||||
});
|
||||
|
||||
// TODO: once we fix static parsing this should pass
|
||||
it.skip("Function 'getTask' that can be confused with Sleeve.getTask", function () {
|
||||
const code = `
|
||||
@@ -174,14 +162,14 @@ describe("Parsing NetScript code to work out static RAM costs", function () {
|
||||
});
|
||||
|
||||
describe("Single files with non-core NS functions", function () {
|
||||
it("Hacknet NS function with a cost from namespace", function () {
|
||||
it("Hacknet NS functions with an individual cost", function () {
|
||||
const code = `
|
||||
export async function main(ns) {
|
||||
ns.hacknet.purchaseNode(0);
|
||||
}
|
||||
`;
|
||||
const calculated = calculateRamUsage(code, filename, server, new Map()).cost;
|
||||
expectCost(calculated, HacknetCost);
|
||||
expectCost(calculated, Hacknet);
|
||||
});
|
||||
|
||||
it("Sleeve functions with an individual cost", function () {
|
||||
|
||||
Reference in New Issue
Block a user