cadence icon indicating copy to clipboard operation
cadence copied to clipboard

[Test Framework] Add support for importing and initializing contracts

Open SupunS opened this issue 3 years ago • 2 comments

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 master branch
  • [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 changed in the Github PR explorer
  • [x] Added appropriate labels

SupunS avatar Jul 20 '22 22:07 SupunS

Codecov Report

Merging #1832 (a612a81) into feature/test-framework (f2ad6e7) will decrease coverage by 0.01%. The diff coverage is 93.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.

codecov[bot] avatar Aug 16 '22 01:08 codecov[bot]

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.txtnew.txt
time/opdelta
CheckContractInterfaceFungibleTokenConformance-2138µs ± 2%140µs ± 3%~(p=0.234 n=6+7)
ContractInterfaceFungibleToken-240.8µs ± 2%41.8µs ± 9%~(p=0.710 n=7+7)
InterpretRecursionFib-23.79ms ± 1%3.72ms ± 2%−1.95%(p=0.004 n=7+7)
NewInterpreter/new_interpreter-21.19µs ± 1%1.19µs ± 1%~(p=0.983 n=7+6)
NewInterpreter/new_sub-interpreter-22.50µs ± 1%2.51µs ± 2%~(p=0.851 n=6+6)
ParseArray-28.63ms ± 2%8.61ms ± 1%~(p=0.937 n=6+6)
ParseDeploy/byte_array-213.2ms ± 2%13.4ms ± 5%~(p=0.097 n=7+7)
ParseDeploy/decode_hex-21.14ms ± 2%1.16ms ± 5%~(p=0.073 n=7+7)
ParseFungibleToken/With_memory_metering-2209µs ± 3%213µs ± 6%~(p=0.318 n=7+7)
ParseFungibleToken/Without_memory_metering-2162µs ± 2%162µs ± 3%~(p=0.620 n=7+7)
ParseInfix-27.77µs ± 1%7.72µs ± 1%~(p=0.394 n=6+6)
QualifiedIdentifierCreation/One_level-22.35ns ± 0%2.35ns ± 0%~(p=0.669 n=6+7)
QualifiedIdentifierCreation/Three_levels-2141ns ± 1%141ns ± 1%~(p=0.781 n=6+6)
RuntimeFungibleTokenTransfer-2959µs ± 4%1085µs ±28%~(p=0.073 n=6+7)
RuntimeResourceDictionaryValues-26.53ms ± 4%6.45ms ± 2%~(p=0.710 n=7+7)
ValueIsSubtypeOfSemaType-290.4ns ± 2%90.2ns ± 1%~(p=1.000 n=7+7)
 
alloc/opdelta
CheckContractInterfaceFungibleTokenConformance-263.6kB ± 0%63.6kB ± 0%~(p=0.462 n=7+7)
ContractInterfaceFungibleToken-225.1kB ± 0%25.1kB ± 0%~(all equal)
InterpretRecursionFib-21.51MB ± 0%1.51MB ± 0%~(p=0.674 n=7+7)
NewInterpreter/new_interpreter-2928B ± 0%928B ± 0%~(all equal)
NewInterpreter/new_sub-interpreter-21.48kB ± 0%1.48kB ± 0%~(all equal)
ParseArray-22.82MB ± 2%2.79MB ± 2%~(p=0.165 n=7+7)
ParseDeploy/byte_array-24.45MB ± 3%4.47MB ± 3%~(p=0.620 n=7+7)
ParseDeploy/decode_hex-2214kB ± 0%214kB ± 0%~(p=0.901 n=7+7)
ParseFungibleToken/With_memory_metering-236.3kB ± 0%36.3kB ± 0%~(p=0.633 n=7+7)
ParseFungibleToken/Without_memory_metering-236.3kB ± 0%36.3kB ± 0%+0.04%(p=0.019 n=7+6)
ParseInfix-22.17kB ± 0%2.17kB ± 0%~(p=0.825 n=7+7)
QualifiedIdentifierCreation/One_level-20.00B 0.00B ~(all equal)
QualifiedIdentifierCreation/Three_levels-264.0B ± 0%64.0B ± 0%~(all equal)
RuntimeFungibleTokenTransfer-2228kB ± 0%228kB ± 1%~(p=0.945 n=6+7)
RuntimeResourceDictionaryValues-22.25MB ± 0%2.25MB ± 0%~(p=0.209 n=7+7)
ValueIsSubtypeOfSemaType-248.0B ± 0%48.0B ± 0%~(all equal)
 
allocs/opdelta
CheckContractInterfaceFungibleTokenConformance-21.05k ± 0%1.05k ± 0%~(all equal)
ContractInterfaceFungibleToken-2441 ± 0%441 ± 0%~(all equal)
InterpretRecursionFib-233.5k ± 0%33.5k ± 0%~(all equal)
NewInterpreter/new_interpreter-213.0 ± 0%13.0 ± 0%~(all equal)
NewInterpreter/new_sub-interpreter-243.0 ± 0%43.0 ± 0%~(all equal)
ParseArray-270.0k ± 0%70.0k ± 0%~(p=0.592 n=7+7)
ParseDeploy/byte_array-2105k ± 0%105k ± 0%~(p=0.592 n=7+7)
ParseDeploy/decode_hex-277.0 ± 0%77.0 ± 0%~(all equal)
ParseFungibleToken/With_memory_metering-21.06k ± 0%1.06k ± 0%~(all equal)
ParseFungibleToken/Without_memory_metering-21.06k ± 0%1.06k ± 0%~(all equal)
ParseInfix-266.0 ± 0%66.0 ± 0%~(all equal)
QualifiedIdentifierCreation/One_level-20.00 0.00 ~(all equal)
QualifiedIdentifierCreation/Three_levels-22.00 ± 0%2.00 ± 0%~(all equal)
RuntimeFungibleTokenTransfer-24.16k ± 0%4.16k ± 0%~(p=0.385 n=6+7)
RuntimeResourceDictionaryValues-237.5k ± 0%37.5k ± 0%~(p=0.849 n=7+7)
ValueIsSubtypeOfSemaType-21.00 ± 0%1.00 ± 0%~(all equal)
 

github-actions[bot] avatar Aug 16 '22 01:08 github-actions[bot]