Skip to content

Commit 46ab1e9

Browse files
authoredNov 15, 2023
Merge pull request #418 from okp4/dependabot/cargo/cw-storage-plus-1.2.0
2 parents 00016db + 723c453 commit 46ab1e9

File tree

4 files changed

+60
-38
lines changed

4 files changed

+60
-38
lines changed
 

‎Cargo.lock

+7-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ cosmwasm-schema = "1.5.0"
66
cosmwasm-std = "1.4.1"
77
cosmwasm-storage = "1.4.1"
88
cw-multi-test = "0.15.1"
9-
cw-storage-plus = "1.1.0"
9+
cw-storage-plus = "1.2.0"
1010
cw-utils = "1.0.2"
1111
cw2 = "1.1.1"
1212
okp4-logic-bindings = { path = "packages/okp4-logic-bindings" }

‎contracts/okp4-cognitarium/src/rdf/atom.rs

-2
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,6 @@ impl<'a> From<&'a Atom> for Triple<'a> {
8787
#[cfg(test)]
8888
mod tests {
8989
use super::*;
90-
use crate::msg::IRI;
91-
use crate::rdf::PrefixMap;
9290

9391
#[test]
9492
fn proper_display() {

‎contracts/okp4-objectarium/src/contract.rs

+52-28
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ pub mod execute {
6161
use crate::msg;
6262
use crate::state::BucketLimits;
6363
use crate::ContractError::ObjectPinned;
64-
use cosmwasm_std::{Order, StdError, Uint128};
65-
use std::any::type_name;
64+
use cosmwasm_std::{Order, Uint128};
6665

6766
pub fn store_object(
6867
deps: DepsMut<'_>,
@@ -118,6 +117,7 @@ pub mod execute {
118117
// store object data
119118
let id = crypto::hash(&bucket.config.hash_algorithm.into(), &data.0);
120119
let data_path = DATA.key(id.clone());
120+
121121
if data_path.has(deps.storage) {
122122
return Err(ContractError::Bucket(BucketError::ObjectAlreadyStored));
123123
}
@@ -178,22 +178,25 @@ pub mod execute {
178178
return Ok(res);
179179
}
180180

181-
let o = objects().update(deps.storage, id.clone(), |o| -> Result<Object, StdError> {
182-
o.map(|mut e: Object| -> Object {
183-
e.pin_count += Uint128::one();
184-
e
185-
})
186-
.ok_or_else(|| StdError::not_found(type_name::<Object>()))
187-
})?;
181+
let object = objects().load(deps.storage, id.clone())?;
182+
let mut updated_object = object.clone();
183+
updated_object.pin_count += Uint128::one();
184+
185+
objects().replace(
186+
deps.storage,
187+
id.clone(),
188+
Some(&updated_object),
189+
Some(&object),
190+
)?;
188191

189192
let bucket = BUCKET.load(deps.storage)?;
190193

191194
match bucket.limits {
192195
BucketLimits {
193196
max_object_pins: Some(max),
194197
..
195-
} if max < o.pin_count => {
196-
Err(BucketError::MaxObjectPinsLimitExceeded(o.pin_count, max).into())
198+
} if max < updated_object.pin_count => {
199+
Err(BucketError::MaxObjectPinsLimitExceeded(updated_object.pin_count, max).into())
197200
}
198201
_ => {
199202
pins().save(
@@ -413,7 +416,6 @@ impl From<state::HashAlgorithm> for crypto::HashAlgorithm {
413416
#[cfg(test)]
414417
mod tests {
415418
use super::*;
416-
use crate::crypto::Hash;
417419
use crate::error::BucketError;
418420
use crate::msg::{
419421
BucketConfig, BucketLimitsBuilder, BucketResponse, CompressionAlgorithm, HashAlgorithm,
@@ -425,6 +427,24 @@ mod tests {
425427
use cosmwasm_std::{from_binary, Attribute, Order, StdError, Uint128};
426428
use std::any::type_name;
427429

430+
fn decode_hex(hex: &str) -> Vec<u8> {
431+
base16ct::lower::decode_vec(hex).unwrap()
432+
}
433+
434+
fn with_namespace(key: &[u8]) -> Vec<u8> {
435+
let namespace = decode_hex("00064f424a454354");
436+
let mut v = Vec::with_capacity(namespace.len() + key.len());
437+
v.extend(namespace);
438+
v.extend_from_slice(key);
439+
v
440+
}
441+
442+
fn not_found_object_info<T>(hex: &str) -> String {
443+
let type_name = type_name::<T>();
444+
let key = with_namespace(&decode_hex(hex));
445+
format!("type: {type_name}; key: {:02X?}", key)
446+
}
447+
428448
#[test]
429449
fn proper_initialization() {
430450
let mut deps = mock_dependencies();
@@ -617,10 +637,6 @@ mod tests {
617637
assert_eq!("foobar", value.name);
618638
}
619639

620-
fn decode_hash(hash: String) -> Hash {
621-
base16ct::lower::decode_vec(hash).unwrap().into()
622-
}
623-
624640
#[test]
625641
fn store_object_without_limits() {
626642
let obj1_content = &general_purpose::STANDARD.encode("hello");
@@ -762,15 +778,15 @@ mod tests {
762778
assert_eq!(
763779
Binary::from_base64(content).unwrap(),
764780
Binary::from(
765-
DATA.load(&deps.storage, decode_hash(expected_hash.clone()))
781+
DATA.load(&deps.storage, decode_hex(&expected_hash).into())
766782
.unwrap()
767783
),
768784
);
769785

770786
let created = objects()
771-
.load(&deps.storage, decode_hash(expected_hash.clone()))
787+
.load(&deps.storage, decode_hex(&expected_hash).into())
772788
.unwrap();
773-
assert_eq!(created.id, decode_hash(expected_hash.to_string()));
789+
assert_eq!(created.id, decode_hex(&expected_hash).into());
774790
assert_eq!(created.owner, info.sender.clone());
775791
assert_eq!(created.size.u128(), *expected_size);
776792
assert_eq!(
@@ -785,7 +801,7 @@ mod tests {
785801
assert_eq!(
786802
pins().has(
787803
&deps.storage,
788-
(decode_hash(expected_hash.to_string()), info.clone().sender),
804+
(decode_hex(&expected_hash).into(), info.clone().sender),
789805
),
790806
*pin,
791807
);
@@ -1422,7 +1438,9 @@ mod tests {
14221438
senders: vec![mock_info("bob", &[])],
14231439
expected_count: 0,
14241440
expected_error: Some(ContractError::Std(StdError::not_found(
1425-
type_name::<Object>(),
1441+
not_found_object_info::<Object>(
1442+
"abafa4428bdc8c34dae28bbc17303a62175f274edf59757b3e9898215a428a56",
1443+
),
14261444
))),
14271445
expected_object_pin_count: vec![(
14281446
ObjectId::from(
@@ -1520,7 +1538,7 @@ mod tests {
15201538
for (object_id, count) in case.expected_object_pin_count {
15211539
assert_eq!(
15221540
objects()
1523-
.load(&deps.storage, decode_hash(object_id))
1541+
.load(&deps.storage, decode_hex(&object_id).into())
15241542
.unwrap()
15251543
.pin_count,
15261544
count
@@ -1689,7 +1707,9 @@ mod tests {
16891707
unpin_senders: vec![mock_info("martin", &[])],
16901708
expected_count: 1,
16911709
expected_error: Some(ContractError::Std(StdError::not_found(
1692-
type_name::<Object>(),
1710+
not_found_object_info::<Object>(
1711+
"abafa4428bdc8c34dae28bbc17303a62175f274edf59757b3e9898215a428a56",
1712+
),
16931713
))),
16941714
expected_object_pin_count: vec![(
16951715
ObjectId::from(
@@ -1801,7 +1821,7 @@ mod tests {
18011821
for (object_id, count) in case.expected_object_pin_count {
18021822
assert_eq!(
18031823
objects()
1804-
.load(&deps.storage, decode_hash(object_id))
1824+
.load(&deps.storage, decode_hex(&object_id).into())
18051825
.unwrap()
18061826
.pin_count,
18071827
count
@@ -2073,7 +2093,9 @@ mod tests {
20732093
after: None,
20742094
first: None,
20752095
},
2076-
ContractError::Std(StdError::not_found(type_name::<Object>())),
2096+
ContractError::Std(StdError::not_found(not_found_object_info::<Object>(
2097+
"abafa4428bdc8c34dae28bbc17303a62175f274edf59757b3e9898215a428a56",
2098+
))),
20772099
),
20782100
(
20792101
QueryMsg::ObjectPins {
@@ -2195,7 +2217,9 @@ mod tests {
21952217
expected_count: 3,
21962218
expected_total_size: Uint128::new(13),
21972219
expected_error: Some(ContractError::Std(StdError::not_found(
2198-
type_name::<Object>(),
2220+
not_found_object_info::<Object>(
2221+
"abafa4428bdc8c34dae28bbc17303a62175f274edf59757b3e9898215a428a56",
2222+
),
21992223
))),
22002224
},
22012225
TC {
@@ -2296,9 +2320,9 @@ mod tests {
22962320
for object_id in case.forget_objects {
22972321
assert_eq!(
22982322
objects()
2299-
.load(&deps.storage, decode_hash(object_id))
2323+
.load(&deps.storage, decode_hex(object_id.as_str()).into())
23002324
.unwrap_err(),
2301-
StdError::not_found(type_name::<Object>())
2325+
StdError::not_found(not_found_object_info::<Object>(&object_id))
23022326
);
23032327
}
23042328
}

0 commit comments

Comments
 (0)
Please sign in to comment.