Skip to content

Commit

Permalink
✅ Improve testing
Browse files Browse the repository at this point in the history
  • Loading branch information
JaredBorders committed Oct 23, 2023
1 parent 8a1a726 commit d5452a3
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 1 deletion.
17 changes: 16 additions & 1 deletion test/unit/Account.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ import {
sETHPERP,
SYSTEM_STATUS,
UNISWAP_PERMIT2,
UNISWAP_UNIVERSAL_ROUTER
UNISWAP_UNIVERSAL_ROUTER,
USER
} from "test/utils/Constants.sol";

contract AccountTest is Test, ConsolidatedEvents {
Expand Down Expand Up @@ -253,6 +254,20 @@ contract AccountTest is Test, ConsolidatedEvents {
account.transferOwnership(KWENTA_TREASURY);
}

function test_Ownership_Transfer_Twice() public {
// ensure factory and account state align
address originalOwner = factory.getAccountOwner(address(account));

account.transferOwnership(KWENTA_TREASURY);
vm.prank(KWENTA_TREASURY);
account.transferOwnership(USER);

address newOwner = factory.getAccountOwner(address(account));
assert(newOwner == USER && newOwner == account.owner());
assert(factory.getAccountsOwnedBy(USER)[0] == address(account));
assert(factory.getAccountsOwnedBy(originalOwner).length == 0);
}

function test_Ownership_setInitialOwnership_OnlyFactory() public {
vm.expectRevert(abi.encodeWithSelector(Auth.Unauthorized.selector));
account.setInitialOwnership(KWENTA_TREASURY);
Expand Down
55 changes: 55 additions & 0 deletions test/unit/Events.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {Test} from "lib/forge-std/src/Test.sol";
import {Setup} from "script/Deploy.s.sol";

import {Account} from "src/Account.sol";
import {Auth} from "src/utils/Auth.sol";
import {Events} from "src/Events.sol";
import {Factory} from "src/Factory.sol";
import {IAccount} from "src/interfaces/IAccount.sol";
Expand Down Expand Up @@ -249,4 +250,58 @@ contract EventsTest is Test, ConsolidatedEvents {
amountOutMinimum: 2
});
}

function test_EmitOwnershipTransferred_Event() public {
vm.expectEmit(true, true, true, true);
emit OwnershipTransferred(address(0xA), address(0xB));
vm.prank(account);
events.emitOwnershipTransferred({
caller: address(0xA),
newOwner: address(0xB)
});
}

function test_EmitOwnershipTransferred_OnlyAccounts() public {
vm.expectRevert(abi.encodeWithSelector(IEvents.OnlyAccounts.selector));
events.emitOwnershipTransferred({
caller: address(0xA),
newOwner: address(0xB)
});
}

function test_EmitDelegatedAccountAdded_Event() public {
vm.expectEmit(true, true, true, true);
emit DelegatedAccountAdded(address(0xA), address(0xB));
vm.prank(account);
events.emitDelegatedAccountAdded({
caller: address(0xA),
delegate: address(0xB)
});
}

function test_EmitDelegatedAccountAdded_OnlyAccounts() public {
vm.expectRevert(abi.encodeWithSelector(IEvents.OnlyAccounts.selector));
events.emitDelegatedAccountAdded({
caller: address(0xA),
delegate: address(0xB)
});
}

function test_EmitDelegatedAccountRemoved_Event() public {
vm.expectEmit(true, true, true, true);
emit DelegatedAccountRemoved(address(0xA), address(0xB));
vm.prank(account);
events.emitDelegatedAccountRemoved({
caller: address(0xA),
delegate: address(0xB)
});
}

function test_EmitDelegatedAccountRemoved_OnlyAccounts() public {
vm.expectRevert(abi.encodeWithSelector(IEvents.OnlyAccounts.selector));
events.emitDelegatedAccountRemoved({
caller: address(0xA),
delegate: address(0xB)
});
}
}

0 comments on commit d5452a3

Please sign in to comment.