Skip to content

Commit

Permalink
fix: change some tests (#46)
Browse files Browse the repository at this point in the history
* fix: change some tests

* fix: ups

* fix: improve tests
  • Loading branch information
sakulstra authored Nov 13, 2024
1 parent 5b2239a commit a1eb1d8
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 20 deletions.
44 changes: 34 additions & 10 deletions test/OwnableWithGuardian.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,53 @@ pragma solidity ^0.8.0;
import 'forge-std/Test.sol';
import {OwnableWithGuardian} from '../src/contracts/access-control/OwnableWithGuardian.sol';

contract ImplOwnableWithGuardian is OwnableWithGuardian {}
contract ImplOwnableWithGuardian is OwnableWithGuardian {
function mock_onlyGuardian() external onlyGuardian {}

function mock_onlyOwnerOrGuardian() external onlyOwnerOrGuardian {}
}

contract TestOfOwnableWithGuardian is Test {
OwnableWithGuardian public withGuardian;
ImplOwnableWithGuardian public withGuardian;

address owner = makeAddr('owner');
address guardian = makeAddr('guardian');

function setUp() public {
withGuardian = new ImplOwnableWithGuardian();
}

function testConstructorLogic() external {
assertEq(withGuardian.owner(), address(this));
assertEq(withGuardian.guardian(), address(this));
withGuardian.transferOwnership(owner);
withGuardian.updateGuardian(guardian);
}

function testGuardianUpdate(address guardian) external {
withGuardian.updateGuardian(guardian);
function testConstructorLogic() external view {
assertEq(withGuardian.owner(), owner);
assertEq(withGuardian.guardian(), guardian);
}

function testGuardianUpdateViaGuardian(address newGuardian) external {
vm.startPrank(guardian);
withGuardian.updateGuardian(newGuardian);
}

function testGuardianUpdateNoAccess(address guardian) external {
vm.assume(guardian != address(this));
function testGuardianUpdateViaOwner(address newGuardian) external {
vm.prank(owner);
withGuardian.updateGuardian(newGuardian);
}

vm.prank(guardian);
function testGuardianUpdateNoAccess() external {
vm.expectRevert('ONLY_BY_OWNER_OR_GUARDIAN');
withGuardian.updateGuardian(guardian);
}

function test_onlyGuardianGuard() external {
vm.prank(guardian);
withGuardian.mock_onlyGuardian();
}

function test_onlyGuardianGuard_shouldRevert() external {
vm.expectRevert('ONLY_BY_GUARDIAN');
withGuardian.mock_onlyGuardian();
}
}
File renamed without changes.
15 changes: 5 additions & 10 deletions test/create3Test.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,7 @@ contract Create3FactoryTest is Test {
factory = new Create3Factory{salt: CREATE3_FACTORY_SALT}();
}

function testCreate3WithoutValue(
address someAddress,
address owner,
bytes32 salt
) public {
function testCreate3WithoutValue(address someAddress, address owner, bytes32 salt) public {
bytes memory encodedParams = abi.encode(someAddress, owner);
bytes memory code = type(MockContract).creationCode;
// deploy Voting portal
Expand All @@ -52,13 +48,12 @@ contract Create3FactoryTest is Test {
);
assertEq(MockContract(votingPortal).owner(), owner);
assertEq(MockContract(votingPortal).SOME_ADDRESS(), someAddress);

vm.expectRevert(abi.encodeWithSelector(Create3.TargetAlreadyExists.selector));
factory.create(salt, abi.encodePacked(code, encodedParams));
}

function testCreate3WithValue(
address someAddress,
address owner,
address creator
) public {
function testCreate3WithValue(address someAddress, address owner, address creator) public {
bytes memory encodedParams = abi.encode(someAddress, owner);
bytes memory code = type(MockContract).creationCode;
bytes32 salt = keccak256(bytes('Voting portal eth-avax-2'));
Expand Down

0 comments on commit a1eb1d8

Please sign in to comment.