forta-network / forta-bot-examples

Example Forta Detection Bots
MIT License
122 stars 59 forks source link

Github Actions implementations to test the agent examples #21

Open JoseRodrigues443 opened 2 years ago

JoseRodrigues443 commented 2 years ago

Description

Currently, if I or the community wants to add a new example there is no pipeline to guarantee code quality. Also to test if any breaking change on the Forta agent occurred this is a great repo to catch and test that.

So this PR adds a GitHub action that runs a pipeline that builds each agent example and then runs the test battery

An example of this pipeline running can be seen here.

Also, the agent's tests required always a jsonRpcUrl in the forta.config.json config file, making it hard to run the pipeline without any keys or secrets, so was provided a way to test the mocked version without the method getEthersProvider() breaking the build.

Note: The python test currently still require the jsonRpcUrl env variable, because the python fort agent sdk init executes Web3(Web3.HTTPProvider(get_json_rpc_url())) which is not possible to mock for now. In the future I plan to provide a proposal for that fix

Pipeline Image

Type of change

How Has This Been Tested?

All the Javascript and Typescript agents now can run the tests.

Checklist:

JoseRodrigues443 commented 2 years ago

@haseebrabbani thank you for the fast response 💯

However please take into consideration that the projects still have the agent.(py/js/ts) and seen in the image below.

image

The problem is that the agent file executes the method getEthersProvider() that requires the jsonRpcUrl, with that it became impossible to test the pipeline without putting client secrets on the repo.

What I did to fix that was:

this is awesome! really appreciate adding these Github actions 🙌🏼

some points though:

  • renaming the agent entry point (i.e. agent.ts -> agentCore.ts) will prevent the agent from running. the CLI looks for a file called agent.js/ts/py to begin execution
  • the default object exported from the agent.js/ts file must provide the handler(s) using the handleTransaction key
  • you bring up a good point about getJsonRpcUrl preventing tests from running without specifying a forta.config.json. I have been planning to set some sort of ENV variable when running tests that would allow this to work
haseebrabbani commented 2 years ago

hey @JoseRodrigues443 🙂 I just released JS SDK v0.0.39 and Python SDK v0.0.13 which fixes the issue of getJsonRpcUrl throwing an error when running unit tests. I have updated the problem examples (flash-loan-ts, minimum-balance-py, minimum-balance-ts) so you shouldn't need to split out those agent files anymore. Would you mind integrating with the latest changes and trying to run the build? I would love to merge this PR 🙌🏼

JoseRodrigues443 commented 2 years ago

Fixed @haseebrabbani