flow-playground icon indicating copy to clipboard operation
flow-playground copied to clipboard

Cannot find declaration for deployed contract

Open neil-ptr opened this issue 2 years ago • 1 comments

Describe the bug Transaction cannot import a deployed contract

To Reproduce

  1. open up a new project on the playground
  2. go to account 1, delete all the code on it and type the following but do not deploy yet: pub contract BasicToken {}
  3. go to a transaction, delete all the code and type in import BasicToken from 0x01
  4. go back to account 1 and deploy
  5. go back to transaction and editor says that it cannot find declaration for BasicToken

Expected behavior For there to be no error and for the editor to be able to find the declaration for BasicToken

Desktop (please complete the following information):

  • OS: MacOS
  • Browser: Chrome
  • Version Version 103.0.5060.134 (Official Build) (x86_64)

Additional Notes

  • Trying to redeploy the account still doesn't update the editor about the declaration BasicToken so a page refresh is required to update the editor
  • Related to #282
  • Related https://github.com/onflow/flow-playground/issues/260

neil-ptr avatar Aug 04 '22 19:08 neil-ptr

This is likely an LS bug, as mentioned in an issue: https://github.com/onflow/cadence/issues/1570

devbugging avatar Aug 12 '22 15:08 devbugging

@sideninja it does look like this is caused by LS caching.

I verified that the LS is receiving the latest deployed code through the getAddressCode callback by logging it in useLanguageServer.ts#getCode. I also noticed that once a specific transaction is checked for errors, the getAddressCode function doesn't get called again. For example:

Initial transaction: import BasicToken from 0x01 Updated transaction: import BasicTokenA from 0x01 - LS calls getAddressCode Reverted back to initial transaction: import BasicToken from 0x01 - LS does not call getAddressCode

This may explain why we only see the problem when viewing the transaction before the contract is deployed.

LS log on step 3 (before deployment, after adding the transaction import):

[
    {
        "resource": {
            "$mid": 1,
            "external": "inmemory://model/5",
            "path": "/5",
            "scheme": "inmemory",
            "authority": "model"
        },
        "owner": "default",
        "severity": 8,
        "message": "cannot find declaration `BasicToken` in `0000000000000001.BasicToken`. available exported declarations are:\n",
        "startLineNumber": 1,
        "startColumn": 8,
        "endLineNumber": 1,
        "endColumn": 18
    }
]

LS log on step 5 (after deployment, when viewing the transaction):

[
    {
        "resource": {
            "$mid": 1,
            "external": "inmemory://model/7",
            "path": "/7",
            "scheme": "inmemory",
            "authority": "model"
        },
        "owner": "default",
        "severity": 8,
        "message": "cannot find declaration `BasicToken` in `0000000000000001.BasicToken`. available exported declarations are:\n",
        "startLineNumber": 1,
        "startColumn": 8,
        "endLineNumber": 1,
        "endColumn": 18
    }
]

alse avatar Aug 19 '22 18:08 alse

This is duplicate to https://github.com/onflow/cadence/issues/1570

devbugging avatar Sep 08 '22 14:09 devbugging