We have some custom pallet unit tests that use multiple mock runtimes that are configured slightly differently. The problem is that when we have to make changes to the runtime, we have to apply those changes to all of them. Furthermore, we'd like to have a set of common functions that all of the unit tests can use. If Rust had inheritance, the solution would be an abstract base runtime and subclasses for each runtime but Rust doesn't have it. The solution likely involves creative use of modules and macros but what's the recommended approach?
I'd like to avoid making changes to the
Cargo.toml. I'd like to have some sort of macro level attribute that I could set in each runtime:
"runtime2" and then conditionally compile which value is used based on that attribute.
In our case, we have two runtimes that differ only by the constant values for two of the associated types.
type MaxMessagesStored = ConstU32<25>; // runtime1
type MaxMessagesStored = ConstU32<1000>; // runtime2
So, I'd like something like this. This code is for example and does NOT work:
#![cfg_attr(RUNTIME, define = "runtime1")] #[cfg(RUNTIME = "runtime1")] type MaxMessagesStored = ConstU32<25>; #[cfg(RUNTIME = "runtime2")] type MaxMessagesStored = ConstU32<1000>;
In C, this would be:
#define RUNTIME "runtime1" #if defined(RUNTIME) && (RUNTIME == "runtime1") // code #else // code #endif
Alternatively, is there a way to change the value at runtime? I assume not because it's a constant but have to ask.