Skip to content

Commit

Permalink
feat: add smart sessions safe test
Browse files Browse the repository at this point in the history
  • Loading branch information
kopy-kat committed Oct 11, 2024
1 parent 575cc32 commit 6aedf16
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 11 deletions.
6 changes: 4 additions & 2 deletions test/e2e/infra/sendUserOp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ export const sendUserOp = async ({
entryPoint: ENTRYPOINT_ADDRESS_V07,
})

return signUserOpHash(hash)
return await signUserOpHash(hash)
}
}

if (getDummySignature) {
smartClient.account.getDummySignature = async (): Promise<Hex> => {
return getDummySignature()
return await getDummySignature()
}
}

Expand All @@ -52,5 +52,7 @@ export const sendUserOp = async ({
nonce,
})

await publicClient.waitForTransactionReceipt({ hash })

return hash
}
36 changes: 30 additions & 6 deletions test/e2e/modules/smartSessionsValidator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Account, isModuleInstalled } from 'src/account'
import { Account, isModuleInstalled, encode1271Hash } from 'src/account'
import {
getModule,
getOwnableValidatorMockSignature,
Expand Down Expand Up @@ -28,6 +28,9 @@ import {
TestClient,
toBytes,
toHex,
fromHex,
slice,
concat,
zeroAddress,
} from 'viem'
import { hashTypedData } from 'viem/experimental/solady'
Expand Down Expand Up @@ -124,6 +127,11 @@ export const testSmartSessionsValidator = async ({
}, 30000)

it('should validate userOp using smart session using ENABLE flow', async () => {

it('should validate userOp using smart session using ENABLE flow for safe', async () => {
if (account.type !== 'safe') {
return
}
const signer = privateKeyToAccount(process.env.PRIVATE_KEY as Hex)

const { smartSessions } = getInstallModuleData({ account })
Expand Down Expand Up @@ -173,10 +181,26 @@ export const testSmartSessionsValidator = async ({

const permissionEnableHash = hashChainSessions(chainSessions)

const formattedHash = encode1271Hash({
account,
chainId: sepolia.id,
validator: account.address,
hash: permissionEnableHash,
})

const permissionEnableSig = await signer.signMessage({
message: { raw: permissionEnableHash },
message: { raw: formattedHash },
})

let formattedSignature: Hex
const v = fromHex(slice(permissionEnableSig, 64, 65), 'number')
if (v < 30) {
formattedSignature = concat([
slice(permissionEnableSig, 0, 64),
toHex(v + 4),
])
}

const receipt = await sendUserOp({
account,
actions: [
Expand All @@ -201,9 +225,9 @@ export const testSmartSessionsValidator = async ({
chainDigestIndex: 0,
hashesAndChainIds: chainDigests,
sessionToEnable: session,
permissionEnableSig,
permissionEnableSig: formattedSignature,
},
validator: OWNABLE_VALIDATOR_ADDRESS,
validator: account.address,
accountType: account.type,
},
})
Expand All @@ -220,9 +244,9 @@ export const testSmartSessionsValidator = async ({
chainDigestIndex: 0,
hashesAndChainIds: chainDigests,
sessionToEnable: session,
permissionEnableSig,
permissionEnableSig: formattedSignature,
},
validator: OWNABLE_VALIDATOR_ADDRESS,
validator: account.address,
accountType: account.type,
},
})
Expand Down
6 changes: 3 additions & 3 deletions test/utils/userOps/smartClients.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,13 @@ const getERC7579Client = async (account: Account) => {
export const getSmartClient = async (account: Account) => {
switch (account.type) {
case 'safe':
return getSafeClient(account)
return await getSafeClient(account)
case 'kernel':
return getKernelClient(account)
return await getKernelClient(account)
case 'erc7579-implementation':
return getERC7579Client(account)
case 'nexus':
return getNexusClient(account)
return await getNexusClient(account)
default:
throw new Error(`Unknown account type: ${account.type}`)
}
Expand Down

0 comments on commit 6aedf16

Please sign in to comment.