Skip to content

Commit

Permalink
chore: cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
loloicci committed Feb 9, 2024
1 parent 7defcca commit f3231de
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 76 deletions.
42 changes: 14 additions & 28 deletions contracts/call-number/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ pub fn execute(

fn handle_add(deps: Deps, by: i32) -> Result<Response, ContractError> {
let address: Addr = from_json(
deps
.storage
deps.storage
.get(ADDRESS_KEY)
.ok_or(ContractError::StorageError)?,
)?;
Expand All @@ -77,8 +76,7 @@ fn handle_add(deps: Deps, by: i32) -> Result<Response, ContractError> {

fn handle_sub(deps: Deps, by: i32) -> Result<Response, ContractError> {
let address: Addr = from_json(
deps
.storage
deps.storage
.get(ADDRESS_KEY)
.ok_or(ContractError::StorageError)?,
)?;
Expand All @@ -100,8 +98,7 @@ fn handle_sub(deps: Deps, by: i32) -> Result<Response, ContractError> {

fn handle_mul(deps: Deps, by: i32) -> Result<Response, ContractError> {
let address: Addr = from_json(
deps
.storage
deps.storage
.get(ADDRESS_KEY)
.ok_or(ContractError::StorageError)?,
)?;
Expand All @@ -123,8 +120,7 @@ fn handle_mul(deps: Deps, by: i32) -> Result<Response, ContractError> {

fn handle_submsg_reply_add(deps: Deps, by: i32) -> Result<Response, ContractError> {
let address: Addr = from_json(
deps
.storage
deps.storage
.get(ADDRESS_KEY)
.ok_or(ContractError::StorageError)?,
)?;
Expand All @@ -138,8 +134,7 @@ fn handle_submsg_reply_add(deps: Deps, by: i32) -> Result<Response, ContractErro

fn handle_submsg_reply_sub(deps: Deps, by: i32) -> Result<Response, ContractError> {
let address: Addr = from_json(
deps
.storage
deps.storage
.get(ADDRESS_KEY)
.ok_or(ContractError::StorageError)?,
)?;
Expand All @@ -153,8 +148,7 @@ fn handle_submsg_reply_sub(deps: Deps, by: i32) -> Result<Response, ContractErro

fn handle_submsg_reply_mul(deps: Deps, by: i32) -> Result<Response, ContractError> {
let address: Addr = from_json(
deps
.storage
deps.storage
.get(ADDRESS_KEY)
.ok_or(ContractError::StorageError)?,
)?;
Expand All @@ -168,8 +162,7 @@ fn handle_submsg_reply_mul(deps: Deps, by: i32) -> Result<Response, ContractErro

fn handle_log_query(deps: Deps) -> Result<Response, ContractError> {
let address: Addr = from_json(
deps
.storage
deps.storage
.get(ADDRESS_KEY)
.ok_or(ContractError::StorageError)?,
)?;
Expand All @@ -184,8 +177,7 @@ fn handle_log_query(deps: Deps) -> Result<Response, ContractError> {

fn handle_log_query_dyn(deps: Deps) -> Result<Response, ContractError> {
let address: Addr = from_json(
deps
.storage
deps.storage
.get(ADDRESS_KEY)
.ok_or(ContractError::StorageError)?,
)?;
Expand All @@ -200,8 +192,7 @@ fn handle_log_query_dyn(deps: Deps) -> Result<Response, ContractError> {
#[entry_point]
pub fn reply(deps: DepsMut, _env: Env, _msg: Reply) -> Result<Response, ContractError> {
let address: Addr = from_json(
deps
.storage
deps.storage
.get(ADDRESS_KEY)
.ok_or(ContractError::StorageError)?,
)?;
Expand Down Expand Up @@ -232,8 +223,7 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> Result<Binary, ContractErr

fn query_number_dyn(deps: Deps) -> Result<NumberResponse, ContractError> {
let address: Addr = from_json(
deps
.storage
deps.storage
.get(ADDRESS_KEY)
.ok_or(ContractError::StorageError)?,
)?;
Expand All @@ -247,8 +237,7 @@ fn query_number_dyn(deps: Deps) -> Result<NumberResponse, ContractError> {
// https://github.com/Finschia/cosmwasm/blob/03abb0871ca5cfe8b874561795bc59d12562002f/packages/vm/src/dynamic_link.rs#L333-L336
fn query_add(deps: Deps, by: i32) -> Result<NumberResponse, ContractError> {
let address: Addr = from_json(
deps
.storage
deps.storage
.get(ADDRESS_KEY)
.ok_or(ContractError::StorageError)?,
)?;
Expand All @@ -263,8 +252,7 @@ fn query_add(deps: Deps, by: i32) -> Result<NumberResponse, ContractError> {
// https://github.com/Finschia/cosmwasm/blob/03abb0871ca5cfe8b874561795bc59d12562002f/packages/vm/src/dynamic_link.rs#L333-L336
fn query_sub(deps: Deps, by: i32) -> Result<NumberResponse, ContractError> {
let address: Addr = from_json(
deps
.storage
deps.storage
.get(ADDRESS_KEY)
.ok_or(ContractError::StorageError)?,
)?;
Expand All @@ -279,8 +267,7 @@ fn query_sub(deps: Deps, by: i32) -> Result<NumberResponse, ContractError> {
// https://github.com/Finschia/cosmwasm/blob/03abb0871ca5cfe8b874561795bc59d12562002f/packages/vm/src/dynamic_link.rs#L333-L336
fn query_mul(deps: Deps, by: i32) -> Result<NumberResponse, ContractError> {
let address: Addr = from_json(
deps
.storage
deps.storage
.get(ADDRESS_KEY)
.ok_or(ContractError::StorageError)?,
)?;
Expand All @@ -292,8 +279,7 @@ fn query_mul(deps: Deps, by: i32) -> Result<NumberResponse, ContractError> {

fn query_number(deps: Deps) -> Result<NumberResponse, ContractError> {
let address: Addr = from_json(
deps
.storage
deps.storage
.get(ADDRESS_KEY)
.ok_or(ContractError::StorageError)?,
)?;
Expand Down
16 changes: 4 additions & 12 deletions contracts/dynamic-callee-contract/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ fn make_callee_instance() -> Instance<MockApi, MockStorage, MockQuerier> {
let querier = MockQuerier::new(&[]);
let env = to_json_vec(&mock_env()).unwrap();
let contract = Contract::from_code(CONTRACT_CALLEE, &env, &options, None).unwrap();

contract.generate_instance(api, querier, &options).unwrap()
}

Expand Down Expand Up @@ -105,12 +105,8 @@ fn callable_point_pong_works() {
let required_exports = required_exports();
let export_index = 0;
assert_eq!("pong".to_string(), required_exports[export_index].0);
let call_result = call_function(
&mut instance,
"pong",
&[env_region_ptr, param_region_ptr],
)
.unwrap();
let call_result =
call_function(&mut instance, "pong", &[env_region_ptr, param_region_ptr]).unwrap();
assert_eq!(call_result.len(), 1);

let serialized_return =
Expand Down Expand Up @@ -212,11 +208,7 @@ fn callable_point_pong_with_tuple_takes_2_args_works() {
let call_result = call_function(
&mut instance,
"pong_with_tuple_takes_2_args",
&[
env_region_ptr,
param_region_ptr1,
param_region_ptr2,
],
&[env_region_ptr, param_region_ptr1, param_region_ptr2],
)
.unwrap();
assert_eq!(call_result.len(), 1);
Expand Down
21 changes: 7 additions & 14 deletions contracts/dynamic-caller-contract/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,7 @@ pub fn execute(

pub fn try_ping(deps: DepsMut, ping_num: Uint128) -> Result<Response, ContractError> {
let address: Addr = from_json(
deps
.storage
deps.storage
.get(b"dynamic_callee_contract")
.ok_or_else(|| ContractError::Storage("cannot get callee address".to_string()))?,
)?;
Expand Down Expand Up @@ -191,8 +190,7 @@ pub fn try_re_entrancy(deps: DepsMut, _env: Env) -> Result<Response, ContractErr
// It will be tried to call the should_never_be_called function below.
// But, should be blocked by VM host side normally because it's a reentrancy case.
let address = from_json(
deps
.storage
deps.storage
.get(b"dynamic_callee_contract")
.ok_or_else(|| ContractError::Storage("cannot get callee address".to_string()))?,
)?;
Expand All @@ -203,8 +201,7 @@ pub fn try_re_entrancy(deps: DepsMut, _env: Env) -> Result<Response, ContractErr

pub fn try_do_panic(deps: DepsMut, _env: Env) -> Result<Response, ContractError> {
let address = from_json(
deps
.storage
deps.storage
.get(b"dynamic_callee_contract")
.ok_or_else(|| ContractError::Storage("cannot get callee address".to_string()))?,
)?;
Expand All @@ -215,8 +212,7 @@ pub fn try_do_panic(deps: DepsMut, _env: Env) -> Result<Response, ContractError>

pub fn try_validate_interface(deps: Deps, _env: Env) -> Result<Response, ContractError> {
let address = from_json(
deps
.storage
deps.storage
.get(b"dynamic_callee_contract")
.ok_or_else(|| ContractError::Storage("cannot get callee address".to_string()))?,
)?;
Expand All @@ -228,8 +224,7 @@ pub fn try_validate_interface(deps: Deps, _env: Env) -> Result<Response, Contrac
// should error
pub fn try_validate_interface_err(deps: Deps, _env: Env) -> Result<Response, ContractError> {
let address = from_json(
deps
.storage
deps.storage
.get(b"dynamic_callee_contract")
.ok_or_else(|| ContractError::Storage("cannot get callee address".to_string()))?,
)?;
Expand All @@ -251,8 +246,7 @@ pub fn try_call_caller_address_of(
target: Addr,
) -> Result<Response, ContractError> {
let address: Addr = from_json(
deps
.storage
deps.storage
.get(b"dynamic_callee_contract")
.ok_or_else(|| ContractError::Storage("cannot get callee address".to_string()))?,
)?;
Expand Down Expand Up @@ -283,8 +277,7 @@ fn get_own_address_via_callees_get_caller_address(
_env: Env,
) -> Result<Binary, ContractError> {
let address: Addr = from_json(
deps
.storage
deps.storage
.get(b"dynamic_callee_contract")
.ok_or_else(|| ContractError::Storage("cannot get callee address".to_string()))?,
)?;
Expand Down
3 changes: 1 addition & 2 deletions contracts/intermediate-number/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,7 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> Result<Binary, ContractErr

fn query_number(deps: Deps) -> Result<NumberResponse, ContractError> {
let address: Addr = from_json(
deps
.storage
deps.storage
.get(ADDRESS_KEY)
.ok_or(ContractError::StorageError)?,
)
Expand Down
25 changes: 6 additions & 19 deletions contracts/number/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ fn make_number_instance() -> Instance<MockApi, MockStorage, MockQuerier> {
let env = to_json_vec(&mock_env()).unwrap();
let querier = MockQuerier::new(&[]);
let contract = Contract::from_code(CONTRACT, &env, &options, None).unwrap();


contract.generate_instance(api, querier, &options).unwrap()
}
Expand Down Expand Up @@ -76,12 +75,8 @@ fn callable_point_add_works() {

// Before solving #213, it issues an error.
// This is because `add` panics without number in deps.storage.
let call_result = call_function(
&mut instance,
"add",
&[env_region_ptr, param_region_ptr],
)
.unwrap_err();
let call_result =
call_function(&mut instance, "add", &[env_region_ptr, param_region_ptr]).unwrap_err();
assert!(call_result
.to_string()
.contains("RuntimeError: unreachable"))
Expand All @@ -104,12 +99,8 @@ fn callable_point_sub_works() {

// Before solving #213, it issues an error.
// This is because `sub` panics without number in deps.storage.
let call_result = call_function(
&mut instance,
"sub",
&[env_region_ptr, param_region_ptr],
)
.unwrap_err();
let call_result =
call_function(&mut instance, "sub", &[env_region_ptr, param_region_ptr]).unwrap_err();
assert!(call_result
.to_string()
.contains("RuntimeError: unreachable"))
Expand All @@ -132,12 +123,8 @@ fn callable_point_mul_works() {

// Before solving #213, it issues an error.
// This is because `mul` panics without number in deps.storage.
let call_result = call_function(
&mut instance,
"mul",
&[env_region_ptr, param_region_ptr],
)
.unwrap_err();
let call_result =
call_function(&mut instance, "mul", &[env_region_ptr, param_region_ptr]).unwrap_err();
assert!(call_result
.to_string()
.contains("RuntimeError: unreachable"))
Expand Down
1 change: 0 additions & 1 deletion contracts/simple-callee/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ fn make_instance() -> Instance<MockApi, MockStorage, MockQuerier> {
let api = MockApi::default();
let querier = MockQuerier::new(&[]);
let contract = Contract::from_code(CONTRACT, &env, &options, None).unwrap();


contract.generate_instance(api, querier, &options).unwrap()
}
Expand Down

0 comments on commit f3231de

Please sign in to comment.