Skip to content

Commit 0734b58

Browse files
committed
fix(storage): ensure max objects limit
1 parent 4d0f17e commit 0734b58

File tree

1 file changed

+82
-12
lines changed

1 file changed

+82
-12
lines changed

contracts/cw-storage/src/contract.rs

+82-12
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ pub mod execute {
6969
Limits {
7070
max_objects: Some(max),
7171
..
72-
} if object_count as u128 > max.u128() => {
72+
} if object_count as u128 >= max.u128() => {
7373
Err(BucketError::MaxObjectsLimitExceeded.into())
7474
}
7575
Limits {
@@ -355,16 +355,80 @@ mod tests {
355355
#[test]
356356
fn store_object_limits() {
357357
let cases = vec![
358-
(BucketLimits {max_objects: Some(2u128.into()), max_object_size: None, max_total_size: None, max_object_pins: None}, None),
359-
(BucketLimits {max_objects: None, max_object_size: Some(5u128.into()), max_total_size: None, max_object_pins: None}, None),
360-
(BucketLimits {max_objects: None, max_object_size: None, max_total_size: Some(9u128.into()), max_object_pins: None}, None),
361-
(BucketLimits {max_objects: None, max_object_size: None, max_total_size: None, max_object_pins: Some(1u128.into())}, None),
362-
(BucketLimits {max_objects: Some(1u128.into()), max_object_size: None, max_total_size: None, max_object_pins: None}, Some(MaxObjectsLimitExceeded {})),
363-
(BucketLimits {max_objects: None, max_object_size: Some(4u128.into()), max_total_size: None, max_object_pins: None}, Some(ObjectMaxSizeLimitExceeded {})),
364-
(BucketLimits {max_objects: None, max_object_size: None, max_total_size: Some(8u128.into()), max_object_pins: None}, Some(BucketSizeLimitExceeded {})),
365-
(BucketLimits {max_objects: None, max_object_size: None, max_total_size: None, max_object_pins: Some(0u128.into())}, Some(MaxObjectPinsLimitExceeded {})),
358+
(
359+
BucketLimits {
360+
max_objects: Some(2u128.into()),
361+
max_object_size: None,
362+
max_total_size: None,
363+
max_object_pins: None,
364+
},
365+
None,
366+
),
367+
(
368+
BucketLimits {
369+
max_objects: None,
370+
max_object_size: Some(5u128.into()),
371+
max_total_size: None,
372+
max_object_pins: None,
373+
},
374+
None,
375+
),
376+
(
377+
BucketLimits {
378+
max_objects: None,
379+
max_object_size: None,
380+
max_total_size: Some(9u128.into()),
381+
max_object_pins: None,
382+
},
383+
None,
384+
),
385+
(
386+
BucketLimits {
387+
max_objects: None,
388+
max_object_size: None,
389+
max_total_size: None,
390+
max_object_pins: Some(1u128.into()),
391+
},
392+
None,
393+
),
394+
(
395+
BucketLimits {
396+
max_objects: Some(1u128.into()),
397+
max_object_size: None,
398+
max_total_size: None,
399+
max_object_pins: None,
400+
},
401+
Some(MaxObjectsLimitExceeded {}),
402+
),
403+
(
404+
BucketLimits {
405+
max_objects: None,
406+
max_object_size: Some(4u128.into()),
407+
max_total_size: None,
408+
max_object_pins: None,
409+
},
410+
Some(ObjectMaxSizeLimitExceeded {}),
411+
),
412+
(
413+
BucketLimits {
414+
max_objects: None,
415+
max_object_size: None,
416+
max_total_size: Some(8u128.into()),
417+
max_object_pins: None,
418+
},
419+
Some(BucketSizeLimitExceeded {}),
420+
),
421+
(
422+
BucketLimits {
423+
max_objects: None,
424+
max_object_size: None,
425+
max_total_size: None,
426+
max_object_pins: Some(0u128.into()),
427+
},
428+
Some(MaxObjectPinsLimitExceeded {}),
429+
),
366430
];
367-
431+
368432
let obj1 = general_purpose::STANDARD.encode("okp4");
369433
let obj2 = general_purpose::STANDARD.encode("hello");
370434

@@ -378,9 +442,15 @@ mod tests {
378442
};
379443
instantiate(deps.as_mut(), mock_env(), info.clone(), msg).unwrap();
380444

381-
let msg = ExecuteMsg::StoreObject { data: Binary::from_base64(obj1.as_str()).unwrap(), pin: false };
445+
let msg = ExecuteMsg::StoreObject {
446+
data: Binary::from_base64(obj1.as_str()).unwrap(),
447+
pin: false,
448+
};
382449
execute(deps.as_mut(), mock_env(), info.clone(), msg).unwrap();
383-
let msg = ExecuteMsg::StoreObject { data: Binary::from_base64(obj2.as_str()).unwrap(), pin: true };
450+
let msg = ExecuteMsg::StoreObject {
451+
data: Binary::from_base64(obj2.as_str()).unwrap(),
452+
pin: true,
453+
};
384454
let res = execute(deps.as_mut(), mock_env(), info.clone(), msg);
385455

386456
assert_eq!(res.err(), case.1);

0 commit comments

Comments
 (0)