diff --git a/contracts/axone-objectarium/src/contract.rs b/contracts/axone-objectarium/src/contract.rs index f7a182ec..74242f07 100644 --- a/contracts/axone-objectarium/src/contract.rs +++ b/contracts/axone-objectarium/src/contract.rs @@ -229,6 +229,7 @@ pub mod execute { BUCKET.update(deps.storage, |mut b| -> Result<_, ContractError> { b.stat.object_count -= Uint128::one(); b.stat.size -= object.size; + b.stat.compressed_size -= object.compressed_size; Ok(b) })?; @@ -2200,6 +2201,7 @@ mod tests { forget_senders: Vec, expected_count: usize, expected_total_size: Uint128, + expected_compressed_size: Uint128, expected_error: Option, } @@ -2211,8 +2213,9 @@ mod tests { "315d0d9ab12c5f8884100055f79de50b72db4bd2c9bfd3df049d89640fed1fa6", )], forget_senders: vec![mock_info("bob", &[])], - expected_count: 2, - expected_total_size: Uint128::new(9), + expected_count: 3, + expected_total_size: Uint128::new(474), + expected_compressed_size: Uint128::new(418), expected_error: None, }, TC { @@ -2227,8 +2230,21 @@ mod tests { ), ], forget_senders: vec![mock_info("bob", &[]), mock_info("bob", &[])], - expected_count: 1, - expected_total_size: Uint128::new(4), + expected_count: 2, + expected_total_size: Uint128::new(469), + expected_compressed_size: Uint128::new(413), + expected_error: None, + }, + TC { + pins: vec![], + pins_senders: vec![], + forget_objects: vec![ObjectId::from( + "d1abcabb14dd23d2cf60472dffb4823be10ac20148e8ef7b9644cc14fcf8a073", + )], + forget_senders: vec![mock_info("bob", &[]), mock_info("bob", &[])], + expected_count: 3, + expected_total_size: Uint128::new(13), + expected_compressed_size: Uint128::new(13), expected_error: None, }, TC { @@ -2240,8 +2256,9 @@ mod tests { "315d0d9ab12c5f8884100055f79de50b72db4bd2c9bfd3df049d89640fed1fa6", )], forget_senders: vec![mock_info("alice", &[])], // the sender is different from the pinner, so error - expected_count: 3, - expected_total_size: Uint128::new(13), + expected_count: 4, + expected_total_size: Uint128::new(478), + expected_compressed_size: Uint128::new(422), expected_error: Some(ContractError::ObjectPinned {}), }, TC { @@ -2253,8 +2270,9 @@ mod tests { "315d0d9ab12c5f8884100055f79de50b72db4bd2c9bfd3df049d89640fed1fa6", )], forget_senders: vec![mock_info("bob", &[])], // the sender is the same as the pinner, so forget should work - expected_count: 2, - expected_total_size: Uint128::new(9), + expected_count: 3, + expected_total_size: Uint128::new(474), + expected_compressed_size: Uint128::new(418), expected_error: None, }, TC { @@ -2271,8 +2289,9 @@ mod tests { "315d0d9ab12c5f8884100055f79de50b72db4bd2c9bfd3df049d89640fed1fa6", )], forget_senders: vec![mock_info("bob", &[])], // the sender is the same as the pinner, but another pinner is on it so error - expected_count: 3, - expected_total_size: Uint128::new(13), + expected_count: 4, + expected_total_size: Uint128::new(478), + expected_compressed_size: Uint128::new(422), expected_error: Some(ContractError::ObjectPinned {}), }, TC { @@ -2289,8 +2308,9 @@ mod tests { "abafa4428bdc8c34dae28bbc17303a62175f274edf59757b3e9898215a428a56", )], forget_senders: vec![mock_info("bob", &[])], // the sender is the same as the pinner, but another pinner is on it so error - expected_count: 3, - expected_total_size: Uint128::new(13), + expected_count: 4, + expected_total_size: Uint128::new(478), + expected_compressed_size: Uint128::new(422), expected_error: Some(ContractError::Std(StdError::not_found( not_found_object_info::( "abafa4428bdc8c34dae28bbc17303a62175f274edf59757b3e9898215a428a56", @@ -2309,8 +2329,9 @@ mod tests { pins_senders: vec![mock_info("bob", &[]), mock_info("alice", &[])], forget_objects: vec![ObjectId::from("invalid id")], forget_senders: vec![mock_info("bob", &[])], // the sender is the same as the pinner, but another pinner is on it so error - expected_count: 3, - expected_total_size: Uint128::new(13), + expected_count: 4, + expected_total_size: Uint128::new(478), + expected_compressed_size: Uint128::new(422), expected_error: Some(ContractError::Std(StdError::parse_err( type_name::>(), "invalid Base16 encoding".to_string(), @@ -2359,6 +2380,22 @@ mod tests { }; let _ = execute(deps.as_mut(), mock_env(), info.clone(), msg).unwrap(); + let data = general_purpose::STANDARD.encode( + "In a magical land, there \ + were many realms, one of which was known as OKP4. Within this realm, druid programmers \ + possessed the power to create smart contracts. As the kingdom grew, the druids used \ + their skills to power decentralized systems, bringing prosperity and wonder to all who \ + sought their expertise. And so, the legend of the druid programmers and their magical \ + smart contracts lived on, inspiring future generations to unlock the power of the \ + digital realm.", + ); + let msg = ExecuteMsg::StoreObject { + data: Binary::from_base64(data.as_str()).unwrap(), + pin: false, + compression_algorithm: Some(CompressionAlgorithm::Snappy), + }; + let _ = execute(deps.as_mut(), mock_env(), info.clone(), msg).unwrap(); + case.pins .iter() .zip(case.pins_senders) @@ -2414,6 +2451,7 @@ mod tests { Uint128::from(case.expected_count as u128) ); assert_eq!(bucket.stat.size, case.expected_total_size); + assert_eq!(bucket.stat.compressed_size, case.expected_compressed_size); } }