Background
The Token interface mock (mock_canton_token.go, 924 lines of mockery-generated code) is currently duplicated across multiple consumer packages:
pkg/token/mocks/mock_canton_token.go
pkg/transfer/mocks/mock_canton_token.go
PR #268 (AcceptWorker) adds a third copy at pkg/custodial/mocks/mock_canton_token.go. Once that PR merges, we'll have ~3000 lines of identical generated code across three locations, and any future consumer of Token will likely add a fourth.
Cost
- Every change to the
Token interface (in pkg/cantonsdk/token/client.go) requires regenerating all copies — easy to forget one and end up with skewed mocks.
- ~3000 lines of identical generated code in the repo.
- Increases diff noise on PRs that touch the
Token interface.
Proposed solution
Move the mock to a single shared location alongside the interface definition:
pkg/cantonsdk/token/mocks/mock_canton_token.go
All consumer packages (pkg/token, pkg/transfer, pkg/custodial, and any future consumers) import from there.
Mockery's --srcpkg flag already supports this pattern. PR #268's pkg/custodial/accept_worker.go:21 go:generate directive uses it:
//go:generate mockery --srcpkg github.com/chainsafe/canton-middleware/pkg/cantonsdk/token --name Token --output ./mocks --filename mock_canton_token.go
The same directive can live once in pkg/cantonsdk/token/ and emit a single mock package.
Sequencing
This should land after PR #268 merges so we consolidate from the full known set of consumers. Otherwise we'd just have to redo the consolidation when #268 lands.
Out of scope
- Other interface mocks in the codebase — this issue is scoped to
Token only. If similar duplication exists for other interfaces, those can be follow-ups.
Background
The
Tokeninterface mock (mock_canton_token.go, 924 lines of mockery-generated code) is currently duplicated across multiple consumer packages:pkg/token/mocks/mock_canton_token.gopkg/transfer/mocks/mock_canton_token.goPR #268 (AcceptWorker) adds a third copy at
pkg/custodial/mocks/mock_canton_token.go. Once that PR merges, we'll have ~3000 lines of identical generated code across three locations, and any future consumer ofTokenwill likely add a fourth.Cost
Tokeninterface (inpkg/cantonsdk/token/client.go) requires regenerating all copies — easy to forget one and end up with skewed mocks.Tokeninterface.Proposed solution
Move the mock to a single shared location alongside the interface definition:
pkg/cantonsdk/token/mocks/mock_canton_token.goAll consumer packages (
pkg/token,pkg/transfer,pkg/custodial, and any future consumers) import from there.Mockery's
--srcpkgflag already supports this pattern. PR #268'spkg/custodial/accept_worker.go:21go:generatedirective uses it://go:generate mockery --srcpkg github.com/chainsafe/canton-middleware/pkg/cantonsdk/token --name Token --output ./mocks --filename mock_canton_token.goThe same directive can live once in
pkg/cantonsdk/token/and emit a single mock package.Sequencing
This should land after PR #268 merges so we consolidate from the full known set of consumers. Otherwise we'd just have to redo the consolidation when #268 lands.
Out of scope
Tokenonly. If similar duplication exists for other interfaces, those can be follow-ups.