You can do it the same way as in tests, by inserting storage items like @Purple_Turtle posted in the comment;
pallet_staking::ActiveEra::<T>::put(…)
One example would be from the nomination-pools benchmark where it fudges the staking stoarge.
Normally it is better to have pallets communicate with each other via traits, since otherwise storage invariants can get invalidated when pallet_x
just modifies the storage of pallet_y
without its knowledge. But if you only do it in testing/benchmarks, then its fine.
Since that type has private fields, you can hack around it by decoding it from its struct elements. It's not ideal, but better than having to go through an upstream change:
#[test]
fn hack() {
use codec::{Encode, Decode};
new_test_ext().execute_with(|| {
let raw = (4 as sp_staking::EraIndex, Some(10u64)).encode();
let info = pallet_staking::ActiveEraInfo::decode(&mut &raw[..]).unwrap();
// Now you can put it into stoarge.
pallet_staking::ActiveEra::<Test>::put(&info);
});
}
pallet_staking::ActiveEra::<T>::mutate/insert( .. )
help? Also make sure to includeT: pallet_staking::Config