Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
fb208cc
test(core-acs-reader): add cache test
mateuszpiatkowski-da Jun 1, 2026
35dde8b
test(core-acs-reader): add collection tests
mateuszpiatkowski-da Jun 1, 2026
30f4e4f
test(core-acs-reader): add reader tests
mateuszpiatkowski-da Jun 1, 2026
2eb3fea
test(core-acs-reader): add test for service
mateuszpiatkowski-da Jun 1, 2026
f02745e
fix(core-acs-reader): undo vitest config modification
mateuszpiatkowski-da Jun 1, 2026
e9363ac
test(core-acs-reader): remove redundant test
mateuszpiatkowski-da Jun 2, 2026
7531418
test(core-acs-reader): add tests for collection & cache items
mateuszpiatkowski-da Jun 10, 2026
43b90e4
test(core-acs-reader): continue working on tests :wip:
mateuszpiatkowski-da Jun 11, 2026
646b89d
test(core-acs-reader): finish working on tests
mateuszpiatkowski-da Jun 11, 2026
00c7708
Merge branch 'main' into mateuszpiatkowski-da/core-acs-reader-unit-tests
mateuszpiatkowski-da Jun 11, 2026
cc6cfb6
refactor(core-acs-reader): remove redundant flags
mateuszpiatkowski-da Jun 16, 2026
cc8d5fd
refactor(wallet-sdk): remove redundant method
mateuszpiatkowski-da Jun 16, 2026
9ebff8b
Merge branch 'main' into mateuszpiatkowski-da/core-acs-reader-unit-tests
mateuszpiatkowski-da Jun 16, 2026
e2f83ab
test(core-acs-reader): add additional test assertion
mateuszpiatkowski-da Jun 16, 2026
9ed38de
Merge branch 'main' into mateuszpiatkowski-da/core-acs-reader-unit-tests
pawelstepien-da Jun 16, 2026
a59ab81
Merge branch 'main' into mateuszpiatkowski-da/core-acs-reader-unit-tests
pawelstepien-da Jun 17, 2026
9961dee
test(core-acs-reader): fix test build
mateuszpiatkowski-da Jun 17, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions core/acs-reader/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
"dev": "tsup --watch --onSuccess \"tsc\"",
"clean": "tsc -b --clean; rm -rf dist",
"flatpack": "yarn pack --out \"$FLATPACK_OUTDIR\"",
"test": "vitest run --project node --project browser --passWithNoTests",
"test:coverage": "vitest run --project node --project browser --coverage --passWithNoTests"
"test": "vitest run --project node --project browser",
"test:coverage": "vitest run --project node --project browser --coverage"
},
"devDependencies": {
"@types/node": "^25.0.10",
Expand Down
226 changes: 226 additions & 0 deletions core/acs-reader/src/__test__/cache/collection.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,226 @@
// Copyright (c) 2025-2026 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

import { beforeEach, describe, expect, it, vi } from 'vitest'
import {
ACSCacheCollection,
PaginatedACSCacheCollection,
} from '../../cache/collection'

const { mockCache, MockACSCache } = vi.hoisted(() => {
const update = vi.fn()
const calculateAt = vi.fn()

const mockCache = {
update,
calculateAt,
}

const MockACSCache = vi.fn(
class {
update = update
calculateAt = calculateAt
}
)

return { mockCache, MockACSCache }
})

vi.mock('../../cache/item', () => {
return {
ACSCache: MockACSCache,
PaginatedACSCache: MockACSCache,
}
})

const ledgerProvider = vi.hoisted(() => ({
request: vi.fn(),
}))

describe('cache collection', () => {
;[ACSCacheCollection, PaginatedACSCacheCollection].forEach(
(cacheConstructor) => {
describe(`using ${cacheConstructor.name}`, () => {
let collection: ACSCacheCollection | PaginatedACSCacheCollection

beforeEach(() => {
vi.clearAllMocks()
mockCache.calculateAt.mockReturnValue([
{
workflowId: 'test-workflow',
contractEntry: {
JsActiveContract: {
createdEvent: {
contractId: 'contract-1',
templateId: 'template1',
},
synchronizerId: 'sync1',
reassignmentCounter: 0,
},
},
},
])

collection = new cacheConstructor(ledgerProvider)
})

it('should create cache collection with custom options', () => {
expect(collection).toBeDefined()

const customCollection = new cacheConstructor(
ledgerProvider,
{
maxSize: 50,
entryExpirationTimeInMS: 5 * 60 * 1000,
}
)
expect(customCollection).toBeDefined()
})

describe('readFromCache', () => {
it('should read from cache with single party and template', async () => {
const options = {
offset: 100,
parties: ['party1'],
templateIds: ['template1'],
}

const result = await collection.readFromCache(options)

expect(MockACSCache).toHaveBeenCalledWith(
ledgerProvider
)
expect(mockCache.update).toHaveBeenCalledWith(options)
expect(mockCache.calculateAt).toHaveBeenCalledWith(100)
expect(result).toHaveLength(1)
})

it('should read from cache with multiple parties and templates', async () => {
const options = {
offset: 100,
parties: ['party1', 'party2'],
templateIds: [
'template1',
'template2',
'template3',
],
}

const result = await collection.readFromCache(options)

// Should create 6 cache instances (2 parties × 3 templates)
expect(MockACSCache).toHaveBeenCalledTimes(6)
expect(mockCache.update).toHaveBeenCalledTimes(6)
Comment thread
mateuszpiatkowski-da marked this conversation as resolved.
expect(mockCache.calculateAt).toHaveBeenCalledTimes(6)
for (let i = 0; i < 6; ++i) {
expect(mockCache.update).toHaveBeenNthCalledWith(
i + 1,
options
)
expect(
mockCache.calculateAt
).toHaveBeenNthCalledWith(i + 1, options.offset)
}
expect(result).toHaveLength(6)
})

it('should read from cache with parties and interfaces', async () => {
const options = {
offset: 100,
parties: ['party1'],
interfaceIds: ['interface1', 'interface2'],
}

const result = await collection.readFromCache(options)

// Should create 2 cache instances (1 party × 2 interfaces)
expect(MockACSCache).toHaveBeenCalledTimes(2)
expect(mockCache.update).toHaveBeenCalledTimes(2)
expect(result).toHaveLength(2)
})

it('should read from cache with parties, templates, and interfaces', async () => {
const options = {
offset: 150,
parties: ['party1'],
templateIds: ['template1'],
interfaceIds: ['interface1'],
}

const result = await collection.readFromCache(options)

// Should create 2 cache instances (1 for interface, 1 for template)
expect(MockACSCache).toHaveBeenCalledTimes(2)
expect(mockCache.update).toHaveBeenCalledTimes(2)
expect(mockCache.calculateAt).toHaveBeenCalledWith(150)
expect(result).toHaveLength(2)
})

it('should reuse existing cache for same key', async () => {
const options = {
offset: 100,
parties: ['party1'],
templateIds: ['template1'],
}

await collection.readFromCache(options)
await collection.readFromCache(options)

// Should only create cache once
expect(MockACSCache).toHaveBeenCalledOnce()
// But should update and calculate twice
expect(mockCache.update).toHaveBeenCalledTimes(2)
expect(mockCache.calculateAt).toHaveBeenCalledTimes(2)
})

it('should create different caches for different keys', async () => {
await collection.readFromCache({
offset: 100,
parties: ['party1'],
templateIds: ['template1'],
})

await collection.readFromCache({
offset: 100,
parties: ['party2'],
templateIds: ['template1'],
})

// Should create two different caches
expect(MockACSCache).toHaveBeenCalledTimes(2)
})

it('should flatten results from multiple queries', async () => {
mockCache.calculateAt.mockReturnValue([
{
contractEntry: {
JsActiveContract: {
createdEvent: { contractId: 'c1' },
},
},
},
{
contractEntry: {
JsActiveContract: {
createdEvent: { contractId: 'c2' },
},
},
},
])

const options = {
offset: 100,
parties: ['party1'],
templateIds: ['template1', 'template2'],
}

const result = await collection.readFromCache(options)

// 2 templates × 2 contracts per template = 4 total contracts
expect(result).toHaveLength(4)
})
})
})
}
)
})
Loading