diff --git a/contracts/solidity/errors/Errors.sol b/contracts/solidity/errors/Errors.sol index 6a9695f70..d390ba5f2 100644 --- a/contracts/solidity/errors/Errors.sol +++ b/contracts/solidity/errors/Errors.sol @@ -45,8 +45,8 @@ contract Errors { function tryCatchWithErrorMessageRevert(string memory message) external returns (int value, bool success) { try errorsExternal.revertWithErrorMessage(message) returns (bool v) { return (1, v); - } catch Error(string memory message) { - emit Result(0, message); + } catch Error(string memory _message) { + emit Result(0, _message); } } diff --git a/contracts/solidity/oz/Pausable/Pausable.sol b/contracts/solidity/oz/Pausable/Pausable.sol new file mode 100644 index 000000000..d63510c23 --- /dev/null +++ b/contracts/solidity/oz/Pausable/Pausable.sol @@ -0,0 +1,24 @@ +// SPDX-License-Identifier: Apache-2.0 +pragma solidity ^0.8.20; + +import "@openzeppelin/contracts/utils/Pausable.sol"; + +contract PausableTest is Pausable { + string public message; + + function setPausedMessage(string calldata _message) external whenNotPaused { + message = _message; + } + + function getPausedMessage() external view whenPaused returns (string memory) { + return message; + } + + function pause() external { + _pause(); + } + + function unpause() external { + _unpause(); + } +} \ No newline at end of file diff --git a/test/solidity/oz/pausable/pausable.js b/test/solidity/oz/pausable/pausable.js new file mode 100644 index 000000000..6ac1fdb8b --- /dev/null +++ b/test/solidity/oz/pausable/pausable.js @@ -0,0 +1,101 @@ +/*- + * + * Hedera Smart Contracts + * + * Copyright (C) 2023 Hedera Hashgraph, LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +const { expect } = require('chai') +const { ethers } = require('hardhat') + +describe('@solidityequiv3 Pausable', function () { + let signers,wallet + let contract + const CALL_EXCEPTION = 'CALL_EXCEPTION' + + before(async function () { + signers = await ethers.getSigners() + wallet = signers[0] + + const factory = await ethers.getContractFactory('PausableTest') + contract = await factory.deploy() + await contract.deployed() + }) + + it('should BE able to call function "setPausedMessage" with "whenNotPaused" modifier when unpaused', async function () { + const tx = await contract.setPausedMessage("Hello World") + await tx.wait() + const message = await contract.message() + + expect(message).to.equal("Hello World") + }) + + it('should NOT be able to call function "setPausedMessage" with "whenNotPaused" modifier when paused', async function () { + await contract.pause() + const tx = await contract.setPausedMessage("Hello World") + + expect(tx.wait()).to.eventually.be.rejected.and.have.property('code', CALL_EXCEPTION) + }) + + it('should BE able to call function "getPausedMessage" with "whenNotPaused" modifier when unpaused', async function () { + expect(await contract.getPausedMessage()).to.be.equal("Hello World") + }) + + it('should NOT be able to call function "getPausedMessage" with "whenNotPaused" modifier when paused', async function () { + await contract.unpause() + + expect(contract.getPausedMessage()).to.eventually.be.rejected.and.have.property('code', CALL_EXCEPTION) + }) + + it('should fire event when Paused', async function () { + const tx = await contract.pause() + const rec = await tx.wait() + const event = rec.events[0] + const account = event.args.account + + + expect(event.event).to.be.equal("Paused") + expect(account).to.be.equal(wallet.address) + }) + + it('should fire event when Unpaused', async function () { + const tx = await contract.unpause() + const rec = await tx.wait() + const event = rec.events[0] + const account = event.args.account + + + expect(event.event).to.be.equal("Unpaused") + expect(account).to.be.equal(wallet.address) + }) + + it('should Not be able to pause when paused', async function () { + const tx = await contract.pause() + await tx.wait() + const tx2 = await contract.pause() + + expect(tx2.wait()).to.eventually.be.rejected.and.have.property('code', CALL_EXCEPTION) + }) + + it('should Not be able to Unpause when Unpaused', async function () { + const tx = await contract.unpause() + await tx.wait() + const tx2 = await contract.unpause() + + expect(tx2.wait()).to.eventually.be.rejected.and.have.property('code', CALL_EXCEPTION) + }) + +})