Skip to content

Commit

Permalink
Change limit + offset type to number for getSafeOperationConfirmations
Browse files Browse the repository at this point in the history
  • Loading branch information
tmjssz committed Jun 25, 2024
1 parent b218e00 commit 1fab95d
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 12 deletions.
12 changes: 6 additions & 6 deletions packages/api-kit/src/SafeApiKit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import {
DeleteSafeDelegateProps,
GetSafeDelegateProps,
GetSafeMessageListProps,
GetSafeOperationConfirmationListOptions,
GetSafeOperationListProps,
GetSafeOperationListResponse,
ListOptions,
ModulesResponse,
OwnerResponse,
ProposeTransactionProps,
Expand Down Expand Up @@ -866,7 +866,7 @@ class SafeApiKit {
*/
async getSafeOperationConfirmations(
safeOperationHash: string,
{ limit, offset }: GetSafeOperationConfirmationListOptions = {}
{ limit, offset }: ListOptions = {}
): Promise<SafeOperationConfirmationListResponse> {
if (!safeOperationHash) {
throw new Error('Invalid SafeOperation hash')
Expand All @@ -876,12 +876,12 @@ class SafeApiKit {
`${this.#txServiceBaseUrl}/v1/safe-operations/${safeOperationHash}/confirmations/`
)

if (limit) {
url.searchParams.set('limit', limit)
if (limit != null) {
url.searchParams.set('limit', limit.toString())
}

if (offset) {
url.searchParams.set('offset', offset)
if (offset != null) {
url.searchParams.set('offset', offset.toString())
}

return sendRequest({
Expand Down
6 changes: 3 additions & 3 deletions packages/api-kit/src/types/safeTransactionServiceTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,9 @@ export type AddSafeOperationProps = {
}
}

export type GetSafeOperationConfirmationListOptions = {
export type ListOptions = {
/** Maximum number of results to return per page */
limit?: string
limit?: number
/** Initial index from which to return the results */
offset?: string
offset?: number
}
47 changes: 44 additions & 3 deletions packages/api-kit/tests/e2e/getSafeOperationConfirmations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,25 @@ chai.use(chaiAsPromised)
let safeApiKit: SafeApiKit

const TX_SERVICE_URL = 'https://safe-transaction-sepolia.staging.5afe.dev/api'
const SAFE_OPERATION_HASH = '0x375d3bd580600ce04d7d2c1d8d88d85f27b9c7d14d7b544f2ee585d672f2b449'
const EXPECTED_SAFE_OPERATION_CONFIRMATIONS = [
{
created: '2024-06-19T10:45:22.906337Z',
modified: '2024-06-19T10:45:22.906337Z',
owner: '0x56e2C102c664De6DfD7315d12c0178b61D16F171',
signature:
'0x3c4a706f78e269e20e046f06a153ff06842045bf2c9e7b28aa9f4e93b530c8aa67b8c0871ae008987ad9d1abbe1aa48efbae3b425c791ba03ed1a7542e07c9ce1b',
signatureType: 'EOA'
},
{
created: '2024-06-19T10:45:25.895780Z',
modified: '2024-06-19T10:45:25.895780Z',
owner: '0x9cCBDE03eDd71074ea9c49e413FA9CDfF16D263B',
signature:
'0x619619f4f29578bc9cc4396ceb4b8ee6cc8722bc011f6cf3ace3c903b29162a07e2ddb3af4beccecd8ce68252af177a29f613d1d27c7961b0fc61cf09a0347fa1b',
signatureType: 'EOA'
}
]

describe('getSafeOperationConfirmations', () => {
before(async () => {
Expand All @@ -27,10 +46,32 @@ describe('getSafeOperationConfirmations', () => {
chai.expect(safeOpConfirmations.results.length).to.be.equal(0)
})

it('should return the SafeOperation with the given safeOperationHash', async () => {
const safeOperationHash = '0x375d3bd580600ce04d7d2c1d8d88d85f27b9c7d14d7b544f2ee585d672f2b449'
const safeOpConfirmations = await safeApiKit.getSafeOperationConfirmations(safeOperationHash)
it('should return the confirmations for the given safeOperationHash', async () => {
const safeOpConfirmations = await safeApiKit.getSafeOperationConfirmations(SAFE_OPERATION_HASH)
chai.expect(safeOpConfirmations.count).to.be.equal(2)
chai.expect(safeOpConfirmations.results.length).to.be.equal(2)
chai.expect(safeOpConfirmations.results).to.deep.equal(EXPECTED_SAFE_OPERATION_CONFIRMATIONS)
})

it('should return only the first confirmation if limit = 1', async () => {
const safeOpConfirmations = await safeApiKit.getSafeOperationConfirmations(
SAFE_OPERATION_HASH,
{ limit: 1 }
)
chai.expect(safeOpConfirmations.count).to.be.equal(2)
chai
.expect(safeOpConfirmations.results)
.to.deep.equal([EXPECTED_SAFE_OPERATION_CONFIRMATIONS[0]])
})

it('should return only the second confirmation if offset = 1', async () => {
const safeOpConfirmations = await safeApiKit.getSafeOperationConfirmations(
SAFE_OPERATION_HASH,
{ offset: 1 }
)
chai.expect(safeOpConfirmations.count).to.be.equal(2)
chai
.expect(safeOpConfirmations.results)
.to.deep.equal([EXPECTED_SAFE_OPERATION_CONFIRMATIONS[1]])
})
})

0 comments on commit 1fab95d

Please sign in to comment.