Skip to content

bug(mock!): Error E0412, Cannot find type K in this scope when using mock! macro #630

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

Open
gate2017aloy opened this issue Dec 11, 2024 · 3 comments

Comments

@gate2017aloy
Copy link

gate2017aloy commented Dec 11, 2024

I encountered an issue while using the mockall library to create a mock implementation for store operations in my Rust project. The error message I received is: error[E0412]: cannot find type K in this scope

use substreams::store::{StoreDelete, StoreNew, StoreSet};
use substreams::{store::StoreGet, Hex};
use mockall::predicate::*;
use mockall::*;
use pretty_assertions::assert_eq;
use prost::Message;

mock! {
    /// Mock implementation for store operations used in testing.
    pub StoreSetProto<T: Default + prost::Message + 'static> {}

    impl<T: prost::Message + 'static + Default> StoreNew for StoreSetProto<T> {
        fn new() -> Self;
    }

    impl<T: prost::Message + 'static + Default> StoreDelete for StoreSetProto<T> {
        #[cfg_attr(concretize)]
        fn delete_prefix(&self, ordinal: i64, key: &String);
    }

    impl<T: Default + prost::Message + 'static> StoreSet<T> for StoreSetProto<T> {
        #[cfg_attr(concretize)]
        fn set<K: AsRef<str>>(&self, ord: u64, key: K, value: &T);

        #[cfg_attr(concretize)]
        fn set_many<K: AsRef<str>>(&self, ord: u64, keys: &Vec<K>, value: &T);
    }
}

@asomers
Copy link
Owner

asomers commented Dec 11, 2024

@gate2017aloy could you please provide some more information? A minimal example to reproduce the problem would be great. The example you provided can't even compile, because it doesn't include definitions for the StoreNew, StoreSet, and StoreDelete traits. Also, which section of code is triggering that error? The compiler should tell you.

Repository owner deleted a comment Dec 11, 2024
@gate2017aloy
Copy link
Author

@gate2017aloy could you please provide some more information? A minimal example to reproduce the problem would be great. The example you provided can't even compile, because it doesn't include definitions for the StoreNew, StoreSet, and StoreDelete traits. Also, which section of code is triggering that error? The compiler should tell you.

Hi @asomers

We are trying to mock StoreSetProto of substreams::store

You can refer to the dependencies below

  • substreams = "0.5.22"
  • substreams-ethereum = "0.9.13"
  • mockall = "0.13.0"
  • prost = '^0.11.0'
  • prost-types = '0.11.0'
  • pretty_assertions = "1.4.1"

The compile time error is seen in the set_many method when mocking the StoreSet trait for StoreSetProto

    impl<T: Default + prost::Message + 'static> StoreSet<T> for StoreSetProto<T> {
        #[cfg_attr(concretize)]
        fn set<K: AsRef<str>>(&self, ord: u64, key: K, value: &T);

        #[cfg_attr(concretize)]
        fn set_many<K: AsRef<str>>(&self, ord: u64, keys: &Vec<K>, value: &T);
    }

The error as mentioned above error[E0412]: cannot find type K in this scope

@asomers
Copy link
Owner

asomers commented Dec 19, 2024

That's still not a complete example. If you think that Mockall has a bug, could you please provide a minimal example? That is, a self-contained example that doesn't rely on external crates and does not contain methods irrelevant to the issue at hand?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants