CosmWasm / cw-multi-test

CosmWasm multi-contract testing framework
Apache License 2.0
48 stars 42 forks source link

Unifying `instantiate2` implementation #207

Closed CyberHoward closed 2 months ago

CyberHoward commented 2 months ago

Description

Our team at @AbstractSDK is working on refactoring our smart-account implementations to be optimized for account-abstraction use-cases. Because each user on the blockchain will have an Abstract smart-account created for them, we're trying to minimize the state that is stored under the contract's namespace.

The account needs to be aware of a few contracts in order to do verification of actions or call specific functionality on them.

Our Solution

To reduce the state we've been exploring the use of instantiate2 to deterministically compute the canonical address of each contract and include them in the WASM binary directly as bytes, to be humanized at runtime. As the # of Accounts scale, this should have a significant impact on the storage use of our solution.

To get the address of any of these native contracts we do the following:

The Problem

The problem that we're facing is that this workflow does not give us the same addresses in the cw-multi-test environment due to the fact that its instantiate2 method does not incorporate the actual checksum of the blob contract.

As a result we're forced to either:

Discussed Solution

We've internally discussed an addition to cw-multi-test that would allow users to set the checksum of a contract through the Contract trait.

pub trait Contract<C, Q = Empty>
where
    C: CustomMsg,
    Q: CustomQuery,
{
    /// Get the checksum of the contract
    // Defaults to None (not API breaking)
    fn checksum(&self) -> AnyResult<Option<String>> {
        Ok(None)
   }
}

And then update ContractWrapper to contain an optional checksum value.

pub struct ContractWrapper<
   ...
> where
    ...
{
    // Add an optional checksum field
    checksum: Option<String>,
}

And update the instantiate2 method to use this checksum if Some.

Doing this would allow developers to use the exact same addresses for their contracts in a test environment as a wasmd environment without requiring custom checksum generators.

Questions

Is this an acceptable solution?

DariuszDepta commented 2 months ago

Hi @CyberHoward, there is PR #212 that implements the proposed solution. Could you take a look at it and confirm if it is fully covering your requirements?