CORPORATION: Dramatically lower API RAM costs (#818)

This commit is contained in:
Jesse Clark
2023-09-27 14:38:30 -07:00
committed by GitHub
parent c5e2f65cb0
commit ad6f919d64
2 changed files with 81 additions and 79 deletions

View File

@@ -1,4 +1,5 @@
import { calculateRamUsage } from "../../../src/Script/RamCalculations";
import { RamCosts } from "../../../src/Netscript/RamCostGenerator";
import { Script } from "../../../src/Script/Script";
const BaseCost = 1.6;
@@ -169,27 +170,6 @@ describe("Parsing NetScript code to work out static RAM costs", function () {
expectCost(calculated, HacknetCost);
});
it("One corporation function reaching max ram cap", async function () {
const code = `
export async function main(ns) {
ns.corporation.getCorporation();
}
`;
const calculated = calculateRamUsage(code, new Map()).cost;
expectCost(calculated, MaxCost);
});
it("Two corporation functions at max ram cap", async function () {
const code = `
export async function main(ns) {
ns.corporation.createCorporation("Noodle Bar");
ns.corporation.getCorporation();
}
`;
const calculated = calculateRamUsage(code, new Map()).cost;
expectCost(calculated, MaxCost);
});
it("Sleeve functions with an individual cost", async function () {
const code = `
export async function main(ns) {
@@ -268,6 +248,27 @@ describe("Parsing NetScript code to work out static RAM costs", function () {
expectCost(calculated, HackCost + GrowCost);
});
it("Using every function in the API costs MaxCost", () => {
const lines: string[] = [];
for (const [key, val] of Object.entries(RamCosts)) {
if (typeof val === "object") {
const namespace = key;
for (const name of Object.keys(val)) {
lines.push(`ns.${namespace}.${name}()`);
}
} else {
lines.push(`ns.${key}()`);
}
}
const code = `
export async function main(ns) {
${lines.join("\n")};
}
`;
const calculated = calculateRamUsage(code, new Map()).cost;
expectCost(calculated, MaxCost);
});
// TODO: once we fix static parsing this should pass
it.skip("Importing a function from a library that contains a class", async function () {
const libCode = `