Skip to content

Commit 6c4c5ec

Browse files
authored
ref: Address All Stable and Nightly Clippy Warnings (#437)
<!-- Thank you for your interest in contributing to OpenZeppelin! Consider opening an issue for discussion prior to submitting a PR. New features will be merged faster if they were first discussed and designed with the team. Describe the changes introduced in this pull request. Include any context necessary for understanding the PR's purpose. --> <!-- Fill in with issue number --> Resolves #436, #385 #### PR Checklist <!-- Before merging the pull request all of the following must be completed. Feel free to submit a PR or Draft PR even if some items are pending. Some of the items may not apply. --> - [x] Tests - [x] Documentation - [x] Changelog
2 parents 60bb984 + 69b6219 commit 6c4c5ec

File tree

35 files changed

+219
-194
lines changed

35 files changed

+219
-194
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1818

1919
- Implement `MethodError` for `safe_erc20::Error`. #402
2020
- Use `function_selector!` to calculate transfer type selector in `Erc1155`. #417
21+
- Update internal functions of `Erc721` and `Erc721Consecutive` accept reference to `Bytes`. #437
2122

2223
### Fixed
2324

clippy.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
doc-valid-idents = ["OpenZeppelin", ".."]

contracts/src/access/control.rs

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
//! Contract module that allows children to implement role-based access control
2-
//! mechanisms. This is a lightweight version that doesn't allow enumerating
3-
//! role members except through off-chain means by accessing the contract event
4-
//! logs.
2+
//! mechanisms.
3+
//!
4+
//! This is a lightweight version that doesn't allow enumerating role members
5+
//! except through off-chain means by accessing the contract event logs.
56
//!
67
//! Roles are referred to by their `bytes32` identifier. These should be exposed
78
//! in the external API and be unique. The best way to achieve this is by using
@@ -429,18 +430,18 @@ mod tests {
429430
contract.grant_role(ROLE.into(), ALICE).unwrap();
430431
contract.grant_role(ROLE.into(), ALICE).unwrap();
431432
let has_role = contract.has_role(ROLE.into(), ALICE);
432-
assert_eq!(has_role, true);
433+
assert!(has_role);
433434
}
434435

435436
#[motsu::test]
436437
fn not_granted_roles_can_be_revoked(contract: AccessControl) {
437438
_grant_role_to_msg_sender(contract, AccessControl::DEFAULT_ADMIN_ROLE);
438439

439440
let has_role = contract.has_role(ROLE.into(), ALICE);
440-
assert_eq!(has_role, false);
441+
assert!(!has_role);
441442
contract.revoke_role(ROLE.into(), ALICE).unwrap();
442443
let has_role = contract.has_role(ROLE.into(), ALICE);
443-
assert_eq!(has_role, false);
444+
assert!(!has_role);
444445
}
445446

446447
#[motsu::test]
@@ -449,18 +450,18 @@ mod tests {
449450
contract._roles.setter(ROLE.into()).has_role.insert(ALICE, true);
450451

451452
let has_role = contract.has_role(ROLE.into(), ALICE);
452-
assert_eq!(has_role, true);
453+
assert!(has_role);
453454
contract.revoke_role(ROLE.into(), ALICE).unwrap();
454455
let has_role = contract.has_role(ROLE.into(), ALICE);
455-
assert_eq!(has_role, false);
456+
assert!(!has_role);
456457
}
457458

458459
#[motsu::test]
459460
fn non_admin_cannot_revoke_role(contract: AccessControl) {
460461
contract._roles.setter(ROLE.into()).has_role.insert(ALICE, true);
461462

462463
let has_role = contract.has_role(ROLE.into(), ALICE);
463-
assert_eq!(has_role, true);
464+
assert!(has_role);
464465
let err = contract.revoke_role(ROLE.into(), ALICE).unwrap_err();
465466
assert!(matches!(err, Error::UnauthorizedAccount(_)));
466467
}
@@ -472,18 +473,18 @@ mod tests {
472473
contract.revoke_role(ROLE.into(), ALICE).unwrap();
473474
contract.revoke_role(ROLE.into(), ALICE).unwrap();
474475
let has_role = contract.has_role(ROLE.into(), ALICE);
475-
assert_eq!(has_role, false);
476+
assert!(!has_role);
476477
}
477478

478479
#[motsu::test]
479480
fn bearer_can_renounce_role(contract: AccessControl) {
480481
_grant_role_to_msg_sender(contract, ROLE);
481482

482483
let has_role = contract.has_role(ROLE.into(), msg::sender());
483-
assert_eq!(has_role, true);
484+
assert!(has_role);
484485
contract.renounce_role(ROLE.into(), msg::sender()).unwrap();
485486
let has_role = contract.has_role(ROLE.into(), msg::sender());
486-
assert_eq!(has_role, false);
487+
assert!(!has_role);
487488
}
488489

489490
#[motsu::test]
@@ -501,7 +502,7 @@ mod tests {
501502
contract.renounce_role(ROLE.into(), sender).unwrap();
502503
contract.renounce_role(ROLE.into(), sender).unwrap();
503504
let has_role = contract.has_role(ROLE.into(), ALICE);
504-
assert_eq!(has_role, false);
505+
assert!(!has_role);
505506
}
506507

507508
#[motsu::test]
@@ -520,7 +521,7 @@ mod tests {
520521

521522
contract.grant_role(ROLE.into(), ALICE).unwrap();
522523
let has_role = contract.has_role(ROLE.into(), ALICE);
523-
assert_eq!(has_role, true);
524+
assert!(has_role);
524525
}
525526

526527
#[motsu::test]
@@ -531,7 +532,7 @@ mod tests {
531532
contract._roles.setter(ROLE.into()).has_role.insert(ALICE, true);
532533
contract.revoke_role(ROLE.into(), ALICE).unwrap();
533534
let has_role = contract.has_role(ROLE.into(), ALICE);
534-
assert_eq!(has_role, false);
535+
assert!(!has_role);
535536
}
536537

537538
#[motsu::test]
@@ -570,26 +571,26 @@ mod tests {
570571
#[motsu::test]
571572
fn internal_grant_role_true_if_no_role(contract: AccessControl) {
572573
let role_granted = contract._grant_role(ROLE.into(), ALICE);
573-
assert_eq!(role_granted, true);
574+
assert!(role_granted);
574575
}
575576

576577
#[motsu::test]
577578
fn internal_grant_role_false_if_role(contract: AccessControl) {
578579
contract._roles.setter(ROLE.into()).has_role.insert(ALICE, true);
579580
let role_granted = contract._grant_role(ROLE.into(), ALICE);
580-
assert_eq!(role_granted, false);
581+
assert!(!role_granted);
581582
}
582583

583584
#[motsu::test]
584585
fn internal_revoke_role_true_if_role(contract: AccessControl) {
585586
contract._roles.setter(ROLE.into()).has_role.insert(ALICE, true);
586587
let role_revoked = contract._revoke_role(ROLE.into(), ALICE);
587-
assert_eq!(role_revoked, true);
588+
assert!(role_revoked);
588589
}
589590

590591
#[motsu::test]
591592
fn internal_revoke_role_false_if_no_role(contract: AccessControl) {
592593
let role_revoked = contract._revoke_role(ROLE.into(), ALICE);
593-
assert_eq!(role_revoked, false);
594+
assert!(!role_revoked);
594595
}
595596
}

contracts/src/finance/vesting_wallet.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//! A vesting wallet handles the vesting of Ether and ERC-20 tokens for a given
2+
//! beneficiary.
3+
//!
14
//! A vesting wallet is an ownable contract that can receive native currency and
25
//! [`crate::token::erc20::Erc20`] tokens, and release these assets to the
36
//! wallet owner, also referred to as "beneficiary", according to a vesting

contracts/src/token/erc1155/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,7 +1203,7 @@ mod tests {
12031203
}
12041204

12051205
pub(crate) fn random_values(size: usize) -> Vec<U256> {
1206-
(1..size + 1).map(U256::from).collect()
1206+
(1..=size).map(U256::from).collect()
12071207
}
12081208

12091209
fn init(
@@ -1295,12 +1295,12 @@ mod tests {
12951295
contract
12961296
.set_approval_for_all(BOB, true)
12971297
.expect("should approve Bob for operations on all Alice's tokens");
1298-
assert_eq!(contract.is_approved_for_all(alice, BOB), true);
1298+
assert!(contract.is_approved_for_all(alice, BOB));
12991299

13001300
contract.set_approval_for_all(BOB, false).expect(
13011301
"should disapprove Bob for operations on all Alice's tokens",
13021302
);
1303-
assert_eq!(contract.is_approved_for_all(alice, BOB), false);
1303+
assert!(!contract.is_approved_for_all(alice, BOB));
13041304
}
13051305

13061306
#[motsu::test]

contracts/src/token/erc20/extensions/permit.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
//! Permit Contract.
22
//!
33
//! Extension of the ERC-20 standard allowing approvals to be made
4-
//! via signatures, as defined in EIP-2612.
4+
//! via signatures, as defined in the [ERC].
55
//!
66
//! Adds the `permit` method, which can be used to change an account’s
77
//! ERC20 allowance (see [`crate::token::erc20::IErc20::allowance`])
88
//! by presenting a message signed by the account.
99
//! By not relying on [`crate::token::erc20::IErc20::approve`],
1010
//! the token holder account doesn’t need to send a transaction,
1111
//! and thus is not required to hold Ether at all.
12+
//!
13+
//! [ERC]: https://eips.ethereum.org/EIPS/eip-2612
14+
1215
use alloy_primitives::{b256, keccak256, Address, B256, U256};
1316
use alloy_sol_types::{sol, SolType};
1417
use stylus_sdk::{

contracts/src/token/erc20/mod.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -366,11 +366,11 @@ impl Erc20 {
366366
/// # Errors
367367
///
368368
/// * If the `from` address is `Address::ZERO`, then the error
369-
/// [`Error::InvalidSender`] is returned.
369+
/// [`Error::InvalidSender`] is returned.
370370
/// * If the `to` address is `Address::ZERO`, then the error
371-
/// [`Error::InvalidReceiver`] is returned.
372-
/// If the `from` address doesn't have enough tokens, then the error
373-
/// [`Error::InsufficientBalance`] is returned.
371+
/// [`Error::InvalidReceiver`] is returned.
372+
/// * If the `from` address doesn't have enough tokens, then the error
373+
/// [`Error::InsufficientBalance`] is returned.
374374
///
375375
/// # Events
376376
///
@@ -514,9 +514,9 @@ impl Erc20 {
514514
/// # Errors
515515
///
516516
/// * If the `from` address is `Address::ZERO`, then the error
517-
/// [`Error::InvalidSender`] is returned.
518-
/// If the `from` address doesn't have enough tokens, then the error
519-
/// [`Error::InsufficientBalance`] is returned.
517+
/// [`Error::InvalidSender`] is returned.
518+
/// * If the `from` address doesn't have enough tokens, then the error
519+
/// [`Error::InsufficientBalance`] is returned.
520520
///
521521
/// # Events
522522
///

contracts/src/token/erc20/utils/safe_erc20.rs

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//! Wrappers around ERC-20 operations that throw on failure (when the token
2-
//! contract returns false). Tokens that return no value (and instead revert or
2+
//! contract returns false).
3+
//!
4+
//! Tokens that return no value (and instead revert or
35
//! throw on failure) are also supported, non-reverting calls are assumed to be
46
//! successful.
57
//!
@@ -389,7 +391,7 @@ impl SafeErc20 {
389391
///
390392
/// * `data` - Slice of bytes.
391393
fn encodes_true(data: &[u8]) -> bool {
392-
data.split_last().map_or(false, |(last, rest)| {
394+
data.split_last().is_some_and(|(last, rest)| {
393395
*last == 1 && rest.iter().all(|&byte| byte == 0)
394396
})
395397
}
@@ -400,40 +402,31 @@ mod tests {
400402
use super::SafeErc20;
401403
#[test]
402404
fn encodes_true_empty_slice() {
403-
assert_eq!(false, SafeErc20::encodes_true(&vec![]));
405+
assert!(!SafeErc20::encodes_true(&[]));
404406
}
405407

406408
#[test]
407409
fn encodes_false_single_byte() {
408-
assert_eq!(false, SafeErc20::encodes_true(&vec![0]));
410+
assert!(!SafeErc20::encodes_true(&[0]));
409411
}
410412

411413
#[test]
412414
fn encodes_true_single_byte() {
413-
assert_eq!(true, SafeErc20::encodes_true(&vec![1]));
415+
assert!(SafeErc20::encodes_true(&[1]));
414416
}
415417

416418
#[test]
417419
fn encodes_false_many_bytes() {
418-
assert_eq!(
419-
false,
420-
SafeErc20::encodes_true(&vec![0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
421-
);
420+
assert!(!SafeErc20::encodes_true(&[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]));
422421
}
423422

424423
#[test]
425424
fn encodes_true_many_bytes() {
426-
assert_eq!(
427-
true,
428-
SafeErc20::encodes_true(&vec![0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1])
429-
);
425+
assert!(SafeErc20::encodes_true(&[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]));
430426
}
431427

432428
#[test]
433429
fn encodes_true_wrong_bytes() {
434-
assert_eq!(
435-
false,
436-
SafeErc20::encodes_true(&vec![0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1])
437-
);
430+
assert!(!SafeErc20::encodes_true(&[0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1]));
438431
}
439432
}

0 commit comments

Comments
 (0)