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

#[drink::contract_bundle_provider] macro #73

Merged
merged 9 commits into from
Oct 27, 2023
Merged

#[drink::contract_bundle_provider] macro #73

merged 9 commits into from
Oct 27, 2023

Conversation

pmikolajczyk41
Copy link
Member

Follow-up to #70 and #68.

We introduce a new macro #[drink::contract_bundle_provider] which provides a convenient way of obtaining contract bundles in drink testing.

This bundling provision wasn't done within #[drink:test] macro so as to avoid generating enums and implementations per-testcase. Now the user has to (although they can still get bytes/transcoders manually or use ContractBundle API) add one new type to the test module:

#[drink::contract_bundle_provider]
enum BundleProvider {}

which will be expanded to:

enum BundleProvider {
    Flipper,
    Counter,
}
impl BundleProvider {
    pub fn local() -> ::drink::DrinkResult<::drink::ContractBundle> {
        ::drink::ContractBundle::load(
            "/home/piomiko/Desktop/drink/examples/flipper/target/ink/flipper.contract",
        )
    }
    pub fn bundle(self) -> ::drink::DrinkResult<::drink::ContractBundle> {
        match self {
            BundleProvider::Flipper => ::drink::ContractBundle::load(
                "/home/piomiko/Desktop/drink/examples/flipper/target/ink/flipper.contract",
            ),
            BundleProvider::Counter => ::drink::ContractBundle::load(
                "/home/piomiko/Desktop/drink/examples/counter/target/ink/counter.contract",
            ),
        }
    }
}

(assuming that we are using it within flipper project and we have counter as a contract dependency in Cargo.toml)

Copy link
Collaborator

@piotrMocz piotrMocz left a comment

Choose a reason for hiding this comment

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

I think this is great! I'd say it still may have the potential to make it even more user-friendly but we can definitely discuss this after merging of this one (which I think is already a great step)

}
}

pub fn generate_bundle_providing(&self, enum_item: ItemEnum) -> TokenStream2 {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is extremely nitpicky but I'd prefer s/providing/provision/g 😄

Copy link
Member Author

Choose a reason for hiding this comment

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

sure, done!

@pmikolajczyk41 pmikolajczyk41 merged commit cb0beb1 into main Oct 27, 2023
2 checks passed
@pmikolajczyk41 pmikolajczyk41 deleted the bundles branch October 27, 2023 07:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants