1

I'm writing a pallet that implements evm::executor::stack::PrecompileSet.

The goal is to use this pallet in conjunction with Frontier's pallet-evm, which has the following types in its Config trait:

type PrecompilesType: PrecompileSet;
type PrecompilesValue: Get<Self::PrecompilesType>;

While writing a mock environment for unit testing the pallet I'm writing, I'm struggling to make the compiler happy for PrecompilesValue:

parameter_types! {
    ...
    pub MockPrecompiles: crate::Pallet<Test> = // ?
}
impl pallet_evm::Config for Test {
    ...
    type PrecompilesType = crate::Pallet<Test>;
    type PrecompilesValue = MockPrecompiles;
    ...
}

It seems non-trivial to use the parameter_types! macro to get an appropriate impl<T: Config> Get<T> for Pallet<T>. With a blind trial-and-error strategy I ran into this error message:

error[E0423]: cannot initialize a tuple struct which contains private fields
   --> frame/evm-precompile/src/mock.rs:136:45
    |
136 |     pub MockPrecompiles: crate::Pallet<Test> = crate::Pallet(PhantomData::<Test>);
    |                                                ^^^^^^^^^^^^^^^^^^^^^

is it possible to set MockPrecompiles/PrecompilesValue in this Runtime configuration?

5
  • what is the appropriate Rust syntax to set MockPrecompiles/PrecompilesValue in this Runtime configuration? your question is not completely understandable. Rust aside, what should PrecompilesValue be, just when thinking about it conceptually?
    – kianenigma
    Commented Mar 12, 2023 at 22:36
  • 1
    pub MockPrecompiles: crate::Pallet<Test> = crate::Pallet(PhantomData::<Test>); pallet structs are never meant to be instantiated, I find it hardly that you will be able to find a way around this.
    – kianenigma
    Commented Mar 12, 2023 at 22:39
  • as defined in pallet-evm: type PrecompilesValue: Get<Self::PrecompilesType>, and I set type PrecompilesType = crate::Pallet<Test> Commented Mar 12, 2023 at 22:41
  • "as defined in pallet-evm.." Rephrasing what I said, I am asking what this type should be all Rust details aside, at a conceptual level. What does it mean and where should it come from?
    – kianenigma
    Commented Mar 14, 2023 at 15:53
  • this type represents the set of precompiles that pallet-evm will be able to execute... it is meant to be a custom implementation for each runtime github.com/paritytech/frontier/blob/… Commented Mar 15, 2023 at 21:59

1 Answer 1

1

Your question makes me confused.

But to your question title.

You could simply do this:

https://github.com/darwinia-network/darwinia/blob/61c6de47e5ef11e1842d1d35476bfb699ef2cd58/pallet/deposit/src/lib.rs#L387-L400

https://github.com/darwinia-network/darwinia/blob/61c6de47e5ef11e1842d1d35476bfb699ef2cd58/runtime/darwinia/src/pallets/staking.rs#L76

I implement the Stake for darwinia_deposit::Pallet<T> and pass it to the other pallet's configuration as a param. And you can simply replace the Stake with Get.

Not the answer you're looking for? Browse other questions tagged or ask your own question.