Skip to content

Commit

Permalink
more clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
dorin-iancu committed Dec 2, 2024
1 parent daa6e2a commit 90f8d81
Show file tree
Hide file tree
Showing 16 changed files with 52 additions and 59 deletions.
2 changes: 1 addition & 1 deletion common/modules/farm/contexts/src/storage_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl<'a, C: FarmContracTraitBounds> StorageCache<'a, C> {
}
}

impl<'a, C: FarmContracTraitBounds> Drop for StorageCache<'a, C> {
impl<C: FarmContracTraitBounds> Drop for StorageCache<'_, C> {
fn drop(&mut self) {
// commit changes to storage for the mutable fields
self.sc_ref.reward_reserve().set(&self.reward_reserve);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ where
&self.energy_factory_wrapper,
&rust_biguint!(0),
|sc| {
sc.user_energy(&managed_address!(user)).set(&Energy::new(
sc.user_energy(&managed_address!(user)).set(Energy::new(
BigInt::from(managed_biguint!(energy)),
last_update_epoch,
managed_biguint!(locked_tokens),
Expand Down
2 changes: 1 addition & 1 deletion dex/farm/tests/farm_setup/farm_rewards_distr_setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ where
sc.farm_token().set_token_id(farm_token_id);

sc.per_block_reward_amount()
.set(&to_managed_biguint(per_block_reward_amount));
.set(to_managed_biguint(per_block_reward_amount));

sc.state().set(State::Active);
sc.produce_rewards_enabled().set(true);
Expand Down
2 changes: 1 addition & 1 deletion dex/farm/tests/farm_setup/multi_user_farm_setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ where
&self.energy_factory_wrapper,
&rust_biguint!(0),
|sc| {
sc.user_energy(&managed_address!(user)).set(&Energy::new(
sc.user_energy(&managed_address!(user)).set(Energy::new(
BigInt::from(managed_biguint!(energy)),
last_update_epoch,
managed_biguint!(locked_tokens),
Expand Down
12 changes: 4 additions & 8 deletions dex/farm/tests/farm_single_user_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,8 @@ where
let second_reward_share =
DIVISION_SAFETY_CONSTANT * 10 * PER_BLOCK_REWARD_AMOUNT / current_farm_supply;
let expected_reward_per_share = (first_reward_share * farm_in_amount
+ second_reward_share * second_farm_in_amount
+ total_amount
- 1)
/ total_amount;
+ second_reward_share * second_farm_in_amount)
.div_ceil(total_amount);

farm_setup.enter_farm(
second_farm_in_amount,
Expand Down Expand Up @@ -174,10 +172,8 @@ fn test_exit_farm_after_enter_twice() {
let second_reward_share =
DIVISION_SAFETY_CONSTANT * 10 * PER_BLOCK_REWARD_AMOUNT / current_farm_supply;
let prev_reward_per_share = (first_reward_share * farm_in_amount
+ second_reward_share * second_farm_in_amount
+ total_farm_token
- 1)
/ total_farm_token;
+ second_reward_share * second_farm_in_amount)
.div_ceil(total_farm_token);
let new_reward_per_share = prev_reward_per_share
+ 25 * PER_BLOCK_REWARD_AMOUNT * DIVISION_SAFETY_CONSTANT / total_farm_token;
let reward_per_share_diff = new_reward_per_share - prev_reward_per_share;
Expand Down
2 changes: 1 addition & 1 deletion dex/fuzz/src/fuzz_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ pub mod fuzz_data_tests {
sc.farm_token().set_token_id(farm_token_id);

sc.per_block_reward_amount()
.set(&to_managed_biguint(per_block_reward_amount));
.set(to_managed_biguint(per_block_reward_amount));

sc.state().set(State::Active);
sc.produce_rewards_enabled().set(true);
Expand Down
10 changes: 5 additions & 5 deletions dex/governance/tests/gov_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ fn test_propose_bad_token() {
});
},
)
.assert_user_error(&String::from_utf8(UNREGISTERED_TOKEN_ID.to_vec()).unwrap());
.assert_user_error(core::str::from_utf8(UNREGISTERED_TOKEN_ID).unwrap());
}

#[test]
Expand All @@ -200,7 +200,7 @@ fn test_propose_bad_amount() {
});
},
)
.assert_user_error(&String::from_utf8(NOT_ENOUGH_FUNDS_TO_PROPOSE.to_vec()).unwrap());
.assert_user_error(core::str::from_utf8(NOT_ENOUGH_FUNDS_TO_PROPOSE).unwrap());
}

#[test]
Expand Down Expand Up @@ -418,7 +418,7 @@ fn test_basic_reclaim() {
sc.redeem();
},
)
.assert_user_error(&String::from_utf8(VOTING_PERIOD_NOT_ENDED.to_vec()).unwrap());
.assert_user_error(core::str::from_utf8(VOTING_PERIOD_NOT_ENDED).unwrap());

gov_setup
.blockchain_wrapper
Expand Down Expand Up @@ -495,7 +495,7 @@ fn test_vote() {
sc.upvote(0);
},
)
.assert_user_error(&String::from_utf8(PROPOSAL_NOT_ACTIVE.to_vec()).unwrap());
.assert_user_error(core::str::from_utf8(PROPOSAL_NOT_ACTIVE).unwrap());

gov_setup
.blockchain_wrapper
Expand Down Expand Up @@ -565,7 +565,7 @@ fn test_vote() {
sc.redeem();
},
)
.assert_user_error(&String::from_utf8(VOTING_PERIOD_NOT_ENDED.to_vec()).unwrap());
.assert_user_error(core::str::from_utf8(VOTING_PERIOD_NOT_ENDED).unwrap());

gov_setup
.blockchain_wrapper
Expand Down
2 changes: 1 addition & 1 deletion dex/pair/src/contexts/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ where
}
}

impl<'a, C> Drop for StorageCache<'a, C>
impl<C> Drop for StorageCache<'_, C>
where
C: crate::config::ConfigModule,
{
Expand Down
2 changes: 1 addition & 1 deletion dex/router/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub trait Router:
self.pair_creation_enabled().set_if_empty(false);

self.init_factory(pair_template_address_opt.into_option());
self.owner().set(&self.blockchain().get_caller());
self.owner().set(self.blockchain().get_caller());
}

#[upgrade]
Expand Down
2 changes: 1 addition & 1 deletion energy-integration/energy-factory-mock/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub trait EnergyFactoryMock {
total_locked_tokens: BigUint,
) {
let current_epoch = self.blockchain().get_block_epoch();
self.user_energy(&user).set(&Energy::new(
self.user_energy(&user).set(Energy::new(
BigInt::from(energy_amount),
current_epoch,
total_locked_tokens,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ where
&self.energy_factory_wrapper,
&rust_biguint!(0),
|sc| {
sc.user_energy(&managed_address!(user)).set(&Energy::new(
sc.user_energy(&managed_address!(user)).set(Energy::new(
BigInt::from(managed_biguint!(energy_amount)),
current_epoch,
managed_biguint!(total_locked_tokens),
Expand Down
53 changes: 26 additions & 27 deletions energy-integration/governance-v2/src/configurable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,32 @@ use crate::errors::ERROR_NOT_AN_ESDT;

multiversx_sc::imports!();

/// # MultiversX smart contract module - Governance
///
/// This is a standard smart contract module, that when added to a smart contract offers governance features:
/// - proposing actions
/// - voting/downvoting a certain proposal
/// - after a voting period, either putting the action in a queue (if it reached quorum), or canceling
///
/// Voting is done through energy.
///
/// The module provides the following configurable parameters:
/// - `minEnergyForPropose` - the minimum energy required for submitting a proposal
/// - `quorum` - the minimum number of (`votes` minus `downvotes`) at the end of voting period
/// - `maxActionsPerProposal` - Maximum number of actions (transfers and/or smart contract calls) that a proposal may have
/// - `votingDelayInBlocks` - Number of blocks to wait after a block is proposed before being able to vote/downvote that proposal
/// - `votingPeriodInBlocks` - Number of blocks the voting period lasts (voting delay does not count towards this)
/// - `lockTimeAfterVotingEndsInBlocks` - Number of blocks to wait before a successful proposal can be executed
///
/// The module also provides events for most actions that happen:
/// - `proposalCreated` - triggers when a proposal is created. Also provoides all the relevant information, like proposer, actions etc.
/// - `voteCast` - user voted on a proposal
/// - `downvoteCast` - user downvoted a proposal
/// - `proposalCanceled`, `proposalQueued` and `proposalExecuted` - provides the ID of the specific proposal
/// - `userDeposit` - a user deposited some tokens needed for a future payable action
///
/// Please note that although the main contract can modify the module's storage directly, it is not recommended to do so,
/// as that defeats the whole purpose of having governance. These parameters should only be modified through actions.
///
// # MultiversX smart contract module - Governance
//
// This is a standard smart contract module, that when added to a smart contract offers governance features:
// - proposing actions
// - voting/downvoting a certain proposal
// - after a voting period, either putting the action in a queue (if it reached quorum), or canceling
//
// Voting is done through energy.
//
// The module provides the following configurable parameters:
// - `minEnergyForPropose` - the minimum energy required for submitting a proposal
// - `quorum` - the minimum number of (`votes` minus `downvotes`) at the end of voting period
// - `maxActionsPerProposal` - Maximum number of actions (transfers and/or smart contract calls) that a proposal may have
// - `votingDelayInBlocks` - Number of blocks to wait after a block is proposed before being able to vote/downvote that proposal
// - `votingPeriodInBlocks` - Number of blocks the voting period lasts (voting delay does not count towards this)
// - `lockTimeAfterVotingEndsInBlocks` - Number of blocks to wait before a successful proposal can be executed
//
// The module also provides events for most actions that happen:
// - `proposalCreated` - triggers when a proposal is created. Also provoides all the relevant information, like proposer, actions etc.
// - `voteCast` - user voted on a proposal
// - `downvoteCast` - user downvoted a proposal
// - `proposalCanceled`, `proposalQueued` and `proposalExecuted` - provides the ID of the specific proposal
// - `userDeposit` - a user deposited some tokens needed for a future payable action
//
// Please note that although the main contract can modify the module's storage directly, it is not recommended to do so,
// as that defeats the whole purpose of having governance. These parameters should only be modified through actions.

const MIN_VOTING_DELAY: u64 = 1;
const MAX_VOTING_DELAY: u64 = 100_800; // 1 Week
Expand Down
8 changes: 4 additions & 4 deletions energy-integration/governance-v2/tests/gov_test_setup/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,25 +79,25 @@ where
.execute_tx(&owner, &energy_factory_wrapper, &rust_zero, |sc| {
sc.init();
sc.user_energy(&managed_address!(&first_user))
.set(&Energy::new(
.set(Energy::new(
BigInt::from(managed_biguint!(USER_ENERGY)),
0,
managed_biguint!(0),
));
sc.user_energy(&managed_address!(&second_user))
.set(&Energy::new(
.set(Energy::new(
BigInt::from(managed_biguint!(USER_ENERGY)),
0,
managed_biguint!(0),
));
sc.user_energy(&managed_address!(&third_user))
.set(&Energy::new(
.set(Energy::new(
BigInt::from(managed_biguint!(USER_ENERGY + 210_000)),
0,
managed_biguint!(0),
));
sc.user_energy(&managed_address!(&no_energy_user))
.set(&Energy::new(
.set(Energy::new(
BigInt::from(managed_biguint!(0)),
0,
managed_biguint!(0),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ where
&self.energy_factory_wrapper,
&rust_biguint!(0),
|sc| {
sc.user_energy(&managed_address!(user)).set(&Energy::new(
sc.user_energy(&managed_address!(user)).set(Energy::new(
BigInt::from(managed_biguint!(energy)),
last_update_epoch,
managed_biguint!(locked_tokens),
Expand Down
2 changes: 1 addition & 1 deletion farm-staking/farm-staking/tests/farm_staking_setup/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,7 @@ where
&self.energy_factory_wrapper,
&rust_biguint!(0),
|sc| {
sc.user_energy(&managed_address!(user)).set(&Energy::new(
sc.user_energy(&managed_address!(user)).set(Energy::new(
BigInt::from(managed_biguint!(energy)),
last_update_epoch,
managed_biguint!(locked_tokens),
Expand Down
6 changes: 2 additions & 4 deletions farm-staking/farm-staking/tests/farm_staking_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,8 @@ where
let first_reward_share = 0;
let second_reward_share = 400_000;
let expected_reward_per_share = (first_reward_share * farm_in_amount
+ second_reward_share * second_farm_in_amount
+ total_amount
- 1)
/ total_amount;
+ second_reward_share * second_farm_in_amount)
.div_ceil(total_amount);

farm_setup.stake_farm(
&user_address,
Expand Down

0 comments on commit 90f8d81

Please sign in to comment.