Skip to content

Commit

Permalink
test: fix cargo lock and fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
dudong2 committed Apr 18, 2023
1 parent 34416b9 commit 359fcc3
Show file tree
Hide file tree
Showing 22 changed files with 48 additions and 21 deletions.
1 change: 1 addition & 0 deletions contracts/call-number/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions contracts/crypto-verify/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions contracts/cyberpunk/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions contracts/dynamic-callee-contract/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions contracts/dynamic-caller-contract/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions contracts/events/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions contracts/floaty/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions contracts/hackatom/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions contracts/ibc-reflect-send/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions contracts/ibc-reflect/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions contracts/intermediate-number/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions contracts/number/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions contracts/reflect/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions contracts/simple-callee/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions contracts/staking/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions contracts/voting-with-uuid/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 11 additions & 5 deletions packages/storage/src/bucket.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use serde::{de::DeserializeOwned, ser::Serialize};
use std::marker::PhantomData;
use std::any::type_name;
use serde_json::to_vec;
use std::any::type_name;
use std::marker::PhantomData;

use cosmwasm_std::{StdError, StdResult, Storage};
#[cfg(feature = "iterator")]
use cosmwasm_std::{Order, Record};
use cosmwasm_std::{StdError, StdResult, Storage};

use crate::length_prefixed::{to_length_prefixed, to_length_prefixed_nested};
#[cfg(feature = "iterator")]
Expand Down Expand Up @@ -63,7 +63,12 @@ where

/// save will serialize the model and store, returns an error on serialization issues
pub fn save(&mut self, key: &[u8], data: &T) -> StdResult<()> {
set_with_prefix(self.storage, &self.prefix, key, &to_vec(data).map_err(|e| StdError::serialize_err(type_name::<T>(), e))?);
set_with_prefix(
self.storage,
&self.prefix,
key,
&to_vec(data).map_err(|e| StdError::serialize_err(type_name::<T>(), e))?,
);
Ok(())
}

Expand Down Expand Up @@ -387,7 +392,8 @@ mod tests {
return Err(StdError::generic_err("Current age is negative").into());
}
if data.age > 10 {
to_vec(&data).map_err(|e| StdError::serialize_err(type_name::<Data>(), e))?; // Uses From to convert StdError to MyError
to_vec(&data).map_err(|e| StdError::serialize_err(type_name::<Data>(), e))?;
// Uses From to convert StdError to MyError
}
data.age += 1;
Ok(data)
Expand Down
12 changes: 8 additions & 4 deletions packages/storage/src/singleton.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use serde::{de::DeserializeOwned, ser::Serialize};
use std::marker::PhantomData;
use std::any::type_name;
use serde_json::to_vec;
use std::any::type_name;
use std::marker::PhantomData;

use cosmwasm_std::{StdError, StdResult, Storage};

Expand Down Expand Up @@ -52,7 +52,10 @@ where

/// save will serialize the model and store, returns an error on serialization issues
pub fn save(&mut self, data: &T) -> StdResult<()> {
self.storage.set(&self.key, &to_vec(data).map_err(|e| StdError::serialize_err(type_name::<T>(), e))?);
self.storage.set(
&self.key,
&to_vec(data).map_err(|e| StdError::serialize_err(type_name::<T>(), e))?,
);
Ok(())
}

Expand Down Expand Up @@ -298,7 +301,8 @@ mod tests {
return Err(StdError::generic_err("broken stuff").into()); // Uses Into to convert StdError to MyError
}
if c.max_tokens > 10 {
to_vec(&c).map_err(|e| StdError::serialize_err(type_name::<Config>(), e))?; // Uses From to convert StdError to MyError
to_vec(&c).map_err(|e| StdError::serialize_err(type_name::<Config>(), e))?;
// Uses From to convert StdError to MyError
}
c.max_tokens += 20;
Ok(c)
Expand Down
6 changes: 4 additions & 2 deletions packages/storage/src/type_helpers.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use serde::de::DeserializeOwned;
use std::any::type_name;
use serde_json::from_slice;
use std::any::type_name;

#[cfg(feature = "iterator")]
use cosmwasm_std::Record;
Expand All @@ -14,7 +14,9 @@ pub(crate) fn may_deserialize<T: DeserializeOwned>(
value: &Option<Vec<u8>>,
) -> StdResult<Option<T>> {
match value {
Some(data) => Ok(Some(from_slice(data).map_err(|e| StdError::parse_err(type_name::<T>(), e))?)),
Some(data) => Ok(Some(
from_slice(data).map_err(|e| StdError::parse_err(type_name::<T>(), e))?,
)),
None => Ok(None),
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/vm/benches/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::thread;
use std::time::{Duration, SystemTime};
use tempfile::TempDir;

use crate::serde::to_vec;
use cosmwasm_std::{coins, Addr, Empty};
use cosmwasm_vm::testing::{
mock_backend, mock_env, mock_info, mock_instance, mock_instance_options,
Expand All @@ -17,7 +18,6 @@ use cosmwasm_vm::{
Backend, BackendApi, BackendError, BackendResult, Cache, CacheOptions, Checksum, Environment,
FunctionMetadata, GasInfo, Instance, InstanceOptions, Querier, Size, Storage, WasmerVal,
};
use crate::serde::to_vec;
use std::cell::RefCell;
use wasmer::Module;
use wasmer_types::Type;
Expand Down
11 changes: 4 additions & 7 deletions packages/vm/src/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use crate::memory::{read_region, write_region};
use crate::sections::decode_sections;
#[allow(unused_imports)]
use crate::sections::encode_sections;
use crate::serde::{to_vec, from_slice};
use crate::serde::{from_slice, to_vec};
use crate::GasInfo;

/// A kibi (kilo binary)
Expand Down Expand Up @@ -1811,8 +1811,7 @@ mod tests {
let response_ptr = do_query_chain(&env, request_ptr).unwrap();
let response = force_read(&env, response_ptr);

let query_result: cosmwasm_std::QuerierResult =
from_slice(&response, usize::MAX).unwrap();
let query_result: cosmwasm_std::QuerierResult = from_slice(&response, usize::MAX).unwrap();
let query_result_inner = query_result.unwrap();
let query_result_inner_inner = query_result_inner.unwrap();
let parsed_again: AllBalanceResponse = from_binary(&query_result_inner_inner).unwrap();
Expand All @@ -1832,8 +1831,7 @@ mod tests {
let response_ptr = do_query_chain(&env, request_ptr).unwrap();
let response = force_read(&env, response_ptr);

let query_result: cosmwasm_std::QuerierResult =
from_slice(&response, usize::MAX).unwrap();
let query_result: cosmwasm_std::QuerierResult = from_slice(&response, usize::MAX).unwrap();
match query_result {
SystemResult::Ok(_) => panic!("This must not succeed"),
SystemResult::Err(SystemError::InvalidRequest { request: err, .. }) => {
Expand All @@ -1860,8 +1858,7 @@ mod tests {
let response_ptr = do_query_chain(&env, request_ptr).unwrap();
let response = force_read(&env, response_ptr);

let query_result: cosmwasm_std::QuerierResult =
from_slice(&response, usize::MAX).unwrap();
let query_result: cosmwasm_std::QuerierResult = from_slice(&response, usize::MAX).unwrap();
match query_result {
SystemResult::Ok(_) => panic!("This must not succeed"),
SystemResult::Err(SystemError::NoSuchContract { addr }) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/vm/src/testing/querier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use serde::de::DeserializeOwned;

use cosmwasm_std::testing::{MockQuerier as StdMockQuerier, MockQuerierCustomHandlerResult};
use cosmwasm_std::{
to_binary, Binary, Coin, ContractResult, CustomQuery, Empty, Querier as _,
QueryRequest, SystemError, SystemResult,
to_binary, Binary, Coin, ContractResult, CustomQuery, Empty, Querier as _, QueryRequest,
SystemError, SystemResult,
};

use crate::serde::to_vec;
Expand Down

0 comments on commit 359fcc3

Please sign in to comment.