From 791cb3615e758722394572e4893e81e19d90ba40 Mon Sep 17 00:00:00 2001 From: aproskill81 Date: Wed, 25 Mar 2026 10:10:05 +0100 Subject: [PATCH] fix: make getLinkedAgw parameters optional --- .../agw-client/src/actions/getLinkedAgw.ts | 2 +- .../test/src/actions/getLinkedAgw.test.ts | 51 +++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 packages/agw-client/test/src/actions/getLinkedAgw.test.ts diff --git a/packages/agw-client/src/actions/getLinkedAgw.ts b/packages/agw-client/src/actions/getLinkedAgw.ts index 1107ec31..f1812575 100644 --- a/packages/agw-client/src/actions/getLinkedAgw.ts +++ b/packages/agw-client/src/actions/getLinkedAgw.ts @@ -72,7 +72,7 @@ export async function getLinkedAgw< account extends Account | undefined = Account | undefined, >( client: Client, - parameters: GetLinkedAgwParameters, + parameters: GetLinkedAgwParameters = {}, ): Promise { const { address = client.account?.address } = parameters; diff --git a/packages/agw-client/test/src/actions/getLinkedAgw.test.ts b/packages/agw-client/test/src/actions/getLinkedAgw.test.ts new file mode 100644 index 00000000..eeb23cdd --- /dev/null +++ b/packages/agw-client/test/src/actions/getLinkedAgw.test.ts @@ -0,0 +1,51 @@ +import { createClient, getAddress } from 'viem'; +import { ChainEIP712 } from 'viem/zksync'; +import { beforeEach, describe, expect, it, vi } from 'vitest'; + +import { getLinkedAgw } from '../../../src/actions/getLinkedAgw.js'; +import { + AGW_LINK_DELEGATION_RIGHTS, + CANONICAL_EXCLUSIVE_DELEGATE_RESOLVER_ADDRESS, +} from '../../../src/constants.js'; +import { anvilAbstractTestnet } from '../../anvil.js'; +import { address } from '../../constants.js'; + +vi.mock('viem/actions', async (importOriginal) => { + const actual = await importOriginal(); + return { + ...(actual as object), + readContract: vi.fn(), + }; +}); + +import { readContract } from 'viem/actions'; + +const baseClient = createClient({ + account: address.smartAccountAddress, + chain: anvilAbstractTestnet.chain as ChainEIP712, + transport: anvilAbstractTestnet.clientConfig.transport, +}); + +beforeEach(() => { + vi.resetAllMocks(); +}); + +describe('getLinkedAgw', () => { + it('uses the connected account when parameters are omitted', async () => { + const linkedAgw = '0x1234567890123456789012345678901234567890'; + vi.mocked(readContract).mockResolvedValue(linkedAgw); + + const result = await getLinkedAgw(baseClient); + + expect(readContract).toHaveBeenCalledWith(baseClient, { + abi: expect.any(Array), + address: CANONICAL_EXCLUSIVE_DELEGATE_RESOLVER_ADDRESS, + functionName: 'exclusiveWalletByRights', + args: [ + getAddress(address.smartAccountAddress), + AGW_LINK_DELEGATION_RIGHTS, + ], + }); + expect(result).toEqual({ agw: linkedAgw }); + }); +});