Skip to content
Merged
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
41 changes: 4 additions & 37 deletions test/access/Owner/LibOwner.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,13 @@ contract LibOwnerTest is Test {
// Fuzz Tests
// ============================================

function test_Fuzz_TransferOwnership(address newOwner) public {
function testFuzz_TransferOwnership(address newOwner) public {
vm.prank(INITIAL_OWNER);
harness.transferOwnership(newOwner);
assertEq(harness.owner(), newOwner);
}

function test_Fuzz_MultipleTransfers(address owner1, address owner2, address owner3) public {
function testFuzz_MultipleTransfers(address owner1, address owner2, address owner3) public {
vm.assume(owner1 != address(0));
vm.assume(owner2 != address(0));

Expand All @@ -206,7 +206,7 @@ contract LibOwnerTest is Test {
assertEq(harness.owner(), owner3);
}

function test_Fuzz_RevertWhen_RenouncedOwnerTransfers(address target) public {
function testFuzz_RevertWhen_RenouncedOwnerTransfers(address target) public {
vm.assume(target != address(0));

// Renounce
Expand Down Expand Up @@ -252,7 +252,7 @@ contract LibOwnerTest is Test {
harness.requireOwner();
}

function test_Fuzz_RequireOwner(address caller) public {
function testFuzz_RequireOwner(address caller) public {
if (caller == INITIAL_OWNER) {
// Should not revert for owner
vm.prank(caller);
Expand All @@ -264,37 +264,4 @@ contract LibOwnerTest is Test {
harness.requireOwner();
}
}

// ============================================
// Gas Tests
// ============================================

function test_Gas_Owner() public view {
uint256 gasBefore = gasleft();
harness.owner();
uint256 gasUsed = gasBefore - gasleft();

console2.log("Gas used for LibOwner.owner():", gasUsed);
assertTrue(gasUsed < 10000, "Owner getter uses too much gas");
}

function test_Gas_TransferOwnership() public {
uint256 gasBefore = gasleft();
vm.prank(INITIAL_OWNER);
harness.transferOwnership(NEW_OWNER);
uint256 gasUsed = gasBefore - gasleft();

console2.log("Gas used for LibOwner.transferOwnership():", gasUsed);
assertTrue(gasUsed < 50000, "Transfer ownership uses too much gas");
}

function test_Gas_TransferOwnership_Renounce() public {
uint256 gasBefore = gasleft();
vm.prank(INITIAL_OWNER);
harness.transferOwnership(ZERO_ADDRESS);
uint256 gasUsed = gasBefore - gasleft();

console2.log("Gas used for LibOwner renounce:", gasUsed);
assertTrue(gasUsed < 50000, "Renounce uses too much gas");
}
}
32 changes: 4 additions & 28 deletions test/access/Owner/OwnerFacet.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,14 @@ contract OwnerFacetTest is Test {
// Fuzz Tests
// ============================================

function test_Fuzz_TransferOwnership(address newOwner) public {
function testFuzz_TransferOwnership(address newOwner) public {
vm.prank(INITIAL_OWNER);
ownerFacet.transferOwnership(newOwner);

assertEq(ownerFacet.owner(), newOwner);
}

function test_Fuzz_SequentialTransfers(address owner1, address owner2, address owner3) public {
function testFuzz_SequentialTransfers(address owner1, address owner2, address owner3) public {
vm.assume(owner1 != address(0));
vm.assume(owner2 != address(0));
vm.assume(owner3 != address(0));
Expand All @@ -190,15 +190,15 @@ contract OwnerFacetTest is Test {
assertEq(ownerFacet.owner(), owner3);
}

function test_Fuzz_RevertWhen_UnauthorizedCaller(address caller, address target) public {
function testFuzz_RevertWhen_UnauthorizedCaller(address caller, address target) public {
vm.assume(caller != INITIAL_OWNER);

vm.prank(caller);
vm.expectRevert(OwnerFacet.OwnerUnauthorizedAccount.selector);
ownerFacet.transferOwnership(target);
}

function test_Fuzz_RenouncePreventsAllTransfers(address caller, address target) public {
function testFuzz_RenouncePreventsAllTransfers(address caller, address target) public {
vm.assume(caller != address(0));

// Renounce ownership
Expand All @@ -212,28 +212,4 @@ contract OwnerFacetTest is Test {
}

// ============================================
// Gas Tests
// ============================================

function test_Gas_TransferOwnership() public {
uint256 gasBefore = gasleft();
vm.prank(INITIAL_OWNER);
ownerFacet.transferOwnership(NEW_OWNER);
uint256 gasUsed = gasBefore - gasleft();

// Log gas usage for optimization tracking
console2.log("Gas used for transferOwnership:", gasUsed);
// Should be relatively low since it's just storage updates
assertTrue(gasUsed < 50000, "Transfer ownership uses too much gas");
}

function test_Gas_OwnerGetter() public view {
uint256 gasBefore = gasleft();
ownerFacet.owner();
uint256 gasUsed = gasBefore - gasleft();

console2.log("Gas used for owner():", gasUsed);
// Should be very low since it's just a storage read
assertTrue(gasUsed < 10000, "Owner getter uses too much gas");
}
}
55 changes: 5 additions & 50 deletions test/access/OwnerTwoSteps/LibOwnerTwoSteps.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -364,15 +364,15 @@ contract LibOwnerTwoStepsTest is Test {
// Fuzz Tests
// ============================================

function test_Fuzz_TransferOwnership(address newOwner) public {
function testFuzz_TransferOwnership(address newOwner) public {
vm.prank(INITIAL_OWNER);
harness.transferOwnership(newOwner);

assertEq(harness.owner(), INITIAL_OWNER);
assertEq(harness.pendingOwner(), newOwner);
}

function test_Fuzz_AcceptOwnership(address newOwner) public {
function testFuzz_AcceptOwnership(address newOwner) public {
vm.assume(newOwner != address(0));

vm.prank(INITIAL_OWNER);
Expand All @@ -385,7 +385,7 @@ contract LibOwnerTwoStepsTest is Test {
assertEq(harness.pendingOwner(), ZERO_ADDRESS);
}

function test_Fuzz_TransferOwnership_AnyCaller(address caller, address target) public {
function testFuzz_TransferOwnership_AnyCaller(address caller, address target) public {
// Library allows any caller
vm.prank(caller);
harness.transferOwnership(target);
Expand All @@ -395,7 +395,7 @@ contract LibOwnerTwoStepsTest is Test {
assertEq(harness.owner(), INITIAL_OWNER); // Owner unchanged until acceptance
}

function test_Fuzz_AcceptOwnership_AnyCaller(address caller) public {
function testFuzz_AcceptOwnership_AnyCaller(address caller) public {
vm.prank(INITIAL_OWNER);
harness.transferOwnership(NEW_OWNER);

Expand All @@ -408,7 +408,7 @@ contract LibOwnerTwoStepsTest is Test {
assertEq(harness.pendingOwner(), ZERO_ADDRESS);
}

function test_Fuzz_SequentialTransfers(address owner1, address owner2, address owner3) public {
function testFuzz_SequentialTransfers(address owner1, address owner2, address owner3) public {
vm.assume(owner1 != address(0));
vm.assume(owner2 != address(0));
vm.assume(owner3 != address(0));
Expand All @@ -434,49 +434,4 @@ contract LibOwnerTwoStepsTest is Test {
harness.acceptOwnership();
assertEq(harness.owner(), owner3);
}

// ============================================
// Gas Tests
// ============================================

function test_Gas_TransferOwnership() public {
uint256 gasBefore = gasleft();
vm.prank(INITIAL_OWNER);
harness.transferOwnership(NEW_OWNER);
uint256 gasUsed = gasBefore - gasleft();

console2.log("Gas used for LibOwnerTwoSteps.transferOwnership():", gasUsed);
assertTrue(gasUsed < 70000, "Transfer ownership uses too much gas");
}

function test_Gas_AcceptOwnership() public {
vm.prank(INITIAL_OWNER);
harness.transferOwnership(NEW_OWNER);

uint256 gasBefore = gasleft();
vm.prank(NEW_OWNER);
harness.acceptOwnership();
uint256 gasUsed = gasBefore - gasleft();

console2.log("Gas used for LibOwnerTwoSteps.acceptOwnership():", gasUsed);
assertTrue(gasUsed < 35000, "Accept ownership uses too much gas");
}

function test_Gas_OwnerGetter() public view {
uint256 gasBefore = gasleft();
harness.owner();
uint256 gasUsed = gasBefore - gasleft();

console2.log("Gas used for LibOwnerTwoSteps.owner():", gasUsed);
assertTrue(gasUsed < 10000, "Owner getter uses too much gas");
}

function test_Gas_PendingOwnerGetter() public view {
uint256 gasBefore = gasleft();
harness.pendingOwner();
uint256 gasUsed = gasBefore - gasleft();

console2.log("Gas used for LibOwnerTwoSteps.pendingOwner():", gasUsed);
assertTrue(gasUsed < 10000, "Pending owner getter uses too much gas");
}
}
69 changes: 7 additions & 62 deletions test/access/OwnerTwoSteps/OwnerTwoSteps.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -254,15 +254,15 @@ contract OwnerTwoStepsFacetTest is Test {
// Fuzz Tests
// ============================================

function test_Fuzz_TransferOwnership(address newOwner) public {
function testFuzz_TransferOwnership(address newOwner) public {
vm.prank(INITIAL_OWNER);
ownerTwoSteps.transferOwnership(newOwner);

assertEq(ownerTwoSteps.owner(), INITIAL_OWNER);
assertEq(ownerTwoSteps.pendingOwner(), newOwner);
}

function test_Fuzz_AcceptOwnership(address newOwner) public {
function testFuzz_AcceptOwnership(address newOwner) public {
vm.assume(newOwner != address(0)); // Zero address can't execute transactions

vm.prank(INITIAL_OWNER);
Expand All @@ -275,15 +275,15 @@ contract OwnerTwoStepsFacetTest is Test {
assertEq(ownerTwoSteps.pendingOwner(), ZERO_ADDRESS);
}

function test_Fuzz_RevertWhen_UnauthorizedTransfer(address caller, address target) public {
function testFuzz_RevertWhen_UnauthorizedTransfer(address caller, address target) public {
vm.assume(caller != INITIAL_OWNER);

vm.prank(caller);
vm.expectRevert(OwnerTwoStepsFacet.OwnerUnauthorizedAccount.selector);
ownerTwoSteps.transferOwnership(target);
}

function test_Fuzz_RevertWhen_UnauthorizedAccept(address caller) public {
function testFuzz_RevertWhen_UnauthorizedAccept(address caller) public {
vm.assume(caller != NEW_OWNER);

vm.prank(INITIAL_OWNER);
Expand Down Expand Up @@ -471,66 +471,11 @@ contract OwnerTwoStepsFacetTest is Test {
assertEq(ownerTwoSteps.pendingOwner(), ZERO_ADDRESS);
}

// ============================================
// Gas Benchmarks
// ============================================

function test_Gas_Owner() public view {
uint256 gasBefore = gasleft();
ownerTwoSteps.owner();
uint256 gasUsed = gasBefore - gasleft();

console2.log("Gas used for owner():", gasUsed);
assertTrue(gasUsed < 10000, "Owner getter uses too much gas");
}

function test_Gas_PendingOwner() public view {
uint256 gasBefore = gasleft();
ownerTwoSteps.pendingOwner();
uint256 gasUsed = gasBefore - gasleft();

console2.log("Gas used for pendingOwner():", gasUsed);
assertTrue(gasUsed < 10000, "Pending owner getter uses too much gas");
}

function test_Gas_TransferOwnership() public {
uint256 gasBefore = gasleft();
vm.prank(INITIAL_OWNER);
ownerTwoSteps.transferOwnership(NEW_OWNER);
uint256 gasUsed = gasBefore - gasleft();

console2.log("Gas used for transferOwnership():", gasUsed);
assertTrue(gasUsed < 50000, "Transfer ownership uses too much gas");
}

function test_Gas_AcceptOwnership() public {
vm.prank(INITIAL_OWNER);
ownerTwoSteps.transferOwnership(NEW_OWNER);

uint256 gasBefore = gasleft();
vm.prank(NEW_OWNER);
ownerTwoSteps.acceptOwnership();
uint256 gasUsed = gasBefore - gasleft();

console2.log("Gas used for acceptOwnership():", gasUsed);
assertTrue(gasUsed < 35000, "Accept ownership uses too much gas");
}

function test_Gas_RenounceOwnership() public {
uint256 gasBefore = gasleft();
vm.prank(INITIAL_OWNER);
ownerTwoSteps.renounceOwnership();
uint256 gasUsed = gasBefore - gasleft();

console2.log("Gas used for renounceOwnership():", gasUsed);
assertTrue(gasUsed < 30000, "Renounce ownership uses too much gas");
}

// ============================================
// Additional Fuzz Tests
// ============================================

function test_Fuzz_RenounceOwnership_OnlyOwner(address caller) public {
function testFuzz_RenounceOwnership_OnlyOwner(address caller) public {
if (caller == INITIAL_OWNER) {
vm.prank(caller);
ownerTwoSteps.renounceOwnership();
Expand All @@ -543,7 +488,7 @@ contract OwnerTwoStepsFacetTest is Test {
}
}

function test_Fuzz_StateAfterRenounce(address caller, address target) public {
function testFuzz_StateAfterRenounce(address caller, address target) public {
// Renounce ownership
vm.prank(INITIAL_OWNER);
ownerTwoSteps.renounceOwnership();
Expand All @@ -567,7 +512,7 @@ contract OwnerTwoStepsFacetTest is Test {
}
}

function test_Fuzz_RenounceWithPendingOwner(address pendingOwner) public {
function testFuzz_RenounceWithPendingOwner(address pendingOwner) public {
vm.assume(pendingOwner != address(0));

// Set pending owner
Expand Down
Loading