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

Enrich test framework interface #2505

Merged
merged 6 commits into from
May 30, 2023

Conversation

m-Peter
Copy link
Contributor

@m-Peter m-Peter commented May 25, 2023

Work towards: onflow/developer-grants#148
Companion PRs:

Description

Adds 5 new methods to the TestFramework interface, and their native implementations.

import Test

pub let blockchain = Test.newEmulatorBlockchain()

// Retrieve all events from the blockchain
pub let events = blockchain.events()

// Retrieve events from the blockchain, filtered by type
let type: Type = CompositeType("A.01cf0e2f2f715450.FooContract.NumberAdded")!
pub let specificEvents = blockchain.eventsOfType(type)

// Retrieve the blockchain's service account. Can be used to sign transactions and send FLOW tokens to other test accounts
// among other things.
pub let serviceAccount = blockchain.serviceAccount()

// Retrieve all the log messages from the blockchain
blockchain.logs()

// Reset the state of the blockchain
blockchain.reset()

  • 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
Copy link
Contributor Author

m-Peter commented May 25, 2023

I would like the team's input, on how to advance with this blocker: https://github.com/onflow/cadence/pull/2505/files#diff-48d2de22767ded1c341778e03aee3e1d3e1006ceeae566f4b0a3a7704c60758dR642-R646. Is there any workaround?

@codecov
Copy link

codecov bot commented May 25, 2023

Codecov Report

Merging #2505 (6b47d46) into master (b24a708) will decrease coverage by 0.03%.
The diff coverage is 39.02%.

❗ Current head 6b47d46 differs from pull request most recent head acc49f3. Consider uploading reports for the commit acc49f3 to get more accurate results

@@            Coverage Diff             @@
##           master    #2505      +/-   ##
==========================================
- Coverage   78.36%   78.33%   -0.03%     
==========================================
  Files         336      327       -9     
  Lines       77123    73393    -3730     
==========================================
- Hits        60436    57492    -2944     
+ Misses      14429    13795     -634     
+ Partials     2258     2106     -152     
Flag Coverage Δ
unittests 78.33% <39.02%> (-0.03%) ⬇️

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

Impacted Files Coverage Δ
runtime/stdlib/test_emulatorbackend.go 32.12% <39.02%> (+2.44%) ⬆️

... and 65 files with indirect coverage changes

@turbolent turbolent self-assigned this May 25, 2023
runtime/stdlib/contracts/test.cdc Outdated Show resolved Hide resolved
runtime/stdlib/test_emulatorbackend.go Outdated Show resolved Hide resolved
runtime/stdlib/contracts/test.cdc Outdated Show resolved Hide resolved
runtime/stdlib/contracts/test.cdc Outdated Show resolved Hide resolved
Copy link
Member

@SupunS SupunS left a comment

Choose a reason for hiding this comment

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

Can you add some tests for the new functions where possible (e.g. serviceAccount())?
Please ignore, just realized we need the blockchain for that. So the test has to be on the tools repo 👍

@m-Peter m-Peter force-pushed the enrich-test-framework-interface branch from 6b47d46 to 7c9d29e Compare May 30, 2023 09:19
@m-Peter m-Peter force-pushed the enrich-test-framework-interface branch from 7c9d29e to acc49f3 Compare May 30, 2023 09:42
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.

Looks good! Would it be possible to add some test cases to cover the added code?

@m-Peter
Copy link
Contributor Author

m-Peter commented May 30, 2023

@turbolent I am not sure how would that be possible here, since we do not have a Blockchain implementation. All these methods are defined on the Blockchain struct:

pub let events = blockchain.events()
pub let specificEvents = blockchain.eventsOfType(type)
pub let serviceAccount = blockchain.serviceAccount()
blockchain.logs()
blockchain.reset()

That's why most of the tests are located in the cadence-tools/test repository.

@m-Peter
Copy link
Contributor Author

m-Peter commented May 30, 2023

For example: https://github.com/onflow/cadence-tools/blob/master/test/test_framework_test.go#L684-L700, test case for the blockchain.createAccount() method.

@turbolent
Copy link
Member

@m-Peter I see. Maybe we can add a mock/test implementation in a follow-up PR? It would be good to not have to rely on some downstream dependencies being the own tests (i.e. performing integration tests), and also have some unit tests up here. Doesn't block this PR, just some general thoughts

@turbolent turbolent requested a review from SupunS May 30, 2023 16:22
@m-Peter
Copy link
Contributor Author

m-Peter commented May 30, 2023

@turbolent You are completely right, I think it will surely increase the developer's confidence for the added code. I will follow up with PR to tackle this 🙏

Copy link
Member

@SupunS SupunS left a comment

Choose a reason for hiding this comment

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

LGTM! left a suggestion for an improvement, which can be a follow-up PR.

runtime/stdlib/contracts/test.cdc Outdated Show resolved Hide resolved
runtime/stdlib/contracts/test.cdc Outdated Show resolved Hide resolved
runtime/stdlib/contracts/test.cdc Outdated Show resolved Hide resolved
runtime/stdlib/test_emulatorbackend.go Outdated Show resolved Hide resolved
runtime/stdlib/test-framework.go 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.

Nice!

@turbolent turbolent merged commit 4cb64ae into onflow:master May 30, 2023
@turbolent turbolent deleted the enrich-test-framework-interface branch May 30, 2023 19:30
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.

3 participants