Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Objectarium] 🐛 fix: compression size decrement on forget_object #570

Merged
merged 2 commits into from
Jun 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 52 additions & 14 deletions contracts/axone-objectarium/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})?;

Expand Down Expand Up @@ -2200,6 +2201,7 @@ mod tests {
forget_senders: Vec<MessageInfo>,
expected_count: usize,
expected_total_size: Uint128,
expected_compressed_size: Uint128,
expected_error: Option<ContractError>,
}

Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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::<Object>(
"abafa4428bdc8c34dae28bbc17303a62175f274edf59757b3e9898215a428a56",
Expand All @@ -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::<Vec<u8>>(),
"invalid Base16 encoding".to_string(),
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
}
}

Expand Down
Loading