dojoengine / dojo

Dojo is a toolchain for building provable games and autonomous worlds with Cairo
https://dojoengine.org
Apache License 2.0
407 stars 163 forks source link

Models with same name are mixed up in cairo test runner #2349

Open glihm opened 2 weeks ago

glihm commented 2 weeks ago

Describe the bug If a projects defines a model that has the name of a model into dojo-core, then the cairo test runner returns erroneous class hash of the dojo-core model, which is not even included in the tests...

Debugging this at the moment, opening this issue to track this behavior.

To Reproduce Steps to reproduce the behavior:

  1. Add a model that is named Character to a project.
  2. Compilation works fine and manifests are generated.
  3. Try to add a test, and the dojo namespace will be required when it shouldn't. This is because the Character model of the project is actually being mapped to the class hash of the dojo-core one.

Expected behavior We shouldn't have this issue and we can have several models with same name, as they are isolated by the namespaces.

Additional context We had the idea before to internalize the models, and a recent discussion on the dojo discord was also evoking this aspect of why do we need models having their own contract?? We don't make direct use of the contracts, and we could easily have a ModelDefinition struct being held into the world's storage. Due to the use of Span, an easy workaround is to keep the model's definition serialized (but this adds some extra steps too).

ScottyDavies commented 2 weeks ago

Hello @glihm can you please assign this issue to me?

Code03hi commented 2 weeks ago

hello @glihm i can solve this issue

glihm commented 2 weeks ago

@ScottyDavies and @Code03hi happy to have your idea on how to solve that.

I'm afraid we may change the test runner, or simply internalize the models into the world contract.

Code03hi commented 1 week ago

ok