Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improve code coverage #438

Merged
merged 26 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
2c50b6d
remove sol! macros from code coverage
qalisander Dec 8, 2024
ff255cd
replace sol_storage! with #[storage]
qalisander Dec 8, 2024
89bc016
use nightly in codecov ci
qalisander Dec 8, 2024
18e3a16
remove sol_interface! macro from code coverage
qalisander Dec 8, 2024
fe7f77b
++
qalisander Dec 8, 2024
1536d68
++
qalisander Dec 8, 2024
9ff05dd
++
qalisander Dec 8, 2024
2e1fd70
include a test case in code coverage
qalisander Dec 8, 2024
eca3bd4
exclude sol! macros from code coverage
qalisander Dec 8, 2024
8774ec3
++
qalisander Dec 8, 2024
ca03c33
Merge remote-tracking branch 'origin/main' into qalisander/make-codec…
qalisander Dec 10, 2024
9881bfa
update description for the workflow
qalisander Dec 10, 2024
5fc416f
Merge remote-tracking branch 'origin/main' into qalisander/make-codec…
qalisander Dec 10, 2024
7060928
use #[storage] in erc1155 supply
qalisander Dec 10, 2024
fadc0d0
Merge branch 'main' into qalisander/make-codecov-great-again
qalisander Dec 10, 2024
1ac80c1
Merge branch 'main' into qalisander/make-codecov-great-again
bidzyyys Dec 10, 2024
a5a2fba
format "*.yml" files
qalisander Dec 11, 2024
8d41e4b
++
qalisander Dec 11, 2024
49fa1e4
exclude e2e and motsu from codecov
qalisander Dec 11, 2024
6e7e5a4
exclude examples from code coverage
qalisander Dec 11, 2024
200c2c0
migrate examples to #[storage] macro
qalisander Dec 11, 2024
b52baa6
migrate readme's to #[storage] macro
qalisander Dec 11, 2024
495294d
migrate adoc's to #[storage] macro
qalisander Dec 11, 2024
6df192f
++
qalisander Dec 11, 2024
19f284d
++
qalisander Dec 11, 2024
733f2e7
remove unused erc1155 in test
qalisander Dec 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/nostd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ permissions:
contents: read
on:
push:
branches: [ main, release/* ]
branches: [ main, release/* ]
pull_request:
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
Expand Down
13 changes: 8 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ permissions:
contents: read
on:
push:
branches: [main, release/*]
branches: [ main, release/* ]
qalisander marked this conversation as resolved.
Show resolved Hide resolved
paths-ignore:
- "**.md"
- "**.adoc"
Expand All @@ -32,7 +32,7 @@ jobs:
matrix:
# Run on stable and beta to ensure that tests won't break on the next
# version of the rust toolchain.
toolchain: [stable, beta]
toolchain: [ stable, beta ]
steps:
- uses: actions/checkout@v4
with:
Expand Down Expand Up @@ -69,7 +69,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [macos-latest]
os: [ macos-latest ]
# Windows fails because of `stylus-proc`.
# os: [macos-latest, windows-latest]
steps:
Expand Down Expand Up @@ -117,16 +117,19 @@ jobs:
#
# for lots of more discussion.
runs-on: ubuntu-latest
name: ubuntu / stable / coverage
name: ubuntu / nightly / coverage
steps:
- uses: actions/checkout@v4
with:
submodules: true

- name: Install rust
# We run in nightly to make use of the `#[coverage(off)]` attribute (see _contracts/src/lib.rs_)
# We'll return to stable release after the tracking issue is merged (and the feature is stable)
# See: https://github.com/rust-lang/rust/issues/84605
uses: actions-rust-lang/setup-rust-toolchain@v1
0xNeshi marked this conversation as resolved.
Show resolved Hide resolved
with:
0xNeshi marked this conversation as resolved.
Show resolved Hide resolved
toolchain: stable
toolchain: nightly
components: llvm-tools-preview
rustflags: ""

Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ version = "0.2.0-alpha.1"
missing_docs = "warn"
unreachable_pub = "warn"
rust_2021_compatibility = { level = "warn", priority = -1 }
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(coverage_nightly)'] }

[workspace.lints.clippy]
pedantic = "warn"
Expand Down
117 changes: 62 additions & 55 deletions contracts/src/access/control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,52 +41,59 @@
//! accounts that have been granted it. We recommend using
//! `AccessControlDefaultAdminRules` to enforce additional security measures for
//! this role.
use alloy_primitives::{Address, B256};
use alloy_sol_types::sol;
use alloy_primitives::{Address, FixedBytes, B256};
pub use sol::*;
use stylus_sdk::{
evm, msg,
stylus_proc::{public, sol_storage, SolidityError},
prelude::storage,
storage::{StorageBool, StorageFixedBytes, StorageMap},
stylus_proc::{public, SolidityError},
};

sol! {
/// Emitted when `new_admin_role` is set as `role`'s admin role, replacing
/// `previous_admin_role`.
///
/// `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite
/// `RoleAdminChanged` not being emitted signaling this.
#[allow(missing_docs)]
event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previous_admin_role, bytes32 indexed new_admin_role);
/// Emitted when `account` is granted `role`.
///
/// `sender` is the account that originated the contract call. This account
/// bears the admin role (for the granted role).
/// Expected in cases where the role was granted using the internal
/// [`AccessControl::grant_role`].
#[allow(missing_docs)]
event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);
/// Emitted when `account` is revoked `role`.
///
/// `sender` is the account that originated the contract call:
/// - if using `revoke_role`, it is the admin role bearer.
/// - if using `renounce_role`, it is the role bearer (i.e. `account`).
#[allow(missing_docs)]
event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);
}

sol! {
/// The `account` is missing a role.
///
/// * `account` - Account that was found to not be authorized.
/// * `needed_role` - The missing role.
#[derive(Debug)]
#[allow(missing_docs)]
error AccessControlUnauthorizedAccount(address account, bytes32 needed_role);
/// The caller of a function is not the expected one.
///
/// NOTE: Don't confuse with [`AccessControlUnauthorizedAccount`].
#[derive(Debug)]
#[allow(missing_docs)]
error AccessControlBadConfirmation();
#[cfg_attr(coverage_nightly, coverage(off))]
mod sol {
0xNeshi marked this conversation as resolved.
Show resolved Hide resolved
use alloy_sol_macro::sol;

sol! {
/// Emitted when `new_admin_role` is set as `role`'s admin role, replacing
/// `previous_admin_role`.
///
/// `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite
/// `RoleAdminChanged` not being emitted signaling this.
#[allow(missing_docs)]
event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previous_admin_role, bytes32 indexed new_admin_role);
/// Emitted when `account` is granted `role`.
///
/// `sender` is the account that originated the contract call. This account
/// bears the admin role (for the granted role).
/// Expected in cases where the role was granted using the internal
/// [`AccessControl::grant_role`].
#[allow(missing_docs)]
event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);
/// Emitted when `account` is revoked `role`.
///
/// `sender` is the account that originated the contract call:
/// - if using `revoke_role`, it is the admin role bearer.
/// - if using `renounce_role`, it is the role bearer (i.e. `account`).
#[allow(missing_docs)]
event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);
}

sol! {
/// The `account` is missing a role.
///
/// * `account` - Account that was found to not be authorized.
/// * `needed_role` - The missing role.
#[derive(Debug)]
#[allow(missing_docs)]
error AccessControlUnauthorizedAccount(address account, bytes32 needed_role);
/// The caller of a function is not the expected one.
///
/// NOTE: Don't confuse with [`AccessControlUnauthorizedAccount`].
#[derive(Debug)]
#[allow(missing_docs)]
error AccessControlBadConfirmation();
}
}

/// An error that occurred in the implementation of an [`AccessControl`]
Expand All @@ -99,23 +106,23 @@
BadConfirmation(AccessControlBadConfirmation),
}

sol_storage! {
/// Information about a specific role.
pub struct RoleData {
/// Whether an account is member of a certain role.
mapping(address => bool) has_role;
/// The admin role for this role.
bytes32 admin_role;
}
/// Information about a specific role.
#[storage]
pub struct RoleData {
bidzyyys marked this conversation as resolved.
Show resolved Hide resolved
/// Whether an account is member of a certain role.
pub has_role: StorageMap<Address, StorageBool>,
/// The admin role for this role.
pub admin_role: StorageFixedBytes<32>,
}

/// State of an `AccessControl` contract.
pub struct AccessControl {
/// Role identifier -> Role information.
mapping(bytes32 => RoleData) _roles;
}
/// State of an `AccessControl` contract.
#[storage]
pub struct AccessControl {
/// Role identifier -> Role information.
pub _roles: StorageMap<FixedBytes<32>, RoleData>,
}

#[public]

Check warning on line 125 in contracts/src/access/control.rs

View workflow job for this annotation

GitHub Actions / nightly / doc

unexpected `cfg` condition value: `export-abi`

Check warning on line 125 in contracts/src/access/control.rs

View workflow job for this annotation

GitHub Actions / ubuntu / beta

unexpected `cfg` condition value: `export-abi`

Check warning on line 125 in contracts/src/access/control.rs

View workflow job for this annotation

GitHub Actions / ubuntu / beta

unexpected `cfg` condition value: `export-abi`

Check warning on line 125 in contracts/src/access/control.rs

View workflow job for this annotation

GitHub Actions / ubuntu / nightly / coverage

unexpected `cfg` condition value: `export-abi`
impl AccessControl {
/// The default admin role. `[0; 32]` by default.
pub const DEFAULT_ADMIN_ROLE: [u8; 32] = [0; 32];
Expand Down
64 changes: 35 additions & 29 deletions contracts/src/access/ownable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,43 @@
//! [`Ownable::only_owner`] function, which can be called to restrict operations
//! to the owner.
use alloy_primitives::Address;
use alloy_sol_types::sol;
use openzeppelin_stylus_proc::interface_id;
pub use sol::*;
use stylus_sdk::{
call::MethodError,
evm, msg,
stylus_proc::{public, sol_storage, SolidityError},
prelude::storage,
storage::StorageAddress,
stylus_proc::{public, SolidityError},
};

sol! {
/// Emitted when ownership gets transferred between accounts.
///
/// * `previous_owner` - Address of the previous owner.
/// * `new_owner` - Address of the new owner.
#[allow(missing_docs)]
event OwnershipTransferred(address indexed previous_owner, address indexed new_owner);
}
#[cfg_attr(coverage_nightly, coverage(off))]
mod sol {
use alloy_sol_macro::sol;

sol! {
/// Emitted when ownership gets transferred between accounts.
///
/// * `previous_owner` - Address of the previous owner.
/// * `new_owner` - Address of the new owner.
#[allow(missing_docs)]
event OwnershipTransferred(address indexed previous_owner, address indexed new_owner);
}

sol! {
/// The caller account is not authorized to perform an operation.
///
/// * `account` - Account that was found to not be authorized.
#[derive(Debug)]
#[allow(missing_docs)]
error OwnableUnauthorizedAccount(address account);
/// The owner is not a valid owner account. (eg. `Address::ZERO`)
///
/// * `owner` - Account that's not allowed to become the owner.
#[derive(Debug)]
#[allow(missing_docs)]
error OwnableInvalidOwner(address owner);
sol! {
/// The caller account is not authorized to perform an operation.
///
/// * `account` - Account that was found to not be authorized.
#[derive(Debug)]
#[allow(missing_docs)]
error OwnableUnauthorizedAccount(address account);
/// The owner is not a valid owner account. (eg. `Address::ZERO`)
///
/// * `owner` - Account that's not allowed to become the owner.
#[derive(Debug)]
#[allow(missing_docs)]
error OwnableInvalidOwner(address owner);
}
}

/// An error that occurred in the implementation of an [`Ownable`] contract.
Expand All @@ -56,12 +63,11 @@
}
}

sol_storage! {
/// State of an `Ownable` contract.
pub struct Ownable {
/// The current owner of this contract.
address _owner;
}
/// State of an `Ownable` contract.
#[storage]
pub struct Ownable {
/// The current owner of this contract.
pub _owner: StorageAddress,
}

/// Interface for an [`Ownable`] contract.
Expand Down Expand Up @@ -120,7 +126,7 @@
fn renounce_ownership(&mut self) -> Result<(), Self::Error>;
}

#[public]

Check warning on line 129 in contracts/src/access/ownable.rs

View workflow job for this annotation

GitHub Actions / nightly / doc

unexpected `cfg` condition value: `export-abi`

Check warning on line 129 in contracts/src/access/ownable.rs

View workflow job for this annotation

GitHub Actions / ubuntu / beta

unexpected `cfg` condition value: `export-abi`

Check warning on line 129 in contracts/src/access/ownable.rs

View workflow job for this annotation

GitHub Actions / ubuntu / beta

unexpected `cfg` condition value: `export-abi`

Check warning on line 129 in contracts/src/access/ownable.rs

View workflow job for this annotation

GitHub Actions / ubuntu / nightly / coverage

unexpected `cfg` condition value: `export-abi`
impl IOwnable for Ownable {
type Error = Error;

Expand Down
46 changes: 26 additions & 20 deletions contracts/src/access/ownable_two_step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,34 @@
//! available.

use alloy_primitives::Address;
use alloy_sol_types::sol;
pub use sol::*;
use stylus_sdk::{
evm, msg,
stylus_proc::{public, sol_storage, SolidityError},
prelude::storage,
storage::StorageAddress,
stylus_proc::{public, SolidityError},
};

use crate::access::ownable::{
Error as OwnableError, IOwnable, Ownable, OwnableUnauthorizedAccount,
};

sol! {
/// Emitted when ownership transfer starts.
///
/// * `previous_owner` - Address of the previous owner.
/// * `new_owner` - Address of the new owner, to which the ownership
/// will be transferred.
event OwnershipTransferStarted(
address indexed previous_owner,
address indexed new_owner
);
#[cfg_attr(coverage_nightly, coverage(off))]
mod sol {
use alloy_sol_macro::sol;

sol! {
/// Emitted when ownership transfer starts.
///
/// * `previous_owner` - Address of the previous owner.
/// * `new_owner` - Address of the new owner, to which the ownership
/// will be transferred.
event OwnershipTransferStarted(
address indexed previous_owner,
address indexed new_owner
);

}
}

/// An error that occurred in the implementation of an [`Ownable2Step`]
Expand All @@ -48,14 +55,13 @@
Ownable(OwnableError),
}

sol_storage! {
/// State of an `Ownable2Step` contract.
pub struct Ownable2Step {
/// [`Ownable`] contract.
Ownable _ownable;
/// Pending owner of the contract.
address _pending_owner;
}
/// State of an `Ownable2Step` contract.
#[storage]
pub struct Ownable2Step {
/// [`Ownable`] contract.
pub _ownable: Ownable,
/// Pending owner of the contract.
pub _pending_owner: StorageAddress,
}

/// Interface for an [`Ownable2Step`] contract.
Expand Down Expand Up @@ -140,7 +146,7 @@
fn renounce_ownership(&mut self) -> Result<(), Self::Error>;
}

#[public]

Check warning on line 149 in contracts/src/access/ownable_two_step.rs

View workflow job for this annotation

GitHub Actions / nightly / doc

unexpected `cfg` condition value: `export-abi`

Check warning on line 149 in contracts/src/access/ownable_two_step.rs

View workflow job for this annotation

GitHub Actions / ubuntu / beta

unexpected `cfg` condition value: `export-abi`

Check warning on line 149 in contracts/src/access/ownable_two_step.rs

View workflow job for this annotation

GitHub Actions / ubuntu / beta

unexpected `cfg` condition value: `export-abi`

Check warning on line 149 in contracts/src/access/ownable_two_step.rs

View workflow job for this annotation

GitHub Actions / ubuntu / nightly / coverage

unexpected `cfg` condition value: `export-abi`
impl IOwnable2Step for Ownable2Step {
type Error = Error;

Expand Down
Loading
Loading