Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Enhance Error Messaging for Failed Tests and Incorrect Contract Addresses #430

Open
mshakeg opened this issue Aug 15, 2024 · 1 comment
Open

Comments

@mshakeg
Copy link

mshakeg commented Aug 15, 2024

Description

Currently, when a test case fails or when the contract address in the subgraph.yaml file is incorrect, Matchstick does not provide clear error messages to indicate these issues. This lack of feedback makes it challenging for developers to identify and resolve problems efficiently.

Current Behavior

  • When a test fails, there is no detailed error message or stack trace.
  • When the contract address in subgraph.yaml is incorrect, the test seems to run without errors but doesn't execute as expected.

Proposed Improvement

  1. For failed tests:

    • Provide a clear error message indicating which assertion failed.
    • Show a stack trace to help pinpoint the location of the failure.
    • Display the expected vs. actual values for failed assertions.
  2. For incorrect contract addresses:

    • Implement a validation check for contract addresses in subgraph.yaml
    • Provide a clear error message if the contract address is invalid or not found.
    • Suggest potential fixes or next steps for the developer.
  3. General improvements:

    • Implement verbose logging options to allow developers to see more details about the test execution process.
    • Add a debug mode that provides step-by-step information about entity creation, updates, and event handling.

Benefits

  • Faster debugging and problem-solving for developers.
  • Improved developer experience when working with Matchstick and subgraphs.
  • Reduced time spent on identifying issues related to configuration or test setup.

Example

Current output for a failed test or incorrect contract address:

Igniting tests 🔥
handletransfer
--------------------------------------------------
  Transfer handling:
✨  Done in 3.10s.

Proposed output for a failed test:

Igniting tests 🔥
handletransfer
--------------------------------------------------
  Transfer handling:
    ✘ should handle a transfer and update user balances - FAILED
      AssertionError: Expected balance to be 1000, but got -1000
      at transfer.test.ts:42:7
      
      Stack trace:
      [stack trace information]

      Expected: 1000
      Actual: -1000

✨  Done in 3.15s.
1 test failed.

Proposed output for an incorrect contract address:

Error: Invalid contract address in subgraph.yaml
The contract address "0x1234...5678" specified in subgraph.yaml could not be found or is invalid.
Please check the following:
1. Ensure the address is correct and properly formatted.
2. Verify that the contract exists on the specified network.
3. Check if the start block is set correctly in subgraph.yaml.

For more information, see: [link to documentation]

Additional Context

This improvement would significantly enhance the developer experience when working with Matchstick, making it easier to identify and resolve issues in subgraph development and testing.

@mshakeg
Copy link
Author

mshakeg commented Aug 15, 2024

Another issue that makes it difficult to debug failed tests is that logs in failed test functions aren't shown

import { log } from "matchstick-as/assembly/log"

test('some failed test case', () => {
  log.debug('aliceBalance: {}', [aliceBalance.toString()]) // logs aren't shown for failed test cases
})

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant