White-Whale-Defi-Platform / white-whale-core

Core contracts for White Whale, The Interchain Liquidity Protocol for the Cosmos.
https://whitewhale.money
MIT License
36 stars 23 forks source link

Generate schema through workspace build script #303

Closed kaimen-sano closed 5 months ago

kaimen-sano commented 5 months ago

Description and Motivation

We currently generate schemas by having a binary schema.rs on each contract which will use the cosmwasm_schema API to write a schema.

While this works, it requires us to maintain the binary for each contract. This is tedious (extra files per contract, including a .cargo alias definition), and also requires us to correctly use the cosmwasm_schema per contract. Additionally, we were getting Cargo binary name collisions:

The targets should have unique names.
Consider changing their names to be unique or compiling them separately.
This may become a hard error in the future; see <https://github.com/rust-lang/cargo/issues/6313>.

This PR aims to standardize the process of creating a schema for a contract by moving the logic to a new xtask: generate_schemas. This task will generate all the schema files for the entire workspace at once.

This is similar work to the previous just schemas (which was broken), however we now get the benefit of being able to remove the binary from each contract. This could potentially speed up compile times.

This PR also moves the schema PR workflow check to a new workflow file, and aims to add a comment to the PR if the schemas failed.


Checklist:

codecov[bot] commented 5 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 88.56%. Comparing base (1aec306) to head (3be1380). Report is 1 commits behind head on release/v2_contracts.

:exclamation: Current head 3be1380 differs from pull request most recent head 755c4bd. Consider uploading reports for the commit 755c4bd to get more accurate results

Additional details and impacted files ```diff @@ Coverage Diff @@ ## release/v2_contracts #303 +/- ## ======================================================== + Coverage 88.50% 88.56% +0.06% ======================================================== Files 252 243 -9 Lines 23602 23586 -16 ======================================================== + Hits 20888 20889 +1 + Misses 2714 2697 -17 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

kaimen-sano commented 5 months ago

Elected to exclude xtask from Tarpaulin here. It is not a critical piece of software for us to test.

github-actions[bot] commented 5 months ago

Schema generation failed. Please run just schemas locally and upload the generated schemas.

github-actions[bot] commented 5 months ago

Schema generation had missing jobs: ``${diffSchemas}```` Please runjust schemas` locally and upload the generated schemas.

github-actions[bot] commented 5 months ago

Schema generation had missing jobs:

contracts/liquidity_hub/fee_collector/schema/raw/query.json

Please run just schemas locally and upload the generated schemas.

github-actions[bot] commented 5 months ago

Schema generation had missing jobs:

Please run just schemas locally and upload the generated schemas.

github-actions[bot] commented 5 months ago

Schema generation had missing jobs:

contracts/liquidity_hub/pool-manager/schema/raw/execute.json
contracts/liquidity_hub/pool-manager/schema/pool-manager.json

Please run just schemas locally and upload the generated schemas.

kaimen-sano commented 5 months ago

Good to review, finally :)

kaimen-sano commented 5 months ago

LGTM great work never heard of xtask until now but looks like its even used by Cargo 🤯

It was a great find to run scripts for the workspace that need access to our Rust interfaces. I was also not aware of how widespread the pattern is in the Rust ecosystem, but it certainly looks like a nice complement to just for our case.

kerber0x commented 5 months ago

:shipit: @kaimen-sano