Skip to content

Commit

Permalink
chore: fix nonce
Browse files Browse the repository at this point in the history
  • Loading branch information
joepegler committed Dec 19, 2024
1 parent aa5983f commit acc77b9
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 22 deletions.
3 changes: 2 additions & 1 deletion src/sdk/account/toNexusAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ export const toNexusAccount = async (
const getNonce = async (parameters?: {
key?: bigint
validationMode?: "0x00" | "0x01"
moduleAddress?: Address
}): Promise<bigint> => {
try {
const TIMESTAMP_ADJUSTMENT = 16777215n
Expand All @@ -410,7 +411,7 @@ export const toNexusAccount = async (
const key: string = concat([
toHex(defaultedKey, { size: 3 }),
defaultedValidationMode,
module.address as Hex
parameters?.moduleAddress ?? (module.address as Hex)
])

const accountAddress = await getCounterFactualAddress()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { getAccount } from "@rhinestone/module-sdk/account"
import {
OWNABLE_VALIDATOR_ADDRESS,
type Session,
SmartSessionMode,
decodeSmartSessionSignature,
encodeSmartSessionSignature,
encodeValidationData,
getEnableSessionDetails,
getOwnableValidatorMockSignature,
getSmartSessionsValidator,
getSudoPolicy
} from "@rhinestone/module-sdk/module"
Expand All @@ -27,7 +29,7 @@ import {
getUserOperationHash
} from "viem/account-abstraction"
import { generatePrivateKey, privateKeyToAccount } from "viem/accounts"
import { afterAll, beforeAll, describe, expect, test } from "vitest"
import { beforeAll, describe, expect, test } from "vitest"
import { CounterAbi } from "../../../test/__contracts/abi/CounterAbi"
import { testAddresses } from "../../../test/callDatas"
import { toNetwork } from "../../../test/testSetup"
Expand All @@ -38,11 +40,8 @@ import {
type NexusClient,
createSmartAccountClient
} from "../../clients/createSmartAccountClient"
import {
MAINNET_ADDRESS_K1_VALIDATOR_ADDRESS,
SIMPLE_SESSION_VALIDATOR_ADDRESS
} from "../../constants"
import { generateSalt } from "./Helpers"
import { MAINNET_ADDRESS_K1_VALIDATOR_ADDRESS } from "../../constants"

describe("modules.smartSessions.enable.mode.dx", async () => {
let network: NetworkConfig
Expand Down Expand Up @@ -161,8 +160,11 @@ describe("modules.smartSessions.enable.mode.dx", async () => {
}

const session: Session = {
sessionValidator: SIMPLE_SESSION_VALIDATOR_ADDRESS,
sessionValidatorInitData: sessionPublicKey,
sessionValidator: OWNABLE_VALIDATOR_ADDRESS,
sessionValidatorInitData: encodeValidationData({
threshold: 1,
owners: [sessionPublicKey]
}),
salt: generateSalt(),
userOpPolicies: [],
erc7739Policies: {
Expand Down Expand Up @@ -199,23 +201,35 @@ describe("modules.smartSessions.enable.mode.dx", async () => {
const sessionDetailKeys = Object.keys(sessionDetails)
console.log({ sessionDetailKeys })

const permissionEnableRawSig = await eoaAccount.signMessage({
message: { raw: permissionEnableHash }
})

sessionDetails.enableSessionData.enableSession.permissionEnableSig =
await eoaAccount.signMessage({
message: { raw: permissionEnableHash }
})
encodePacked(
["address", "bytes"],
[MAINNET_ADDRESS_K1_VALIDATOR_ADDRESS, permissionEnableRawSig]
)

const nonce = await nexusClient.account.getNonce({
// @ts-ignore
moduleAddress: OWNABLE_VALIDATOR_ADDRESS
})

const signature = encodeSmartSessionSignature(sessionDetails)
console.log({ nonce })

const decodededSignature = decodeSmartSessionSignature({
signature,
account: nexusAccount
})
// const signature = encodeSmartSessionSignature(sessionDetails)

// const decodededSignature = decodeSmartSessionSignature({
// signature,
// account: nexusAccount
// })

expect(decodededSignature.mode).toBe(SmartSessionMode.UNSAFE_ENABLE)
expect(decodededSignature.permissionId).toBe(sessionDetails.permissionId)
expect(decodededSignature.signature).toBe(sessionDetails.signature)
// expect(decodededSignature.mode).toBe(SmartSessionMode.UNSAFE_ENABLE)
// expect(decodededSignature.permissionId).toBe(sessionDetails.permissionId)
// expect(decodededSignature.signature).toBe(sessionDetails.signature)

console.log({ decodededSignature })
// console.log({ decodededSignature })

const calls = [
{
Expand All @@ -233,10 +247,15 @@ describe("modules.smartSessions.enable.mode.dx", async () => {

console.log({ calls })

sessionDetails.signature = getOwnableValidatorMockSignature({
threshold: 1
})

const userOperation = await nexusClient.prepareUserOperation({

Check failure on line 254 in src/sdk/modules/smartSessionsValidator/toSmartSessionValidator.enable.mode.test.ts

View workflow job for this annotation

GitHub Actions / unit-tests

src/sdk/modules/smartSessionsValidator/toSmartSessionValidator.enable.mode.test.ts > modules.smartSessions.enable.mode.dx > should support smart sessions enable mode

UserOperationExecutionError: The `validateUserOp` function on the Smart Account reverted. Request Arguments: callData: 0xe9ae5c5300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000003814e4829e655f0b3a1793838ddd47273d5341d4160000000000000000000000000000000000000000000000000000000000000000273ea3e30000000000000000 callGasLimit: 0 maxFeePerGas: 0.001500789 gwei maxPriorityFeePerGas: 0.0015 gwei nonce: 2822986803341493805304976706285081757671653550070739114876484268125551853568 preVerificationGas: 0 sender: 0x9d853Bb2cF20B803f7B0F4535EF46a35685802e9 signature: 0x00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000002D6DB27c52E3C11c1Cf24072004AC75cBa000000000000000000000000000000000000000000000000000000000000004181d4b4981670cb18f99f0b4a66446df1bf5b204d24cfcb659bf38ba27a4359b5711649ec2423c5e1247245eba2964679b6a1dbb85c992ae40b9b00c6935b02ff1b00000000000000000000000000000000000000000000000000000000000000 verificationGasLimit: 0 Details: {"code":-32500,"message":"AA23 reverted"} Version: 2.21.6 ❯ getUserOperationError node_modules/viem/account-abstraction/utils/errors/getUserOperationError.ts:68:10 ❯ estimateUserOperationGas node_modules/viem/account-abstraction/actions/bundler/estimateUserOperationGas.ts:186:11 ❯ prepareUserOperation node_modules/viem/account-abstraction/actions/bundler/prepareUserOperation.ts:559:19 ❯ src/sdk/modules/smartSessionsValidator/toSmartSessionValidator.enable.mode.test.ts:254:27 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Serialized Error: { details: '{"code":-32500,"message":"AA23 reverted"}', docsPath: undefined, metaMessages: [ 'Request Arguments:', ' callData: 0xe9ae5c5300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000003814e4829e655f0b3a1793838ddd47273d5341d4160000000000000000000000000000000000000000000000000000000000000000273ea3e30000000000000000\n callGasLimit: 0\n maxFeePerGas: 0.001500789 gwei\n maxPriorityFeePerGas: 0.0015 gwei\n nonce: 2822986803341493805304976706285081757671653550070739114876484268125551853568\n preVerificationGas: 0\n sender: 0x9d853Bb2cF20B803f7B0F4535EF46a35685802e9\n signature: 0x00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000002D6DB27c52E3C11c1Cf24072004AC75cBa000000000000000000000000000000000000000000000000000000000000004181d4b4981670cb18f99f0b4a66446df1bf5b204d24cfcb659bf38ba27a4359b5711649ec2423c5e1247245eba2964679b6a1dbb85c992ae40b9b00c6935b02ff1b00000000000000000000000000000000000000000000000000000000000000\n verificationGasLimit: 0' ], shortMessage: 'The `validateUserOp` function on the Smart Account reverted.', version: '2.21.6', walk: 'Function<walk>' } Caused by: SmartAccountFunctionRevertedError: The `validateUserOp` function on the Smart Account reverted. Details: {"code":-32500,"message":"AA23 reverted"} Version: 2.21.6 ❯ getBundlerError node_modules/viem/account-abstraction/utils/errors/getBundlerError.ts:219:12 ❯ node_modules/viem/account-abstraction/utils/errors/getUserOperationError.ts:54:19 ❯ getUserOperationError node_modules/viem/account-abstraction/utils/errors/getUserOperationError.ts:67:5 ❯ estimateUserOperationGas node_modules/viem/account-abstraction/actions/bundler/estimateUserOperationGas.ts:186:11 ❯ prepareUserOperation node_modules/viem/account-abstraction/actions/bundler/prepareUserOperation.ts:559:19 ❯ src/sdk/modules/smartSessionsValidator/toSmartSessionValidator.enable.mode.test.ts:254:27 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Serialized Error: { details: '{"code":-32500,"message":"AA23 reverted"}', docsPath: undefined, metaMessages: undefined, shortMessage: 'The `validateUserOp` function on the Smart Accou
account: nexusClient.account,
calls,
signature
nonce,
signature: encodeSmartSessionSignature(sessionDetails)
})

const userOpHashToSign = getUserOperationHash({
Expand Down

0 comments on commit acc77b9

Please sign in to comment.