import { describe, it, expect, beforeEach, vi } from 'vitest'; import { getIsSmartWallet } from './is-smart-wallet'; import { PublicActions } from 'viem'; describe('getIsSmartWallet', () => { let client: PublicActions; beforeEach(() => { client = { getCode: vi.fn(), } as unknown as PublicActions; }); it('should return false if code is undefined', async () => { vi.mocked(client.getCode).mockResolvedValue(undefined); const result = await getIsSmartWallet(client, '0x123'); expect(result).toBe(false); }); it('should return false if code is "0x"', async () => { vi.mocked(client.getCode).mockResolvedValue('0x'); const result = await getIsSmartWallet(client, '0x123'); expect(result).toBe(false); }); it('should return true if code is not "0x"', async () => { vi.mocked(client.getCode).mockResolvedValue('0x123'); const result = await getIsSmartWallet(client, '0x123'); expect(result).toBe(true); }); it('should return false and log error if an exception is thrown', async () => { const consoleErrorSpy = vi .spyOn(console, 'error') .mockImplementation(() => {}); vi.mocked(client.getCode).mockRejectedValue(new Error('Test error')); const result = await getIsSmartWallet(client, '0x123'); expect(result).toBe(false); expect(consoleErrorSpy).toHaveBeenCalledWith( 'Error checking if address is a smart wallet:', new Error('Test error') ); consoleErrorSpy.mockRestore(); }); });