Skip to content

Commit

Permalink
fix(lint): format all rust code
Browse files Browse the repository at this point in the history
  • Loading branch information
bdeneux committed Feb 9, 2023
1 parent 43129c0 commit b955d74
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 47 deletions.
15 changes: 11 additions & 4 deletions contracts/cw-logic-sample/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ pub mod query {
mod tests {
use super::*;
use cosmwasm_std::testing::{mock_env, mock_info};
use cosmwasm_std::{Coin, coins, from_binary};
use cosmwasm_std::{coins, from_binary, Coin};
use logic_bindings::testing::mock::mock_dependencies_with_logic_and_balance;


#[test]
fn proper_initialization() {
let mut deps = mock_dependencies_with_logic_and_balance(&[Coin::new(10000, "uknow".to_string())]);
let mut deps =
mock_dependencies_with_logic_and_balance(&[Coin::new(10000, "uknow".to_string())]);

let msg = InstantiateMsg {
program: "bank_balances_has_coin(A, D, V, S) :- bank_balances(A, R), member(D-V, R), compare(>, V, S).".to_string(),
Expand All @@ -75,7 +75,14 @@ mod tests {
assert_eq!(0, res.messages.len());

// it worked, let's check if logic querier is called to answer to the `Ask` query.
let res = query(deps.as_ref(), mock_env(), QueryMsg::Ask { query: "".to_string() }).unwrap();
let res = query(
deps.as_ref(),
mock_env(),
QueryMsg::Ask {
query: "".to_string(),
},
)
.unwrap();
let value: AskResponse = from_binary(&res).unwrap();
assert_eq!(true, value.answer.unwrap().success);
}
Expand Down
16 changes: 8 additions & 8 deletions contracts/cw-logic-sample/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#![forbid(unsafe_code)]
#![deny(
warnings,
rust_2018_idioms,
trivial_casts,
trivial_numeric_casts,
unused_lifetimes,
unused_import_braces,
unused_qualifications,
unused_qualifications
warnings,
rust_2018_idioms,
trivial_casts,
trivial_numeric_casts,
unused_lifetimes,
unused_import_braces,
unused_qualifications,
unused_qualifications
)]

pub mod contract;
Expand Down
6 changes: 5 additions & 1 deletion contracts/cw-template/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ pub mod execute {
Ok(Response::new().add_attribute("action", "increment"))
}

pub fn reset(deps: DepsMut<'_>, info: MessageInfo, count: i32) -> Result<Response, ContractError> {
pub fn reset(
deps: DepsMut<'_>,
info: MessageInfo,
count: i32,
) -> Result<Response, ContractError> {
STATE.update(deps.storage, |mut state| -> Result<_, ContractError> {
if info.sender != state.owner {
return Err(ContractError::Unauthorized {});
Expand Down
16 changes: 8 additions & 8 deletions contracts/cw-template/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#![forbid(unsafe_code)]
#![deny(
warnings,
rust_2018_idioms,
trivial_casts,
trivial_numeric_casts,
unused_lifetimes,
unused_import_braces,
unused_qualifications,
unused_qualifications
warnings,
rust_2018_idioms,
trivial_casts,
trivial_numeric_casts,
unused_lifetimes,
unused_import_braces,
unused_qualifications,
unused_qualifications
)]

pub mod contract;
Expand Down
16 changes: 8 additions & 8 deletions packages/logic-bindings/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#![forbid(unsafe_code)]
#![deny(
warnings,
rust_2018_idioms,
trivial_casts,
trivial_numeric_casts,
unused_lifetimes,
unused_import_braces,
unused_qualifications,
unused_qualifications
warnings,
rust_2018_idioms,
trivial_casts,
trivial_numeric_casts,
unused_lifetimes,
unused_import_braces,
unused_qualifications,
unused_qualifications
)]

mod query;
Expand Down
37 changes: 19 additions & 18 deletions packages/logic-bindings/src/testing/mock.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use std::marker::PhantomData;
use cosmwasm_std::{Coin, OwnedDeps, QuerierResult, SystemResult, to_binary};
use cosmwasm_std::testing::{MOCK_CONTRACT_ADDR, MockApi, MockQuerier, MockStorage};
use crate::{Answer, AskResponse, LogicCustomQuery, Substitution, Term};
use cosmwasm_std::testing::{MockApi, MockQuerier, MockStorage, MOCK_CONTRACT_ADDR};
use cosmwasm_std::{to_binary, Coin, OwnedDeps, QuerierResult, SystemResult};
use std::marker::PhantomData;

/// Creates all external requirements that can be injected for unit tests.
///
/// It sets the given balance for the contract itself, nothing else and set the custom default logic
/// querier handler.
pub fn mock_dependencies_with_logic_and_balance( contract_balance: &[Coin],
pub fn mock_dependencies_with_logic_and_balance(
contract_balance: &[Coin],
) -> OwnedDeps<MockStorage, MockApi, MockQuerier<LogicCustomQuery>, LogicCustomQuery> {
mock_dependencies_with_logic_and_balances(&[(MOCK_CONTRACT_ADDR, contract_balance)])
}
Expand All @@ -16,14 +17,15 @@ pub fn mock_dependencies_with_logic_and_balance( contract_balance: &[Coin],
///
/// Set the logic querier mock handler.
/// Sets all balances provided (you must explicitly set contract balance if desired).
pub fn mock_dependencies_with_logic_and_balances(balances: &[(&str, &[Coin])]) -> OwnedDeps<MockStorage, MockApi, MockQuerier<LogicCustomQuery>, LogicCustomQuery> {
pub fn mock_dependencies_with_logic_and_balances(
balances: &[(&str, &[Coin])],
) -> OwnedDeps<MockStorage, MockApi, MockQuerier<LogicCustomQuery>, LogicCustomQuery> {
OwnedDeps {
storage: MockStorage::default(),
api: MockApi::default(),
querier: MockLogicQuerier::new(LogicQuerier::default(), balances),
custom_query_type: PhantomData,
}

}

trait MockLogicQuerier {
Expand Down Expand Up @@ -51,8 +53,8 @@ impl LogicQuerier {

#[allow(dead_code)]
fn update_handler<LH: 'static>(&mut self, handler: LH)
where
LH: Fn(&LogicCustomQuery) -> QuerierResult,
where
LH: Fn(&LogicCustomQuery) -> QuerierResult,
{
self.handler = Box::from(handler)
}
Expand All @@ -69,16 +71,15 @@ impl Default for LogicQuerier {
success: true,
has_more: false,
variables: vec!["foo".to_string()],
results: vec![
crate::Result {
substitutions: vec![Substitution {
variable: "foo".to_string(),
term: Term {
name: "bar".to_string(),
arguments: vec![]
}
}] }
],
results: vec![crate::Result {
substitutions: vec![Substitution {
variable: "foo".to_string(),
term: Term {
name: "bar".to_string(),
arguments: vec![],
},
}],
}],
}),
}),
};
Expand Down

0 comments on commit b955d74

Please sign in to comment.