inkdevhub / drink

De-chained Ready-to-play ink! playground
Apache License 2.0
69 stars 15 forks source link

#[drink::contract_bundle_provider] macro #73

Closed pmikolajczyk41 closed 1 year ago

pmikolajczyk41 commented 1 year ago

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)