diff --git a/packages/sdk-starter-kit/src/SafeClient.ts b/packages/sdk-starter-kit/src/SafeClient.ts index 60bb66155..7595ea94c 100644 --- a/packages/sdk-starter-kit/src/SafeClient.ts +++ b/packages/sdk-starter-kit/src/SafeClient.ts @@ -145,18 +145,16 @@ export class SafeClient extends BaseClient { * @param extendFunc * @returns */ - extend(extendFunc: (client: SafeClient) => Promise): Promise - extend(extendFunc: (client: SafeClient) => T): SafeClient & T + extend(extendFunc: (client: this) => Promise): Promise + extend(extendFunc: (client: this) => T): this & T - extend( - extendFunc: (client: SafeClient) => T | Promise - ): (SafeClient & T) | Promise { + extend(extendFunc: (client: this) => T | Promise): (this & T) | Promise { const result = extendFunc(this) if (result instanceof Promise) { - return result.then((extensions) => Object.assign(this, extensions) as SafeClient & T) + return result.then((extensions) => Object.assign(this, extensions) as this & T) } else { - return Object.assign(this, result) as SafeClient & T + return Object.assign(this, result) as this & T } } diff --git a/packages/sdk-starter-kit/src/index.test.ts b/packages/sdk-starter-kit/src/index.test.ts new file mode 100644 index 000000000..45b82d586 --- /dev/null +++ b/packages/sdk-starter-kit/src/index.test.ts @@ -0,0 +1,40 @@ +import { createSafeClient, offChainMessages, onChainMessages } from './index' + +const RPC_URL = 'https://ethereum-sepolia-rpc.publicnode.com' +const SAFE_ADDRESS = '0x60C4Ab82D06Fd7dFE9517e17736C2Dcc77443EF0' +const SAFE_OWNERS = [ + '0x9cCBDE03eDd71074ea9c49e413FA9CDfF16D263B', + '0x56e2C102c664De6DfD7315d12c0178b61D16F171' +] + +describe('createSafeClient', () => { + it('should create a Safe client instance', async () => { + const safeClient = await createSafeClient({ + provider: RPC_URL, + safeAddress: SAFE_ADDRESS + }) + + const safeAddress = await safeClient.getAddress() + const owners = await safeClient.getOwners() + const threshold = await safeClient.getThreshold() + + expect(safeAddress).toBe('0x60C4Ab82D06Fd7dFE9517e17736C2Dcc77443EF0') + expect(owners).toStrictEqual(SAFE_OWNERS) + expect(threshold).toBe(1) + }) + + it('should allow to extend the client several times and accumulating methods', async () => { + const safeClient1 = await createSafeClient({ + provider: RPC_URL, + safeAddress: SAFE_ADDRESS + }) + + const safeClient2 = safeClient1.extend(offChainMessages()) + const safeClient3 = safeClient2.extend(onChainMessages()) + + expect(safeClient3).toBeDefined() + expect(safeClient3.send).toBeDefined() + expect(safeClient3.sendOnChainMessage).toBeDefined() + expect(safeClient3.sendOffChainMessage).toBeDefined() + }) +}) diff --git a/packages/sdk-starter-kit/src/types.ts b/packages/sdk-starter-kit/src/types.ts index 5021ed852..01d64b34c 100644 --- a/packages/sdk-starter-kit/src/types.ts +++ b/packages/sdk-starter-kit/src/types.ts @@ -58,7 +58,7 @@ export type PredictedSafeConfig = { export type SdkStarterKitRootConfig = { provider: SafeProvider['provider'] - signer: SafeProvider['signer'] + signer?: SafeProvider['signer'] } export type SdkStarterKitConfig = SdkStarterKitRootConfig &