-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add json schema for test output #7813
Comments
It would be nice to also have an explanation for each of the attributes to understand what they mean. I'm looking at some JSON logs and without having a full understanding of the whole source code (which is difficult for people not familiar with the source code and rust) is pretty difficult if not impossible. As a quick example, the JSON structure inside 'kind' changes completely between the "standard" test and the "fuzz" test, which IMHO is not good {
"kind": {
"Standard": 257
},
} {
"kind": {
"Fuzz": {
"first_case": {
"calldata": "...",
"gas": 21607,
"stipend": 21204
},
"runs": 257,
"mean_gas": 403,
"median_gas": 403
}
},
} |
I have this documented here already Gas Snapshot Format
FooTest:testSetFoo() (gas: 64071)
BarTest:testFuzzCurrentBar(uint256) (runs: 256, μ: 408, ~: 423) JSON-Schema definitionEach test object represents a test function and has the following properties:
The This JSON Schema describes the structure of the .gas-snapshot file format used by Forge. It allows for both regular tests with a single gas value and fuzz tests with multiple runs and statistical data (average and median gas used). gas-snapshotThe schema defines an object with a single property tests, which is an array of test objects. {
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"tests": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string",
"description": "The name of the test function"
},
"gas": {
"type": "integer",
"description": "The gas used by the test function"
},
"runs": {
"type": "integer",
"description": "The number of runs for the test function (only applicable for fuzz tests)"
},
"avg": {
"type": "integer",
"description": "The average gas used across all runs (only applicable for fuzz tests)"
},
"median": {
"type": "integer",
"description": "The median gas used across all runs (only applicable for fuzz tests)"
}
},
"required": [
"name"
],
"oneOf": [
{
"required": [
"gas"
]
},
{
"required": [
"runs",
"avg",
"median"
]
}
]
}
}
},
"required": [
"tests"
]
} |
I am applying to this issue via OnlyDust platform. My background and how it can be leveragedI am an open-source enthusiast with a strong proficiency in Rust, JavaScript, TypeScript, and Solidity. Given my experience and skills, I believe I am well-suited to work on the task of generating a JSON schema for the forge test --json output. My approach would involve thoroughly analyzing the current JSON structure, defining an accurate and comprehensive schema using tools like Schemars, and integrating this schema generation seamlessly into the forge codebase. I would also ensure that the schema remains in sync with future updates and provide thorough documentation and tests to support the implementation. This work will enhance the tool's usability, especially for those looking to integrate it with other systems or generate TypeScript bindings. I'm confident that my background in these technologies will allow me to deliver a solution that meets the project's needs. How I plan on tackling this issueTo tackle the task of generating a JSON schema for the forge test --json output, I would proceed as follows: Understand the Current Output Define the JSON Schema Integrate Schema Generation Test the Schema Document and Submit |
I am applying to this issue via OnlyDust platform. My background and how it can be leveragedEngineering student just a web3kid How I plan on tackling this issueuse schemars::JsonSchema; #[derive(Serialize, Deserialize, JsonSchema)] |
Can I take this from here? |
Let me handle this issue! |
Can I take this from here? |
Sure, feel free to open a PR |
Component
Forge
Describe the feature you would like
the test --json output can be useful for better integration.
foundry/crates/forge/src/result.rs
Lines 193 to 206 in f0d9eec
We currently don't have a proper spec for this making it hard to generate TS bindings for example.
This could be useful here: https://docs.rs/schemars/latest/schemars/
TODO
generate json schema for test --json ouput
Additional context
No response
The text was updated successfully, but these errors were encountered: