diff --git a/contracts/cw-storage/src/contract.rs b/contracts/cw-storage/src/contract.rs index 6db50f1c..c9e4b899 100644 --- a/contracts/cw-storage/src/contract.rs +++ b/contracts/cw-storage/src/contract.rs @@ -121,6 +121,7 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { match msg { QueryMsg::Bucket {} => to_binary(&query::bucket(deps)?), QueryMsg::Object { id } => to_binary(&query::object(deps, id)?), + QueryMsg::ObjectData { id } => to_binary(&query::data(deps, id)?), _ => Err(StdError::generic_err("Not implemented")), } } @@ -154,6 +155,10 @@ pub mod query { .is_some(), }) } + + pub fn data(deps: Deps, id: ObjectId) -> StdResult { + DATA.load(deps.storage, id).map(Binary::from) + } } #[cfg(test)] @@ -458,4 +463,41 @@ mod tests { assert!(!res.is_pinned); assert_eq!(res.size.u128(), 4u128); } + + #[test] + fn object_data() { + let mut deps = mock_dependencies(); + let info = mock_info("creator", &[]); + + let msg = InstantiateMsg { + bucket: String::from("test"), + limits: BucketLimits::new(), + }; + instantiate(deps.as_mut(), mock_env(), info.clone(), msg).unwrap(); + + match query::object( + deps.as_ref(), + ObjectId::from("315d0d9ab12c5f8884100055f79de50b72db4bd2c9bfd3df049d89640fed1fa6"), + ) + .err() + .unwrap() + { + NotFound { .. } => (), + _ => panic!("assertion failed"), + } + + let data = general_purpose::STANDARD.encode("okp4"); + let msg = ExecuteMsg::StoreObject { + data: Binary::from_base64(data.as_str()).unwrap(), + pin: false, + }; + execute(deps.as_mut(), mock_env(), info, msg).unwrap(); + + let res = query::data( + deps.as_ref(), + ObjectId::from("315d0d9ab12c5f8884100055f79de50b72db4bd2c9bfd3df049d89640fed1fa6"), + ) + .unwrap(); + assert_eq!(res, Binary::from_base64(data.as_str()).unwrap()); + } }