-
-
Save coffiasd/84552b5a33845fa567bfc3aa5204d460 to your computer and use it in GitHub Desktop.
how to master openzeppelin access control
This file contains 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
pragma solidity ^0.8.13; | |
import "forge-std/Test.sol"; | |
import {MyContract} from "../src/Access.sol"; | |
contract AccessTest is Test { | |
MyContract public myContract; | |
address owner = address(0x100); | |
address arbitrary = address(0x101); | |
function setUp() public { | |
//let's set address owner to msg.sender. | |
vm.prank(owner); | |
//create the contract. | |
myContract = new MyContract(); | |
} | |
function testAccessControl() public { | |
//check the .owner() eq owner. | |
assert(owner == myContract.owner()); | |
//use arbitrary address invoke specialThing() function. | |
vm.prank(arbitrary); | |
vm.expectRevert("Ownable: caller is not the owner"); | |
myContract.specialThing(); | |
//switch to owner. | |
vm.prank(owner); | |
myContract.specialThing(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment