GithubHelp home page GithubHelp logo

forta-bots's Introduction

Forta Bots

List of bots

name Status
Nethermind Deployer Detection Bot Ready to deploy
Rare Scam Tokens Forta Detection Bot In process

forta-bots's People

Contributors

aladeenb avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

forta-bots's Issues

handleTransaction() returning empty array when bot is created

Description:

I am trying to test the case when a bot is created. The function is supposed to return a Finding object if a bot is created, but it is returning an empty array instead.

Here is the code for the test:

describe("handleTransaction", () => {
    it("returns a finding if a bot is created", async () => {
      const mockCreateBot = {
        args: {
          agentId: "0001",
          owner: "0xabc",
          metadata: "metadata",
          chainIds: "[001, 002, 003, 004]",
        },
      };
      mockTxEvent.filterFunction = jest.fn().mockReturnValue([mockCreateBot]);

      const findings = await handleTransaction(mockTxEvent);

      expect(findings).toStrictEqual([
        Finding.fromObject({
          name: "Nethermind Bot",
          description: `Bot created from (${NETHERMIND_ADDRESS}).`,
          alertId: "NETHERMIND-1",
          type: FindingType.Info,
          severity: FindingSeverity.Info,
          metadata: {
            from: mockCreateBot.args.owner,
          },
        }),
      ]);
      expect(mockTxEvent.filterFunction).toHaveBeenCalledTimes(2);
      expect(mockTxEvent.filterFunction).toHaveBeenCalledWith(CREATE_BOT_FUNCTION, DEPLOY_UPDATE_CONTRACT_ADDRESS);
    });
  });

I am expecting the test to pass, but it is failing with the error message:

    - Expected  - 15
    + Received  +  1

It seems that handleTransaction() function is not correctly handling the returned value from mockTxEvent.filterFunction.

I would appreciate any help in resolving this issue. Please let me know if you need any more information or context.

Steps to Reproduce:

  1. Run the test case
  2. See the test case is failing

Expected outcome:

npx jest
 PASS  src/agent.spec.ts
  Bot created
    handleTransaction
      √ return empty findings if there are no bots created (7 ms)
      √ returns a finding if a bot is created (10 ms)

Test Suites: 1 passed, 1 total
Tests:       2 passed, 2 total

Actual outcome:

npx jest
 FAIL  src/agent.spec.ts (5.279 s)
  Bot created
    handleTransaction
      √ return empty findings if there are no bots created (7 ms)
      × returns a finding if a bot is created (10 ms)

  ● Bot created › handleTransaction › returns a finding if a bot is created

    expect(received).toStrictEqual(expected) // deep equality

    - Expected  - 15
    + Received  +  1

    - Array [
    -   Finding {
    -     "addresses": Array [],
    -     "alertId": "NETHERMIND-1",
    -     "description": "Bot created from (0x88dC3a2284FA62e0027d6D6B1fCfDd2141a143b8).",
    -     "labels": Array [],
    -     "metadata": Object {
    -       "from": "0xabc",
    -     },
    -     "name": "Nethermind Bot",
    -     "protocol": "ethereum",
    -     "severity": 1,
    -     "type": 4,
    -   },
    - ]
    + Array []

      47 |       const findings = await handleTransaction(mockTxEvent);
      48 |
    > 49 |       expect(findings).toStrictEqual([
         |                        ^
      50 |         Finding.fromObject({
      51 |           name: "Nethermind Bot",
      52 |           description: `Bot created from (${NETHERMIND_ADDRESS}).`,

      at src/agent.spec.ts:49:24
      at step (src/agent.spec.ts:56:23)
      at Object.next (src/agent.spec.ts:37:53)
      at fulfilled (src/agent.spec.ts:28:58)

Test Suites: 1 failed, 1 total
Tests:       1 failed, 1 passed, 2 total

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.