-
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
Initialize stdlib
values of Test
contract lazily
#2403
Initialize stdlib
values of Test
contract lazily
#2403
Conversation
Test
contract lazily
Codecov Report
@@ Coverage Diff @@
## master #2403 +/- ##
==========================================
- Coverage 78.29% 78.29% -0.01%
==========================================
Files 325 327 +2
Lines 72465 72697 +232
==========================================
+ Hits 56738 56919 +181
- Misses 13644 13687 +43
- Partials 2083 2091 +8
Flags with carried forward coverage won't be shown. Click here to find out more.
|
Test
contract lazilystdlib
values of Test
contract lazily
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Thank you for adding this!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great start 👏
why this is in cadence ? shouldn't be in https://github.com/onflow/cadence-tools/test ? |
To avoid circular dependency. Because the test module depends on cadence already (at go level). Moving this to test would cause cadence to also depends on the test module, creating the cycle. |
can't we simple expose |
@bluesign The current idea is that Cadence itself exposes a test framework in its standard library. That is similar to e.g. Rust having testing support in the language and the cargo test runner tool. That does not mean that it has to stay that way of course, we could consider refactoring the test framework out of Cadence. What do you think would be the advantages of that? |
Cadence needs to know about the |
I don't know if any advantage tbh; but I always thought, host can expose stuff ( like flow-go was exposing some account freezing before ) to Cadence. As we don't use test on mainnet/testnet, I thought that would be the way. Even I was thinking if it is possible to bridge js-cadence like this. ( like webassembly bridging js - go etc ) |
@bluesign Sounds good. Maybe open a new issue for that, as this PR only really is an optimization of the existing code |
e646efb
to
9be5866
Compare
@turbolent If this is in good shape, could we get it merged? I want to open another PR (for onflow/cadence-tools#108), however, I have branched-off of this one, to avoid conflicts 🙏 |
@m-Peter Nice work, I'll review tomorrow |
9be5866
to
8acaeba
Compare
8acaeba
to
831b4b9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Ardit for continuing to improve this!
It would be nice if this could be refactored more to avoid all the global variables.
In the current version, the main initialization function, initTest
, triggers the initialization of all those globals in an imperative way, which is then often followed by a use of the global for further initialization, and later to also construct a value. Between the globals there are many inter-dependencies.
For example, initEmulatorBackendType
initializes the global emulatorBackendType
, but it actually depends on the function globals, i.e. initEmulatorBackendFunctions
having being called and e.g. the global emulatorBackendExecuteScriptFunctionType
having been initialized. Finally, emulatorBackendType
exists because it is needed in newEmulatorBackend
.
Instead, maybe the initialization could be done in a more "functional" way without side-effects / global initialization. This could be done e.g. by introducing a type TestEmulatorBackendType
, which holds the composite type and all function types. The type is then returned from initEmulatorBackendType
, instead of it mutating a global. initTest
could then be the place where the whole group is initialized.
I pushed a refactor in 25279e6 illustrating the idea.
I'll try to refactor the remainder, mainly, the Test
contract code itself.
…le, avoid global variables
Thanks for the heavy lifting 🙌 💯 |
@m-Peter No, that should be all now. We'll need to update some downstream dependencies, but the required changes are very small. @dsainati1 @SupunS Could you please review? |
@turbolent I can update the downstream dependencies, as soon as there's a release. I have to update the cadence-tools/test repo, because I introduced another breaking change, regarding the runtime.Config. Ping me any time, to do so 🙏 |
Closes #2215
Description
Lazily instantiated
stdlib
values related toTest
contract.Since we have an accepted proposal (onflow/developer-grants#148), regarding the Cadence testing framework, we thought it would be a good first issue to tackle, in order to get acquainted with the codebase 🙏
master
branchFiles changed
in the Github PR explorer