-
Notifications
You must be signed in to change notification settings - Fork 12.3k
ERC6909Pausable #6174
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
Open
RenanSouza2
wants to merge
3
commits into
OpenZeppelin:master
Choose a base branch
from
RenanSouza2:erc6909-pausable
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
ERC6909Pausable #6174
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| 'openzeppelin-solidity': patch | ||
| --- | ||
|
|
||
| Implements ERC6909Pausable |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| // OpenZeppelin Contracts (last updated v5.5.0) (token/ERC6909/extensions/ERC6909Pausable.sol) | ||
|
|
||
| pragma solidity ^0.8.24; | ||
|
|
||
| import {ERC6909} from "../ERC6909.sol"; | ||
| import {Pausable} from "../../../utils/Pausable.sol"; | ||
|
|
||
| /** | ||
| * @dev ERC-6909 token with pausable token transfers, minting and burning. | ||
| * | ||
| * Useful for scenarios such as preventing trades until the end of an evaluation | ||
| * period, or having an emergency switch for freezing all token transfers in the | ||
| * event of a large bug. | ||
| * | ||
| * IMPORTANT: This contract does not include public pause and unpause functions. In | ||
| * addition to inheriting this contract, you must define both functions, invoking the | ||
| * {Pausable-_pause} and {Pausable-_unpause} internal functions, with appropriate | ||
| * access control, e.g. using {AccessControl} or {Ownable}. Not doing so will | ||
| * make the contract pause mechanism of the contract unreachable, and thus unusable. | ||
| */ | ||
| abstract contract ERC6909Pausable is ERC6909, Pausable { | ||
| /** | ||
| * @dev See {ERC6909-_update}. | ||
| * | ||
| * Requirements: | ||
| * | ||
| * - the contract must not be paused. | ||
| */ | ||
| function _update(address from, address to, uint256 ids, uint256 values) internal virtual override whenNotPaused { | ||
| super._update(from, to, ids, values); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| const { ethers } = require('hardhat'); | ||
| const { expect } = require('chai'); | ||
| const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers'); | ||
| const { shouldBehaveLikeERC6909 } = require('../ERC6909.behavior'); | ||
|
|
||
| async function fixture() { | ||
| const [holder, operator, recipient, other] = await ethers.getSigners(); | ||
| const token = await ethers.deployContract('$ERC6909Pausable'); | ||
| return { token, holder, operator, recipient, other }; | ||
| } | ||
|
|
||
| describe('ERC6909Pausable', function () { | ||
| const firstTokenId = 37n; | ||
| const firstTokenValue = 42n; | ||
| const secondTokenId = 19842n; | ||
| const secondTokenValue = 23n; | ||
|
|
||
| beforeEach(async function () { | ||
| Object.assign(this, await loadFixture(fixture)); | ||
| }); | ||
|
|
||
| shouldBehaveLikeERC6909(); | ||
|
|
||
| describe('when token is paused', function () { | ||
| beforeEach(async function () { | ||
| await this.token.connect(this.holder).setOperator(this.operator, true); | ||
| await this.token.$_mint(this.holder, firstTokenId, firstTokenValue); | ||
| await this.token.$_pause(); | ||
| }); | ||
|
|
||
| it('reverts when trying to transfer', async function () { | ||
| await expect( | ||
| this.token.connect(this.holder).transfer(this.recipient, firstTokenId, firstTokenValue), | ||
| ).to.be.revertedWithCustomError(this.token, 'EnforcedPause'); | ||
| }); | ||
|
|
||
| it('reverts when trying to transferFrom from operator', async function () { | ||
| await expect( | ||
| this.token.connect(this.operator).transferFrom(this.holder, this.recipient, firstTokenId, firstTokenValue), | ||
| ).to.be.revertedWithCustomError(this.token, 'EnforcedPause'); | ||
| }); | ||
|
|
||
| it('reverts when trying to mint', async function () { | ||
| await expect(this.token.$_mint(this.holder, secondTokenId, secondTokenValue)).to.be.revertedWithCustomError( | ||
| this.token, | ||
| 'EnforcedPause', | ||
| ); | ||
| }); | ||
|
|
||
| it('reverts when trying to burn', async function () { | ||
| await expect(this.token.$_burn(this.holder, firstTokenId, firstTokenValue)).to.be.revertedWithCustomError( | ||
| this.token, | ||
| 'EnforcedPause', | ||
| ); | ||
| }); | ||
|
|
||
| describe('setOperator', function () { | ||
| it('approves an operator', async function () { | ||
| await this.token.connect(this.holder).setOperator(this.other, true); | ||
| expect(await this.token.isOperator(this.holder, this.other)).to.be.true; | ||
| }); | ||
|
|
||
| it('disapproves an operator', async function () { | ||
| await this.token.connect(this.holder).setOperator(this.other, false); | ||
| expect(await this.token.isOperator(this.holder, this.other)).to.be.false; | ||
| }); | ||
| }); | ||
|
|
||
| describe('balanceOf', function () { | ||
| it('returns the token value owned by the given address', async function () { | ||
| expect(await this.token.balanceOf(this.holder, firstTokenId)).to.equal(firstTokenValue); | ||
| }); | ||
| }); | ||
|
|
||
| describe('isOperator', function () { | ||
| it('returns the approval of the operator', async function () { | ||
| expect(await this.token.isOperator(this.holder, this.operator)).to.be.true; | ||
| }); | ||
| }); | ||
| }); | ||
| }); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
disapproves an operatortest never makesotheran operatorIn this block,
this.otheris never approved before callingsetOperator(this.other, false), so the test will pass even if disapproval is a no-op. To actually exercise revocation while paused, first approveother, then disapprove:describe('setOperator', function () { it('approves an operator', async function () { await this.token.connect(this.holder).setOperator(this.other, true); expect(await this.token.isOperator(this.holder, this.other)).to.be.true; }); it('disapproves an operator', async function () { - await this.token.connect(this.holder).setOperator(this.other, false); - expect(await this.token.isOperator(this.holder, this.other)).to.be.false; + await this.token.connect(this.holder).setOperator(this.other, true); + await this.token.connect(this.holder).setOperator(this.other, false); + expect(await this.token.isOperator(this.holder, this.other)).to.be.false; }); });This way the test guarantees that operator revocation still works while the token is paused.
📝 Committable suggestion
🤖 Prompt for AI Agents