ubiquibot / comment-incentives

0 stars 10 forks source link

fix: avoid built-ins #34

Closed Keyrxng closed 3 months ago

Keyrxng commented 3 months ago

Resolves #31

QA:

image


(async () => {
  const wordScoreCommentDetails: { [key: string]: Decimal } = {};
  const words = ["hasOwnProperty", "valueOf", "was", "async", "but", "the", "constructor", "isn", "t", "I", "was"];
  const ZERO = new Decimal(0);

  const builtIns = new Set(
    Object.getOwnPropertyNames(Object.prototype).filter((name) => typeof Object.prototype[name] === "function")
  );

  for (const word of words) {
    if (!builtIns.has(word)) {
      let counter = wordScoreCommentDetails[word] || ZERO;
      wordScoreCommentDetails[word] = counter;
    }
  }

  console.log("scoringDetails: ", wordScoreCommentDetails);
})().catch(console.error);
0x4007 commented 3 months ago

You can definitely include my.ts as a jest test. Just name it the same as the filename like *.test.ts

molecula451 commented 3 months ago

the only viable way i'd see testing this in a production like env is keyring setting up basically everything from scratch which would take more time than what the fix should be accomplished

I would merge this a HOT-fix to check the reproduction, it doesn't do then a revert back pretty much won't break any other stuff, i recall originally pavlovcik asked a core dev to have a test env for similar situations but not sure if it was built