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: Investigate Test Coverage Drop #427

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,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)'] }

[workspace.lints.clippy]
pedantic = "warn"
Expand Down Expand Up @@ -102,7 +103,9 @@ tiny-keccak = { version = "2.0.2", features = ["keccak"] }
tokio = { version = "1.12.0", features = ["full"] }
futures = "0.3.30"
dashmap = "6.1.0"
crypto-bigint = { version = "0.5.5", default-features = false, features = ["zeroize"] }
crypto-bigint = { version = "0.5.5", default-features = false, features = [
"zeroize",
] }
num-traits = "0.2.14"
zeroize = { version = "1.8.1", features = ["derive"] }
proptest = "1"
Expand Down
135 changes: 75 additions & 60 deletions contracts/src/finance/vesting_wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
//! By setting the duration to 0, one can configure this contract to behave like
//! an asset timelock that hold tokens for a beneficiary until a specified time.
//!
//! NOTE: Since the wallet is [`Ownable`], and ownership

Check failure on line 14 in contracts/src/finance/vesting_wallet.rs

View workflow job for this annotation

GitHub Actions / nightly / doc

unresolved link to `Ownable`
//! can be transferred, it is possible to sell unvested tokens. Preventing this
//! in a smart contract is difficult, considering that: 1) a beneficiary address
//! could be a counterfactually deployed contract, 2) there is likely to be a
Expand All @@ -23,64 +23,97 @@
//! intended.

use alloy_primitives::{Address, U256, U64};
use alloy_sol_types::sol;
use openzeppelin_stylus_proc::interface_id;
use stylus_sdk::{
block,
call::{self, call, Call},
call::{call, Call},
contract, evm, function_selector,
storage::TopLevelStorage,
stylus_proc::{public, sol_storage, SolidityError},
stylus_proc::public,
};

use crate::{
access::ownable::{self, IOwnable, Ownable},
token::erc20::utils::safe_erc20::{self, ISafeErc20, SafeErc20},
access::ownable::IOwnable, token::erc20::utils::safe_erc20::ISafeErc20,
};

sol! {
/// Emitted when `amount` of Ether has been released.
///
/// * `amount` - Total Ether released.
#[allow(missing_docs)]
event EtherReleased(uint256 amount);
#[cfg_attr(coverage, coverage(off))]
mod sol_defs {
use alloy_sol_types::sol;
use stylus_sdk::{
call,
stylus_proc::{sol_storage, SolidityError},
};

use crate::{
access::ownable::{self, Ownable},
token::erc20::utils::safe_erc20::{self, SafeErc20},
};

sol! {
/// Emitted when `amount` of Ether has been released.
///
/// * `amount` - Total Ether released.
#[allow(missing_docs)]
event EtherReleased(uint256 amount);

/// Emitted when `amount` of ERC-20 `token` has been released.
///
/// * `token` - Address of the token being released.
/// * `amount` - Number of tokens released.
#[allow(missing_docs)]
event ERC20Released(address indexed token, uint256 amount);
}

/// Emitted when `amount` of ERC-20 `token` has been released.
///
/// * `token` - Address of the token being released.
/// * `amount` - Number of tokens released.
#[allow(missing_docs)]
event ERC20Released(address indexed token, uint256 amount);
}
sol! {
/// Indicates an error related to the underlying Ether transfer.
#[derive(Debug)]
#[allow(missing_docs)]
error ReleaseEtherFailed();

/// The token address is not valid (eg. `Address::ZERO`).
///
/// * `token` - Address of the token being released.
#[derive(Debug)]
#[allow(missing_docs)]
error InvalidToken(address token);
}

sol! {
/// Indicates an error related to the underlying Ether transfer.
#[derive(Debug)]
#[allow(missing_docs)]
error ReleaseEtherFailed();
/// An error that occurred in the [`VestingWallet`] contract.
#[derive(SolidityError, Debug)]
pub enum Error {
/// Error type from [`Ownable`] contract [`ownable::Error`].
Ownable(ownable::Error),
/// Indicates an error related to the underlying Ether transfer.
ReleaseEtherFailed(call::Error),
/// Error type from [`SafeErc20`] contract [`safe_erc20::Error`].
SafeErc20(safe_erc20::Error),
/// The token address is not valid. (eg. `Address::ZERO`).
InvalidToken(InvalidToken),
}

/// The token address is not valid (eg. `Address::ZERO`).
///
/// * `token` - Address of the token being released.
#[derive(Debug)]
#[allow(missing_docs)]
error InvalidToken(address token);
sol_storage! {
/// State of the [`VestingWallet`] Contract.
pub struct VestingWallet {
/// [`Ownable`] contract.
Ownable ownable;
/// Amount of Ether already released.
uint256 _released;
/// Amount of ERC-20 tokens already released.
mapping(address => uint256) _erc20_released;
/// Start timestamp.
uint64 _start;
/// Vesting duration.
uint64 _duration;
/// [`SafeErc20`] contract.
SafeErc20 safe_erc20;
}
}
}

/// An error that occurred in the [`VestingWallet`] contract.
#[derive(SolidityError, Debug)]
pub enum Error {
/// Error type from [`Ownable`] contract [`ownable::Error`].
Ownable(ownable::Error),
/// Indicates an error related to the underlying Ether transfer.
ReleaseEtherFailed(call::Error),
/// Error type from [`SafeErc20`] contract [`safe_erc20::Error`].
SafeErc20(safe_erc20::Error),
/// The token address is not valid. (eg. `Address::ZERO`).
InvalidToken(InvalidToken),
}
pub use sol_defs::VestingWallet;
use sol_defs::*;

Check warning on line 114 in contracts/src/finance/vesting_wallet.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] contracts/src/finance/vesting_wallet.rs#L114

warning: usage of wildcard import --> contracts/src/finance/vesting_wallet.rs:114:5 | 114 | use sol_defs::*; | ^^^^^^^^^^^ help: try: `sol_defs::{ERC20Released, Error, EtherReleased, InvalidToken}` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#wildcard_imports = note: `-W clippy::wildcard-imports` implied by `-W clippy::pedantic` = help: to override `-W clippy::pedantic` add `#[allow(clippy::wildcard_imports)]`
Raw output
contracts/src/finance/vesting_wallet.rs:114:5:w:warning: usage of wildcard import
   --> contracts/src/finance/vesting_wallet.rs:114:5
    |
114 | use sol_defs::*;
    |     ^^^^^^^^^^^ help: try: `sol_defs::{ERC20Released, Error, EtherReleased, InvalidToken}`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#wildcard_imports
    = note: `-W clippy::wildcard-imports` implied by `-W clippy::pedantic`
    = help: to override `-W clippy::pedantic` add `#[allow(clippy::wildcard_imports)]`


__END__
use token::IErc20;

pub use token::IErc20;
#[allow(missing_docs)]
mod token {
stylus_sdk::stylus_proc::sol_interface! {
Expand All @@ -91,24 +124,6 @@
}
}

sol_storage! {
/// State of the [`VestingWallet`] Contract.
pub struct VestingWallet {
/// [`Ownable`] contract.
Ownable ownable;
/// Amount of Ether already released.
uint256 _released;
/// Amount of ERC-20 tokens already released.
mapping(address => uint256) _erc20_released;
/// Start timestamp.
uint64 _start;
/// Vesting duration.
uint64 _duration;
/// [`SafeErc20`] contract.
SafeErc20 safe_erc20;
}
}

/// NOTE: Implementation of [`TopLevelStorage`] to be able use `&mut self` when
/// calling other contracts and not `&mut (impl TopLevelStorage +
/// BorrowMut<Self>)`. Should be fixed in the future by the Stylus team.
Expand All @@ -120,7 +135,7 @@
/// The error type associated to this trait implementation.
type Error: Into<alloc::vec::Vec<u8>>;

/// Returns the address of the current owner.

Check failure on line 138 in contracts/src/finance/vesting_wallet.rs

View workflow job for this annotation

GitHub Actions / nightly / doc

unresolved link to `Ownable::owner`
///
/// Re-export of [`Ownable::owner`].
///
Expand All @@ -129,7 +144,7 @@
/// * `&self` - Read access to the contract's state.
fn owner(&self) -> Address;

/// Transfers ownership of the contract to a new account (`new_owner`). Can

Check failure on line 147 in contracts/src/finance/vesting_wallet.rs

View workflow job for this annotation

GitHub Actions / nightly / doc

unresolved link to `Ownable::transfer_ownership`

Check failure on line 147 in contracts/src/finance/vesting_wallet.rs

View workflow job for this annotation

GitHub Actions / nightly / doc

unresolved link to `ownable::Error::UnauthorizedAccount`

Check failure on line 147 in contracts/src/finance/vesting_wallet.rs

View workflow job for this annotation

GitHub Actions / nightly / doc

unresolved link to `ownable::Error::InvalidOwner`

Check failure on line 147 in contracts/src/finance/vesting_wallet.rs

View workflow job for this annotation

GitHub Actions / nightly / doc

unresolved link to `ownable::OwnershipTransferred`
/// only be called by the current owner.
///
/// Re-export of [`Ownable::transfer_ownership`].
Expand All @@ -154,7 +169,7 @@
new_owner: Address,
) -> Result<(), Self::Error>;

/// Leaves the contract without owner. It will not be possible to call

Check failure on line 172 in contracts/src/finance/vesting_wallet.rs

View workflow job for this annotation

GitHub Actions / nightly / doc

unresolved link to `Ownable::only_owner`

Check failure on line 172 in contracts/src/finance/vesting_wallet.rs

View workflow job for this annotation

GitHub Actions / nightly / doc

unresolved link to `Ownable::renounce_ownership`

Check failure on line 172 in contracts/src/finance/vesting_wallet.rs

View workflow job for this annotation

GitHub Actions / nightly / doc

unresolved link to `ownable::Error::UnauthorizedAccount`

Check failure on line 172 in contracts/src/finance/vesting_wallet.rs

View workflow job for this annotation

GitHub Actions / nightly / doc

unresolved link to `ownable::OwnershipTransferred`
/// [`Ownable::only_owner`] functions. Can only be called by the current
/// owner.
///
Expand Down Expand Up @@ -343,7 +358,7 @@
) -> Result<U256, Self::Error>;
}

#[public]

Check warning on line 361 in contracts/src/finance/vesting_wallet.rs

View workflow job for this annotation

GitHub Actions / nightly / doc

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

Check warning on line 361 in contracts/src/finance/vesting_wallet.rs

View workflow job for this annotation

GitHub Actions / ubuntu / beta

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

Check warning on line 361 in contracts/src/finance/vesting_wallet.rs

View workflow job for this annotation

GitHub Actions / ubuntu / beta

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

Expand Down
1 change: 1 addition & 0 deletions contracts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
)]
#![cfg_attr(not(feature = "std"), no_std, no_main)]
#![deny(rustdoc::broken_intra_doc_links)]
#![cfg_attr(coverage, feature(coverage_attribute))]

Check failure on line 49 in contracts/src/lib.rs

View workflow job for this annotation

GitHub Actions / ubuntu / stable / coverage

`#![feature]` may not be used on the stable release channel
extern crate alloc;

pub mod access;
Expand Down
Loading