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

Cannot import non "library" features in dev-dependencies #577

Closed
orkunkl opened this issue Dec 14, 2021 · 2 comments
Closed

Cannot import non "library" features in dev-dependencies #577

orkunkl opened this issue Dec 14, 2021 · 2 comments

Comments

@orkunkl
Copy link
Contributor

orkunkl commented Dec 14, 2021

I am currently building a NFT project that imports cw721-metadata-onchain. I assume the same problem will be relevant here.

Imported cw721-metadata-onchain with library feature in dependencies, but since I am using multitest library for testing, I need entry package which is ignored in dev-dependencies. This makes it impossible to use multitest and have reduced binary size at the same time.

Made research and found updating to resolver to version 2. Yet I could not make it work and above my rust knowledge :(

@ethanfrey
Copy link
Member

This is an issue in the source repo: https://github.com/CosmWasm/cw-nfts/blob/main/contracts/cw721-metadata-onchain/src/lib.rs#L33-L67

Basically, you have two choice:

  1. Just copy these minimal execute/instaniate/query definitions into your test helpers
  2. Export them, but wrap each entry point definition in library (a bit more verbose and change upstream)

The first would be to add something like this to your multitest test helper:

use cw721_onchain_metadata::Cw721MetadataContract;

pub fn instantiate(
        deps: DepsMut,
        env: Env,
        info: MessageInfo,
        msg: InstantiateMsg,
    ) -> StdResult<Response> {
        Cw721MetadataContract::default().instantiate(deps, env, info, msg)
    }

The second would be to change cw721_onchain_metadata like:

pub mod entry {
    use super::*;

    use cosmwasm_std::entry_point;
    use cosmwasm_std::{Binary, Deps, DepsMut, Env, MessageInfo, Response, StdResult};

    // This makes a conscious choice on the various generics used by the contract
    #[cfg_attr(not(feature = "library"), entry_point)]
    pub fn instantiate(
        deps: DepsMut,
        env: Env,
        info: MessageInfo,
        msg: InstantiateMsg,
    ) -> StdResult<Response> {
        Cw721MetadataContract::default().instantiate(deps, env, info, msg)
    }
}

Which could them be imported

@ethanfrey
Copy link
Member

Good question, but closing as this is answered and no work to do ins cw-plus

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

No branches or pull requests

2 participants