[Test Framework] Add support for importing and initializing contracts
Work towards https://github.com/onflow/cadence/issues/331
Description
This PR adds support for importing and initializing contracts in tests.
import FooContract from "./path/to/FooContract"
pub fun testImportingContract() {
var foo = FooContract()
var result = foo.sayHello()
assert(result == "hello from Foo")
}
Note:
This currently doesn't support importing a contract with imports (i.e: more than one level of imports)
- [ ] Targeted PR against
masterbranch - [x] Linked to Github issue with discussion and accepted design OR link to spec that describes this work
- [x] Code follows the standards mentioned here
- [x] Updated relevant documentation
- [x] Re-reviewed
Files changedin the Github PR explorer - [x] Added appropriate labels
Codecov Report
Merging #1832 (a612a81) into feature/test-framework (f2ad6e7) will decrease coverage by
0.01%. The diff coverage is93.24%.
@@ Coverage Diff @@
## feature/test-framework #1832 +/- ##
==========================================================
- Coverage 77.53% 77.51% -0.02%
==========================================================
Files 296 296
Lines 62441 62458 +17
==========================================================
+ Hits 48411 48416 +5
- Misses 12298 12308 +10
- Partials 1732 1734 +2
| Flag | Coverage Δ | |
|---|---|---|
| unittests | 77.51% <93.24%> (-0.02%) |
:arrow_down: |
Flags with carried forward coverage won't be shown. Click here to find out more.
| Impacted Files | Coverage Δ | |
|---|---|---|
| runtime/interpreter/function.go | 70.44% <0.00%> (-0.90%) |
:arrow_down: |
| runtime/sema/checker.go | 90.05% <66.66%> (-0.25%) |
:arrow_down: |
| runtime/sema/check_composite_declaration.go | 95.46% <92.10%> (-0.18%) |
:arrow_down: |
| runtime/interpreter/interpreter.go | 89.54% <100.00%> (+<0.01%) |
:arrow_up: |
| runtime/interpreter/value.go | 72.31% <100.00%> (+<0.01%) |
:arrow_up: |
| runtime/runtime.go | 86.17% <100.00%> (ø) |
|
| runtime/sema/check_for.go | 92.77% <100.00%> (ø) |
|
| runtime/sema/check_function.go | 98.48% <100.00%> (ø) |
|
| runtime/sema/check_import_declaration.go | 89.76% <100.00%> (ø) |
|
| runtime/sema/check_variable_declaration.go | 95.40% <100.00%> (ø) |
|
| ... and 2 more |
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.
Cadence Benchstat comparison
This branch with compared with the base branch onflow:feature/test-framework commit 4b1cfb8e4f169237351fe3d0d64dd233a636ea92
The command for i in {1..N}; do go test ./... -run=XXX -bench=. -benchmem -shuffle=on; done was used.
Bench tests were run a total of 7 times on each branch.
Collapsed results for better readability
| old.txt | new.txt | |||
|---|---|---|---|---|
| time/op | delta | |||
| CheckContractInterfaceFungibleTokenConformance-2 | 138µs ± 2% | 140µs ± 3% | ~ | (p=0.234 n=6+7) |
| ContractInterfaceFungibleToken-2 | 40.8µs ± 2% | 41.8µs ± 9% | ~ | (p=0.710 n=7+7) |
| InterpretRecursionFib-2 | 3.79ms ± 1% | 3.72ms ± 2% | −1.95% | (p=0.004 n=7+7) |
| NewInterpreter/new_interpreter-2 | 1.19µs ± 1% | 1.19µs ± 1% | ~ | (p=0.983 n=7+6) |
| NewInterpreter/new_sub-interpreter-2 | 2.50µs ± 1% | 2.51µs ± 2% | ~ | (p=0.851 n=6+6) |
| ParseArray-2 | 8.63ms ± 2% | 8.61ms ± 1% | ~ | (p=0.937 n=6+6) |
| ParseDeploy/byte_array-2 | 13.2ms ± 2% | 13.4ms ± 5% | ~ | (p=0.097 n=7+7) |
| ParseDeploy/decode_hex-2 | 1.14ms ± 2% | 1.16ms ± 5% | ~ | (p=0.073 n=7+7) |
| ParseFungibleToken/With_memory_metering-2 | 209µs ± 3% | 213µs ± 6% | ~ | (p=0.318 n=7+7) |
| ParseFungibleToken/Without_memory_metering-2 | 162µs ± 2% | 162µs ± 3% | ~ | (p=0.620 n=7+7) |
| ParseInfix-2 | 7.77µs ± 1% | 7.72µs ± 1% | ~ | (p=0.394 n=6+6) |
| QualifiedIdentifierCreation/One_level-2 | 2.35ns ± 0% | 2.35ns ± 0% | ~ | (p=0.669 n=6+7) |
| QualifiedIdentifierCreation/Three_levels-2 | 141ns ± 1% | 141ns ± 1% | ~ | (p=0.781 n=6+6) |
| RuntimeFungibleTokenTransfer-2 | 959µs ± 4% | 1085µs ±28% | ~ | (p=0.073 n=6+7) |
| RuntimeResourceDictionaryValues-2 | 6.53ms ± 4% | 6.45ms ± 2% | ~ | (p=0.710 n=7+7) |
| ValueIsSubtypeOfSemaType-2 | 90.4ns ± 2% | 90.2ns ± 1% | ~ | (p=1.000 n=7+7) |
| alloc/op | delta | |||
| CheckContractInterfaceFungibleTokenConformance-2 | 63.6kB ± 0% | 63.6kB ± 0% | ~ | (p=0.462 n=7+7) |
| ContractInterfaceFungibleToken-2 | 25.1kB ± 0% | 25.1kB ± 0% | ~ | (all equal) |
| InterpretRecursionFib-2 | 1.51MB ± 0% | 1.51MB ± 0% | ~ | (p=0.674 n=7+7) |
| NewInterpreter/new_interpreter-2 | 928B ± 0% | 928B ± 0% | ~ | (all equal) |
| NewInterpreter/new_sub-interpreter-2 | 1.48kB ± 0% | 1.48kB ± 0% | ~ | (all equal) |
| ParseArray-2 | 2.82MB ± 2% | 2.79MB ± 2% | ~ | (p=0.165 n=7+7) |
| ParseDeploy/byte_array-2 | 4.45MB ± 3% | 4.47MB ± 3% | ~ | (p=0.620 n=7+7) |
| ParseDeploy/decode_hex-2 | 214kB ± 0% | 214kB ± 0% | ~ | (p=0.901 n=7+7) |
| ParseFungibleToken/With_memory_metering-2 | 36.3kB ± 0% | 36.3kB ± 0% | ~ | (p=0.633 n=7+7) |
| ParseFungibleToken/Without_memory_metering-2 | 36.3kB ± 0% | 36.3kB ± 0% | +0.04% | (p=0.019 n=7+6) |
| ParseInfix-2 | 2.17kB ± 0% | 2.17kB ± 0% | ~ | (p=0.825 n=7+7) |
| QualifiedIdentifierCreation/One_level-2 | 0.00B | 0.00B | ~ | (all equal) |
| QualifiedIdentifierCreation/Three_levels-2 | 64.0B ± 0% | 64.0B ± 0% | ~ | (all equal) |
| RuntimeFungibleTokenTransfer-2 | 228kB ± 0% | 228kB ± 1% | ~ | (p=0.945 n=6+7) |
| RuntimeResourceDictionaryValues-2 | 2.25MB ± 0% | 2.25MB ± 0% | ~ | (p=0.209 n=7+7) |
| ValueIsSubtypeOfSemaType-2 | 48.0B ± 0% | 48.0B ± 0% | ~ | (all equal) |
| allocs/op | delta | |||
| CheckContractInterfaceFungibleTokenConformance-2 | 1.05k ± 0% | 1.05k ± 0% | ~ | (all equal) |
| ContractInterfaceFungibleToken-2 | 441 ± 0% | 441 ± 0% | ~ | (all equal) |
| InterpretRecursionFib-2 | 33.5k ± 0% | 33.5k ± 0% | ~ | (all equal) |
| NewInterpreter/new_interpreter-2 | 13.0 ± 0% | 13.0 ± 0% | ~ | (all equal) |
| NewInterpreter/new_sub-interpreter-2 | 43.0 ± 0% | 43.0 ± 0% | ~ | (all equal) |
| ParseArray-2 | 70.0k ± 0% | 70.0k ± 0% | ~ | (p=0.592 n=7+7) |
| ParseDeploy/byte_array-2 | 105k ± 0% | 105k ± 0% | ~ | (p=0.592 n=7+7) |
| ParseDeploy/decode_hex-2 | 77.0 ± 0% | 77.0 ± 0% | ~ | (all equal) |
| ParseFungibleToken/With_memory_metering-2 | 1.06k ± 0% | 1.06k ± 0% | ~ | (all equal) |
| ParseFungibleToken/Without_memory_metering-2 | 1.06k ± 0% | 1.06k ± 0% | ~ | (all equal) |
| ParseInfix-2 | 66.0 ± 0% | 66.0 ± 0% | ~ | (all equal) |
| QualifiedIdentifierCreation/One_level-2 | 0.00 | 0.00 | ~ | (all equal) |
| QualifiedIdentifierCreation/Three_levels-2 | 2.00 ± 0% | 2.00 ± 0% | ~ | (all equal) |
| RuntimeFungibleTokenTransfer-2 | 4.16k ± 0% | 4.16k ± 0% | ~ | (p=0.385 n=6+7) |
| RuntimeResourceDictionaryValues-2 | 37.5k ± 0% | 37.5k ± 0% | ~ | (p=0.849 n=7+7) |
| ValueIsSubtypeOfSemaType-2 | 1.00 ± 0% | 1.00 ± 0% | ~ | (all equal) |