Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yagopv committed Oct 20, 2023
1 parent 9c9243d commit f7bd768
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/api-kit/src/SafeApiKit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ class SafeApiKit {

async addMessage(
safeAddress: string,
{ message, safeAppId, signature }: AddMessageProps
{ message, safeAppId = 0, signature }: AddMessageProps
): Promise<void> {
if (!safeAddress) {
throw new Error('Invalid safeAddress')
Expand Down
2 changes: 1 addition & 1 deletion packages/api-kit/src/types/safeTransactionServiceTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,6 @@ export type EIP712TypedData = {

export type AddMessageProps = {
message: string | EIP712TypedData
safeAppId: number
safeAppId?: number
signature: string
}
45 changes: 45 additions & 0 deletions packages/api-kit/tests/e2e/addMessage.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { Signer } from '@ethersproject/abstract-signer'
import SafeApiKit, { AddSafeDelegateProps } from '@safe-global/api-kit/index'

Check warning on line 2 in packages/api-kit/tests/e2e/addMessage.test.ts

View workflow job for this annotation

GitHub Actions / eslint

'AddSafeDelegateProps' is defined but never used
import chai from 'chai'
import chaiAsPromised from 'chai-as-promised'
import config from '../utils/config'

Check warning on line 5 in packages/api-kit/tests/e2e/addMessage.test.ts

View workflow job for this annotation

GitHub Actions / eslint

'config' is defined but never used
import { getServiceClient } from '../utils/setupServiceClient'
import { ethers } from 'ethers'

Check warning on line 7 in packages/api-kit/tests/e2e/addMessage.test.ts

View workflow job for this annotation

GitHub Actions / eslint

'ethers' is defined but never used

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
})
})

0 comments on commit f7bd768

Please sign in to comment.