Skip to content

Contributor Modifications Guide

0xdavinchee edited this page Jun 22, 2023 · 7 revisions

Writing Tests

Ethereum Contracts

Please refer to this section in the README on our conventions for writing tests in Foundry.

Adding/Modifying Events in Contracts

Ethereum Contracts

  • When we make upgrades/updates to our contracts, we may choose to add a new event, update the name of the event or the name of one of the fields.

Subgraph

  • If we are interested in indexing these new events and returning this data, we need to add do the following to add this information to the subgraph:
  1. Add the new entity to the schema.graphql file in packages/subgraph.
  2. Create a mapping handler function in the appropriate folder (src/mappings/[contract]).
  3. Add the new entity under dataSources.mapping.entities to the appropriate dataSource in dataSources in both subgraph.template.yaml and test-subgraph.template.yaml.
  4. Add the new/modified event under dataSources.mapping.eventHandlers and its handler (name of handler function). Look at the subgraph.template.yaml as an example.

Note: if you want to run tests/subgraph locally after an event has been modified (contract ABI changes, so you need to rebuild contracts), look at tasks/testenv-ctl.sh for further guidance on the necessary steps required to do so.

SDK-Core

  1. Now, we need to update the sdk-core/src/subgraph/schema.graphql file.
  • IF the feature-goerli endpoint has the desired schema deployed:
    • run yarn generate-graphql-schema inside the packages/sdk-core directory
  • IF you only have this schema locally:
    • Spin up and deploy a local instance of the subgraph and use the local endpoint with this command: npx get-graphql-schema http://localhost:8000/subgraphs/name/superfluid-test > src/subgraph/schema.graphql in the packages/sdk-core directory.
  1. Next, we need to add/or modify an interface for the new events into sdk-core/src/events.ts OR add/modify an entity in the specific entity file. We add the new event under AccountEvents or OtherEvents depending on whether the event is specifically related to an account or not.
  2. In addition, there is another file in src/subgraph/events: events.graphql which you also need to change.
  3. After this, run yarn generate:graphql-types to regenerate the type files for the queries.
  4. Then, we need to add the event to the query in sdk-core/src/subgraph/queries/getAllEvents.graphql. This will ensure that the getAllEvents.ts file gets generated properly. We also need to add a query for the new event, add this query to the larger events query and a query fragment in: sdk-core/src/subgraph/events/events.graphql.
  5. Lastly, we must add a case for our new event in sdk-core/src/mapGetAllEventsQueryEvents.ts (for event entities, for HOL entities, each entity will have its own file and mapping function). We specify the name of the entity for the case: case "EntityName": and return a typeGuard object passing in the desired event as the generic and we map each of the properties accordingly.
Clone this wiki locally