Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Imports not resolving properly in a freshly scaffolded Flow project #1765

Closed
bartolomej opened this issue Aug 22, 2023 · 2 comments
Closed
Labels
Bug Something isn't working

Comments

@bartolomej
Copy link

bartolomej commented Aug 22, 2023

Current Behavior

I scaffolded a new project using this template: https://github.com/sideninja/flow-basic-scaffold

After the project setup, my config for Person contract looked like this:

{
	"contracts": {
		"Person": "cadence/contracts/Person.cdc"
	}
}

But when I ran flow dev and tried executing makeFriends.cdc transaction with FCL, that failed with error:

[Error Code: 1101] error caused by: 1 error occurred:
	* transaction preprocess failed: [Error Code: 1101] cadence runtime error: Execution failed:
error: [Error Code: 1054] location (Person) is not a valid location: expecting an AddressLocation, but other location types are passed
--> Person

error: cannot find type in this scope: `Person`
  --> df15814c58d0250b708d7bc1101e7e624598fa18479bbf8c51f43c7536686157:15:23
   |
15 |         self.acc.save<@Person.Friendship>(<-Person.makeFriends(), to: StoragePath(identifier: "friendship")!)
   |                        ^^^^^^ not found in this scope

error: cannot find variable in this scope: `Person`
  --> df15814c58d0250b708d7bc1101e7e624598fa18479bbf8c51f43c7536686157:15:44
   |
15 |         self.acc.save<@Person.Friendship>(<-Person.makeFriends(), to: StoragePath(identifier: "friendship")!)
   |                                             ^^^^^^ not found in this scope

I checked the transaction source that was executed on the blockchain and saw that the import "Person" wasn’t properly replaced with the address of the account where it is deployed:

import "Person"

// ...

But when executing the same transaction using Flow CLI, the import was resolved/replaced properly:

import Person from 0x01cf0e2f2f715450

// ...

Note that my FCl instance is properly configured using load({ flowJSON }): https://developers.flow.com/tooling/fcl-js/api#using-flowjson

Expected Behavior

Imports in transactions or scripts should resolve consistently between all Flow tools (e.g. Flow CLI and FCL in this case).

Specifically, the flow.json format used by the flow dev command should also work with FCL.

Steps To Reproduce

  1. Run flow setup my-flow-project --scaffold and enter 2 (Simple Cadence Project)
  2. cd my-flow-project && flow dev
  3. Configure FCL with fcl.load({ flowJSON }), where flowJSON is the contents of my-flow-project/flow.json
  4. Run fcl.query({ cadence: makeFriendsSource }), where makeFriendsSource is this cadence code: https://github.com/sideninja/flow-basic-scaffold/blob/main/cadence/transactions/makeFriends.cdc (any other cadence code using the new import syntax should also reproduce the same issue)
  5. The fcl.query should return something similar to the error I described above

Environment

- OS: MacOS
- Node: v16.15.0
- npm: v8.5.5
- FCL: v1.5.1

What are you currently working on that this is blocking?

This is blocking us from testing (and releasing) the new Flowser app version with "Interact screen", which includes a way to execute scripts or transactions using the new import syntax: onflow/developer-grants#150

@bartolomej bartolomej added the Bug Something isn't working label Aug 22, 2023
@bartolomej
Copy link
Author

Any progress on this issue? It seems like a pretty impactful issue to me, unless I'm missing something.

@bartolomej
Copy link
Author

Turns out that when I executed the transaction that was causing the issue, flow.json that I used wasn't updated to reflect the latest contract deployment status (the deployments section), so FCL probably couldn't resolve the imported contract.

Just tested now, and it works when flow.json is correctly configured.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant