From f7bd768d2065c25ce7be630f7c09e16b2b5c7437 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yago=20P=C3=A9rez=20V=C3=A1zquez?= Date: Fri, 20 Oct 2023 10:11:23 +0200 Subject: [PATCH] Add tests --- packages/api-kit/src/SafeApiKit.ts | 2 +- .../src/types/safeTransactionServiceTypes.ts | 2 +- packages/api-kit/tests/e2e/addMessage.test.ts | 45 +++++++++++++++++++ 3 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 packages/api-kit/tests/e2e/addMessage.test.ts diff --git a/packages/api-kit/src/SafeApiKit.ts b/packages/api-kit/src/SafeApiKit.ts index 2dc05fd15..d757e8be8 100644 --- a/packages/api-kit/src/SafeApiKit.ts +++ b/packages/api-kit/src/SafeApiKit.ts @@ -659,7 +659,7 @@ class SafeApiKit { async addMessage( safeAddress: string, - { message, safeAppId, signature }: AddMessageProps + { message, safeAppId = 0, signature }: AddMessageProps ): Promise { if (!safeAddress) { throw new Error('Invalid safeAddress') diff --git a/packages/api-kit/src/types/safeTransactionServiceTypes.ts b/packages/api-kit/src/types/safeTransactionServiceTypes.ts index dd383c938..00a4880e6 100644 --- a/packages/api-kit/src/types/safeTransactionServiceTypes.ts +++ b/packages/api-kit/src/types/safeTransactionServiceTypes.ts @@ -301,6 +301,6 @@ export type EIP712TypedData = { export type AddMessageProps = { message: string | EIP712TypedData - safeAppId: number + safeAppId?: number signature: string } diff --git a/packages/api-kit/tests/e2e/addMessage.test.ts b/packages/api-kit/tests/e2e/addMessage.test.ts new file mode 100644 index 000000000..5a89cc2f8 --- /dev/null +++ b/packages/api-kit/tests/e2e/addMessage.test.ts @@ -0,0 +1,45 @@ +import { Signer } from '@ethersproject/abstract-signer' +import SafeApiKit, { AddSafeDelegateProps } from '@safe-global/api-kit/index' +import chai from 'chai' +import chaiAsPromised from 'chai-as-promised' +import config from '../utils/config' +import { getServiceClient } from '../utils/setupServiceClient' +import { ethers } from 'ethers' + +chai.use(chaiAsPromised) + +let safeApiKit: SafeApiKit +let signer: Signer + +const MESSAGE = 'I am the owner of this safe' + +describe.only('addMessage', () => { + before(async () => { + ;({ safeApiKit, signer } = await getServiceClient( + '0x4f3edf983ac636a65a842ce7c78d9aa706d3b113bce9c46f30d7d21715b23b1d' + )) + }) + + it('should fail if safeAddress is empty', async () => { + await chai + .expect( + safeApiKit.addMessage('', { + message: MESSAGE, + signature: '0x' + }) + ) + .to.be.rejectedWith('Invalid safeAddress') + }) + + it('should allow to add an offchain message', async () => { + console.log(await signer.getAddress()) + const signature = await signer.signMessage(MESSAGE) + + await chai.expect( + safeApiKit.addMessage('0x9D1E7371852a9baF631Ea115b9815deb97cC3205', { + message: MESSAGE, + signature + }) + ).to.be.fulfilled + }) +})