Skip to content

Commit

Permalink
add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kingster-will committed May 24, 2024
1 parent 70bc331 commit bd88431
Showing 1 changed file with 34 additions and 25 deletions.
59 changes: 34 additions & 25 deletions test/foundry/IPAccount.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -126,40 +126,20 @@ contract IPAccountTest is BaseTest {

IIPAccount ipAccount = IIPAccount(payable(account));

// test isValidSigner with non-owner and empty data
vm.expectRevert(
abi.encodeWithSelector(
Errors.AccessController__PermissionDenied.selector,
address(ipAccount),
address(module),
address(0),
bytes4(0)
)
);
ipAccount.isValidSigner(address(module), "");

// test isValidSigner with owner and empty data
assertEq(ipAccount.isValidSigner(owner, ""), IERC6551Account.isValidSigner.selector);

// test isValidSigner with owner and encoded "to" address and "calldata" as data
bytes memory data = abi.encode(address(module), abi.encodeWithSignature("executeSuccessfully(string)", "test"));
assertEq(ipAccount.isValidSigner(owner, data), IERC6551Account.isValidSigner.selector);

// test isValidSigner with non-owner and encoded "to" address and "calldata" as data
address nonOwner = vm.addr(2);
vm.prank(nonOwner);
vm.expectRevert(
abi.encodeWithSelector(
Errors.AccessController__PermissionDenied.selector,
address(ipAccount),
nonOwner,
address(module),
module.executeSuccessfully.selector
)
assertEq(
ipAccount.isValidSigner(owner, abi.encode(address(module), "")),
IERC6551Account.isValidSigner.selector
);
ipAccount.isValidSigner(nonOwner, data);

// Transfer token to new owner and make sure account owner changes
address nonOwner = vm.addr(2);
vm.prank(owner);
mockNFT.transferFrom(owner, nonOwner, tokenId);
assertEq(ipAccount.isValidSigner(nonOwner, data), IERC6551Account.isValidSigner.selector);
Expand All @@ -175,7 +155,6 @@ contract IPAccountTest is BaseTest {

IIPAccount ipAccount = IIPAccount(payable(account));

// test isValidSigner with owner and empty data
vm.expectRevert(Errors.IPAccount__InvalidCalldata.selector);
ipAccount.isValidSigner(address(module), bytes("123"));

Expand All @@ -187,6 +166,36 @@ contract IPAccountTest is BaseTest {

vm.expectRevert();
ipAccount.isValidSigner(address(module), abi.encodeWithSignature("executeSuccessfully(string)", "test"));

vm.expectRevert(Errors.IPAccount__InvalidCalldata.selector);
ipAccount.isValidSigner(owner, abi.encode(address(module), bytes("123")));

// test isValidSigner with non-owner and empty data
vm.expectRevert(
abi.encodeWithSelector(
Errors.AccessController__PermissionDenied.selector,
address(ipAccount),
address(module),
address(0),
bytes4(0)
)
);
ipAccount.isValidSigner(address(module), "");

// test isValidSigner with non-owner and encoded "to" address and "calldata" as data
bytes memory data = abi.encode(address(module), abi.encodeWithSignature("executeSuccessfully(string)", "test"));
address nonOwner = vm.addr(2);
vm.prank(nonOwner);
vm.expectRevert(
abi.encodeWithSelector(
Errors.AccessController__PermissionDenied.selector,
address(ipAccount),
nonOwner,
address(module),
module.executeSuccessfully.selector
)
);
ipAccount.isValidSigner(nonOwner, data);
}

function test_IPAccount_revert_NonOwnerNoPermissionToExecute() public {
Expand Down

0 comments on commit bd88431

Please sign in to comment.