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

Add functions on testing framework's blockchain to create/load snapshots #2763

Merged
merged 2 commits into from
Sep 6, 2023

Conversation

m-Peter
Copy link
Contributor

@m-Peter m-Peter commented Sep 4, 2023

Description

Allow developers to create snapshots of the blockchain's current ledge state, and load them on demand at any time. For example:

import Test
import BlockchainHelpers

pub let blockchain = Test.newEmulatorBlockchain()
pub let helpers = BlockchainHelpers(blockchain: blockchain)

pub fun test() {
    let admin = blockchain.createAccount()
    blockchain.createSnapshot("adminCreated")

    helpers.mintFlow(to: admin, amount: 1000.0)
    blockchain.createSnapshot("adminFunded")

    var balance = helpers.getFlowBalance(for: admin)
    Test.assertEqual(1000.0, balance)

    blockchain.loadSnapshot("adminCreated")
            
    balance = helpers.getFlowBalance(for: admin)
    Test.assertEqual(0.0, balance)

    blockchain.loadSnapshot("adminFunded")
            
    balance = helpers.getFlowBalance(for: admin)
    Test.assertEqual(1000.0, balance)
}

  • Targeted PR against master branch
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work
  • Code follows the standards mentioned here
  • Updated relevant documentation
  • Re-reviewed Files changed in the Github PR explorer
  • Added appropriate labels

@m-Peter m-Peter changed the title Add function for testing framework's blockchain to create/load snapshots Add functions on testing framework's blockchain to create/load snapshots Sep 4, 2023
@codecov
Copy link

codecov bot commented Sep 4, 2023

Codecov Report

Patch coverage: 92.00% and project coverage change: +0.03% 🎉

Comparison is base (5254952) 79.18% compared to head (0c10225) 79.21%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2763      +/-   ##
==========================================
+ Coverage   79.18%   79.21%   +0.03%     
==========================================
  Files         333      333              
  Lines       78614    78664      +50     
==========================================
+ Hits        62248    62313      +65     
+ Misses      14063    14044      -19     
- Partials     2303     2307       +4     
Flag Coverage Δ
unittests 79.21% <92.00%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Changed Coverage Δ
runtime/stdlib/test_emulatorbackend.go 58.27% <92.00%> (+3.33%) ⬆️

... and 1 file with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@m-Peter
Copy link
Contributor Author

m-Peter commented Sep 4, 2023

Credits to @bluesign for his original idea 👏

@SupunS SupunS self-assigned this Sep 5, 2023
@SupunS SupunS added the Feature label Sep 5, 2023
runtime/stdlib/contracts/test.cdc Outdated Show resolved Hide resolved
Copy link
Member

@turbolent turbolent left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome!

runtime/stdlib/contracts/test.cdc Outdated Show resolved Hide resolved
@bluesign
Copy link
Contributor

bluesign commented Sep 6, 2023

this is awesome!

Copy link
Member

@turbolent turbolent left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@turbolent turbolent merged commit 75f6616 into onflow:master Sep 6, 2023
11 of 14 checks passed
@m-Peter m-Peter deleted the add-blockchain-snapshots branch September 6, 2023 16:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants