Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { encodeFunctionData, keccak256 } from 'viem/utils';
import { beforeEach, describe, expect, vi } from 'vitest';

import { createSmartAccount, sign, wrapSignature } from './createSmartAccount.js';
import { factoryAddress } from './constants.js';

const privateKey = '0x8d0ec8aa1f67f8c11db3c191d3d66408e148759acd617fa22ab5d5d677a234e9';
const signer = privateKeyToAccount(privateKey);
Expand All @@ -19,6 +20,38 @@ const client = createClient({
chain: baseSepolia,
});

describe('getFactoryArgs', () => {
it('returns the factory and factoryData when factoryData is provided', async () => {
const factoryData = '0x1234';
const account = await createSmartAccount({
client,
owner: signer,
ownerIndex: 0,
address: '0xBb0c1d5E7f530e8e648150fc7Cf30912575523E8',
factoryData,
});

await expect(account.getFactoryArgs()).resolves.toEqual({
factory: factoryAddress,
factoryData,
});
});

it('throws a clear error when factoryData is missing', async () => {
const account = await createSmartAccount({
client,
owner: signer,
ownerIndex: 0,
address: '0xBb0c1d5E7f530e8e648150fc7Cf30912575523E8',
factoryData: undefined,
});

await expect(account.getFactoryArgs()).rejects.toThrow(
'factoryData was not provided',
);
});
});

describe('encodeCalls', () => {
it('single', async () => {
const account = await createSmartAccount({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,11 @@ export async function createSmartAccount(
},

async getFactoryArgs() {
if (factoryData) return { factory: factory.address, factoryData };
// TODO: support creating factory data
if (!factoryData) {
throw new BaseError(
'Cannot deploy smart account: factoryData was not provided and cannot be derived locally.',
);
}
return { factory: factory.address, factoryData };
},

Expand Down