onflow / flow-cli

The Flow CLI is a command-line interface that provides useful utilities for building Flow applications
https://onflow.org
Apache License 2.0
206 stars 62 forks source link

`flow test` should deploy smart contracts defined in flow.json #1377

Open wfalcon0x opened 4 months ago

wfalcon0x commented 4 months ago

Instructions

Issue To Be Solved

Currently we need to explicitly deploy a smart contract in the cadence unit or integration tests, e.g.:

import "FLIXRegistry"
...
...
access(all)
fun setup() {
    let flixRegistryErr = Test.deployContract(
        name: "FLIXRegistry",
        path: "../contracts/flix_registry.cdc",
        arguments: []
    )
...

In the above example FLIXRegistry cannot be referenced in the code before it was deployed with Test.deployContract, even if it is imported on the the top, and defined in the flow.json as follows:

{
  "contracts": {
    "FLIXRegistry": {
      "source": "cadence/contracts/flix_registry.cdc",
      "aliases": {
        "emulator": "0xf8d6e0586b0a20c7",
        "testing": "0x0000000000000007"
      }
    },
...

(Optional): Suggest A Solution

It could increase developer experience if smart contracts defined in the flow.json are readily available in the unit tests, so the developers only have to import those as dependencies. Also it could keep the unit tests code more concise and clean.

(Optional): Context

chasefleming commented 4 months ago

@wfalcon0x do they need to be deployed? It seems like you'd want to keep control of deployment in your tests for state. Would the issue be solved for you if the import syntax worked correctly in tests?

wfalcon0x commented 4 months ago

It was my assumption that they need to be deployed to make it work based on the current behaviour. But I think you make a good point, and there are 2 separate issues. 1) for the actual problem I faced they don't need to be deployed, i just wanted to be able to reference a resource, before they were deployed 2) it would be nice to have a way to deploy them, so I don't have to control the deployment from the test in every case