Skip to content

[xcm-emulator] Make a generic constructor method for genesis Storage #2613

Open
@0xmovses

Description

Currently we write a separate genesis function for each Parachain when creating the emulated test environments cumulus/parachains/integration-tests/emulated/chains/parachains/bridges/bridge-hub-rococo/src/genesis.rs.
Much of this logic is repeated, but some is chain / environment specific. We can make a generic function, reducing code repetition and making this code more expressive and configurable.

There will likely be more situations in the future where we want to configure genesis state for XCM testing.

We could do something like

trait RuntimeGenesisConfig {
    fn configure_storage(storage: &mut Storage);
}

Then we could do a impl RuntimeGenesisConfig for BridgeHubRococoRuntime, for example.

And finally:

impl Storage {
    pub fn new_genesis<R: RuntimeGenesisConfig>() -> Self {
        let mut storage = Storage::default();
        R::configure_storage(&mut storage);
        storage
    }
}

Originally suggested here by @liamaharon

Metadata

Assignees

No one assigned

    Labels

    I4-refactorCode needs refactoring.T10-testsThis PR/Issue is related to tests.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions