Skip to content

Commit

Permalink
Testcase for new multitest query
Browse files Browse the repository at this point in the history
  • Loading branch information
ueco-jb committed Nov 16, 2021
1 parent 27e9712 commit 6df19ad
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/multi-test/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl BankKeeper {

// this is an "admin" function to let us adjust bank accounts
fn get_balance(&self, bank_storage: &dyn Storage, account: &Addr) -> AnyResult<Vec<Coin>> {
let val = BALANCES.may_load(bank_storage, &account)?;
let val = BALANCES.may_load(bank_storage, account)?;
Ok(val.unwrap_or_default().into_vec())
}

Expand Down
4 changes: 2 additions & 2 deletions packages/multi-test/src/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ impl Op {
/// applies this `Op` to the provided storage
pub fn apply(&self, storage: &mut dyn Storage) {
match self {
Op::Set { key, value } => storage.set(&key, &value),
Op::Delete { key } => storage.remove(&key),
Op::Set { key, value } => storage.set(key, value),
Op::Delete { key } => storage.remove(key),
}
}

Expand Down
40 changes: 39 additions & 1 deletion packages/multi-test/src/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ where

pub fn query_raw(&self, address: Addr, storage: &dyn Storage, key: &[u8]) -> Binary {
let storage = self.contract_storage_readonly(storage, &address);
let data = storage.get(&key).unwrap_or_default();
let data = storage.get(key).unwrap_or_default();
data.into()
}

Expand Down Expand Up @@ -1031,6 +1031,44 @@ mod test {
);
}

#[test]
fn query_contract_into() {
let api = MockApi::default();
let mut keeper = WasmKeeper::<Empty, Empty>::new();
let block = mock_env().block;
let code_id = keeper.store_code(payout::contract());

let mut wasm_storage = MockStorage::new();

let contract_addr = keeper
.register_contract(
&mut wasm_storage,
code_id,
Addr::unchecked("foobar"),
Addr::unchecked("admin"),
"label".to_owned(),
1000,
)
.unwrap();

let querier: MockQuerier<Empty> = MockQuerier::new(&[]);
let query = WasmQuery::ContractInfo {
contract_addr: contract_addr.to_string(),
};
let info = keeper
.query(&api, &wasm_storage, &querier, &block, query)
.unwrap();

let expected = ContractInfoResponse {
code_id: code_id as u64,
creator: "foobar".to_owned(),
admin: Some("admin".to_owned()),
pinned: false,
ibc_port: None,
};
assert_eq!(expected, from_slice(&info).unwrap());
}

#[test]
fn contract_send_coins() {
let api = MockApi::default();
Expand Down

0 comments on commit 6df19ad

Please sign in to comment.