name | Status |
---|---|
Nethermind Deployer Detection Bot | Ready to deploy |
Rare Scam Tokens Forta Detection Bot | In process |
aladeenb / forta-bots Goto Github PK
View Code? Open in Web Editor NEWLicense: MIT License
License: MIT License
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.
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
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.