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

fix(L-04): Public Exposure of pause and unpause Functions #311

Open
wants to merge 4 commits into
base: v0.1.0
Choose a base branch
from
Open
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
14 changes: 9 additions & 5 deletions contracts/src/utils/pausable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
//! which can be added to the functions of your contract.
//!
//! Note that they will not be pausable by simply including this module,
//! only once the modifiers are put in place.
//! only once function [`Pausable::when_not_paused`] is put in place.
//!
//! Note that [`Pausable::pause`] and [`Pausable::unpause`] methods are not
//! exposed by default.
//! You should expose them manually in your contract's abi.
ggonzalez94 marked this conversation as resolved.
Show resolved Hide resolved

use alloy_sol_types::sol;
use stylus_proc::{public, sol_storage, SolidityError};
Expand Down Expand Up @@ -67,7 +71,9 @@ impl Pausable {
fn paused(&self) -> bool {
self._paused.get()
}
}

impl Pausable {
/// Triggers `Paused` state.
///
/// # Arguments
Expand Down Expand Up @@ -102,8 +108,7 @@ impl Pausable {
Ok(())
}

/// Modifier to make a function callable only when the contract is NOT
/// paused.
/// Returns error when the contract is NOT paused.
///
/// # Arguments
///
Expand All @@ -120,8 +125,7 @@ impl Pausable {
Ok(())
}

/// Modifier to make a function callable
/// only when the contract is paused.
/// Returns error when the contract is paused.
///
/// # Arguments
///
Expand Down
8 changes: 8 additions & 0 deletions examples/erc20/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,12 @@ impl Erc20Example {
self.pausable.when_not_paused()?;
self.erc20.transfer_from(from, to, value).map_err(|e| e.into())
}

pub fn pause(&mut self) -> Result<(), Vec<u8>> {
self.pausable.pause().map_err(|e| e.into())
}

pub fn unpause(&mut self) -> Result<(), Vec<u8>> {
self.pausable.unpause().map_err(|e| e.into())
}
}
4 changes: 0 additions & 4 deletions examples/erc20/tests/abi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ sol!(
function paused() external view returns (bool paused);
function pause() external;
function unpause() external;
#[derive(Debug)]
function whenPaused() external view;
#[derive(Debug)]
function whenNotPaused() external view;

error EnforcedPause();
error ExpectedPause();
Expand Down
24 changes: 0 additions & 24 deletions examples/erc20/tests/erc20.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1061,18 +1061,6 @@ async fn pauses(alice: Account) -> eyre::Result<()> {

assert_eq!(true, paused);

let result = contract.whenPaused().call().await;

assert!(result.is_ok());

let err = contract
.whenNotPaused()
.call()
.await
.expect_err("should return `EnforcedPause`");

assert!(err.reverted_with(Erc20::EnforcedPause {}));

Ok(())
}

Expand All @@ -1096,18 +1084,6 @@ async fn unpauses(alice: Account) -> eyre::Result<()> {

assert_eq!(false, paused);

let result = contract.whenNotPaused().call().await;

assert!(result.is_ok());

let err = contract
.whenPaused()
.call()
.await
.expect_err("should return `ExpectedPause`");

assert!(err.reverted_with(Erc20::ExpectedPause {}));

Ok(())
}

Expand Down
8 changes: 8 additions & 0 deletions examples/erc721/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,12 @@ impl Erc721Example {

Ok(())
}

pub fn pause(&mut self) -> Result<(), Vec<u8>> {
self.pausable.pause().map_err(|e| e.into())
}

pub fn unpause(&mut self) -> Result<(), Vec<u8>> {
self.pausable.unpause().map_err(|e| e.into())
}
}
4 changes: 0 additions & 4 deletions examples/erc721/tests/abi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ sol!(
function pause() external;
function unpause() external;
#[derive(Debug)]
function whenPaused() external view;
#[derive(Debug)]
function whenNotPaused() external view;
#[derive(Debug)]
function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256 tokenId);
#[derive(Debug)]
function tokenByIndex(uint256 index) external view returns (uint256 tokenId);
Expand Down
24 changes: 0 additions & 24 deletions examples/erc721/tests/erc721.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1371,18 +1371,6 @@ async fn pauses(alice: Account) -> eyre::Result<()> {

assert!(paused);

let result = contract.whenPaused().call().await;

assert!(result.is_ok());

let err = contract
.whenNotPaused()
.call()
.await
.expect_err("should return `EnforcedPause`");

assert!(err.reverted_with(Erc721::EnforcedPause {}));

Ok(())
}

Expand All @@ -1401,18 +1389,6 @@ async fn unpauses(alice: Account) -> eyre::Result<()> {

assert_eq!(false, paused);

let result = contract.whenNotPaused().call().await;

assert!(result.is_ok());

let err = contract
.whenPaused()
.call()
.await
.expect_err("should return `ExpectedPause`");

assert!(err.reverted_with(Erc721::ExpectedPause {}));

Ok(())
}

Expand Down
Loading