Skip to content

Commit

Permalink
Enable clippy in the CI for test-tube for merkle-incentives (#720)
Browse files Browse the repository at this point in the history
  • Loading branch information
lubkoll authored Jul 29, 2024
1 parent 38699af commit 95074bf
Show file tree
Hide file tree
Showing 18 changed files with 66 additions and 88 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test_tube_osmosis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
restore-keys: ${{ runner.os }}-cargo-osmosis
- name: Rust lint
run: cargo clippy --features test-tube --all-targets -- -D warnings --A deprecated
working-directory: smart-contracts/osmosis/contracts/dex-router-osmosis
working-directory: smart-contracts/osmosis
- name: Build merkle-incentives
run: cargo test-tube-build
working-directory: smart-contracts/osmosis/contracts/merkle-incentives
Expand Down
6 changes: 3 additions & 3 deletions scripts/git/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ update_schemas_and_formatting() {
if [[ $CHANGES == *contracts/${contract}* ]]
then
echo "Changes in ${contract} contract"
cd ${REPO_ROOT}/smart-contracts/contracts/${contract}
cd ${REPO_ROOT}/smart-contracts/osmosis/contracts/${contract}

# generate schemas
cargo schema
NEW_CHANGES=$(git diff --name-only origin/main)
NEW_CHANGES=$(git diff --name-only origin/main..HEAD)
if [[ $NEW_CHANGES == *schema/* ]]
then
git add schema
Expand All @@ -33,7 +33,7 @@ update_schemas_and_formatting() {
# fix formatting
cargo fmt --all
cd ${REPO_ROOT}
NEW_CHANGES=$(git diff --name-only origin/main --diff-filter=A)
NEW_CHANGES=$(git diff --name-only origin/main..HEAD --diff-filter=AMR)
git add $NEW_CHANGES
fi
}
Expand Down
4 changes: 2 additions & 2 deletions smart-contracts/osmosis/contracts/cl-vault/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ mod tests {
if let Some(SubMsg {
msg: CosmosMsg::Bank(BankMsg::Send { to_address, amount }),
..
}) = migrate_resp.messages.get(0)
}) = migrate_resp.messages.first()
{
assert_eq!(to_address, "treasury");
assert_eq!(amount, &rewards_coins);
Expand Down Expand Up @@ -622,7 +622,7 @@ mod tests {
}
}

fn assert_multi_send(msg: &CosmosMsg, expected_user: &String, user_rewards_coins: &Vec<Coin>) {
fn assert_multi_send(msg: &CosmosMsg, expected_user: &String, user_rewards_coins: &[Coin]) {
if let CosmosMsg::Stargate { type_url, value } = msg {
// Decode and validate the MsgMultiSend message
// This has been decoded manually rather than encoding the expected message because its simpler to assert the values
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ mod tests {
fn coins_works() {
let mut rewards = CoinList::new();
rewards
.update_rewards(&vec![
.update_rewards(&[
OsmoCoin {
denom: "uosmo".into(),
amount: "1000".into(),
Expand All @@ -200,7 +200,7 @@ mod tests {
fn coins_only_positive_works() {
let mut rewards = CoinList::new();
rewards
.update_rewards(&vec![
.update_rewards(&[
OsmoCoin {
denom: "uosmo".into(),
amount: "1000".into(),
Expand All @@ -227,7 +227,7 @@ mod tests {
fn sub_works() {
let mut rewards = CoinList::new();
rewards
.update_rewards(&vec![
.update_rewards(&[
OsmoCoin {
denom: "uosmo".into(),
amount: "1000".into(),
Expand Down Expand Up @@ -290,7 +290,7 @@ mod tests {
fn percentage_works() {
let mut rewards = CoinList::new();
rewards
.update_rewards(&vec![
.update_rewards(&[
OsmoCoin {
denom: "uosmo".into(),
amount: "1000".into(),
Expand Down Expand Up @@ -321,7 +321,7 @@ mod tests {
fn sub_percentage_works() {
let mut rewards = CoinList::new();
rewards
.update_rewards(&vec![
.update_rewards(&[
OsmoCoin {
denom: "uosmo".into(),
amount: "1000".into(),
Expand Down Expand Up @@ -365,7 +365,7 @@ mod tests {
fn add_works() {
let mut rewards = CoinList::new();
rewards
.update_rewards(&vec![
.update_rewards(&[
OsmoCoin {
denom: "uosmo".into(),
amount: "1000".into(),
Expand Down Expand Up @@ -403,7 +403,7 @@ mod tests {
fn update_rewards_works() {
let mut rewards = CoinList::new();
rewards
.update_rewards(&vec![
.update_rewards(&[
OsmoCoin {
denom: "uosmo".into(),
amount: "1000".into(),
Expand All @@ -420,7 +420,7 @@ mod tests {
.unwrap();

rewards
.update_rewards(&vec![
.update_rewards(&[
OsmoCoin {
denom: "uosmo".into(),
amount: "1000".into(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl QuasarQuerier {

impl Querier for QuasarQuerier {
fn raw_query(&self, bin_request: &[u8]) -> cosmwasm_std::QuerierResult {
let request: QueryRequest<Empty> = from_json(&Binary::from(bin_request)).unwrap();
let request: QueryRequest<Empty> = from_json(Binary::from(bin_request)).unwrap();
match request {
QueryRequest::Stargate { path, data } => match path.as_str() {
"/osmosis.concentratedliquidity.v1beta1.Query/PositionById" => {
Expand Down Expand Up @@ -89,11 +89,11 @@ impl Querier for QuasarQuerier {
))
}
"/cosmos.bank.v1beta.Query/Balance" => {
let query: BankQuery = from_json(&Binary::from(bin_request)).unwrap();
let query: BankQuery = from_json(Binary::from(bin_request)).unwrap();
self.bank.query(&query)
}
"/cosmos.bank.v1beta.Query/AllBalances" => {
let query: BankQuery = from_json(&Binary::from(bin_request)).unwrap();
let query: BankQuery = from_json(Binary::from(bin_request)).unwrap();
self.bank.query(&query)
}
"/osmosis.poolmanager.v1beta1.Query/Pool" => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,7 @@ mod tests {
let mut deps = mock_dependencies();

build_tick_exp_cache(&mut deps.storage).unwrap();
let verify_resp = verify_tick_exp_cache(&mut deps.storage).unwrap();
assert_eq!((), verify_resp);
assert!(verify_tick_exp_cache(&deps.storage).is_ok());
}

#[test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ mod tests {
)
.unwrap();

let result = withdraw_from_position(&mut deps.storage, &env, liquidity_amount).unwrap();
let result = withdraw_from_position(&deps.storage, &env, liquidity_amount).unwrap();

assert_eq!(
result,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,8 +348,7 @@ mod tests {
amount0: "1000".to_string(),
amount1: "1000".to_string(),
}
.try_into()
.unwrap();
.into();

let response = handle_withdraw_user_reply(
deps.as_mut(),
Expand Down
2 changes: 1 addition & 1 deletion smart-contracts/osmosis/contracts/cl-vault/tests/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,5 @@ fn admin_build_tick_cache_works() {
)),
)
.unwrap();
assert_eq!((), verify_resp.result.unwrap());
assert!(verify_resp.result.is_ok());
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ fn do_and_verify_any_deposit(
.find(|coin| coin.denom == DENOM_QUOTE)
.map(|coin| {
let quote_amount = Uint128::from(coin.amount.parse::<u128>().unwrap());
let quote_as_base = quote_amount * spot_price_quote_to_base;
quote_as_base
quote_amount * spot_price_quote_to_base
})
.unwrap_or_else(Uint128::zero);

Expand All @@ -115,8 +114,7 @@ fn do_and_verify_any_deposit(
.find(|coin| coin.denom == DENOM_QUOTE)
.map(|coin| {
let quote_amount = Uint128::from(coin.amount.parse::<u128>().unwrap());
let quote_as_base = quote_amount * spot_price_quote_to_base;
quote_as_base
quote_amount * spot_price_quote_to_base
})
.unwrap_or_else(Uint128::zero);

Expand Down
22 changes: 8 additions & 14 deletions smart-contracts/osmosis/contracts/cl-vault/tests/authz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,11 @@ fn exact_deposit_withdraw_equal() {
assert_eq!(deposit_response.data, authz_deposit_response.data);

assert_eq!(
deposit_response
.events
.iter()
.find(|e| e.ty == "wasm".to_string()),
deposit_response.events.iter().find(|e| e.ty == *"wasm"),
authz_deposit_response
.events
.iter()
.find(|e| e.ty == "wasm".to_string())
.find(|e| e.ty == *"wasm")
);

let shares: UserSharesBalanceResponse = wasm
Expand Down Expand Up @@ -117,14 +114,11 @@ fn exact_deposit_withdraw_equal() {

assert_eq!(withdraw_response.data, authz_withdraw_response.data);
assert_eq!(
withdraw_response
.events
.iter()
.find(|e| e.ty == "wasm".to_string()),
withdraw_response.events.iter().find(|e| e.ty == *"wasm"),
authz_withdraw_response
.events
.iter()
.find(|e| e.ty == "wasm".to_string())
.find(|e| e.ty == *"wasm")
);
}

Expand Down Expand Up @@ -175,12 +169,12 @@ fn any_deposit_withdraw_equal() {
let deposit_event = deposit_response
.events
.iter()
.find(|e| e.ty == "wasm".to_string())
.find(|e| e.ty == *"wasm")
.unwrap();
let authz_deposit_event = authz_deposit_response
.events
.iter()
.find(|e| e.ty == "wasm".to_string())
.find(|e| e.ty == *"wasm")
.unwrap();
// Assert events are equal
assert_eq!(deposit_event.ty, authz_deposit_event.ty);
Expand Down Expand Up @@ -250,12 +244,12 @@ fn any_deposit_withdraw_equal() {
let withdraw_event = withdraw_response
.events
.iter()
.find(|e| e.ty == "wasm".to_string())
.find(|e| e.ty == *"wasm")
.unwrap();
let authz_withdraw_event = authz_withdraw_response
.events
.iter()
.find(|e| e.ty == "wasm".to_string())
.find(|e| e.ty == *"wasm")
.unwrap();
// Assert events are equal
assert_eq!(withdraw_event.ty, authz_withdraw_event.ty);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,20 +72,20 @@ fn single_deposit_withdraw_works() {

// assert that the refund + used funds are equal to what we deposited
let refund0: u128 = get_event_attributes_by_ty_and_key(&response, "wasm", vec!["refund0"])
.get(0)
.first()
.map(|attr| attr.value.parse().unwrap())
.unwrap_or(0);
let refund1: u128 = get_event_attributes_by_ty_and_key(&response, "wasm", vec!["refund1"])
.get(0)
.first()
.map(|attr| attr.value.parse().unwrap())
.unwrap_or(0);

let deposited0: u128 = get_event_attributes_by_ty_and_key(&response, "wasm", vec!["amount0"])
.get(0)
.first()
.map(|attr| attr.value.parse().unwrap())
.unwrap_or(0);
let deposited1: u128 = get_event_attributes_by_ty_and_key(&response, "wasm", vec!["amount1"])
.get(0)
.first()
.map(|attr| attr.value.parse().unwrap())
.unwrap_or(0);

Expand Down
14 changes: 7 additions & 7 deletions smart-contracts/osmosis/contracts/cl-vault/tests/setup/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,8 @@ pub fn fixture_dex_router(
)
}

// INIT PRIVATE METHODS

// TODO: This is pub because of the proptest still not having a default_init implementation
#[allow(clippy::too_many_arguments)]
pub fn init_test_contract(
filename: &str,
admin_balance: &[Coin],
Expand Down Expand Up @@ -260,6 +259,7 @@ pub fn init_test_contract(
)
}

#[allow(clippy::too_many_arguments)]
fn init_test_contract_with_dex_router_and_swap_pools(
filename_cl: &str,
filename_dex: &str,
Expand Down Expand Up @@ -366,7 +366,7 @@ fn init_test_contract_with_dex_router_and_swap_pools(
// TODO: We could be using a mixed set of CL and gAMM pools here
let mut lp_pools = vec![];
for pool_coins in &pools_coins {
let lp_pool = gm.create_basic_pool(&pool_coins, &admin).unwrap();
let lp_pool = gm.create_basic_pool(pool_coins, &admin).unwrap();
lp_pools.push(lp_pool.data.pool_id);
}

Expand Down Expand Up @@ -480,8 +480,8 @@ fn init_test_contract_with_dex_router_and_swap_pools(
fn set_dex_router_paths(
app: &OsmosisTestApp,
dex_router: String,
pools: &Vec<u64>,
pools_coins: &Vec<Vec<Coin>>,
pools: &[u64],
pools_coins: &[Vec<Coin>],
admin: &SigningAccount,
) {
let wasm = Wasm::new(app);
Expand All @@ -498,7 +498,7 @@ fn set_dex_router_paths(
bidirectional: true,
},
vec![].as_ref(),
&admin,
admin,
)
.unwrap();
}
Expand Down Expand Up @@ -530,7 +530,7 @@ pub fn get_balance_amount(app: &OsmosisTestApp, address: String, denom: String)
.unwrap()
}

pub fn get_amount_from_denom(value: &String) -> u128 {
pub fn get_amount_from_denom(value: &str) -> u128 {
// Find the position where the non-numeric part starts
let pos = value.find(|c: char| !c.is_numeric()).unwrap_or(value.len());
// Extract the numeric part from the string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ mod tests {
fn test_update_merkle_root_valid() {
let mut deps = mock_dependencies();
let env = mock_env();
let info = mock_info("admin", &vec![]);
let info = mock_info("admin", &[]);

// Set incentives admin
INCENTIVES_ADMIN
Expand All @@ -112,7 +112,7 @@ mod tests {
fn test_update_merkle_root_invalid() {
let mut deps = mock_dependencies();
let env = mock_env();
let info = mock_info("admin", &vec![]);
let info = mock_info("admin", &[]);

// Set incentives admin
INCENTIVES_ADMIN
Expand Down
Loading

0 comments on commit 95074bf

Please sign in to comment.