Skip to content

Commit

Permalink
Merge pull request #108 from rhinestonewtf/fix/smart-sessions-tests
Browse files Browse the repository at this point in the history
fix(smartsessions): fix smart sessions test
  • Loading branch information
kopy-kat authored Dec 26, 2024
2 parents 29fda02 + 5db9a33 commit 8aa338e
Show file tree
Hide file tree
Showing 13 changed files with 404 additions and 180 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"tsc-alias": "^1.8.10",
"typescript": "^5.3.3",
"utf-8-validate": "^6.0.3",
"viem": "^2.4.1",
"viem": "^2.16.3",
"ws": "^8.16.0"
},
"dependencies": {
Expand Down
3 changes: 2 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/account/nexus/constants/abis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const bootstrapAbi = [

export const accountAbi = [
'function getActiveHook() external view returns (address hook)',
'function getValidatorPaginated(address cursor,uint256 size) returns (address[] memory, address)',
'function getValidatorsPaginated(address cursor,uint256 size) returns (address[] memory, address)',
'function getExecutorsPaginated(address cursor,uint256 size) returns (address[] memory, address)',
'function installModule(uint256 moduleTypeId,address module,bytes calldata initData)',
'function uninstallModule(uint256 moduleTypeId,address module,bytes calldata deInitData)',
Expand Down
2 changes: 2 additions & 0 deletions src/module/smart-sessions/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ import { Address } from 'viem'

export const SMART_SESSIONS_ADDRESS: Address =
'0x00000000002B0eCfbD0496EE71e01257dA0E37DE'
export const SMART_SESSIONS_COMPATIBILITY_FALLBACK_ADDRESS: Address =
'0xBad7E91C4F2803978cd6c7C3Fe80B5Fd7f7B0b50'
19 changes: 18 additions & 1 deletion src/module/smart-sessions/installation.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { Address, encodeAbiParameters, encodePacked } from 'viem'
import { Module } from '../types'
import { SMART_SESSIONS_ADDRESS } from './constants'
import {
SMART_SESSIONS_ADDRESS,
SMART_SESSIONS_COMPATIBILITY_FALLBACK_ADDRESS,
} from './constants'
import { Session } from './types'
import { installSmartSessionsAbi } from './abi'
import { SmartSessionMode } from './types'
import { CallType } from '../../module/types'

type Params = {
sessions?: Session[]
Expand Down Expand Up @@ -36,3 +40,16 @@ export const getSmartSessionsValidator = ({
hook,
}
}

export const getSmartSessionsCompatibilityFallback = (): Module => {
return {
address: SMART_SESSIONS_COMPATIBILITY_FALLBACK_ADDRESS,
module: SMART_SESSIONS_COMPATIBILITY_FALLBACK_ADDRESS,
initData: '0x',
deInitData: '0x',
selector: '0x84b0196e',
callType: CallType.CALLTYPE_SINGLE,
additionalContext: '0x',
type: 'fallback',
}
}
93 changes: 92 additions & 1 deletion src/module/smart-sessions/usage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,96 @@ export const getSessionNonce = async ({
})) as bigint
}

export const getVerifySignatureResult = async ({
client,
account,
sender,
hash,
signature,
}: {
client: PublicClient
account: Account
sender: Address
hash: Hex
signature: Hex
}) => {
let calldata = encodeFunctionData({
abi,
functionName: 'isValidSignatureWithSender',
args: [sender, hash, signature],
})
const { data } = await client.call({
account: account.address,
to: SMART_SESSIONS_ADDRESS,
data: calldata,
})

return (
data ===
'0x1626ba7e00000000000000000000000000000000000000000000000000000000'
)
}

export const getAccountEIP712Domain = async ({
client,
account,
}: {
client: PublicClient
account: Account
}) => {
let data = await client.readContract({
address: account.address,
abi: [
{
type: 'function',
name: 'eip712Domain',
inputs: [],
outputs: [
{
type: 'bytes1',
name: 'fields,',
},
{
type: 'string',
name: 'name',
},
{
type: 'string',
name: 'version',
},
{
type: 'uint256',
name: 'chainId',
},
{
type: 'address',
name: 'verifyingContract',
},
{
type: 'bytes32',
name: 'salt',
},
{
type: 'uint256[]',
name: 'extensions',
},
],
stateMutability: 'view',
constant: true,
},
],
functionName: 'eip712Domain',
args: [],
})
return {
name: data[1],
version: data[2],
chainId: data[3],
verifyingContract: data[4],
salt: data[5],
}
}

export const isSessionEnabled = async ({
client,
account,
Expand Down Expand Up @@ -139,7 +229,6 @@ export const encodeSmartSessionSignature = ({
if (!enableSessionData) {
throw new Error('enableSession is required for ENABLE mode')
}

return encodePacked(
['bytes1', 'bytes'],
[
Expand Down Expand Up @@ -386,7 +475,9 @@ export const formatPermissionEnableSig = ({
}) => {
switch (accountType) {
case 'erc7579-implementation':
return encodePacked(['address', 'bytes'], [validator, signature])
case 'nexus':
return encodePacked(['address', 'bytes'], [validator, signature])
case 'safe':
return encodePacked(['address', 'bytes'], [validator, signature])
case 'kernel':
Expand Down
8 changes: 4 additions & 4 deletions test/e2e/accounts/7579-ref-implementation.e2e-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ describe('Test erc7579 reference implementation', () => {
}, 80000)

afterAll(async () => {
// await cleanUpEnvironment({
// account,
// client: publicClient,
// })
await cleanUpEnvironment({
account,
client: publicClient,
})
}, 50000)

testOwnableValidator({
Expand Down
132 changes: 66 additions & 66 deletions test/e2e/accounts/Nexus-7579.e2e-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('Test Nexus-7579 Account', () => {
const testClient = getTestClient()
const publicClient = getPublicClient()
const account = getAccount({
address: '0xD13D10447C8684D7793715272A57C2E35ae63823',
address: '0x0000000000781492f9942b873C29635420c31e7f',
type: 'nexus',
})

Expand All @@ -45,71 +45,71 @@ describe('Test Nexus-7579 Account', () => {
testClient,
})

testWebauthnValidator({
account,
publicClient,
testClient,
})

testOwnableExecutor({
account,
publicClient,
testClient,
})

testAutoSavingsExecutor({
account,
publicClient,
testClient,
})

testDeadmanSwitchValidator({
account,
publicClient,
testClient,
})

testSocialRecoveryValidator({
account,
publicClient,
testClient,
})

testRegistryHook({
account,
publicClient,
testClient,
})

testMultiFactorValidator({
account,
publicClient,
testClient,
})

testColdStorageHook({
account,
publicClient,
testClient,
})

testScheduledOrdersExecutor({
account,
publicClient,
testClient,
})

testScheduledTransfersExecutor({
account,
publicClient,
testClient,
})

testHookMultiPlexer({
account,
publicClient,
testClient,
})
// testWebauthnValidator({
// account,
// publicClient,
// testClient,
// })

// testOwnableExecutor({
// account,
// publicClient,
// testClient,
// })

// testAutoSavingsExecutor({
// account,
// publicClient,
// testClient,
// })

// testDeadmanSwitchValidator({
// account,
// publicClient,
// testClient,
// })

// testSocialRecoveryValidator({
// account,
// publicClient,
// testClient,
// })

// testRegistryHook({
// account,
// publicClient,
// testClient,
// })

// testMultiFactorValidator({
// account,
// publicClient,
// testClient,
// })

// testColdStorageHook({
// account,
// publicClient,
// testClient,
// })

// testScheduledOrdersExecutor({
// account,
// publicClient,
// testClient,
// })

// testScheduledTransfersExecutor({
// account,
// publicClient,
// testClient,
// })

// testHookMultiPlexer({
// account,
// publicClient,
// testClient,
// })

testSmartSessionsValidator({
account,
Expand Down
Loading

0 comments on commit 8aa338e

Please sign in to comment.