Skip to content

Commit a0e9137

Browse files
committed
Start removing custom protobuf code
1 parent 725fb14 commit a0e9137

File tree

3 files changed

+7
-19
lines changed

3 files changed

+7
-19
lines changed

packages/multi-test/src/executor.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use std::fmt;
22

3-
use crate::parse_contract_addr;
43
use cosmwasm_std::{
54
to_binary, Addr, Attribute, BankMsg, Binary, Coin, CosmosMsg, Event, SubMsgExecutionResponse,
65
WasmMsg,
76
};
7+
use cw0::parse_instantiate_response_data;
88
use schemars::JsonSchema;
99
use serde::Serialize;
1010

@@ -91,7 +91,8 @@ where
9191
label: label.into(),
9292
};
9393
let res = self.execute(sender, msg.into())?;
94-
parse_contract_addr(&res.data)
94+
let data = parse_instantiate_response_data(res.data.unwrap_or_default().as_slice())?;
95+
Ok(Addr::unchecked(data.contract_address))
9596
}
9697

9798
/// Execute a contract and process all returned messages.

packages/multi-test/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ pub use crate::contracts::{Contract, ContractWrapper};
2828
pub use crate::executor::{AppResponse, Executor};
2929
pub use crate::module::Module;
3030
pub use crate::staking::{FailingDistribution, FailingStaking, Staking, StakingSudo};
31-
pub use crate::wasm::{parse_contract_addr, Wasm, WasmKeeper, WasmSudo};
31+
pub use crate::wasm::{Wasm, WasmKeeper, WasmSudo};

packages/multi-test/src/wasm.rs

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ use crate::executor::AppResponse;
2323
use crate::transactions::transactional;
2424
use cosmwasm_std::testing::mock_wasmd_attr;
2525

26-
use anyhow::{anyhow, bail, Result as AnyResult};
27-
use cw0::parse_instantiate_response_data;
26+
use anyhow::{bail, Result as AnyResult};
2827

2928
// Contract state is kept in Storage, separate from the contracts themselves
3029
const CONTRACTS: Map<&Addr, ContractData> = Map::new("contracts");
@@ -836,6 +835,8 @@ where
836835
}
837836
}
838837

838+
// TODO: replace with code in cw0
839+
839840
#[derive(Clone, PartialEq, Message)]
840841
pub struct InstantiateData {
841842
#[prost(string, tag = "1")]
@@ -857,20 +858,6 @@ fn init_response(res: &mut AppResponse, contact_address: &Addr) {
857858
res.data = Some(new_data.into());
858859
}
859860

860-
// this parses the result from a wasm contract init
861-
pub fn parse_contract_addr(data: &Option<Binary>) -> AnyResult<Addr> {
862-
let bin = data
863-
.as_ref()
864-
.ok_or_else(|| anyhow!("No data response"))?
865-
.to_vec();
866-
// parse the protobuf struct
867-
let init_data = parse_instantiate_response_data(bin.as_slice())?;
868-
if init_data.contract_address.is_empty() {
869-
bail!("no contract address provided");
870-
}
871-
Ok(Addr::unchecked(init_data.contract_address))
872-
}
873-
874861
#[cfg(test)]
875862
mod test {
876863
use cosmwasm_std::testing::{mock_env, mock_info, MockApi, MockQuerier, MockStorage};

0 commit comments

Comments
 (0)