Skip to content

Commit

Permalink
Fix clippy lints
Browse files Browse the repository at this point in the history
Signed-off-by: Danil <[email protected]>
  • Loading branch information
Deniallugo committed Mar 3, 2023
1 parent 4640336 commit 87e870b
Show file tree
Hide file tree
Showing 27 changed files with 46 additions and 51 deletions.
2 changes: 1 addition & 1 deletion core/bin/data_restore/src/inmemory_storage_interactor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ impl InMemoryStorageInteractor {

let verify_op = Operation {
action: Action::Verify {
proof: Box::new(Default::default()),
proof: Box::default(),
},
block: block.clone(),
id: None,
Expand Down
2 changes: 1 addition & 1 deletion core/bin/key_generator/src/sample_proofs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,6 @@ pub fn make_sample_proofs(config: ChainConfig) -> anyhow::Result<()> {
};

let serialized = serde_json::to_vec_pretty(&precomputed_proofs)?;
std::fs::write(get_precomputed_proofs_path(), &serialized)?;
std::fs::write(get_precomputed_proofs_path(), serialized)?;
Ok(())
}
3 changes: 3 additions & 0 deletions core/bin/zksync_api/src/fee_ticker/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ fn test_ticker_subsidy() {
);

let config = get_test_ticker_config();
#[allow(clippy::box_default)]
let mut ticker = FeeTicker::new(Box::new(MockTickerInfo::default()), config, validator);

// Only CREATE2 is subsidized
Expand Down Expand Up @@ -456,6 +457,7 @@ fn test_ticker_formula() {
);

let config = get_test_ticker_config();
#[allow(clippy::box_default)]
let mut ticker = FeeTicker::new(Box::new(MockTickerInfo::default()), config, validator);

let get_relative_diff = |a: &Ratio<BigUint>, b: &Ratio<BigUint>| -> BigDecimal {
Expand Down Expand Up @@ -690,6 +692,7 @@ fn test_zero_price_token_fee() {
);

let config = get_test_ticker_config();
#[allow(clippy::box_default)]
let ticker = FeeTicker::new(Box::new(MockTickerInfo::default()), config, validator);

let token = TestToken::zero_price();
Expand Down
19 changes: 7 additions & 12 deletions core/lib/circuit/src/exit_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,28 +250,23 @@ pub fn create_exit_circuit_with_public_input(
let serial_id_fe = Fr::from_str(&nft_serial_id.to_string()).unwrap();
let root_hash = account_tree.root_hash();
let (account_witness, _, balance, _) =
apply_leaf_operation(account_tree, *account_id, *token_id as u32, |_| {}, |_| {});
let (audit_path, audit_balance_path) = get_audits(account_tree, *account_id, *token_id as u32);
apply_leaf_operation(account_tree, *account_id, *token_id, |_| {}, |_| {});
let (audit_path, audit_balance_path) = get_audits(account_tree, *account_id, *token_id);

let (special_account_witness, _, special_account_balance, _) = apply_leaf_operation(
account_tree,
NFT_STORAGE_ACCOUNT_ID.0,
*token_id as u32,
*token_id,
|_| {},
|_| {},
);
let (special_account_audit_path, special_account_audit_balance_path) =
get_audits(account_tree, NFT_STORAGE_ACCOUNT_ID.0, *token_id as u32);
get_audits(account_tree, NFT_STORAGE_ACCOUNT_ID.0, *token_id);

let (creator_account_witness, _, creator_account_balance, _) = apply_leaf_operation(
account_tree,
*nft_creator_id,
*token_id as u32,
|_| {},
|_| {},
);
let (creator_account_witness, _, creator_account_balance, _) =
apply_leaf_operation(account_tree, *nft_creator_id, *token_id, |_| {}, |_| {});
let (creator_account_audit_path, creator_account_audit_balance_path) =
get_audits(account_tree, *nft_creator_id, *token_id as u32);
get_audits(account_tree, *nft_creator_id, *token_id);

let mut pubdata_commitment = Vec::new();
append_be_fixed_width(
Expand Down
2 changes: 1 addition & 1 deletion core/lib/circuit/src/witness/change_pubkey_offchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl Witness for ChangePubkeyOffChainWitness<Bn256> {
account_id: *change_pubkey_offchain.account_id,
address: eth_address_to_fr(&change_pubkey_offchain.tx.account),
new_pubkey_hash: change_pubkey_offchain.tx.new_pk_hash.as_fr(),
fee_token: *change_pubkey_offchain.tx.fee_token as u32,
fee_token: *change_pubkey_offchain.tx.fee_token,
fee: change_pubkey_offchain.tx.fee.to_u128().unwrap(),
nonce: fr_from(change_pubkey_offchain.tx.nonce),
valid_from,
Expand Down
2 changes: 1 addition & 1 deletion core/lib/circuit/src/witness/deposit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl Witness for DepositWitness<Bn256> {
fn apply_tx(tree: &mut CircuitAccountTree, deposit: &DepositOp) -> Self {
let deposit_data = DepositData {
amount: deposit.priority_op.amount.to_string().parse().unwrap(),
token: *deposit.priority_op.token as u32,
token: *deposit.priority_op.token,
account_address: *deposit.account_id,
address: eth_address_to_fr(&deposit.priority_op.to),
};
Expand Down
2 changes: 1 addition & 1 deletion core/lib/circuit/src/witness/forced_exit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl Witness for ForcedExitWitness<Bn256> {
.to_u128()
.unwrap(),
fee: forced_exit.tx.fee.to_u128().unwrap(),
token: *forced_exit.tx.token as u32,
token: *forced_exit.tx.token,
initiator_account_address: *forced_exit.tx.initiator_account_id,
target_account_address: *forced_exit.target_account_id,
target_account_eth_address: eth_address_to_fr(&forced_exit.tx.target),
Expand Down
2 changes: 1 addition & 1 deletion core/lib/circuit/src/witness/full_exit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl Witness for FullExitWitness<Bn256> {
(full_exit, is_success): &(FullExitOp, bool),
) -> Self {
let full_exit = FullExitData {
token: *full_exit.priority_op.token as u32,
token: *full_exit.priority_op.token,
account_address: *full_exit.priority_op.account_id,
eth_address: eth_address_to_fr(&full_exit.priority_op.eth_address),
full_exit_amount: full_exit
Expand Down
2 changes: 1 addition & 1 deletion core/lib/circuit/src/witness/mint_nft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl Witness for MintNFTWitness<Bn256> {
fn apply_tx(tree: &mut CircuitAccountTree, mint_nft: &MintNFTOp) -> Self {
let mint_nft_data = MintNFTData {
fee: mint_nft.tx.fee.to_u128().unwrap(),
fee_token: *mint_nft.tx.fee_token as u32,
fee_token: *mint_nft.tx.fee_token,
creator_account_id: *mint_nft.creator_account_id,
recipient_account_id: *mint_nft.recipient_account_id,
content_hash: mint_nft.tx.content_hash,
Expand Down
17 changes: 7 additions & 10 deletions core/lib/circuit/src/witness/swap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ impl Witness for SwapWitness<Bn256> {

fn apply_tx(tree: &mut CircuitAccountTree, swap: &SwapOp) -> Self {
let order_0 = OrderData {
account: *swap.accounts.0 as u32,
recipient: *swap.recipients.0 as u32,
account: *swap.accounts.0,
recipient: *swap.recipients.0,
recipient_address: eth_address_to_fr(&swap.tx.orders.0.recipient_address),
amount: swap.tx.orders.0.amount.to_u128().unwrap(),
price_sell: swap.tx.orders.0.price.0.to_u128().unwrap(),
Expand All @@ -85,8 +85,8 @@ impl Witness for SwapWitness<Bn256> {
};

let order_1 = OrderData {
account: *swap.accounts.1 as u32,
recipient: *swap.recipients.1 as u32,
account: *swap.accounts.1,
recipient: *swap.recipients.1,
recipient_address: eth_address_to_fr(&swap.tx.orders.1.recipient_address),
amount: swap.tx.orders.1.amount.to_u128().unwrap(),
price_sell: swap.tx.orders.1.price.0.to_u128().unwrap(),
Expand All @@ -101,14 +101,11 @@ impl Witness for SwapWitness<Bn256> {
swap.tx.amounts.0.to_u128().unwrap(),
swap.tx.amounts.1.to_u128().unwrap(),
),
tokens: (
*swap.tx.orders.0.token_sell as u32,
*swap.tx.orders.1.token_sell as u32,
),
tokens: (*swap.tx.orders.0.token_sell, *swap.tx.orders.1.token_sell),
fee: swap.tx.fee.to_u128().unwrap(),
fee_token: *swap.tx.fee_token as u32,
fee_token: *swap.tx.fee_token,
orders: (order_0, order_1),
submitter: *swap.submitter as u32,
submitter: *swap.submitter,
submitter_address: eth_address_to_fr(&swap.tx.submitter_address),
nonce: *swap.tx.nonce,
};
Expand Down
2 changes: 1 addition & 1 deletion core/lib/circuit/src/witness/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl Witness for TransferWitness<Bn256> {
let transfer_data = TransferData {
amount: transfer.tx.amount.to_u128().unwrap(),
fee: transfer.tx.fee.to_u128().unwrap(),
token: *transfer.tx.token as u32,
token: *transfer.tx.token,
from_account_address: *transfer.from,
to_account_address: *transfer.to,
valid_from: time_range.valid_from,
Expand Down
2 changes: 1 addition & 1 deletion core/lib/circuit/src/witness/transfer_to_new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl Witness for TransferToNewWitness<Bn256> {
let transfer_data = TransferToNewData {
amount: transfer_to_new.tx.amount.to_string().parse().unwrap(),
fee: transfer_to_new.tx.fee.to_string().parse().unwrap(),
token: *transfer_to_new.tx.token as u32,
token: *transfer_to_new.tx.token,
from_account_address: *transfer_to_new.from,
to_account_address: *transfer_to_new.to,
new_address: eth_address_to_fr(&transfer_to_new.tx.to),
Expand Down
2 changes: 1 addition & 1 deletion core/lib/circuit/src/witness/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ impl<'a> WitnessBuilder<'a> {
let (root, acc_witness) = crate::witness::utils::apply_fee(
self.account_tree,
*self.fee_account_id,
**token as u32,
**token,
amount.to_u128().unwrap(),
);
root_after_fee = root;
Expand Down
2 changes: 1 addition & 1 deletion core/lib/circuit/src/witness/withdraw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl Witness for WithdrawWitness<Bn256> {
let withdraw_data = WithdrawData {
amount: withdraw.tx.amount.to_u128().unwrap(),
fee: withdraw.tx.fee.to_u128().unwrap(),
token: *withdraw.tx.token as u32,
token: *withdraw.tx.token,
account_address: *withdraw.account_id,
eth_address: eth_address_to_fr(&withdraw.tx.to),
valid_from,
Expand Down
4 changes: 2 additions & 2 deletions core/lib/circuit/src/witness/withdraw_nft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ impl Witness for WithdrawNFTWitness<Bn256> {
let time_range = withdraw_nft.tx.time_range;
let withdraw_nft_data = WithdrawNFTData {
fee: withdraw_nft.tx.fee.to_u128().unwrap(),
fee_token: *withdraw_nft.tx.fee_token as u32,
fee_token: *withdraw_nft.tx.fee_token,
initiator_account_id: *withdraw_nft.tx.account_id,
creator_account_id: *withdraw_nft.creator_id,
nft_serial_id: withdraw_nft.serial_id,
content_hash: withdraw_nft.content_hash,
token: *withdraw_nft.tx.token as u32,
token: *withdraw_nft.tx.token,
to_address: eth_address_to_fr(&withdraw_nft.tx.to),
valid_from: time_range.valid_from,
valid_until: time_range.valid_until,
Expand Down
2 changes: 1 addition & 1 deletion core/lib/crypto/src/merkle_tree/parallel_smt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,7 @@ mod tests {
(aggregated_hash, hash)
};

aggregated_hash = hasher.compress(&lhs, &rhs, level as usize);
aggregated_hash = hasher.compress(&lhs, &rhs, level);

level += 1;
}
Expand Down
4 changes: 2 additions & 2 deletions core/lib/crypto/src/primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ impl FloatConversions {

let max_power = (1 << exponent_length) - 1;

let max_exponent = (exponent_base as u128).saturating_pow(max_power);
let max_exponent = exponent_base.saturating_pow(max_power);

let max_mantissa = (1u128 << mantissa_length) - 1;

Expand Down Expand Up @@ -326,7 +326,7 @@ impl FloatConversions {

let max_power = (1 << exponent_length) - 1;

let max_exponent = (exponent_base as u128).saturating_pow(max_power);
let max_exponent = exponent_base.saturating_pow(max_power);

let max_mantissa = (1u128 << mantissa_length) - 1;

Expand Down
4 changes: 2 additions & 2 deletions core/lib/crypto/src/serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ impl SingleProofSerde {
// First, deserialize a string value. It is expected to be a
// base64 representation of `SingleProof`.
let deserialized_string = String::deserialize(deserializer)?;
let bytes = base64::decode(&deserialized_string).map_err(de::Error::custom)?;
let bytes = base64::decode(deserialized_string).map_err(de::Error::custom)?;

// Then, parse hexadecimal string to obtain `SingleProof`.
OldProof::read(&*bytes).map_err(de::Error::custom)
Expand Down Expand Up @@ -258,7 +258,7 @@ impl AggregatedProofSerde {
// First, deserialize a string value. It is expected to be a
// base64 representation of `AggregatedProof`.
let deserialized_string = String::deserialize(deserializer)?;
let bytes = base64::decode(&deserialized_string).map_err(de::Error::custom)?;
let bytes = base64::decode(deserialized_string).map_err(de::Error::custom)?;

// Then, parse hexadecimal string to obtain `SingleProof`.
NewProof::read(&*bytes).map_err(de::Error::custom)
Expand Down
2 changes: 1 addition & 1 deletion core/lib/state/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl ZkSyncState {
next_free_id = std::cmp::max(next_free_id, **account.0 + 1);
}
}
empty.next_free_id = AccountId(next_free_id as u32);
empty.next_free_id = AccountId(next_free_id);

for (id, account) in accounts {
empty.insert_account(id, account);
Expand Down
2 changes: 1 addition & 1 deletion core/lib/storage/src/chain/operations_ext/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1527,7 +1527,7 @@ impl<'a, 'c> OperationsExtSchema<'a, 'c> {
)
.fetch_one(self.0.conn())
.await?
.count as i64
.count
};
metrics::histogram!(
"sql.chain.operations_ext.get_account_transactions_count",
Expand Down
2 changes: 1 addition & 1 deletion core/lib/storage/src/tests/chain/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,7 @@ async fn pending_block_workflow(mut storage: StorageProcessor<'_>) -> QueryResul
.expect("No pending block");
assert_eq!(pending_block.number, pending_block_1.number);
assert_eq!(pending_block.chunks_left, pending_block_1.chunks_left);
assert_eq!(pending_block.chunks_left, chunks_left as usize);
assert_eq!(pending_block.chunks_left, chunks_left);
assert_eq!(
pending_block.unprocessed_priority_op_before,
pending_block_1.unprocessed_priority_op_before
Expand Down
2 changes: 1 addition & 1 deletion core/lib/storage/src/tests/chain/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ async fn aggregated_operations(mut storage: StorageProcessor<'_>) -> QueryResult
.await?;

let stored_operation = OperationsSchema(&mut storage)
.get_stored_aggregated_operation(BlockNumber(block_number as u32), action_type)
.get_stored_aggregated_operation(BlockNumber(block_number), action_type)
.await
.unwrap();

Expand Down
2 changes: 1 addition & 1 deletion core/lib/types/src/tx/primitives/packed_public_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl<'de> Deserialize<'de> for PackedPublicKey {
{
use serde::de::Error;
let string = String::deserialize(deserializer)?;
let bytes = hex::decode(&string).map_err(Error::custom)?;
let bytes = hex::decode(string).map_err(Error::custom)?;
Self::deserialize_packed(&bytes).map_err(Error::custom)
}
}
4 changes: 2 additions & 2 deletions core/lib/types/src/tx/primitives/packed_signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl Serialize for PackedSignature {
S: Serializer,
{
let packed_signature = self.serialize_packed().map_err(serde::ser::Error::custom)?;
serializer.serialize_str(&hex::encode(&packed_signature))
serializer.serialize_str(&hex::encode(packed_signature))
}
}

Expand All @@ -72,7 +72,7 @@ impl<'de> Deserialize<'de> for PackedSignature {
{
use serde::de::Error;
let string = String::deserialize(deserializer)?;
let bytes = hex::decode(&string).map_err(Error::custom)?;
let bytes = hex::decode(string).map_err(Error::custom)?;
Self::deserialize_packed(&bytes).map_err(Error::custom)
}
}
4 changes: 2 additions & 2 deletions core/lib/types/src/tx/primitives/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ impl Default for TxSignature {

impl std::fmt::Debug for TxSignature {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
let hex_pk = hex::encode(&self.pub_key.serialize_packed().unwrap());
let hex_sign = hex::encode(&self.signature.serialize_packed().unwrap());
let hex_pk = hex::encode(self.pub_key.serialize_packed().unwrap());
let hex_sign = hex::encode(self.signature.serialize_packed().unwrap());
write!(f, "{{ pub_key: {}, sign: {} }}", hex_pk, hex_sign)
}
}
2 changes: 1 addition & 1 deletion core/tests/loadnext/src/rng.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ impl LoadtestRng {
let seed: [u8; SEED_SIZE] = seed_hex
.map(|seed_str| {
let mut output = [0u8; SEED_SIZE];
let decoded_seed = hex::decode(&seed_str).expect("Incorrect seed hex");
let decoded_seed = hex::decode(seed_str).expect("Incorrect seed hex");
output.copy_from_slice(decoded_seed.as_ref());
output
})
Expand Down
2 changes: 1 addition & 1 deletion core/tests/testkit/src/test_setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1282,7 +1282,7 @@ impl TestSetup {
}

pub fn get_tokens(&self) -> Vec<Token> {
self.tokens.iter().map(|(id, _)| Token(*id)).collect()
self.tokens.keys().map(|id| Token(*id)).collect()
}

pub async fn trigger_exodus_if_needed(&self, eth_account: ETHAccountId) {
Expand Down

0 comments on commit 87e870b

Please sign in to comment.