-
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
Refine API of the testing framework #2783
Conversation
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## master #2783 +/- ##
==========================================
+ Coverage 79.26% 79.37% +0.10%
==========================================
Files 333 333
Lines 78769 78696 -73
==========================================
+ Hits 62440 62468 +28
+ Misses 14025 13924 -101
Partials 2304 2304
Flags with carried forward coverage won't be shown. Click here to find out more.
☔ View full report in Codecov by Sentry. |
Great work @m-Peter! I haven't looked into the code in detail yet, but I have one suggestion on the API: Can we completely hide the "blockchain" from the users? import Test
// Every function call to `Test.xyz` will use the singleton blockchain instance
pub let account = Test.getAccount(0x0000000000000011)
pub fun setup() {
let err = Test.deployContract( // e.g: Will deploy to the singleton blockchain instance
name: "FooContract",
path: "../contracts/FooContract.cdc",
arguments: []
)
Test.expect(err, Test.beNil())
}
pub fun testGetIntegerTrait() {
let script = Test.readFile("../scripts/get_integer_traits.cdc")
let result = Test.executeScript(script, [])
...
}
pub fun testAddSpecialNumber() {
...
let tx = Test.Transaction(...)
let result = Test.executeTransaction(tx)
...
} |
@SupunS I can try to see how much effort that would require 👍 . In fact, I first went for this approach, since you had already mentioned this API, but fell into some blockers. The pub contract Test {
pub let backend: AnyStruct{BlockchainBackend}
init(backend: AnyStruct{BlockchainBackend}) {
self.backend = backend
}
pub fun addTransaction(_ tx: Transaction) {
self.backend.addTransaction(tx)
}
} But that resulted in checking errors, so I went for the alternative 😇 To be honest, to me it feels more intuitive to have the Test.deployContract(...)
Test.getAccount(...)
Test.executeScript(...)
Test.executeTransaction(...) vs blockchain.deployContract(...)
blockchain.getAccount(...)
blockchain.executeScript(...)
blockchain.executeTransaction(...) Not a very strong opinion though 😅 |
Yeah, but then again, since there will be one blockchain anyway, having to work with a Also, with this, it might be possible to replace |
@SupunS I have removed entirely the |
533e628
to
0f9ba5d
Compare
Nice! I'll have a look 👍 Thank you for making all these changes 🙌 |
23dbe7c
to
09498dd
Compare
I have also removed the |
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! Just wondering about the CompositeType
member resolution/initialization changes
These changes will allow testing providers to unify unit & integration tests.
For contracts that contain both a .cdc source file, with Cadence code, and with some functions being implemented natively, the GetMembers() does not return the natively implemented members.
2e67f57
to
20a58ec
Compare
I have also renamed the |
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.
Looks good!
Description
Test.newEmulatorBlockchain()
method, sinceEmulatorBackend
is now a singletonTest.useConfiguration()
method, since the mappings will be provided byflow.json
config fileTest.getAccount(_ address: Address): Test.Account
method, to retrieve an account from theEmulatorBackend
Test.deployContract
to require onlyname
/path
&arguments
These changes will allow testing providers to unify unit & integration tests.
An example of unit testing:
An example of integration testing:
All contracts are to be deployed on a blockchain.
In unit tests, developers can import the deployed contracts and directly access fields and call methods.
In integration tests, developers can still import the deployed contracts, to make use of the defined nested types, and interact with the contract by re-using their scripts & transactions.
To make this possible, developers will need to make use of
flow.json
config file, e.g:The account where the contracts should be deployed, is set above.
master
branchFiles changed
in the Github PR explorer