diff --git a/contracts/cw-storage/src/contract.rs b/contracts/cw-storage/src/contract.rs index f1056410..d40b7d5a 100644 --- a/contracts/cw-storage/src/contract.rs +++ b/contracts/cw-storage/src/contract.rs @@ -20,10 +20,10 @@ const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION"); pub fn instantiate( deps: DepsMut, _env: Env, - _info: MessageInfo, + info: MessageInfo, msg: InstantiateMsg, ) -> Result { - let bucket = Bucket::new(msg.bucket, msg.limits.into())?; + let bucket = Bucket::new(info.sender, msg.bucket, msg.limits.into())?; set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?; BUCKET.save(deps.storage, &bucket)?; @@ -191,6 +191,12 @@ mod tests { let res = query(deps.as_ref(), mock_env(), QueryMsg::Bucket {}).unwrap(); let value: BucketResponse = from_binary(&res).unwrap(); assert_eq!("foo", value.name); + + // check internal state too + let bucket = BUCKET.load(&deps.storage).unwrap(); + assert_eq!("creator", bucket.owner.into_string()); + assert_eq!(Uint128::zero(), bucket.stat.size); + assert_eq!(Uint128::zero(), bucket.stat.object_count); } #[test] diff --git a/contracts/cw-storage/src/state.rs b/contracts/cw-storage/src/state.rs index cf354c49..058408bf 100644 --- a/contracts/cw-storage/src/state.rs +++ b/contracts/cw-storage/src/state.rs @@ -10,6 +10,8 @@ pub const DATA: Map> = Map::new("DATA"); #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] pub struct Bucket { + /// The owner of the bucket. + pub owner: Addr, /// The name of the bucket. pub name: String, /// The limits of the bucket. @@ -27,13 +29,14 @@ pub struct BucketStat { } impl Bucket { - pub fn new(name: String, limits: Limits) -> Result { + pub fn new(owner: Addr, name: String, limits: Limits) -> Result { let n: String = name.split_whitespace().collect(); if n.is_empty() { return Err(EmptyName); } Ok(Self { + owner, name: n, limits, stat: BucketStat {