-
Notifications
You must be signed in to change notification settings - Fork 137
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
Contracts, scripts and transactions as first-class citizens in testing framework #1993
Comments
Also, I completely understand if what I'm proposing is outside the scope of a testing feature or doesn't make sense due to fundamental constraints in Cadence. I'm now wondering if this requires the Cadence interpreter to know too much about blockchain-specific features (i.e. account storage). 🤔 |
Thank you @psiemens for spending time to test the feature and for the feedback! 🙏 The test-framework provides two approaches for testing:
Integration tests Also, one reason to allow reading the content from file (as string) and mapping the import paths to addresses is to allow devs to use the existing project as-is without changing and use them for testing. Unit testing For now, the features supported for unit testing are very limited due to some implementation complexities.
But definitely, this unit testing can be improved a lot, and these ideas are great! |
Added these to the improvements list: #1889 |
I made a very similar comment before @psiemens, but your implementation looks even better. Maybe even better can be using some helper functions (instead of import syntax), instead of
I think this is good case to make it like as you said, so Cadence can have more access to chain when in normal use too |
I guess I'm proposing a combination of the two approaches you described. I think it should be possible to create accounts, deploy contracts and submit transactions directly inside unit tests. If the unit testing functionality was extended to support the cases I showed above, as a developer, I probably wouldn't use the emulator-backed blockchain inside Cadence. I like that the unit tests allow me to focus on my Cadence code without any overhead. If I wanted to test across different networks, I think I'd prefer to use an external client library through the Access API so that I can make sure my application is properly connecting to the blockchain, signing transactions, properly decoding output, etc.
Yeah, I think it's important to allow developers to test the same transaction and script files that they use in their production app. The approach I outlined also aims to allow a project to keep its files as-is ( |
Yeah, makes sense. The current challenge is to support this within the existing cadence syntax/semantics. This is just a hypothetical example - but it's possible to have such dependencies. Not saying we can't implement this, but just pointing out some edge cases we need to consider when designing the API/semantics. |
Contracts were made first-class in onflow/cadence-tools#210. And thus also scripts can become first class (methods in the same test script) too. |
First off, great work on the Cadence testing framework! It's so awesome to see native testing features.
As I was trying it out, I was a bit surprised to find that contracts, scripts and transactions are still passed as strings inside Cadence. It felt odd to me that I had to put Cadence code in a string inside a Cadence program.
I was then thinking: do we need to have the
Blockchain
construct in order to test Cadence programs?Would it be possible to have a version like this?
Sorry this feedback is so late. I wish I'd had a chance to dig into the testing framework sooner. Even if none of this makes sense for the first version, wanted to share some ideas for future versions.
The text was updated successfully, but these errors were encountered: