Skip to content

Commit

Permalink
docs: Update MIGRATING.md for 0.10 and 1.0 (#373)
Browse files Browse the repository at this point in the history
  • Loading branch information
kulikthebird authored May 20, 2024
1 parent 741b358 commit 1e555ae
Showing 1 changed file with 121 additions and 2 deletions.
123 changes: 121 additions & 2 deletions MIGRATING.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,129 @@ ignored in the further process.
+}
```

## 0.10.0 -> 1.0.0
### Update deps to 2.0.0
In Cargo.toml:
```diff
-cosmwasm-schema = "1.5.0"
-cosmwasm-std = "1.5.0"
-cw-multi-test = "0.20.0"
-cw-storage-plus = "1.2.0"
-cw-utils = "1.0.2"
-cw2 = "1.1.2"
+cosmwasm-schema = "2.0.0"
+cosmwasm-std = "2.0.0"
+cw-multi-test = "2.0.0"
+cw-storage-plus = "2.0.0"
+cw-utils = "2.0.0"
+cw2 = "2.0.0"
```

In a multi-test code:
```diff
-let addr = Addr::unchecked("addr0001");
+use cw_multi_test::IntoBech32;
+let addr = "addr0001".into_bech32();
let contract = code_id
.instantiate(vec![owner.to_owned()], false)
.with_label("Sublist contract")
- .call(addr)
+ .call(&addr)
.unwrap();
```

In the contract's code:
```diff
struct Contract<'a> {
- data: Item<'static, ContractData>,
- admins: Map<'static, &'a Addr, Empty>,
+ data: Item<ContractData>,
+ admins: Map<&'a Addr, Empty>,
}
```


## 0.9.3 -> 0.10.0

## Multitest proxy

### Querier in Multitest App
```diff
let version: ContractVersion =
- query_contract_info(&app.app_mut().wrap(), contract.contract_addr.to_string()).unwrap();
+ query_contract_info(&app.querier(), contract.contract_addr.to_string()).unwrap();
```

### Multitest module name
```diff
-use contract::multitest_utils::Group;
+use contract::mt::Group;
```

### BoundQuerier improve
```diff
let querier = sylvia::types::BoundQuerier::<
_,
- std::marker::PhantomData<(
- SvCustomMsg,
- SvCustomMsg,
- SvCustomMsg,
- SvCustomMsg,
- )>,
+ &dyn super::CustomAndGeneric<
+ RetT = SvCustomMsg,
+ Exec = SvCustomMsg,
+ Query = SvCustomMsg,
+ Sudo = SvCustomMsg,
+ Error = (),
+ ExecC = (),
+ QueryC = (),
+ >,
>::borrowed(&contract, &querier_wrapper);
```

### Remove `#[contract(module=...)]` support
There is no need to provide any additional data to an interface implementation on a contract.
```diff
-#[contract(module=crate::contract)]
-#[sv::messages(cw1 as Cw1)]
impl Cw1 for CustomContract {
type Error = StdError;

#[sv::msg(exec)]
fn execute(&self, _ctx: ExecCtx, _msgs: Vec<CosmosMsg>) -> StdResult<Response> {
Ok(Response::new())
}
}
```

### Sylvia attributes
Each sylvia attribute that is used by `#[contract]` and `#[interface]` macro needs to be prefixed with `sv::`, for e.g.:
```diff
#[cfg_attr(not(feature = "library"), entry_points)]
#[contract]
-#[messages(cw1 as Cw1: custom(msg, query))]
+#[sv::messages(cw1 as Cw1: custom(msg, query))]
#[sv::custom(query=CounterQuery, msg=CounterMsg)]
impl CustomContract {
pub const fn new() -> Self {
Self {
sudo_counter: Item::new("sudo_counter"),
}
}

- #[msg(instantiate)]
+ #[sv::msg(instantiate)]
pub fn instantiate(
&self,
ctx: InstantiateCtx<CounterQuery>,
) -> StdResult<Response<CounterMsg>> {
self.sudo_counter.save(ctx.deps.storage, &0)?;
Ok(Response::default())
}
}
```

### Multitest proxy

Since `0.10.0` Sylvia won't generate multitest Proxy types for the `Interface` macro call. Instead, all the methods from interfaces are directly implemented on the contract's multitest proxy.
To use methods from an implemented interface like before, the user has to import the multitest trait from the module in which the interface is implemented.
Expand All @@ -66,7 +185,7 @@ To use methods from an implemented interface like before, the user has to import
+ .unwrap();
```

## Associated types in generics
### Associated types in generics

`Sylvia` interface is meant to be implemented on contract only once. Because of that, we decided to remove support for generics in interfaces.
Instead, when migrating from `0.9.3` to `0.10.0`, the user must replace generics with associated types.
Expand Down

0 comments on commit 1e555ae

Please sign in to comment.