Skip to content
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

MockBuilder: add support for traits with methods with the same name #1

Merged
merged 2 commits into from
Oct 16, 2023

Conversation

lemunozm
Copy link
Collaborator

Description

Add support for testing pallets that implement traits whose methods have the same name.

When a pallet, implements two traits with the same methods, the trait name should now be in the name signature (only needed in case of name collision, otherwise the pallet can be constructed as always). Example:

struct Pallet;

impl Pallet {
    #[allow(non_snake_case)]
    pub fn mock_TraitA_get(f: impl Fn(u64) -> usize + 'static) {
        register_call!(f);
    }

    #[allow(non_snake_case)]
    pub fn mock_TraitB_get(f: impl Fn(i32) -> bool + 'static) {
        register_call!(f);
    }
}

impl TraitA for Pallet {
    fn get(a: u64) -> usize {
        execute_call!(a)
    }
    
    fn get(a: i32) -> bool {
        execute_call!(a)
    }
}

This change is retrocompatible

Fixes centrifuge/centrifuge-chain#1564

@lemunozm lemunozm added the enhancement New feature or request label Oct 16, 2023
@lemunozm lemunozm self-assigned this Oct 16, 2023
@lemunozm lemunozm force-pushed the mock-builder/same-name-trait-support branch from b4ebc48 to e5da848 Compare October 16, 2023 07:40
@lemunozm lemunozm force-pushed the mock-builder/same-name-trait-support branch from e5da848 to 01cd045 Compare October 16, 2023 07:41
Copy link
Collaborator

@wischli wischli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great addition to the mock-builder operationality! Thanks for picking this up. Three non-blocking super minor nits:

mock-builder/src/location.rs Outdated Show resolved Hide resolved
mock-builder/src/location.rs Outdated Show resolved Hide resolved
mock-builder/src/location.rs Outdated Show resolved Hide resolved
@lemunozm
Copy link
Collaborator Author

Thanks for your fast review!

@lemunozm
Copy link
Collaborator Author

This project has no CI yet, but it has passed all tests.

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

Successfully merging this pull request may close these issues.

MockBuilder: allow traits whose name methods collide
2 participants