software-mansion / scarb

The Cairo package manager
http://docs.swmansion.com/scarb/
MIT License
191 stars 71 forks source link

Cairo runner `CLASS_HASH_NOT_FOUND` when using other package contract #1642

Closed glihm closed 1 month ago

glihm commented 1 month ago

Problem

Since scarb 2.8.3, when a contract is imported from an other package, the deploy syscall using other_package::contract::TEST_CLASS_HASH panics with CLASS_HASH_NOT_FOUND.

Using scarb 2.8.2, it works as expected.

Steps

  1. Write a first package with this contract:
    #[starknet::contract]
    pub mod c1 {
    #[storage]
    struct Storage {}
    }
  2. Write a second package with this test:

    #[cfg(test)]
    mod tests {
    use other::c1;
    
    #[test]
    fn deploy_other_package_contract() {        
        let r = starknet::syscalls::deploy_syscall(
            c1::TEST_CLASS_HASH.try_into().unwrap(),
            1234,
            [].span(),
            false
        );
    
        println!("{:?}", r);
    }
    }
  3. You should see an error like:
    Result::Err([384202928933128251697107453381487007374824001092])

    Which stands for CLASS_HASH_NOT_FOUND.

Possible Solution(s)

The way crates ids are collected has changed between 2.8.2and 2.8.3, not using collect_all_crate_ids anymore.

But even trying to add it back, the correct crate ids are shown, but the error seems to persist.

Notes

No response

Version

`2.8.2` works, `2.8.3` stop working.
glihm commented 1 month ago

Manually adding the contract with build-external-contracts works. But is that the intended behavior for testing too?

If yes, then can be closed.

maciektr commented 1 month ago

Hi!

Yes, since 2.8.3 we have stopped building all contracts from all dependencies preemptively. This is an optimization. Please take a look at the release notes https://github.com/software-mansion/scarb/releases/tag/v2.8.3

glihm commented 1 month ago

Found the release afterward, sorry didn’t close. Thank you @maciektr. 👍