-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update sylvia so all execute messages payable
- Loading branch information
Showing
7 changed files
with
110 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// This contains all code we needed to manually add to make it work well with cw-orch | ||
// In the future, hopefully some of this can me auto-generated. But let's get it to work now. | ||
use crate::contract::entry_points::{execute, instantiate, query}; | ||
use crate::contract::sv::{ContractExecMsg, ContractQueryMsg, ContractSudoMsg, InstantiateMsg}; | ||
use cw_orch::prelude::*; | ||
|
||
// Maybe uploadable can be autogenerated? | ||
// But this is fine to include in the client code | ||
|
||
#[cw_orch::interface(InstantiateMsg, ContractExecMsg, ContractQueryMsg, Empty)] | ||
pub struct MeshVault; | ||
|
||
impl<Chain> Uploadable for MeshVault<Chain> { | ||
/// Return the path to the wasm file corresponding to the contract | ||
fn wasm(_chain: &ChainInfoOwned) -> WasmPath { | ||
artifacts_dir_from_workspace!() | ||
.find_wasm_path("mesh_vault") | ||
.unwrap() | ||
} | ||
/// Returns a CosmWasm contract wrapper | ||
fn wrapper() -> Box<dyn MockContract<Empty>> { | ||
Box::new(ContractWrapper::new_with_empty(execute, instantiate, query)) | ||
} | ||
} | ||
|
||
// Autogenerating these Froms caused all kinds of rust compiler issues. | ||
// For now, I will just manually implement them to show what could work. | ||
// The following is done in Sylvia, ideally the other (interface) variants could be added there too: | ||
// impl From<ExecMsg> for ContractExecMsg | ||
|
||
// Since we know the regular structure here, this may be easy enough to | ||
// generate inside the `sv::messages` macro rather than the `contract` macro, eg. | ||
// #[sv::messages(cw20_marketing as Marketing)] | ||
// #[sv::messages(cw20_minting as Minting)] | ||
|
||
use mesh_apis::vault_api::sv::{VaultApiExecMsg, VaultApiQueryMsg, VaultApiSudoMsg}; | ||
|
||
impl From<VaultApiExecMsg> for ContractExecMsg { | ||
fn from(msg: VaultApiExecMsg) -> Self { | ||
ContractExecMsg::VaultApi(msg) | ||
} | ||
} | ||
|
||
impl From<VaultApiQueryMsg> for ContractQueryMsg { | ||
fn from(msg: VaultApiQueryMsg) -> Self { | ||
ContractQueryMsg::VaultApi(msg) | ||
} | ||
} | ||
|
||
impl From<VaultApiSudoMsg> for ContractSudoMsg { | ||
fn from(msg: VaultApiSudoMsg) -> Self { | ||
ContractSudoMsg::VaultApi(msg) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use cosmwasm_std::coin; | ||
// use cw_orch::environment::IndexResponse; | ||
use cw_orch::prelude::*; | ||
|
||
use crate::orch::MeshVault; | ||
|
||
use crate::contract::sv::{ExecMsgFns, InstantiateMsg, QueryMsgFns}; | ||
|
||
// TODO: shared variable | ||
const BECH_PREFIX: &str = "osmo"; | ||
|
||
#[test] | ||
fn happy_path_works() { | ||
let denom = "uosmo"; | ||
let chain = MockBech32::new(BECH_PREFIX); | ||
chain | ||
.add_balance(&chain.sender(), vec![coin(1_000_000, denom)]) | ||
.unwrap(); | ||
|
||
let contract = MeshVault::new("vault", chain.clone()); | ||
contract.upload().unwrap(); | ||
let msg = InstantiateMsg { | ||
denom: denom.to_string(), | ||
local_staking: None, | ||
}; | ||
contract.instantiate(&msg, None, None).unwrap(); | ||
|
||
let cfg = contract.config().unwrap(); | ||
println!("{:?}", cfg); | ||
|
||
let account = contract.account(chain.sender().into()).unwrap(); | ||
assert_eq!(account.bonded.u128(), 0u128); | ||
|
||
contract.bond(&[coin(400_000, denom)]).unwrap(); | ||
|
||
let account = contract.account(chain.sender().into()).unwrap(); | ||
assert_eq!(account.bonded.u128(), 400_000u128); | ||
} |