onflow / cadence-tools

Developer tools for Cadence
https://www.onflow.org/
Apache License 2.0
24 stars 20 forks source link

[Testing Framework] Error when returning a reference type #339

Open joshuahannan opened 5 months ago

joshuahannan commented 5 months ago

Current Behavior

When executing a script that returns a reference, the error that the testing framework gives is unclear:

- FAIL: testGetIterator
    Execution failed:
    error: slab (0x0.1055) not found: slab not found for stored value
      --> tests/example_nft_test.cdc:262:12

Expected Behavior

Since scripts are normally allowed to return reference types, it would make sense to allow returning these types in the testing framework, or at least have a more clear error.

Steps To Reproduce

  1. Run a script from the testing framework that returns a reference, like this one:
    
    import "FungibleToken"

access(all) fun main(account: Address): &{FungibleToken.Balance} {

let vaultRef = getAccount(account)
    .capabilities.borrow<&{FungibleToken.Balance}>(/public/flowTokenBalance)
    ?? panic("Could not borrow Balance reference to the Vault")

return vaultRef

}

3. Observe the error

### Environment

```markdown
- Network: Emulator

github.com/onflow/cadence v1.0.0-preview.19
github.com/onflow/cadence-tools/test v1.0.0-preview.13
github.com/onflow/flow-emulator v1.0.0-preview.16