Skip to content
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

Snapshot Testing #260

Merged
merged 18 commits into from
Nov 22, 2023
Merged

Snapshot Testing #260

merged 18 commits into from
Nov 22, 2023

Conversation

Kayanski
Copy link
Contributor

@Kayanski Kayanski commented Oct 18, 2023

This PR aims at introducing snapshot testing for migrations of smart-contracts. This is used to make sure that no breaking change to underlying state is introduced my version modifications :

  • Implementation
  • Snapshot testing documentation

Implementation

We introduce a new snapshot_testing method on the Mock structure. We advise using it at the end of every test that need stabilizing. It dumps the whole contract states of your structures and snapshot tests it.

You can test it by:

  • commenting out the line counter.increment()?; in the packages/cw-orch-mock/tests/conditional.rs file
  • running cargo test

More information about snapshot testing here
https://insta.rs/docs/quickstart/

@Kayanski Kayanski changed the title Added snapshot testing Added migration helpers Oct 18, 2023
@Kayanski Kayanski changed the title Added migration helpers Add migration helpers Oct 18, 2023
@Kayanski Kayanski marked this pull request as draft October 18, 2023 10:11
@Kayanski Kayanski requested a review from CyberHoward October 18, 2023 10:12
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Oct 18, 2023

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: 1a3bc1b
Status:⚡️  Build in progress...

View logs

@codecov
Copy link

codecov bot commented Oct 18, 2023

Codecov Report

Merging #260 (fe97013) into main (f43ae81) will increase coverage by 0.2%.
The diff coverage is 100.0%.

❗ Current head fe97013 differs from pull request most recent head 0d78ac9. Consider uploading reports for the commit 0d78ac9 to get more accurate results

Additional details and impacted files
Files Coverage Δ
cw-orch/src/snapshots.rs 100.0% <100.0%> (ø)

... and 3 files with indirect coverage changes

@AndrewPochapsky
Copy link

This is great! I never knew that I wanted snapshot testing in cosmwasm but it seems like the perfect fit :)

@Kayanski Kayanski marked this pull request as ready for review November 10, 2023 13:40
@Kayanski Kayanski requested a review from CyberHoward November 10, 2023 13:44
@Kayanski Kayanski changed the title Add migration helpers Snapshot Testing Nov 10, 2023
Co-authored-by: CyberHoward <88450409+CyberHoward@users.noreply.github.com>
@Kayanski
Copy link
Contributor Author

Today, the take_storage_snapshot function is a member of the Mock and thus the snapshots have to be named to be recognized from one another.
We could prevent that by changing that function to a macro, which would allow to not input a name for the snaps.
However, that would remove the function from the Mock API and thus would make it harder to find. What do you think ?

@CyberHoward
Copy link
Contributor

CyberHoward commented Nov 10, 2023

It's good that it needs a name but in the code it doesn't? See my comment above.

@Kayanski
Copy link
Contributor Author

It's good that it needs a name but in the code it doesn't? See my comment above.

Oh yeah I have added a name after you suggested it

@CyberHoward
Copy link
Contributor

Status on this? Really want Abstract snapshots for our next release!

@Kayanski Kayanski merged commit 6007f3e into main Nov 22, 2023
@Kayanski Kayanski deleted the update/snapshot-testing branch November 22, 2023 15:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants