From 1f363a1758be66f11b2cacb0091a1b3e58e5124d Mon Sep 17 00:00:00 2001 From: Snowmanzx <105658828+Snowmanzx@users.noreply.github.com> Date: Wed, 10 Jun 2026 17:03:06 +0300 Subject: [PATCH] fix: throw when adding sub account owner fails The catch block in sendRequestToSubAccountSigner used return standardErrors.provider.unauthorized(...). That factory returns an error object so the promise resolved with the error instead of rejecting and the caller used it as a successful result. Changed return to throw. Added a regression test. --- .../src/sign/base-account/Signer.test.ts | 65 +++++++++++++++++++ .../src/sign/base-account/Signer.ts | 2 +- 2 files changed, 66 insertions(+), 1 deletion(-) diff --git a/packages/account-sdk/src/sign/base-account/Signer.test.ts b/packages/account-sdk/src/sign/base-account/Signer.test.ts index 23598e56..53cfef37 100644 --- a/packages/account-sdk/src/sign/base-account/Signer.test.ts +++ b/packages/account-sdk/src/sign/base-account/Signer.test.ts @@ -1539,6 +1539,71 @@ describe('Signer', () => { expect(handleAddSubAccountOwner).toHaveBeenCalled(); }); + it('throws when adding the sub account owner fails', async () => { + await signer.cleanup(); + + store.subAccounts.set({ + address: '0x7838d2724FC686813CAf81d4429beff1110c739a', + }); + + // Mock that spend permissions exist so we don't route through global account + const mockSpendPermissions = [createMockSpendPermission()]; + vi.spyOn(store.spendPermissions, 'get').mockReturnValue(mockSpendPermissions); + + (findOwnerIndex as Mock).mockResolvedValueOnce(-1); + (handleAddSubAccountOwner as Mock).mockRejectedValueOnce(new Error('user rejected')); + + (decryptContent as Mock).mockResolvedValueOnce({ + result: { + value: null, + }, + }); + + await signer.handshake({ method: 'handshake' }); + expect(signer['accounts']).toEqual([]); + + signer['accounts'] = [ + '0x7838d2724FC686813CAf81d4429beff1110c739a', + '0xe6c7D51b0d5ECC217BE74019447aeac4580Afb54', + ]; + + const mockRequest: RequestArguments = { + method: 'wallet_sendCalls', + params: [ + { + to: '0xe6c7D51b0d5ECC217BE74019447aeac4580Afb54', + version: '1', + calls: [], + from: '0x7838d2724FC686813CAf81d4429beff1110c739a', + }, + ], + }; + + (decryptContent as Mock).mockResolvedValueOnce({ + result: { + value: { + accounts: [ + { + address: '0xe6c7D51b0d5ECC217BE74019447aeac4580Afb54', + capabilities: { + subAccounts: [ + { + address: '0x7838d2724FC686813CAf81d4429beff1110c739a', + factory: '0xe6c7D51b0d5ECC217BE74019447aeac4580Afb54', + factoryData: '0x', + }, + ], + }, + }, + ], + }, + }, + }); + + // Before the fix this resolved with the error object instead of rejecting + await expect(signer.request(mockRequest)).rejects.toThrow(); + }); + it('should not handle insufficient balance error if external funding source data is not provided', async () => { (createSubAccountSigner as Mock).mockImplementation(async () => { const request = vi.fn((args) => { diff --git a/packages/account-sdk/src/sign/base-account/Signer.ts b/packages/account-sdk/src/sign/base-account/Signer.ts index 1cffe605..58ee5ad2 100644 --- a/packages/account-sdk/src/sign/base-account/Signer.ts +++ b/packages/account-sdk/src/sign/base-account/Signer.ts @@ -792,7 +792,7 @@ export class Signer { correlationId, errorMessage: parseErrorMessageFromAny(error), }); - return standardErrors.provider.unauthorized( + throw standardErrors.provider.unauthorized( 'failed to add sub account owner when sending request to sub account signer' ); }