Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make some devx improvements #150

Merged
merged 1 commit into from
Oct 25, 2024
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
43 changes: 12 additions & 31 deletions src/test/ModuleKitHelpers.sol
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ library ModuleKitHelpers {
)
internal
withAccountDeployed(instance)
returns (PermissionId[] memory permissionIds)
returns (PermissionId permissionIds)
{
// Check if smart sessions module is already installed
if (!instance.isModuleInstalled(1, address(instance.smartSession))) {
Expand All @@ -618,7 +618,7 @@ library ModuleKitHelpers {
Session[] memory sessions = new Session[](1);
sessions[0] = session;
prank(instance.account);
permissionIds = instance.smartSession.enableSessions(sessions);
permissionIds = instance.smartSession.enableSessions(sessions)[0];
}

/// @dev Adds a session to the account with the default validator
Expand All @@ -631,7 +631,7 @@ library ModuleKitHelpers {
)
internal
withAccountDeployed(instance)
returns (PermissionId[] memory permissionIds)
returns (PermissionId permissionIds)
{
// Check if smart sessions module is already installed
if (!instance.isModuleInstalled(1, address(instance.smartSession))) {
Expand Down Expand Up @@ -718,39 +718,22 @@ library ModuleKitHelpers {
}

/// @dev Encodes a signature for a user operation using the correct format
/// @param instance AccountInstance
/// @param userOperation PackedUserOperation
/// @param context bytes, a bytes array with the following format:
/// [0-24] : nonce key
/// [24-56] : execution mode
/// [56-88] : permissionId
/// [88]: abi.encode(EnableSession)
function encodeSignature(
AccountInstance memory instance,
PackedUserOperation memory userOperation,
bytes calldata context
SmartSessionMode mode,
Session memory session
)
internal
returns (bytes memory)
{
// Parse context
PermissionId permissionId = abi.decode(context[:32], (PermissionId));
EnableSession memory enableData = abi.decode(context[88:], (EnableSession));
Session memory session = enableData.sessionToEnable;

// Encode based on length
if (context.length < 88) {
revert InvalidContextLength();
} else if (context.length == 88) {
// Encode signature
// Get permission id
PermissionId permissionId = getPermissionId(instance, session);
// Encode based on mode
if (mode == SmartSessionMode.USE) {
return EncodeLib.encodeUse(permissionId, userOperation.signature);
} else {
// Use encodeUse or encodeUnsafeEnable if policies are enabled
if (!instance.isSessionEnabled(session)) {
return EncodeLib.encodeUse(permissionId, userOperation.signature);
} else {
return EncodeLib.encodeUnsafeEnable(userOperation.signature, enableData);
}
revert("Missing signFunction and validator params");
}
}

Expand All @@ -773,8 +756,7 @@ library ModuleKitHelpers {
return EncodeLib.encodeUse(permissionId, userOperation.signature);
} else {
// Create enable session data
EnableSession memory enableData =
makeMultiChainEnableData(instance, permissionId, session, mode);
EnableSession memory enableData = makeMultiChainEnableData(instance, session, mode);
// Get the hash
bytes32 hash = HashLib.multichainDigest(enableData.hashesAndChainIds);
// Sign the enable hash
Expand Down Expand Up @@ -929,14 +911,13 @@ library ModuleKitHelpers {

function makeMultiChainEnableData(
AccountInstance memory instance,
PermissionId permissionId,
Session memory session,
SmartSessionMode mode
)
internal
view
returns (EnableSession memory enableData)
{
PermissionId permissionId = instance.getPermissionId(session);
bytes32 sessionDigest = instance.smartSession.getSessionDigest({
permissionId: permissionId,
account: instance.account,
Expand Down
20 changes: 10 additions & 10 deletions test/integrations/SmartSession.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ contract SmartSessionTest is BaseTest {

function test_addSession() public {
// Add a session
PermissionId[] memory permissionIds = instance.addSession({
PermissionId permissionIds = instance.addSession({
salt: bytes32("salt1"),
userOpPolicies: _getEmptyPolicyDatas(address(mockPolicy)),
erc7739Policy: _getEmptyERC7739Data(
Expand All @@ -102,7 +102,7 @@ contract SmartSessionTest is BaseTest {
)
});
// Check if the session is enabled
assertTrue(instance.isPermissionEnabled(permissionIds[0]));
assertTrue(instance.isPermissionEnabled(permissionIds));
}

function test_addSession_preInstalled() public {
Expand All @@ -113,7 +113,7 @@ contract SmartSessionTest is BaseTest {
data: ""
});
// Add a session
PermissionId[] memory permissionIds = instance.addSession({
PermissionId permissionIds = instance.addSession({
salt: bytes32("salt1"),
userOpPolicies: _getEmptyPolicyDatas(address(mockPolicy)),
erc7739Policy: _getEmptyERC7739Data(
Expand All @@ -124,12 +124,12 @@ contract SmartSessionTest is BaseTest {
)
});
// Check if the session is enabled
assertTrue(instance.isPermissionEnabled(permissionIds[0]));
assertTrue(instance.isPermissionEnabled(permissionIds));
}

function test_removeSession() public {
// Add a session
PermissionId[] memory permissionIds = instance.addSession({
PermissionId permissionIds = instance.addSession({
salt: bytes32("salt1"),
userOpPolicies: _getEmptyPolicyDatas(address(mockPolicy)),
erc7739Policy: _getEmptyERC7739Data(
Expand All @@ -140,11 +140,11 @@ contract SmartSessionTest is BaseTest {
)
});
// Check if the session is enabled
assertTrue(instance.isPermissionEnabled(permissionIds[0]));
assertTrue(instance.isPermissionEnabled(permissionIds));
// Remove the session
instance.removeSession(permissionIds[0]);
instance.removeSession(permissionIds);
// Check if the session is disabled
assertFalse(instance.isPermissionEnabled(permissionIds[0]));
assertFalse(instance.isPermissionEnabled(permissionIds));
}

function test_getPermissionId() public {
Expand All @@ -161,12 +161,12 @@ contract SmartSessionTest is BaseTest {
});

// Add a session
PermissionId[] memory permissionIds = instance.addSession({ session: session });
PermissionId permissionIds = instance.addSession({ session: session });
// Get the permission id
PermissionId permissionId = instance.getPermissionId(session);

// Check if the permission id is correct
assertTrue(permissionIds[0] == permissionId);
assertTrue(permissionIds == permissionId);
}

function test_useSession() public {
Expand Down
Loading