Skip to content

Commit d112a7e

Browse files
fix(synapse-core): address PR review — simplify getClientDataSets args, update GIT_REF, add paginated RPC test
1 parent d14c1a1 commit d112a7e

3 files changed

Lines changed: 40 additions & 21 deletions

File tree

packages/synapse-core/src/warm-storage/get-client-data-sets.ts

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ export namespace getClientDataSets {
1919
export type OptionsType = {
2020
/** Client address to fetch data sets for. */
2121
address: Address
22-
/** Starting index (0-based). Use 0 to start from beginning. Defaults to fetching all (unpaginated). */
22+
/** Starting index (0-based). Use `0` to start from the beginning. Defaults to `0n`. */
2323
offset?: bigint
24-
/** Maximum number of data sets to return. Use 0 to get all remaining. Defaults to fetching all (unpaginated). */
24+
/** Maximum number of data sets to return. Use `0` to get all remaining. Defaults to `0n` (all). */
2525
limit?: bigint
2626
/** Warm storage contract address. If not provided, the default is the storage view contract address for the chain. */
2727
contractAddress?: Address
@@ -87,7 +87,12 @@ export async function getClientDataSets(
8787
export namespace getClientDataSetsCall {
8888
export type OptionsType = Simplify<getClientDataSets.OptionsType & ActionCallChain>
8989
export type ErrorType = asChain.ErrorType
90-
export type OutputType = ContractFunctionParameters<typeof storageViewAbi, 'pure' | 'view', 'getClientDataSets'>
90+
export type OutputType = ContractFunctionParameters<
91+
typeof storageViewAbi,
92+
'pure' | 'view',
93+
'getClientDataSets',
94+
[Address, bigint, bigint]
95+
>
9196
}
9297

9398
/**
@@ -123,21 +128,10 @@ export namespace getClientDataSetsCall {
123128
*/
124129
export function getClientDataSetsCall(options: getClientDataSetsCall.OptionsType) {
125130
const chain = asChain(options.chain)
126-
const base = {
131+
return {
127132
abi: chain.contracts.fwssView.abi,
128133
address: options.contractAddress ?? chain.contracts.fwssView.address,
129134
functionName: 'getClientDataSets',
130-
} as const
131-
132-
if (options.offset != null || options.limit != null) {
133-
return {
134-
...base,
135-
args: [options.address, options.offset ?? 0n, options.limit ?? 0n],
136-
} as getClientDataSetsCall.OutputType
137-
}
138-
139-
return {
140-
...base,
141-
args: [options.address],
135+
args: [options.address, options.offset ?? 0n, options.limit ?? 0n],
142136
} satisfies getClientDataSetsCall.OutputType
143137
}

packages/synapse-core/test/get-client-data-sets.test.ts

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ describe('getClientDataSets', () => {
2828
})
2929

3030
assert.equal(call.functionName, 'getClientDataSets')
31-
assert.deepEqual(call.args, [ADDRESSES.client1])
31+
assert.deepEqual(call.args, [ADDRESSES.client1, 0n, 0n])
3232
assert.equal(call.address, calibration.contracts.fwssView.address)
3333
assert.equal(call.abi, calibration.contracts.fwssView.abi)
3434
})
@@ -40,7 +40,7 @@ describe('getClientDataSets', () => {
4040
})
4141

4242
assert.equal(call.functionName, 'getClientDataSets')
43-
assert.deepEqual(call.args, [ADDRESSES.client1])
43+
assert.deepEqual(call.args, [ADDRESSES.client1, 0n, 0n])
4444
assert.equal(call.address, mainnet.contracts.fwssView.address)
4545
assert.equal(call.abi, mainnet.contracts.fwssView.abi)
4646
})
@@ -68,14 +68,14 @@ describe('getClientDataSets', () => {
6868
assert.deepEqual(call.args, [ADDRESSES.client1, 10n, 50n])
6969
})
7070

71-
it('should use unpaginated args when no offset/limit provided', () => {
71+
it('should default offset/limit to 0n when not provided', () => {
7272
const call = getClientDataSetsCall({
7373
chain: calibration,
7474
address: ADDRESSES.client1,
7575
})
7676

7777
assert.equal(call.functionName, 'getClientDataSets')
78-
assert.deepEqual(call.args, [ADDRESSES.client1])
78+
assert.deepEqual(call.args, [ADDRESSES.client1, 0n, 0n])
7979
})
8080
})
8181

@@ -109,5 +109,30 @@ describe('getClientDataSets', () => {
109109
assert.equal(typeof first.providerId, 'bigint')
110110
assert.equal(typeof first.dataSetId, 'bigint')
111111
})
112+
113+
it('should fetch client data sets with pagination', async () => {
114+
server.use(JSONRPC(presets.basic))
115+
116+
const client = createPublicClient({
117+
chain: calibration,
118+
transport: http(),
119+
})
120+
121+
const dataSets = await getClientDataSets(client, {
122+
address: ADDRESSES.client1,
123+
offset: 0n,
124+
limit: 10n,
125+
})
126+
127+
assert.ok(dataSets.length > 0)
128+
const [first] = dataSets
129+
assert.ok(first)
130+
if (!first) return
131+
132+
assert.equal(typeof first.pdpRailId, 'bigint')
133+
assert.equal(typeof first.dataSetId, 'bigint')
134+
assert.equal(typeof first.payer, 'string')
135+
assert.equal(typeof first.payee, 'string')
136+
})
112137
})
113138
})

packages/synapse-core/wagmi.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { multicall } from 'viem/actions'
55
import { calibration, mainnet } from './src/chains.ts'
66

77
// GIT_REF can be one of: '<branch name>', '<commit>' or 'tags/<tag>'
8-
const GIT_REF = 'd08214e1b3d200e0bc80f0d4f2e5ea3e1e4d603e'
8+
const GIT_REF = 'ed85348ebad54196b5bfefc5cb0dbe7e8bfd6f7c'
99
const BASE_URL = `https://raw.githubusercontent.com/FilOzone/filecoin-services/${GIT_REF.replace(/^(?![a-f0-9]{40}$)/, 'refs/')}/service_contracts/abi`
1010
const FWSS_ADDRESS_CALIBRATION = '0x02925630df557F957f70E112bA06e50965417CA0' as Address
1111
const FWSS_ADDRESS_MAINNET = '0x8408502033C418E1bbC97cE9ac48E5528F371A9f' as Address

0 commit comments

Comments
 (0)